# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104826 | 2024-10-24T13:54:58 Z | ro9669 | Airplane (NOI23_airplane) | C++17 | 48 ms | 17996 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 limit = *max_element(a + 1 , a + n + 1); ll ans = 0; int pre = 0 , suf = 0; for (int i = 2 ; i <= n ; i++){ if (pre == limit){ break; } else{ ans += 1ll * (max(0 , a[i] - pre - 1) + 1); pre = max(pre + 1 , a[i]); } } for (int i = n - 1 ; i >= 1 ; i--){ if (suf == limit){ break; } else{ ans += 1ll * (max(0 , a[i] - suf - 1) + 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 | Incorrect | 48 ms | 17996 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 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 | 3 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 | 48 ms | 17996 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |