Submission #1038478

# Submission time Handle Problem Language Result Execution time Memory
1038478 2024-07-29T20:52:06 Z PM1 Watermelon (INOI20_watermelon) C++17
100 / 100
94 ms 43236 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);
		}
	}

}
struct segment{
	int val[szz];
	void build(int id,int L,int R){
		if(L+1==R){
			val[id]=b[L];
			return ;
		}
		int mid=(L+R)>>1;
		build(id*2,L,mid);
		build(id*2+1,mid,R);
		val[id]=max(val[id*2],val[id*2+1]);
	}
	int get(int id,int L,int R,int l,int r){
		if(L>=r || l>=R)
			return 0;
		if(l<=L && R<=r)
			return val[id];
		int mid=(L+R)>>1;
		return max(get(id*2,L,mid,l,r),get(id*2+1,mid,R,l,r));
	}
}seg;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("gen.txt","r",stdin);
	//freopen("gh.txt","w",stdout);
	cin>>n>>k;
	int cnt=0;
	vector<int>hey;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		if(b[i]==-1)hey.push_back(i);
	}
	if(b[n]!=-1){
		cout<<-1;
		return 0;
	}
	for(int i=1;i<hey.size();i++){
		par[hey[i]].push_back(hey[i-1]);
		g[hey[i-1]].push_back(hey[i]);
	}
	seg.build(1,1,n+1);
	for(int i=0;i<hey.size();i++){
		int l=(i==0)?1:hey[i-1]+1;
		vector<int>v;
		for(int j=hey[i]-1;j>=l;j--){
			par[j].push_back(hey[i]);
			g[hey[i]].push_back(j);
			R[j]=j+1;
			while(R[j]<hey[i] && b[R[j]]<b[j]){
				if(seg.get(1,1,n+1,j+1,R[j])<b[R[j]]){
					par[R[j]].push_back(j);
					g[j].push_back(R[j]);
				}
				
				R[j]=R[R[j]];
			}
			par[j].push_back(R[j]);
			g[R[j]].push_back(j);
			if(seg.get(1,1,n+1,j+1,R[j])+1!=b[j]){
				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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:89:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for(int i=1;i<hey.size();i++){
      |              ~^~~~~~~~~~~
Main.cpp:94:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i=0;i<hey.size();i++){
      |              ~^~~~~~~~~~~
Main.cpp:79:6: warning: unused variable 'cnt' [-Wunused-variable]
   79 |  int cnt=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8672 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8660 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8632 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8796 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8672 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8672 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8660 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8632 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8796 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8672 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 2 ms 9308 KB Output is correct
35 Correct 2 ms 9136 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 3 ms 9260 KB Output is correct
39 Correct 3 ms 9116 KB Output is correct
40 Correct 3 ms 9308 KB Output is correct
41 Correct 3 ms 9308 KB Output is correct
42 Correct 2 ms 9308 KB Output is correct
43 Correct 3 ms 9308 KB Output is correct
44 Correct 3 ms 9052 KB Output is correct
45 Correct 4 ms 9340 KB Output is correct
46 Correct 2 ms 9052 KB Output is correct
47 Correct 2 ms 8792 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8796 KB Output is correct
53 Correct 2 ms 9052 KB Output is correct
54 Correct 2 ms 9308 KB Output is correct
55 Correct 1 ms 8536 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 3 ms 9052 KB Output is correct
58 Correct 3 ms 9308 KB Output is correct
59 Correct 2 ms 9052 KB Output is correct
60 Correct 2 ms 9308 KB Output is correct
61 Correct 2 ms 9052 KB Output is correct
62 Correct 2 ms 9308 KB Output is correct
63 Correct 2 ms 9308 KB Output is correct
64 Correct 2 ms 8796 KB Output is correct
65 Correct 2 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 26080 KB Output is correct
2 Correct 5 ms 11096 KB Output is correct
3 Correct 38 ms 26272 KB Output is correct
4 Correct 4 ms 11100 KB Output is correct
5 Correct 40 ms 26092 KB Output is correct
6 Correct 36 ms 26196 KB Output is correct
7 Correct 35 ms 26204 KB Output is correct
8 Correct 36 ms 26200 KB Output is correct
9 Correct 36 ms 26192 KB Output is correct
10 Correct 35 ms 26352 KB Output is correct
11 Correct 87 ms 41604 KB Output is correct
12 Correct 94 ms 41812 KB Output is correct
13 Correct 71 ms 41776 KB Output is correct
14 Correct 69 ms 41884 KB Output is correct
15 Correct 7 ms 11612 KB Output is correct
16 Correct 7 ms 11752 KB Output is correct
17 Correct 6 ms 11760 KB Output is correct
18 Correct 7 ms 11608 KB Output is correct
19 Correct 6 ms 11612 KB Output is correct
20 Correct 7 ms 11612 KB Output is correct
21 Correct 7 ms 11612 KB Output is correct
22 Correct 10 ms 11732 KB Output is correct
23 Correct 7 ms 11524 KB Output is correct
24 Correct 58 ms 39888 KB Output is correct
25 Correct 57 ms 40140 KB Output is correct
26 Correct 58 ms 40908 KB Output is correct
27 Correct 58 ms 41168 KB Output is correct
28 Correct 60 ms 40908 KB Output is correct
29 Correct 57 ms 39760 KB Output is correct
30 Correct 19 ms 20308 KB Output is correct
31 Correct 30 ms 26828 KB Output is correct
32 Correct 54 ms 39936 KB Output is correct
33 Correct 59 ms 43076 KB Output is correct
34 Correct 6 ms 11608 KB Output is correct
35 Correct 15 ms 16984 KB Output is correct
36 Correct 30 ms 26716 KB Output is correct
37 Correct 60 ms 43088 KB Output is correct
38 Correct 66 ms 42172 KB Output is correct
39 Correct 59 ms 43088 KB Output is correct
40 Correct 46 ms 38360 KB Output is correct
41 Correct 65 ms 38592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 26080 KB Output is correct
2 Correct 5 ms 11096 KB Output is correct
3 Correct 38 ms 26272 KB Output is correct
4 Correct 4 ms 11100 KB Output is correct
5 Correct 40 ms 26092 KB Output is correct
6 Correct 36 ms 26196 KB Output is correct
7 Correct 35 ms 26204 KB Output is correct
8 Correct 36 ms 26200 KB Output is correct
9 Correct 36 ms 26192 KB Output is correct
10 Correct 35 ms 26352 KB Output is correct
11 Correct 87 ms 41604 KB Output is correct
12 Correct 94 ms 41812 KB Output is correct
13 Correct 71 ms 41776 KB Output is correct
14 Correct 69 ms 41884 KB Output is correct
15 Correct 7 ms 11612 KB Output is correct
16 Correct 7 ms 11752 KB Output is correct
17 Correct 6 ms 11760 KB Output is correct
18 Correct 7 ms 11608 KB Output is correct
19 Correct 6 ms 11612 KB Output is correct
20 Correct 7 ms 11612 KB Output is correct
21 Correct 7 ms 11612 KB Output is correct
22 Correct 10 ms 11732 KB Output is correct
23 Correct 7 ms 11524 KB Output is correct
24 Correct 58 ms 39888 KB Output is correct
25 Correct 57 ms 40140 KB Output is correct
26 Correct 58 ms 40908 KB Output is correct
27 Correct 58 ms 41168 KB Output is correct
28 Correct 60 ms 40908 KB Output is correct
29 Correct 57 ms 39760 KB Output is correct
30 Correct 19 ms 20308 KB Output is correct
31 Correct 30 ms 26828 KB Output is correct
32 Correct 54 ms 39936 KB Output is correct
33 Correct 59 ms 43076 KB Output is correct
34 Correct 6 ms 11608 KB Output is correct
35 Correct 15 ms 16984 KB Output is correct
36 Correct 30 ms 26716 KB Output is correct
37 Correct 60 ms 43088 KB Output is correct
38 Correct 66 ms 42172 KB Output is correct
39 Correct 59 ms 43088 KB Output is correct
40 Correct 46 ms 38360 KB Output is correct
41 Correct 65 ms 38592 KB Output is correct
42 Correct 36 ms 26192 KB Output is correct
43 Correct 4 ms 11100 KB Output is correct
44 Correct 35 ms 26240 KB Output is correct
45 Correct 4 ms 11356 KB Output is correct
46 Correct 4 ms 11100 KB Output is correct
47 Correct 4 ms 11096 KB Output is correct
48 Correct 4 ms 11100 KB Output is correct
49 Correct 45 ms 26028 KB Output is correct
50 Correct 36 ms 26196 KB Output is correct
51 Correct 36 ms 26196 KB Output is correct
52 Correct 72 ms 41556 KB Output is correct
53 Correct 85 ms 41808 KB Output is correct
54 Correct 7 ms 11608 KB Output is correct
55 Correct 7 ms 11612 KB Output is correct
56 Correct 53 ms 39840 KB Output is correct
57 Correct 56 ms 42960 KB Output is correct
58 Correct 57 ms 43088 KB Output is correct
59 Correct 58 ms 42320 KB Output is correct
60 Correct 72 ms 43088 KB Output is correct
61 Correct 46 ms 38356 KB Output is correct
62 Correct 55 ms 37816 KB Output is correct
63 Correct 64 ms 40016 KB Output is correct
64 Correct 55 ms 39368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8672 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8660 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 8632 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8796 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8672 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 2 ms 9308 KB Output is correct
35 Correct 2 ms 9136 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 3 ms 9260 KB Output is correct
39 Correct 3 ms 9116 KB Output is correct
40 Correct 3 ms 9308 KB Output is correct
41 Correct 3 ms 9308 KB Output is correct
42 Correct 2 ms 9308 KB Output is correct
43 Correct 3 ms 9308 KB Output is correct
44 Correct 3 ms 9052 KB Output is correct
45 Correct 4 ms 9340 KB Output is correct
46 Correct 2 ms 9052 KB Output is correct
47 Correct 2 ms 8792 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8796 KB Output is correct
53 Correct 2 ms 9052 KB Output is correct
54 Correct 2 ms 9308 KB Output is correct
55 Correct 1 ms 8536 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 3 ms 9052 KB Output is correct
58 Correct 3 ms 9308 KB Output is correct
59 Correct 2 ms 9052 KB Output is correct
60 Correct 2 ms 9308 KB Output is correct
61 Correct 2 ms 9052 KB Output is correct
62 Correct 2 ms 9308 KB Output is correct
63 Correct 2 ms 9308 KB Output is correct
64 Correct 2 ms 8796 KB Output is correct
65 Correct 2 ms 9052 KB Output is correct
66 Correct 46 ms 26080 KB Output is correct
67 Correct 5 ms 11096 KB Output is correct
68 Correct 38 ms 26272 KB Output is correct
69 Correct 4 ms 11100 KB Output is correct
70 Correct 40 ms 26092 KB Output is correct
71 Correct 36 ms 26196 KB Output is correct
72 Correct 35 ms 26204 KB Output is correct
73 Correct 36 ms 26200 KB Output is correct
74 Correct 36 ms 26192 KB Output is correct
75 Correct 35 ms 26352 KB Output is correct
76 Correct 87 ms 41604 KB Output is correct
77 Correct 94 ms 41812 KB Output is correct
78 Correct 71 ms 41776 KB Output is correct
79 Correct 69 ms 41884 KB Output is correct
80 Correct 7 ms 11612 KB Output is correct
81 Correct 7 ms 11752 KB Output is correct
82 Correct 6 ms 11760 KB Output is correct
83 Correct 7 ms 11608 KB Output is correct
84 Correct 6 ms 11612 KB Output is correct
85 Correct 7 ms 11612 KB Output is correct
86 Correct 7 ms 11612 KB Output is correct
87 Correct 10 ms 11732 KB Output is correct
88 Correct 7 ms 11524 KB Output is correct
89 Correct 58 ms 39888 KB Output is correct
90 Correct 57 ms 40140 KB Output is correct
91 Correct 58 ms 40908 KB Output is correct
92 Correct 58 ms 41168 KB Output is correct
93 Correct 60 ms 40908 KB Output is correct
94 Correct 57 ms 39760 KB Output is correct
95 Correct 19 ms 20308 KB Output is correct
96 Correct 30 ms 26828 KB Output is correct
97 Correct 54 ms 39936 KB Output is correct
98 Correct 59 ms 43076 KB Output is correct
99 Correct 6 ms 11608 KB Output is correct
100 Correct 15 ms 16984 KB Output is correct
101 Correct 30 ms 26716 KB Output is correct
102 Correct 60 ms 43088 KB Output is correct
103 Correct 66 ms 42172 KB Output is correct
104 Correct 59 ms 43088 KB Output is correct
105 Correct 46 ms 38360 KB Output is correct
106 Correct 65 ms 38592 KB Output is correct
107 Correct 36 ms 26192 KB Output is correct
108 Correct 4 ms 11100 KB Output is correct
109 Correct 35 ms 26240 KB Output is correct
110 Correct 4 ms 11356 KB Output is correct
111 Correct 4 ms 11100 KB Output is correct
112 Correct 4 ms 11096 KB Output is correct
113 Correct 4 ms 11100 KB Output is correct
114 Correct 45 ms 26028 KB Output is correct
115 Correct 36 ms 26196 KB Output is correct
116 Correct 36 ms 26196 KB Output is correct
117 Correct 72 ms 41556 KB Output is correct
118 Correct 85 ms 41808 KB Output is correct
119 Correct 7 ms 11608 KB Output is correct
120 Correct 7 ms 11612 KB Output is correct
121 Correct 53 ms 39840 KB Output is correct
122 Correct 56 ms 42960 KB Output is correct
123 Correct 57 ms 43088 KB Output is correct
124 Correct 58 ms 42320 KB Output is correct
125 Correct 72 ms 43088 KB Output is correct
126 Correct 46 ms 38356 KB Output is correct
127 Correct 55 ms 37816 KB Output is correct
128 Correct 64 ms 40016 KB Output is correct
129 Correct 55 ms 39368 KB Output is correct
130 Correct 1 ms 8536 KB Output is correct
131 Correct 1 ms 8540 KB Output is correct
132 Correct 1 ms 8540 KB Output is correct
133 Correct 66 ms 41712 KB Output is correct
134 Correct 66 ms 41584 KB Output is correct
135 Correct 76 ms 41556 KB Output is correct
136 Correct 7 ms 11608 KB Output is correct
137 Correct 7 ms 11612 KB Output is correct
138 Correct 7 ms 11608 KB Output is correct
139 Correct 7 ms 11612 KB Output is correct
140 Correct 7 ms 11612 KB Output is correct
141 Correct 7 ms 11612 KB Output is correct
142 Correct 72 ms 41768 KB Output is correct
143 Correct 85 ms 41704 KB Output is correct
144 Correct 62 ms 42952 KB Output is correct
145 Correct 51 ms 39972 KB Output is correct
146 Correct 57 ms 43236 KB Output is correct
147 Correct 64 ms 42320 KB Output is correct
148 Correct 71 ms 38248 KB Output is correct
149 Correct 78 ms 38424 KB Output is correct
150 Correct 64 ms 38456 KB Output is correct
151 Correct 63 ms 39888 KB Output is correct
152 Correct 69 ms 41164 KB Output is correct
153 Correct 57 ms 41168 KB Output is correct
154 Correct 57 ms 39712 KB Output is correct
155 Correct 57 ms 40904 KB Output is correct
156 Correct 54 ms 39116 KB Output is correct
157 Correct 60 ms 39284 KB Output is correct
158 Correct 61 ms 40656 KB Output is correct
159 Correct 66 ms 40600 KB Output is correct
160 Correct 61 ms 40556 KB Output is correct