# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
484783 | 2021-11-05T13:10:35 Z | nhanbin03 | Watermelon (INOI20_watermelon) | C++14 | 75 ms | 18188 KB |
#include <bits/stdc++.h> #define task "INOI20_watermelon" #define X first #define Y second using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 1e5 + 10; int n, k; int a[N], inDeg[N], ans[N]; vector<int> adj[N], pos[N]; bool buildDAG(int maxVal) { for (int i = 1; i <= n; i++) { pos[a[i]].push_back(i); } set<int> posSet; for (int i = maxVal; i >= 1; i--) { if (pos[i].empty()) return 0; for (int j = pos[i].size() - 1; j >= 0; j--) { int x = pos[i][j]; auto it = posSet.lower_bound(x); if (it != posSet.end()) { adj[x].push_back(*it); inDeg[*it]++; } if (it != posSet.begin()) { it--; if (j == 0 || pos[i][j - 1] < *it) { adj[x].push_back(*it); inDeg[*it]++; } } posSet.insert(x); } } return 1; } void solve() { priority_queue<int, vector<int>, greater<int>> pq; for (int i = 1; i <= n; i++) { if (inDeg[i] == 0) { pq.push(i); } } for (int i = 1; i <= n; i++) { int u = pq.top(); pq.pop(); ans[u] = i; for (int v : adj[u]) { inDeg[v]--; if (inDeg[v] == 0) pq.push(v); } } for (int i = 1; i <= n; i++) { assert(inDeg[i] == 0); } } int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); if (fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (a[n] != -1) { cout << -1; return 0; } int maxVal = 0; for (int i = 1; i <= n; i++) { maxVal = max(maxVal, a[i]); } for (int i = n; i >= 1; i--) { if (a[i] == -1) a[i] = ++maxVal; } // for (int i = 1; i <= n; i++) { // cout << a[i] << " "; // } // cout << "\n"; if (!buildDAG(maxVal)) { cout << -1; return 0; } // for (int i = 1; i <= n; i++) { // cout << i << ": "; // for (int j : adj[i]) { // cout << j << " "; // } // cout << "\n"; // } solve(); for (int i = 1; i <= n; i++) { cout << ans[i] << " "; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4940 KB | Output is correct |
2 | Correct | 2 ms | 4940 KB | Output is correct |
3 | Correct | 2 ms | 4940 KB | Output is correct |
4 | Incorrect | 2 ms | 5012 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4940 KB | Output is correct |
2 | Correct | 2 ms | 4940 KB | Output is correct |
3 | Correct | 2 ms | 4940 KB | Output is correct |
4 | Incorrect | 2 ms | 5012 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 10140 KB | Output is correct |
2 | Correct | 10 ms | 6220 KB | Output is correct |
3 | Correct | 29 ms | 10204 KB | Output is correct |
4 | Correct | 12 ms | 6220 KB | Output is correct |
5 | Correct | 30 ms | 10180 KB | Output is correct |
6 | Correct | 29 ms | 10236 KB | Output is correct |
7 | Correct | 31 ms | 10276 KB | Output is correct |
8 | Correct | 31 ms | 10200 KB | Output is correct |
9 | Correct | 37 ms | 10172 KB | Output is correct |
10 | Correct | 31 ms | 10240 KB | Output is correct |
11 | Correct | 67 ms | 15316 KB | Output is correct |
12 | Correct | 62 ms | 15292 KB | Output is correct |
13 | Correct | 70 ms | 15272 KB | Output is correct |
14 | Correct | 55 ms | 15292 KB | Output is correct |
15 | Correct | 14 ms | 7628 KB | Output is correct |
16 | Correct | 14 ms | 7500 KB | Output is correct |
17 | Correct | 16 ms | 7548 KB | Output is correct |
18 | Correct | 19 ms | 7588 KB | Output is correct |
19 | Correct | 18 ms | 7564 KB | Output is correct |
20 | Correct | 16 ms | 7552 KB | Output is correct |
21 | Correct | 16 ms | 7604 KB | Output is correct |
22 | Correct | 16 ms | 7628 KB | Output is correct |
23 | Correct | 15 ms | 7636 KB | Output is correct |
24 | Correct | 62 ms | 16192 KB | Output is correct |
25 | Correct | 60 ms | 16148 KB | Output is correct |
26 | Correct | 58 ms | 16368 KB | Output is correct |
27 | Correct | 59 ms | 15948 KB | Output is correct |
28 | Correct | 60 ms | 16108 KB | Output is correct |
29 | Correct | 60 ms | 15884 KB | Output is correct |
30 | Correct | 18 ms | 8140 KB | Output is correct |
31 | Correct | 31 ms | 10180 KB | Output is correct |
32 | Correct | 61 ms | 14444 KB | Output is correct |
33 | Correct | 75 ms | 15440 KB | Output is correct |
34 | Correct | 7 ms | 6092 KB | Output is correct |
35 | Correct | 13 ms | 7044 KB | Output is correct |
36 | Correct | 31 ms | 10288 KB | Output is correct |
37 | Correct | 71 ms | 15404 KB | Output is correct |
38 | Correct | 60 ms | 15648 KB | Output is correct |
39 | Correct | 70 ms | 15556 KB | Output is correct |
40 | Correct | 55 ms | 16788 KB | Output is correct |
41 | Correct | 62 ms | 18188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 10140 KB | Output is correct |
2 | Correct | 10 ms | 6220 KB | Output is correct |
3 | Correct | 29 ms | 10204 KB | Output is correct |
4 | Correct | 12 ms | 6220 KB | Output is correct |
5 | Correct | 30 ms | 10180 KB | Output is correct |
6 | Correct | 29 ms | 10236 KB | Output is correct |
7 | Correct | 31 ms | 10276 KB | Output is correct |
8 | Correct | 31 ms | 10200 KB | Output is correct |
9 | Correct | 37 ms | 10172 KB | Output is correct |
10 | Correct | 31 ms | 10240 KB | Output is correct |
11 | Correct | 67 ms | 15316 KB | Output is correct |
12 | Correct | 62 ms | 15292 KB | Output is correct |
13 | Correct | 70 ms | 15272 KB | Output is correct |
14 | Correct | 55 ms | 15292 KB | Output is correct |
15 | Correct | 14 ms | 7628 KB | Output is correct |
16 | Correct | 14 ms | 7500 KB | Output is correct |
17 | Correct | 16 ms | 7548 KB | Output is correct |
18 | Correct | 19 ms | 7588 KB | Output is correct |
19 | Correct | 18 ms | 7564 KB | Output is correct |
20 | Correct | 16 ms | 7552 KB | Output is correct |
21 | Correct | 16 ms | 7604 KB | Output is correct |
22 | Correct | 16 ms | 7628 KB | Output is correct |
23 | Correct | 15 ms | 7636 KB | Output is correct |
24 | Correct | 62 ms | 16192 KB | Output is correct |
25 | Correct | 60 ms | 16148 KB | Output is correct |
26 | Correct | 58 ms | 16368 KB | Output is correct |
27 | Correct | 59 ms | 15948 KB | Output is correct |
28 | Correct | 60 ms | 16108 KB | Output is correct |
29 | Correct | 60 ms | 15884 KB | Output is correct |
30 | Correct | 18 ms | 8140 KB | Output is correct |
31 | Correct | 31 ms | 10180 KB | Output is correct |
32 | Correct | 61 ms | 14444 KB | Output is correct |
33 | Correct | 75 ms | 15440 KB | Output is correct |
34 | Correct | 7 ms | 6092 KB | Output is correct |
35 | Correct | 13 ms | 7044 KB | Output is correct |
36 | Correct | 31 ms | 10288 KB | Output is correct |
37 | Correct | 71 ms | 15404 KB | Output is correct |
38 | Correct | 60 ms | 15648 KB | Output is correct |
39 | Correct | 70 ms | 15556 KB | Output is correct |
40 | Correct | 55 ms | 16788 KB | Output is correct |
41 | Correct | 62 ms | 18188 KB | Output is correct |
42 | Incorrect | 29 ms | 10252 KB | Output isn't correct |
43 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4940 KB | Output is correct |
2 | Correct | 2 ms | 4940 KB | Output is correct |
3 | Correct | 2 ms | 4940 KB | Output is correct |
4 | Incorrect | 2 ms | 5012 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |