QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#181647 | #5259. Skills in Pills | ucup-team1209 | WA | 2ms | 11520kb | C++14 | 1.5kb | 2023-09-16 21:44:50 | 2023-09-16 21:44:51 |
Judging History
answer
#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
using pi = pair <int, int> ;
void cmn(int &x, int y) {
if(x > y) x = y;
}
cs int N = 1e6 + 5;
int n, a, b, f[N][2];
pi calc(int x, int y) {
int ans = 0;
if(x == y) {
x += a;
++ ans;
}
while(x != y) {
if(x < y) x += a;
else y += b;
++ ans;
if(x > n || y > n) return {0, 0};
}
return {x, ans};
}
int F(int x, int y, int n) {
return (n - x) / a + (n - y) / b;
}
int main() {
#ifdef zqj
freopen("1.in","r",stdin);
#endif
cin >> a >> b >> n;
memset(f, 0x3f, sizeof f);
auto [p0, c0] = calc(0, 0);
auto [p1, c1] = calc(-1, 0);
auto [p2, c2] = calc(0, -1);
f[p0][0] = f[p0][1] = c0;
int ans = 1e9;
for(int i = p0; i <= n; i++) {
if(p1 == 0) {
cmn(ans, f[i][0] + F(i - 1, i, n));
}
else {
if(i + p1 > n) cmn(ans, f[i][0] + F(i - 1, i, n));
else {
cmn(f[i + p1][0], f[i][0] + c1);
cmn(f[i + p1][1], f[i][0] + c1);
}
}
if(p2 == 0) {
cmn(ans, f[i][1] + F(i, i - 1, n));
}
else {
if(i + p2 > n) cmn(ans, f[i][1] + F(i, i - 1, n));
else {
cmn(f[i + p2][0], f[i][1] + c2);
cmn(f[i + p2][1], f[i][1] + c2);
}
}
}
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11504kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11440kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 11424kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 2ms
memory: 11392kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 11428kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 11520kb
input:
2 3 5
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'