QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#99956 | #5259. Skills in Pills | cardinal_city# | WA | 2ms | 3488kb | C++20 | 1.3kb | 2023-04-24 08:00:25 | 2023-04-24 08:00:27 |
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);
}
for(int i = n; i >= 0; i--) {
int ja = min(n - i, jumpa);
int jb = min(n - i, jumpb);
int v1 = 1 + ja/a + 1 + (ja - 1)/b + dp[i + jumpa];
int v2 = 1 + jb/b + 1 + (jb - 1)/a + dp[i + jumpb];
// cout << v1 << " " << v2 << endl;
dp[i] = min(v1, v2);
}
int ans = 1e8;
// for(int i = 0; i <= n; i++) {
// cout << dp[i] << " ";
// }
// cout << endl;
for(int i = 1; i <= a * b; i++) {
// cout << (i-1)/a << " " << (i-1)/b << " " << dp[i] << endl;
ans = min(ans, (i-1)/a + (i-1)/b + dp[i]);
}
cout << ans << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3376kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3372kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3324kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3372kb
input:
2 3 5
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3364kb
input:
4 2 8
output:
6
result:
ok single line: '6'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3360kb
input:
5 5 5
output:
2
result:
ok single line: '2'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3380kb
input:
3 8 11
output:
4
result:
ok single line: '4'
Test #10:
score: -100
Wrong Answer
time: 2ms
memory: 3488kb
input:
5 8 16
output:
4
result:
wrong answer 1st lines differ - expected: '5', found: '4'