結果

問題 No.5004 Room Assignment
ユーザー 👑 NachiaNachia
提出日時 2021-12-01 23:55:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 4,557 bytes
コンパイル時間 1,094 ms
実行使用メモリ 22,380 KB
スコア 139,870,768
平均クエリ数 7643.62
最終ジャッジ日時 2021-12-01 23:56:20
合計ジャッジ時間 19,492 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
21,948 KB
testcase_01 AC 137 ms
22,032 KB
testcase_02 AC 130 ms
21,924 KB
testcase_03 AC 129 ms
21,936 KB
testcase_04 AC 128 ms
21,960 KB
testcase_05 AC 128 ms
22,092 KB
testcase_06 AC 128 ms
21,912 KB
testcase_07 AC 128 ms
21,888 KB
testcase_08 AC 127 ms
21,960 KB
testcase_09 AC 127 ms
21,900 KB
testcase_10 AC 138 ms
21,768 KB
testcase_11 AC 129 ms
22,092 KB
testcase_12 AC 126 ms
21,924 KB
testcase_13 AC 128 ms
21,936 KB
testcase_14 AC 128 ms
22,152 KB
testcase_15 AC 127 ms
22,020 KB
testcase_16 AC 128 ms
22,128 KB
testcase_17 AC 128 ms
21,912 KB
testcase_18 AC 129 ms
21,768 KB
testcase_19 AC 136 ms
22,128 KB
testcase_20 AC 140 ms
21,972 KB
testcase_21 AC 129 ms
21,920 KB
testcase_22 AC 129 ms
21,944 KB
testcase_23 AC 129 ms
21,924 KB
testcase_24 AC 129 ms
21,972 KB
testcase_25 AC 129 ms
21,912 KB
testcase_26 AC 129 ms
21,792 KB
testcase_27 AC 129 ms
22,128 KB
testcase_28 AC 130 ms
21,936 KB
testcase_29 AC 144 ms
21,912 KB
testcase_30 AC 130 ms
22,104 KB
testcase_31 AC 129 ms
22,020 KB
testcase_32 AC 127 ms
21,780 KB
testcase_33 AC 128 ms
21,936 KB
testcase_34 AC 130 ms
21,780 KB
testcase_35 AC 128 ms
21,780 KB
testcase_36 AC 127 ms
21,780 KB
testcase_37 AC 129 ms
22,104 KB
testcase_38 AC 129 ms
21,984 KB
testcase_39 AC 140 ms
21,780 KB
testcase_40 AC 128 ms
21,936 KB
testcase_41 AC 128 ms
21,924 KB
testcase_42 AC 128 ms
22,380 KB
testcase_43 AC 127 ms
21,972 KB
testcase_44 AC 129 ms
22,016 KB
testcase_45 AC 130 ms
21,936 KB
testcase_46 AC 128 ms
22,104 KB
testcase_47 AC 127 ms
22,152 KB
testcase_48 AC 140 ms
22,368 KB
testcase_49 AC 138 ms
21,948 KB
testcase_50 AC 130 ms
21,936 KB
testcase_51 AC 131 ms
21,768 KB
testcase_52 AC 127 ms
22,152 KB
testcase_53 AC 129 ms
21,900 KB
testcase_54 AC 127 ms
21,972 KB
testcase_55 AC 127 ms
22,128 KB
testcase_56 AC 127 ms
22,128 KB
testcase_57 AC 133 ms
22,212 KB
testcase_58 AC 141 ms
21,912 KB
testcase_59 AC 130 ms
21,972 KB
testcase_60 AC 128 ms
21,912 KB
testcase_61 AC 128 ms
21,984 KB
testcase_62 AC 129 ms
21,948 KB
testcase_63 AC 134 ms
22,356 KB
testcase_64 AC 130 ms
21,900 KB
testcase_65 AC 129 ms
21,792 KB
testcase_66 AC 128 ms
21,960 KB
testcase_67 AC 144 ms
21,960 KB
testcase_68 AC 131 ms
22,092 KB
testcase_69 AC 129 ms
22,092 KB
testcase_70 AC 129 ms
21,912 KB
testcase_71 AC 130 ms
21,924 KB
testcase_72 AC 130 ms
22,152 KB
testcase_73 AC 131 ms
21,792 KB
testcase_74 AC 128 ms
21,948 KB
testcase_75 AC 130 ms
21,780 KB
testcase_76 AC 145 ms
21,840 KB
testcase_77 AC 137 ms
22,032 KB
testcase_78 AC 127 ms
22,212 KB
testcase_79 AC 128 ms
22,020 KB
testcase_80 AC 130 ms
21,960 KB
testcase_81 AC 127 ms
21,936 KB
testcase_82 AC 128 ms
21,780 KB
testcase_83 AC 129 ms
21,936 KB
testcase_84 AC 130 ms
22,044 KB
testcase_85 AC 131 ms
22,152 KB
testcase_86 AC 149 ms
21,924 KB
testcase_87 AC 129 ms
21,960 KB
testcase_88 AC 128 ms
21,960 KB
testcase_89 AC 130 ms
21,936 KB
testcase_90 AC 128 ms
22,032 KB
testcase_91 AC 128 ms
22,152 KB
testcase_92 AC 129 ms
21,924 KB
testcase_93 AC 130 ms
21,924 KB
testcase_94 AC 130 ms
21,840 KB
testcase_95 AC 143 ms
22,128 KB
testcase_96 AC 136 ms
21,780 KB
testcase_97 AC 128 ms
21,936 KB
testcase_98 AC 128 ms
21,936 KB
testcase_99 AC 129 ms
21,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <cmath>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)


vector<int> player_skills;
vector<int> player_times;

double enter_count_sum;


struct Room{
    int id;
    vector<int> players;
    int value_e;

    Room(int player_id){
        id = player_id;
        players = { id };
        value_e = 0;
    }

    int get_num_players() const { return players.size(); }

    pair<int,int> merge_in(Room another, int tick){
        value_e += another.value_e;
        for(int l : players) for(int r : another.players){
            value_e += tick - player_times[l];
            value_e += tick - player_times[r];
        }
        for(int r : another.players) players.push_back(r);
        return { id, another.id };
    }

    double receive_score(int player_id, int tick){
        double skill = player_skills[player_id];
        
        int min_skill = 100;
        int max_skill = 0;
        int min_tick = 1001001;
        for(auto a : players){
            min_skill = min(min_skill, player_skills[a]);
            max_skill = max(max_skill, player_skills[a]);
            min_tick = min(min_tick, player_times[a]);
        }
        if(min_skill <= skill && skill <= max_skill) return 1.0e100;
        double mid_skill = (min_skill + max_skill) / 2.0;
        tick -= min_tick;

        // double w = 4.0;
        // double w = pow((mid_skill - 50.0) / 50.0, 2.0) * 2.0 + 3.2;
        // double w = (exp(abs(mid_skill - 50.0) / 50.0 * 0.1) - 1.0) * 2.0 + 3.0;
        double w = (exp(pow(abs(mid_skill-50.0), 2.0) / 4500.0) - 1.0) * 2.0 + 3.75;


        double margin_ticks = 30.0;
        double margin_w = 0.0;
        // if(tick >= margin_ticks) margin_w += (log(tick / margin_ticks)) * 1.0;
        // if(tick >= margin_ticks) margin_w += (log(tick / margin_ticks)) * 1.0;
        margin_w += 1.5 / (enter_count_sum + 0.1) - 1.0;
        if(tick >= margin_ticks) margin_w += (log(tick / margin_ticks)) * 1.0;
        margin_w *= 0.5;
        // if(tick >= margin_ticks) margin_w += (tick - margin_ticks) / 20;
        if(false){
            cerr << w;
            cerr << ", " << enter_count_sum;
            cerr << "\n";
        }
        w += margin_w;

        double l = min<double>(min_skill, max_skill - w);
        double r = max<double>(max_skill, min_skill + w);

        auto skill_dist = abs(mid_skill - skill) / 100.0;
        // return (l <= skill && skill <= r) ? (100.0 - skill_dist) : 0.0;
        return (l <= skill && skill <= r) ? (100.0 - skill_dist / w) : 0.0;
    }
};




int main(){

    const double enter_count_delay = 0.95;
    enter_count_sum = 10;

    vector<Room> rooms;

    int num_tick; cin >> num_tick;
    int max_room_size; cin >> max_room_size;

    int next_player_id = 1;
    player_skills.push_back(0);
    player_times.push_back(0);

    rep(tick_idx, num_tick){
        int num_enter; cin >> num_enter;
        vector<pair<int,int>> buf;

        enter_count_sum *= enter_count_delay;
        enter_count_sum += (1.0 - enter_count_delay) * num_enter;

        rep(enter_idx, num_enter){
            int enter_id = next_player_id++;
            int player_skill; cin >> player_skill;
            player_skills.push_back(player_skill);
            player_times.push_back(tick_idx);
            
            int to_enter = -1;
            double receive_score_max = 0.0;
            rep(room_arr_idx, rooms.size()){
                auto receive_score = rooms[room_arr_idx].receive_score(enter_id, tick_idx);
                if(receive_score > receive_score_max){
                    to_enter = room_arr_idx;
                    receive_score_max = receive_score;
                }
            }

            if(to_enter == -1){
                rooms.emplace_back(enter_id);
            }
            else{
                buf.push_back(rooms[to_enter].merge_in(Room(enter_id), tick_idx));
                if(rooms[to_enter].players.size() >= max_room_size){
                    swap(rooms[to_enter], rooms.back());
                    rooms.pop_back();
                }
            }
        }

        cout << buf.size() << "\n";
        for(auto a : buf){
            cout << a.first << " " << a.second << "\n";
        }
        cout << flush;
    }
    return 0;
}




struct ios_do_not_sync {
    ios_do_not_sync() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0