QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#570695 | #9319. Bull Farm | neetman | WA | 1ms | 7780kb | C++14 | 3.0kb | 2024-09-17 17:09:49 | 2024-09-17 17:09:49 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<bitset>
using namespace std;
const int N = 2e3 + 5, M = 1e6 + 5;
int n, l, q;
int sta[N], top = 0;
bool ans[M];
string s;
bitset<N> bit[N];
struct query{
int a, b, c, id;
}que[M];
struct bottom{
int t[N];
}bot[N];
int decode(int idx){
return ((s[idx] - 48) * 50 + s[idx + 1] - 48);
}
int vis[N], tot;
void dfs(int x, int idx){
vis[x] = 1;
sta[++top] = x;
if(vis[bot[idx].t[x]]) return;
dfs(bot[idx].t[x], idx);
}
void addedge(int idx){
for(int i = 1; i <= n; i ++)
vis[i] = 0;
tot = 0;
for(int i = 1; i <= n; i ++){
int to = bot[idx].t[i];
if(!vis[to]) ++tot;
++ vis[to];
}
if(tot == n){
for(int i = 1; i <= n; i ++)
vis[i] = 0;
for(int i = 1; i <= n; i ++){
if(!vis[i]){
top = 0;
dfs(i, idx);
for(int j = 1, x, y; j < top; j ++){
bit[0][sta[j]] = 1;
}
for(int to = 1; to <= n; to ++){
if((bit[to] & bit[0]).any())
for(int j = 1; j <= top; j ++)
bit[to] |= bit[sta[j]];
}
for(int j = 1, x, y; j < top; j ++){
bit[0][sta[j]] = 0;
}
}
}
}
else if(tot == n - 1){
int x1 = 0, x2 = 0, y;
for(int i = 1; i <= n; i ++){
if(!vis[i])
y = i;
if(vis[bot[idx].t[i]] == 2)
if(!x1)
x1 = i;
else
x2 = i;
}
for(int i = 1; i <= n; i ++){
if(bit[i][x1] || bit[i][x2])
bit[i] |= bit[y];
}
}
}
void init(){
for(int i = 1; i <= q; i ++)
ans[i] = 0;
for(int i = 1; i <= n; i ++){
bit[i].reset();
bit[i][i] = 1;
}
}
int main(){
ios::sync_with_stdio();
int T;
cin >> T;
while(T --){
cin >> n >> l >> q;
init();
for(int i = 1; i <= l; i ++){
cin >> s;
for(int idx = 1; idx <= n; idx ++){
bot[i].t[idx] = decode((idx - 1) * 2);
}
}
for(int i = 1; i <= q; i ++){
cin >> s;
que[i].id = i;
que[i].a = decode(0);
que[i].b = decode(2);
que[i].c = decode(4);
}
sort(que + 1, que + 1 + q, [](query x, query y){
return x.c < y.c;
});
for(int now = 0, i = 1; i <= q; i ++){
while(now < que[i].c){
addedge(++now);
}
if(bit[que[i].a][que[i].b])
ans[que[i].id] = 1;
}
for(int i = 1; i <= q; i ++)
cout << ans[i];
cout << "\n";
}
return 0;
}
/*
1
15 6
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7780kb
input:
2 5 2 4 0305040201 0404040404 030300 020500 050102 020501 6 2 4 030603010601 010203060504 030202 060402 050602 060401
output:
1001 0000
result:
wrong answer 1st lines differ - expected: '1011', found: '1001'