QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139440#5259. Skills in Pillstselmegkh#TL 0ms0kbC++202.4kb2023-08-13 15:48:032023-08-13 15:48:06

Judging History

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

  • [2023-08-13 15:48:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-08-13 15:48:03]
  • 提交

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_fast16_t doit(int lst, int type){
    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{
            cout << (n / i) * 2 + 1 << '\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{
        ans = min(doit(lst, 1), doit(lst, 0)) + lst / i + lst / j;
        cout << ans << '\n';
        return;
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

3 9 20

output:


result: