結果
問題 | No.2986 Permutation Puzzle |
ユーザー | t98slider |
提出日時 | 2024-12-11 06:21:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 5,005 bytes |
コンパイル時間 | 2,571 ms |
コンパイル使用メモリ | 225,528 KB |
実行使用メモリ | 928,524 KB |
最終ジャッジ日時 | 2024-12-11 06:22:24 |
合計ジャッジ時間 | 61,841 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | MLE | - |
testcase_02 | WA | - |
testcase_03 | MLE | - |
testcase_04 | WA | - |
testcase_05 | MLE | - |
testcase_06 | WA | - |
testcase_07 | MLE | - |
testcase_08 | WA | - |
testcase_09 | MLE | - |
testcase_10 | WA | - |
testcase_11 | MLE | - |
testcase_12 | WA | - |
testcase_13 | MLE | - |
testcase_14 | WA | - |
testcase_15 | MLE | - |
testcase_16 | WA | - |
testcase_17 | MLE | - |
testcase_18 | TLE | - |
testcase_19 | MLE | - |
testcase_20 | WA | - |
testcase_21 | MLE | - |
testcase_22 | WA | - |
testcase_23 | MLE | - |
testcase_24 | WA | - |
testcase_25 | MLE | - |
testcase_26 | WA | - |
testcase_27 | MLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | WA | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | WA | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | MLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using T = array<array<int,10>,10>; template<const long long MOD = 2305843009213693951, const long long MASK31 = (1ll << 31) - 1, const long long MASK30 = (1ll << 30) - 1> struct modint61 { using mint = modint61; long long v; modint61() : v(0) {} template<class T> modint61(T x) { while(x < 0) x += MOD; while(x >= MOD) x -= MOD; v = x; } long long safe_mod(long long x){ x = (x >> 61) + (x & MOD); if (x >= MOD) x -= MOD; return x; } static constexpr long long mod() { return MOD; } mint& operator++() {v++; if(v == MOD)v = 0; return *this;} mint& operator--() {if(v == 0)v = MOD; v--; return *this;} mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; } mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; } mint& operator*=(const mint& rhs) { long long u = v >> 31, d = v & MASK31; long long ru = rhs.v >> 31, rd = rhs.v & MASK31; long long mid = d * ru + u * rd; v = safe_mod(u * ru * 2 + (mid >> 30) + ((mid & MASK30) << 31) + d * rd); return *this; } mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); mint r = 1, x = *this; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { assert(v); return pow(MOD - 2); } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator<(const mint& lhs, const mint& rhs) { return lhs.v < rhs.v; } friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); } friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); } friend std::istream& operator >> (std::istream& is, mint& rhs) noexcept { long long tmp; rhs = mint{(is >> tmp, tmp)}; return is; } friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; } }; using mint61 = modint61<2305843009213693951>; int n; ll fh(T &A){ mint61 res; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ res *= 1145141919810ll; res += A[i][j]; } } return res.v; } T gen(T &A, char c, int p){ T B{{}}; array<int, 10> tr{}; if(c == 'R'){ for(int i = 0; i < n; i++) tr[A[p][i]] = i; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ B[tr[i]][j] = A[i][j]; } } }else{ for(int i = 0; i < n; i++) tr[A[i][p]] = i; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ B[i][tr[j]] = A[i][j]; } } } return B; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int k; cin >> n >> k; T A{{}}, B{{}}; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ cin >> A[i][j]; A[i][j]--; } } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ cin >> B[i][j]; B[i][j]--; } } queue<T> que; unordered_map<ll, int> mp; unordered_map<ll, tuple<ll, char, int>> par; ll st = fh(B), gl = fh(A); mp[st] = 0; que.emplace(B); while(!que.empty()){ T C = que.front(); que.pop(); ll hs = fh(C); if(hs == gl) break; int d = mp[hs]; for(int i = 0; i < n; i++){ T D = gen(C, 'R', i); ll hsD = fh(D); if(mp.find(hsD) == mp.end()){ mp[hsD] = d + 1; par[hsD] = make_tuple(hs, 'R', i + 1); if(d <= 999) que.emplace(D); } D = gen(C, 'C', i); hsD = fh(D); if(mp.find(hsD) == mp.end()){ mp[hsD] = d + 1; par[hsD] = make_tuple(hs, 'C', i + 1); if(d <= 999) que.emplace(D); } } } vector<pair<char,int>> ans; while(gl != st){ auto [fr, ch, ps] = par[gl]; ans.emplace_back(ch, ps); gl = fr; } reverse(ans.begin(), ans.end()); cout << ans.size() << '\n'; for(auto [c, p] : ans) cout << c << ' ' << p << '\n'; }