Submission #261753

#TimeUsernameProblemLanguageResultExecution timeMemory
261753cheehengClimbers (RMI18_climbers)C++14
5 / 100
270 ms297304 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; int h[5005]; int h3[5005]; int h2[25000005]; int dist[5005][5005]; int main(){ int N; scanf("%d", &N); for(int i = 0; i < N; i ++){ scanf("%d", &h[i]); } int P = 2; h3[0] = h[0]; h3[1] = h[1]; for(int i = 2; i < N; i ++){ if(h3[i-2] >= h3[i-1] && h3[i-1] >= h3[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("%d ", h2[i]); } printf("\n"); */ 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; memset(dist, -1, sizeof(dist)); dist[A][B] = 0; queue<ii> q; q.push(ii(A, B)); while(!q.empty()){ int A, B; tie(A, B) = q.front(); q.pop(); if(A == B){ printf("%d\n", dist[A][B]); return 0; } //printf("while loop: %d %d %d\n", A, B, dist[A][B]); //printf("%d %d %d %d\n", h2[A+1], h2[A-1], h2[B+1], h2[B-1]); //if(ans > 100){break;} if(h2[A+1] == h2[B-1]){ if(dist[A+1][B-1] == -1){ dist[A+1][B-1] = dist[A][B]+1; q.push(ii(A+1, B-1)); } } if(h2[A-1] == h2[B-1]){ if(dist[A-1][B-1] == -1){ dist[A-1][B-1] = dist[A][B]+1; q.push(ii(A-1, B-1)); } } if(h2[A+1] == h2[B+1]){ if(dist[A+1][B+1] == -1){ dist[A+1][B+1] = dist[A][B]+1; q.push(ii(A+1, B+1)); } } } ans = 1LL << 61; for(int i = 0; i < M; i ++){ if(dist[i][i] == -1){continue;} ans = min(ans, (long long)dist[i][i]); } if(ans == (1LL << 61)){ printf("NO"); return 0; } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

climbers.cpp: In function 'int main()':
climbers.cpp:22:9: warning: unused variable 'P' [-Wunused-variable]
     int P = 2;
         ^
climbers.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
climbers.cpp:18: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...