/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 896ms 664.0 KiB
#3 Accepted 963ms 760.0 KiB
#4 Accepted 986ms 2.469 MiB
#5 Accepted 983ms 19.805 MiB
#6 Accepted 1120ms 193.055 MiB
#7 Accepted 1124ms 193.023 MiB
#8 Accepted 1123ms 193.168 MiB
#9 Accepted 1123ms 193.129 MiB
#10 Accepted 1102ms 192.961 MiB
#11 Accepted 1118ms 193.078 MiB
#12 Accepted 1118ms 192.961 MiB
#13 Accepted 1100ms 193.074 MiB
#14 Accepted 1103ms 192.934 MiB
#15 Accepted 1119ms 193.066 MiB
#16 Accepted 1103ms 193.145 MiB
#17 Accepted 347ms 60.023 MiB
#18 Accepted 211ms 8.176 MiB
#19 Accepted 286ms 9.562 MiB
#20 Accepted 1108ms 193.105 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=200001,MOD=1e18;
#define int long long
//typedef long long int ll;

int dp[M][5][5][5];
int limit=5;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int>a(n+1);
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int l=0;l<limit;l++)
            for(int j=0;j<limit;j++)
                for(int k=0;k<limit;k++)dp[1][l][j][k]=l*a[1];

          for(int l=0;l<limit;l++)
            for(int j=0;j<limit;j++)
                for(int k=0;k<limit;k++){
                    if(l!=j)dp[2][l][j][k]=l*a[2]+j*a[1];
                    else dp[2][l][j][k]=MOD;
                }

            for(int i=3;i<=n;i++){
                for(int l=0;l<limit;l++){
               for(int j=0;j<limit;j++){
                if(l==j){continue;}
                for(int k=0;k<limit;k++){
                    if(k==l || k==j){continue;}
                    dp[i][l][j][k]=MOD;
                   // if(l==j || l==k || j==k)continue;
                    int cur=a[i]*l+a[i-1]*j+ a[i-2]*k;

                    for(int x=0;x<limit;x++){
                        if(x==j || x==k)continue;
                       for(int y=0;y<limit;y++){
                           if( y==x || y==k)continue;
                           for(int z=0;z<limit;z++){
                            if(z==x || z==y )continue;
                            dp[i][l][j][k]=min(dp[i][l][j][k],cur+dp[i-3][x][y][z]);
                           }
                       }
                    }
                }
            }
        }
            }
            int mx=MOD;
             for(int l=0;l<limit;l++)
            for(int j=0;j<limit;j++)
                for(int k=0;k<limit;k++)
                    {
                        if(l==j || l==k || j==k)continue;
                        mx=min(dp[n][l][j][k],mx);
                    }
                    cout<<mx<<"\n";
        
    
    }


   
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1087 Face the monsters
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-22 13:20:33
Judged At
2024-08-22 13:20:33
Judged By
Score
100
Total Time
1124ms
Peak Memory
193.168 MiB