QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#701874#8770. Comparatorucup-team5062AC ✓326ms39732kbC++173.0kb2024-11-02 14:51:192024-11-02 14:51:19

Judging History

你现在查看的是最新测评结果

  • [2024-11-02 14:51:19]
  • 评测
  • 测评结果:AC
  • 用时:326ms
  • 内存:39732kb
  • [2024-11-02 14:51:19]
  • 提交

answer

#include <array>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int parse(const string& s) {
	const int L = s.size();
	int pos = 0;
	auto e1 = [&](auto& e1, auto& e2, auto& e3, auto& e4, auto& e5) -> int {
		int res = e2(e1, e2, e3, e4, e5);
		while (pos != L && s[pos] == '^') {
			pos++;
			res ^= e2(e1, e2, e3, e4, e5);
		}
		return res;
	};
	auto e2 = [&](auto& e1, auto& e2, auto& e3, auto& e4, auto& e5) -> int {
		int res = e3(e1, e2, e3, e4, e5);
		while (pos != L && s[pos] == '|') {
			pos++;
			res |= e3(e1, e2, e3, e4, e5);
		}
		return res;
	};
	auto e3 = [&](auto& e1, auto& e2, auto& e3, auto& e4, auto& e5) -> int {
		int res = e4(e1, e2, e3, e4, e5);
		while (pos != L && s[pos] == '&') {
			pos++;
			res &= e4(e1, e2, e3, e4, e5);
		}
		return res;
	};
	auto e4 = [&](auto& e1, auto& e2, auto& e3, auto& e4, auto& e5) -> int {
		int res = e5(e1, e2, e3, e4, e5);
		while (pos != L && s[pos] == '=') {
			pos++;
			res ^= e5(e1, e2, e3, e4, e5) ^ 1;
		}
		return res;
	};
	auto e5 = [&](auto& e1, auto& e2, auto& e3, auto& e4, auto& e5) -> int {
		if (s[pos] == '0') {
			pos++;
			return 0;
		}
		if (s[pos] == '1') {
			pos++;
			return 1;
		}
		if (s[pos] == '!') {
			pos++;
			return 1 - e5(e1, e2, e3, e4, e5);
		}
		pos++; // '('
		int res = e1(e1, e2, e3, e4, e5);
		pos++; // ')'
		return res;
	};
	return e1(e1, e2, e3, e4, e5);
}

