답안 #293512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293512 2020-09-08T07:04:12 Z crossing0ver Exercise Deadlines (CCO20_day1problem2) C++17
17 / 25
1000 ms 3204 KB
#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

Main.cpp:12:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main() {
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 384 KB Output is correct
2 Correct 30 ms 384 KB Output is correct
3 Correct 30 ms 384 KB Output is correct
4 Correct 30 ms 384 KB Output is correct
5 Correct 25 ms 384 KB Output is correct
6 Correct 26 ms 384 KB Output is correct
7 Correct 24 ms 384 KB Output is correct
8 Correct 24 ms 512 KB Output is correct
9 Correct 18 ms 384 KB Output is correct
10 Correct 17 ms 384 KB Output is correct
11 Correct 27 ms 384 KB Output is correct
12 Correct 29 ms 384 KB Output is correct
13 Correct 24 ms 384 KB Output is correct
14 Correct 25 ms 512 KB Output is correct
15 Correct 17 ms 384 KB Output is correct
16 Correct 19 ms 384 KB Output is correct
17 Correct 32 ms 384 KB Output is correct
18 Correct 29 ms 384 KB Output is correct
19 Correct 25 ms 384 KB Output is correct
20 Correct 25 ms 384 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 22 ms 384 KB Output is correct
23 Correct 27 ms 384 KB Output is correct
24 Correct 28 ms 384 KB Output is correct
25 Correct 30 ms 424 KB Output is correct
26 Correct 30 ms 384 KB Output is correct
27 Correct 33 ms 384 KB Output is correct
28 Correct 32 ms 384 KB Output is correct
29 Correct 29 ms 384 KB Output is correct
30 Correct 30 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 11 ms 512 KB Output is correct
33 Correct 33 ms 384 KB Output is correct
34 Correct 33 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 10 ms 384 KB Output is correct
37 Correct 34 ms 384 KB Output is correct
38 Correct 35 ms 384 KB Output is correct
39 Correct 28 ms 384 KB Output is correct
40 Correct 28 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 28 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 384 KB Output is correct
2 Correct 30 ms 384 KB Output is correct
3 Correct 30 ms 384 KB Output is correct
4 Correct 30 ms 384 KB Output is correct
5 Correct 25 ms 384 KB Output is correct
6 Correct 26 ms 384 KB Output is correct
7 Correct 24 ms 384 KB Output is correct
8 Correct 24 ms 512 KB Output is correct
9 Correct 18 ms 384 KB Output is correct
10 Correct 17 ms 384 KB Output is correct
11 Correct 27 ms 384 KB Output is correct
12 Correct 29 ms 384 KB Output is correct
13 Correct 24 ms 384 KB Output is correct
14 Correct 25 ms 512 KB Output is correct
15 Correct 17 ms 384 KB Output is correct
16 Correct 19 ms 384 KB Output is correct
17 Correct 32 ms 384 KB Output is correct
18 Correct 29 ms 384 KB Output is correct
19 Correct 25 ms 384 KB Output is correct
20 Correct 25 ms 384 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 22 ms 384 KB Output is correct
23 Correct 27 ms 384 KB Output is correct
24 Correct 28 ms 384 KB Output is correct
25 Correct 30 ms 424 KB Output is correct
26 Correct 30 ms 384 KB Output is correct
27 Correct 33 ms 384 KB Output is correct
28 Correct 32 ms 384 KB Output is correct
29 Correct 29 ms 384 KB Output is correct
30 Correct 30 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 11 ms 512 KB Output is correct
33 Correct 33 ms 384 KB Output is correct
34 Correct 33 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 10 ms 384 KB Output is correct
37 Correct 34 ms 384 KB Output is correct
38 Correct 35 ms 384 KB Output is correct
39 Correct 28 ms 384 KB Output is correct
40 Correct 28 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 28 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 1 ms 256 KB Output is correct
45 Correct 1 ms 256 KB Output is correct
46 Execution timed out 1076 ms 3204 KB Time limit exceeded
47 Halted 0 ms 0 KB -