제출 #261796

#제출 시각아이디문제언어결과실행 시간메모리
261796oolimryClimbers (RMI18_climbers)C++14
0 / 100
2 ms512 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define sz(x) (int) (x).size() using namespace std; typedef long long lint; typedef pair<lint,lint> ii; const lint inf = 12345678901234567; lint H[5005]; int n; vector<ii> trans(int peak, int slope){ vector<ii> res; if(peak&1){ ///is peak int slopeEnd; if(slope & 1) slopeEnd = slope+1; else slopeEnd = slope; ///go right if(H[slopeEnd] >= H[peak+1]){ ii nxt = ii(slopeEnd, peak); res.push_back(ii(nxt)); } else{ ii nxt = ii(peak+1, slope); res.push_back(ii(nxt)); } ///go left if(H[slopeEnd] >= H[peak-1]){ ii nxt = ii(slopeEnd, peak-1); res.push_back(ii(nxt)); } else{ ii nxt = ii(peak-1, slope); res.push_back(ii(nxt)); } } else{ ///is valley int slopeEnd; if(slope & 1) slopeEnd = slope; else slopeEnd = slope + 1; ///go right if(H[slopeEnd] <= H[peak+1]){ ii nxt = ii(slopeEnd, peak); res.push_back(ii(nxt)); } else{ ii nxt = ii(peak+1, slope); res.push_back(ii(nxt)); } ///go left if(H[slopeEnd] <= H[peak-1]){ ii nxt = ii(slopeEnd, peak-1); res.push_back(ii(nxt)); } else{ ii nxt = ii(peak-1, slope); res.push_back(ii(nxt)); } } return res; } vector<ii> trans(ii c){ return trans(c.first, c.second); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0;i < n;i++) cin >> H[i]; cout << -1; return 0; if(n == 3){ cout << H[1]; return 0; } if(H[1] > H[n-2]) reverse(H,H+n); ii pre = ii(n-1, 0); ii cur = ii(1, n-2); lint ans = H[1]; int ctr = 0; while(true){ ctr++; //if(ctr >= 400000000) break; if(cur.first == cur.second || cur.first == cur.second + 1) break; vector<ii> res = trans(cur); if(res[0] == pre){ pre = cur; cur = res[1]; } else{ pre = cur; cur = res[0]; } ans += abs(H[pre.first] - H[cur.first]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...