QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102500#5259. Skills in PillsLukenWA 3ms7432kbC++142.0kb2023-05-03 14:01:312023-05-03 14:01:35

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 14:01:35]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7432kb
  • [2023-05-03 14:01:31]
  • 提交

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,o=0;
    for (int i = 1; i <= n-m; i++) {
        if ((i + 1) % a == 0 && i % b == 0) {
            num += 2;
            af.len = i;
            af.num = num;
            o=1;
            break;
        }
        if ((i + 1) % a == 0 || i % b == 0)num++;
    }
    if(!o){
        af.len=n-m;
        af.num=num;
    }
    num = 0;
    o=0;
    for (int i = 1; i <= n-m; i++) {
        if ((i + 1) % b == 0 && i % a == 0) {
            num += 2;
            bf.len = i;
            bf.num = num;
            o=1;
            break;
        }
        if ((i + 1) % b == 0 || i % a == 0)num++;
    }
    if(!o){
        bf.len=n-m;
        bf.num=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: 100
Accepted
time: 0ms
memory: 6028kb

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 3ms
memory: 7156kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 0ms
memory: 7432kb

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 5884kb

input:

10 8 13

output:

4

result:

wrong answer 1st lines differ - expected: '2', found: '4'