QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#437114#8770. ComparatorUSP_USP_USP#ML 204ms3980kbC++233.7kb2024-06-09 05:30:292024-06-09 05:30:30

Judging History

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

  • [2024-06-09 05:30:30]
  • 评测
  • 测评结果:ML
  • 用时:204ms
  • 内存:3980kb
  • [2024-06-09 05:30:29]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define all(v) (v).begin(), (v).end()
#define pb push_back

void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }


bool rec(string s, int&i, bool token){
	if(token){
		assert(i <= int(s.size()));
		if(s[i] == '0'){
			i++;
			return 0;
		}
		if(s[i] == '1'){
			i++;
			return 1;
		}
		if(s[i] == '!'){
			i++;
			return 1^rec(s,i,token);
		}
		if(s[i] == '('){
			i++;
			int u = rec(s,i,0);
			i++;
			return u;
		}
		assert(0);
	}else{
		int ant = 0;
		int op = 0;
		//0 = or, 1 = xor, 2 = &, 3 = equal
		while(true){
			bool at = rec(s,i,1);
			if(op == 0){
				ant = ant|at;
			}else if(op == 1){
				ant = ant^at;
			}else if(op == 2){
				ant = ant&at;
			}else{
				ant = ant == at;
			}
			int sz = s.size();
			if(i == sz) break;
			if(s[i] == '|'){
				op = 0;
			}else if(s[i] == '&'){
				op = 2;
			}else if(s[i] == '^'){
				op = 1;
			}else if(s[i] == '='){
				op = 3;
			}else{
				break;
			}
			i++;
		}
		return ant;
	}
	assert(0);
	return false;
}

string transform(string s, int x, int y){
	int sz  = s.size();
	for(int i = 0; i < sz; i++){
		if(s[i] == 'x'){
			s[i] = char('0'+x);
		}
		if(s[i] == 'y'){
			s[i] = char('0'+y);
		}
	}
	return s;
}

array<int,4> truetable(string s){
	array<int,4> retorno;
	for(int x = 0; x < 2; x++){
		for(int y = 0; y < 2; y++){
			string t = transform(s,x,y);
			int po = 0;
			bool ret = rec(t,po,0);
			retorno[x*2 + y]  = ret;
		}
	}
	return retorno;
}

int mapeia[11][11][2][2];
int tempo[11][11][2][2];

using bit = bitset<1002>;

void solve() {
	int n,k;
	cin >> n >> k;

	for(int i = 0; i < k; i++){
		for(int j = 0; j < k; j++){
			for(int w = 0; w < 2; w++){
				for(int z = 0; z < 2; z++){
					mapeia[i][j][w][z] = -1;
				}
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		int A,B;
		cin >> A >> B;
		A--;
		B--;
		string s;
		cin >> s;
		array<int,4> at = truetable(s);
		int retval;
		cin >> retval;
		for(int x = 0; x < 2; x++){
			for(int y = 0; y < 2; y++){
				if(mapeia[A][B][x][y] != -1) continue;
				int id = x*2+y;
				if(at[id]){
					mapeia[A][B][x][y] = retval;
					tempo[A][B][x][y] = i;
				}
			}
		}
	}
	int base;
	cin >> base;
	for(int i = 0; i < k; i++){
		for(int j = 0; j < k; j++){
			for(int w = 0; w < 2; w++){
				for(int z = 0; z < 2; z++){
					if(mapeia[i][j][w][z] == -1){
						mapeia[i][j][w][z] = base;
						tempo[i][j][w][z] = n;
					}
				}
			}
		}
	}
	vector<bit> g((1<<k));
	for(int mask1 = 0; mask1 < (1<<k); mask1++){
		for(int mask2 = 0; mask2 < (1<<k); mask2++){
			int val = base;
			int tem = n;
			for(int i = 0; i < k; i++){
				for(int j = 0; j < k; j++){
					int x = (mask1>>i)&1;
					int y = (mask2>>j)&1;
					if(tempo[i][j][x][y] < tem){
						tem = tempo[i][j][x][y];
						val = mapeia[i][j][x][y];
					}
				}
			}
			g[mask1][mask2] = val;
		}
	}
	int refle = 0;
	for(int mask = 0; mask < (1<<k); mask++){
		refle += g[mask][mask];
	}
	int sime = 0;
	for(int mask1 = 0; mask1 < (1<<k); mask1++){
		for(int mask2 = 0; mask2 < (1<<k); mask2++){
			if(g[mask1][mask2] == 1){
				sime +=  g[mask2][mask1];
			}
		}
	}
	int trans = 0;
	for(int mask1 = 0; mask1 < (1<<k); mask1++){
		bit neg = g[mask1];
		for(int mask2 = 0; mask2 < (1<<k); mask2++){
			if(neg[mask2]) neg[mask2] = 0;
			else neg[mask2] = 1;
		}
		for(int mask2 = 0; mask2 < (1<<k); mask2++){
			if(g[mask1][mask2]){
				bit at = neg&g[mask2];
				trans += at.count();
			}
		}
	}
	cout << refle << ' ' << sime << ' ' << trans <<'\n';

}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3624kb

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: 166ms
memory: 3980kb

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: 204ms
memory: 3628kb

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: -100
Memory Limit Exceeded

input:

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

output:


result: