QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#439371#8770. ComparatorPetroTarnavskyiAC ✓386ms46780kbC++143.5kb2024-06-11 20:34:062024-06-11 20:34:07

Judging History

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

  • [2024-06-11 20:34:07]
  • 评测
  • 测评结果:AC
  • 用时:386ms
  • 内存:46780kb
  • [2024-06-11 20:34:06]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 200'447;
const int K = 10;
VI f[N];
string s[N];
int res[N];
int idxA[N];
int idxB[N];
int val[K][K][2][2];
int h[1 << K][1 << K];
bitset<(1 << K)> bts[1 << K];
bitset<(1 << K)> rbts[1 << K];

void upd(int& a, int b)
{
	a = min(a, b);
}

bool g(bool x, bool y, char c)
{
	if (c == '=')
		return x == y;
	if (c == '&')
		return x && y;
	if (c == '|')
		return x || y;
	return x ^ y;
}

bool eval(int i, int l, int r, bool x, bool y)
{
	//cerr << s[i] << ' ' << l << ' ' << r << '\n';
	bool nt = false;
	VI v;
	string op = "";
	FOR (j, l, r)
	{
		if (s[i][j] == '!')
			nt ^= 1;
		else if (s[i][j] == '(')
		{
			v.PB(eval(i, j + 1, f[i][j], x, y) ^ nt);
			nt = 0;
			j = f[i][j];
		}
		else if (s[i][j] == 'x')
		{
			v.PB(x ^ nt);
			nt = 0;
		}
		else if (s[i][j] == 'y')
		{
			v.PB(y ^ nt);
			nt = 0;
		}
		else if (s[i][j] == '0' || s[i][j] == '1')
		{
			v.PB((s[i][j] - '0') ^ nt);
			nt = 0;
		}
		else
		{
			//cerr << s[i][j] << '\n';
			assert(s[i][j] == '=' || s[i][j] == '&' || s[i][j] == '|' || s[i][j] == '^');
			op += s[i][j];
		}
	}
	string all = "=&|^";
	FOR (t, 0, 4)
	{
		int last = v[0];
		VI v2;
		string op2 = "";
		FOR (j, 0, SZ(op))
		{
			if (op[j] == all[t])
			{
				last = g(last, v[j + 1], op[j]);
			}
			else
			{
				v2.PB(last);
				op2 += op[j];
				last = v[j + 1];
			}
		}
		v2.PB(last);
		v = v2;
		op = op2;
	}
	//cerr << SZ(v) << ' ' << SZ(op) << '\n';
	assert(SZ(v) == 1);
	return v[0];
} 

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	FOR (i, 0, k) FOR (j, 0, k) FOR (vi, 0, 2) FOR (vj, 0, 2) val[i][j][vi][vj] = n;
	FOR (i, 0, n)
	{
		cin >> idxA[i] >> idxB[i];
		idxA[i] = k - idxA[i];
		idxB[i] = k - idxB[i];
		cin >> s[i];
		f[i].resize(SZ(s[i]));
		VI st;
		FOR (j, 0, SZ(s[i]))
		{
			if (s[i][j] == '(')
				st.PB(j);
			else if (s[i][j] == ')')
			{
				f[i][st.back()] = j;
				st.pop_back();
			}
		}
		FOR (vi, 0, 2)
		{
			FOR (vj, 0, 2)
			{
				int x = eval(i, 0, SZ(s[i]), vi, vj);
				//cerr << x;
				if (x)
					upd(val[idxA[i]][idxB[i]][vi][vj], i);
			}
		}
		//cerr << "\n";
		cin >> res[i];
	}
	cin >> res[n];
	
	//FOR (i, 0, k) FOR (j, 0, k) FOR (vi, 0, 2) FOR (vj, 0, 2) 
	//	cerr << i << ' ' << j << ' ' << vi << ' ' << vj << ' ' << val[i][j][vi][vj] << '\n';
	
	int a = 0;
	int b = 0;
	int c = 0;
	
	FOR (mask1, 0, 1 << k)
	{
		FOR (mask2, 0, 1 << k)
		{
			int mn = n;
			FOR (i, 0, k)
			{
				FOR (j, 0, k)
				{
					int vi = (mask1 >> i) & 1;
					int vj = (mask2 >> j) & 1;
					upd(mn, val[i][j][vi][vj]);
				}
			}
			h[mask1][mask2] = res[mn];
			if (mask1 == mask2 && h[mask1][mask2] == 1)
				a++;
			
			if (h[mask1][mask2])
				bts[mask1][mask2] = rbts[mask2][mask1] = 1;
		}
	}
	//b = (1 << k) * ((1 << k) - 1) / 2;
	FOR (x, 0, 1 << k)
	{
		FOR (y, 0, 1 << k)
		{
			if (h[x][y] && h[y][x])
				b++;
		}
	}
	//b += 2 * a;
	FOR (x, 0, 1 << k)
	{
		FOR (z, 0, 1 << k)
		{
			if (h[x][z] == 0)
			{
				c += (bts[x] & rbts[z]).count();
			}
		}
	}
	cout << a << ' ' << b << ' ' << c << '\n';
	return 0;
}

詳細信息

Test #1:

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

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: 3ms
memory: 14548kb

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: 179ms
memory: 19320kb

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: 386ms
memory: 27860kb

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: 12ms
memory: 19232kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 3ms
memory: 14784kb

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

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

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

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: 172ms
memory: 18992kb

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: 2ms
memory: 14568kb

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: 59ms
memory: 46780kb

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 346ms
memory: 27756kb

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

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: 2ms
memory: 14528kb

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'