QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#574516 | #9319. Bull Farm | EBeason | TL | 147ms | 44444kb | C++20 | 2.8kb | 2024-09-18 22:30:43 | 2024-09-18 22:30:44 |
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
int N, L, Q;
int a[MAXN][MAXN], dis[MAXN][MAXN];
vector<pair<int, int>> G1[MaxN];
inline void Solve() {
cin >> N >> L >> Q;
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];
G1[x].emplace_back(y, i);
G1[y].emplace_back(x, i);
// cerr << x << ' ';
// cerr << y << endl;
}
}
}
for (int s = 1; s <= N; s++) {
priority_queue<pii, vector<pii>, greater<pii> > q;
q.emplace(0, s);
vector<int> vis(N + 1);
dis[s][s] = 0;
while (!q.empty()) {
auto [d, x] = q.top(); q.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);
q.emplace(dis[s][y], 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
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: 5680kb
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: 57ms
memory: 5720kb
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: 0
Accepted
time: 147ms
memory: 44444kb
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...
output:
000101000101100010001000000010010110000001000001001100000000010000100001000000101100000000010000001000000001110000010110100000111100100000001000000000011001010001000001001000100000000100011001100110010000010000101100000011111000000010000101010010000000010101000001010111100000100000000000000101000100...
result:
ok single line: '000101000101100010001000000010...0101000101000000000010101001000'
Test #5:
score: -100
Time Limit Exceeded
input:
1 2000 2000 1000000 FVAaH7GRPO;_11Da5J18@3SMG==\G8E8S^6:M4L0JH>MN5IXT>2<7WJ3U8LVJS=;;3F13>0D0>VOIIU@EPHG6ABL6;K?T1PXDERLG07]5C9^GDKG<SBMIW;`4W8P3=469TIPKH0O34523_J5C2MJ17D25Z@=K8H@M>WK<CMK7EO]BPD7B6AW741J5YIHIa1:ERSG>L3N2^F3<4F`DLE@2AA5=8GZK6:192FB736[WMV7:^DA2C:<LK040VJBM3M]WXU50`407TR_?PLF@5VL7OSL...