結果

問題 No.5013 セクスタプル (open)
ユーザー wanuiwanui
提出日時 2022-12-29 15:10:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,966 ms / 2,000 ms
コード長 6,313 bytes
コンパイル時間 2,234 ms
実行使用メモリ 5,164 KB
スコア 18,408
最終ジャッジ日時 2022-12-29 15:13:44
合計ジャッジ時間 202,255 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,933 ms
3,856 KB
testcase_01 AC 1,932 ms
3,800 KB
testcase_02 AC 1,931 ms
3,804 KB
testcase_03 AC 1,934 ms
3,848 KB
testcase_04 AC 1,938 ms
4,020 KB
testcase_05 AC 1,932 ms
3,804 KB
testcase_06 AC 1,931 ms
3,848 KB
testcase_07 AC 1,940 ms
3,844 KB
testcase_08 AC 1,930 ms
3,700 KB
testcase_09 AC 1,934 ms
3,716 KB
testcase_10 AC 1,940 ms
3,848 KB
testcase_11 AC 1,932 ms
3,700 KB
testcase_12 AC 1,940 ms
3,804 KB
testcase_13 AC 1,939 ms
3,720 KB
testcase_14 AC 1,938 ms
3,848 KB
testcase_15 AC 1,931 ms
3,784 KB
testcase_16 AC 1,951 ms
3,800 KB
testcase_17 AC 1,931 ms
3,716 KB
testcase_18 AC 1,932 ms
3,884 KB
testcase_19 AC 1,938 ms
3,800 KB
testcase_20 AC 1,930 ms
3,816 KB
testcase_21 AC 1,931 ms
3,776 KB
testcase_22 AC 1,940 ms
3,712 KB
testcase_23 AC 1,931 ms
3,968 KB
testcase_24 AC 1,935 ms
3,796 KB
testcase_25 AC 1,944 ms
3,780 KB
testcase_26 AC 1,933 ms
3,700 KB
testcase_27 AC 1,931 ms
3,712 KB
testcase_28 AC 1,966 ms
3,800 KB
testcase_29 AC 1,930 ms
3,784 KB
testcase_30 AC 1,932 ms
4,900 KB
testcase_31 AC 1,931 ms
3,756 KB
testcase_32 AC 1,952 ms
3,880 KB
testcase_33 AC 1,930 ms
3,812 KB
testcase_34 AC 1,945 ms
3,880 KB
testcase_35 AC 1,936 ms
3,800 KB
testcase_36 AC 1,931 ms
3,704 KB
testcase_37 AC 1,952 ms
3,848 KB
testcase_38 AC 1,931 ms
3,704 KB
testcase_39 AC 1,932 ms
3,700 KB
testcase_40 AC 1,949 ms
3,712 KB
testcase_41 AC 1,932 ms
4,020 KB
testcase_42 AC 1,952 ms
3,720 KB
testcase_43 AC 1,931 ms
3,844 KB
testcase_44 AC 1,944 ms
3,852 KB
testcase_45 AC 1,952 ms
3,700 KB
testcase_46 AC 1,931 ms
3,772 KB
testcase_47 AC 1,939 ms
4,020 KB
testcase_48 AC 1,939 ms
3,716 KB
testcase_49 AC 1,933 ms
3,716 KB
testcase_50 AC 1,952 ms
3,856 KB
testcase_51 AC 1,931 ms
3,884 KB
testcase_52 AC 1,933 ms
3,780 KB
testcase_53 AC 1,940 ms
4,020 KB
testcase_54 AC 1,930 ms
3,780 KB
testcase_55 AC 1,942 ms
3,852 KB
testcase_56 AC 1,938 ms
4,024 KB
testcase_57 AC 1,963 ms
3,804 KB
testcase_58 AC 1,940 ms
3,884 KB
testcase_59 AC 1,932 ms
3,760 KB
testcase_60 AC 1,946 ms
3,844 KB
testcase_61 AC 1,936 ms
3,804 KB
testcase_62 AC 1,934 ms
3,852 KB
testcase_63 AC 1,940 ms
3,812 KB
testcase_64 AC 1,932 ms
3,812 KB
testcase_65 AC 1,940 ms
3,716 KB
testcase_66 AC 1,965 ms
3,844 KB
testcase_67 AC 1,912 ms
3,712 KB
testcase_68 AC 1,911 ms
3,808 KB
testcase_69 AC 1,909 ms
3,800 KB
testcase_70 AC 1,910 ms
3,772 KB
testcase_71 AC 1,908 ms
3,812 KB
testcase_72 AC 1,911 ms
3,776 KB
testcase_73 AC 1,910 ms
4,904 KB
testcase_74 AC 1,913 ms
4,904 KB
testcase_75 AC 1,909 ms
4,904 KB
testcase_76 AC 1,932 ms
5,160 KB
testcase_77 AC 1,942 ms
4,904 KB
testcase_78 AC 1,933 ms
4,900 KB
testcase_79 AC 1,931 ms
4,904 KB
testcase_80 AC 1,939 ms
5,160 KB
testcase_81 AC 1,932 ms
4,904 KB
testcase_82 AC 1,937 ms
4,904 KB
testcase_83 AC 1,939 ms
4,904 KB
testcase_84 AC 1,931 ms
4,908 KB
testcase_85 AC 1,939 ms
4,904 KB
testcase_86 AC 1,931 ms
4,904 KB
testcase_87 AC 1,931 ms
4,900 KB
testcase_88 AC 1,942 ms
5,156 KB
testcase_89 AC 1,933 ms
4,904 KB
testcase_90 AC 1,939 ms
5,160 KB
testcase_91 AC 1,938 ms
5,160 KB
testcase_92 AC 1,930 ms
5,160 KB
testcase_93 AC 1,940 ms
4,904 KB
testcase_94 AC 1,932 ms
4,904 KB
testcase_95 AC 1,937 ms
4,900 KB
testcase_96 AC 1,946 ms
4,904 KB
testcase_97 AC 1,932 ms
4,904 KB
testcase_98 AC 1,946 ms
5,164 KB
testcase_99 AC 1,936 ms
4,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 col_score(vector<vector<int>> &perm, vector<six> &rolls, int xj) {
    int score = 0;
    {
        for (int d = 0; d < N; d++) {
            int cnt = 0;
            for (int i = 0; i < N; i++) {
                int rollid = perm[i][xj];
                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;
}
void anneal(vector<six> rolls) {
    vector<vector<int>> perm(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            perm[i][j] = i * N + j;
        }
    }
    int old_score = calc_score(perm, rolls);

    vector<vector<int>> best_perm = perm;
    int best_score = old_score;

    double begin_time = marathon::now();
    double end_time = END_TIME;
    double begin_temp = 2.0;
    double end_temp = begin_temp * 0.1;

    int anneal_iter = 0;
    int anneal_accept = 0;
    while (marathon::now() < END_TIME) {
        anneal_iter++;
        int x = 0;
        int y = 0;
        while (x == y) {
            x = marathon::engine() % N2;
            y = marathon::engine() % N2;
        }
        int xi = x / N;
        int xj = x % N;
        int yi = y / N;
        int yj = y % N;

        int new_score = old_score;
        if (xi != yi) {
            new_score -= row_score(perm, rolls, xi);
            new_score -= row_score(perm, rolls, yi);
        }
        if (xj != yj) {
            new_score -= col_score(perm, rolls, xj);
            new_score -= col_score(perm, rolls, yj);
        }
        swap(perm[xi][xj], perm[yi][yj]);
        if (xi != yi) {
            new_score += row_score(perm, rolls, xi);
            new_score += row_score(perm, rolls, yi);
        }
        if (xj != yj) {
            new_score += col_score(perm, rolls, xj);
            new_score += col_score(perm, rolls, yj);
        }

        if (best_score < new_score) {
            best_perm = perm;
            best_score = new_score;
        }
        if (marathon::anneal_accept(new_score, old_score, marathon::now(), begin_time, end_time, begin_temp, end_temp)) {
            anneal_accept++;
            old_score = new_score;
        } else {
            swap(perm[xi][xj], perm[yi][yj]);
        }
    }
    debug3(anneal_iter, anneal_accept, best_score);

    vector<pair<int, int>> revperm(N2);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            revperm[best_perm[i][j]] = {i, j};
        }
    }
    for (int i = 0; i < N2; i++) {
        print(revperm[i].first + 1, revperm[i].second + 1);
    }
}

int main() {
    marathon::marathon_init();
    vector<six> rolls(N2);
    for (int i = 0; i < N2; i++) {
        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[i] = s;
    }
    anneal(rolls);
    return 0;
}
0