/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 436.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 48ms 612.0 KiB
#4 Accepted 36ms 592.0 KiB
#5 Accepted 39ms 604.0 KiB
#6 Accepted 46ms 648.0 KiB
#7 Accepted 50ms 620.0 KiB
#8 Accepted 51ms 1.617 MiB
#9 Accepted 38ms 1.605 MiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e6+10,MOD=1000000007;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<vector<ll>>dp(3,vector<ll>(n+1,0));
        vector<vector<ll>>arr(3,vector<ll>(n+1,0));
        for(int i=1;i<=2;i++){
            for(int j=1;j<=n;j++){
                cin>>dp[i][j];
                arr[i][j]=dp[i][j];
        }
    }
       for(int i=1;i<=n;i++){
          if(i==1)continue;
          if(i==n){
            dp[1][i]+=dp[1][i-1];
            continue;
          }
          dp[1][i]=max((ll)i*(-1),dp[1][i])+dp[1][i-1];
       }
       for(int i=1;i<=n;i++){
           if(i==1){
            dp[2][i]+=dp[1][i];
            continue;
          }
          if(i==n){
            dp[2][i]+=max(dp[1][i],dp[2][i-1]);
            continue;
          }
          dp[2][i]=max(dp[1][i-1]+arr[1][i]+arr[2][i],dp[2][i-1]+max(arr[2][i],(ll)i*(-1)));

       }
       cout<<dp[2][n]<<"\n";
       
    }
    
   
   return 0;
}
 

Information

Submit By
Type
Submission
Problem
P1050 Game on 2d grid
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-03 21:48:21
Judged At
2024-11-11 03:35:47
Judged By
Score
100
Total Time
51ms
Peak Memory
1.617 MiB