結果

問題 No.158 奇妙なお使い
ユーザー keikei
提出日時 2018-08-27 21:23:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,477 ms / 5,000 ms
コード長 3,036 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 171,620 KB
実行使用メモリ 90,452 KB
最終ジャッジ日時 2023-09-13 19:37:58
合計ジャッジ時間 65,231 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,914 ms
90,160 KB
testcase_01 AC 1,906 ms
90,320 KB
testcase_02 AC 1,912 ms
90,180 KB
testcase_03 AC 1,918 ms
90,168 KB
testcase_04 AC 2,477 ms
90,188 KB
testcase_05 AC 1,907 ms
90,284 KB
testcase_06 AC 1,911 ms
90,452 KB
testcase_07 AC 1,911 ms
90,188 KB
testcase_08 AC 1,902 ms
90,188 KB
testcase_09 AC 1,905 ms
90,280 KB
testcase_10 AC 1,908 ms
90,184 KB
testcase_11 AC 1,917 ms
90,184 KB
testcase_12 AC 1,913 ms
90,232 KB
testcase_13 AC 1,917 ms
90,316 KB
testcase_14 AC 1,910 ms
90,204 KB
testcase_15 AC 1,907 ms
90,188 KB
testcase_16 AC 1,908 ms
90,184 KB
testcase_17 AC 1,925 ms
90,236 KB
testcase_18 AC 1,969 ms
90,244 KB
testcase_19 AC 1,906 ms
90,156 KB
testcase_20 AC 1,906 ms
90,240 KB
testcase_21 AC 1,929 ms
90,436 KB
testcase_22 AC 1,925 ms
90,204 KB
testcase_23 AC 1,919 ms
90,208 KB
testcase_24 AC 1,910 ms
90,268 KB
testcase_25 AC 1,907 ms
90,188 KB
testcase_26 AC 1,913 ms
90,212 KB
testcase_27 AC 1,901 ms
90,280 KB
testcase_28 AC 1,915 ms
90,344 KB
testcase_29 AC 1,914 ms
90,284 KB
testcase_30 AC 1,919 ms
90,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://yukicoder.me/problems/no/158>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll dp[11][101][10001];

tuple<int,int,int> can_pay(int i,int j,int k,int D){
    int t;
    
    t = min(i,D/1000);
    i -= t; D -= t*1000;
    
    t = min(j,D/100);
    j -= t; D -= t*100;
    
    t = min(k,D);
    k -= t; D -= t;
    if(D) return tuple<int,int,int>{-1,-1,-1};
    return tuple<int,int,int>{i,j,k};
}
ll solve(){
    fill(**dp,**dp+11*101*10001,-1);
    ll res = 0;
    vector<ll> A(3),B(3),C(3);
    int Db,Dc;
    for(auto& in:A) cin >> in;
    cin >> Db;
    for(auto& in:B) cin >> in;
    cin >> Dc;
    for(auto& in:C) cin >> in;
    
    dp[A[0]][A[1]][A[2]] = 0;
    for(int kassa = 0; kassa < 100; kassa++){
   
        for(int i = 10; i >= 0; i--){
            for(int j = 100; j >= 0; j--){
                for(int k = 10000; k >= 0; k--){
                    if(dp[i][j][k] == -1) continue;
                    {
                        int ni,nj,nk; tie(ni,nj,nk) = can_pay(i, j, k, Db);
                        if(ni != -1){
                            dp[ni+B[0]][nj+B[1]][nk+B[2]] = max(dp[ni+B[0]][nj+B[1]][nk+B[2]],dp[i][j][k]+1);
                        }
                    }
                    {
                        int ni,nj,nk; tie(ni,nj,nk) = can_pay(i, j, k, Dc);
                        if(ni != -1){
                            dp[ni+C[0]][nj+C[1]][nk+C[2]] = max(dp[ni+C[0]][nj+C[1]][nk+C[2]],dp[i][j][k]+1);
                        }
                    }
                }
            }
        }
    }
    for(int i = 10; i >= 0; i--){
        for(int j = 100; j >= 0; j--){
            for(int k = 10000; k >= 0; k--){
                res = max(res,dp[i][j][k]);
            }
        }
    }
    
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}
0