QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571428 | #9319. Bull Farm | yukino_yukinoshita | WA | 164ms | 11688kb | C++14 | 3.3kb | 2024-09-17 22:56:23 | 2024-09-17 22:56:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int M = 1e6 + 5;
int n, m, l, t[N][N];
int vis[N], flg[N], u1[N], u2[N], tt[N];
struct Qry {int a, b, c, id;} q[M];
bool cmp(Qry x, Qry y) {return x.c < y.c;}
bitset<2048> f[N];
int fa[N];
int find(int x) {return fa[x] == x ? x : fa[x] = find(fa[x]);}
void link(int x, int y)
{
for(int i = 1; i <= n; i++)
if(f[i][x]) f[i] |= f[y];
}
void merge(int x, int y)
{
x = find(x), y = find(y);
link(x, y), link(y, x);
fa[y] = x;
}
bool vs[N];
bool g[N][N];
bool bfs(int s, int t)
{
memset(vs, 0, sizeof(vs));
queue<int> que;
que.push(s); vs[s] = 1;
while(!que.empty())
{
int u = que.front(); que.pop();
// printf("u = %d\n", u);
if(u == t) return 1;
for(int i = 1; i <= n; i++) if(g[u][i] && !vs[i])
que.push(i), vs[i] = 1;
}
return 0;
}
void solve()
{
cin >> n >> l >> m;
for(int i = 1; i <= l; i++)
{
string s; cin >> s;
for(int j = 1; j <= n; j++) vis[j] = 0;
int cnt = 0;
for(int j = 1; j <= n; j++)
{
t[i][j] = 50 * (s[2 * j - 2] - '0') + s[2 * j - 1] - '0';
// cout << t[i][j] << " \n"[j == n];
if(vis[t[i][j]])
{
cnt++;
if(cnt == 1) flg[i] = 1, u1[i] = j, u2[i] = vis[t[i][j]];
else flg[i] = 2;
}
vis[t[i][j]] = j;
}
if(flg[i] == 1)
{
for(int j = 1; j <= n; j++) if(!vis[j])
{
tt[i] = j;
break;
}
}
}
// cout << "\n";
for(int i = 1; i <= m; i++)
{
string s; cin >> s;
q[i].a = 50 * (s[0] - '0') + s[1] - '0';
q[i].b = 50 * (s[2] - '0') + s[3] - '0';
q[i].c = 50 * (s[4] - '0') + s[5] - '0';
q[i].id = i;
// cerr << q[i].a << " " << q[i].b << " " << q[i].c << "\n";
}
sort(q + 1, q + m + 1, cmp);
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= n; i++) f[i][i] = 1, fa[i] = i;
memset(g, 0, sizeof(g));
string ans; ans.resize(m);
for(int i = 1, cc = 1; i <= m; i++)
{
for(; cc <= q[i].c; cc++)
{
if(flg[cc] == 2) continue;
if(flg[cc] == 1)
{
// printf("cc = %d\n", cc);
// printf("edge1 %d %d\n", u1[cc], tt[cc]);
// printf("edge2 %d %d\n", u2[cc], tt[cc]);
g[u1[cc]][tt[cc]] = 1;
g[u2[cc]][tt[cc]] = 1;
continue;
}
for(int u = 1; u <= n; u++) if(vis[u] == 0)
{
int st = u;
bool ok = 0;
bitset<2048> to, from;
for(; vis[u] == 0; u = t[cc][u])
{
vis[u] = 1, to |= f[u], from[u] = 1;
if(find(u) != find(st)) merge(st, u);
// printf("edge %d %d\n", st, u);
// printf("edge %d %d\n", u, st);
g[st][u] = g[u][st] = 1;
}
}
}
// ans[q[i].id - 1] = f[q[i].a][q[i].b] + '0';
// printf("%d %d\n", q[i].a, q[i].b);
// for(int I=1; I<=n; ++I) for(int J=1; J<=n; ++J) printf("%d%c", g[I][J], J==n?10:32);
ans[q[i].id - 1] = bfs(q[i].a, q[i].b) + '0';
}
cout << ans << "\n";
for(int i = 1; i <= n; i++) f[i].reset();
for(int i = 1; i <= l; i++) flg[i] = 0;
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T; cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11688kb
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: 11204kb
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: 164ms
memory: 11580kb
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:
010000001101101111101010001101100000001111110101001110000100001011010101110111000011000100110011110100001001100011110101110101101010001010100100011110010101000000000111111010011111101001111010101010000111010111001111011000111010100101001001010100000110011011100000100100100010001010000001011101101110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '010000001101101111101010001101...1111110011111101001111010011101'