結果

問題 No.9 モンスターのレベル上げ
ユーザー keikei
提出日時 2018-03-29 21:51:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 501 ms / 5,000 ms
コード長 3,684 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 174,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 06:46:48
合計ジャッジ時間 7,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 501 ms
4,380 KB
testcase_03 AC 404 ms
4,380 KB
testcase_04 AC 213 ms
4,380 KB
testcase_05 AC 139 ms
4,380 KB
testcase_06 AC 47 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 63 ms
4,384 KB
testcase_09 AC 484 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 434 ms
4,376 KB
testcase_12 AC 352 ms
4,384 KB
testcase_13 AC 287 ms
4,380 KB
testcase_14 AC 491 ms
4,380 KB
testcase_15 AC 452 ms
4,380 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 289 ms
4,380 KB
testcase_18 AC 239 ms
4,380 KB
testcase_19 AC 6 ms
4,376 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/9>
 問題文============================================================
 HeliaはRPGゲームをしている。そのRPGゲームは味方のモンスターのレベル上げていきゲームを進めるゲームである。
 Heliaは手持ちにN匹のモンスターのパーティーがいてレベル上げしたいと思っている。
 
 レベル上げは、敵のモンスターと1対1で戦い、敵のレベルの半分小数切り捨てを獲得できる。
 (自分の戦ったモンスターのレベルに加算する)
 
 例えば、自分のモンスターのレベルが1で相手のモンスターのレベルが5の時、
 戦ったあと、自分のモンスターのレベルは3になる。
 戦いに関してはアイテムを駆使してでも勝つため、レベル差に関係なく勝てるとする。
 
 ここで、敵のモンスターが円状に時計回りに並んでいて、
 最初に戦うモンスターを決めると時計回りの順番に全員と一度だけ戦うことができる狩場がある。
 (最初に戦えるモンスターは自由に選べる)
 Heliaは、自分の手持ちのモンスターの中から、1戦毎、その時に一番レベルが低い、
 複数いる場合は、一番戦いをしてないモンスターを戦わせるとする。
 
 この狩場のモンスターを全て倒すとして、
 手持ちのパーティー中で戦闘回数が一番多い回数がもっとも低くなるよう狩場で最初に戦うモンスターを選んだとき、
 その中で一番戦闘回数が多い数を求めてください。
 
 =================================================================
 解説=============================================================
 全ての開始位置について
 愚直シミュレーションだとO(N^3)になって間に合わないが
 priority_queueなどで次に選ぶべきモンスターを洗濯すれば O(N^2 *logN)となる
 
 ================================================================
 */

ll solve(){
    ll res = LINF;
    ll N; cin >> N;
    vector<ll> A(N),B(N);
    for(auto& in:A) cin >> in;
    for(auto& in:B) cin >> in;
    
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    for(int i = 0; i < N;i++){
        for(int j = 0; j < N;j++) pq.push({A[j],0});
        for(int j = 0; j < N;j++){
            pll p = pq.top(); pq.pop();
            p.first += B[(i+j)%N]/2; p.second++;
            pq.push(p);
        }
        ll t = 0;
        while(pq.size()){ t = max(t,pq.top().second); pq.pop(); }
        res = min(t,res);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}
0