# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104863 | 2024-10-24T14:50:03 Z | ro9669 | Airplane (NOI23_airplane) | C++17 | 56 ms | 18848 KB |
#include <bits/stdc++.h> #define fi first #define se second #define all(v) v.begin() , v.end() #define sz(v) int(v.size()) #define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); using namespace std; typedef long long ll; typedef pair<int , int> ii; typedef pair<long long , int> lli; const int maxN = int(2e5)+7; const int maxM = int(4e5)+7; int n , m , a[maxN]; ii E[maxM]; vector<int> g[maxN]; namespace sub1{ bool check(){ if (m != n - 1) return 0; for (int i = 1 ; i <= m ; i++){ if (E[i].fi != i || E[i].se != i + 1) return 0; } return 1; } void solve(){ int p = -1; for (int i = 1 ; i <= n ; i++){ if (p == -1 || a[p] < a[i]) p = i; } ll ans = 0; int pre = 0 , suf = 0; for (int i = 2 ; i <= p ; i++){ if (pre == a[p]){ ans++; } else{ ans += 1ll * max(a[i] - pre , 1); pre = max(pre + 1 , a[i]); } } for (int i = n - 1 ; i >= p ; i--){ if (suf == a[p]){ ans++; } else{ ans += 1ll * max(a[i] - suf , 1); suf = max(suf + 1 , a[i]); } } cout << ans << "\n"; } } void solve(){ cin >> n >> m; for (int i = 1 ; i <= n ; i++) cin >> a[i]; for (int i = 1 ; i <= m ; i++){ int u , v; cin >> u >> v; E[i] = {u , v}; g[u].push_back(v); g[v].push_back(u); } if (sub1::check()) return sub1::solve(); } #define name "A" int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(name".INP" , "r")){ freopen(name".INP" , "r" , stdin); freopen(name".OUT" , "w" , stdout); } int t = 1; //cin >> t; while (t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Correct | 48 ms | 16712 KB | Output is correct |
3 | Correct | 50 ms | 18376 KB | Output is correct |
4 | Correct | 56 ms | 18344 KB | Output is correct |
5 | Correct | 52 ms | 18848 KB | Output is correct |
6 | Correct | 52 ms | 18760 KB | Output is correct |
7 | Correct | 54 ms | 18760 KB | Output is correct |
8 | Correct | 2 ms | 8784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Incorrect | 2 ms | 8784 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Incorrect | 2 ms | 8784 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8784 KB | Output is correct |
2 | Correct | 48 ms | 16712 KB | Output is correct |
3 | Correct | 50 ms | 18376 KB | Output is correct |
4 | Correct | 56 ms | 18344 KB | Output is correct |
5 | Correct | 52 ms | 18848 KB | Output is correct |
6 | Correct | 52 ms | 18760 KB | Output is correct |
7 | Correct | 54 ms | 18760 KB | Output is correct |
8 | Correct | 2 ms | 8784 KB | Output is correct |
9 | Correct | 2 ms | 8784 KB | Output is correct |
10 | Incorrect | 2 ms | 8784 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |