QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#579533 | #9319. Bull Farm | lmeowdn# | WA | 46ms | 11952kb | C++14 | 3.3kb | 2024-09-21 14:49:40 | 2024-09-21 14:49:42 |
Judging History
answer
//Shirasu Azusa 2024.09
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=2005,M=1e6+5;
int n,m,q,f[N][N],id[N],a[M],b[M],t[N][N],ans[N];
bitset<N> fr[N],to[N];
vi qq[N];
int getint(char a,char b) {
return (a-48)*50+(b-48);
}
int find(int i) {
return i==id[i]?i:id[i]=find(id[i]);
}
signed main() {
int T=read();
while(T--) {
n=read(), m=read(), q=read();
rep(i,1,n) rep(j,1,n) f[i][j]=m+1;
rep(i,1,n) fr[i].reset(), to[i].reset();
rep(i,1,n) id[i]=i, fr[i][i]=to[i][i]=1;
rep(i,1,n) f[i][i]=0;
rep(i,1,m) {
static char st[N*2];
scanf("%s",st);
rep(j,1,n) {
int x=j*2-2, y=j*2-1;
t[i][j]=getint(st[x],st[y]);
}
}
rep(i,0,m) qq[i].clear();
rep(i,1,q) {
static char st[10];
scanf("%s",st);
a[i]=getint(st[0],st[1]), b[i]=getint(st[2],st[3]);
int c=getint(st[4],st[5]); qq[c].eb(i);
}
for(int x:qq[0]) ans[x]=(a[x]==b[x]);
rep(i,1,m) {
static int vs[N];
rep(i,1,n) vs[i]=0;
int xc=0,y=0;
rep(j,1,n) vs[t[i][j]]++;
rep(i,1,n) if(vs[i]!=1) {
if(vs[i]==0) {
if(y) {y=-1; break;}
else y=i;
} else xc=i;
}
if(y==0) {
rep(j,1,n) {
int u=j, v=t[i][j];
if(find(u)!=find(v)) {
id[u]=v;
fr[v]|=fr[u];
to[v]|=to[u];
}
}
} else if(y>0) {
rep(j,1,n) if(t[i][j]==xc) {
int u=j, v=y;
u=find(u), v=find(v);
for(int x=fr[u]._Find_first();1<=x&&x<=n;x=fr[u]._Find_next(x)) {
x=find(x);
to[x]|=to[v];
}
for(int x=to[u]._Find_first();1<=x&&x<=n;x=to[u]._Find_next(x)) {
x=find(x);
fr[x]|=fr[u];
}
}
}
for(int x:qq[i]) {
int u=a[x], v=b[x];
u=find(u), v=find(v);
if(to[u][v]) ans[x]=1;
else ans[x]=0;
}
}
rep(i,1,q) putchar('0'+ans[i]); puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9896kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1011 0100
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 9884kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: -100
Wrong Answer
time: 46ms
memory: 11952kb
input:
200 10 10 5000 01060:04020305080709 0103070:060204050908 09070503080401060:02 050308010204090:0607 03010502040607080:09 03080109020504060:07 06050:09040302080107 07080305010409060:02 030809010:0204060507 0:060908070201050304 060700 090:03 09080: 070405 010703 0:0100 080601 030600 070206 0:0:09 08040...
output:
011110001101001101111111111111111101111110110111010110110110110011010111011111111111111101001101111110111111110111111111111101011111111110011111111101111111110001100101011111111111111111111011001111111101111101111111101111111111111111011011110100111110110111110111011100111111101110111111111001110110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101001101111111111111...1111111111111110100111111111011'