QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102492#5259. Skills in PillsLukenWA 3ms5780kbC++141.8kb2023-05-03 13:55:142023-05-03 13:55:16

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 13:55:16]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5780kb
  • [2023-05-03 13:55:14]
  • 提交

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);
}

詳細信息

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'