QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#572042 | #9319. Bull Farm | ship2077# | WA | 26ms | 3996kb | C++23 | 1.5kb | 2024-09-18 11:23:49 | 2024-09-18 11:23:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=2005;
int n,m,q,p[M][M],ans[M];
vector<int>vec[M];bitset<M>bit[M];
vector<tuple<int,int,int>>qry[M];
void link(int x,int y){
if (bit[x][y]) return;
for (int i=1;i<=n;i++)
if (bit[i][x])
bit[i]|=bit[y];
}
void solve(){
cin>>n>>m>>q;
for (int i=1;i<=m;i++){
string str;cin>>str;
for (int j=1;j<=n;j++)
p[i][j]=(str[j*2-2]-'0')*50+str[j*2-1]-'0';
}
for (int i=1;i<=m;i++) qry[i].clear();
for (int i=1;i<=q;i++){
string str;cin>>str;
int a=(str[0]-'0')*50+str[1]-'0';
int b=(str[2]-'0')*50+str[3]-'0';
int c=(str[4]-'0')*50+str[5]-'0';
if (a==b) {ans[i]=1;continue;}
if (c) qry[c].emplace_back(a,b,i); else ans[i]=0;
}
for (int i=1;i<=n;i++) bit[i].reset(),bit[i][i]=1;
for (int i=1;i<=m;i++){
for (int j=1;j<=n;j++) vec[j].clear();
int cnt=0,pos=0;
for (int j=1;j<=n;j++) vec[p[i][j]].emplace_back(j);
for (int j=1;j<=n;j++)
if (vec[j].size()>1)
cnt+=vec[j].size()-1,pos=j;
if (cnt>1) goto jumping;
if (!cnt){
for (int j=1;j<=n;j++) link(j,p[i][j]);
goto jumping;
}
{
int p=0;
for (int i=1;i<=n;i++)
if (vec[i].empty()){
p=i;break;
}
link(vec[pos][0],p);link(vec[pos][1],p);
}
jumping:
for (auto [a,b,id]:qry[i])
ans[id]=bit[a][b];
}
for (int i=1;i<=q;i++) putchar(ans[i]+'0');puts("");
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;cin>>T;while (T--) solve();return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 0ms
memory: 3608kb
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: 26ms
memory: 3996kb
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:
011110001101001101111111111111111101111110110111011110110110110011010111011111111111111101001101111110111111110111111111111101011111111110111111111111111111110001100101011111111111111111111011101111111101111101111111101111111111111111011011110100111110110111110111011100111111101110111111111001110110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110001101001101111111111111...1111111111111110100111111111011'