답안 #863398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863398 2023-10-20T07:07:09 Z Trisanu_Das Alternating Current (BOI18_alternating) C++17
32 / 100
143 ms 10588 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
const int maxn5 = 2e5 + 10;
 
int a[200005], b[200005];
bool av[2][200005];
int n, m;
bool ty[200005];
vector <int> seg[200005], ex;
 
void kill(){
	cout << "impossible\n";
	exit(0);
}
 
void solve(){
	for(int i = 0; i < m; i++) seg[a[i]].push_back(i);
	int id1 = -1, id2 = -1;
	for(int i = 0; i < n; i++){
		if(b[id1] < i) id1 = -1;
		if(b[id2] < i) id2 = -1;
		while(!ex.empty() && b[ex.back()] < i) ex.pop_back();
		for(auto u : seg[i]) ex.push_back(u);
		if(id1 == -1){
			if(ex.empty()) kill();
			id1 = ex.back();
			ty[id1] = true;
			ex.pop_back();
		}
		while(!ex.empty() && b[ex.back()] < i) ex.pop_back();
		if(id2 == -1){
			if(ex.empty()) kill();
			id2 = ex.back();
			ex.pop_back();
		}
	}
	for(int i = 0; i < m; i++) cout << ty[i];
	cout << '\n';
	exit(0);
}
 
 
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	if(max(n, m) > 20) 
		solve();
 
	for(int mask = 1; mask < (1 << m) - 1; mask++){
		memset(av, false, sizeof av);
		for(int i = 0; i < m; i++){
			int x = a[i];
			while(true){
				av[(mask >> i)&1][x] = true;
				if(x == b[i]) break;
				x++;
				if(x == n) x = 0;
			}
		}
		bool re = true;
		for(int i = 0; i < n; i++) if(!av[0][i] || !av[1][i]) re = false;
		if(re){
			for(int i = 0; i < m; i++) cout << ((mask >> i)&1);
			return cout << '\n', 0;
		}
	}
	cout << "impossible\n";
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 1 ms 6900 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 13 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 18 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 19 ms 6796 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 7000 KB Output is correct
27 Correct 20 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 136 ms 6768 KB Output is correct
36 Correct 7 ms 6744 KB Output is correct
37 Correct 2 ms 7000 KB Output is correct
38 Correct 143 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 1 ms 6900 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 13 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 18 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 19 ms 6796 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 7000 KB Output is correct
27 Correct 20 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 136 ms 6768 KB Output is correct
36 Correct 7 ms 6744 KB Output is correct
37 Correct 2 ms 7000 KB Output is correct
38 Correct 143 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 7000 KB Output is correct
42 Incorrect 1 ms 6748 KB 'impossible' claimed, but there is a solution
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 1 ms 6900 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 13 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 18 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 19 ms 6796 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 7000 KB Output is correct
27 Correct 20 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 136 ms 6768 KB Output is correct
36 Correct 7 ms 6744 KB Output is correct
37 Correct 2 ms 7000 KB Output is correct
38 Correct 143 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 7000 KB Output is correct
42 Incorrect 1 ms 6748 KB 'impossible' claimed, but there is a solution
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 7900 KB Output is correct
2 Correct 2 ms 6744 KB Output is correct
3 Correct 9 ms 8796 KB Output is correct
4 Correct 15 ms 9296 KB Output is correct
5 Correct 23 ms 10332 KB Output is correct
6 Correct 21 ms 10064 KB Output is correct
7 Correct 20 ms 10328 KB Output is correct
8 Correct 2 ms 6744 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 22 ms 10332 KB Output is correct
11 Correct 21 ms 9720 KB Output is correct
12 Correct 19 ms 10588 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 21 ms 9820 KB Output is correct
16 Correct 9 ms 9304 KB Output is correct
17 Correct 21 ms 10356 KB Output is correct
18 Correct 20 ms 9428 KB Output is correct
19 Correct 2 ms 7000 KB Output is correct
20 Correct 18 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 1 ms 6768 KB Output is correct
6 Correct 1 ms 6900 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 3 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 13 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 18 ms 6744 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 1 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 19 ms 6796 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 7000 KB Output is correct
27 Correct 20 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 2 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 136 ms 6768 KB Output is correct
36 Correct 7 ms 6744 KB Output is correct
37 Correct 2 ms 7000 KB Output is correct
38 Correct 143 ms 6748 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 7000 KB Output is correct
42 Incorrect 1 ms 6748 KB 'impossible' claimed, but there is a solution
43 Halted 0 ms 0 KB -