답안 #232299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232299 2020-05-16T14:56:15 Z pedy4000 Ili (COI17_ili) C++14
49 / 100
4000 ms 14840 KB
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <unordered_map>
using namespace std;

const int N = 1e4 + 8, MOD = 1e9 + 7;
int pw[N];
int n, m;
string s;
int type[N * 2];
bool mark[N * 2];
bitset <N> bt[N];
vector <int> in[N * 2], out[N * 2];
vector <int> one;
unordered_map <int, bool> Map;

void set0 (int d) {
	mark[d] = true;
	type[d] = 0;
	for (int v: in[d])
		if (!mark[v])
			set0(v);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	pw[0] = 1;
	for (int i = 1; i < N; i++)
		pw[i] = (2 * pw[i - 1]) % MOD;
	cin >> n >> m >> s;
	for (int i = 0; i < m; i++)
		type[i] = (s[i] == '?'? 2: s[i] - '0');
	for (int i = m; i < m + n; i++)
		type[i] = 2;

	for (int i = 0; i < m; i++)
		for (int j = 0; j < 2; j++) {
			char c;
			int ind;
			cin >> c >> ind;
			ind--;
			if (c == 'x')
				ind += m;

			in[i].push_back(ind);
			out[ind].push_back(i);
		}

	for (int i = 0; i < m + n; i++)
		if (type[i] == 0 && !mark[i])
			set0(i);

	for (int i = 0; i < m + n; i++)
		mark[i] = 0;

	for (int i = 0; i < m; i++) {
		if (type[i] == 0)
			continue;

		for (int v: in[i]) {
			if (type[v] == 0)
				continue;

			if (m <= v)
				bt[i][v - m] = true;
			else
				bt[i] |= bt[v];

			if (type[v] == 1)
				type[i] = 1;
		}
		if (bt[i].count() == 0)
			type[i] = 0;
	}

	for (int i = m - 1; ~i; i--) {
		if (type[i] != 1)
			continue;
		if (type[in[i][0]] == 1 || type[in[i][1]] == 1)
			continue;
		if (type[in[i][0]] == 2 && type[in[i][1]] == 2) {
			// one.push_back(i);
			continue;
		}

		if (type[in[i][0]] == 0)
			type[in[i][1]] = 1;
		else
			type[in[i][0]] = 1;
	}

	for (int i = 0; i < m; i++) {
		if (type[i] != 1)
			continue;
		int val = 0;
		for (int j = 0; j < n; j++)
			if (bt[i][j])
				val = (val + pw[j]) % MOD;
		Map[val] = true;
	}

	for (int i = 0; i < m; i++) {
		if (type[i] != 2)
			continue;
		int val = 0;
		for (int j = 0; j < n; j++)
			if (bt[i][j])
				val = (val + pw[j]) % MOD;

		if (Map[val])
			type[i] = 1;
		if (type[in[i][0]] == 1 || type[in[i][1]] == 1)
			type[i] = 1;
	}

	for (int i = m - 1; ~i; i--) {
		if (type[i] != 1)
			continue;
		if (type[in[i][0]] == 1 || type[in[i][1]] == 1)
			continue;
		if (type[in[i][0]] == 2 && type[in[i][1]] == 2) {
			one.push_back(i);
			continue;
		}

		if (type[in[i][0]] == 0)
			type[in[i][1]] = 1;
		else
			type[in[i][0]] = 1;
	}

	for (int i = 0; i < m; i++) {
		if (type[i] != 2)
			continue;
		if (type[in[i][0]] == 1 || type[in[i][1]] == 1) {
			type[i] = 1;
			continue;
		}
		if (type[in[i][0]] == 0 || type[in[i][1]] == 0)
			continue;

		for (int v: one)
			if ((bt[i] & bt[v]) == bt[v]) {
				type[i] = 1;
				break;
			}
	}

	for (int i = 0; i < m; i++)
		cout << (type[i] == 2? '?': char('0' + type[i]));
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 6 ms 1920 KB Output is correct
9 Correct 6 ms 1792 KB Output is correct
10 Correct 6 ms 1920 KB Output is correct
11 Correct 6 ms 1920 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 6 ms 1920 KB Output is correct
14 Correct 7 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 6 ms 1920 KB Output is correct
9 Correct 6 ms 1792 KB Output is correct
10 Correct 6 ms 1920 KB Output is correct
11 Correct 6 ms 1920 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 6 ms 1920 KB Output is correct
14 Correct 7 ms 1920 KB Output is correct
15 Correct 22 ms 9216 KB Output is correct
16 Correct 60 ms 10524 KB Output is correct
17 Correct 27 ms 12032 KB Output is correct
18 Correct 491 ms 14548 KB Output is correct
19 Correct 39 ms 10496 KB Output is correct
20 Correct 425 ms 14456 KB Output is correct
21 Correct 928 ms 14840 KB Output is correct
22 Correct 666 ms 14200 KB Output is correct
23 Correct 733 ms 14708 KB Output is correct
24 Correct 634 ms 14712 KB Output is correct
25 Execution timed out 4046 ms 14076 KB Time limit exceeded
26 Halted 0 ms 0 KB -