Submission #261744

#TimeUsernameProblemLanguageResultExecution timeMemory
261744cheehengClimbers (RMI18_climbers)C++14
0 / 100
1096 ms5240 KiB
#include <bits/stdc++.h> using namespace std; int h[5005]; int h2[250005]; int main(){ int N; scanf("%d", &N); for(int i = 0; i < N; i ++){ scanf("%d", &h[i]); } int M = 1; h2[0] = 0; for(int i = 0; i < N-1; i ++){ if(h[i] < h[i+1]){ for(int j = h[i]+1; j <= h[i+1]; j ++){ h2[M++] = j; } }else if(h[i] > h[i+1]){ for(int j = h[i]-1; j >= h[i+1]; j --){ h2[M++] = j; } } } for(int i = 0; i < M; i ++){ printf("h2[%d]=%d\n", i, h2[i]); } long long ans = 0; int A = 0; int B = M-1; while(A < B){ //printf("while loop: %d %d %lld\n", A, B, ans); //if(ans > 100){break;} if(h2[A+1] == h2[B-1]){ A ++; B --; ans ++; continue; } if(h2[A-1] == h2[B-1]){ while(h2[A-1] == h2[B-1]){ A --; B --; ans ++; } }else{ while(h2[A+1] == h2[B+1]){ A ++; B ++; ans ++; } } } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

climbers.cpp: In function 'int main()':
climbers.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
climbers.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &h[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...