QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588398 | #9319. Bull Farm | youthpaul | WA | 50ms | 3844kb | C++20 | 3.1kb | 2024-09-25 10:29:55 | 2024-09-25 10:29:57 |
Judging History
answer
#include<bits/stdc++.h>
#define fore(i,l,r) for(int i=(int)(l);i<(int)(r);++i)
#define fi first
#define se second
#define endl '\n'
#define ull unsigned long long
#define ALL(v) v.begin(), v.end()
#define Debug(x, ed) std::cerr << #x << " = " << x << ed;
const int INF=0x3f3f3f3f;
const long long INFLL=1e18;
typedef long long ll;
struct Edge{
int u;
int v;
int w;
};
const int N = 2005;
int fa[N];
int find(int x){
if(x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int t;
std::cin >> t;
while(t--){
int n, l, q;
std::cin >> n >> l >> q;
std::vector<Edge> e;
fore(i, 1, n + 1) fa[i] = i;
fore(w, 1, l + 1){
std::string s;
std::cin >> s;
std::vector<int> in(n + 1);
std::vector<int> to(n + 1);
int cnt = 0;
for(int i = 0; i < s.size(); i += 2){
int u = i / 2 + 1, v = 50 * (s[i] - '0') + (s[i + 1] - '0');
to[u] = v;
if(!in[v]) ++cnt;
++in[v];
}
if(cnt <= n - 2) continue;
if(cnt == n){
fore(u, 1, n + 1){
int v = to[u];
int fau = find(u), fav = find(v);
if(fau == fav) continue;
e.push_back({u, v, w});
e.push_back({v, u, w});
fa[fau] = fav;
}
}
else{
int x0 = 0, y = 0;
fore(i, 1, n + 1){
if(!in[i]) x0 = i;
else if(in[i] == 2) y = i;
}
fore(u, 1, n + 1)
if(to[u] == y)
e.push_back({u, x0, w});
}
}
std::vector<std::vector<int>> f(n + 1, std::vector<int>(n + 1, l + 5));
std::vector<std::vector<std::pair<int, int>>> g(n + 1);
fore(i, 1, n + 1) f[i][i] = 0;
fore(i, 1, n + 1){
fore(u, 1, n + 1) g[u].clear();
for(auto [u, v, w] : e){
std::queue<int> q;
g[u].push_back({v, w});
if(f[i][v] > w && f[i][u] <= w){
f[i][v] = w;
q.push(v);
}
while(!q.empty()){
int u = q.front();
q.pop();
for(auto [v, w] : g[u])
if(f[i][v] > w){
f[i][v] = w;
q.push(v);
}
}
}
}
while (q--){
std::string s;
std::cin >> s;
std::array<int, 3> arr;
for(int i = 0; i < s.size(); i += 2) arr[i / 2] = 50 * (s[i] - '0') + (s[i + 1] - '0');
auto [a, b, c] = arr;
std::cout << (f[a][b] <= c);
}
std::cout << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
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: 3608kb
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: 50ms
memory: 3844kb
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:
011110101101111111111111111111111111111111110111111111111111111011010111111111111111111101111111111110111111110111111111111111111111111111111111111111111111110001110111111111111111111111111011101111111111111111111111111111111111111111111011110100111111111111111111111100111111101110111111111101111110...
result:
wrong answer 1st lines differ - expected: '011110001101101111111111111111...1111111111111111101111111111111', found: '011110101101111111111111111111...1111111111111111101111111111111'