Submission #293507

#TimeUsernameProblemLanguageResultExecution timeMemory
293507crossing0verInterval Collection (CCO20_day2problem2)C++17
0 / 25
6 ms1920 KiB
#include<bits/stdc++.h> #define vi vector<int> #define pii pair<int,int> #define fi first #define se second #define pb push_back #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> main() { int n; cin >> n; vi v(n); for (int i = 0; i < n; i++) { cin >> v[i]; --v[i]; } vi g = v; sort(g.begin(),g.end()); // INVALID for (int i = 0; i < n; i++) if (g[i] < i) { cout <<-1; return 0; }// int ans = 0; while(v.size()) { int n = v.size(); for (int i = n-1; i >= 0; i --) { if (v[i] == n-1) { int j = i; while (j < n-1) { swap(v[j],v[j+1]); ans++; j++; } v.pop_back(); for (int i = 0; i < n-1; i++) if (v[i] == n-1) v[i]--; break; //cout << ans; } // cout <<"DS"; } } cout << ans; }

Compilation message (stderr)

Main.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...