/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 850ms 684.0 KiB
#3 Accepted 926ms 756.0 KiB
#4 Accepted 963ms 2.48 MiB
#5 Accepted 961ms 19.812 MiB
#6 Accepted 1100ms 193.168 MiB
#7 Accepted 1101ms 193.109 MiB
#8 Accepted 1095ms 193.055 MiB
#9 Accepted 1104ms 193.094 MiB
#10 Accepted 1110ms 193.098 MiB
#11 Accepted 1094ms 193.012 MiB
#12 Accepted 1097ms 192.957 MiB
#13 Accepted 1093ms 193.086 MiB
#14 Accepted 1096ms 193.148 MiB
#15 Accepted 1091ms 193.113 MiB
#16 Accepted 1092ms 192.953 MiB
#17 Accepted 342ms 60.035 MiB
#18 Accepted 202ms 8.191 MiB
#19 Accepted 271ms 9.785 MiB
#20 Accepted 1111ms 193.07 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-12-17 11:27:46
Judged By
Score
100
Total Time
1111ms
Peak Memory
193.168 MiB