QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#432760#8770. Comparatorideograph_advantage#WA 205ms11808kbC++203.4kb2024-06-07 16:43:312024-06-07 16:43:32

Judging History

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

  • [2024-06-07 16:43:32]
  • 评测
  • 测评结果:WA
  • 用时:205ms
  • 内存:11808kb
  • [2024-06-07 16:43:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define iter(v) v.begin(), v.end()
#define SZ(v) int(v.size())
#define pb emplace_back
#define ff first
#define ss second

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef zisk
void debug(){cerr << "\n";}
template<class T, class ... U>
void debug(T a, U ... b){ cerr << a << " ", debug(b...); }
template<class T> void pary(T l, T r){
	while(l != r) cerr << *l << " ", l++;
	cerr << "\n";
}
#else
#define debug(...) void()
#define pary(...) void()
#endif

template<class A, class B>
ostream& operator<<(ostream& o, pair<A, B> p){
	return o << '(' << p.ff << ',' << p.ss << ')';
}

struct condition{
	int a, b;
	string expr;
	int r;
};

int eval(string &expr, int x, int y){
	//debug("eval", expr, x, y);
	vector<int> stk;
	vector<char> opt;
	auto put_val = [&](int v) -> void{
		//debug("put_val", v);
		while(!opt.empty() && opt.back() != '('){
			if(opt.back() == '!'){
				opt.pop_back();
				v = !v;
				continue;
			}
			int t = stk.back();
			stk.pop_back();
			if(opt.back() == '=')
				opt.pop_back(), v = v == t;
			else if(opt.back() == '&')
				opt.pop_back(), v = v && t;
			else if(opt.back() == '|')
				opt.pop_back(), v = v || t;
			else{ // ^
				opt.pop_back(), v = v ^ t;
			}
		}
		stk.pb(v);
	};
	auto put_opt = [&](char c){
		if(c == ')'){
			assert(!stk.empty() && !opt.empty() && opt.back() == '(');
			int t = stk.back();
			opt.pop_back();
			stk.pop_back();
			put_val(t);
		}
		else{
			opt.pb(c);
		}
	};
	for(char c : expr){
		if(c == '0') put_val(0);
		else if(c == '1') put_val(1);
		else if(c == 'x') put_val(x);
		else if(c == 'y') put_val(y);
		else put_opt(c);
		//debug("cur", c);
		//pary(iter(stk));
		//pary(iter(opt));
	}
	assert(SZ(stk) == 1 && opt.empty());
	return stk[0];
}
inline int get(int i,int k){
	return (i>>k)&1;
}
vector<bitset<1024> > in,out;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	int u=(1<<k);
	in.resize(u);
	out.resize(u);
	vector<condition> opt(n+1);
	for(int i = 0; i < n; i++){
		int a, b;
		string expr;
		int r;
		cin >> a >> b >> expr >> r;
		a--;
		b--;

		opt[i] = condition({a, b, expr, r});
	}
	int else_ret; cin >> else_ret;
	opt[n].r=else_ret;
	int f[10][10][2][2]={0};
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int x=0;x<2;x++){
				for(int y=0;y<2;y++){
					f[i][j][x][y]=n;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int x=0;x<2;x++){
			for(int y=0;y<2;y++){
				int z=eval(opt[i].expr,x,y);
				if(z){
					f[opt[i].a][opt[i].b][x][y]=min(f[opt[i].a][opt[i].b][x][y],i);
				}
			}	
		}
	}
	//debug(f[0][0][0][1],f[0][0][1][0]);
	for(int i=0;i<u;i++){
		for(int j=0;j<u;j++){
			int w=1e9;
			for(int p=0;p<k;p++){
				for(int q=0;q<k;q++){
					w=min(w,f[p][q][get(i,p)][get(j,q)]);
				}
			}
			if(opt[w].r){
				//debug(i,j,w);
				in[i][j]=1;
				out[j][i]=1;
			}
		}
	}
	int cnt1=0,cnt2=0,cnt3=0;
	for(int i=0;i<u;i++){
		if(in[i][i]!=0){
			cnt1++;
		}
	}
	for(int i=0;i<u;i++){
		for(int j=0;j<u;j++){
			if(in[i][j] && in[j][i]){
				cnt2++;
			}
		}
	}
	for(int i=0;i<u;i++){
		for(int j=0;j<u;j++){
			if(in[i][j]){
				continue;
			}
		//	debug(i,j);

		//	cout << (in[i]&out[j]) << "\n";
			cnt3+=(in[i]&out[j]).count();
		}
	}
	cout << cnt1 << " " << cnt2 << " " << cnt3 << "\n";
	// test
	/*
	for(int i = 0; i < n; i++){
		debug("expression", opt[i].expr);
		for(int x : {0, 1}) for(int y : {0, 1}){
			debug("x", x, "y", y, "ret", eval(opt[i].expr, x, y));
		}
	}
	*/

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3844kb

input:

1 1
1 1 x^y|1 0
1

output:

0 0 0

result:

wrong answer 1st lines differ - expected: '1 1 0', found: '0 0 0'