// TEMPLATE.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) template using vi = vector; template using vii = vector>; template using viii = vector>; using pii = pair; int n = 36; const int len = 6; const int TL1 = 1930 * 1000; const int TL2 = 2 * 1000; struct dice { vi vec; int idx = 0; dice() : vec(len), idx(0){} }; vi d(n); vii board(len, vi(len)); int score() { const int inf = 1e9; int res = 0; rep(i, len){ vi cnt(len, 0); rep(j, len) { rep(k, len) { //どの値 int pos = board[i][j]; int num = d[pos].vec[k]; if (num) cnt[k] += num; else cnt[k] = -inf; } } rep(k, len) { if (cnt[k] > 0) res += 3 + cnt[k] - 6; } } rep(j, len){ vi cnt(len, -inf); rep(i, len) { rep(k, len) { //どの値 int pos = board[i][j]; int num = cnt[d[pos].vec[k]]; if (num) { if (cnt[k] < 0) cnt[k] = 0; cnt[k] += num; } } } rep(k, len) { if (cnt[k] > 0) res += 3 + cnt[k] - 6; } } return res * 1000; } int main() { random_device rnd; clock_t start = clock(); rep(i, n) { rep(j, len) { int t; cin >> t; t--; d[i].vec[t]++; } d[i].idx = i; } int scr = 0; { vi used(n); rep(i, len) { scr = 0; rep(j, len) { vi cnt; rep(k, n) { if (used[k]) continue; cnt.push_back({ d[k].vec[j], k }); } sort(cnt.begin(), cnt.end(), greater{}); int ts = 0; rep(k2, len) ts += cnt[k2].first; if (ts > scr) { rep(k2, len) board[i][k2] = cnt[k2].second; scr = ts; } } rep(j, len) used[board[i][j]] = true; } } scr = score(); while (clock() - start < TL1) { if (rnd() & 1) { int idx0 = rnd() % len; int idx1 = (idx0 + rnd() % (len - 1) + 1) % len; int row = rnd() % len; if (rnd() & 1) { swap(board[row][idx0], board[row][idx1]); int ts = score(); if (ts >= scr) scr = ts; else swap(board[row][idx0], board[row][idx1]); } else { swap(board[idx0][row], board[idx1][row]); int ts = score(); if (ts >= scr) scr = ts; else swap(board[idx0][row], board[idx1][row]); } } else { int row = rnd() % len; vi td = board[row]; shuffle(board[row].begin(), board[row].end(), rnd); int ts = score(); if (ts >= scr) scr = ts; else swap(board[row], td); } } vi ans(n); rep(i, len) rep(j, len) { ans[board[i][j]] = { i + 1, j + 1 }; } for (pii elem : ans) cout << elem.first << " " << elem.second << endl; return 0; }