QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485594 | #8008. Fortune Wheel | _log_ | RE | 31ms | 5640kb | C++14 | 1.4kb | 2024-07-20 20:42:48 | 2024-07-20 20:42:49 |
Judging History
answer
# include <bits/stdc++.h>
# define maxn 100100
# define int long long
# define rep(i, j, k) for(int i = j; i <= k; ++i)
using namespace std;
int n, x, k, Max, sum, ans1 = 2e9, ans2 = 1;
int a[maxn], dis[maxn], cnt[maxn];
bool vis[maxn];
queue<pair<int, int> > que;
void bfs() {
que.push({0, 0}); dis[0] = 0; vis[0] = 1;
while(que.size()) {
int u = que.front().first; dis[u] = que.front().second; que.pop();
cnt[dis[u]]++; Max = max(Max, dis[u]);
rep(i, 1, k) {
int v = (u - a[i] + n) % n;
if(!vis[v]) vis[v] = 1, que.push({v, dis[u] + 1});
}
}
}
inline int gcd(int x, int y) {int r; while(x && y) r = x % y, x = y, y = r; return x;}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> x >> k; rep(i, 1, k) cin >> a[i]; memset(dis, 0x3f, sizeof(dis)); bfs();
// rep(i, 0, n - 1) cerr << i << ' ' << dis[i] << '\n';
ans1 = dis[x];
rep(i, 0, Max) {
sum += cnt[i] * i; cnt[i] += (i ? cnt[i - 1] : 0);
// cout << i << ' ' << cnt[i] << ' ' << sum << ' ' << 1.0 * (n + sum) / cnt[i] << '\n';
if(ans1 * cnt[i] > ans2 * (n + sum)) ans1 = n + sum, ans2 = cnt[i];
if(i == dis[x]) break;
}
// cout << ans1 << ' '<< ans2 << '\n';
// return 0;
cout << ans1 / gcd(ans1, ans2) << ' ' << ans2 / gcd(ans1, ans2);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4424kb
input:
6 3 2 2 4
output:
8 3
result:
ok 2 number(s): "8 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5640kb
input:
5 4 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 31ms
memory: 5348kb
input:
99999 65238 100 64714 45675 36156 13116 93455 22785 10977 60219 14981 25839 83709 80404 41400 12469 31530 65521 35436 20326 96792 50699 27522 98233 26187 12509 90992 72693 83919 74145 80892 68422 38333 33497 89154 88403 77492 4570 3908 59194 3482 89871 96330 45114 5555 73987 95832 476 949 74649 2084...
output:
3 1
result:
ok 2 number(s): "3 1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 4708kb
input:
10000 23 7 9594 8998 9330 6851 1662 6719 583
output:
42726 4805
result:
ok 2 number(s): "42726 4805"
Test #5:
score: 0
Accepted
time: 1ms
memory: 4368kb
input:
100 3 100 7 68 28 98 19 32 90 79 92 40 96 30 95 91 71 15 33 18 69 1 61 43 5 75 73 64 58 100 88 20 99 37 17 22 82 67 70 55 47 80 66 12 4 24 26 54 74 57 21 77 86 89 83 29 46 31 2 16 49 48 25 93 52 9 85 84 42 39 8 65 10 45 63 87 78 60 23 14 34 59 81 38 41 76 3 13 27 36 35 51 44 62 53 94 6 50 11 97 72 56
output:
1 1
result:
ok 2 number(s): "1 1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 4360kb
input:
100 93 4 63 58 3 89
output:
19 4
result:
ok 2 number(s): "19 4"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4452kb
input:
75057 45721 3 10861 27551 14278
output:
32797 933
result:
ok 2 number(s): "32797 933"
Test #8:
score: 0
Accepted
time: 3ms
memory: 5280kb
input:
97777 94043 1 83579
output:
97619 221
result:
ok 2 number(s): "97619 221"
Test #9:
score: 0
Accepted
time: 1ms
memory: 4632kb
input:
13515 10596 5 11890 9097 4596 13464 13309
output:
6022 489
result:
ok 2 number(s): "6022 489"
Test #10:
score: 0
Accepted
time: 2ms
memory: 4528kb
input:
77777 64477 3 45863 40922 74543
output:
298537 8416
result:
ok 2 number(s): "298537 8416"
Test #11:
score: -100
Runtime Error
input:
1 0 1 1