Submission #293514

# Submission time Handle Problem Language Result Execution time Memory
293514 2020-09-08T07:04:49 Z crossing0ver Exercise Deadlines (CCO20_day1problem2) C++17
17 / 25
1000 ms 2040 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() {
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 10 ms 384 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 13 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 16 ms 384 KB Output is correct
12 Correct 17 ms 384 KB Output is correct
13 Correct 13 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 20 ms 384 KB Output is correct
18 Correct 18 ms 384 KB Output is correct
19 Correct 13 ms 384 KB Output is correct
20 Correct 14 ms 512 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 10 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 14 ms 384 KB Output is correct
25 Correct 9 ms 384 KB Output is correct
26 Correct 9 ms 384 KB Output is correct
27 Correct 7 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 11 ms 384 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 22 ms 384 KB Output is correct
34 Correct 22 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 22 ms 384 KB Output is correct
38 Correct 22 ms 400 KB Output is correct
39 Correct 8 ms 384 KB Output is correct
40 Correct 8 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 8 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 0 ms 256 KB Output is correct
45 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 10 ms 384 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 13 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 16 ms 384 KB Output is correct
12 Correct 17 ms 384 KB Output is correct
13 Correct 13 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 20 ms 384 KB Output is correct
18 Correct 18 ms 384 KB Output is correct
19 Correct 13 ms 384 KB Output is correct
20 Correct 14 ms 512 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 10 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 14 ms 384 KB Output is correct
25 Correct 9 ms 384 KB Output is correct
26 Correct 9 ms 384 KB Output is correct
27 Correct 7 ms 384 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 11 ms 384 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 22 ms 384 KB Output is correct
34 Correct 22 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 KB Output is correct
37 Correct 22 ms 384 KB Output is correct
38 Correct 22 ms 400 KB Output is correct
39 Correct 8 ms 384 KB Output is correct
40 Correct 8 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 8 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 0 ms 256 KB Output is correct
45 Correct 0 ms 256 KB Output is correct
46 Execution timed out 1087 ms 2040 KB Time limit exceeded
47 Halted 0 ms 0 KB -