結果
問題 | No.2432 Flip and Move |
ユーザー | Kude |
提出日時 | 2023-08-18 22:44:28 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 2,043 bytes |
コンパイル時間 | 2,903 ms |
コンパイル使用メモリ | 228,412 KB |
実行使用メモリ | 34,432 KB |
最終ジャッジ日時 | 2024-11-28 08:52:56 |
合計ジャッジ時間 | 6,056 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; // returns (len_of_cycle, first_in-cycle_index) template<class S, class F> std::pair<int, int> detect_cycle(F f, S x) { S p = x, q = x; int l = 0; int ub = 1; do { if (l == ub) { ub <<= 1; l = 0; p = q; } q = f(q); l++; } while(p != q); p = q = x; for(int it = l; it > 0; it--) q = f(q); int m = 0; while(p != q) p = f(p), q = f(q), m++; return {l, m}; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; ll k; cin >> h >> w >> k; struct S { int i, j, d; bool operator==(const S& rhs) const { return i == rhs.i && j == rhs.j && d == rhs.d; } bool operator!=(const S& rhs) const { return !(*this == rhs); } }; auto f = [&](S x) { auto [i, j, d] = x; int di = 1 - 2 * (d & 1); int ni = i + di; if (0 <= ni && ni < h) i = ni; else d ^= 1; int dj = 1 - (d & 2); int nj = j + dj; if (0 <= nj && nj < w) j = nj; else d ^= 2; return S{i, j, d}; }; S now{0, 0, 0}; auto [l, m] = detect_cycle(f, now); vector<string> s(h, string(w, '.')); if (k >= m) { k = m + (k - m) % (2 * l); } rrep(_, k) { s[now.i][now.j] ^= '.' ^ '#'; now = f(now); } rep(i, h) cout << s[i] << '\n'; }