QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574797 | #9319. Bull Farm | EBeason | RE | 60ms | 5728kb | C++20 | 4.1kb | 2024-09-19 00:39:13 | 2024-09-19 00:39:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(it, ff, ee) for (int it = (ff); it <= (ee); ++it)
#define per(it, ff, ee) for (int it = (ff); it >= (ee); --it)
#define SZ(_x_) ((int) _x_.size())
#define all(_x_) (_x_).begin(), (_x_).end()
#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vi = vector<int>;
const int MAXN = 2e3 + 10;
const int MaxN = 2e3 + 10;
const int INF = 1e9;
#define MUT
struct DSU {
vector<int> fa, siz, sum, g;
vector<pair<int, int>> tmp;
DSU(int n) {
fa.assign(n + 1, 0);
siz.assign(n + 1, 1);
sum.assign(n + 1, 0);
g.assign(n + 1, 0);
for (int i = 1; i <= n; i++) {
fa[i] = i;
sum[i] = i;
}
}
// int find(int x) {
// if (fa[x] == x) return x;
// auto f = find(fa[x]);
// g[x] += g[fa[x]];
// return fa[x] = f;
// }
int find(int x) {
if (fa[x] == x) return x;
return find(fa[x]);
}
void hebin(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
tmp.emplace_back(-1, -1);
return;
}
if (siz[x] < siz[y]) swap(x, y);
tmp.emplace_back(x, y);
fa[y] = x;
siz[x] += siz[y];
sum[x] += sum[y];
}
void undone() { //撤销
auto [x, y] = tmp.back();
tmp.pop_back();
if (x == -1) return;
fa[y] = y;
siz[x] -= siz[y];
sum[x] -= sum[y];
}
void move(int x, int y) { // x -> y
auto fx = find(x), fy = find(y);
if (fx == fy) return;
fa[x] = fy;
--siz[fx], ++siz[fy];
sum[fx] -= x, sum[fy] += x;
}
};
int N, L, Q;
int a[MAXN][MAXN], dis[MAXN][MAXN];
vector<pair<int, int>> G1[MaxN];
inline void Solve() {
cin >> N >> L >> Q;
DSU dsu(N);
int NN = N;
vector<int> ans(Q + 1);
for (int i = 1; i <= N; i++) {
G1[i].clear();
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
dis[i][j] = INF;
}
}
for (int i = 1; i <= L; i++) {
string s1;
cin >> s1;
for (int j = 0; j < 2 * N; j += 2) {
a[i][j / 2 + 1] = (s1[j] - '0') * 50 + (s1[j + 1] - '0') % 50;
}
}
for (int i = 1; i <= L; i++) {
map<int, int> mp;
for (int j = 1; j <= N; j++) {
mp[a[i][j]]++;
}
if (mp.size() == N - 1) {
int id = 0, maxn = 0;
for (auto [x, y] : mp) {
if (y == 2) {
maxn = x;
}
}
for (int j = 1; j <= N; j++) {
if (mp[j] == 0) id = j;
}
for (int j = 1; j <= N; j++) {
if (a[i][j] == maxn) {
auto x = j, y = id;
G1[x].emplace_back(y, i);
// cerr << x << ' ';
// cerr << y << endl;
}
}
} else if (mp.size() == N) {
for (int j = 1; j <= N; j++) {
auto x = j, y = a[i][j];
if (dsu.find(x) != dsu.find(y)) {
G1[x].emplace_back(y, i);
G1[y].emplace_back(x, i);
dsu.hebin(x, y);
}
// cerr << x << ' ';
// cerr << y << endl;
}
}
}
for (int s = 1; s <= N; s++) {
vector<queue<int> > q(L + 10, queue<int>());
q[0].emplace(s);
vector<int> vis(N + 1);
dis[s][s] = 0;
for (int d = 0; d <= N; d++) {
while (!q[d].empty()) {
auto x = q[d].front(); q[d].pop();
if (vis[x]) continue;
vis[x] = 1;
for (auto [y, w] : G1[x]) {
if (max(dis[s][x], w) < dis[s][y]) {
dis[s][y] = max(dis[s][x], w);
if (!vis[y]) q[dis[s][y]].emplace(y);
}
}
}
}
}
// for (int i = 1; i <= N; i++) {
// for (int j = 1; j <= N; j++) {
// cerr << dis[i][j] << ' ';
// }
// cerr << endl;
// }
for (int i = 1; i <= Q; i++) {
string s1;
cin >> s1;
int res[3];
for (int j = 0; j < 6; j += 2) {
res[j / 2] = (s1[j] - '0') * 50 + (s1[j + 1] - '0') % 50;
}
int x = res[0];
int y = res[1];
int z = res[2];
int ans = dis[x][y];
// cerr << ans << endl;
cout << (ans <= z);
}
cout << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef MUT
int T;
cin >> T;
while (T--)
#endif
Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5664kb
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: 5704kb
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: 60ms
memory: 5728kb
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
Runtime Error
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...