Submission #635366

# Submission time Handle Problem Language Result Execution time Memory
635366 2022-08-26T07:02:41 Z S2speed Watermelon (INOI20_watermelon) C++17
100 / 100
768 ms 23576 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

#define sze(x) (int)(x.size())
typedef long long ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;

const ll maxn = 1e5 + 17 , inf = 2e8;

ll a[maxn] , p[maxn] , b[maxn] , d[maxn] , f[maxn] , ans[maxn];
vector<ll> adj[maxn] , jda[maxn] , v;
set<pll> s;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	ll n , k;
	cin>>n>>k;
	for(ll i = 0 ; i < n ; i++){
		cin>>a[i];
	}
	if(a[n - 1] != -1){
		cout<<"-1\n";
		return 0;
	}
	ll o = n + 1;
	for(ll i = n - 1 ; ~i ; i--){
		if(a[i] == -1){
			a[i] = o++;
		}
	}
	for(ll i = n - 1 ; ~i ; i--){
		ll h = 0;
		while(!v.empty()){
			ll j = v.back();
			if(a[j] >= a[i]) break;
			adj[i].push_back(j); jda[j].push_back(i);
			d[i]++;
			h = a[j];
			v.pop_back();
		}
		if(!v.empty()){
			if(h != a[i] - 1){
				cout<<"-1\n";
				return 0;
			}
			adj[v.back()].push_back(i); jda[i].push_back(v.back());
			d[v.back()]++;
			if(a[v.back()] == a[i]) v.pop_back();
		}
		v.push_back(i);
	}
	for(ll e = 0 ; e < k ; e++){
		if(b[0] == -1){
			cout<<"-1\n";
			return 0;
		}
		memcpy(f , d , sizeof(f));
		for(ll i = 0 ; i < n ; i++){
			s.insert({f[i] , i});
		}
		ll ind = -1;
		for(ll i = 0 ; i < n ; i++){
			auto it = s.begin();
			if((*it).first != 0){
				cout<<"-1\n";
				return 0;
			}
			ll h = b[i];
			while(h--){
				it++;
			}
			p[i] = (*it).second;
			it++;
			if(it != s.end()){
				if((*it).first == 0){
					ind = i;
				}
			}
			s.erase(--it);
			ll v = p[i];
			for(auto j : jda[v]){
				s.erase({f[j] , j});
				s.insert({--f[j] , j});
			}
		}
		if(ind == -1){
			b[0] = -1;
		} else {
			b[ind]++;
			for(ll j = ind + 1 ; j < n ; j++) b[j] = 0;
		}
	}
	for(ll i = 0 ; i < n ; i++){
		ans[p[i]] = i + 1;
//		cout<<p[i]<<' ';
	}
//	cout<<'\n';
	for(ll i = 0 ; i < n ; i++){
		cout<<ans[i]<<' ';
	}
	cout<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5792 KB Output is correct
