結果

問題 No.2390 Udon Coupon (Hard)
ユーザー wtz2333
提出日時 2023-07-21 22:12:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 798 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 168,652 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 01:51:52
合計ジャッジ時間 2,437 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll V;
    cin >> V;
    int n = 3;
    std::vector<ll> v(3),c(3);
    ll w = 0,m = 1;
    ll mn = 1e9;
    for(int i = 0;i < 3;i ++){
        cin >> v[i] >> c[i];
        if(w * v[i] < m * c[i])w = c[i],m = v[i];
        mn = min(v[i],mn);
    }
    std::vector<ll> f(m);
    for(int i = 0; i < n; i++){
        for(int j = 0, lim = __gcd(v[i], m); j < lim; j++){
            for(int t = j, _ = 0; _ < 2; _ += t == j) {
                int q = (t + v[i]) % m;
                f[q] = max(f[q], f[t] + c[i] - ((t + v[i]) / m) * w), t = q;
            }
        }
    }
    if(V < mn) cout << 0 << "\n";
    else cout << f[V % m] + (V / m * w) << "\n";
    return 0;
}
0