結果

問題 No.5004 Room Assignment
ユーザー 👑 NachiaNachia
提出日時 2021-12-01 18:37:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 150 ms / 5,000 ms
コード長 3,765 bytes
コンパイル時間 1,425 ms
実行使用メモリ 22,380 KB
スコア 139,489,241
平均クエリ数 7643.15
最終ジャッジ日時 2021-12-01 18:37:22
合計ジャッジ時間 21,425 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#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;


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 = pow((mid_skill - 50.0) / 50.0, 2.0) * 2.0 + 3.0;
        //double w = 4.0;

        double margin_ticks = 30.0;
        double margin_w = 0.0;
        if(tick >= margin_ticks) w += (log(tick / margin_ticks)) * 1.0;
        // if(tick >= margin_ticks) margin_w += (tick - margin_ticks) / 20;
        // if(tick >= margin_ticks) cerr << margin_w << endl;
        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;
    }
};




int main(){

    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;

        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