結果

問題 No.9 モンスターのレベル上げ
ユーザー drymousedrymouse
提出日時 2024-02-16 18:18:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,782 ms / 5,000 ms
コード長 1,401 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 75,492 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-16 18:19:06
合計ジャッジ時間 15,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1,472 ms
6,676 KB
testcase_03 AC 1,021 ms
6,676 KB
testcase_04 AC 419 ms
6,676 KB
testcase_05 AC 234 ms
6,676 KB
testcase_06 AC 53 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 84 ms
6,676 KB
testcase_09 AC 1,380 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2,782 ms
6,676 KB
testcase_12 AC 13 ms
6,676 KB
testcase_13 AC 1,916 ms
6,676 KB
testcase_14 AC 1,412 ms
6,676 KB
testcase_15 AC 1,242 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 638 ms
6,676 KB
testcase_18 AC 516 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <memory.h>
#include <iostream>
#include <algorithm>

using namespace std;

void output(int array[], int l) {
    cout << "[";
    for (int i = 0; i < l; i++) {
        cout << array[i] << ", ";
    }
    cout << "]" << endl;
}

int main(void) {
    int N;
    cin >> N;
    int A[N], B[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    sort(A, A + N);
    int minimax = 1e+7;
    
    for (int h = 0; h < N; h++) {
        int level[N], battles[N];
        for (int i = 0; i < N; i++) {
            battles[i] = 0;
        }
        memcpy(level, A, sizeof(A));
        for (int i = 0; i < N; i++) {
            int nlevel = level[0] + B[(h+i)%N] / 2;
            int nbattles = battles[0] + 1;
            for (int j = 1; j < N + 1; j++) {
                if (nlevel < level[j] || (nlevel == level[j] && nbattles <= battles[j]) || j == N) {
                    level[j-1] = nlevel;
                    battles[j-1] = nbattles;
                    break;
                } else {
                    level[j-1] = level[j];
                    battles[j-1] = battles[j];
                }
            }
        }
        //output(level, N);
        //output(battles, N);
        minimax = min(minimax, *max_element(battles, battles + N));
    }
    cout << minimax << endl;
    
    return 0;
}
0