Submission #309535

#TimeUsernameProblemLanguageResultExecution timeMemory
309535kesochel_Exercise Deadlines (CCO20_day1problem2)C++14
17 / 25
1079 ms2440 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n, ans = 0; cin >> n; int a[n]; for(int i = 0; i < n; i++){ cin >> a[i]; } int k = 0; for(int i = 0; i < n; i++){ if(a[i] == n){ k++; } } if(k == 0){ cout << -1 << endl; } else { for(int i = n - 1; i >= 0; i--){ for(int j = i; j >= 0; j--){ if(a[j] > i){ for(int k = j; k < i; k++){ swap(a[k], a[k+1]); } ans += i - j; break; } } } for(int i = 0; i < n; i++){ if(a[i] < i + 1){ cout << -1 << endl; return 0; } } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...