답안 #106132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106132 2019-04-16T17:54:23 Z Noam527 Alternating Current (BOI18_alternating) C++17
13 / 100
9 ms 5248 KB
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 0;
const int OOO = 1;
using namespace std;

struct edge {
	int to, i;
	edge(int tt = 0, int ii = 0) : to(tt), i(ii) {}
};

int n, m;
int C[100005] = {};
int dp[200005], to[200005];
int range[200005] = {};

vector<edge> g[200005];
vector<int> vis;
vector<int> path;

string ans;

void add(int l, int r) {
	C[l]++;
	C[r + 1]--;
}
void pre() {
	for (int i = 1; i <= n; i++) C[i] += C[i - 1];
	for (int i = 1; i <= n; i++) {
		if (C[i] == 1) {
			cout << "impossible\n";
			exit(0);
		}
		C[i] = max(0, min(1, C[i] - 2));
		if (C[i]) {
			if (OO) {
				cout << "from C adding " << i << " " << i - 1 << '\n';
			}
			g[i].push_back(edge(i - 1, -1));
			g[i + n].push_back(edge(i - 1 + n, -1));
		}
	}
}

bool dfs(int v, int tar) {
	if (OO) {
		cout << "dfsing " << v << " tar " << tar << '\n';
	}
	if (v == tar) return true;
	if (vis[v % n]) return false;
	vis[v % n] = 1;
	for (const auto &i : g[v]) {
		path.push_back(i.i);
		if (dfs(i.to, tar)) return true;
		path.pop_back();
	}
	return false;
}

bool check(int v) {
	if (OO) {
		cout << "starting check on " << v << '\n';
	}
	for (auto &i : vis) i = 0;
	if (dfs(v, v + n)) return true;
	return false;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	if (n > 1000) finish(-1); // quick please
	for (int i = 0, l, r; i < m; i++) {
		cin >> l >> r;
		if (l > r) {
			add(l, n);
			add(1, r);
			l--;
			r += n;
			if (OO) cout << "from input adding " << l << " " << r << '\n';
			g[l].push_back(edge(r, i));
			g[l + n].push_back(edge(2 * n, i));
		}
		else {
			add(l, r);
			l--;
			if (OO) cout << "from input adding " << l << " " << r << '\n';
			g[l].push_back(edge(r, i));
			g[l + n].push_back(edge(r + n, i));
		}
	}
	pre();

	ans.resize(m, '1');
	vis.resize(n, 0);

	for (int i = n - 1; i >= 0; i--) {
		if (check(i)) {
			for (const auto &j : path)
				if (j != -1) ans[j] = '0';
			finish(ans);
		}
	}
	finish("impossible");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 9 ms 4992 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 4992 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 8 ms 4992 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 8 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 6 ms 5120 KB Output is correct
28 Correct 6 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 6 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 9 ms 4992 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 4992 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 8 ms 4992 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 8 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 6 ms 5120 KB Output is correct
28 Correct 6 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 6 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 7 ms 4992 KB Output is correct
42 Correct 7 ms 5120 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Incorrect 7 ms 5120 KB no wires in direction 1 between segments 4 and 22
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 9 ms 4992 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 4992 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 8 ms 4992 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 8 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 6 ms 5120 KB Output is correct
28 Correct 6 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 6 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 7 ms 4992 KB Output is correct
42 Correct 7 ms 5120 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Incorrect 7 ms 5120 KB no wires in direction 1 between segments 4 and 22
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB -1 is not a string of length exactly 100000
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 9 ms 5120 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 9 ms 4992 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 4992 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 4992 KB Output is correct
15 Correct 6 ms 4992 KB Output is correct
16 Correct 8 ms 4992 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 6 ms 5120 KB Output is correct
19 Correct 6 ms 4992 KB Output is correct
20 Correct 8 ms 4992 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 7 ms 4992 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 8 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 6 ms 5120 KB Output is correct
28 Correct 6 ms 4992 KB Output is correct
29 Correct 6 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 8 ms 5120 KB Output is correct
35 Correct 7 ms 4992 KB Output is correct
36 Correct 6 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 7 ms 4992 KB Output is correct
39 Correct 6 ms 4992 KB Output is correct
40 Correct 7 ms 4992 KB Output is correct
41 Correct 7 ms 4992 KB Output is correct
42 Correct 7 ms 5120 KB Output is correct
43 Correct 7 ms 5120 KB Output is correct
44 Incorrect 7 ms 5120 KB no wires in direction 1 between segments 4 and 22
45 Halted 0 ms 0 KB -