QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#427287 | #8770. Comparator | ucup-team1447# | AC ✓ | 429ms | 54668kb | C++14 | 4.9kb | 2024-06-01 11:58:30 | 2024-06-01 11:58:30 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
int mod;
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 1000045
#define inf 0x3f3f3f3f
int n,k;
string s;
int tim[13][13][2][2];
int tp;
bool rev[maxn];
vector<int>st[maxn];
vector<int>op[maxn];
int OP(int x,int y,int o){
// cout<<"OP "<<x<<" "<<y<<" "<<o<<"\n";
if(x==-1){
if(o==4) return !y;
if(o==0) return y;
exit(66);
}
if(o>=4) o-=4,y=!y;
if(o==0) return x&y;
if(o==1) return x|y;
if(o==2) return x^y;
if(o==3) return !(x^y);
exit(666);
}
int clr(int u){
for(int ox:{3,0,1,2}){
int now=st[u][0];
int sz=st[u].size();
vi st2,op2;
For(i,1,sz-1){
if(op[u][i-1]==ox) now=OP(now,st[u][i],ox);
else st2.pb(now),op2.pb(op[u][i-1]),now=st[u][i];
}
st2.pb(now);
st[u]=st2,op[u]=op2;
}
int now=st[u][0];
return now;
}
int calc(string s,bool x,bool y){
tp=0;
// cout<<"S "<<s<<"\n";
st[tp].clear(),op[tp].clear(),rev[tp]=0;
auto GO=[&](int tp,int now){
st[tp].pb(now^rev[tp]);
rev[tp]=0;
};
For(i,0,SZ(s)-1){
// cout<<"i,tp "<<i<<" "<<tp<<"\n";
char c=s[i];
if(c=='('){
++tp;
st[tp].clear(),op[tp].clear(),rev[tp]=0;
continue;
}
if(c==')'){
int now=clr(tp);
--tp;
GO(tp,now);
continue;
}
if(c=='&' || c=='|' || c=='^' || c=='='){
int o=0;
if(c=='|') o=1;
if(c=='^') o=2;
if(c=='=') o=3;
op[tp].pb(o);
rev[tp]=0;
continue;
}
if(c=='!'){
rev[tp]^=1;
continue;
}
//cout<<"char c="<<c<<"\n";
int now=0;
if(c=='0' || c=='1') now=c-'0';
else if(c=='x') now=x;
else if(c=='y') now=y;
else exit(233);
GO(tp,now);
}
if(tp!=0) exit(123);
int res=clr(0);
// cout<<"calc "<<s<<" "<<x<<" "<<y<<" "<<res<<"\n";
return res;
}
int ans[maxn];
bitset<1030>g[1030],h[1030];
signed main()
{
cin>>n>>k;
For(i,1,n){
int u,v; cin>>u>>v;
string s;cin>>s;
For(x,0,1) For(y,0,1) {
if(calc(s,x,y)){
if(!tim[u][v][x][y]) tim[u][v][x][y]=i;
}
}
cin>>ans[i];
}
cin>>ans[n+1];
For(s,0,(1<<k)-1)
For(t,0,(1<<k)-1) {
int mn=n+1;
For(i,0,k-1) For(j,0,k-1)
if(tim[i+1][j+1][s>>i&1][t>>j&1]){
mn=min(mn,tim[i+1][j+1][s>>i&1][t>>j&1]);
}
g[s][t]=ans[mn];
}
int res1=0,res2=0; long long res3=0;
n=(1<<k);
For(i,0,n-1) For(j,0,n-1) h[i][j]=(!g[i][j]);
For(i,0,n-1) {
res1+=(g[i][i]!=0);
For(j,0,n-1)
res2+=(g[i][j]==1 && g[j][i]==1);
}
For(i,0,n-1){
For(j,0,n-1) if(g[i][j]) {
// For(k,0,n-1)
// res3+=(g[i][j] && g[j][k] && !g[i][k]);
res3+=((g[j])&(h[i])).count();
}
}
cout<<res1<<" "<<res2<<" "<<res3;
return 0;
}
/*
10 10
1 2 2 2 5 2 3 4 3
1 10 5 7
2 4 3 4 5 6
*/
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 50840kb
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: 8ms
memory: 54668kb
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: 165ms
memory: 50864kb
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: 429ms
memory: 52492kb
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: 34ms
memory: 52824kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 8ms
memory: 52696kb
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: 8ms
memory: 50640kb
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: 12ms
memory: 51644kb
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: 7ms
memory: 51276kb
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: 125ms
memory: 51244kb
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: 4ms
memory: 52732kb
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: 44ms
memory: 54584kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 380ms
memory: 52652kb
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: 4ms
memory: 51924kb
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: 3ms
memory: 51668kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'