int main() {
	// step #1. input & make array
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<bitset<1024> > G(1 << K), H(1 << K);
	vector<vector<array<bool, 4> > > vis(K, vector<array<bool, 4> >(K, {false, false, false, false}));
	for (int i = 0; i < N; i++) {
		int a, b, c; string s;
		cin >> a >> b >> s >> c;
		a--; b--;
		for (int x = 0; x < 2; x++) {
			for (int y = 0; y < 2; y++) {
				string t = s;
				replace(t.begin(), t.end(), 'x', char(x + '0'));
				replace(t.begin(), t.end(), 'y', char(y + '0'));
				int res = parse(t);
				if (res == 1) {
					if (!vis[a][b][x * 2 + y]) {
						vis[a][b][x * 2 + y] = true;
						for (int j = 0; j < (1 << K); j++) {
							if (((j >> a) & 1) == x) {
								for (int k = 0; k < (1 << K); k++) {
									if (((k >> b) & 1) == y && H[j][k] == 0) {
										G[j][k] = c;
										H[j][k] = 1;
									}
								}
							}
						}
					}
				}
			}
		}
	}
	int R;
	cin >> R;
	for (int i = 0; i < (1 << K); i++) {
		for (int j = 0; j < (1 << K); j++) {
			if (H[i][j] == 0) {
				G[i][j] = R;
			}
		}
	}

	// step #2. calculate answer
	int ans1 = 0, ans2 = 0, ans3 = 0;
	for (int i = 0; i < (1 << K); i++) {
		ans1 += int(G[i][i] == 1);
		for (int j = 0; j < (1 << K); j++) {
			ans2 += int(G[i][j] == 1 && G[j][i] == 1);
			if (G[i][j] == 1) {
				ans3 += (~G[i] & G[j]).count();
			}
		}
	}

	// step #3. output
	cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3880kb

input:

3 2
1 1 (x=0)&(y=1) 1
1 1 (x=1)&(y=(x^x)) 0
2 2 (x=1)|(y=0) 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

4 3
2 1 x=0&(y=1) 1
1 2 !x^!!y 0
2 3 ((x|1)=y)&1&1 1
3 1 !x&!x&!x 0
1

output:

3 25 52

result:

ok single line: '3 25 52'

Test #3:

score: 0
Accepted
time: 37ms
memory: 3772kb

input:

1413 3
1 3 0 0
3 3 !x 0
2 2 x=0 1
1 2 !y^0 1
2 3 (x^1) 0
3 2 ((!0)) 1
1 1 !!1=(y) 0
2 2 !(1^x)&y 1
3 2 (y)&1|!!1 0
3 1 !x=(y&y=y) 0
2 1 (((!1)^!x)) 1
2 3 !0=(0&y)=1&y 0
1 2 ((((!0)))|!1) 0
3 1 !(y=!1=x|(!x)) 0
1 1 ((((y=!y)))&!0) 0
2 3 ((y=1)^!1^!!1|0) 1
2 3 1|(!x)&!x|1|(x=1) 1
2 3 !0^!!!!y&0=(!1&!0...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #4:

score: 0
Accepted
time: 326ms
memory: 3652kb

input:

181737 10
5 2 1 1
1 10 !1=!x 0
10 1 (1^x) 0
2 4 !1 1
10 8 y=(!1)^1 1
6 2 !((x&!x)) 1
1 10 !!((!x)|x) 1
7 10 (((0))) 0
7 3 !(1)^!x 0
10 4 (!1)&x 0
7 7 !y&!0 1
8 8 !1=(x)|1^1 1
2 6 ((!!!x)) 0
7 2 1 1
2 2 y=1=0 0
6 3 (!0) 0
6 4 0 0
1 1 (!1) 1
1 8 y 1
3 5 !x|!x^!1 0
4 7 (!0) 0
3 4 !1&1&!1|!0 1
2 7 ((0|1...

output:

1024 1048576 0

result:

ok single line: '1024 1048576 0'

Test #5:

score: 0
Accepted
time: 7ms
memory: 5408kb

input:

1 3
1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

1 1
1 1 x^y|1 0
1

output:

1 1 0

result:

ok single line: '1 1 0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 1
1 1 x&y|1 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

1 1
1 1 x=y|1 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

2 2
1 2 !x&!y 1
1 1 !x&y 0
1

output:

4 12 2

result:

ok single line: '4 12 2'

Test #10:

score: 0
Accepted
time: 13ms
memory: 4024kb

input:

2 10
9 8 ((((!((!x=1))^(!1&(x|x|!y))&((!y&!x=(x=y)))&!((((x=1))&(0=(y))^(!!(!!x^1=x)&(x)^y&1=!x&1=(((!0^(1)^1))^!(((((y))|x|!y))))^!!0=!y&(0)|(y=x&!y&y=x)))=((((!!y&!!0|!0^!0)=!x))))^0&(((!1=!(!x)))|(((((x=1|!y|y)=(!1^1^0^(0)))=!0^1)))=(!(!1^(((((!1)^!x^0))))=(1)^((((y=((x))|(0)|(!1^1)))|(!!!y))=((!...

output:

0 0 0

result:

ok single line: '0 0 0'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

4 3
1 1 !!!!!!x 0
2 1 !!y 1
1 2 !!!!!x 1
2 2 !!!x 0
1

output:

4 16 0

result:

ok single line: '4 16 0'

Test #12:

score: 0
Accepted
time: 24ms
memory: 39732kb

input:

1 1
1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 73ms
memory: 3820kb

input:

200000 10
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10...

output:

512 262144 134217728

result:

ok single line: '512 262144 134217728'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

10 3
3 1 (!x) 1
3 2 !1&x&1&!y 1
2 1 ((x)&y) 1
1 3 0 0
2 2 !1&0=y&0 1
3 3 (!y)^y 1
2 1 0|((!y)) 0
3 2 x 0
2 2 (y|1^x) 0
2 1 ((!0)|y) 0
1

output:

8 64 0

result:

ok single line: '8 64 0'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'