QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#429540#8770. Comparatorkaruna#AC ✓201ms21612kbC++203.4kb2024-06-02 16:40:562024-06-02 16:40:56

Judging History

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

  • [2024-06-02 16:40:56]
  • 评测
  • 测评结果:AC
  • 用时:201ms
  • 内存:21612kb
  • [2024-06-02 16:40:56]
  • 提交

answer

#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

bool eval(string s)
{
	vector<int> st, V;
	for(auto c : s)
	{
		if(c == '0') V.push_back(0);
		else if(c == '1') V.push_back(1);
		else if(c == '(') st.push_back(-1);
		else if(c == ')')
		{
			while(st.back() != -1) V.push_back(st.back()), st.pop_back();
			st.pop_back();
		}
		else
		{
			int k;
			if(c == '^') k = 2;
			else if(c == '|') k = 3;
			else if(c == '&') k = 4;
			else if(c == '=') k = 5;
			else k = 6;
			while(st.size() && st.back() > k) V.push_back(st.back()), st.pop_back();
			st.push_back(k); 
		}
	}
	while(st.size()) V.push_back(st.back()), st.pop_back();

	// for(auto i : V) cout << i << ' '; cout << endl;

	vector<int> num;
	for(auto i : V)
	{
		if(i <= 1) num.push_back(i);
		else if(i == 2)
		{
			int x = num.back(); num.pop_back();
			int y = num.back(); num.pop_back();
			num.push_back(x ^ y);
		}
		else if(i == 3)
		{
			int x = num.back(); num.pop_back();
			int y = num.back(); num.pop_back();
			num.push_back(x | y);
		}
		else if(i == 4)
		{
			int x = num.back(); num.pop_back();
			int y = num.back(); num.pop_back();
			num.push_back(x & y);
		}
		else if(i == 5)
		{
			int x = num.back(); num.pop_back();
			int y = num.back(); num.pop_back();
			num.push_back(x == y);
		}
		else
		{
			int x = num.back(); num.pop_back();
			num.push_back(!x);
		}
	}
	assert(num.size() == 1);
	return num[0];
}

bool eval2(string S, int x, int y)
{
	for(int i=0; i<S.size(); i++)
	{
		if(S[i]=='x') S[i]='0'+x;
		if(S[i]=='y') S[i]='0'+y;
	}
	return eval(S);
}

int eval3(string S)
{
	int ret=0;
	ret|=(eval2(S, 0, 0)<<0);
	ret|=(eval2(S, 0, 1)<<1);
	ret|=(eval2(S, 1, 0)<<2);
	ret|=(eval2(S, 1, 1)<<3);
	return ret;
}

const int MAXN = 2e5;
const int MAXK = 10;

int N, K, R;

struct Data
{
	int x, y;
	int res;
	int r;
};
Data A[MAXN+10];
bool alive[MAXN+10];
vector<int> V[11][11], V2;
bool B[1100][1100];

typedef bitset<1100> BS;
BS B1[1100], B2[1100];

bool f(int x, int y)
{
	for(auto it : V2)
	{
		int p=0, q=0;
		if(x&(1<<A[it].x)) p=1;
		if(y&(1<<A[it].y)) q=1;
		int t=p*2+q;
		if(A[it].res&(1<<t)) return A[it].r;
	}
	return R;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	
	// cout << eval("!0^!!0");

	cin >> N >> K;
	for(int i=1; i<=N; i++)
	{
		string S;
		cin >> A[i].x >> A[i].y >> S >> A[i].r;
		A[i].x--; A[i].y--;
		A[i].res = eval3(S);
		V[A[i].x][A[i].y].push_back(i);
	}
	cin >> R;

	for(int i=0; i<K; i++) for(int j=0; j<K; j++)
	{
		int mask = 15;
		for(auto it : V[i][j])
		{
			if((mask & A[it].res) != 0)
			{
				mask &= (~A[it].res);
				alive[it]=1;
			}
		}
	}

	for(int i=1; i<=N; i++) if(alive[i]) V2.push_back(i);

	for(int i=0; i<(1<<K); i++) for(int j=0; j<(1<<K); j++) B[i][j]=f(i, j);

	int ans=0;
	for(int i=0; i<(1<<K); i++) if(B[i][i]!=0) ans++;
	cout << ans << " ";

	ans=0;
	for(int i=0; i<(1<<K); i++) for(int j=0; j<(1<<K); j++) if(B[i][j]==1 && B[j][i]==1) ans++;
	cout << ans << " ";

	ans=0;

	for(int i=0; i<(1<<K); i++) for(int j=0; j<(1<<K); j++)
	{
		B1[i][j]=B[i][j];
		B2[j][i]=B[i][j];
	}

	for(int i=0; i<(1<<K); i++) for(int j=0; j<(1<<K); j++)
	{
		if(B[i][j]==0)
		{
			ans+=(B1[i] & B2[j]).count();
		}
	}
	cout << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5520kb

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

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: 51ms
memory: 6040kb

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: 184ms
memory: 8704kb

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: 30ms
memory: 21612kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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: 1ms
memory: 5848kb

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: 1ms
memory: 5580kb

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: 65ms
memory: 5176kb

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: 1ms
memory: 5660kb

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: 5ms
memory: 6856kb

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 201ms
memory: 8704kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'