Submission #293916

# Submission time Handle Problem Language Result Execution time Memory
293916 2020-09-08T13:44:26 Z sabamaku Exercise Deadlines (CCO20_day1problem2) C++14
17 / 25
244 ms 11616 KB
#include<bits/stdc++.h>
using namespace std;

int n,d[200005],p[2000005];

vector <int> mp[200005];

priority_queue <int> q;

int solve(int a){
    int x = 0;
    for(int i = a; i > 0; i -= (i & -i)){
        x += p[i];
    }
    return x;
}

void update(int a){
    for(int i = a + 1; i <= n; i += (i & -i)){
        p[i]++;
    }
}

int a;

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> d[i];
        mp[d[i]].push_back(i);
    }
    sort(d + 1,d + n + 1);
    for(int i = 1; i <= n; i++){
        if(d[i] < i){
            cout << -1;
            return 0;
        }
    }
    int ans = 0;
    for(int i = n; i >= 1; i--){
        for(int j = 0; j < mp[i].size(); j++){
            q.push(mp[i][j]);
        }
        a = q.top();
        q.pop();
        int x = solve(a);
        ans += i - (a - x);
        update(a);
    }
    cout << ans;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(int j = 0; j < mp[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 9 ms 5248 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 9 ms 5120 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 8 ms 5248 KB Output is correct
9 Correct 7 ms 5224 KB Output is correct
10 Correct 7 ms 5248 KB Output is correct
11 Correct 9 ms 5224 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 9 ms 5120 KB Output is correct
14 Correct 8 ms 5120 KB Output is correct
15 Correct 7 ms 5248 KB Output is correct
16 Correct 8 ms 5248 KB Output is correct
17 Correct 8 ms 5248 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
19 Correct 9 ms 5240 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
21 Correct 8 ms 5248 KB Output is correct
22 Correct 9 ms 5248 KB Output is correct
23 Correct 7 ms 5248 KB Output is correct
24 Correct 9 ms 5188 KB Output is correct
25 Correct 8 ms 5240 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 20 ms 5248 KB Output is correct
28 Correct 9 ms 5248 KB Output is correct
29 Correct 9 ms 5248 KB Output is correct
30 Correct 7 ms 5248 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 5212 KB Output is correct
33 Correct 7 ms 5248 KB Output is correct
34 Correct 7 ms 5248 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 8 ms 5120 KB Output is correct
37 Correct 7 ms 5248 KB Output is correct
38 Correct 7 ms 5248 KB Output is correct
39 Correct 7 ms 5248 KB Output is correct
40 Correct 8 ms 5212 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 8 ms 5244 KB Output is correct
43 Correct 8 ms 5216 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 9 ms 5248 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 9 ms 5120 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 8 ms 5248 KB Output is correct
9 Correct 7 ms 5224 KB Output is correct
10 Correct 7 ms 5248 KB Output is correct
11 Correct 9 ms 5224 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 9 ms 5120 KB Output is correct
14 Correct 8 ms 5120 KB Output is correct
15 Correct 7 ms 5248 KB Output is correct
16 Correct 8 ms 5248 KB Output is correct
17 Correct 8 ms 5248 KB Output is correct
18 Correct 8 ms 5120 KB Output is correct
19 Correct 9 ms 5240 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
21 Correct 8 ms 5248 KB Output is correct
22 Correct 9 ms 5248 KB Output is correct
23 Correct 7 ms 5248 KB Output is correct
24 Correct 9 ms 5188 KB Output is correct
25 Correct 8 ms 5240 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 20 ms 5248 KB Output is correct
28 Correct 9 ms 5248 KB Output is correct
29 Correct 9 ms 5248 KB Output is correct
30 Correct 7 ms 5248 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 5212 KB Output is correct
33 Correct 7 ms 5248 KB Output is correct
34 Correct 7 ms 5248 KB Output is correct
35 Correct 8 ms 5120 KB Output is correct
36 Correct 8 ms 5120 KB Output is correct
37 Correct 7 ms 5248 KB Output is correct
38 Correct 7 ms 5248 KB Output is correct
39 Correct 7 ms 5248 KB Output is correct
40 Correct 8 ms 5212 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 8 ms 5244 KB Output is correct
43 Correct 8 ms 5216 KB Output is correct
44 Correct 4 ms 4992 KB Output is correct
45 Correct 4 ms 4992 KB Output is correct
46 Incorrect 244 ms 11616 KB Output isn't correct
47 Halted 0 ms 0 KB -