QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274651 | #5259. Skills in Pills | ucup-team859# | WA | 0ms | 3432kb | C++17 | 2.0kb | 2023-12-03 19:41:59 | 2023-12-03 19:42:00 |
Judging History
answer
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
inline ll Get(int n, int a, int b) {
int i = 1;
while (true) {
ll pos = 1LL * i * a;
if ((pos - 1) % b == 0) {
return pos;
}
if (pos > n) {
return 2 * n;
}
i++;
}
return -1;
}
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, a, b;
cin >> a >> b >> n;
if (a == b) {
int answer = 0;
for (int i = a; i <= n; i += a) {
answer++;
}
for (int i = a - 1; i <= n; i += a) {
answer++;
}
cout << answer << "\n";
return 0;
}
ll ab = Get(n, a, b);
ll ba = Get(n, b, a);
ll C = 1LL * a * b / __gcd(a, b);
if (C > n) {
int answer = 0;
for (int i = a; i <= n; i += a) {
answer++;
}
for (int i = b; i <= n; i += b) {
answer++;
}
cout << answer << "\n";
return 0;
}
vector<int> cntA(n + 1), cntB(n + 1);
for (int i = n; i >= 1; i--) {
cntA[i] = 1 + (i + a <= n ? cntA[i + a] : 0);
cntB[i] = 1 + (i + b <= n ? cntB[i + b] : 0);
}
vector<int> dp(n + 1, n + 1);
dp[n - 1] = 2;
for (int i = n - 2; i >= 1; i--) {
ll pos = i + ab;
if (pos > n) {
dp[i] = min(dp[i], cntA[i] + cntB[i + 1]);
} else {
dp[i] = min(dp[i], dp[pos - 1] + cntA[i] - cntA[pos] + cntB[i + 1] - cntB[pos]);
}
pos = i + ba;
if (pos > n) {
dp[i] = min(dp[i], cntB[i] + cntA[i + 1]);
} else {
dp[i] = min(dp[i], dp[pos - 1] + cntB[i] - cntB[pos] + cntA[i + 1] - cntA[pos]);
}
}
cout << dp[C - 1] + a + b - 2 << "\n";
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3432kb
input:
3 9 20
output:
16
result:
wrong answer 1st lines differ - expected: '8', found: '16'