Submission #627039

# Submission time Handle Problem Language Result Execution time Memory
627039 2022-08-12T05:25:44 Z AA_Surely Watermelon (INOI20_watermelon) C++14
31 / 100
22 ms 3816 KB
#include <bits/stdc++.h>

#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)

#define WTF cout << "WTF" << endl

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

using namespace std;

typedef long long LL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;

const int N = 1e5 + 7;
const int LOG = 22;
const int INF = 1e9 + 7;

int n, k;
int ns[N], ans[N], adj[N];
int lst[N], pl[N], big[N];
PII st[N];

int main() {
    IOS;

    cin >> n >> k;
    F0R(i, n) cin >> ns[i];

    if (ns[n - 1] != -1) return cout << -1, 0;
    F0R(i, n) if (ns[i] == -1) ns[i] = n + 1;
    
    fill(pl, pl + n + 2, n + 1);
    fill(adj, adj + n, -1);
    R0F(i, n) {
        pl[ ns[i] ] = i;
        if (ns[i] == n + 1) continue;

        if (ns[i] == 1) lst[i] = i;
        else {
            lst[i] = pl[ ns[i] - 1 ];
            adj[ pl[ ns[i] - 1 ] ] = i;
        }
    }

    stack<int> keep;
    R0F(i, n) {
        while(!keep.empty() && ns[keep.top()] < ns[i]) keep.pop();
        big[i] = n + 1;
        if (!keep.empty()) big[i] = keep.top();

        keep.push(i);
    }

    F0R(i, n) if (ns[i] != 1 && ns[i] != n + 1)
        if (lst[i] > big[i]) return cout << -1, 0;
    
    int v = 1;
    F0R(i, n) if (ns[i] == 1) {
        int now = i;
        while(now != -1) {
            ans[now] = v++;
            now = adj[now];
        }
    }
    R0F(i, n) if (ns[i] == n + 1) ans[i] = v++;

    F0R(i, n) cout << ans[i] << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1732 KB Output is correct
2 Correct 5 ms 1480 KB Output is correct
3 Correct 8 ms 1876 KB Output is correct
4 Correct 6 ms 1484 KB Output is correct
5 Correct 11 ms 1904 KB Output is correct
6 Correct 8 ms 1876 KB Output is correct
7 Correct 10 ms 1896 KB Output is correct
8 Correct 9 ms 1844 KB Output is correct
9 Correct 8 ms 1848 KB Output is correct
10 Correct 8 ms 1908 KB Output is correct
11 Correct 22 ms 3412 KB Output is correct
12 Correct 20 ms 3412 KB Output is correct
13 Correct 17 ms 3456 KB Output is correct
14 Correct 16 ms 3448 KB Output is correct
15 Correct 10 ms 2772 KB Output is correct
16 Correct 12 ms 2820 KB Output is correct
17 Correct 22 ms 2816 KB Output is correct
18 Correct 12 ms 2772 KB Output is correct
19 Correct 12 ms 2772 KB Output is correct
20 Correct 11 ms 2760 KB Output is correct
21 Correct 11 ms 2760 KB Output is correct
22 Correct 13 ms 2736 KB Output is correct
23 Correct 10 ms 2772 KB Output is correct
24 Correct 18 ms 3688 KB Output is correct
25 Correct 16 ms 3672 KB Output is correct
26 Correct 21 ms 3796 KB Output is correct
27 Correct 17 ms 3688 KB Output is correct
28 Correct 17 ms 3668 KB Output is correct
29 Correct 16 ms 3648 KB Output is correct
30 Correct 5 ms 1236 KB Output is correct
31 Correct 8 ms 1884 KB Output is correct
32 Correct 14 ms 3304 KB Output is correct
33 Correct 19 ms 3540 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 4 ms 1108 KB Output is correct
36 Correct 8 ms 2004 KB Output is correct
37 Correct 15 ms 3528 KB Output is correct
38 Correct 15 ms 3540 KB Output is correct
39 Correct 17 ms 3644 KB Output is correct
40 Correct 15 ms 3676 KB Output is correct
41 Correct 17 ms 3816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1732 KB Output is correct
2 Correct 5 ms 1480 KB Output is correct
3 Correct 8 ms 1876 KB Output is correct
4 Correct 6 ms 1484 KB Output is correct
5 Correct 11 ms 1904 KB Output is correct
6 Correct 8 ms 1876 KB Output is correct
7 Correct 10 ms 1896 KB Output is correct
8 Correct 9 ms 1844 KB Output is correct
9 Correct 8 ms 1848 KB Output is correct
10 Correct 8 ms 1908 KB Output is correct
11 Correct 22 ms 3412 KB Output is correct
12 Correct 20 ms 3412 KB Output is correct
13 Correct 17 ms 3456 KB Output is correct
14 Correct 16 ms 3448 KB Output is correct
15 Correct 10 ms 2772 KB Output is correct
16 Correct 12 ms 2820 KB Output is correct
17 Correct 22 ms 2816 KB Output is correct
18 Correct 12 ms 2772 KB Output is correct
19 Correct 12 ms 2772 KB Output is correct
20 Correct 11 ms 2760 KB Output is correct
21 Correct 11 ms 2760 KB Output is correct
22 Correct 13 ms 2736 KB Output is correct
23 Correct 10 ms 2772 KB Output is correct
24 Correct 18 ms 3688 KB Output is correct
25 Correct 16 ms 3672 KB Output is correct
26 Correct 21 ms 3796 KB Output is correct
27 Correct 17 ms 3688 KB Output is correct
28 Correct 17 ms 3668 KB Output is correct
29 Correct 16 ms 3648 KB Output is correct
30 Correct 5 ms 1236 KB Output is correct
31 Correct 8 ms 1884 KB Output is correct
32 Correct 14 ms 3304 KB Output is correct
33 Correct 19 ms 3540 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 4 ms 1108 KB Output is correct
36 Correct 8 ms 2004 KB Output is correct
37 Correct 15 ms 3528 KB Output is correct
38 Correct 15 ms 3540 KB Output is correct
39 Correct 17 ms 3644 KB Output is correct
40 Correct 15 ms 3676 KB Output is correct
41 Correct 17 ms 3816 KB Output is correct
42 Incorrect 8 ms 1884 KB Output isn't correct
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Halted 0 ms 0 KB -