結果

問題 No.158 奇妙なお使い
ユーザー cormorancormoran
提出日時 2016-11-15 18:00:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 2,734 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 183,296 KB
実行使用メモリ 47,228 KB
最終ジャッジ日時 2023-09-12 07:10:08
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
46,828 KB
testcase_01 AC 34 ms
46,892 KB
testcase_02 AC 34 ms
47,108 KB
testcase_03 AC 34 ms
46,824 KB
testcase_04 AC 105 ms
47,228 KB
testcase_05 AC 34 ms
46,836 KB
testcase_06 AC 34 ms
46,832 KB
testcase_07 AC 34 ms
46,772 KB
testcase_08 AC 34 ms
46,880 KB
testcase_09 AC 34 ms
46,904 KB
testcase_10 AC 35 ms
47,064 KB
testcase_11 AC 35 ms
46,824 KB
testcase_12 AC 35 ms
46,880 KB
testcase_13 AC 35 ms
46,920 KB
testcase_14 AC 34 ms
46,848 KB
testcase_15 AC 35 ms
47,028 KB
testcase_16 AC 35 ms
46,828 KB
testcase_17 AC 36 ms
46,792 KB
testcase_18 AC 49 ms
46,896 KB
testcase_19 AC 34 ms
46,768 KB
testcase_20 AC 36 ms
46,800 KB
testcase_21 AC 36 ms
46,776 KB
testcase_22 AC 35 ms
46,884 KB
testcase_23 AC 35 ms
46,832 KB
testcase_24 AC 35 ms
46,784 KB
testcase_25 AC 34 ms
46,916 KB
testcase_26 AC 34 ms
46,844 KB
testcase_27 AC 35 ms
46,824 KB
testcase_28 AC 35 ms
47,112 KB
testcase_29 AC 34 ms
46,948 KB
testcase_30 AC 35 ms
46,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define rrep(i, j) for(int i=(j)-1; i >= 0; i--)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

tuple<bool, int, int, int> make(int a, int b, int c, int D) {
    int DD = D;
    int aa = min(a, D / 1000);
    D -= aa * 1000;
    int bb = min(b, D / 100);
    D -= bb * 100;
    int cc = D;
    return make_tuple(cc <= c, a - aa, b - bb, c - cc);
}

struct state {
    int a, b, c;
    bool operator < (const state &s) const {
        return a * 1000 + b * 100 + c < s.a * 1000 + s.b * 1000 + s.c;
    }
};

class Solver {
  public:
    bool solve() {
        vector<int> A(3), B(3), C(3);
        int Db, Dc;
        cin >> A >> Db >> B >> Dc >> C;

        vector<vector<vector<int>>> dp(11);
        for(auto &a : dp ) {
            a.resize(101);
            for(auto &b : a) b.resize(10001, -INF);
        }

        priority_queue<state> que;
        que.push({A[0], A[1], A[2]});
        
        dp[A[0]][A[1]][A[2]] = 0;
        int ans = 0;

        while(que.size()) {
            state now = que.top(); que.pop();
            int a = now.a, b = now.b, c = now.c;
            
            bool ok;
            int aa, bb, cc;
            tie(ok, aa, bb, cc) = make(a, b, c, Db);
            if(ok and set_max(dp[aa + B[0]][bb + B[1]][cc + B[2]], dp[a][b][c] + 1)) {
                set_max(ans, dp[a][b][c] + 1);
                que.push({aa + B[0], bb + B[1], cc + B[2]});
            }            
            tie(ok, aa, bb, cc) = make(a, b, c, Dc);
            if(ok and set_max(dp[aa + C[0]][bb + C[1]][cc + C[2]], dp[a][b][c] + 1)) {
                set_max(ans, dp[a][b][c] + 1);
                que.push({aa + C[0], bb + C[1], cc + C[2]});
            }
        }
        
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0