QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108647 | #5573. Holiday Regifting | LG_Monkey | WA | 2ms | 3664kb | C++14 | 1.4kb | 2023-05-25 21:45:05 | 2023-05-25 21:45:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define deb(var) cerr << #var << '=' << (var) << "; "
#define int long long
int n, m, c[10010];
const int mod = 998244353;
vector<int> g[10010]; int ind[10010], ord[10010], f[10010];
int lcm(int x, int y) {
if (!x || !y) return x + y;
return x / __gcd(x, y) * y;
}
signed main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> c[i];
while (m--) {
int u, v;
cin >> u >> v; g[u].pb(v); ind[v]++;
}
queue<int> q;
for (int i = 1; i <= n; i++)
if (!ind[i]) q.push(i);
int cnt = 0;
while (q.size()) {
int u = q.front(); q.pop();
ord[++cnt] = u;
for (int j = 0; j < g[u].size(); j++) {
int v = g[u][j];
ind[v]--;
if (!ind[v]) q.push(v);
}
}
int ans = c[1];
f[1] = ans;
for (int j = 1; j <= n; j++) {
int u = ord[j];
for (int k = 0; k < g[u].size(); k++) {
int v = g[u][k];
f[v] += f[u] / c[u];
}
f[u] %= c[u];
}
for (int i = 2; i <= cnt; i++) {
int u = ord[i];
int o = c[u] / __gcd(f[u], c[u]);
for (int j = 1; j <= n; j++) {
int u = ord[j];
f[u] *= o;
for (int k = 0; k < g[u].size(); k++) {
int v = g[u][k];
f[v] += f[u] / c[u];
}
f[u] %= c[u];
}
ans = ans * o % mod;
}
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3664kb
input:
5 10 4 3 2 2 2 1 3 3 4 1 4 1 5 2 5 2 4 1 2 2 3 3 5 4 5
output:
24
result:
ok 1 number(s): "24"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
3 0 95 13 77
output:
95
result:
ok 1 number(s): "95"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3576kb
input:
12 14 6 7 17 16 20 14 17 16 6 11 6 14 4 11 3 5 2 5 9 11 7 12 1 3 5 9 3 7 3 8 4 9 1 9 4 7 2 11 1 12
output:
342720
result:
wrong answer 1st numbers differ - expected: '8739360', found: '342720'