結果

問題 No.2432 Flip and Move
ユーザー polylogKpolylogK
提出日時 2023-09-28 18:37:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,899 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 206,836 KB
実行使用メモリ 143,780 KB
最終ジャッジ日時 2023-09-28 18:37:24
合計ジャッジ時間 12,975 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 923 ms
116,268 KB
testcase_03 AC 1,817 ms
143,780 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#if defined(DONLINE_JUDGE)
#define NDEBUG
#elif defined(ONLINE_JUDGE)
#define NDEBUG
#endif

template <typename T>
std::vector<T> make_v(size_t a) {
    return std::vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main() {
    int h, w;
    i64 k;
    scanf("%d%d%lld", &h, &w, &k);

    auto color = make_v<int>(h, w);
    for (auto& x : color)
        for (auto& y : x) y = 0;

    auto used = make_v<int>(h, w, 4);
    for (auto& x : used)
        for (auto& y : x)
            for (auto& z : y) z = 0;

    int y = 0, x = 0, dy = 1, dx = 1, cnt = 0;
    while (cnt < k) {
        const int state = ((dy == 1) << 1) | (dx == 1);
        if (used[y][x][state]) {
            const i64 repeat = k / cnt;
            if (repeat % 2 == 0) {
                for (auto& x : color)
                    for (auto& y : x) y = 0;
            }
            k %= cnt;
            break;
        }

        ++cnt;
        color[y][x] = 1 - color[y][x];
        if (0 <= y + dy and y + dy < h)
            y = y + dy;
        else
            dy = -dy;
        if (0 <= x + dx and x + dx < w)
            x = x + dx;
        else
            dx = -dx;
    }

    while (cnt < k) {
        ++cnt;
        color[y][x] = 1 - color[y][x];
        if (0 <= y + dy and y + dy < h)
            y = y + dy;
        else
            dy = -dy;
        if (0 <= x + dx and x + dx < w)
            x = x + dx;
        else
            dx = -dx;
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            putchar(color[i][j] == 0 ? '.' : '#');
        }
        putchar('\n');
    }

    return 0;
}
0