답안 #795299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795299 2023-07-27T08:14:17 Z RushB Watermelon (INOI20_watermelon) C++17
31 / 100
39 ms 12452 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 
#define int int64_t
const int64_t INF = 1ll << 60;
const int N = 1e5 + 5;
int b[N], in[N], nx[N], n, k, a[N];
vector<int> adj[N];

signed main() {
        ios::sync_with_stdio(0), cin.tie(0);
        cin >> n >> k;
        assert(k == 1);
        FOR(i, 0, n) {
                cin >> b[i];
                b[i] = (b[i] == -1 ? INF : b[i]);
        }
        vector<int> st;
        for (int i = n - 1; i >= 0; i--) {
                while (st.size() && b[st.back()] < b[i]) st.pop_back();
                if (st.size() && b[i] != INF) {
                        adj[i].push_back(st.back());
                        in[st.back()]++;
                }
                st.push_back(i);
        }
        for (int i = n - 1; i >= 0; i--) {
                if (b[i] == INF) {
                        FOR(j, i + 1, n) {
                                adj[j].push_back(i);
                                in[i]++;
                                if (b[j] == INF) 
                                        break;
                        }
                }
                else {
                        if (nx[b[i] - 1]) {
                                FOR(j, i + 1, nx[b[i] - 1] + 1) {
                                        adj[j].push_back(i);
                                        in[i]++;
                                }
                        }
                        else if (b[i] > 1) {
                                cout << -1;
                                return 0;
                        }
                        nx[b[i]] = i;
                }
        }
        /*
        FOR(i, 0, n) {
                for (auto u: adj[i])
                        cout << i << ' ' << u << endl;
                cout << endl;
        }
        */
        set<int> S;
        FOR(i, 0, n) 
                if (!in[i])
                        S.insert(i);
        FOR(i, 1, n + 1) {
                if (S.empty()) {
                        cout << -1;
                        return 0;
                }
                int x = *S.begin();
                a[x] = i;
                S.erase(S.begin());
                for (auto u: adj[x]) {
                        in[u]--;
                        if (!in[u])
                                S.insert(u);
                }
        }
        FOR(i, 0, n)
                cout << a[i] << ' ';
        cout << endl;
}
//11:28:05
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB Output is correct
2 Correct 1 ms 2688 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2684 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Runtime error 5 ms 5332 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB Output is correct
2 Correct 1 ms 2688 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2684 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Runtime error 5 ms 5332 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 7776 KB Output is correct
2 Correct 7 ms 5252 KB Output is correct
3 Correct 20 ms 7696 KB Output is correct
4 Correct 7 ms 5204 KB Output is correct
5 Correct 18 ms 7316 KB Output is correct
6 Correct 18 ms 7252 KB Output is correct
7 Correct 18 ms 7380 KB Output is correct
8 Correct 18 ms 7368 KB Output is correct
9 Correct 22 ms 7512 KB Output is correct
10 Correct 18 ms 7524 KB Output is correct
11 Correct 39 ms 12212 KB Output is correct
12 Correct 35 ms 12256 KB Output is correct
13 Correct 37 ms 12452 KB Output is correct
14 Correct 37 ms 12448 KB Output is correct
15 Correct 13 ms 7892 KB Output is correct
16 Correct 12 ms 7892 KB Output is correct
17 Correct 12 ms 7808 KB Output is correct
18 Correct 13 ms 7892 KB Output is correct
19 Correct 12 ms 7804 KB Output is correct
20 Correct 12 ms 7880 KB Output is correct
21 Correct 13 ms 7816 KB Output is correct
22 Correct 12 ms 7796 KB Output is correct
23 Correct 15 ms 7868 KB Output is correct
24 Correct 27 ms 10492 KB Output is correct
25 Correct 28 ms 10884 KB Output is correct
26 Correct 27 ms 10688 KB Output is correct
27 Correct 28 ms 10768 KB Output is correct
28 Correct 28 ms 11028 KB Output is correct
29 Correct 28 ms 10956 KB Output is correct
30 Correct 10 ms 4692 KB Output is correct
31 Correct 13 ms 5892 KB Output is correct
32 Correct 21 ms 8404 KB Output is correct
33 Correct 23 ms 9032 KB Output is correct
34 Correct 4 ms 3412 KB Output is correct
35 Correct 7 ms 4308 KB Output is correct
36 Correct 15 ms 6664 KB Output is correct
37 Correct 28 ms 10576 KB Output is correct
38 Correct 31 ms 10832 KB Output is correct
39 Correct 35 ms 10760 KB Output is correct
40 Correct 28 ms 11608 KB Output is correct
41 Correct 26 ms 10088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 7776 KB Output is correct
2 Correct 7 ms 5252 KB Output is correct
3 Correct 20 ms 7696 KB Output is correct
4 Correct 7 ms 5204 KB Output is correct
5 Correct 18 ms 7316 KB Output is correct
6 Correct 18 ms 7252 KB Output is correct
7 Correct 18 ms 7380 KB Output is correct
8 Correct 18 ms 7368 KB Output is correct
9 Correct 22 ms 7512 KB Output is correct
10 Correct 18 ms 7524 KB Output is correct
11 Correct 39 ms 12212 KB Output is correct
12 Correct 35 ms 12256 KB Output is correct
13 Correct 37 ms 12452 KB Output is correct
14 Correct 37 ms 12448 KB Output is correct
15 Correct 13 ms 7892 KB Output is correct
16 Correct 12 ms 7892 KB Output is correct
17 Correct 12 ms 7808 KB Output is correct
18 Correct 13 ms 7892 KB Output is correct
19 Correct 12 ms 7804 KB Output is correct
20 Correct 12 ms 7880 KB Output is correct
21 Correct 13 ms 7816 KB Output is correct
22 Correct 12 ms 7796 KB Output is correct
23 Correct 15 ms 7868 KB Output is correct
24 Correct 27 ms 10492 KB Output is correct
25 Correct 28 ms 10884 KB Output is correct
26 Correct 27 ms 10688 KB Output is correct
27 Correct 28 ms 10768 KB Output is correct
28 Correct 28 ms 11028 KB Output is correct
29 Correct 28 ms 10956 KB Output is correct
30 Correct 10 ms 4692 KB Output is correct
31 Correct 13 ms 5892 KB Output is correct
32 Correct 21 ms 8404 KB Output is correct
33 Correct 23 ms 9032 KB Output is correct
34 Correct 4 ms 3412 KB Output is correct
35 Correct 7 ms 4308 KB Output is correct
36 Correct 15 ms 6664 KB Output is correct
37 Correct 28 ms 10576 KB Output is correct
38 Correct 31 ms 10832 KB Output is correct
39 Correct 35 ms 10760 KB Output is correct
40 Correct 28 ms 11608 KB Output is correct
41 Correct 26 ms 10088 KB Output is correct
42 Runtime error 4 ms 5292 KB Execution killed with signal 6
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2676 KB Output is correct
2 Correct 1 ms 2688 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2684 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Runtime error 5 ms 5332 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -