QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469496 | #8008. Fortune Wheel | WRuperD | WA | 37ms | 6688kb | C++20 | 2.0kb | 2024-07-09 19:47:34 | 2024-07-09 19:47:34 |
Judging History
answer
// Problem: A - Fortune Wheel
// URL: https://vjudge.net/contest/639440#problem/A
// Written by WRuperD
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 1e5 + 10;
int a[MAX];
int dis[MAX];
pair <int, int> b[MAX];
void solve(){
int n = read(), s = read(), k = read();
if(s == 0){
puts("0 0");
return ;
}
for(int i = 1; i <= k; i++){
a[i] = read();
}
queue <int> que;
memset(dis, -1, sizeof(dis));
dis[0] = 0;
que.push(0);
while(!que.empty()){
int u = que.front();
que.pop();
for(int i = 1; i <= k; i++){
int v = (u - a[i] + n) % n;
if(dis[v] != -1) continue;
dis[v] = dis[u] + 1;
que.push(v);
}
}
for(int i = 0; i < n; i++){
if(dis[i] == -1) dis[i] = inf;
}
for(int i = 0; i < n; i++){
b[i].first = dis[i], b[i].second = i;
if(b[i].second == s){
b[i].second = n + 1;
// write(b[i].first);
}
}
sort(b, b + n);
int base = 0;
int ansp = n, ansq = 1;
for(int j = 1; j < n; j++){
if(b[j].second == n + 1){
// write(b[j].first), endl;
int nowp = b[j].first, nowq = 1;
// write(b[])
if(ansq * nowp < nowq * ansp){
ansp = nowp, ansq = nowq;
}
break;
}
base += b[j].first;
int nowq = j + 1, nowp = base + n;
// write(base), endl;
// write(nowp), put(), write(nowq), endl;
if(ansq * nowp < nowq * ansp){
ansp = nowp, ansq = nowq;
}
}
// write(ansp), endl;
int com = __gcd(ansp, ansq);
write(ansp / com), put(), write(ansq / com), endl;
}
signed main(){
int t = 1;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4324kb
input:
6 3 2 2 4
output:
8 3
result:
ok 2 number(s): "8 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4372kb
input:
5 4 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 37ms
memory: 6232kb
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: 0ms
memory: 5824kb
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: 5672kb
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: 4592kb
input:
100 93 4 63 58 3 89
output:
19 4
result:
ok 2 number(s): "19 4"
Test #7:
score: 0
Accepted
time: 8ms
memory: 5696kb
input:
75057 45721 3 10861 27551 14278
output:
32797 933
result:
ok 2 number(s): "32797 933"
Test #8:
score: 0
Accepted
time: 8ms
memory: 6688kb
input:
97777 94043 1 83579
output:
97619 221
result:
ok 2 number(s): "97619 221"
Test #9:
score: 0
Accepted
time: 2ms
memory: 4516kb
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: 8ms
memory: 5832kb
input:
77777 64477 3 45863 40922 74543
output:
298537 8416
result:
ok 2 number(s): "298537 8416"
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 3544kb
input:
1 0 1 1
output:
0 0
result:
wrong answer 2nd numbers differ - expected: '1', found: '0'