QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#429171#8770. Comparatorucup-team191#AC ✓228ms109800kbC++232.7kb2024-06-02 02:26:272024-06-02 02:26:28

Judging History

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

  • [2024-06-02 02:26:28]
  • 评测
  • 测评结果:AC
  • 用时:228ms
  • 内存:109800kb
  • [2024-06-02 02:26:27]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

const int N=1000010,MOD=1e9+7,M=1<<10;
const char en='\n';
const ll LLINF=1ll<<60;

string st;
int pri[300],ps[N];
string priord="^|&=!";
vi poj[N][7];

int bef(int i,int j,int x)
{
	auto it=lower_bound(all(poj[i][j]),x);
	if (it==poj[i][j].begin()) return -1;
	--it;
	return *it;
}

int ev(int l,int r)
{
	if (l==r-1) return st[l]-'0';
	//cout<<"BEGIN "<<l<<' '<<r<<' '<<st
	for (int i=0;i<5;++i)
	{
		int po=bef(ps[l],i,r);
		if (po<l) continue;
		if (priord[i]=='!')
		{
			po=l;
			return !ev(l+1,r);
		}
		int x=ev(l,po),y=ev(po+1,r);
		if (priord[i]=='^') return x^y;
		if (priord[i]=='|') return x|y;
		if (priord[i]=='&') return x&y;
		if (priord[i]=='=') return x==y;
	}
	//cout<<l<<' '<<r<<endl;
	assert(st[l]=='(' && st[r-1]==')');
	return ev(l+1,r-1);
}

int eva(string s)
{
	ps[0]=0;
	for (int i=0;i<(int)s.size();++i) for (int j=0;j<(int)priord.size();++j) poj[i][j].clear();
	for (int i=0;i<(int)s.size();++i)
	{
		ps[i+1]=ps[i]+(s[i]=='(')-(s[i]==')');
		if (pri[s[i]]!=-1) poj[ps[i]][pri[s[i]]].pb(i);
	}
	st=s;
	return ev(0,s.size());
}

int eval(string s,int x,int y)
{
	for (auto&c: s)
	{
		if (c=='x') c=x+'0';
		if (c=='y') c=y+'0';
	}
	return eva(s);
}

int n,k;
bool br[20][20][3][3];
vector<pair<pii,pair<array<int,4>,int>>> ops;
bitset<M> adj[M],con[M];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	memset(pri,-1,sizeof(pri));
	for (int i=0;i<(int)priord.size();++i) pri[priord[i]]=i;
	cin>>n>>k;
	for (int i=0;i<n;++i)
	{
		int x,y,r;
		string u;
		cin>>x>>y>>u>>r;
		--x;
		--y;
		bool worth=0;
		array<int,4> vas;
		for (int a=0;a<2;++a) for (int b=0;b<2;++b)
		{
			vas[a*2+b]=eval(u,a,b);
			//cout<<a<<' '<<b<<' '<<vas[a*2+b]<<en;
			if (vas[a*2+b] && !br[x][y][a][b])
			{
				br[x][y][a][b]=1;
				worth=1;
			}
		}
		if (worth)
		{
			ops.pb({{x,y},{vas,r}});
		}
	}
	int def;
	cin>>def;
	assert(ops.size()<=4*k*k);
	for (int b1=0;b1<(1<<k);++b1) for (int b2=0;b2<(1<<k);++b2)
	{
		int va=-1;
		for (auto x: ops)
		{
			if (x.y.x[((b1>>x.x.x)&1)*2+((b2>>x.x.y)&1)])
			{
				va=x.y.y;
				break;
			}
		}
		if (va==-1) va=def;
		//cout<<b1<<' '<<b2<<' '<<va<<en;
		adj[b1][b2]=va;
		con[b2][b1]=va;
	}
	int an1=0,an2=0,an3=0,m=1<<k;
	for (int i=0;i<m;++i) an1+=adj[i][i];
	for (int i=0;i<m;++i) for (int j=0;j<m;++j) an2+=adj[i][j] && adj[j][i];
	for (int i=0;i<m;++i) for (int j=0;j<m;++j) if (!adj[i][j]) an3+=(adj[i]&con[j]).count();
	cout<<an1<<' '<<an2<<' '<<an3<<en;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 7744kb

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

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: 177ms
memory: 5816kb

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: 140ms
memory: 6008kb

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: 228ms
memory: 109800kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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: 91ms
memory: 6380kb

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

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: 15ms
memory: 8196kb

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 126ms
memory: 7784kb

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: 6ms
memory: 5636kb

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: 6ms
memory: 3888kb

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'