Submission #1038601

# Submission time Handle Problem Language Result Execution time Memory
1038601 2024-07-30T03:20:26 Z PM1 Watermelon (INOI20_watermelon) C++17
100 / 100
91 ms 38684 KB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define ll long long
const int mxn=1e5+5,szz=(1<<20);
int n,a[mxn],b[mxn],k,L[mxn],R[mxn],sz[mxn],mx[mxn];
vector<int>g[mxn],par[mxn];
set<int>s;
void solve(int m){
	if(s.size()==0 && m<n+1){
		cout<<-1;
		exit(0);
	}
	if(m==n+1){
		k--;
		if(k==0){
			for(int i=1;i<=n;i++)
				cout<<a[i]<<" ";
			cout<<'\n';
			exit(0);	
		}
		return ;
	}
	vector<int>v;
	for(auto i:s){
		v.push_back(i);
		if(v.size()==10)
			break;
	}
	for(auto i:v){
		a[i]=m;
		s.erase(i);
		for(auto j:par[i]){
			sz[j]--;
			if(sz[j]==0)
				s.insert(j);
		}
	
		solve(m+1);

		s.insert(i);
		for(auto j:par[i]){
			sz[j]++;
			if(sz[j]==1)
				s.erase(j);
		}
	}

}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	int cnt=0;
	vector<int>hey;
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	if(b[n]!=-1){
		cout<<-1;
		return 0;
	}
	for(int i=n;i>=1;i--){
		if(b[i]==-1){
			b[i]=n+cnt;
			cnt++;
		}
	}
	vector<int>v;
	for(int i=1;i<=n;i++){
		while(v.size() && b[v.back()]<b[i]){
			v.pop_back();
		}
		if(v.size())
			L[i]=v.back();
		v.push_back(i);
	}
	v.clear();
	for(int i=n;i>=1;i--){
		while(v.size() && b[v.back()]<b[i]){
			v.pop_back();
		}
		if(v.size())
			R[i]=v.back();
		v.push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(L[i]!=0 && b[L[i]]>b[i]){
			par[i].push_back(L[i]);
			g[L[i]].push_back(i);
			mx[L[i]]=max(mx[L[i]],b[i]);
		}
		if(R[i]!=0){
			par[i].push_back(R[i]);
			g[R[i]].push_back(i);
		}
	}
	for(int i=1;i<=n;i++){
	//	cout<<L[i]<<" "<<R[i]<<'\n';
		if(b[i]<n && mx[i]+1!=b[i]){
			cout<<-1;
			return 0;
		}
	}
	for(int i=1;i<=n;i++){
		sz[i]=g[i].size();
		if(sz[i]==0)
			s.insert(i);
	}
	solve(1);
	cout<<-1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 5164 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 5032 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 4 ms 5316 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4952 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 5164 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 5032 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 4 ms 5316 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4952 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 3 ms 5724 KB Output is correct
