Submission #232298

# Submission time Handle Problem Language Result Execution time Memory
232298 2020-05-16T14:53:47 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;
	}

	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;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1408 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1408 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 1408 KB Output is correct
7 Correct 5 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1408 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1408 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 1408 KB Output is correct
7 Correct 5 ms 1408 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 7 ms 2048 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 7 ms 1920 KB Output is correct
14 Correct 6 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1408 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1408 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 1408 KB Output is correct
7 Correct 5 ms 1408 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 7 ms 2048 KB Output is correct
12 Correct 6 ms 1920 KB Output is correct
13 Correct 7 ms 1920 KB Output is correct
14 Correct 6 ms 2048 KB Output is correct
15 Correct 19 ms 9088 KB Output is correct
16 Correct 87 ms 10568 KB Output is correct
17 Correct 34 ms 12032 KB Output is correct
18 Correct 606 ms 14544 KB Output is correct
19 Correct 61 ms 10496 KB Output is correct
20 Correct 522 ms 14328 KB Output is correct
21 Correct 1221 ms 14840 KB Output is correct
22 Correct 710 ms 14200 KB Output is correct
23 Correct 779 ms 14584 KB Output is correct
24 Correct 676 ms 14712 KB Output is correct
25 Execution timed out 4096 ms 14072 KB Time limit exceeded
26 Halted 0 ms 0 KB -