結果

問題 No.3068 Speedrun (Hard)
ユーザー t98slider
提出日時 2025-03-21 23:35:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,318 ms / 2,000 ms
コード長 1,411 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 196,972 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-21 23:35:20
合計ジャッジ時間 11,585 ms
ジャッジサーバーID
(参考情報)
judge7 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll t, n;
    vector<ll> a(4), b(4);
    cin >> a >> n >> b >> t;
    const ll d = b[2] - b[3];
    for(ll i = 0; i <= n && i <= a[0] && i * b[0] <= t; i++){
        for(ll j = 0; i + j <= n && j <= a[1] && i * b[0] + j * b[1] <= t; j++){
            ll rt = t - (i * b[0] + j * b[1]);
            ll r = n - (i + j);
            // Ax + B * (r - x) = rt
            // (A - B) * x + B * r == rt
            ll rhs = rt - b[3] * r;
            if(rhs == 0 && r <= a[3]){
                cout << i << " " << j << " " << 0 << " " << r << '\n';
                return 0;
            }
            if(d == 0){
                ll c2 = min(a[2], r), c3 = r - c2;
                if(b[2] * c2 + b[3] * c3 == rt && c3 <= a[3]){
                    cout << i << " " << j << " " << c2 << " " << c3 << '\n';
                    return 0;
                }
                continue;
            }
            if(rhs % d != 0) continue;
            ll c2 = rhs / d, c3 = r - c2;
            if(0 <= c2 && c2 <= a[2] && 0 <= c3 && c3 <= a[3]){
                cout << i << " " << j << " " << c2 << " " << c3 << '\n';
                return 0;
            }
        }
    }
}
0