QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#150504 | #4934. Forbidden Card | zqs | WA | 2ms | 9820kb | C++14 | 1.3kb | 2023-08-25 18:31:37 | 2023-08-25 18:31:39 |
Judging History
answer
#include <cstdio>
#include <cstring>
int lst[1000005], a[1000005], b[1000005], choice[1000005], lst2[1000005], ans[1000005];
bool mark[1000005], bchosen[1000005];
int main() {
int n, m, N = 0, lst1 = 0; scanf("%d%d", &n, &m), N = n;
for (int i = 1; i <= n; ++ i) scanf("%d%d", a + i, b + i);
for (int i = 1; i <= n; ++ i) {
bchosen[i] = mark[b[i]];
if (!mark[a[i]]) choice[i] = 0, mark[a[i]] = true;
else if (!mark[b[i]]) choice[i] = 1, mark[b[i]] = true;
else {N = i - 1; break;}
}
for (int i = N; i; -- i)
if (choice[i] == 0) lst[a[i]] = ((lst[b[i]] && !bchosen[i]) ? lst[b[i]] : i);
else lst[b[i]] = i;
if (N == n) {
lst1 = 0;
while (lst2[0] < n && (choice[lst2[0] + 1] == 0 && !mark[b[lst2[0] + 1]])) mark[b[++ lst2[0]]] = true;
if (lst2[0] == n) lst2[0] = 1;
else ++ lst2[0];
for (int i = 1; i <= m; ++ i) lst2[i] = lst2[0];
for (int i = lst2[0] == 1 ? n : lst2[0] - 1; i; -- i) lst2[b[i]] = i;
}
for (int i = 1; i <= m; ++ i) {
int x = lst[i];
if (x && (choice[x] == 1 || (choice[x] == 0 && bchosen[x]))) ++ ans[x];
else if (x && choice[x] == 0 && !bchosen[x]) ++ ans[N == n ? lst2[b[x]] : N + 1];
else if (N != n) ++ ans[N + 1];
// else ++ ans[lst2[i]];
else ++ ans[1];
}
for (int i = 1; i <= n; ++ i) printf("%d\n", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9820kb
input:
3 6 1 2 2 4 4 2
output:
3 0 3
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7760kb
input:
4 10 1 5 2 6 3 7 4 8
output:
7 1 1 1
result:
wrong answer 1st lines differ - expected: '4', found: '7'