답안 #386814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386814 2021-04-07T11:01:23 Z maximath_1 Alternating Current (BOI18_alternating) C++11
74 / 100
3000 ms 14568 KB
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <iostream>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <limits.h>
#include <random>
#include <chrono>
using namespace std;
 
#define ll long long
#define ld long double
const int MX = 300005;
const int BLOCK = 105;
const ll inf = 8000000000000000069ll;
const ll mod = 1e9 + 7;
const ll inv2 = (mod + 1) / 2;
const int dxh[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int dyh[] = {2, -2, 2, -2, 1, -1, 1, -1}; // horse
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0}; // adj
const int dz[] = {0, 0, 0, 0, 1, -1};
const int dxd[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dyd[] = {1, 0, -1, -1, -1, 0, 1, 1}; // diag

mt19937 rng(time(NULL));

int n, m;
vector<pair<pair<int, int>, int> > v;

void imp(){
	cout << "impossible\n";
	exit(0);
}

int dist(int x, int y){
	int get = y + n - x + 1;
	if(get > n) get -= n;
	return get;
}

void solve(){
	set<pair<int, int> > s;
	vector<int> ans(m + 1, 0);

	int c1 = 0, c2 = 0;
	for(int j = 0, i = 1; i <= n; i ++){
		for(; j < m && v[j].first.first == i; j ++)
			s.insert(make_pair(v[j].first.second, v[j].second));
		for(; s.size() && s.begin() -> first < i;)
			s.erase(s.begin());

		if(c1 < i){
			if(s.empty()) imp();
			c1 = s.begin() -> first;
			ans[s.begin() -> second] = 1;
			s.erase(s.begin());
		}

		if(c2 < i){
			if(s.empty()) imp();
			c2 = s.begin() -> first;
			ans[s.begin() -> second] = 0;
			s.erase(s.begin());
		}
	}

	for(int i = 0; i < m; i ++)
		cout << ans[i];
	exit(0);
}

vector<pair<int, int> > adj[MX];
int vis[MX][2];

int main(){
	cin.tie(0) -> sync_with_stdio(0);
	cin >> n >> m;
	v.resize(m);

	bool aa = 1;
	for(int i = 0; i < m; i ++){
		cin >> v[i].first.first >> v[i].first.second;
		if(v[i].first.first > v[i].first.second) aa = 0;
		v[i].second = i;
	}
	for(int i = 0; i < m; i ++)
		adj[v[i].first.first].emplace_back(dist(v[i].first.first, v[i].first.second), i);

	sort(v.begin(), v.end());

	if(aa) solve();

	int c1 = 0, c2 = 0;
	vector<int> ans(m);

	for(int offset = 0; offset < n; offset ++){
		for(int i = 1; i <= n; i ++)
			vis[i][0] = vis[i][1] = 0;

		for(int i = 1; i <= n; i ++){
			int gt = i + offset;
			if(gt > n) gt -= n;
			for(int j = 0; j < adj[gt].size(); j ++){
				int x = adj[gt][j].first;
				for(int k = 0; k < n; k ++){
					int nw = gt + k;
					if(nw > n) nw -= n;

					if(vis[nw][0] == 0){
						ans[adj[gt][j].second] = 0;
						break;
					}
					if(vis[nw][1] == 0){
						ans[adj[gt][j].second] = 1;
						break;
					}
				}

				for(int l = 0; l < x; l ++){
					int cr = gt + l;
					if(cr > n) cr -= n;
					vis[cr][ans[adj[gt][j].second]] = 1;
				}
			}
		}

		bool ok = 1;
		for(int i = 1; i <= n; i ++)
			if(vis[i][0] == 0 || vis[i][1] == 0)
				ok = 0;
		
		if(ok){
			for(int i = 0; i < m; i ++)
				cout << ans[i];
			cout << endl;
			exit(0);
		}
	}

	imp();
	return 0;
}

Compilation message

alternating.cpp: In function 'int main()':
alternating.cpp:111:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |    for(int j = 0; j < adj[gt].size(); j ++){
      |                   ~~^~~~~~~~~~~~~~~~
alternating.cpp:101:6: warning: unused variable 'c1' [-Wunused-variable]
  101 |  int c1 = 0, c2 = 0;
      |      ^~
alternating.cpp:101:14: warning: unused variable 'c2' [-Wunused-variable]
  101 |  int c1 = 0, c2 = 0;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 7 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 6 ms 7404 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 6 ms 7404 KB Output is correct
30 Correct 6 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7404 KB Output is correct
33 Correct 5 ms 7424 KB Output is correct
34 Correct 5 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 5 ms 7404 KB Output is correct
37 Correct 6 ms 7404 KB Output is correct
38 Correct 5 ms 7404 KB Output is correct
39 Correct 5 ms 7404 KB Output is correct
40 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 7 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 6 ms 7404 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 6 ms 7404 KB Output is correct
30 Correct 6 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7404 KB Output is correct
33 Correct 5 ms 7424 KB Output is correct
34 Correct 5 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 5 ms 7404 KB Output is correct
37 Correct 6 ms 7404 KB Output is correct
38 Correct 5 ms 7404 KB Output is correct
39 Correct 5 ms 7404 KB Output is correct
40 Correct 5 ms 7404 KB Output is correct
41 Correct 5 ms 7404 KB Output is correct
42 Correct 6 ms 7404 KB Output is correct
43 Correct 6 ms 7404 KB Output is correct
44 Correct 5 ms 7404 KB Output is correct
45 Correct 5 ms 7404 KB Output is correct
46 Correct 5 ms 7404 KB Output is correct
47 Correct 6 ms 7424 KB Output is correct
48 Correct 7 ms 7412 KB Output is correct
49 Correct 6 ms 7404 KB Output is correct
50 Correct 6 ms 7404 KB Output is correct
51 Correct 6 ms 7404 KB Output is correct
52 Correct 6 ms 7404 KB Output is correct
53 Correct 6 ms 7404 KB Output is correct
54 Correct 5 ms 7404 KB Output is correct
55 Correct 6 ms 7404 KB Output is correct
56 Correct 5 ms 7404 KB Output is correct
57 Correct 6 ms 7404 KB Output is correct
58 Correct 6 ms 7404 KB Output is correct
59 Correct 5 ms 7404 KB Output is correct
60 Correct 5 ms 7404 KB Output is correct
61 Correct 6 ms 7404 KB Output is correct
62 Correct 6 ms 7404 KB Output is correct
63 Correct 5 ms 7404 KB Output is correct
64 Correct 5 ms 7404 KB Output is correct
65 Correct 6 ms 7404 KB Output is correct
66 Correct 6 ms 7404 KB Output is correct
67 Correct 5 ms 7404 KB Output is correct
68 Correct 5 ms 7404 KB Output is correct
69 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 7 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 6 ms 7404 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 6 ms 7404 KB Output is correct
30 Correct 6 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7404 KB Output is correct
33 Correct 5 ms 7424 KB Output is correct
34 Correct 5 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 5 ms 7404 KB Output is correct
37 Correct 6 ms 7404 KB Output is correct
38 Correct 5 ms 7404 KB Output is correct
39 Correct 5 ms 7404 KB Output is correct
40 Correct 5 ms 7404 KB Output is correct
41 Correct 5 ms 7404 KB Output is correct
42 Correct 6 ms 7404 KB Output is correct
43 Correct 6 ms 7404 KB Output is correct
44 Correct 5 ms 7404 KB Output is correct
45 Correct 5 ms 7404 KB Output is correct
46 Correct 5 ms 7404 KB Output is correct
47 Correct 6 ms 7424 KB Output is correct
48 Correct 7 ms 7412 KB Output is correct
49 Correct 6 ms 7404 KB Output is correct
50 Correct 6 ms 7404 KB Output is correct
51 Correct 6 ms 7404 KB Output is correct
52 Correct 6 ms 7404 KB Output is correct
53 Correct 6 ms 7404 KB Output is correct
54 Correct 5 ms 7404 KB Output is correct
55 Correct 6 ms 7404 KB Output is correct
56 Correct 5 ms 7404 KB Output is correct
57 Correct 6 ms 7404 KB Output is correct
58 Correct 6 ms 7404 KB Output is correct
59 Correct 5 ms 7404 KB Output is correct
60 Correct 5 ms 7404 KB Output is correct
61 Correct 6 ms 7404 KB Output is correct
62 Correct 6 ms 7404 KB Output is correct
63 Correct 5 ms 7404 KB Output is correct
64 Correct 5 ms 7404 KB Output is correct
65 Correct 6 ms 7404 KB Output is correct
66 Correct 6 ms 7404 KB Output is correct
67 Correct 5 ms 7404 KB Output is correct
68 Correct 5 ms 7404 KB Output is correct
69 Correct 5 ms 7404 KB Output is correct
70 Correct 6 ms 7404 KB Output is correct
71 Correct 27 ms 7404 KB Output is correct
72 Correct 16 ms 7404 KB Output is correct
73 Correct 5 ms 7404 KB Output is correct
74 Correct 6 ms 7404 KB Output is correct
75 Correct 6 ms 7404 KB Output is correct
76 Correct 6 ms 7404 KB Output is correct
77 Correct 7 ms 7404 KB Output is correct
78 Correct 23 ms 7404 KB Output is correct
79 Correct 26 ms 7404 KB Output is correct
80 Correct 50 ms 7404 KB Output is correct
81 Correct 5 ms 7404 KB Output is correct
82 Correct 5 ms 7404 KB Output is correct
83 Correct 6 ms 7404 KB Output is correct
84 Correct 6 ms 7404 KB Output is correct
85 Correct 5 ms 7404 KB Output is correct
86 Correct 5 ms 7404 KB Output is correct
87 Correct 6 ms 7404 KB Output is correct
88 Correct 6 ms 7404 KB Output is correct
89 Correct 6 ms 7404 KB Output is correct
90 Correct 10 ms 7404 KB Output is correct
91 Correct 6 ms 7404 KB Output is correct
92 Correct 6 ms 7404 KB Output is correct
93 Correct 5 ms 7404 KB Output is correct
94 Correct 6 ms 7404 KB Output is correct
95 Correct 6 ms 7404 KB Output is correct
96 Correct 6 ms 7404 KB Output is correct
97 Correct 6 ms 7404 KB Output is correct
98 Correct 6 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 14568 KB Output is correct
2 Correct 6 ms 7404 KB Output is correct
3 Correct 19 ms 9708 KB Output is correct
4 Correct 33 ms 12140 KB Output is correct
5 Correct 55 ms 11244 KB Output is correct
6 Correct 48 ms 11244 KB Output is correct
7 Correct 50 ms 11372 KB Output is correct
8 Correct 8 ms 7660 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 56 ms 11372 KB Output is correct
11 Correct 44 ms 10604 KB Output is correct
12 Correct 50 ms 11628 KB Output is correct
13 Correct 6 ms 7424 KB Output is correct
14 Correct 6 ms 7404 KB Output is correct
15 Correct 60 ms 10988 KB Output is correct
16 Correct 32 ms 12140 KB Output is correct
17 Correct 85 ms 13420 KB Output is correct
18 Correct 81 ms 12652 KB Output is correct
19 Correct 8 ms 7660 KB Output is correct
20 Correct 50 ms 10604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 5 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 6 ms 7404 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 6 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 6 ms 7404 KB Output is correct
16 Correct 7 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 6 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 6 ms 7404 KB Output is correct
26 Correct 6 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 6 ms 7404 KB Output is correct
30 Correct 6 ms 7404 KB Output is correct
31 Correct 6 ms 7404 KB Output is correct
32 Correct 6 ms 7404 KB Output is correct
33 Correct 5 ms 7424 KB Output is correct
34 Correct 5 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 5 ms 7404 KB Output is correct
37 Correct 6 ms 7404 KB Output is correct
38 Correct 5 ms 7404 KB Output is correct
39 Correct 5 ms 7404 KB Output is correct
40 Correct 5 ms 7404 KB Output is correct
41 Correct 5 ms 7404 KB Output is correct
42 Correct 6 ms 7404 KB Output is correct
43 Correct 6 ms 7404 KB Output is correct
44 Correct 5 ms 7404 KB Output is correct
45 Correct 5 ms 7404 KB Output is correct
46 Correct 5 ms 7404 KB Output is correct
47 Correct 6 ms 7424 KB Output is correct
48 Correct 7 ms 7412 KB Output is correct
49 Correct 6 ms 7404 KB Output is correct
50 Correct 6 ms 7404 KB Output is correct
51 Correct 6 ms 7404 KB Output is correct
52 Correct 6 ms 7404 KB Output is correct
53 Correct 6 ms 7404 KB Output is correct
54 Correct 5 ms 7404 KB Output is correct
55 Correct 6 ms 7404 KB Output is correct
56 Correct 5 ms 7404 KB Output is correct
57 Correct 6 ms 7404 KB Output is correct
58 Correct 6 ms 7404 KB Output is correct
59 Correct 5 ms 7404 KB Output is correct
60 Correct 5 ms 7404 KB Output is correct
61 Correct 6 ms 7404 KB Output is correct
62 Correct 6 ms 7404 KB Output is correct
63 Correct 5 ms 7404 KB Output is correct
64 Correct 5 ms 7404 KB Output is correct
65 Correct 6 ms 7404 KB Output is correct
66 Correct 6 ms 7404 KB Output is correct
67 Correct 5 ms 7404 KB Output is correct
68 Correct 5 ms 7404 KB Output is correct
69 Correct 5 ms 7404 KB Output is correct
70 Correct 6 ms 7404 KB Output is correct
71 Correct 27 ms 7404 KB Output is correct
72 Correct 16 ms 7404 KB Output is correct
73 Correct 5 ms 7404 KB Output is correct
74 Correct 6 ms 7404 KB Output is correct
75 Correct 6 ms 7404 KB Output is correct
76 Correct 6 ms 7404 KB Output is correct
77 Correct 7 ms 7404 KB Output is correct
78 Correct 23 ms 7404 KB Output is correct
79 Correct 26 ms 7404 KB Output is correct
80 Correct 50 ms 7404 KB Output is correct
81 Correct 5 ms 7404 KB Output is correct
82 Correct 5 ms 7404 KB Output is correct
83 Correct 6 ms 7404 KB Output is correct
84 Correct 6 ms 7404 KB Output is correct
85 Correct 5 ms 7404 KB Output is correct
86 Correct 5 ms 7404 KB Output is correct
87 Correct 6 ms 7404 KB Output is correct
88 Correct 6 ms 7404 KB Output is correct
89 Correct 6 ms 7404 KB Output is correct
90 Correct 10 ms 7404 KB Output is correct
91 Correct 6 ms 7404 KB Output is correct
92 Correct 6 ms 7404 KB Output is correct
93 Correct 5 ms 7404 KB Output is correct
94 Correct 6 ms 7404 KB Output is correct
95 Correct 6 ms 7404 KB Output is correct
96 Correct 6 ms 7404 KB Output is correct
97 Correct 6 ms 7404 KB Output is correct
98 Correct 6 ms 7404 KB Output is correct
99 Correct 54 ms 14568 KB Output is correct
100 Correct 6 ms 7404 KB Output is correct
101 Correct 19 ms 9708 KB Output is correct
102 Correct 33 ms 12140 KB Output is correct
103 Correct 55 ms 11244 KB Output is correct
104 Correct 48 ms 11244 KB Output is correct
105 Correct 50 ms 11372 KB Output is correct
106 Correct 8 ms 7660 KB Output is correct
107 Correct 6 ms 7404 KB Output is correct
108 Correct 56 ms 11372 KB Output is correct
109 Correct 44 ms 10604 KB Output is correct
110 Correct 50 ms 11628 KB Output is correct
111 Correct 6 ms 7424 KB Output is correct
112 Correct 6 ms 7404 KB Output is correct
113 Correct 60 ms 10988 KB Output is correct
114 Correct 32 ms 12140 KB Output is correct
115 Correct 85 ms 13420 KB Output is correct
116 Correct 81 ms 12652 KB Output is correct
117 Correct 8 ms 7660 KB Output is correct
118 Correct 50 ms 10604 KB Output is correct
119 Execution timed out 3074 ms 8172 KB Time limit exceeded
120 Halted 0 ms 0 KB -