結果

問題 No.9 モンスターのレベル上げ
ユーザー yasunoriyasunori
提出日時 2024-04-15 09:58:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 770 ms / 5,000 ms
コード長 5,094 bytes
コンパイル時間 2,656 ms
コンパイル使用メモリ 215,584 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 09:58:37
合計ジャッジ時間 9,848 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 770 ms
6,944 KB
testcase_03 AC 628 ms
6,944 KB
testcase_04 AC 313 ms
6,940 KB
testcase_05 AC 205 ms
6,944 KB
testcase_06 AC 71 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 94 ms
6,940 KB
testcase_09 AC 770 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 462 ms
6,940 KB
testcase_12 AC 288 ms
6,944 KB
testcase_13 AC 385 ms
6,940 KB
testcase_14 AC 742 ms
6,940 KB
testcase_15 AC 680 ms
6,940 KB
testcase_16 AC 12 ms
6,944 KB
testcase_17 AC 432 ms
6,944 KB
testcase_18 AC 363 ms
6,944 KB
testcase_19 AC 7 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T> using min_priority_queue = priority_queue<T,vector<T>,greater<T>>;

random_device seed_gen;
mt19937 engine(seed_gen());

uint64_t rand64(){
    uint64_t a = engine();
    uint64_t b = engine();
    return (a << 32) + b;
}

int64_t get_time(){
    struct::timespec t;
    clock_gettime(CLOCK_MONOTONIC, &t);
    return t.tv_sec * int64_t(1'000'000'000) + t.tv_nsec;
}

template<typename T>
void invec(vector<T> &v){
    for(auto &i : v) cin >> i;
    return;
}

template<typename T>
void outvec(vector<T> &v){
    bool b = false;
    for(auto i : v){
        if(b) cout << " ";
        else b = true;
        cout << i;
    }
    cout << endl;
    return;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

bool yn(bool b){
    if(b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return b;
}

bool check_with_simple_solution;
bool calc_time;
bool random_input;
bool debug_output;
int num_of_testcase;

using ans_type = int;
int N;
vector<int> A, B;
int INF = 1001002003;

void input(){
    if(num_of_testcase > 1){
        A.clear();
        B.clear();
    }
    if(random_input){
        N = engine()%1500+1;
        N = 1500;
        for(int i = 0; i < N; i++) A.push_back(engine()%10000+1);
        for(int i = 0; i < N; i++) B.push_back(engine()%10000+1);
    }   
    else{
        cin >> N;
        A.resize(N);
        B.resize(N);
        invec(A);
        invec(B);
    }
    return;
}

void output_input(){
    cout << N << endl;
    outvec(A);
    outvec(B);
    return;
}

void pre_solve(){
    return;
}

ans_type solve(){
    int ans = INF;
    for(int i = 0; i < N; i++){
        if(debug_output) cout << "i: " << i << endl;
        multiset<pair<int,int>> Aset;
        for(int a : A) Aset.insert({a, 0});
        for(int j = i; j < i+N; j++){
            auto itr = Aset.begin();
            auto pr = *itr;

            if(debug_output) cout << pr.first << " " << pr.second << " -> ";

            pr.first += B[j % N] / 2;
            pr.second++;
            Aset.erase(itr);
            Aset.insert(pr);

            if(debug_output) cout << pr.first << " " << pr.second << endl;
        }
        int cnt = 0;
        for(auto[lv, c] : Aset) chmax(cnt, c);
        chmin(ans, cnt);
        
        if(debug_output){
            for(auto[lv, c] : Aset) cout << lv << " " << c << " / ";
            cout << endl;
        }
    }
    return ans;
    return ans_type();
}

ans_type solve_simple(){
    int ans = INF;
    for(int i = 0; i < N; i++){
        if(debug_output) cout << "i: " << i << endl;
        vector<pair<int,int>> V;
        for(int a : A) V.push_back({a, 0});
        for(int j = 0; j < N; j++){
            sort(V.begin(), V.end());

            if(debug_output) cout << V[0].first << " " << V[0].second << " -> ";

            V[0].first += B[(i + j) % N] / 2;
            V[0].second++;

            if(debug_output) cout << V[0].first << " " << V[0].second << endl;
        }
        int cnt = 0;
        for(auto [lv, c] : V) chmax(cnt, c);
        chmin(ans, cnt);

        if(debug_output){
            sort(V.begin(), V.end());
            for(auto[lv, c] : V) cout << lv << " " << c << " / ";
            cout << endl;
        }
    }
    return ans;
    return ans_type();
}

void output(ans_type ans){
    cout << ans << endl;
    return;
}

int main(){
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cout << fixed << setprecision(20);

    check_with_simple_solution = 0;
    calc_time = 0;
    random_input = 0;
    debug_output = 0;
    num_of_testcase = 1;
    
    if(num_of_testcase == 0) cin >> num_of_testcase;

    pre_solve();

    if(check_with_simple_solution){
        for(int i = 0; i < num_of_testcase; i++){
            if(debug_output) cout << "begin case " << i << " " << string(16, '=') << endl;
            input();
            ans_type ans = solve();
            if(debug_output) cout << string(16, '=') << endl;
            ans_type ans_simple = solve_simple();
            if(ans != ans_simple){
                cout << "input: " << endl;
                output_input();
                cout << "output: " << endl;
                output(ans);
                cout << "expected: " << endl;
                output(ans_simple);
            }
            if(debug_output) cout << "end case " << i << " " << string(16, '=') << endl;
        }
    }
    else{
        int64_t time_start = get_time();
        for(int i = 0; i < num_of_testcase; i++){
            input();
            output(solve());
        }
        int64_t time_end = get_time();

        if(calc_time){
            double time_per_case = (time_end - time_start) / (1e9 * num_of_testcase);
            cout << fixed << setprecision(3) << time_per_case << "[second/case]" << endl;
        }
    }

    return 0;
}
0