Submission #273233

# Submission time Handle Problem Language Result Execution time Memory
273233 2020-08-19T04:32:07 Z 임성재(#5106) Exercise Deadlines (CCO20_day1problem2) C++17
17 / 25
6 ms 5248 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
int d[100010];
int p[100010];
vector<int> g[100010];
priority_queue<int> pQ;
int tree[100010];

void update(int i) {
	while(i <= n) {
		tree[i]++;

		i += i & -i;
	}
}

int sum(int i) {
	int ret = 0;

	while(i) {
		ret += tree[i];

		i -= i & -i;
	}

	return ret;
}

int main() {
	fast;

	cin >> n;

	for(int i=1; i<=n; i++) {
		cin >> d[i];

		g[d[i]].eb(i);
	}

	for(int i=n; i>=1; i--) {
		for(auto j : g[i]) {
			pQ.em(j);
		}

		if(pQ.empty()) {
			cout << -1;
			return 0;
		}

		p[i] = pQ.top();
		pQ.pop();
	}

	ll ans = 0;

	for(int i=1; i<=n; i++) {
		update(p[i]);
		ans += i - sum(p[i]);
	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
3 Correct 5 ms 2816 KB Output is correct
4 Correct 3 ms 2816 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 4 ms 2816 KB Output is correct
7 Correct 3 ms 2944 KB Output is correct
8 Correct 4 ms 2944 KB Output is correct
9 Correct 4 ms 2944 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 4 ms 2944 KB Output is correct
12 Correct 4 ms 2944 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 3 ms 2816 KB Output is correct
16 Correct 4 ms 2816 KB Output is correct
17 Correct 4 ms 2816 KB Output is correct
18 Correct 4 ms 2816 KB Output is correct
19 Correct 3 ms 2816 KB Output is correct
20 Correct 4 ms 2816 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 4 ms 2816 KB Output is correct
23 Correct 5 ms 2816 KB Output is correct
24 Correct 5 ms 2816 KB Output is correct
25 Correct 4 ms 2816 KB Output is correct
26 Correct 3 ms 2816 KB Output is correct
27 Correct 4 ms 2816 KB Output is correct
28 Correct 4 ms 2816 KB Output is correct
29 Correct 4 ms 2816 KB Output is correct
30 Correct 4 ms 2816 KB Output is correct
31 Correct 3 ms 2816 KB Output is correct
32 Correct 4 ms 2816 KB Output is correct
33 Correct 4 ms 2944 KB Output is correct
34 Correct 3 ms 2816 KB Output is correct
35 Correct 5 ms 2816 KB Output is correct
36 Correct 4 ms 2816 KB Output is correct
37 Correct 4 ms 2944 KB Output is correct
38 Correct 3 ms 2816 KB Output is correct
39 Correct 4 ms 2816 KB Output is correct
40 Correct 4 ms 2816 KB Output is correct
41 Correct 4 ms 2816 KB Output is correct
42 Correct 4 ms 2816 KB Output is correct
43 Correct 3 ms 2816 KB Output is correct
44 Correct 3 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 4 ms 2816 KB Output is correct
3 Correct 5 ms 2816 KB Output is correct
4 Correct 3 ms 2816 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 4 ms 2816 KB Output is correct
7 Correct 3 ms 2944 KB Output is correct
8 Correct 4 ms 2944 KB Output is correct
9 Correct 4 ms 2944 KB Output is correct
10 Correct 3 ms 2944 KB Output is correct
11 Correct 4 ms 2944 KB Output is correct
12 Correct 4 ms 2944 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 3 ms 2816 KB Output is correct
16 Correct 4 ms 2816 KB Output is correct
17 Correct 4 ms 2816 KB Output is correct
18 Correct 4 ms 2816 KB Output is correct
19 Correct 3 ms 2816 KB Output is correct
20 Correct 4 ms 2816 KB Output is correct
21 Correct 3 ms 2816 KB Output is correct
22 Correct 4 ms 2816 KB Output is correct
23 Correct 5 ms 2816 KB Output is correct
24 Correct 5 ms 2816 KB Output is correct
25 Correct 4 ms 2816 KB Output is correct
26 Correct 3 ms 2816 KB Output is correct
27 Correct 4 ms 2816 KB Output is correct
28 Correct 4 ms 2816 KB Output is correct
29 Correct 4 ms 2816 KB Output is correct
30 Correct 4 ms 2816 KB Output is correct
31 Correct 3 ms 2816 KB Output is correct
32 Correct 4 ms 2816 KB Output is correct
33 Correct 4 ms 2944 KB Output is correct
34 Correct 3 ms 2816 KB Output is correct
35 Correct 5 ms 2816 KB Output is correct
36 Correct 4 ms 2816 KB Output is correct
37 Correct 4 ms 2944 KB Output is correct
38 Correct 3 ms 2816 KB Output is correct
39 Correct 4 ms 2816 KB Output is correct
40 Correct 4 ms 2816 KB Output is correct
41 Correct 4 ms 2816 KB Output is correct
42 Correct 4 ms 2816 KB Output is correct
43 Correct 3 ms 2816 KB Output is correct
44 Correct 3 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
46 Runtime error 6 ms 5248 KB Execution killed with signal 11
47 Halted 0 ms 0 KB -