답안 #232297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232297 2020-05-16T14:53:34 Z pedy4000 Ili (COI17_ili) C++14
49 / 100
4000 ms 14716 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;
	}

	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 1408 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 5 ms 1408 KB Output is correct
4 Correct 5 ms 1408 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 6 ms 1408 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1408 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 5 ms 1408 KB Output is correct
4 Correct 5 ms 1408 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 6 ms 1408 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 6 ms 1920 KB Output is correct
9 Correct 7 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 8 ms 2048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1408 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 5 ms 1408 KB Output is correct
4 Correct 5 ms 1408 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 6 ms 1408 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 6 ms 1920 KB Output is correct
9 Correct 7 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 8 ms 2048 KB Output is correct
15 Correct 29 ms 9088 KB Output is correct
16 Correct 85 ms 10616 KB Output is correct
17 Correct 32 ms 12032 KB Output is correct
18 Correct 620 ms 14540 KB Output is correct
19 Correct 59 ms 10496 KB Output is correct
20 Correct 552 ms 14332 KB Output is correct
21 Correct 1151 ms 14716 KB Output is correct
22 Correct 707 ms 14072 KB Output is correct
23 Correct 762 ms 14632 KB Output is correct
24 Correct 685 ms 14712 KB Output is correct
25 Execution timed out 4098 ms 14080 KB Time limit exceeded
26 Halted 0 ms 0 KB -