結果
問題 | No.5014 セクスタプル (reactive) |
ユーザー | wanui |
提出日時 | 2022-12-29 21:54:50 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 9,580 bytes |
コンパイル時間 | 2,766 ms |
実行使用メモリ | 22,856 KB |
スコア | 631,796,955 |
平均クエリ数 | 34.65 |
最終ジャッジ日時 | 2022-12-29 21:59:41 |
合計ジャッジ時間 | 200,565 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,859 ms
21,880 KB |
testcase_01 | AC | 1,863 ms
22,600 KB |
testcase_02 | AC | 1,832 ms
21,756 KB |
testcase_03 | AC | 1,832 ms
21,780 KB |
testcase_04 | AC | 1,888 ms
21,880 KB |
testcase_05 | AC | 1,870 ms
22,600 KB |
testcase_06 | AC | 1,883 ms
21,768 KB |
testcase_07 | AC | 1,882 ms
21,880 KB |
testcase_08 | AC | 1,894 ms
21,796 KB |
testcase_09 | AC | 1,869 ms
21,880 KB |
testcase_10 | AC | 1,849 ms
22,564 KB |
testcase_11 | AC | 1,924 ms
22,856 KB |
testcase_12 | AC | 1,840 ms
22,832 KB |
testcase_13 | AC | 1,866 ms
22,612 KB |
testcase_14 | AC | 1,917 ms
21,992 KB |
testcase_15 | AC | 1,884 ms
21,868 KB |
testcase_16 | AC | 1,910 ms
22,608 KB |
testcase_17 | AC | 1,920 ms
21,916 KB |
testcase_18 | AC | 1,925 ms
21,892 KB |
testcase_19 | AC | 1,880 ms
21,916 KB |
testcase_20 | AC | 1,873 ms
21,980 KB |
testcase_21 | AC | 1,909 ms
22,276 KB |
testcase_22 | AC | 1,902 ms
22,564 KB |
testcase_23 | AC | 1,928 ms
21,880 KB |
testcase_24 | AC | 1,887 ms
22,252 KB |
testcase_25 | AC | 1,837 ms
22,608 KB |
testcase_26 | AC | 1,928 ms
21,768 KB |
testcase_27 | AC | 1,816 ms
21,928 KB |
testcase_28 | AC | 1,848 ms
21,880 KB |
testcase_29 | AC | 1,943 ms
21,756 KB |
testcase_30 | AC | 1,833 ms
22,252 KB |
testcase_31 | AC | 1,925 ms
21,748 KB |
testcase_32 | AC | 1,818 ms
22,856 KB |
testcase_33 | AC | 1,890 ms
21,892 KB |
testcase_34 | AC | 1,913 ms
22,264 KB |
testcase_35 | AC | 1,945 ms
21,768 KB |
testcase_36 | AC | 1,908 ms
21,868 KB |
testcase_37 | AC | 1,904 ms
21,768 KB |
testcase_38 | AC | 1,892 ms
21,928 KB |
testcase_39 | AC | 1,935 ms
22,264 KB |
testcase_40 | AC | 1,899 ms
22,576 KB |
testcase_41 | AC | 1,871 ms
21,880 KB |
testcase_42 | AC | 1,919 ms
22,420 KB |
testcase_43 | AC | 1,893 ms
22,216 KB |
testcase_44 | AC | 1,914 ms
21,916 KB |
testcase_45 | AC | 1,910 ms
21,916 KB |
testcase_46 | AC | 1,839 ms
22,204 KB |
testcase_47 | AC | 1,888 ms
22,608 KB |
testcase_48 | AC | 1,846 ms
22,552 KB |
testcase_49 | AC | 1,856 ms
22,264 KB |
testcase_50 | AC | 1,925 ms
21,940 KB |
testcase_51 | AC | 1,906 ms
22,564 KB |
testcase_52 | TLE | - |
testcase_53 | AC | 1,869 ms
22,552 KB |
testcase_54 | AC | 1,861 ms
21,756 KB |
testcase_55 | AC | 1,915 ms
22,204 KB |
testcase_56 | AC | 1,784 ms
21,756 KB |
testcase_57 | AC | 1,894 ms
22,204 KB |
testcase_58 | AC | 1,916 ms
21,780 KB |
testcase_59 | AC | 1,860 ms
22,456 KB |
testcase_60 | AC | 1,885 ms
22,600 KB |
testcase_61 | AC | 1,871 ms
21,892 KB |
testcase_62 | AC | 1,872 ms
22,608 KB |
testcase_63 | AC | 1,875 ms
21,768 KB |
testcase_64 | AC | 1,902 ms
22,552 KB |
testcase_65 | AC | 1,921 ms
21,892 KB |
testcase_66 | AC | 1,898 ms
22,552 KB |
testcase_67 | AC | 1,859 ms
21,992 KB |
testcase_68 | AC | 1,884 ms
22,264 KB |
testcase_69 | AC | 1,864 ms
21,756 KB |
testcase_70 | AC | 1,885 ms
22,680 KB |
testcase_71 | AC | 1,898 ms
22,704 KB |
testcase_72 | AC | 1,872 ms
21,744 KB |
testcase_73 | AC | 1,903 ms
21,868 KB |
testcase_74 | AC | 1,884 ms
21,756 KB |
testcase_75 | AC | 1,864 ms
21,980 KB |
testcase_76 | AC | 1,964 ms
21,928 KB |
testcase_77 | AC | 1,892 ms
22,276 KB |
testcase_78 | AC | 1,880 ms
22,704 KB |
testcase_79 | AC | 1,868 ms
22,692 KB |
testcase_80 | AC | 1,910 ms
22,444 KB |
testcase_81 | AC | 1,900 ms
22,576 KB |
testcase_82 | AC | 1,908 ms
22,444 KB |
testcase_83 | AC | 1,917 ms
21,768 KB |
testcase_84 | AC | 1,859 ms
21,904 KB |
testcase_85 | AC | 1,875 ms
21,940 KB |
testcase_86 | AC | 1,865 ms
22,204 KB |
testcase_87 | AC | 1,899 ms
21,940 KB |
testcase_88 | AC | 1,868 ms
22,004 KB |
testcase_89 | AC | 1,961 ms
21,648 KB |
testcase_90 | AC | 1,858 ms
22,252 KB |
testcase_91 | AC | 1,881 ms
21,980 KB |
testcase_92 | AC | 1,876 ms
22,612 KB |
testcase_93 | AC | 1,825 ms
22,420 KB |
testcase_94 | AC | 1,891 ms
21,892 KB |
testcase_95 | AC | 1,889 ms
21,904 KB |
testcase_96 | AC | 1,910 ms
21,916 KB |
testcase_97 | AC | 1,842 ms
21,892 KB |
testcase_98 | AC | 1,882 ms
22,576 KB |
testcase_99 | AC | 1,936 ms
21,904 KB |
ソースコード
#include <bits/stdc++.h> // clang-format off using namespace std; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} #define debug1(a) { cerr<<#a<<":"<<a<<endl; } #define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; } #define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; } #define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; } using pii = pair<int,int>; // clang-format on namespace marathon { mt19937 engine(0); clock_t start_time; double now() { return 1000.0 * (clock() - start_time) / CLOCKS_PER_SEC; } void marathon_init() { start_time = clock(); random_device seed_gen; engine.seed(seed_gen()); } int randint(int mn, int mx) { int rng = mx - mn + 1; return mn + (engine() % rng); } bool anneal_accept(double new_score, double old_score, double cur_time, double begin_time, double end_time, double begin_temp, double end_temp) { const int ANNEAL_RND = 1e8; const double ANNEAL_EPS = 1e-6; double temp = (begin_temp * (end_time - cur_time) + end_temp * (cur_time - begin_time)) / (end_time - begin_time); return (exp((new_score - old_score) / temp) > double(engine() % ANNEAL_RND) / ANNEAL_RND + ANNEAL_EPS); } } // namespace marathon const int N2 = 36; const int N = 6; const int SCORE_BASE = 3; const double END_TIME = 1900; struct six { int val[6]; }; struct monte_carlo_state { bool row_exist[6][6]; bool col_exist[6][6]; int row_cnt[6][6]; int col_cnt[6][6]; }; vector<six> all_rolls; map<vector<int>, int> rev_all_rolls; void make_all_rolls() { for (int a = 0; a < N; a++) { for (int b = 0; b < N; b++) { for (int c = 0; c < N; c++) { for (int d = 0; d < N; d++) { for (int e = 0; e < N; e++) { for (int f = 0; f < N; f++) { six s; for (int j = 0; j < N; j++) { s.val[j] = 0; } s.val[a]++; s.val[b]++; s.val[c]++; s.val[d]++; s.val[e]++; s.val[f]++; vector<int> r(N); for (int j = 0; j < N; j++) { r[j] = s.val[j]; } rev_all_rolls[r] = all_rolls.size(); all_rolls.push_back(s); } } } } } } } int calc_score(vector<vector<int>> &perm, vector<int> &rolls) { int score = 0; for (int i = 0; i < N; i++) { for (int d = 0; d < N; d++) { int cnt = 0; for (int j = 0; j < N; j++) { int rollid = perm[i][j]; int roll_cnt = all_rolls[rolls[rollid]].val[d]; if (!roll_cnt) { cnt = 0; break; } cnt += roll_cnt; } if (!cnt) continue; score += cnt - N + SCORE_BASE; } } for (int j = 0; j < N; j++) { for (int d = 0; d < N; d++) { int cnt = 0; for (int i = 0; i < N; i++) { int rollid = perm[i][j]; int roll_cnt = all_rolls[rolls[rollid]].val[d]; if (!roll_cnt) { cnt = 0; break; } cnt += roll_cnt; } if (!cnt) continue; score += cnt - N + SCORE_BASE; } } return score; } int row_score(vector<vector<int>> &perm, vector<six> &rolls, int xi) { int score = 0; { for (int d = 0; d < N; d++) { int cnt = 0; for (int j = 0; j < N; j++) { int rollid = perm[xi][j]; int roll_cnt = rolls[rollid].val[d]; if (!roll_cnt) { cnt = 0; break; } cnt += roll_cnt; } if (!cnt) continue; score += cnt - N + SCORE_BASE; } } return score; } int random_dice_roll() { return marathon::engine() % all_rolls.size(); } void update_state(monte_carlo_state &st, six roll, int i, int j) { for (int d = 0; d < N; d++) { st.row_cnt[i][d] += roll.val[d]; st.row_exist[i][d] &= (roll.val[d] > 0); st.col_cnt[j][d] += roll.val[d]; st.col_exist[j][d] &= (roll.val[d] > 0); } } int monte_carlo_score1(int s_turn, vector<int> s_rolls, vector<vector<int>> s_perm, int si, int sj) { int MONTE_CARLO_ITER = 840; if (s_turn < 10) MONTE_CARLO_ITER = 560; int score = 0; s_perm[si][sj] = s_turn; for (int iter = 0; iter < MONTE_CARLO_ITER; iter++) { auto rolls = s_rolls; auto perm = s_perm; vector<pii> rests; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (perm[i][j] < 0) rests.push_back({i, j}); } } shuffle(rests.begin(), rests.end(), marathon::engine); for (int turn = s_turn + 1; turn < N2; turn++) { pii pt = rests.back(); rests.pop_back(); perm[pt.first][pt.second] = turn; rolls[turn] = random_dice_roll(); } score += calc_score(perm, rolls); } return score; } int monte_carlo_score2(int s_turn, vector<int> s_rolls, vector<vector<int>> s_perm, int si, int sj) { int MONTE_CARLO_ITER = 420; if (s_turn < 10) MONTE_CARLO_ITER = 280; s_perm[si][sj] = s_turn; int score = 0; monte_carlo_state s_st; for (int i = 0; i < N; i++) { for (int d = 0; d < N; d++) { s_st.row_exist[i][d] = true; s_st.row_cnt[i][d] = 0; s_st.col_exist[i][d] = true; s_st.col_cnt[i][d] = 0; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (s_perm[i][j] >= 0) { int rollid = s_perm[i][j]; six roll = all_rolls[s_rolls[rollid]]; update_state(s_st, roll, i, j); } } } for (int iter = 0; iter < MONTE_CARLO_ITER; iter++) { auto rolls = s_rolls; auto perm = s_perm; monte_carlo_state st = s_st; for (int turn = s_turn + 1; turn < N2; turn++) { int rollid = random_dice_roll(); six roll = all_rolls[rollid]; rolls[turn] = rollid; pii pt; int bestscore = -1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (perm[i][j] >= 0) continue; int score = marathon::randint(1, 99); for (int d = 0; d < N; d++) { if (st.row_exist[i][d] && roll.val[d]) score += (roll.val[d] + st.row_cnt[i][d]) * 100; if (st.col_exist[j][d] && roll.val[d]) score += (roll.val[d] + st.col_cnt[j][d]) * 100; } if (bestscore < score) { bestscore = score; pt = {i, j}; } } } update_state(st, roll, pt.first, pt.second); perm[pt.first][pt.second] = turn; } score += calc_score(perm, rolls); } return score; } pii select_op(int turn, vector<int> &rolls, vector<vector<int>> &perm) { vector<pair<int, pii>> scores; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (perm[i][j] >= 0) continue; int score = monte_carlo_score1(turn, rolls, perm, i, j); scores.push_back({score, {i, j}}); } } sort(scores.rbegin(), scores.rend()); if (scores.size() <= 2) { return scores[0].second; } vector<pii> cand; cand.push_back(scores[0].second); cand.push_back(scores[1].second); cand.push_back(scores[2].second); scores.clear(); for (auto pt : cand) { int score = monte_carlo_score2(turn, rolls, perm, pt.first, pt.second); scores.push_back({score, {pt.first, pt.second}}); } sort(scores.rbegin(), scores.rend()); return scores[0].second; } int main() { marathon::marathon_init(); make_all_rolls(); vector<int> rolls(N2); vector<vector<int>> perm(N, vector<int>(N, -1)); for (int turn = 0; turn < N2 - 1; turn++) { vector<int> s(N); for (int j = 0; j < N; j++) { int d; cin >> d; d--; s[d]++; } rolls[turn] = rev_all_rolls[s]; pii op = select_op(turn, rolls, perm); cout << op.first + 1 << " " << op.second + 1 << endl; perm[op.first][op.second] = turn; } { rolls[N2 - 1] = random_dice_roll(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (perm[i][j] < 0) { perm[i][j] = N2 - 1; } } } int score = calc_score(perm, rolls); int now = marathon::now(); debug2(score, now); } return 0; }