結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2017-06-18 14:42:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 508 ms / 5,000 ms |
コード長 | 1,077 bytes |
コンパイル時間 | 681 ms |
コンパイル使用メモリ | 73,228 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 00:10:31 |
合計ジャッジ時間 | 5,636 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | int n; scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:13:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | for(int i=0; i<n; ++i) { scanf("%d", &a[i]); } | ~~~~~^~~~~~~~~~~~~ main.cpp:14:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | for(int i=0; i<n; ++i) { scanf("%d", &b[i]); } | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <queue> #include <tuple> using namespace std; constexpr int inf = 987654321; int main(void) { int n; scanf("%d", &n); vector<int> a(n, 0); // a[n] vector<int> b(n, 0); // b[n] for(int i=0; i<n; ++i) { scanf("%d", &a[i]); } for(int i=0; i<n; ++i) { scanf("%d", &b[i]); } int res = inf; for(int i=0; i<n; ++i) { // 敵の最初を決める priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; for(int j=0; j<n; ++j) { // 味方: レベル、戦闘回数 pq.emplace(a[j], 0); } int mini = inf; for(int kk=i; kk<i+n; ++kk) { int k = kk % n; // 敵の番号 int level, cnt; tie(level, cnt) = pq.top(); pq.pop(); // 対戦する味方の情報 pq.emplace(level + b[k] / 2, cnt+1); } int maxi = 0; // 戦闘回数が最大な味方の、その回数 while(!pq.empty()) { int _, cnt; tie(_, cnt) = pq.top(); pq.pop(); maxi = max(maxi, cnt); } res = min(res, maxi); } printf("%d\n", res); return 0; }