Submission #742402

#TimeUsernameProblemLanguageResultExecution timeMemory
742402jamezzzTortoise (CEOI21_tortoise)C++17
48 / 100
3093 ms393168 KiB
#include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf #define pb push_back #define INF 1023456789 #define maxn 5005 int n,a[maxn],pv[maxn],nx[maxn]; vector<int> shop,play; int memo[2*maxn][maxn][2]; int dp(int t,int i,int hv){ if(i>=shop.size()||t>2*n)return 0; if(memo[t][i][hv]!=-1)return memo[t][i][hv]; int sd=INF; if(pv[i]!=-1)sd=min(sd,shop[i]-play[pv[i]]); if(nx[i]<play.size())sd=min(sd,play[nx[i]]-shop[i]); int ans=0; //transition 0: don't do anything ans=max(ans,dp(t+shop[i+1]-shop[i],i+1,hv)); for(int x=1;x<=a[shop[i]]+hv;++x){ if(t+2*(x-1)*sd>2*shop[i])break; //transition 1: back and forth x times ans=max(ans,dp(t+2*x*sd+shop[i+1]-shop[i],i+1,0)+x); //transition 2: back and forth x-1 times, carry 1 to a playground in between i and i+1 if(nx[i]<play.size()&&play[nx[i]]<shop[i+1]){ ans=max(ans,dp(t+2*(x-1)*sd+shop[i+1]-shop[i],i+1,0)+x); } //transition 3: back and forth x-1 times, carry 1 to i+1, then let i+1 settle that ans=max(ans,dp(t+2*(x-1)*sd+shop[i+1]-shop[i],i+1,1)+x-1); } //pf("dp %d %d %d: %d\n",t,i,hv,ans); return memo[t][i][hv]=ans; } int main(){ sf("%d",&n); int sm=0; for(int i=0;i<n;++i){ sf("%d",&a[i]); if(a[i]==-1)play.pb(i); else shop.pb(i),sm+=a[i]; } if(shop.size()==0){ pf("0\n"); return 0; } shop.pb(n); int cur=-1; for(int x=0;x<shop.size();++x){ int i=shop[x]; while(cur+1<play.size()&&play[cur+1]<i)++cur; pv[x]=cur; nx[x]=cur+1; } memset(memo,-1,sizeof memo); pf("%d\n",sm-dp(shop[0],0,0)); }

Compilation message (stderr)

tortoise.cpp: In function 'int dp(int, int, int)':
tortoise.cpp:16:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if(i>=shop.size()||t>2*n)return 0;
      |     ~^~~~~~~~~~~~~
tortoise.cpp:21:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  if(nx[i]<play.size())sd=min(sd,play[nx[i]]-shop[i]);
      |     ~~~~~^~~~~~~~~~~~
tortoise.cpp:35:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   if(nx[i]<play.size()&&play[nx[i]]<shop[i+1]){
      |      ~~~~~^~~~~~~~~~~~
tortoise.cpp: In function 'int main()':
tortoise.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int x=0;x<shop.size();++x){
      |              ~^~~~~~~~~~~~
tortoise.cpp:63:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   while(cur+1<play.size()&&play[cur+1]<i)++cur;
      |         ~~~~~^~~~~~~~~~~~
tortoise.cpp:48:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  sf("%d",&n);
      |    ^
tortoise.cpp:51:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   sf("%d",&a[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...
#Verdict Execution timeMemoryGrader output
Fetching results...