結果
問題 | No.2986 Permutation Puzzle |
ユーザー | ID 21712 |
提出日時 | 2024-12-15 12:21:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,409 bytes |
コンパイル時間 | 1,088 ms |
コンパイル使用メモリ | 83,024 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 12:21:49 |
合計ジャッジ時間 | 3,823 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
6,816 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 2 ms
6,816 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 53 ms
6,820 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | AC | 2 ms
6,816 KB |
testcase_41 | AC | 53 ms
6,816 KB |
testcase_42 | WA | - |
testcase_43 | WA | - |
ソースコード
// yukicoder - ProblemID 11672 - writer's solution #include <iostream> #include <vector> using namespace std; using matrix = vector<vector<int>>; void reorder_cols_by_col_perm(matrix &s, int x) { matrix t = s; for (int r = 0; r < s.size(); r++) { for (int c = 0; c < s.size(); c++) { s[ r ][ t[c][x] ] = t[r][c]; } } } void reorder_rows_by_row_perm(matrix &s, int y) { matrix t = s; for (int r = 0; r < s.size(); r++) { for (int c = 0; c < s.size(); c++) { s[ t[y][r] ][ c ] = t[r][c]; } } } vector<int> select_col(matrix &s, int x) { vector<int> v; for (int r = 0; r < s.size(); r++) { v.push_back(s[r][x]); } return v; } vector<int> select_row(matrix &s, int y) { return s[y]; } bool search(matrix &b, int k, matrix &s, vector<int> &v) { if (k == 0) { return b == s; } for (int i = 0; i < b.size()*2; i++) { v.push_back(i); matrix t = s; if (i < b.size()) { reorder_cols_by_col_perm(t, i); } else { reorder_rows_by_row_perm(t, i-b.size()); } if (search(b, k-1, t, v)) { return true; } v.pop_back(); } return false; } int cycle(vector<int> &s) { vector<int> t(s.size()); vector<int> w = s; for (int cnt = 1; ; cnt++) { for (int i = 0; i < s.size(); i++) { t[s[i]] = w[i]; } if (s == t) { return cnt; } w = t; } } vector<int> solve(int n, int k, matrix &a, matrix &b) { vector<int> ops; search(b, k, a, ops); vector<int> ans; matrix s = a; for (auto op : ops) { vector<int> perm; int z; if (op < n) { perm = select_col(s, op); reorder_cols_by_col_perm(s, op); z = op; } else { perm = select_row(s, op-n); reorder_rows_by_row_perm(s, op-n); z = op - n; } z = perm[z]; vector<int> tmp; for (int cnt = cycle(perm) - 1; cnt > 0; cnt--) { tmp.push_back(z); z = perm[z]; } ans.insert(ans.begin(), tmp.begin(), tmp.end()); } return ans; } int main() { int n, k; matrix a, b; cin >> n >> k; a.resize(n); for (int r = 0; r < n; r++) { a[r].resize(n); for (int c = 0; c < n; c++) { cin >> a[r][c]; a[r][c]--; } } b.resize(n); for (int r = 0; r < n; r++) { b[r].resize(n); for (int c = 0; c < n; c++) { cin >> b[r][c]; b[r][c]--; } } auto ans = solve(n, k, a, b); cout << ans.size() << '\n'; for (auto op : ans) { if (op < n) { cout << "C " << (op+1) << '\n'; } else { cout << "R " << (op+1-n) << '\n'; } } return 0; }