14 Correct 3 ms 5716 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5844 KB Output is correct
17 Correct 3 ms 5716 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 5028 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 4 ms 5796 KB Output is correct
26 Correct 4 ms 5716 KB Output is correct
27 Correct 4 ms 5716 KB Output is correct
28 Correct 3 ms 5716 KB Output is correct
29 Correct 4 ms 5716 KB Output is correct
30 Correct 3 ms 5716 KB Output is correct
31 Correct 3 ms 5812 KB Output is correct
32 Correct 3 ms 5716 KB Output is correct
33 Correct 4 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5792 KB Output is correct
14 Correct 3 ms 5716 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5844 KB Output is correct
17 Correct 3 ms 5716 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 5028 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 4 ms 5796 KB Output is correct
26 Correct 4 ms 5716 KB Output is correct
27 Correct 4 ms 5716 KB Output is correct
28 Correct 3 ms 5716 KB Output is correct
29 Correct 4 ms 5716 KB Output is correct
30 Correct 3 ms 5716 KB Output is correct
31 Correct 3 ms 5812 KB Output is correct
32 Correct 3 ms 5716 KB Output is correct
33 Correct 4 ms 5716 KB Output is correct
34 Correct 7 ms 6100 KB Output is correct
35 Correct 7 ms 6056 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 5036 KB Output is correct
38 Correct 8 ms 6100 KB Output is correct
39 Correct 10 ms 6112 KB Output is correct
40 Correct 12 ms 6100 KB Output is correct
41 Correct 10 ms 6100 KB Output is correct
42 Correct 13 ms 6100 KB Output is correct
43 Correct 12 ms 6048 KB Output is correct
44 Correct 9 ms 6184 KB Output is correct
45 Correct 4 ms 6100 KB Output is correct
46 Correct 10 ms 6188 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5036 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 5028 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 9 ms 6160 KB Output is correct
54 Correct 10 ms 6048 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 5032 KB Output is correct
57 Correct 12 ms 6100 KB Output is correct
58 Correct 12 ms 6128 KB Output is correct
59 Correct 8 ms 6100 KB Output is correct
60 Correct 10 ms 6152 KB Output is correct
61 Correct 11 ms 6164 KB Output is correct
62 Correct 9 ms 6160 KB Output is correct
63 Correct 5 ms 6180 KB Output is correct
64 Correct 5 ms 5972 KB Output is correct
65 Correct 10 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 13744 KB Output is correct
2 Correct 6 ms 5588 KB Output is correct
3 Correct 46 ms 13900 KB Output is correct
4 Correct 6 ms 5664 KB Output is correct
5 Correct 47 ms 13912 KB Output is correct
6 Correct 54 ms 13852 KB Output is correct
7 Correct 52 ms 13824 KB Output is correct
8 Correct 46 ms 13800 KB Output is correct
9 Correct 47 ms 13856 KB Output is correct
10 Correct 51 ms 14020 KB Output is correct
11 Correct 95 ms 21944 KB Output is correct
12 Correct 98 ms 21916 KB Output is correct
13 Correct 101 ms 22028 KB Output is correct
14 Correct 103 ms 21948 KB Output is correct
15 Correct 13 ms 6304 KB Output is correct
16 Correct 10 ms 6356 KB Output is correct
17 Correct 9 ms 6356 KB Output is correct
18 Correct 10 ms 6292 KB Output is correct
19 Correct 11 ms 6300 KB Output is correct
20 Correct 9 ms 6312 KB Output is correct
21 Correct 11 ms 6324 KB Output is correct
22 Correct 9 ms 6356 KB Output is correct
23 Correct 10 ms 6308 KB Output is correct
24 Correct 89 ms 23356 KB Output is correct
25 Correct 100 ms 23408 KB Output is correct
26 Correct 93 ms 23324 KB Output is correct
27 Correct 92 ms 23384 KB Output is correct
28 Correct 103 ms 23292 KB Output is correct
29 Correct 94 ms 23316 KB Output is correct
30 Correct 23 ms 11092 KB Output is correct
31 Correct 38 ms 14668 KB Output is correct
32 Correct 69 ms 21692 KB Output is correct
33 Correct 76 ms 23452 KB Output is correct
34 Correct 9 ms 7508 KB Output is correct
35 Correct 19 ms 9296 KB Output is correct
36 Correct 38 ms 14628 KB Output is correct
37 Correct 85 ms 23348 KB Output is correct
38 Correct 89 ms 22968 KB Output is correct
39 Correct 77 ms 23424 KB Output is correct
40 Correct 100 ms 21844 KB Output is correct
41 Correct 89 ms 23576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 13744 KB Output is correct
2 Correct 6 ms 5588 KB Output is correct
3 Correct 46 ms 13900 KB Output is correct
4 Correct 6 ms 5664 KB Output is correct
5 Correct 47 ms 13912 KB Output is correct
6 Correct 54 ms 13852 KB Output is correct
7 Correct 52 ms 13824 KB Output is correct
8 Correct 46 ms 13800 KB Output is correct
9 Correct 47 ms 13856 KB Output is correct
10 Correct 51 ms 14020 KB Output is correct
11 Correct 95 ms 21944 KB Output is correct
12 Correct 98 ms 21916 KB Output is correct
13 Correct 101 ms 22028 KB Output is correct
14 Correct 103 ms 21948 KB Output is correct
15 Correct 13 ms 6304 KB Output is correct
16 Correct 10 ms 6356 KB Output is correct
17 Correct 9 ms 6356 KB Output is correct
18 Correct 10 ms 6292 KB Output is correct
19 Correct 11 ms 6300 KB Output is correct
20 Correct 9 ms 6312 KB Output is correct
21 Correct 11 ms 6324 KB Output is correct
22 Correct 9 ms 6356 KB Output is correct
23 Correct 10 ms 6308 KB Output is correct
24 Correct 89 ms 23356 KB Output is correct
25 Correct 100 ms 23408 KB Output is correct
26 Correct 93 ms 23324 KB Output is correct
27 Correct 92 ms 23384 KB Output is correct
28 Correct 103 ms 23292 KB Output is correct
29 Correct 94 ms 23316 KB Output is correct
30 Correct 23 ms 11092 KB Output is correct
31 Correct 38 ms 14668 KB Output is correct
32 Correct 69 ms 21692 KB Output is correct
33 Correct 76 ms 23452 KB Output is correct
34 Correct 9 ms 7508 KB Output is correct
35 Correct 19 ms 9296 KB Output is correct
36 Correct 38 ms 14628 KB Output is correct
37 Correct 85 ms 23348 KB Output is correct
38 Correct 89 ms 22968 KB Output is correct
39 Correct 77 ms 23424 KB Output is correct
40 Correct 100 ms 21844 KB Output is correct
41 Correct 89 ms 23576 KB Output is correct
42 Correct 80 ms 13880 KB Output is correct
43 Correct 6 ms 5568 KB Output is correct
44 Correct 74 ms 13828 KB Output is correct
45 Correct 7 ms 5676 KB Output is correct
46 Correct 9 ms 5696 KB Output is correct
47 Correct 6 ms 5588 KB Output is correct
48 Correct 8 ms 5612 KB Output is correct
49 Correct 84 ms 13900 KB Output is correct
50 Correct 77 ms 13844 KB Output is correct
51 Correct 83 ms 13872 KB Output is correct
52 Correct 173 ms 22020 KB Output is correct
53 Correct 171 ms 21920 KB Output is correct
54 Correct 10 ms 6324 KB Output is correct
55 Correct 14 ms 6308 KB Output is correct
56 Correct 108 ms 21708 KB Output is correct
57 Correct 117 ms 23460 KB Output is correct
58 Correct 120 ms 23440 KB Output is correct
59 Correct 150 ms 23096 KB Output is correct
60 Correct 111 ms 23400 KB Output is correct
61 Correct 158 ms 21844 KB Output is correct
62 Correct 76 ms 21992 KB Output is correct
63 Correct 138 ms 23328 KB Output is correct
64 Correct 153 ms 23408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 5036 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5792 KB Output is correct
14 Correct 3 ms 5716 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5844 KB Output is correct
17 Correct 3 ms 5716 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 5032 KB Output is correct
21 Correct 3 ms 5028 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5032 KB Output is correct
25 Correct 4 ms 5796 KB Output is correct
26 Correct 4 ms 5716 KB Output is correct
27 Correct 4 ms 5716 KB Output is correct
28 Correct 3 ms 5716 KB Output is correct
29 Correct 4 ms 5716 KB Output is correct
30 Correct 3 ms 5716 KB Output is correct
31 Correct 3 ms 5812 KB Output is correct
32 Correct 3 ms 5716 KB Output is correct
33 Correct 4 ms 5716 KB Output is correct
34 Correct 7 ms 6100 KB Output is correct
35 Correct 7 ms 6056 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 5036 KB Output is correct
38 Correct 8 ms 6100 KB Output is correct
39 Correct 10 ms 6112 KB Output is correct
40 Correct 12 ms 6100 KB Output is correct
41 Correct 10 ms 6100 KB Output is correct
42 Correct 13 ms 6100 KB Output is correct
43 Correct 12 ms 6048 KB Output is correct
44 Correct 9 ms 6184 KB Output is correct
45 Correct 4 ms 6100 KB Output is correct
46 Correct 10 ms 6188 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5036 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 5028 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 9 ms 6160 KB Output is correct
54 Correct 10 ms 6048 KB Output is correct
55 Correct 3 ms 4948 KB Output is correct
56 Correct 3 ms 5032 KB Output is correct
57 Correct 12 ms 6100 KB Output is correct
58 Correct 12 ms 6128 KB Output is correct
59 Correct 8 ms 6100 KB Output is correct
60 Correct 10 ms 6152 KB Output is correct
61 Correct 11 ms 6164 KB Output is correct
62 Correct 9 ms 6160 KB Output is correct
63 Correct 5 ms 6180 KB Output is correct
64 Correct 5 ms 5972 KB Output is correct
65 Correct 10 ms 6100 KB Output is correct
66 Correct 48 ms 13744 KB Output is correct
67 Correct 6 ms 5588 KB Output is correct
68 Correct 46 ms 13900 KB Output is correct
69 Correct 6 ms 5664 KB Output is correct
70 Correct 47 ms 13912 KB Output is correct
71 Correct 54 ms 13852 KB Output is correct
72 Correct 52 ms 13824 KB Output is correct
73 Correct 46 ms 13800 KB Output is correct
74 Correct 47 ms 13856 KB Output is correct
75 Correct 51 ms 14020 KB Output is correct
76 Correct 95 ms 21944 KB Output is correct
77 Correct 98 ms 21916 KB Output is correct
78 Correct 101 ms 22028 KB Output is correct
79 Correct 103 ms 21948 KB Output is correct
80 Correct 13 ms 6304 KB Output is correct
81 Correct 10 ms 6356 KB Output is correct
82 Correct 9 ms 6356 KB Output is correct
83 Correct 10 ms 6292 KB Output is correct
84 Correct 11 ms 6300 KB Output is correct
85 Correct 9 ms 6312 KB Output is correct
86 Correct 11 ms 6324 KB Output is correct
87 Correct 9 ms 6356 KB Output is correct
88 Correct 10 ms 6308 KB Output is correct
89 Correct 89 ms 23356 KB Output is correct
90 Correct 100 ms 23408 KB Output is correct
91 Correct 93 ms 23324 KB Output is correct
92 Correct 92 ms 23384 KB Output is correct
93 Correct 103 ms 23292 KB Output is correct
94 Correct 94 ms 23316 KB Output is correct
95 Correct 23 ms 11092 KB Output is correct
96 Correct 38 ms 14668 KB Output is correct
97 Correct 69 ms 21692 KB Output is correct
98 Correct 76 ms 23452 KB Output is correct
99 Correct 9 ms 7508 KB Output is correct
100 Correct 19 ms 9296 KB Output is correct
101 Correct 38 ms 14628 KB Output is correct
102 Correct 85 ms 23348 KB Output is correct
103 Correct 89 ms 22968 KB Output is correct
104 Correct 77 ms 23424 KB Output is correct
105 Correct 100 ms 21844 KB Output is correct
106 Correct 89 ms 23576 KB Output is correct
107 Correct 80 ms 13880 KB Output is correct
108 Correct 6 ms 5568 KB Output is correct
109 Correct 74 ms 13828 KB Output is correct
110 Correct 7 ms 5676 KB Output is correct
111 Correct 9 ms 5696 KB Output is correct
112 Correct 6 ms 5588 KB Output is correct
113 Correct 8 ms 5612 KB Output is correct
114 Correct 84 ms 13900 KB Output is correct
115 Correct 77 ms 13844 KB Output is correct
116 Correct 83 ms 13872 KB Output is correct
117 Correct 173 ms 22020 KB Output is correct
118 Correct 171 ms 21920 KB Output is correct
119 Correct 10 ms 6324 KB Output is correct
120 Correct 14 ms 6308 KB Output is correct
121 Correct 108 ms 21708 KB Output is correct
122 Correct 117 ms 23460 KB Output is correct
123 Correct 120 ms 23440 KB Output is correct
124 Correct 150 ms 23096 KB Output is correct
125 Correct 111 ms 23400 KB Output is correct
126 Correct 158 ms 21844 KB Output is correct
127 Correct 76 ms 21992 KB Output is correct
128 Correct 138 ms 23328 KB Output is correct
129 Correct 153 ms 23408 KB Output is correct
130 Correct 3 ms 5796 KB Output is correct
131 Correct 4 ms 5716 KB Output is correct
132 Correct 3 ms 5716 KB Output is correct
133 Correct 393 ms 21936 KB Output is correct
134 Correct 605 ms 21948 KB Output is correct
135 Correct 662 ms 22056 KB Output is correct
136 Correct 11 ms 6356 KB Output is correct
137 Correct 15 ms 6356 KB Output is correct
138 Correct 13 ms 6372 KB Output is correct
139 Correct 10 ms 6356 KB Output is correct
140 Correct 10 ms 6332 KB Output is correct
141 Correct 12 ms 6332 KB Output is correct
142 Correct 768 ms 21932 KB Output is correct
143 Correct 751 ms 22068 KB Output is correct
144 Correct 483 ms 23396 KB Output is correct
145 Correct 410 ms 21660 KB Output is correct
146 Correct 485 ms 23364 KB Output is correct
147 Correct 653 ms 23104 KB Output is correct
148 Correct 604 ms 21804 KB Output is correct
149 Correct 719 ms 21800 KB Output is correct
150 Correct 394 ms 21848 KB Output is correct
151 Correct 252 ms 23392 KB Output is correct
152 Correct 435 ms 23424 KB Output is correct
153 Correct 100 ms 23496 KB Output is correct
154 Correct 114 ms 23416 KB Output is correct
155 Correct 82 ms 23336 KB Output is correct
156 Correct 98 ms 23364 KB Output is correct
157 Correct 95 ms 23312 KB Output is correct
158 Correct 90 ms 23368 KB Output is correct
159 Correct 93 ms 23432 KB Output is correct
160 Correct 93 ms 23384 KB Output is correct