제출 #293512

#제출 시각아이디문제언어결과실행 시간메모리
293512crossing0verExercise Deadlines (CCO20_day1problem2)C++17
17 / 25
1076 ms3204 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;
}

컴파일 시 표준 에러 (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...