Submission #393690

#TimeUsernameProblemLanguageResultExecution timeMemory
393690Qw3rTyRabbit Carrot (LMIO19_triusis)C++11
0 / 100
1 ms332 KiB
#include <iostream> using namespace std; const int maxN = 2e5+5; int a[maxN]; int f[maxN]; int dif[maxN]; int ps[maxN]; int N,M; void testIO(){ freopen("../test.in","r",stdin); return; return; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); //testIO(); cin >> N >> M; for(int i = 1; i <= N; ++i)cin >> a[i]; int curHeight = M; //current height that can be reached int prevHeight = M; //maximum height that can be reached for(int i = 1; i <= N; ++i){ //Can jump onto the next pole if(a[i] <= curHeight){ dif[i] = 0; //Moves forward prevHeight = curHeight; curHeight = a[i] + M; } else{ dif[i] = 1; curHeight = max(prevHeight, curHeight); //Tries to go as high as possible } } for(int i = 1; i <= N; ++i)ps[i] = ps[i-1] + dif[i]; for(int i = 1; i <= N; ++i){ for(int j = 1; j < i; ++j){ if(a[j] + M < a[i]){ f[i] = max(f[i],f[j] + ps[i] - ps[j-1]); } } } int res = 0; for(int i = 1; i <= N; ++i)res = max(res,f[i]); cout << res << '\n'; return 0; }

Compilation message (stderr)

triusis.cpp: In function 'void testIO()':
triusis.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     freopen("../test.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...