# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104863 | ro9669 | Airplane (NOI23_airplane) | C++17 | 56 ms | 18848 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |