Submission #1104863

#TimeUsernameProblemLanguageResultExecution timeMemory
1104863ro9669Airplane (NOI23_airplane)C++17
22 / 100
56 ms18848 KiB
#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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(name".INP" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(name".OUT" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...