QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#304837 | #8008. Fortune Wheel | ucup-team2000# | WA | 0ms | 3480kb | C++20 | 2.2kb | 2024-01-14 03:59:37 | 2024-01-14 03:59:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lep(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,b,a) for(int i = (b); i >= (a); i--)
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;
// const int mod = 1e9 + 7;
int reduce(int x, int n) {
return (x %= n) < 0 ? x + n : x;
}
// int prod(int a, int b) {
// return reduce(reduce(a) * reduce(b));
// }
// int add(int a, int b) {
// return reduce(reduce(a) + reduce(b));
// }
// int modpow(int a, int pw) {
// if (a == 0) return 0;
// if (pw == 0) return 1;
// if (pw % 2 == 0) {
// int res = modpow(a, pw / 2);
// return prod(res, res);
// }
// return prod(modpow(a,pw), a);
// }
pi red(pi p) {
int g = __gcd(p.f,p.s);
return {p.f/g,p.s/g};
}
pi get_better(pi a, pi b) {
a = red(a);
b = red(b);
// a.f / a.s < b.f / b.s whenever a.f * b.s < a.s * b.f
if (a.f == inf) return b;
if (a.f * b.s < a.s * b.f) return a;
return b;
}
void submit(int ans) {
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, x,k;
cin >> n >> x >> k;
vector<int> F(n, inf);
vector<bool> visited(n);
visited[0] = true;
F[0] = 0;
vector<int> vals(k+1);
lep(i,1,k) {
cin >> vals[i];
}
queue<int> q;
F[0] = 0;
visited[0] = 0;
q.push(0);
while (!q.empty()) {
int u = q.front();
q.pop();
lep(i,1,k) {
int len = vals[i];
int v = reduce(u - len, n);
if (!visited[v]) {
visited[v] = 1;
F[v] = F[u] + 1;
q.push(v);
}
}
}
vector<int> dists(n+1);
lep(i,1,n) dists[i] = F[i-1];
sort(dists.begin()+1,dists.end());
pi ans = {F[x],1};
int sm = 0;
lep(i,1,n-1) {
sm += dists[i];
if (dists[i] < F[x] and dists[i] != dists[i+1]) {
// c = 1 + 1/n sum_{i=1}^i dists[i] + (n-i)/n * c
ans = get_better(ans, mp(n+sm,i));
}
}
cout << ans.f << " " << ans.s << "\n";
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3480kb
input:
6 3 2 2 4
output:
10 3
result:
wrong answer 1st numbers differ - expected: '8', found: '10'