답안 #109666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109666 2019-05-07T09:26:26 Z jangwonyoung Alternating Current (BOI18_alternating) C++14
74 / 100
306 ms 16396 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=1e5+1,M=1e5+1;
int n,m;
int u[M],v[M];
vector<int>add[M];
bool in[M];
set<int>s;
vector<int>adj[M];
int col[M];
bool ok=true;
void dfs(int id){
	for(auto cur:adj[id]){
		if(col[cur]==col[id]) ok=false;
		if(!col[cur]){
			col[cur]=3-col[id];
			dfs(cur);
		}
	}
}
int lz[262144],mi[262144];
void push(int id){
	lz[id*2]+=lz[id];
	mi[id*2]+=lz[id];
	lz[id*2+1]+=lz[id];
	mi[id*2+1]+=lz[id];
	lz[id]=0;
}
void upd(int id,int l,int r,int ql,int qr,int v){
	if(l>qr || r<ql) return;
	if(ql<=l && r<=qr){
		lz[id]+=v;mi[id]+=v;return;
	}
	push(id);
	int mid=(l+r)/2;
	upd(id*2,l,mid,ql,qr,v);upd(id*2+1,mid+1,r,ql,qr,v);
}
int qry(int id,int l,int r,int ql,int qr){
	if(l>qr || r<ql) return 1e9;
	if(ql<=l && r<=qr) return mi[id];
	push(id);
	int mid=(l+r)/2;
	return min(qry(id*2,l,mid,ql,qr),qry(id*2+1,mid+1,r,ql,qr));
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=1; i<=m ;i++){
		cin >> u[i] >> v[i];
		add[u[i]-1].pb(i);add[v[i]].pb(i);
		if(u[i]>v[i] || u[i]==1) s.insert(i),in[i]=true;
	}
	for(int i=1; i<=n ;i++){
		if(s.size()<2) return cout << "impossible\n",0;
		if(s.size()==2){
			int x=*s.begin(),y=*s.rbegin();
			adj[x].pb(y);adj[y].pb(x);
		}
		for(auto cur:add[i]){
			if(in[cur]) in[cur]=false,s.erase(cur);
			else in[cur]=true,s.insert(cur);
		}
	}
	for(int i=1; i<=m ;i++){
		if(!col[i]){col[i]=1;dfs(i);}
		if(col[i]==1){
			if(u[i]<=v[i]) upd(1,1,n,u[i],v[i],1);
			else upd(1,1,n,u[i],n,1),upd(1,1,n,1,v[i],1);
		}
	}
	if(!ok) return cout << "impossible\n",0;
	for(int i=1; i<=m ;i++){
		if(col[i]!=1){cout << "0";continue;}
		int val;
		if(u[i]<=v[i]) val=qry(1,1,n,u[i],v[i]);
		else val=min(qry(1,1,n,u[i],n),qry(1,1,n,1,v[i]));
		if(val==1){cout << "1";continue;}
		if(u[i]<=v[i]) upd(1,1,n,u[i],v[i],-1);
		else upd(1,1,n,u[i],n,-1),upd(1,1,n,1,v[i],-1);
		cout << "0";
	}
	cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5092 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 7 ms 4988 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 4992 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 9 ms 4992 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 7 ms 5120 KB Output is correct
