QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133666 | #4934. Forbidden Card | SolitaryDream# | WA | 17ms | 9280kb | C++20 | 2.1kb | 2023-08-02 12:41:57 | 2023-08-02 12:42:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
int n, m, a[N], b[N];
int vis[M];
int ans[N];
int fa[N];
inline int Ask(int x) {
return fa[x] >= 0 ? fa[x] = Ask(fa[x]) : x;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
}
vector<int> seq;
int loser = 1;
memset(vis, -1, sizeof vis);
for (int round = 0; round < 2; ++round) {
for (int i = 1; i <= n; ++i) {
if (vis[a[i]] == -1) { vis[a[i]] = seq.size(); seq.push_back(i << 1 | 0); }
else if (vis[b[i]] == -1) { vis[b[i]] = seq.size(); seq.push_back(i << 1 | 1); }
else { loser = i; break; }
}
if (seq.size() != n) break;
}
// printf("loser: %d\n", loser);
// for (auto x : seq) printf("%d %d\n", x >> 1, x & 1);
// puts("");
for (int i = 0; i < seq.size(); ++i) fa[i] = -1;
for (int i = 0; i < (int)seq.size(); ++i) {
int who = seq[i] >> 1, card = seq[i] & 1;
if (card == 0) {
if (vis[b[who]] == -1) fa[i] = -loser;
else {
int oth = seq[vis[b[who]]] >> 1, oth_card = seq[vis[b[who]]] & 1;
if (oth_card == 1) {
// printf("Link0 %d %d\n", i, -oth);
fa[i] = -oth;
} else if (vis[b[who]] < i) {
// printf("Link1 %d %d\n", i, -i);
fa[i] = -who;
} else {
// printf("Link %d %d\n", i, vis[b[who]]);
fa[i] = vis[b[who]];
}
}
}
}
// for (int i = 0; i < (int)seq.size(); ++i) printf("%d ", fa[i]);
// puts("");
for (int i = 1; i <= m; ++i) {
if (vis[i] == -1) {
++ans[loser];
} else {
int who = seq[vis[i]] >> 1, card = seq[vis[i]] & 1;
if (card == 1) ++ans[who];
else {
++ans[-fa[Ask(vis[i])]];
}
}
}
for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8432kb
input:
3 6 1 2 2 4 4 2
output:
3 0 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 8152kb
input:
4 10 1 5 2 6 3 7 4 8
output:
4 2 2 2
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 7928kb
input:
1 2 1 2
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 17ms
memory: 8764kb
input:
69332 250102 51362 228823 206751 31351 181790 44202 186695 92215 172072 173179 86663 76959 42382 25827 204750 30001 42502 11959 201030 71886 227497 216114 164282 235028 178967 181951 125356 20611 169528 174071 50985 175562 63676 208400 189134 229462 49746 131529 180236 247427 29278 229589 30381 4412...
output:
197458 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 69332 lines
Test #5:
score: 0
Accepted
time: 15ms
memory: 9124kb
input:
80145 426253 421996 34366 346502 239646 343011 88629 67397 242186 299496 244930 21243 104718 387596 328535 219758 313693 75331 382300 313805 77098 42577 148653 337458 118115 214642 386869 250381 179903 371620 42703 175776 57872 382478 385425 67153 363632 137021 301439 54496 28984 416540 87624 180610...
output:
2 2 387645 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 80145 lines
Test #6:
score: -100
Wrong Answer
time: 16ms
memory: 9280kb
input:
100000 1000000 123135 548518 73705 792839 425849 331898 823140 91484 612409 674530 215766 587078 145133 904035 435464 107690 291461 358251 156778 270843 378425 339959 353997 687100 373365 903063 948343 203641 349073 91866 329756 348161 731516 202789 767371 938875 3496 388919 998073 384450 73693 8551...
output:
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 956616 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
wrong answer 1st lines differ - expected: '2', found: '1'