QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102492 | #5259. Skills in Pills | Luken | WA | 3ms | 5780kb | C++14 | 1.8kb | 2023-05-03 13:55:14 | 2023-05-03 13:55:16 |
Judging History
answer
//
// Created by 86189 on 2023/5/3.
//
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 1000010
using namespace std;
struct {
int len, num;
} af, bf;
int f[N], g[N];
int a, b, n, m;
int ans;
int main() {
scanf("%d%d%d", &a, &b, &n);
memset(f, 127, sizeof(f));
m = -1;
for (int i = 1; i <= n; i++) {
if (i % a == 0 && i % b == 0) {
ans += 2;
m = i;
break;
}
if (i % a == 0 || i % b == 0)ans++;
}
int num = 0;
for (int i = 1; i <= n; i++) {
if ((i + 1) % a == 0 && i % b == 0) {
num += 2;
af.len = i;
af.num = num;
break;
}
if ((i + 1) % a == 0 || i % b == 0)num++;
}
num = 0;
for (int i = 1; i <= n; i++) {
if ((i + 1) % b == 0 && i % a == 0) {
num += 2;
bf.len = i;
bf.num = num;
break;
}
if ((i + 1) % b == 0 || i % a == 0)num++;
}
f[m] = ans;
for (int i = m; i <= n; i++) {
if (f[i] > n)continue;
if (i + af.len <= n)f[i + af.len] = min(f[i + af.len], f[i] + af.num);
if (i + bf.len <= n)f[i + bf.len] = min(f[i + bf.len], f[i] + bf.num);
}
int num1 = 0, num2 = 0;
for (int i = 1; i <= max(af.len, bf.len); i++) {
if ((i + 1) % a == 0 || i % b == 0)num1++;
if ((i + 1) % b == 0 || i % a == 0)num2++;
g[i] = 1 << 30;
if (i < af.len)g[i] = min(g[i], num1);
if (i < bf.len)g[i] = min(g[i], num2);
}
int an = 1 << 30;
for (int i = max(n - max(af.len, bf.len), m); i <= n; i++) {
if (f[i] > n)continue;
an = min(an, f[i] + g[n - i]);
}
printf("%d", an);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 5780kb
input:
3 9 20
output:
1073741824
result:
wrong answer 1st lines differ - expected: '8', found: '1073741824'