結果

問題 No.2432 Flip and Move
ユーザー KudeKude
提出日時 2023-08-18 22:44:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,043 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 228,168 KB
実行使用メモリ 34,392 KB
最終ジャッジ日時 2024-05-06 05:06:45
合計ジャッジ時間 5,170 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 23 ms
5,248 KB
testcase_03 AC 69 ms
34,392 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 7 ms
5,376 KB
testcase_07 AC 56 ms
23,424 KB
testcase_08 AC 45 ms
25,208 KB
testcase_09 AC 62 ms
33,408 KB
testcase_10 AC 17 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 16 ms
10,200 KB
testcase_15 AC 50 ms
28,928 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 22 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 19 ms
5,376 KB
testcase_20 AC 24 ms
5,376 KB
testcase_21 AC 15 ms
5,376 KB
testcase_22 AC 17 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 20 ms
5,376 KB
testcase_25 AC 17 ms
5,376 KB
testcase_26 AC 13 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 15 ms
5,376 KB
testcase_30 AC 18 ms
5,376 KB
testcase_31 AC 8 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 18 ms
5,376 KB
testcase_34 AC 9 ms
5,376 KB
testcase_35 AC 6 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0