QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#567575 | #9319. Bull Farm | cdd | WA | 4884ms | 56056kb | C++20 | 5.7kb | 2024-09-16 12:50:50 | 2024-09-16 12:50:50 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int read() {
int x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch ^ 48);
ch = getchar();
}
return x * w;
}
const int maxn = 2e3 + 5;
const int maxm = 1e6 + 5;
int T;
int n, m, Q;
struct node {
int u, v, c, id;
}q[maxm];
bool cmp(node x, node y) {
if (x.c != y.c) return x.c < y.c;
return x.id < y.id;
}
char ch[maxn << 1];
int ans[maxm];
pair<int, int> edge[maxm];
int edge_cnt;
vector<int> G[maxn];
int main()
{
int start = clock();
T = read();
while (T--) {
n = read(); m = read(); Q = read();
vector<vector<int>> t(m + 5, vector<int>(n + 5, 0));
for (int i = 1; i <= m; i++) {
scanf("%s", ch);
for (int j = 0; j < n; j++) {
int aa = (int)ch[j << 1] - 48, bb = (int)ch[j << 1 | 1] - 48;
t[i][j + 1] = aa * 50 + bb;
}
}
for (int i = 1; i <= Q; i++) {
scanf("%s", ch);
for (int j = 0; j < 3; j++) {
int aa = (int)ch[j << 1] - 48, bb = (int)ch[j << 1 | 1] - 48;
if (j == 0) q[i].u = aa * 50 + bb;
if (j == 1) q[i].v = aa * 50 + bb;
if (j == 2) q[i].c = aa * 50 + bb;
}
q[i].id = i;
}
sort(q + 1, q + 1 + Q, cmp);
int finish_read = clock();
double tmp = (double)(finish_read - start) / CLOCKS_PER_SEC;
// for (int i = 1; i <= m; i++) {
// for (int j = 1; j <= n; j++)
// cout << t[i][j] << ' ';
// cout << endl;
// }
int now = 1;
while (now <= Q && q[now].c == 0) {
if (q[now].u == q[now].v) ans[q[now].id] = 1;
now++;
}
for (int k = 1; k <= m; k++) {
int finish = clock();
if ((double)((finish - start)) / CLOCKS_PER_SEC >= 4.9) {
cout << k << ' ' << now << endl;
cout << tmp << endl;
return 0;
}
vector<int> in(n + 5, 0);
for (int i = 1; i <= n; i++) in[t[k][i]]++;
int cnt = 0, pos0 = 0, pos2 = 0, ff = 1;
for (int i = 1; i <= n; i++) {
if (in[i] == 0) pos0 = i;
if (in[i] == 2) pos2 = i, cnt++;
if (in[i] >= 3) ff = 0;
}
if (cnt >= 2) ff = 0;
// cout << pos0 << ' ' << pos2 <<' ' << cnt <<' '<<ff<<endl;
if (ff) {
if (cnt == 0) {
for (int i = 1; i <= n; i++) G[i].push_back(t[k][i]);
} else {
for (int i = 1; i <= n; i++) {
if (t[k][i] == pos2) G[i].push_back(pos0), edge[++edge_cnt] = {i, pos0}; // , cout << i << ' ' << pos0 << endl;
}
}
}
vector<int> dfn(n + 5, 0), low(n + 5, 0), l(n + 5, 0), ins(n + 5, 0), col(n + 5, 0);
int id = 0, top = 0, colcnt = 0;
auto tarjan = [&] (auto self_tarjan, int cur) -> void {
dfn[cur] = low[cur] = ++id;
l[++top] = cur, ins[cur] = 1;
for (int v : G[cur])
if (!dfn[v]) self_tarjan(self_tarjan, v), low[cur] = min(low[v], low[cur]);
else if (ins[v]) low[cur] = min(low[cur], dfn[v]);
if (low[cur] == dfn[cur]) {
++colcnt;
while (l[top] != cur) {
col[l[top]] = colcnt;
ins[l[top]] = 0;
top--;
}
col[cur] = colcnt;
ins[cur] = 0;
top--;
}
};
for (int i = 1; i <= n; i++)
if (!dfn[i]) tarjan(tarjan, i);
// for (int i = 1; i <= n; i++) cout << col[i] << ' '; cout << endl;
vector<vector<int>> GT(colcnt + 5, vector<int>());
map<pair<int, int>, int> mp;
in.assign(n + 5, 0);
for (int i = 1; i <= edge_cnt; i++) {
auto [x, y] = edge[i];
x = col[x], y = col[y];
if (x == y || mp.count({x, y})) continue;
mp[{x, y}] = 1;
in[y]++;
GT[x].push_back(y);
}
queue<int> que;
vector<int> vis(n + 5, 0);
vector<bitset<maxn>> fff(colcnt + 5, bitset<maxn>());
for (int i = 1; i <= colcnt; i++) {
if (!in[i]) que.push(i);
fff[i][i] = 1;
}
while (!que.empty()) {
auto cur = que.front();
que.pop();
if (vis[cur]) continue;
vis[cur] = 1;
for (auto v : GT[cur]) {
fff[v] |= fff[cur];
in[v]--;
if (!in[v]) que.push(v);
}
}
while (now <= Q && q[now].c == k) {
auto [u, v, ccc, id] = q[now++];
u = col[u], v = col[v];
ans[id] = fff[v][u];
}
}
for (int i = 1; i <= Q; i++)
putchar(ans[i] + 48);
putchar('\n');
for (int i = 1; i <= n; i++) G[i].clear();
edge_cnt = 0;
for (int i = 1; i <= Q; i++) ans[i] = 0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7904kb
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: 8144kb
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: 109ms
memory: 8164kb
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: 121ms
memory: 25640kb
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
Wrong Answer
time: 4884ms
memory: 56056kb
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...
output:
1419 708968 0.170636
result:
wrong answer 1st lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: '1419 708968'