/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 384.0 KiB
#2 Accepted 769ms 672.0 KiB
#3 Accepted 848ms 764.0 KiB
#4 Accepted 849ms 2.473 MiB
#5 Runtime Error 52ms 10.27 MiB
#6 Runtime Error 92ms 11.523 MiB
#7 Runtime Error 69ms 11.578 MiB
#8 Runtime Error 68ms 11.574 MiB
#9 Runtime Error 96ms 11.566 MiB
#10 Runtime Error 81ms 11.566 MiB
#11 Runtime Error 93ms 11.828 MiB
#12 Runtime Error 65ms 11.566 MiB
#13 Runtime Error 66ms 11.562 MiB
#14 Runtime Error 65ms 11.52 MiB
#15 Runtime Error 61ms 11.52 MiB
#16 Runtime Error 62ms 11.52 MiB
#17 Runtime Error 58ms 10.566 MiB
#18 Accepted 185ms 8.02 MiB
#19 Accepted 247ms 9.746 MiB
#20 Runtime Error 72ms 11.52 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=10001,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:53:51
Judged At
2024-08-22 12:53:51
Judged By
Score
30
Total Time
849ms
Peak Memory
11.828 MiB