QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#99952 | #5259. Skills in Pills | cardinal_city# | WA | 2ms | 3540kb | C++20 | 1.1kb | 2023-04-24 07:22:44 | 2023-04-24 07:22:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
if(b == 0) return a;
return gcd(b, a % b);;
}
int dp[2000006] = {};
int main() {
cin.tie(0)->sync_with_stdio(0);
int a,b,n; cin >> a >> b >> n;
if(gcd(a,b) > 1) {
int ans1 = n/a + (n+1)/b;
int ans2 = (n+1)/a + n/b;
cout << min(ans1, ans2) << endl;
return 0;
}
int jumpa = 0;
int jumpb = 0;
for(int i = 1; i < b; i++) {
if((i * a - 1) % b == 0) jumpa = (i * a - 1);
}
for(int i = 1; i < a; i++) {
if((i * b - 1) % a == 0) jumpb = (i * b - 1);
}
// cout << jumpa/b << " " << (jumpa+1)/a << endl;
// cout << jumpb/a << " " << (jumpb+1)/b << endl;
for(int i = n-1; i >= 0; i--) {
int v1 = jumpa/b + (jumpa+1)/a + dp[i + jumpa];
int v2 = jumpb/a + (jumpb+1)/b + dp[i + jumpb];
dp[i] = min(v1, v2);
}
// for(int i = 0; i <= n; i++) {
// cout << dp[i] << " ";
// }
// cout << endl;
cout << dp[0] - 2 << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3540kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3360kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3372kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
2 3 5
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3328kb
input:
4 2 8
output:
6
result:
ok single line: '6'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
5 5 5
output:
2
result:
ok single line: '2'
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 3336kb
input:
3 8 11
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'