Submission #959319

#TimeUsernameProblemLanguageResultExecution timeMemory
959319gmroh06빌딩 장식 3 (JOI15_building3)C++14
100 / 100
79 ms14928 KiB
#import <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; inline void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ll n, ans = 1, cnt, loc; vector<ll> arr; int main() { fastio(); cin >> n; arr.resize(n); for (ll i = 1; i < n; i++) { cin >> arr[i]; } for (ll i = 0, h = 0; i < n; i++) { if (arr[i] - h > 2) { cout << 0 << '\n'; return 0; } else if (arr[i] - h == 2) { if (cnt) { cout << 0 << '\n'; return 0; } else { cnt = arr[i]; loc = i; } } h = max(h, arr[i]); ans += h; } if (cnt) { for (ll i = 0; i < loc; i++) { if (arr[i] + 2 == cnt) { ans = loc - i; break; } } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

building3.cpp:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
    1 | #import <bits/stdc++.h>
      |  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...