結果
問題 |
No.5022 XOR Printer
|
ユーザー |
|
提出日時 | 2025-07-26 15:20:33 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 506 ms / 2,000 ms |
コード長 | 4,306 bytes |
コンパイル時間 | 3,484 ms |
コンパイル使用メモリ | 296,704 KB |
実行使用メモリ | 7,716 KB |
スコア | 2,659,818,750 |
最終ジャッジ日時 | 2025-07-26 15:21:05 |
合計ジャッジ時間 | 28,914 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#line 1 "main.cpp" #include <bits/stdc++.h> using namespace std; #line 6 "/home/hidehic0/src/github.com/hidehic0/library_cpp/templates/alias.hpp" using ll = long long; using ld = long double; using vi = std::vector<long long>; using vvi = std::vector<std::vector<long long>>; using si = std::set<long long>; using mii = std::map<long long, long, long>; template <typename T> using V = std::vector<T>; const std::string upperlist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const std::string lowerlist = "abcdefghijklmnopqrstuvwxyz"; #define mp make_pair #define dms << " " << #line 3 "/home/hidehic0/src/github.com/hidehic0/library_cpp/templates/macro.hpp" #define rep(i, n) for (ll i = 0; i < (int)(n); i++) #define REP(i, a, b) for (ll i = (int)(a); i < (int)(b); ++i) #define all(a) (a).begin(), (a).end() template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } void YN(bool b) { std::cout << (b ? "Yes" : "No") << std::endl; } void YE(bool b) { if (b) { std::cout << "Yes" << std::endl; exit(1); } } void NE(bool b) { if (b) { std::cout << "No" << std::endl; exit(1); } } #line 8 "main.cpp" ll N, T; unsigned long long randint() { static unsigned long long x = 88172645463325252LL; x ^= (x << 13); x ^= (x >> 7); return (x ^= (x << 17)); } ll randrange(ll a, ll b) { return a + randint() % (b - a + 1); } ll getscore(vector<vector<ll>> A, vector<pair<ll, ll>> L) { ll res = 0, t = 0; for (auto [i, k] : L) { t += (i + k) * 2; t += 180; rep(x, N) { rep(y, N) { if (find(all(L), make_pair(x, y)) == L.end()) { if (A[x][y] < (A[x][y] ^ A[i][k])) { t++; A[x][y] ^= A[i][k]; } } } } } rep(x, N) { rep(y, N) { res += A[x][y]; } } if (t > 1000) { return 0; } return res; } vector<string> get_output(vector<vector<ll>> A, vector<pair<ll, ll>> L) { vector<string> res; for (auto [i, k] : L) { rep(_, i) { res.emplace_back("R"); } rep(_, k) { res.emplace_back("D"); } res.emplace_back("W"); rep(_, i) { res.emplace_back("L"); } rep(_, k) { res.emplace_back("U"); } bool f = false; rep(x, N) { ll y = f ? N - 1 : 0; while (0 <= y && y < N) { if (find(all(L), make_pair(x, y)) == L.end() && A[x][y] < (A[i][k] ^ A[x][y])) { A[i][k] ^= A[x][y]; res.emplace_back("W"); } if ((f && y != 0) || (!f && y != 9)) { res.emplace_back(f ? "L" : "R"); } y += f ? -1 : 1; } f ^= 1; if (x != N - 1) { res.emplace_back("D"); } } rep(_, 9) { res.emplace_back("U"); } } return res; } int main() { cin >> N >> T; vector<vector<ll>> A(N, vector<ll>(N)); rep(i, N) { rep(k, N) { cin >> A[i][k]; } } vector<pair<ll, ll>> CL; ll _sc = getscore(A, CL); rep(i, N) { rep(k, N) { ll _nc = getscore(A, {make_pair(i, k)}); if (_sc < _nc) { CL = {make_pair(i, k)}; _sc = _nc; } } } ll Q = 100000; while (Q--) { ll type = randrange(0, 1); type = CL.size() == 0 ? 0 : type; if (type == 0) { ll i = randrange(0, N - 1); ll k = randrange(0, N - 1); while (find(all(CL), make_pair(i, k)) != CL.end()) { i = randrange(0, N - 1); k = randrange(0, N - 1); } CL.push_back(make_pair(i, k)); ll _nc = getscore(A, CL); if (_sc < _nc) { _sc = _nc; } else { CL.pop_back(); } } else { ll pi = randrange(0, CL.size() - 1); auto [px, py] = CL[pi]; CL.erase(CL.begin() + pi); ll i = randrange(0, N - 1); ll k = randrange(0, N - 1); while (find(all(CL), make_pair(i, k)) != CL.end()) { i = randrange(0, N - 1); k = randrange(0, N - 1); } CL.push_back(make_pair(i, k)); ll _nc = getscore(A, CL); if (_sc < _nc) { _sc = _nc; } else { CL.pop_back(); CL.insert(CL.begin() + pi, make_pair(px, py)); } } } for (auto s : get_output(A, CL)) { cout << s << "\n"; } }