35 Correct 3 ms 5724 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 2 ms 5268 KB Output is correct
38 Correct 3 ms 5724 KB Output is correct
39 Correct 3 ms 5648 KB Output is correct
40 Correct 3 ms 5724 KB Output is correct
41 Correct 4 ms 5724 KB Output is correct
42 Correct 4 ms 5724 KB Output is correct
43 Correct 4 ms 5724 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 3 ms 5724 KB Output is correct
46 Correct 3 ms 5644 KB Output is correct
47 Correct 3 ms 5164 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 2 ms 5212 KB Output is correct
53 Correct 3 ms 5724 KB Output is correct
54 Correct 3 ms 5724 KB Output is correct
55 Correct 2 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 4 ms 5724 KB Output is correct
58 Correct 3 ms 5724 KB Output is correct
59 Correct 4 ms 5724 KB Output is correct
60 Correct 3 ms 5720 KB Output is correct
61 Correct 3 ms 5724 KB Output is correct
62 Correct 3 ms 5724 KB Output is correct
63 Correct 3 ms 5724 KB Output is correct
64 Correct 3 ms 5468 KB Output is correct
65 Correct 3 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 21084 KB Output is correct
2 Correct 11 ms 8796 KB Output is correct
3 Correct 29 ms 20980 KB Output is correct
4 Correct 12 ms 8772 KB Output is correct
5 Correct 29 ms 21140 KB Output is correct
6 Correct 37 ms 21072 KB Output is correct
7 Correct 30 ms 21056 KB Output is correct
8 Correct 30 ms 21152 KB Output is correct
9 Correct 29 ms 20996 KB Output is correct
10 Correct 30 ms 21072 KB Output is correct
11 Correct 59 ms 36944 KB Output is correct
12 Correct 58 ms 37204 KB Output is correct
13 Correct 59 ms 37204 KB Output is correct
14 Correct 58 ms 37060 KB Output is correct
15 Correct 23 ms 12636 KB Output is correct
16 Correct 22 ms 12668 KB Output is correct
17 Correct 26 ms 12568 KB Output is correct
18 Correct 21 ms 12636 KB Output is correct
19 Correct 21 ms 12636 KB Output is correct
20 Correct 22 ms 12628 KB Output is correct
21 Correct 22 ms 12636 KB Output is correct
22 Correct 21 ms 12688 KB Output is correct
23 Correct 22 ms 12632 KB Output is correct
24 Correct 46 ms 35584 KB Output is correct
25 Correct 45 ms 35560 KB Output is correct
26 Correct 47 ms 36436 KB Output is correct
27 Correct 47 ms 36688 KB Output is correct
28 Correct 48 ms 36432 KB Output is correct
29 Correct 45 ms 35412 KB Output is correct
30 Correct 16 ms 15192 KB Output is correct
31 Correct 26 ms 21892 KB Output is correct
32 Correct 60 ms 35196 KB Output is correct
33 Correct 49 ms 38484 KB Output is correct
34 Correct 6 ms 8028 KB Output is correct
35 Correct 11 ms 11612 KB Output is correct
36 Correct 25 ms 21588 KB Output is correct
37 Correct 50 ms 38480 KB Output is correct
38 Correct 52 ms 37724 KB Output is correct
39 Correct 55 ms 38480 KB Output is correct
40 Correct 49 ms 34264 KB Output is correct
41 Correct 39 ms 34256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 21084 KB Output is correct
2 Correct 11 ms 8796 KB Output is correct
3 Correct 29 ms 20980 KB Output is correct
4 Correct 12 ms 8772 KB Output is correct
5 Correct 29 ms 21140 KB Output is correct
6 Correct 37 ms 21072 KB Output is correct
7 Correct 30 ms 21056 KB Output is correct
8 Correct 30 ms 21152 KB Output is correct
9 Correct 29 ms 20996 KB Output is correct
10 Correct 30 ms 21072 KB Output is correct
11 Correct 59 ms 36944 KB Output is correct
12 Correct 58 ms 37204 KB Output is correct
13 Correct 59 ms 37204 KB Output is correct
14 Correct 58 ms 37060 KB Output is correct
15 Correct 23 ms 12636 KB Output is correct
16 Correct 22 ms 12668 KB Output is correct
17 Correct 26 ms 12568 KB Output is correct
18 Correct 21 ms 12636 KB Output is correct
19 Correct 21 ms 12636 KB Output is correct
20 Correct 22 ms 12628 KB Output is correct
21 Correct 22 ms 12636 KB Output is correct
22 Correct 21 ms 12688 KB Output is correct
23 Correct 22 ms 12632 KB Output is correct
24 Correct 46 ms 35584 KB Output is correct
25 Correct 45 ms 35560 KB Output is correct
26 Correct 47 ms 36436 KB Output is correct
27 Correct 47 ms 36688 KB Output is correct
28 Correct 48 ms 36432 KB Output is correct
29 Correct 45 ms 35412 KB Output is correct
30 Correct 16 ms 15192 KB Output is correct
31 Correct 26 ms 21892 KB Output is correct
32 Correct 60 ms 35196 KB Output is correct
33 Correct 49 ms 38484 KB Output is correct
34 Correct 6 ms 8028 KB Output is correct
35 Correct 11 ms 11612 KB Output is correct
36 Correct 25 ms 21588 KB Output is correct
37 Correct 50 ms 38480 KB Output is correct
38 Correct 52 ms 37724 KB Output is correct
39 Correct 55 ms 38480 KB Output is correct
40 Correct 49 ms 34264 KB Output is correct
41 Correct 39 ms 34256 KB Output is correct
42 Correct 32 ms 21072 KB Output is correct
43 Correct 12 ms 8792 KB Output is correct
44 Correct 33 ms 21084 KB Output is correct
45 Correct 12 ms 8796 KB Output is correct
46 Correct 13 ms 8792 KB Output is correct
47 Correct 12 ms 8796 KB Output is correct
48 Correct 11 ms 8796 KB Output is correct
49 Correct 30 ms 20936 KB Output is correct
50 Correct 30 ms 21072 KB Output is correct
51 Correct 31 ms 21084 KB Output is correct
52 Correct 60 ms 36944 KB Output is correct
53 Correct 60 ms 37092 KB Output is correct
54 Correct 21 ms 12628 KB Output is correct
55 Correct 21 ms 12636 KB Output is correct
56 Correct 44 ms 35152 KB Output is correct
57 Correct 49 ms 38684 KB Output is correct
58 Correct 49 ms 38480 KB Output is correct
59 Correct 53 ms 37716 KB Output is correct
60 Correct 48 ms 38384 KB Output is correct
61 Correct 65 ms 34264 KB Output is correct
62 Correct 41 ms 33744 KB Output is correct
63 Correct 50 ms 35664 KB Output is correct
64 Correct 47 ms 34984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 5164 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 5032 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 4 ms 5316 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4952 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 3 ms 5724 KB Output is correct
35 Correct 3 ms 5724 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 2 ms 5268 KB Output is correct
38 Correct 3 ms 5724 KB Output is correct
39 Correct 3 ms 5648 KB Output is correct
40 Correct 3 ms 5724 KB Output is correct
41 Correct 4 ms 5724 KB Output is correct
42 Correct 4 ms 5724 KB Output is correct
43 Correct 4 ms 5724 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 3 ms 5724 KB Output is correct
46 Correct 3 ms 5644 KB Output is correct
47 Correct 3 ms 5164 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 2 ms 5212 KB Output is correct
52 Correct 2 ms 5212 KB Output is correct
53 Correct 3 ms 5724 KB Output is correct
54 Correct 3 ms 5724 KB Output is correct
55 Correct 2 ms 5212 KB Output is correct
56 Correct 2 ms 5212 KB Output is correct
57 Correct 4 ms 5724 KB Output is correct
58 Correct 3 ms 5724 KB Output is correct
59 Correct 4 ms 5724 KB Output is correct
60 Correct 3 ms 5720 KB Output is correct
61 Correct 3 ms 5724 KB Output is correct
62 Correct 3 ms 5724 KB Output is correct
63 Correct 3 ms 5724 KB Output is correct
64 Correct 3 ms 5468 KB Output is correct
65 Correct 3 ms 5468 KB Output is correct
66 Correct 30 ms 21084 KB Output is correct
67 Correct 11 ms 8796 KB Output is correct
68 Correct 29 ms 20980 KB Output is correct
69 Correct 12 ms 8772 KB Output is correct
70 Correct 29 ms 21140 KB Output is correct
71 Correct 37 ms 21072 KB Output is correct
72 Correct 30 ms 21056 KB Output is correct
73 Correct 30 ms 21152 KB Output is correct
74 Correct 29 ms 20996 KB Output is correct
75 Correct 30 ms 21072 KB Output is correct
76 Correct 59 ms 36944 KB Output is correct
77 Correct 58 ms 37204 KB Output is correct
78 Correct 59 ms 37204 KB Output is correct
79 Correct 58 ms 37060 KB Output is correct
80 Correct 23 ms 12636 KB Output is correct
81 Correct 22 ms 12668 KB Output is correct
82 Correct 26 ms 12568 KB Output is correct
83 Correct 21 ms 12636 KB Output is correct
84 Correct 21 ms 12636 KB Output is correct
85 Correct 22 ms 12628 KB Output is correct
86 Correct 22 ms 12636 KB Output is correct
87 Correct 21 ms 12688 KB Output is correct
88 Correct 22 ms 12632 KB Output is correct
89 Correct 46 ms 35584 KB Output is correct
90 Correct 45 ms 35560 KB Output is correct
91 Correct 47 ms 36436 KB Output is correct
92 Correct 47 ms 36688 KB Output is correct
93 Correct 48 ms 36432 KB Output is correct
94 Correct 45 ms 35412 KB Output is correct
95 Correct 16 ms 15192 KB Output is correct
96 Correct 26 ms 21892 KB Output is correct
97 Correct 60 ms 35196 KB Output is correct
98 Correct 49 ms 38484 KB Output is correct
99 Correct 6 ms 8028 KB Output is correct
100 Correct 11 ms 11612 KB Output is correct
101 Correct 25 ms 21588 KB Output is correct
102 Correct 50 ms 38480 KB Output is correct
103 Correct 52 ms 37724 KB Output is correct
104 Correct 55 ms 38480 KB Output is correct
105 Correct 49 ms 34264 KB Output is correct
106 Correct 39 ms 34256 KB Output is correct
107 Correct 32 ms 21072 KB Output is correct
108 Correct 12 ms 8792 KB Output is correct
109 Correct 33 ms 21084 KB Output is correct
110 Correct 12 ms 8796 KB Output is correct
111 Correct 13 ms 8792 KB Output is correct
112 Correct 12 ms 8796 KB Output is correct
113 Correct 11 ms 8796 KB Output is correct
114 Correct 30 ms 20936 KB Output is correct
115 Correct 30 ms 21072 KB Output is correct
116 Correct 31 ms 21084 KB Output is correct
117 Correct 60 ms 36944 KB Output is correct
118 Correct 60 ms 37092 KB Output is correct
119 Correct 21 ms 12628 KB Output is correct
120 Correct 21 ms 12636 KB Output is correct
121 Correct 44 ms 35152 KB Output is correct
122 Correct 49 ms 38684 KB Output is correct
123 Correct 49 ms 38480 KB Output is correct
124 Correct 53 ms 37716 KB Output is correct
125 Correct 48 ms 38384 KB Output is correct
126 Correct 65 ms 34264 KB Output is correct
127 Correct 41 ms 33744 KB Output is correct
128 Correct 50 ms 35664 KB Output is correct
129 Correct 47 ms 34984 KB Output is correct
130 Correct 3 ms 4952 KB Output is correct
131 Correct 2 ms 4956 KB Output is correct
132 Correct 2 ms 4956 KB Output is correct
133 Correct 60 ms 36964 KB Output is correct
134 Correct 57 ms 37204 KB Output is correct
135 Correct 57 ms 37200 KB Output is correct
136 Correct 22 ms 12628 KB Output is correct
137 Correct 23 ms 12632 KB Output is correct
138 Correct 21 ms 12756 KB Output is correct
139 Correct 23 ms 12740 KB Output is correct
140 Correct 30 ms 12636 KB Output is correct
141 Correct 21 ms 12564 KB Output is correct
142 Correct 78 ms 37028 KB Output is correct
143 Correct 59 ms 37212 KB Output is correct
144 Correct 51 ms 38608 KB Output is correct
145 Correct 61 ms 35156 KB Output is correct
146 Correct 54 ms 38480 KB Output is correct
147 Correct 62 ms 37708 KB Output is correct
148 Correct 91 ms 34264 KB Output is correct
149 Correct 91 ms 34280 KB Output is correct
150 Correct 67 ms 34128 KB Output is correct
151 Correct 49 ms 35668 KB Output is correct
152 Correct 55 ms 36692 KB Output is correct
153 Correct 45 ms 36688 KB Output is correct
154 Correct 44 ms 35156 KB Output is correct
155 Correct 55 ms 36432 KB Output is correct
156 Correct 44 ms 34616 KB Output is correct
157 Correct 52 ms 34896 KB Output is correct
158 Correct 49 ms 36176 KB Output is correct
159 Correct 47 ms 36176 KB Output is correct
160 Correct 45 ms 36068 KB Output is correct