답안 #234728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234728 2020-05-25T11:29:20 Z ArshiaDadras Ili (COI17_ili) C++14
0 / 100
5 ms 768 KB
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 2e4 + 5;
vector<int> adj[N];
bool mark[N];
int n, m;
char c[N];

int read() {
	getchar();
	char x; int u;
	cin >> x >> u;
	if (x ^ 'x')
		u += n;
	return --u;
}

bool check(int root) {
	c[root] = '0';
	mark[root] = true;
	for (int u = n + m - 1; u >= n; u--) {
		if (mark[u])
			for (auto v: adj[u])
				if (c[v] == '?') {
					mark[v] = true;
					c[v] = '0';
				}
		bool one = false;
		for (auto v: adj[u])
			one |= c[v] != '0';
		if (c[u] != '?' && c[u] - '0' != one)
			return false;
	}
	return true;
}

void read_input() {
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> c[n + i];
	for (int i = 0; i < m; i++) {
		int u = read(), v = read();
		adj[n + i].push_back(u);
		adj[n + i].push_back(v);
	}
}

void solve() {
	for (int u = 0; u < n; u++)
		c[u] = '?';
	for (int u = n + m - 1; u >= n; u--)
		if (c[u] == '0')
			for (auto v: adj[u])
				c[v] = '0';
	for (int u = 0; u < n + m; u++) {
		if (c[u] == '?' && !check(u)) {
			mark[u] = false;
			c[u] = '1';
		}
		for (int v = 0; v < n + m; v++)
			if (mark[v]) {
				mark[v] = false;
				c[v] = '?';
			}
	}
	for (int i = 0; i < m; i++)
		cout << c[n + i];
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Incorrect 5 ms 768 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Incorrect 5 ms 768 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Incorrect 5 ms 768 KB Output isn't correct
4 Halted 0 ms 0 KB -