QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#181637#5259. Skills in Pillsucup-team1209TL 0ms0kbC++141.2kb2023-09-16 21:40:132023-09-16 21:40:14

Judging History

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

  • [2023-09-16 21:40:14]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-09-16 21:40:13]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
using pi = pair <int, int> ; 

void cmn(int &x, int y) {
    if(x > y) x = y; 
}
cs int N = 1e6 + 5; 

int n, a, b, f[N][2];

pi calc(int x, int y) {
    int ans = 0; 
    if(x == y) {
        x += a; 
        ++ ans; 
    }
    while(x != y) {
        if(x < y) x += a; 
        else y += b; 
        ++ ans; 
    }
    return {x, ans};
}
int F(int x, int y, int n) {
    return (n - x) / a + (n - y) / b;
}

int main() {
    #ifdef zqj 
    freopen("1.in","r",stdin);
    #endif
    cin >> a >> b >> n; 
    memset(f, 0x3f, sizeof f);
    auto [p0, c0] = calc(0, 0);
    auto [p1, c1] = calc(-1, 0);
    auto [p2, c2] = calc(0, -1);
    f[p0][0] = f[p0][1] = c0; 
    int ans = 1e9; 
    for(int i = p0; i <= n; i++) {
        if(i + p1 > n) cmn(ans, f[i][0] + F(i - 1, i, n));
        else {
            cmn(f[i + p1][0], f[i][0] + c1);
            cmn(f[i + p1][1], f[i][0] + c1);
        }
        if(i + p2 > n) cmn(ans, f[i][1] + F(i, i - 1, n));
        else {
            cmn(f[i + p2][0], f[i][1] + c2);
            cmn(f[i + p2][1], f[i][1] + c2);
        }
    }
    cout << ans << '\n';
    return 0; 
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3 9 20

output:


result: