QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293965 | #5259. Skills in Pills | LaStataleBlue# | WA | 1ms | 3552kb | C++20 | 1.7kb | 2023-12-30 00:44:17 | 2023-12-30 00:44:18 |
Judging History
answer
#pragma ide diagnostic ignored "misc-no-recursion"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double db;
#define TESTCASE 0
static constexpr int MAX_N = 5000;
static constexpr int INF = 1e9;
static pair<int, ll> advance(ll A, ll B, ll N) {
ll p1 = 0, p2 = -1, c = 0;
while (p1 != p2) {
if (p1 >= N) return {INF, INF};
if (p1 < p2) {
p1 += A;
} else {
p2 += B;
}
c++;
}
return {p1, c};
}
static void solve([[maybe_unused]] int tc) {
ll N, A, B;
cin >> A >> B >> N;
ll f = lcm(A, B);
if (f > N) {
ll ans = N / A + N / B;
cout << ans + (f == N + 1) << endl;
return;
}
auto c1 = advance(A, B, N);
auto c2 = advance(B, A, N);
vector <ll> dp(N, INF);
dp[f - 1] = f / A + f / B;
ll res = INF;
for (int i = 0; i < N; i++) {
int x1 = i + c1.first;
if (x1 < N) {
dp[x1] = min(dp[x1], dp[i] + c1.second);
} else {
res = min(res, dp[i] + (N - i - 1) / A + (N - i) / B);
}
int x2 = i + c2.first;
if (x2 < N) {
dp[x2] = min(dp[x2], dp[i] + c2.second);
} else {
res = min(res, dp[i] + (N - i - 1) / B + (N - i) / A);
}
}
cout << res << endl;
}
int main() {
ios::sync_with_stdio(false);
if (const char *f = getenv("REDIRECT_STDOUT"); f) {
freopen(f, "w", stdout);
}
int T = 1;
#if TESTCASE
cin >> T;
#endif
for (int t = 1; t <= T; t++) {
solve(t);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3552kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3364kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3464kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3420kb
input:
2 3 5
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'