結果
問題 | No.5014 セクスタプル (reactive) |
ユーザー | wanui |
提出日時 | 2022-12-29 15:47:50 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 743 ms / 2,000 ms |
コード長 | 5,817 bytes |
コンパイル時間 | 3,059 ms |
実行使用メモリ | 22,864 KB |
スコア | 572,160,361 |
平均クエリ数 | 35.00 |
最終ジャッジ日時 | 2022-12-29 15:52:17 |
合計ジャッジ時間 | 82,746 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#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; } // 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]; }; int calc_score(vector<vector<int>> &perm, vector<six> &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 = 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 = 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; } six random_dice_roll() { six s; for (int i = 0; i < N; i++) { s.val[i] = 0; } for (int i = 0; i < N; i++) { int d = marathon::engine() % N; s.val[d]++; } return s; } int monte_carlo_score(int s_turn, vector<six> &s_rolls, vector<vector<int>> &s_perm, int si, int sj) { const int MONTE_CARLO_ITER = 170; int score = 0; for (int iter = 0; iter < MONTE_CARLO_ITER; iter++) { auto rolls = s_rolls; auto perm = s_perm; perm[si][sj] = s_turn; for (int turn = s_turn + 1; turn < N2; turn++) { int rest = N2 - turn; int tgt = marathon::engine() % rest; int c = 0; rolls[turn] = random_dice_roll(); for (int i = 0; (c >= 0 && i < N); i++) { for (int j = 0; (c >= 0 && j < N); j++) { if (perm[i][j] >= 0) continue; if (c == tgt) { perm[i][j] = turn; c = -1; break; } c++; } } random_dice_roll(); } score += calc_score(perm, rolls); } return score; } pair<int, int> select_op(int turn, vector<six> &rolls, vector<vector<int>> &perm) { vector<pair<int, pair<int, int>>> 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_score(turn, rolls, perm, i, j); scores.push_back({score, {i, j}}); } } sort(scores.rbegin(), scores.rend()); return scores[0].second; } int main() { marathon::marathon_init(); vector<six> rolls(N2); vector<vector<int>> perm(N, vector<int>(N, -1)); for (int turn = 0; turn < N2 - 1; turn++) { six s; for (int k = 0; k < N; k++) { s.val[k] = 0; } for (int j = 0; j < N; j++) { int d; cin >> d; d--; s.val[d]++; } rolls[turn] = s; pair<int, int> 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; }