/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 110ms 656.0 KiB
#4 Accepted 89ms 612.0 KiB
#5 Accepted 78ms 604.0 KiB
#6 Accepted 55ms 540.0 KiB
#7 Accepted 49ms 612.0 KiB
#8 Accepted 76ms 2.055 MiB
#9 Accepted 51ms 2.059 MiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define m(a,b,c) max(a,max(b,c))
#define N ll n;cin >> n;
#define Nk ll n,k;cin >> n >> k;
#define A ll a[n];f(i,n) cin >> a[i];
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define S string s;cin>>s;
#define pb push_back

int main()
{
   FAST_IO;
   ll t;
   cin>>t;
   while(t--)
   {
        N;
        ll a[3][n+1];
        ll p[n+1]={0};
        ll q[n+1]={0};
        memset(a,0,sizeof(a));
        for(ll i=1;i<=2;i++)
        {
            for(ll j=1;j<=n;j++)
            {
                ll x;
                cin>>x;
                a[i][j]=x;
                if(j!=1 && j!=n && x+j<0)
                {
                    x=-j;
                }
                if(i==1)
                p[j]=x;
                else
                q[j]=x;
            }
        }
        ll dp[3][n+1];
        memset(dp,0,sizeof(dp));
        for(ll j=2;j<=n;j++)
        {
            dp[1][j]=dp[1][j-1]+p[j-1];
        }
        ll c[n+1]={0};
        c[1]=a[1][1];
        for(ll j=2;j<=n;j++)
        {
            c[j]=dp[1][j]+a[1][j];
        }
        dp[2][1]=a[1][1]+a[2][1];
        ll d[n+1]={0};
        d[1]=a[1][1]+a[2][1];
        for(ll j=2;j<=n;j++)
        {
            dp[2][j]=fmax(dp[2][j-1],d[j-1])+q[j];
            d[j]=fmax(fmax(c[j],dp[2][j-1]),d[j-1])+a[2][j];
        }
        
        cout<<d[n]<<endl;
   }
   
   return 0;
}

Information

Submit By
Type
Submission
Problem
P1050 Game on 2d grid
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 18:02:57
Judged At
2024-11-11 03:31:41
Judged By
Score
100
Total Time
110ms
Peak Memory
2.059 MiB