結果
問題 | No.158 奇妙なお使い |
ユーザー | 古寺いろは |
提出日時 | 2015-04-14 01:11:41 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 591 ms / 5,000 ms |
コード長 | 1,966 bytes |
コンパイル時間 | 1,383 ms |
コンパイル使用メモリ | 181,020 KB |
実行使用メモリ | 59,136 KB |
最終ジャッジ日時 | 2024-06-29 01:41:30 |
合計ジャッジ時間 | 2,832 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 591 ms
59,136 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 6 ms
6,940 KB |
testcase_18 | AC | 65 ms
11,392 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 10 ms
6,944 KB |
testcase_22 | AC | 11 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 1 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 4 ms
6,944 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; int A[3], B[3], C[3]; int now[3]; int DB, DC; bool useB(){ int nokori = DB; int use0 = min(now[0], nokori / 1000); nokori -= use0 * 1000; int use1 = min(now[1], nokori / 100); nokori -= use1 * 100; int use2 = min(now[2], nokori / 1); nokori -= use2 * 1; if (nokori != 0) return false; now[0] += B[0] - use0; now[1] += B[1] - use1; now[2] += B[2] - use2; return true; } bool useC(){ int nokori = DC; int use0 = min(now[0], nokori / 1000); nokori -= use0 * 1000; int use1 = min(now[1], nokori / 100); nokori -= use1 * 100; int use2 = min(now[2], nokori / 1); nokori -= use2 * 1; if (nokori != 0) return false; now[0] += C[0] - use0; now[1] += C[1] - use1; now[2] += C[2] - use2; return true; } int main() { cin >> A[0] >> A[1] >> A[2]; cin >> DB; cin >> B[0] >> B[1] >> B[2]; cin >> DC; cin >> C[0] >> C[1] >> C[2]; auto first = make_tuple(A[0] * 1000 + A[1] * 100 + A[2], 0, A[0], A[1], A[2]); priority_queue<tuple<int, int, int, int, int>> pq; pq.push(first); set<tuple<int, int, int>> s; set<tuple<int, int, int, int, int>> s2; int ans = 0; while (pq.size()){ auto i = pq.top(); pq.pop(); now[0] = get<2>(i); now[1] = get<3>(i); now[2] = get<4>(i); ans = max(ans, get<1>(i)); //cout << get<0>(i) << " " << get<1>(i) << " " << get<2>(i) << " " << get<3>(i) << " " << get<4>(i) << endl; if (s.count(make_tuple(now[0], now[1], now[2]))) continue; s.insert(make_tuple(now[0], now[1], now[2])); if (useB()){ auto n = make_tuple(now[0] * 1000 + now[1] * 100 + now[2], get<1>(i) + 1, now[0], now[1], now[2]); if (s2.count(n) == 0){ pq.push(n); s2.insert(n); } now[0] = get<2>(i); now[1] = get<3>(i); now[2] = get<4>(i); } if (useC()){ auto n = make_tuple(now[0] * 1000 + now[1] * 100 + now[2], get<1>(i) + 1, now[0], now[1], now[2]); if (s2.count(n) == 0){ s2.insert(n); pq.push(n); } } } cout << ans << endl; }