Submission #430017

#TimeUsernameProblemLanguageResultExecution timeMemory
430017Rouge_HugoHoliday (IOI14_holiday)C++14
0 / 100
14 ms1228 KiB
#include<bits/stdc++.h> #include"holiday.h" #define ll long long #define fi first #define se second #define pb push_back using namespace std; const int M=30; ll INF=-1e9; ll dp[M][M*2][2],a[M]; int n,s; ll d(int x,int y,int z) { if(y<0)return INF; if(x==-1||x==n)return 0; if(y==0)return 0; ll &u=dp[x][y][z]; if(u!=-1)return u; u=a[x]; if(z==0) { u=d(x-1,y-2,z)+a[x]; u=max(d(x-1,y-1,z),u); u=max(u,d(s+1,y-(s-x),1)); u=max(u,d(s+1,y-(s-x)-1,1)+a[x]); return u; } u=d(x+1,y-1,z); u=max(u,d(x+1,y-2,z)+a[x]); return u; } ll d1(int x,int y,int z) { if(y<0)return INF; if(x==-1||x==n)return 0; if(y==0)return 0; ll &u=dp[x][y][z]; if(u!=-1)return u; if(z==0) { u=d1(x+1,y-2,z)+a[x]; u=max(d1(x+1,y-1,z),u); u=max(u,d1(s-1,y-abs(s-x),1)); u=max(u,d1(s-1,y-abs(s-x)-1,1)+a[x]); return u; } u=d1(x-1,y-1,z); u=max(u,d1(x-1,y-2,z)+a[x]); return u; } long long findMaxAttraction(int N, int start, int D, int A[]) { for(int i=0;i<3001;i++) { for(int j=0;j<3001;j++) { dp[i][j][0]=-1; dp[i][j][1]=-1; } } s=start; n=N; for(int i=0;i<n;i++) { a[i]=A[i]; } ll u= d(start,D,0); //memset(dp,-1,sizeof dp); for(int i=0;i<3001;i++) { for(int j=0;j<3001;j++) { dp[i][j][0]=-1; dp[i][j][1]=-1; } } u=max(u,d1(start,D,0)); return u; }

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:57:24: warning: iteration 60 invokes undefined behavior [-Waggressive-loop-optimizations]
   57 |             dp[i][j][0]=-1;
      |             ~~~~~~~~~~~^~~
holiday.cpp:55:22: note: within this loop
   55 |         for(int j=0;j<3001;j++)
      |                     ~^~~~~
holiday.cpp:73:24: warning: iteration 60 invokes undefined behavior [-Waggressive-loop-optimizations]
   73 |             dp[i][j][0]=-1;
      |             ~~~~~~~~~~~^~~
holiday.cpp:71:22: note: within this loop
   71 |         for(int j=0;j<3001;j++)
      |                     ~^~~~~
holiday.cpp:73:24: warning: iteration 30 invokes undefined behavior [-Waggressive-loop-optimizations]
   73 |             dp[i][j][0]=-1;
      |             ~~~~~~~~~~~^~~
holiday.cpp:69:18: note: within this loop
   69 |     for(int i=0;i<3001;i++)
      |                 ~^~~~~
holiday.cpp:57:24: warning: iteration 30 invokes undefined behavior [-Waggressive-loop-optimizations]
   57 |             dp[i][j][0]=-1;
      |             ~~~~~~~~~~~^~~
holiday.cpp:53:18: note: within this loop
   53 |     for(int i=0;i<3001;i++)
      |                 ~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...