Submission #307019

#TimeUsernameProblemLanguageResultExecution timeMemory
307019NintsiChkhaidzeExercise Deadlines (CCO20_day1problem2)C++14
0 / 25
1048 ms384 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define ll long long using namespace std; int a[200005],b[200005]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n; cin>>n; for (int i = 1; i <= n; i++) cin>>a[i],b[i] = a[i]; sort(b + 1,b + n + 1); for (int i = 1;i <= n; i++) if (b[i] < i) { cout<<-1; return 0; } int ans=0; while (true){ int ind = 0; for (int i = 1; i <= n; i++) if (a[i] < i) {ind = i; break;} if (ind == 0) break; //cout<<ind<<" "<<a[ind]<<endl; int m = a[ind]; for (int i = ind - 1; i >= 1; i--){ if (a[i] == a[i + 1]) continue; swap(a[i],a[i + 1]); ans++; if (m >= i) break; } /* for (int i =1;i<=n;i++) cout<<a[i]<<" "; cout<<endl; */ } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...