30 Correct 7 ms 5120 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 9 ms 4992 KB Output is correct
35 Correct 6 ms 5000 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 7 ms 5120 KB Output is correct
39 Correct 8 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5092 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 7 ms 4988 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 4992 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 9 ms 4992 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 7 ms 5120 KB Output is correct
30 Correct 7 ms 5120 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 9 ms 4992 KB Output is correct
35 Correct 6 ms 5000 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 7 ms 5120 KB Output is correct
39 Correct 8 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 6 ms 5120 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 4992 KB Output is correct
48 Correct 6 ms 5120 KB Output is correct
49 Correct 7 ms 5120 KB Output is correct
50 Correct 6 ms 5120 KB Output is correct
51 Correct 5 ms 4992 KB Output is correct
52 Correct 6 ms 4992 KB Output is correct
53 Correct 6 ms 4992 KB Output is correct
54 Correct 7 ms 5120 KB Output is correct
55 Correct 8 ms 5068 KB Output is correct
56 Correct 8 ms 5120 KB Output is correct
57 Correct 7 ms 5120 KB Output is correct
58 Correct 7 ms 5120 KB Output is correct
59 Correct 8 ms 5120 KB Output is correct
60 Correct 7 ms 5120 KB Output is correct
61 Correct 7 ms 5120 KB Output is correct
62 Correct 7 ms 5120 KB Output is correct
63 Correct 7 ms 5120 KB Output is correct
64 Correct 6 ms 5120 KB Output is correct
65 Correct 6 ms 5120 KB Output is correct
66 Correct 7 ms 5092 KB Output is correct
67 Correct 7 ms 5120 KB Output is correct
68 Correct 6 ms 5120 KB Output is correct
69 Correct 6 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5092 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 7 ms 4988 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 4992 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 9 ms 4992 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 7 ms 5120 KB Output is correct
30 Correct 7 ms 5120 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 9 ms 4992 KB Output is correct
35 Correct 6 ms 5000 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 7 ms 5120 KB Output is correct
39 Correct 8 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 6 ms 5120 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 4992 KB Output is correct
48 Correct 6 ms 5120 KB Output is correct
49 Correct 7 ms 5120 KB Output is correct
50 Correct 6 ms 5120 KB Output is correct
51 Correct 5 ms 4992 KB Output is correct
52 Correct 6 ms 4992 KB Output is correct
53 Correct 6 ms 4992 KB Output is correct
54 Correct 7 ms 5120 KB Output is correct
55 Correct 8 ms 5068 KB Output is correct
56 Correct 8 ms 5120 KB Output is correct
57 Correct 7 ms 5120 KB Output is correct
58 Correct 7 ms 5120 KB Output is correct
59 Correct 8 ms 5120 KB Output is correct
60 Correct 7 ms 5120 KB Output is correct
61 Correct 7 ms 5120 KB Output is correct
62 Correct 7 ms 5120 KB Output is correct
63 Correct 7 ms 5120 KB Output is correct
64 Correct 6 ms 5120 KB Output is correct
65 Correct 6 ms 5120 KB Output is correct
66 Correct 7 ms 5092 KB Output is correct
67 Correct 7 ms 5120 KB Output is correct
68 Correct 6 ms 5120 KB Output is correct
69 Correct 6 ms 5248 KB Output is correct
70 Correct 6 ms 5120 KB Output is correct
71 Correct 7 ms 5248 KB Output is correct
72 Correct 7 ms 5120 KB Output is correct
73 Correct 6 ms 5120 KB Output is correct
74 Correct 8 ms 5120 KB Output is correct
75 Correct 8 ms 5120 KB Output is correct
76 Correct 10 ms 5120 KB Output is correct
77 Correct 8 ms 5120 KB Output is correct
78 Correct 7 ms 5120 KB Output is correct
79 Correct 7 ms 5120 KB Output is correct
80 Correct 8 ms 5120 KB Output is correct
81 Correct 7 ms 5120 KB Output is correct
82 Correct 7 ms 5120 KB Output is correct
83 Correct 8 ms 5120 KB Output is correct
84 Correct 8 ms 5196 KB Output is correct
85 Correct 7 ms 5120 KB Output is correct
86 Correct 7 ms 5120 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 6 ms 5120 KB Output is correct
89 Correct 7 ms 5120 KB Output is correct
90 Correct 9 ms 5120 KB Output is correct
91 Correct 8 ms 5088 KB Output is correct
92 Correct 9 ms 5120 KB Output is correct
93 Correct 7 ms 5120 KB Output is correct
94 Correct 7 ms 5120 KB Output is correct
95 Correct 8 ms 5120 KB Output is correct
96 Correct 9 ms 5120 KB Output is correct
97 Correct 8 ms 5120 KB Output is correct
98 Correct 8 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 12852 KB Output is correct
2 Correct 8 ms 6140 KB Output is correct
3 Correct 28 ms 9152 KB Output is correct
4 Correct 89 ms 13788 KB Output is correct
5 Correct 142 ms 14916 KB Output is correct
6 Correct 72 ms 9848 KB Output is correct
7 Correct 141 ms 15096 KB Output is correct
8 Correct 14 ms 8064 KB Output is correct
9 Correct 11 ms 7808 KB Output is correct
10 Correct 154 ms 15232 KB Output is correct
11 Correct 134 ms 13688 KB Output is correct
12 Correct 185 ms 15552 KB Output is correct
13 Correct 9 ms 6052 KB Output is correct
14 Correct 9 ms 6016 KB Output is correct
15 Correct 149 ms 11904 KB Output is correct
16 Correct 34 ms 11512 KB Output is correct
17 Correct 306 ms 15068 KB Output is correct
18 Correct 239 ms 11128 KB Output is correct
19 Correct 12 ms 5496 KB Output is correct
20 Correct 74 ms 13304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 7 ms 5092 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5248 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 7 ms 4988 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 7 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 4992 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 6 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 6 ms 4992 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 6 ms 4992 KB Output is correct
27 Correct 9 ms 4992 KB Output is correct
28 Correct 8 ms 5120 KB Output is correct
29 Correct 7 ms 5120 KB Output is correct
30 Correct 7 ms 5120 KB Output is correct
31 Correct 6 ms 5120 KB Output is correct
32 Correct 6 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 9 ms 4992 KB Output is correct
35 Correct 6 ms 5000 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 6 ms 5120 KB Output is correct
38 Correct 7 ms 5120 KB Output is correct
39 Correct 8 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 6 ms 5120 KB Output is correct
42 Correct 6 ms 4992 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Correct 6 ms 5120 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 6 ms 5120 KB Output is correct
47 Correct 6 ms 4992 KB Output is correct
48 Correct 6 ms 5120 KB Output is correct
49 Correct 7 ms 5120 KB Output is correct
50 Correct 6 ms 5120 KB Output is correct
51 Correct 5 ms 4992 KB Output is correct
52 Correct 6 ms 4992 KB Output is correct
53 Correct 6 ms 4992 KB Output is correct
54 Correct 7 ms 5120 KB Output is correct
55 Correct 8 ms 5068 KB Output is correct
56 Correct 8 ms 5120 KB Output is correct
57 Correct 7 ms 5120 KB Output is correct
58 Correct 7 ms 5120 KB Output is correct
59 Correct 8 ms 5120 KB Output is correct
60 Correct 7 ms 5120 KB Output is correct
61 Correct 7 ms 5120 KB Output is correct
62 Correct 7 ms 5120 KB Output is correct
63 Correct 7 ms 5120 KB Output is correct
64 Correct 6 ms 5120 KB Output is correct
65 Correct 6 ms 5120 KB Output is correct
66 Correct 7 ms 5092 KB Output is correct
67 Correct 7 ms 5120 KB Output is correct
68 Correct 6 ms 5120 KB Output is correct
69 Correct 6 ms 5248 KB Output is correct
70 Correct 6 ms 5120 KB Output is correct
71 Correct 7 ms 5248 KB Output is correct
72 Correct 7 ms 5120 KB Output is correct
73 Correct 6 ms 5120 KB Output is correct
74 Correct 8 ms 5120 KB Output is correct
75 Correct 8 ms 5120 KB Output is correct
76 Correct 10 ms 5120 KB Output is correct
77 Correct 8 ms 5120 KB Output is correct
78 Correct 7 ms 5120 KB Output is correct
79 Correct 7 ms 5120 KB Output is correct
80 Correct 8 ms 5120 KB Output is correct
81 Correct 7 ms 5120 KB Output is correct
82 Correct 7 ms 5120 KB Output is correct
83 Correct 8 ms 5120 KB Output is correct
84 Correct 8 ms 5196 KB Output is correct
85 Correct 7 ms 5120 KB Output is correct
86 Correct 7 ms 5120 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 6 ms 5120 KB Output is correct
89 Correct 7 ms 5120 KB Output is correct
90 Correct 9 ms 5120 KB Output is correct
91 Correct 8 ms 5088 KB Output is correct
92 Correct 9 ms 5120 KB Output is correct
93 Correct 7 ms 5120 KB Output is correct
94 Correct 7 ms 5120 KB Output is correct
95 Correct 8 ms 5120 KB Output is correct
96 Correct 9 ms 5120 KB Output is correct
97 Correct 8 ms 5120 KB Output is correct
98 Correct 8 ms 5120 KB Output is correct
99 Correct 72 ms 12852 KB Output is correct
100 Correct 8 ms 6140 KB Output is correct
101 Correct 28 ms 9152 KB Output is correct
102 Correct 89 ms 13788 KB Output is correct
103 Correct 142 ms 14916 KB Output is correct
104 Correct 72 ms 9848 KB Output is correct
105 Correct 141 ms 15096 KB Output is correct
106 Correct 14 ms 8064 KB Output is correct
107 Correct 11 ms 7808 KB Output is correct
108 Correct 154 ms 15232 KB Output is correct
109 Correct 134 ms 13688 KB Output is correct
110 Correct 185 ms 15552 KB Output is correct
111 Correct 9 ms 6052 KB Output is correct
112 Correct 9 ms 6016 KB Output is correct
113 Correct 149 ms 11904 KB Output is correct
114 Correct 34 ms 11512 KB Output is correct
115 Correct 306 ms 15068 KB Output is correct
116 Correct 239 ms 11128 KB Output is correct
117 Correct 12 ms 5496 KB Output is correct
118 Correct 74 ms 13304 KB Output is correct
119 Correct 10 ms 6784 KB Output is correct
120 Correct 132 ms 16396 KB Output is correct
121 Incorrect 74 ms 11896 KB no wires in direction 0 between segments 80993 and 80994
122 Halted 0 ms 0 KB -