/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 440.0 KiB
#2 Accepted 806ms 672.0 KiB
#3 Accepted 855ms 764.0 KiB
#4 Accepted 862ms 2.48 MiB
#5 Accepted 872ms 19.812 MiB
#6 Accepted 1006ms 192.977 MiB
#7 Accepted 1009ms 193.133 MiB
#8 Accepted 1016ms 192.969 MiB
#9 Accepted 1004ms 193.023 MiB
#10 Accepted 1000ms 192.996 MiB
#11 Accepted 998ms 192.941 MiB
#12 Accepted 1001ms 192.977 MiB
#13 Accepted 998ms 193.121 MiB
#14 Accepted 992ms 193.133 MiB
#15 Accepted 997ms 193.145 MiB
#16 Accepted 1010ms 193.137 MiB
#17 Accepted 316ms 59.922 MiB
#18 Accepted 188ms 8.184 MiB
#19 Accepted 250ms 9.676 MiB
#20 Accepted 1070ms 193.148 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++)
                for(int k=0;k<limit;k++){
                    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++)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 12:56:02
Judged At
2024-12-17 11:27:49
Judged By
Score
100
Total Time
1070ms
Peak Memory
193.148 MiB