QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#702207 | #5259. Skills in Pills | Ashbourne | WA | 0ms | 3688kb | C++23 | 1023b | 2024-11-02 15:29:40 | 2024-11-02 15:29:41 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int f[N][2];
signed main(){
int n, a, b;
cin >> a >> b >> n;
if(gcd(a, b) > 1){
cout << min((n + 1) / a + n / b, n / a + (n + 1) / b) << endl;
return 0;
}
int m1 = a * b, m2, m3;
// m1 = a * b;
for(int i = 1; i <= b; ++ i){
if((i * a) % b == b - 1){
m2 = i * a; break; // BA
}
}
// m2 = m2 * a;
for(int i = 1; i <= a; ++ i){
if((i * b) % a == a - 1){
m3 = i * b; break; //AB
}
}
// m1 = m1 * b;
f[0][0] = f[0][1] = 0;
int s1 = (m2 + 1) / b + m2 / a;
int s2 = (m3 + 1) / a + m3 / b;
for(int i = 1; i <= n; ++ i){
if(i < m2){
f[i][0] = (i + 1) / b + i / a;
}else{
f[i][0] = min(f[i - m2][0], f[i - m2][1]) + s1;
}
if(i < m3){
f[i][1] = i / a + (i + 1) / b;
}else{
f[i][1] = min(f[i - m3][0], f[i - m3][1]) + s2;
}
}
if(n < a * b){
cout << n / a + n / b << endl;
}else{
cout << a + b + min(f[n - m1][0], f[n - m1][1]);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
2 3 5
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
4 2 8
output:
6
result:
ok single line: '6'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
5 5 5
output:
2
result:
ok single line: '2'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
3 8 11
output:
4
result:
ok single line: '4'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 8 16
output:
5
result:
ok single line: '5'
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 3536kb
input:
9 7 279
output:
71
result:
wrong answer 1st lines differ - expected: '70', found: '71'