QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470105 | #8008. Fortune Wheel | Akagishigeru | WA | 979ms | 161156kb | C++14 | 2.4kb | 2024-07-10 10:18:26 | 2024-07-10 10:18:26 |
Judging History
answer
// #pragma GCC optimize(2)
// #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
namespace zzx{
typedef long long ll;
typedef unsigned long long uint;
typedef long double ld;
// typedef __int128 intl;
#define pc putchar
#define gc getchar
#define et pc('\n')
#define spc pc(' ')
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define pii pair<int,int>
#define pint pair<int,int>
#define tiii tuple<int,int,int>
#define tintl tuple<int,int,int>
#define mk make_pair
#define pp pop_back
#define ppc __builtin_popcount
#define ppcl __builtin_popcountint
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void read(T &num){
T x=0,f=1;
char c=gc();
while(!isdigit(c)){
if(c=='-') f=-1;
c=gc();
}
while(isdigit(c)){
x=(x<<3)+(x<<1)+c-48;
c=gc();
}
num=f*x;
}
template<class T>
void write(T x){
static char buf[40];
static int len=-1;
if(x<0) pc('-'),x=-x;
do{
buf[++len]=x%10+48;
x/=10;
}while(x);
while(len>=0) pc(buf[len--]);
}
}
using namespace zzx;
const int maxn=1e5+10;
const int maxm=510;
int n,x,m,k[maxm],head[maxn],tot,dis[maxn];
struct frac{
ll p,q;
bool operator < (frac tmp) const{
return p*tmp.q<tmp.p*q;
}
}ans;
frac min(frac a,frac b){
if(a<b) return a;
return b;
}
struct edge{
int t,nxt;
}e[maxn*maxm<<1];
void add(int u,int v){
e[++tot]={v,head[u]};
head[u]=tot;
}
void bfs(){
memset(dis,0x3f,sizeof(dis));
dis[0]=0;
queue<int> q;
q.push(0);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i;i=e[i].nxt){
if(dis[e[i].t]>dis[u]+1){
dis[e[i].t]=dis[u]+1;
q.push(e[i].t);
}
}
}
}
void solve(){
read(n),read(x),read(m);
for(int i=1;i<=m;i++){
read(k[i]);
}
for(int i=0;i<n;i++){
for(int j=1;j<=m;j++){
add(i,(i+k[j])%n);
add((i+k[j])%n,i);
}
}
bfs();
frac ans={dis[x],1};
sort(dis,dis+n);
ll sum=0;
for(int i=0;i<n;i++){
sum+=dis[i];
ans=min(ans,{(ll)n+sum,(i+1)});
}
int g=__gcd(ans.p,ans.q);
ans.p/=g,ans.q/=g;
write(ans.p),spc,write(ans.q);
}
int main(){
int t=1;
// read(t);
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4004kb
input:
6 3 2 2 4
output:
8 3
result:
ok 2 number(s): "8 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3956kb
input:
5 4 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 979ms
memory: 161156kb
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: -100
Wrong Answer
time: 2ms
memory: 5100kb
input:
10000 23 7 9594 8998 9330 6851 1662 6719 583
output:
6 1
result:
wrong answer 1st numbers differ - expected: '42726', found: '6'