結果

問題 No.2432 Flip and Move
ユーザー polylogKpolylogK
提出日時 2023-09-28 18:38:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 706 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 2,435 ms
コンパイル使用メモリ 206,464 KB
実行使用メモリ 143,596 KB
最終ジャッジ日時 2023-09-28 18:38:51
合計ジャッジ時間 14,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 191 ms
116,320 KB
testcase_03 AC 275 ms
143,596 KB
testcase_04 AC 106 ms
61,656 KB
testcase_05 AC 107 ms
61,772 KB
testcase_06 AC 79 ms
47,952 KB
testcase_07 AC 193 ms
94,420 KB
testcase_08 AC 196 ms
101,940 KB
testcase_09 AC 273 ms
138,820 KB
testcase_10 AC 125 ms
74,656 KB
testcase_11 AC 142 ms
84,956 KB
testcase_12 AC 109 ms
64,336 KB
testcase_13 AC 108 ms
65,232 KB
testcase_14 AC 64 ms
34,464 KB
testcase_15 AC 229 ms
118,904 KB
testcase_16 AC 220 ms
26,600 KB
testcase_17 AC 636 ms
53,936 KB
testcase_18 AC 104 ms
17,900 KB
testcase_19 AC 432 ms
42,636 KB
testcase_20 AC 656 ms
59,540 KB
testcase_21 AC 460 ms
41,648 KB
testcase_22 AC 323 ms
47,864 KB
testcase_23 AC 56 ms
15,032 KB
testcase_24 AC 674 ms
51,944 KB
testcase_25 AC 399 ms
39,072 KB
testcase_26 AC 280 ms
47,992 KB
testcase_27 AC 8 ms
6,276 KB
testcase_28 AC 4 ms
4,756 KB
testcase_29 AC 444 ms
40,792 KB
testcase_30 AC 621 ms
56,240 KB
testcase_31 AC 294 ms
45,296 KB
testcase_32 AC 11 ms
7,136 KB
testcase_33 AC 706 ms
54,844 KB
testcase_34 AC 257 ms
30,236 KB
testcase_35 AC 186 ms
39,744 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
            cnt = 0;
            break;
        }
        used[y][x][state] = 1;

        ++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