QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577911 | #9319. Bull Farm | clapp | WA | 43ms | 3944kb | C++17 | 2.9kb | 2024-09-20 15:24:16 | 2024-09-20 15:24:19 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
const int inf = 1e9 + 7;
int n, l, q, du[2005], fa[2005], dis[2005][2005], vis[2005];
vector<pair<int, int>> e[2005];
vector<int> blk[2005];
char s[20005];
int getfa(int o) {
return (fa[o] == o) ? o : (fa[o] = getfa(fa[o]));
}
void init(int rk) {
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) du[i] = 0;
for (int i = 1; i <= n + n; i += 2) {
int x = (s[i] - 48) * 50 + s[i + 1] - 48;
du[x]++;
}
int cnt = 0, pos = 0, p = 0;
for (int i = 1; i <= n; i++) {
if (du[i] > 2) return;
if (du[i] == 2) {
cnt++;
pos = i;
}
if (du[i] == 0) {
p = i;
}
}
if (cnt == 1) {
for (int i = 1; i <= n + n; i += 2) {
int x = (s[i] - 48) * 50 + s[i + 1] - 48;
if (x == pos) {
e[(i + 1) >> 1].emplace_back(p, rk);
}
}
} else if (cnt == 0) {
for (int i = 1; i <= n + n; i += 2) {
int x = (s[i] - 48) * 50 + s[i + 1] - 48;
int fx = getfa(i >> 1);
int fy = getfa(x);
if (fx != fy) {
fa[fx] = fy;
e[(i + 1) >> 1].emplace_back(x, rk);
e[x].emplace_back((i + 1) >> 1, rk);
}
}
}
}
void relax(int i, int o) {
for (auto &[to, w]: e[o]) {
if (dis[i][to] > max(dis[i][o], w)) {
dis[i][to] = max(dis[i][o], w);
blk[dis[i][to]].push_back(to);
}
}
}
int main() {
int T;
cin >> T;
while (T--) {
scanf("%d%d%d", &n, &l, &q);
for (int i = 1; i <= n; i++) e[i].clear();
for (int i = 1; i <= n; i++) fa[i] = i;
for (int i = 1; i <= l; i++) init(i);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dis[i][j] = inf;
vis[j] = 0;
}
for (int j = 0; j <= l; j++) blk[j].clear();
dis[i][i] = 0;
blk[0].push_back(i);
for (int j = 0; j <= l; j++) {
while (!blk[j].empty()) {
if (!vis[blk[j].back()]) {
relax(i, blk[j].back());
vis[blk[j].back()] = 1;
}
blk[j].pop_back();
}
}
}
while (q--) {
scanf("%s", s + 1);
int a = (s[1] - 48) * 50 + s[2] - 48;
int b = (s[3] - 48) * 50 + s[4] - 48;
int c = (s[5] - 48) * 50 + s[6] - 48;
if (dis[a][b] <= c) {
putchar('1');
} else {
putchar('0');
}
}
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3944kb
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: 3824kb
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: 43ms
memory: 3780kb
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:
000000001101001111101010000101000000001111110101000100000100001001000101010100000011000100000001110000001001000010110101000100001010001000000100001100010101000000000101111010011101101001111010001000000101000000001101001000111010100101001000010000000010000011100000000100100000001010000001001001101110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '000000001101001111101010000101...1010110001111100000111000011000'