QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#139446#5259. Skills in Pillstselmegkh#WA 1ms3564kbC++202.7kb2023-08-13 16:07:042023-08-13 16:07:07

Judging History

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

  • [2023-08-13 16:07:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3564kb
  • [2023-08-13 16:07:04]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;

const int N = 2e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int dp[1000006][2];
int n, i, j;
int doit(int lst, int type){
    cout << lst << ' ' << type << '\n';
    if(dp[lst][type] != 0) return dp[lst][type];
    if(type == 1 && lst + i - 1 > n && lst + j > n) return 0;
    if(type == 0 && lst + j - 1 > n && lst + i > n) return 0;
    if(type == 1){
        // i, j
        int cnt = 0;
        while(true){
            cnt += j;
            if((cnt + 1) % i == 0) break;
        }
        if(lst + cnt > n){
            dp[lst][type] = (n - lst + 1) / i + (n - lst) / j;
            return dp[lst][type];
        }
        else{
            dp[lst][type] = ((cnt + 1 ) / i + cnt / j) + min(doit(lst + cnt, 0), doit(lst + cnt, 1));
            return dp[lst][type];
        }
    }
    else{
        //  j i 
        int cnt = 0;
        while(true){
            cnt += i;

            if((cnt + 1) % j == 0) break;
        }
        if(cnt + lst > n){
            dp[lst][type] = (n - lst + 1) / i + (n - lst) / j;
            return dp[lst][type];
        }
        else{
            dp[lst][type] = ((cnt + 1 ) / j + cnt / i) + min(doit(lst + cnt, 0), doit(lst + cnt, 1));
            return dp[lst][type];
        }
    }
    return dp[lst][type];
}


void solve(){
    cin >> i >> j >> n;
    
    if(i == j){
        if(n % i == 0){
            cout << (n / i) * 2 << '\n';
        }   
        else{
            if(n % i + 1 >= i){
               cout << (n / i) * 2 + 1 << '\n';
            }
            else cout << (n / i) * 2 << '\n';
        }
        return;
    }
    int lst = 0;

    while(true){
        lst += i;
        if(lst % j == 0){
            break;
        }
    }

    int ans = 0;
    if(lst >= n){
        ans = n / i + n / j;
        cout << ans << '\n';
        return;
    }
    else{
        if(__gcd(i, j) != 1){
            ans = min((n - lst) / i + (n - lst + 1) / j, (n - lst + 1) / i + (n - lst) / j) + lst / i + lst / j;
            cout << ans << '\n';
            return;
        }
        ans = min(doit(lst, 1), doit(lst, 0)) + lst / i + lst / j;
        cout << ans << '\n';
        return;
    }
    return;
}

int main(){
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3448kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3564kb

input:

2 5 15

output:

10 0
14 1
14 0
10 1
15 1
15 0
10

result:

wrong answer 1st lines differ - expected: '10', found: '10 0'