QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#566591 | #9319. Bull Farm | Uraboku | TL | 66ms | 12492kb | C++14 | 3.1kb | 2024-09-16 00:38:27 | 2024-09-16 00:38:30 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define O4 __inline__ __attribute__((always_inline))
#define inf 0x7fffffff
#define UL unsigned LL
#define LD long double
#ifdef ONLINE_JUDGE
#define getchar nc
#endif
//#define int LL
namespace FastIO{
O4 char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
O4 int read(){
char t;int u=0,k=1;t=getchar();
while(t<'0'||t>'9'){if(t==EOF)return -233;if(t=='-')k=-1;t=getchar();}
while(t>='0'&&t<='9'){u=u*10+t-'0';t=getchar();}
return u*k;
}
template <typename T>
O4 void read(T &u){
char t;T k=1;u=0;t=getchar();
while(t<'0'||t>'9'){if(t=='-')k=-1;t=getchar();}
while(t>='0'&&t<='9'){u=u*10+t-'0';t=getchar();}
if(t=='.'){
T mass=0.1;t=getchar();
while(t>='0'&&t<='9'){u+=mass*(t-'0');mass/=10;t=getchar();}
}u*=k;
}
O4 int read(char asd[]){
char t=getchar();int u=0;
while(t==' '||t=='\n'||t=='\r')t=getchar();
if(t==EOF)return -1;
while(t!=' '&&t!='\n'&&t!=EOF&&t!='\r')asd[u++]=t,t=getchar();
asd[u]='\0';return u;
}
// char sr[1<<23],z[23];int C=-1,Z;
// O4 void wer(int x,char T){
// int y=0;if(x<0)y=1,x=-x;
// while(z[++Z]=x%10+'0',x/=10);if(y)z[++Z]='-';
// while(sr[++C]=z[Z],--Z);sr[++C]=T;
// }
// O4 void wer(char T[],char QWQ){
// for(int i=0;T[i]!='\0';i++)sr[++C]=T[i];
// sr[++C]=QWQ;
// }
// O4 void out(){fwrite(sr,1,C+1,stdout);C=-1;}
}
using namespace std;
using namespace FastIO;
const int N=2005,M=1e6+5;
int n,q,l;
struct sss{
int a,b,c,num;
}que[M];
int mp[N][N];
int vis[N];
char ans[M];
bool MP[N][N];
char QwQ(){
char yy=getchar();
while(yy<48||yy>100)yy=getchar();
return yy;
}
int QWQ(){
int yy=(QwQ()-48)*50;
yy+=QwQ()-48;
return yy;
}
int rd[N];
void link(int a,int b){
if(MP[a][b])return;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
MP[i][j]|=(MP[i][a]&MP[b][j]);
}
void add(int x){
memset(rd,0,sizeof rd);
int a1=0,a2=0,ze=0;
for(int i=1;i<=n;i++){
int t=mp[x][i];
if(rd[t]){
if(a1)return;
a1=rd[t];
a2=i;
}
rd[t]=i;
}
if(!a1){
for(int i=1;i<=n;i++)link(i,mp[x][i]);
}
else{
for(int i=1;i<=n;i++)
if(rd[i]==0)ze=i;
if(a1!=ze)link(a1,ze);
if(a2!=ze)link(a2,ze);
}
}
int yy=0;
void solve(){
memset(MP,0,sizeof MP);
n=read();l=read();q=read();
for(int i=1;i<=l;i++)
for(int j=1;j<=n;j++)mp[i][j]=QWQ();
for(int i=1;i<=n;i++)MP[i][i]=1;
for(int i=1;i<=q;i++){
que[i].a=QWQ();
que[i].b=QWQ();
que[i].c=QWQ();
que[i].num=i;
}
sort(que+1,que+1+q,[](sss a,sss b){return a.c<b.c;});
int now=0;
for(int i=1;i<=q;i++){
while(now!=que[i].c){
now++;
add(now);
}
ans[que[i].num-1]=MP[que[i].a][que[i].b]?'1':'0';
}
for(int i=0;i<q;i++)putchar(ans[i]);putchar('\n');
}
signed main(){
int T=read();
while(T--)solve();
}
/*
3
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 12076kb
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: 2ms
memory: 12492kb
input:
1 3 3 6 020202 030301 030201 020102 030203 010201 010303 020303 010202
output:
010101
result:
ok single line: '010101'
Test #3:
score: 0
Accepted
time: 66ms
memory: 11252kb
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:
011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...
result:
ok 200 lines
Test #4:
score: -100
Time Limit Exceeded
input:
1 2000 1 1000000 M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...