QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99958 | #5259. Skills in Pills | cardinal_city# | RE | 11ms | 7288kb | C++20 | 1.2kb | 2023-04-24 08:04:19 | 2023-04-24 08:04:23 |
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[5000006] = {};
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 + 1 - i, jumpa);
int jb = min(n + 1 - 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 <= min(a * b, n+1000); i++) {
ans = min(ans, (i-1)/a + (i-1)/b + dp[i]);
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3368kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3328kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3360kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
2 3 5
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3320kb
input:
4 2 8
output:
6
result:
ok single line: '6'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3332kb
input:
5 5 5
output:
2
result:
ok single line: '2'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
3 8 11
output:
4
result:
ok single line: '4'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
5 8 16
output:
5
result:
ok single line: '5'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
9 7 279
output:
70
result:
ok single line: '70'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
8 3 56
output:
25
result:
ok single line: '25'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3348kb
input:
5 9 46
output:
14
result:
ok single line: '14'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3320kb
input:
8 4 251
output:
93
result:
ok single line: '93'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3432kb
input:
8 7 41
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3344kb
input:
60 17 360
output:
27
result:
ok single line: '27'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3368kb
input:
16 55 388
output:
31
result:
ok single line: '31'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
25 38 292
output:
18
result:
ok single line: '18'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
22 59 177
output:
11
result:
ok single line: '11'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
4 3 82
output:
50
result:
ok single line: '50'
Test #21:
score: 0
Accepted
time: 9ms
memory: 5436kb
input:
77 18 511543
output:
35070
result:
ok single line: '35070'
Test #22:
score: 0
Accepted
time: 11ms
memory: 7288kb
input:
37 32 987861
output:
57612
result:
ok single line: '57612'
Test #23:
score: 0
Accepted
time: 4ms
memory: 4608kb
input:
29 8 300899
output:
48059
result:
ok single line: '48059'
Test #24:
score: 0
Accepted
time: 6ms
memory: 5428kb
input:
73 83 533839
output:
13745
result:
ok single line: '13745'
Test #25:
score: 0
Accepted
time: 2ms
memory: 4192kb
input:
12 23 181193
output:
23008
result:
ok single line: '23008'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3364kb
input:
2 2 864514
output:
864514
result:
ok single line: '864514'
Test #27:
score: 0
Accepted
time: 4ms
memory: 3968kb
input:
27 7 165249
output:
29765
result:
ok single line: '29765'
Test #28:
score: 0
Accepted
time: 7ms
memory: 6304kb
input:
15 2 751665
output:
429522
result:
ok single line: '429522'
Test #29:
score: 0
Accepted
time: 2ms
memory: 3328kb
input:
2 16 818146
output:
460207
result:
ok single line: '460207'
Test #30:
score: 0
Accepted
time: 10ms
memory: 5832kb
input:
43 88 631366
output:
21860
result:
ok single line: '21860'
Test #31:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
215 1222 3597
output:
18
result:
ok single line: '18'
Test #32:
score: -100
Runtime Error
input:
9619 3375 604892