QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577888 | #9319. Bull Farm | rotcar07 | WA | 228ms | 13520kb | C++20 | 1.2kb | 2024-09-20 15:16:59 | 2024-09-20 15:17:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=2e3+5,M=1e6+5;
int n,m,q;
int t[N][N],A[M],B[M];
vector<int> Q[N];
bool ans[M];bitset<N> b[N];
vector<int> tmp[N];
inline void solve(){
cin>>n>>m>>q;
auto tr=[&](char c,char d){return (c-48)*50+d-48;};
for(int i=1;i<=m;i++){
string s;cin>>s;
for(int j=0;j<n;j++) t[i][j+1]=tr(s[j<<1],s[j<<1|1]);
}
for(int i=1;i<=n;i++) b[i].reset(),b[i].set(i);
for(int i=1;i<=q;i++){
string s;cin>>s;
A[i]=tr(s[0],s[1]),B[i]=tr(s[2],s[3]);
int c=tr(s[4],s[5]);
if(!c) ans[i]=(A[i]==B[i]);
else Q[c].push_back(i);
}
for(int i=1;i<=m;i++){
for(int i=1;i<=n;i++) tmp[i].clear();
for(int j=1;j<=n;j++) tmp[t[i][j]].push_back(j);
int pos=0,cnt=0,emp=0;
for(int i=1;i<=n;i++) if(tmp[i].size()>1) cnt+=tmp[i].size()-1,pos=i;else if(tmp[i].empty()) emp=i;
auto con=[&](int x,int y){
if(!b[x][y]) for(int i=1;i<=n;i++) if(b[i][x]&&!b[i][y]) b[i]|=b[y];
};
if(!cnt){
for(int j=1;j<=n;j++) con(j,t[i][j]);
}
else if(cnt==1) con(tmp[pos][0],emp),con(tmp[pos][1],emp);
for(auto x:Q[i]) ans[x]=b[A[x]][B[x]];
}
for(int i=1;i<=q;i++) putchar(ans[i]+'0');putchar('\n');
}
int main(){
int t;cin>>t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9756kb
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: 9740kb
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: 228ms
memory: 13520kb
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:
wrong answer 2nd lines differ - expected: '111111011101111011011111111111...1111110111111110111011110101111', found: '111111011101111111111111111111...1111111111111110111111111111111'