QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#731223#5259. Skills in Pillsjay248WA 3ms11496kbC++141.6kb2024-11-10 00:43:272024-11-10 00:43:34

Judging History

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

  • [2024-11-10 00:43:34]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11496kb
  • [2024-11-10 00:43:27]
  • 提交

answer

#include <iostream>
#include <cmath>
using namespace std;


int gcd(int x, int y){
    int tmp;
    if(x<y){
        tmp = x;
        x = y;
        y = tmp;
    }
    while(y>0){
        tmp = y;
        y = x%y;
        x = tmp;
    }
    return x;
}

int main(){
    int k, j, n;
    int ans;
    int a[1000005];
    int b[1000005];
    cin>>k>>j>>n;
    int cnt1=0;
    int cnt2=0;
    if(gcd(k, j)>1){
        ans = fmin(n/k + (n+1)/j, (n+1)/k + n/j);
    }

    else{
    int x, y;

    x=1;
    while(true){
        if((k*x-1)%j==0) break;
        x++;
    }

    for(int i=1; i<=k*x-1; i++){
        if(i>n) break;
        a[i] = (i+1)/k + i/j;
    }

    y=1;
    while(true){
        if((j*y-1)%k==0) break;
        y++;
    }

    for(int i=1; i<=j*y-1; i++){
        if(i>n) break;
        b[i] = (i+1)/j + i/k;
    }

    if(k*x > y*j){
        for(int i=y*j; i<k*x; i++){
            if(i>n) break;
            b[i] = fmin(b[i-j*y+1] + b[j*y-1], a[i-j*y+1] + b[j*y-1]);
        }
        for(int i=k*x; i<=n; i++){
            a[i] = fmin(a[i-k*x+1] + a[k*x-1], b[i-k*x+1] + a[k*x-1]);
            b[i] = fmin(b[i-j*y+1] + b[j*y-1], a[i-j*y+1] + b[j*y-1]);
        }
    }

    else{
        for(int i=k*x; i<y*j; i++){
            if(i>n) break;
            a[i] = fmin(a[i-k*x+1] + a[k*x-1], b[i-k*x+1] + a[k*x-1]);
        }
        for(int i=y*j; i<=n; i++){
            a[i] = fmin(a[i-k*x+1] + a[k*x-1], b[i-k*x+1] + a[k*x-1]);
            b[i] = fmin(b[i-j*y+1] + b[j*y-1], a[i-j*y+1] + b[j*y-1]);
        }
    }

    ans = k+j+fmin(a[n-j*k], b[n-j*k]);
    }
    cout<<ans<<'\n';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11496kb

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

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

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

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

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

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

input:

10 8 13

output:

2

result:

ok single line: '2'

Test #5:

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

input:

6 6 19

output:

6

result:

ok single line: '6'

Test #6:

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

input:

2 3 5

output:

5

result:

wrong answer 1st lines differ - expected: '3', found: '5'