QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#568037 | #9319. Bull Farm | awu | TL | 87ms | 8212kb | C++14 | 3.1kb | 2024-09-16 15:01:19 | 2024-09-16 15:01:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 N = 2010, M = 1e6 + 10;
i64 n, l, Q;
i64 g[N][N];
bool f[N][N];
struct node
{
i64 a, b, c, ans;
} q[M];
map<i64, vector<i64>> vec;
i64 get(char a, char b)
{
// i64 t = ((i64)a - 48) * 50 + ((i64)b - 48);
// cout << t << '\n';
return ((i64)a - 48) * 50 + ((i64)b - 48);
}
// 添加 a -> b
void work(i64 a, i64 b)
{
if (!f[a][b])
{
// cout << a << " -> " << b << '\n';
// f[a][b] = true;
// for (i64 c = 1; c <= n; c++)
// {
// // 更新 a -> 其他点
// if (f[b][c])
// f[a][c] = true;
// // 更新 其他点 -> b
// if (f[c][a])
// f[c][b] = true;
// }
f[a][b] = true;
for (i64 u = 1; u <= n; u++)
for (i64 v = u + 1; v <= n; v++)
{
if (f[u][a] && f[b][v])
f[u][v] = true;
if (f[v][a] && f[b][u])
f[v][u] = true;
}
}
}
void solve()
{
cin >> n >> l >> Q;
for (i64 i = 0; i <= n; i++)
{
for (i64 j = 0; j <= n; j++)
f[i][j] = false;
f[i][i] = true;
}
for (i64 i = 0; i <= l; i++)
vec[i].clear();
for (i64 i = 1; i <= l; i++)
for (i64 j = 1; j <= n; j++)
{
char a, b;
cin >> a >> b;
g[i][j] = get(a, b);
}
for (i64 i = 1; i <= Q; i++)
{
char ch1, ch2;
cin >> ch1 >> ch2;
q[i].a = get(ch1, ch2);
cin >> ch1 >> ch2;
q[i].b = get(ch1, ch2);
cin >> ch1 >> ch2;
q[i].c = get(ch1, ch2);
vec[q[i].c].push_back(i);
}
for (i64 i = 0; i <= l; i++)
{
set<i64> S;
for (i64 j = 1; j <= n; j++)
S.insert(g[i][j]);
if (S.size() == n)
{
for (i64 j = 1; j <= n; j++)
{
work(j, g[i][j]);
work(g[i][j], j);
}
}
else if (S.size() == n - 1)
{
i64 t = 1;
while (S.count(t))
t++;
map<i64, i64> mp;
for (i64 j = 1; j <= n; j++)
{
if (mp.count(g[i][j]))
{
work(mp[g[i][j]], t);
work(j, t);
break;
}
mp[g[i][j]] = j;
}
}
for (i64 u : vec[i])
{
// cout << "i: " << i << " u: " << u << '\n';
// cout << "a: " << q[u].a << " b: " << q[u].b << '\n';
q[u].ans = f[q[u].a][q[u].b];
}
}
for (i64 i = 1; i <= Q; i++)
cout << q[i].ans;
cout << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
i64 T = 1;
cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7972kb
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: 1ms
memory: 7972kb
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: 87ms
memory: 8212kb
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...