結果

問題 No.9 モンスターのレベル上げ
ユーザー なおなお
提出日時 2014-10-05 15:59:40
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 387 ms / 5,000 ms
コード長 1,542 bytes
コンパイル時間 770 ms
使用メモリ 3,548 KB
最終ジャッジ日時 2023-01-21 13:37:18
合計ジャッジ時間 5,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,428 KB
testcase_01 AC 1 ms
3,492 KB
testcase_02 AC 387 ms
3,544 KB
testcase_03 AC 308 ms
3,488 KB
testcase_04 AC 160 ms
3,484 KB
testcase_05 AC 105 ms
3,388 KB
testcase_06 AC 36 ms
3,452 KB
testcase_07 AC 2 ms
3,472 KB
testcase_08 AC 48 ms
3,388 KB
testcase_09 AC 377 ms
3,488 KB
testcase_10 AC 1 ms
3,420 KB
testcase_11 AC 305 ms
3,448 KB
testcase_12 AC 235 ms
3,508 KB
testcase_13 AC 187 ms
3,460 KB
testcase_14 AC 377 ms
3,420 KB
testcase_15 AC 343 ms
3,400 KB
testcase_16 AC 7 ms
3,440 KB
testcase_17 AC 219 ms
3,472 KB
testcase_18 AC 182 ms
3,452 KB
testcase_19 AC 4 ms
3,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define mp                  make_pair
int N, A[1501], B[1501];

int solve(){
    priority_queue<pair<int,int> > q0;
    REP(i,N) q0.push(mp(-A[i],0));

    int minv = 1<<29;
    REP(i,N){
        auto q = q0;
        REP(j,N){
            int add = B[(i+j)%N]/2;
            auto a = q.top(); q.pop();
            a.first-=add; a.second--;
            q.push(a);
        }
        int maxv = 0;
        while(q.size()){
            maxv = max(maxv, -q.top().second); q.pop();
        }
        minv = min(minv, maxv);
    }
    return minv;
}

int naive(){
    vector<pair<int,int> > v0,v;
    REP(i,N) v0.push_back(mp(A[i],0));
    sort(v0.begin(), v0.end());

    int minv = 1<<29;
    REP(i,N){
        v = v0;
        REP(j,N){
            int add = B[(i+j)%N]/2;
            v[0].first += add;
            v[0].second++;
            sort(v.begin(), v.end());
        }
        int maxv = 0;
        REP(j,N) maxv = max(maxv, v[j].second);
        //REP(j,N) cerr<<"("<<v[j].first<<","<<v[j].second<<"),"; cerr << endl;
        minv = min(minv, maxv);
    }
    return minv;
}

int main(){
    cin >> N;
    if(N > 1500){ cerr << "error" << endl; return 1; }
    REP(i,N){ cin >> A[i]; if(A[i] > 10000){ cerr << "error" << endl; return 1; } }
    REP(i,N){ cin >> B[i]; if(B[i] > 10000){ cerr << "error" << endl; return 1; } }

    cout << solve() << endl;
//  cout << naive() << endl;
    return 0;
}
0