QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293963 | #5259. Skills in Pills | LaStataleBlue# | WA | 0ms | 3796kb | C++20 | 1.7kb | 2023-12-30 00:43:01 | 2023-12-30 00:43:01 |
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) << 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: 0ms
memory: 3796kb
input:
3 9 20
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
8 2 12
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2 5 15
output:
10
result:
ok single line: '10'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
10 8 13
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
6 6 19
output:
6
result:
ok single line: '6'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
2 3 5
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
4 2 8
output:
6
result:
ok single line: '6'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3564kb
input:
5 5 5
output:
3
result:
wrong answer 1st lines differ - expected: '2', found: '3'