답안 #782172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782172 2023-07-13T15:59:01 Z amirhoseinfar1385 Watermelon (INOI20_watermelon) C++17
31 / 100
13 ms 2520 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	vector<int>all(n);
	for(int i=0;i<n;i++){
		cin>>all[i];
	}
	vector<int>res(n+1);
	vector<int>allv;
	for(int i=0;i<n;i++){
		if(all[i]==-1){
			allv.push_back(i);
		}
	}
	vector<int>w(n+1);
	int now=n;
	for(int i=0;i<(int)allv.size();i++){
		res[allv[i]]=now;
		w[now]=i;
		now--;
	}
	now=1;
	int last=-1;
	vector<int>st;
	for(int j=0;j<n;j++){
		if(all[j]==1){
			res[j]=now;
			now++;
			int z=2;
			while((int)st.size()>0){
				auto x=st.back();
				if(all[x]==z){
					z++;
					res[x]=now;
					w[now]=x;
					st.pop_back();
					now++;
					continue;
				}
				break;
			}
		}	
		if(all[j]!=1&&all[j]!=-1){
			st.push_back(j);
		}
	}
	if((int)st.size()>0){
		cout<<-1<<"\n";
		return 0;
	}
	if(m==2){
		swap(res[n-1],res[w[res[n-1]-1]]);
	}
	for(int i=0;i<n;i++){
		cout<<res[i]<<" ";
	}
	cout<<"\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:29:6: warning: unused variable 'last' [-Wunused-variable]
   29 |  int last=-1;
      |      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 276 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 276 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1108 KB Output is correct
2 Correct 3 ms 1240 KB Output is correct
3 Correct 6 ms 1204 KB Output is correct
4 Correct 4 ms 1240 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 11 ms 2028 KB Output is correct
12 Correct 11 ms 2004 KB Output is correct
13 Correct 11 ms 2000 KB Output is correct
14 Correct 11 ms 2004 KB Output is correct
15 Correct 7 ms 2136 KB Output is correct
16 Correct 7 ms 2136 KB Output is correct
17 Correct 7 ms 2060 KB Output is correct
18 Correct 7 ms 2132 KB Output is correct
19 Correct 7 ms 2136 KB Output is correct
20 Correct 7 ms 2136 KB Output is correct
21 Correct 7 ms 2136 KB Output is correct
22 Correct 7 ms 2136 KB Output is correct
23 Correct 7 ms 2136 KB Output is correct
24 Correct 12 ms 2260 KB Output is correct
25 Correct 12 ms 2340 KB Output is correct
26 Correct 12 ms 2264 KB Output is correct
27 Correct 12 ms 2260 KB Output is correct
28 Correct 12 ms 2260 KB Output is correct
29 Correct 12 ms 2268 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 6 ms 1108 KB Output is correct
32 Correct 10 ms 1912 KB Output is correct
33 Correct 11 ms 2028 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 6 ms 1236 KB Output is correct
37 Correct 11 ms 2004 KB Output is correct
38 Correct 11 ms 2132 KB Output is correct
39 Correct 11 ms 2136 KB Output is correct
40 Correct 11 ms 2400 KB Output is correct
41 Correct 13 ms 2520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1108 KB Output is correct
2 Correct 3 ms 1240 KB Output is correct
3 Correct 6 ms 1204 KB Output is correct
4 Correct 4 ms 1240 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 6 ms 1108 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 6 ms 1108 KB Output is correct
11 Correct 11 ms 2028 KB Output is correct
12 Correct 11 ms 2004 KB Output is correct
13 Correct 11 ms 2000 KB Output is correct
14 Correct 11 ms 2004 KB Output is correct
15 Correct 7 ms 2136 KB Output is correct
16 Correct 7 ms 2136 KB Output is correct
17 Correct 7 ms 2060 KB Output is correct
18 Correct 7 ms 2132 KB Output is correct
19 Correct 7 ms 2136 KB Output is correct
20 Correct 7 ms 2136 KB Output is correct
21 Correct 7 ms 2136 KB Output is correct
22 Correct 7 ms 2136 KB Output is correct
23 Correct 7 ms 2136 KB Output is correct
24 Correct 12 ms 2260 KB Output is correct
25 Correct 12 ms 2340 KB Output is correct
26 Correct 12 ms 2264 KB Output is correct
27 Correct 12 ms 2260 KB Output is correct
28 Correct 12 ms 2260 KB Output is correct
29 Correct 12 ms 2268 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 6 ms 1108 KB Output is correct
32 Correct 10 ms 1912 KB Output is correct
33 Correct 11 ms 2028 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 6 ms 1236 KB Output is correct
37 Correct 11 ms 2004 KB Output is correct
38 Correct 11 ms 2132 KB Output is correct
39 Correct 11 ms 2136 KB Output is correct
40 Correct 11 ms 2400 KB Output is correct
41 Correct 13 ms 2520 KB Output is correct
42 Incorrect 6 ms 1108 KB Output isn't correct
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Incorrect 1 ms 276 KB Output isn't correct
13 Halted 0 ms 0 KB -