QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643929#8770. Comparatorainta#AC ✓332ms31736kbC++206.4kb2024-10-16 08:20:022024-10-16 08:20:03

Judging History

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

  • [2024-10-16 08:20:03]
  • 评测
  • 测评结果:AC
  • 用时:332ms
  • 内存:31736kb
  • [2024-10-16 08:20:02]
  • 提交

answer

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

#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define rep(i,b) rng(i,0,b-1)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
#define per(i,b) gnr(i,b-1,0)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long ll;
using pii=pair<int,int>;
using vi=vc<int>;
using uint=unsigned;
using ull=unsigned long long;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using t3=tuple<int,int,int>;

ll rand_int(ll l, ll r) { //[l, r]
	#ifdef LOCAL
	static mt19937_64 gen;
	#else
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    #endif
    return uniform_int_distribution<ll>(l, r)(gen);
}


struct modinfo{uint mod,root;};
template<modinfo const&ref>
struct modular{
	static constexpr uint const &mod=ref.mod;
	static modular root(){return modular(ref.root);}
	uint v;
	//modular(initializer_list<uint>ls):v(*ls.bg){}
	modular(ll vv=0){s(vv%mod+mod);}
	modular& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	modular operator-()const{return modular()-*this;}
	modular& operator+=(const modular&rhs){return s(v+rhs.v);}
	modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);}
	modular&operator*=(const modular&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	modular&operator/=(const modular&rhs){return *this*=rhs.inv();}
	modular operator+(const modular&rhs)const{return modular(*this)+=rhs;}
	modular operator-(const modular&rhs)const{return modular(*this)-=rhs;}
	modular operator*(const modular&rhs)const{return modular(*this)*=rhs;}
	modular operator/(const modular&rhs)const{return modular(*this)/=rhs;}
	modular pow(int n)const{
		modular res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modular inv()const{return pow(mod-2);}
	/*modular inv()const{
		int x,y;
		int g=extgcd(v,mod,x,y);
		assert(g==1);
		if(x<0)x+=mod;
		return modular(x);
	}*/
	friend modular operator+(int x,const modular&y){
		return modular(x)+y;
	}
	friend modular operator-(int x,const modular&y){
		return modular(x)-y;
	}
	friend modular operator*(int x,const modular&y){
		return modular(x)*y;
	}
	friend modular operator/(int x,const modular&y){
		return modular(x)/y;
	}
	friend ostream& operator<<(ostream&os,const modular&m){
		return os<<m.v;
	}
	friend istream& operator>>(istream&is,modular&m){
		ll x;is>>x;
		m=modular(x);
		return is;
	}
	bool operator<(const modular&r)const{return v<r.v;}
	bool operator==(const modular&r)const{return v==r.v;}
	bool operator!=(const modular&r)const{return v!=r.v;}
	explicit operator bool()const{
		return v;
	}
};
extern constexpr modinfo base{998244353,0};
using mint=modular<base>;
using pdi = pair<double, int>;
using ld = long double;
#define N_  1010010
const int SZ = (1<<19);

int Q, W;
char p[N_], q[N_];
int st[N_], Mat[N_];
int Go(int b, int e){
	string s="";
	for(int i=b;i<=e;i++){
		if(p[i]=='('){
			s += Go(i+1,Mat[i]-1) + '0';
			i=Mat[i];
		}
		else s += p[i];
	}
	int n = s.size();
	string ss="";
	for(int i=0;i<n;i++){
		if(s[i]=='!'){
			for(int j=i;j<n;j++){
				if(s[j]!='!'){
					assert(s[j]=='0'||s[j]=='1');
					int x = s[j]-'0';
					if((j-i)%2) ss += (!x)+'0';
					else ss += x+'0';
					i = j;
					break;
				}
			}
		}
		else ss += s[i];
	}
	n = ss.size();
	vi V;
	rep(i,n){
		if(ss[i]=='0'||ss[i]=='1'){
			V.pb(ss[i]-'0');
			continue;
		}
		int l = si(V);
		if(ss[i]=='='){
			while(si(V)>=3 && V[l-2] == -1){
				int c = (V[l-1] == V[l-3]);
				V.pop_back();V.pop_back();V.pop_back(); V.pb(c);
				l=si(V);
			}
			V.pb(-1);
		}
		if(ss[i]=='&'){
			while(si(V)>=3 && V[l-2] >= -2){
				int c;
				if(V[l-2]==-1) c = (V[l-1] == V[l-3]);
				if(V[l-2]==-2) c = (V[l-1] & V[l-3]);
				V.pop_back();V.pop_back();V.pop_back(); V.pb(c);
				l=si(V);
			}
			V.pb(-2);
		}
		if(ss[i]=='|'){
			while(si(V)>=3 && V[l-2] >= -3){
				int c;
				if(V[l-2]==-1) c = (V[l-1] == V[l-3]);
				if(V[l-2]==-2) c = (V[l-1] & V[l-3]);
				if(V[l-2]==-3) c = (V[l-1] | V[l-3]);
				V.pop_back();V.pop_back();V.pop_back(); V.pb(c);
				l=si(V);
			}
			V.pb(-3);
		}
		if(ss[i]=='^'){
			while(si(V)>=3 && V[l-2] >= -3){
				int c;
				if(V[l-2]==-1) c = (V[l-1] == V[l-3]);
				if(V[l-2]==-2) c = (V[l-1] & V[l-3]);
				if(V[l-2]==-3) c = (V[l-1] | V[l-3]);
				if(V[l-2]==-4) c = (V[l-1] ^ V[l-3]);
				V.pop_back();V.pop_back();V.pop_back(); V.pb(c);
				l=si(V);
			}
			V.pb(-4);
		}
	}
	int l = si(V);
	while(si(V)>=3){
		int c;
		if(V[l-2]==-1) c = (V[l-1] == V[l-3]);
		if(V[l-2]==-2) c = (V[l-1] & V[l-3]);
		if(V[l-2]==-3) c = (V[l-1] | V[l-3]);
		if(V[l-2]==-4) c = (V[l-1] ^ V[l-3]);
		V.pop_back();V.pop_back();V.pop_back(); V.pb(c);
		l=si(V);
	}
	assert(si(V)==1);
	return V[0];
}
int Calc(int n, int x, int y){
	int top=0;
	rep(i,n){
		q[i]=p[i];
		if(p[i]=='x')p[i]='0'+x;
		if(p[i]=='y')p[i]='0'+y;
	}
	rep(i,n){
		if(p[i]=='(')st[++top]=i;
		if(p[i]==')'){
			Mat[i]=st[top];Mat[st[top]]=i;top--;
		}
	}
	int a = Go(0,n-1);
	rep(i,n)p[i]=q[i];
	return a;
}
int m, K, U[10][10][4][2], w[1<<10][1<<10];
bitset<1024>B[1024];
void Solve(){
	scanf("%d%d",&m,&K);
	rep(i,K)rep(j,K)rep(k,4)U[i][j][k][0]=m;
	rep(i,m){
		int a,b, r;
		scanf("%d%d",&a,&b);
		a--,b--;
		scanf("%s",p);
		scanf("%d",&r);
		int n = strlen(p);
		rep(x,2){
			rep(y,2){
				if(Calc(n,x,y) && U[a][b][x*2+y][0] > i){
					U[a][b][x*2+y][0] = i;
					U[a][b][x*2+y][1] = r;
				}
			}
		}
	}
	int xx;scanf("%d",&xx);
	rep(i,K)rep(j,K)rep(k,4)if(U[i][j][k][0]==m)U[i][j][k][1]=xx;
	rep(i,(1<<K)){
		rep(j,(1<<K)){
			int Mn = 1e9, t=0;
			rep(k,K){
				rep(l,K){
					int x = (i>>k)&1;
					int y = (j>>l)&1;
					if(Mn > U[k][l][x*2+y][0]){
						Mn = U[k][l][x*2+y][0];
						t=U[k][l][x*2+y][1];
					}
				}
			}
			w[i][j]=t;
			B[i][j]=t;
			//printf("%d",w[i][j]);
		}
		//puts("");
	}
	int r1=0,r2=0,r3=0;
	rep(i,(1<<K)){
		if(w[i][i])r1++;
		rep(j,(1<<K)){
			if(w[i][j]&&w[j][i])r2++;
			if(w[i][j]){
				r3 += (B[j]&(~B[i])).count();
			}
		}
	}
	printf("%d %d %d\n",r1,r2,r3);
}

int main(){
	int TC=1;
	//scanf("%d",&TC);
	while(TC--){
		Solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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

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

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

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 245ms
memory: 10428kb

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

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'