QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97671 | #5259. Skills in Pills | Khoas | WA | 2ms | 3484kb | C++14 | 1.8kb | 2023-04-17 21:03:14 | 2023-04-17 21:03:18 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
long long k, j, n, i, tot = 0;
long long a = 0, b = 0, x, y;
long long p, q;
cin >> k >> j >> n;
if(k > j) swap(k, j);
if(n % k == 0) p = k - 1;
else{
p = (n / k + 1) * k - n - 1;
}
if(n % j == 0) q = j - 1;
else{
q = (n / j + 1) * j - n - 1;
}
for(i = k; i <= n; ++ i)
{
x = i - a; y = i - b;
if(x == k && y == j)
{
if(p == q && p == 0)
{
p = 0; q = j;
a = i; b = i - 1;
tot += 2; //-- q;
}
else
{
if(q > 0)
{
a = i; b = i - 1;
tot += 2; -- q;
}
else
{
a = i - 1; b = i;
tot += 2; -- p;
}
}
}
else{
if(x == k){
a = i; ++ tot;
continue;
}
if(y == j){
b = i; ++ tot;
continue;
}
}
}
if(n % k == 0) p = k - 1;
else{
p = (n / k + 1) * k - n - 1;
}
if(n % j == 0) q = j - 1;
else{
q = (n / j + 1) * j - n - 1;
}
if(p > q)
{
a = n; b = n - 1;
-- p;
}
else
{
a = n - 1; b = n;
if(q > 0) -- q;
}
long long tot1 = 2;
for(i = n - 2; i >= 1; -- i)
{
x = a - i; y = b - i;
if(x == k && y == j)
{
if(p == q && p == 0)
{
p = 0; q = j;
a = i; b = i + 1;
tot1 += 2; //-- q;
}
else
{
if(q > 0)
{
a = i; b = i + 1;
tot1 += 2; -- q;
}
else
{
a = i + 1; b = i;
tot1 += 2; -- p;
}
}
}
else{
if(x == k){
a = i; ++ tot1;
continue;
}
if(y == j){
b = i; ++ tot1;
continue;
}
}
}
tot = min(tot, tot1);
cout << tot;
return 0;
}
/*
1 : AB
2 : BA
f[1][n]
f[2][n]
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3268kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3384kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3472kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3268kb
input:
2 3 5
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
4 2 8
output:
6
result:
ok single line: '6'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
5 5 5
output:
2
result:
ok single line: '2'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
3 8 11
output:
4
result:
ok single line: '4'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3292kb
input:
5 8 16
output:
5
result:
ok single line: '5'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
9 7 279
output:
70
result:
ok single line: '70'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
8 3 56
output:
25
result:
ok single line: '25'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3276kb
input:
5 9 46
output:
14
result:
ok single line: '14'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3264kb
input:
8 4 251
output:
93
result:
ok single line: '93'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3268kb
input:
8 7 41
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3276kb
input:
60 17 360
output:
27
result:
ok single line: '27'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3264kb
input:
16 55 388
output:
31
result:
ok single line: '31'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3268kb
input:
25 38 292
output:
18
result:
ok single line: '18'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3296kb
input:
22 59 177
output:
11
result:
ok single line: '11'
Test #20:
score: -100
Wrong Answer
time: 2ms
memory: 3316kb
input:
4 3 82
output:
52
result:
wrong answer 1st lines differ - expected: '50', found: '52'