QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210666 | #61. Cut Cut Cut! | fstqwq | WA | 6ms | 17856kb | C++14 | 1.6kb | 2023-10-11 18:28:33 | 2023-10-11 18:28:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
typedef vector <LL> vec;
const int N = 3e5 + 5;
const int MOD = 1065138983;
mt19937 rng(MOD - 1);
LL inv (LL x) {
LL ret = 1;
while (x > 1) {
ret *= MOD - MOD / x;
ret %= MOD;
x = MOD % x;
}
return ret;
}
int n, m, d;
struct basis {
vector <vec> a;
basis () {}
void add (vec v) {
for (int i = 0; i < d; i++) if (v[i]) {
LL w = inv(v[i]);
for (int k = 0; k < d; k++) (v[k] *= w) %= MOD;
if (!a[i].size()) {
a[i] = v;
break;
} else {
for (int k = 0; k < d; k++) (v[k] -= a[i][k]) %= MOD;
}
}
}
int rank() {
int cnt = 0;
for (auto v : a) if (v.size()) cnt++;
return cnt;
}
};
vector <int> E[N];
basis p[N];
void work() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
E[u].push_back(v);
}
d = (int) E[1].size();
for (int i = 2; i <= n; i++) p[i].a.resize(d);
int c = 0;
for (auto i : E[1]) {
vec tmp(d);
tmp[c++] = 1;
p[i].add (tmp);
}
for (int x = 2; x <= n; x++) {
for (auto to : E[x]) {
vec tmp(d);
for (auto &v : p[x].a) if (v.size()) {
int w = int(rng() % int(1e9)) + 123;
for (int i = 0; i < d; i++) {
(tmp[i] += w * v[i]) %= MOD;
}
}
p[to].add(tmp);
}
}
for (int i = 2; i <= n; i++) {
printf("%d%c", p[i].rank(), i == n ? '\n' : ' ');
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
for (int ca = 1; ca <= T; ca ++) {
work();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17748kb
input:
3 3 1 2 1 3 2 3
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: 0
Accepted
time: 6ms
memory: 17748kb
input:
8 8 1 2 1 3 1 5 2 4 2 5 3 6 4 5 7 8
output:
1 1 1 2 1 0 0
result:
ok 7 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 17816kb
input:
20 70 3 18 14 16 8 10 5 7 2 14 10 18 14 15 17 19 18 20 4 6 3 20 16 17 6 7 6 17 6 19 5 19 12 16 18 19 13 19 13 19 8 9 15 17 8 9 1 7 5 18 6 14 2 17 4 20 12 16 9 20 2 7 6 19 12 13 6 7 1 5 19 20 9 14 13 14 16 17 17 20 9 16 1 6 12 15 2 8 1 3 4 19 1 4 9 13 14 15 15 20 17 18 14 19 13 14 2 5 7 14 7 18 10 16...
output:
0 1 1 1 2 4 0 1 0 0 1 2 5 3 3 4 6 6 6
result:
ok 19 numbers
Test #4:
score: -100
Wrong Answer
time: 6ms
memory: 17856kb
input:
100 1000 26 51 88 93 96 97 55 92 49 60 89 92 81 84 87 95 80 96 33 81 48 73 12 91 71 86 89 90 33 78 13 100 60 89 45 48 98 100 10 43 40 50 13 29 96 99 83 92 84 85 20 39 97 100 41 76 51 71 28 61 2 80 57 89 58 83 10 30 21 85 1 21 86 95 1 65 66 78 57 91 30 41 46 72 59 64 59 79 17 33 68 79 45 78 8 91 12 7...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 1 1 1 1 1 2 3 0 1 3 3 0 2 4 1 4 3 2 1 3 1 4 4 3 2 4 4 4 3 4 4 4 5 2 5 3 7 7 5 6 4 7 7 6 7 6 4 5 7 7 7 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
result:
wrong answer 53rd numbers differ - expected: '3', found: '4'