結果

問題 No.2432 Flip and Move
ユーザー polylogKpolylogK
提出日時 2023-09-28 18:38:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 632 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 200,480 KB
最終ジャッジ日時 2025-02-17 02:49:14
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:19: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘i64*’ {aka ‘long int*’} [-Wformat=]
   27 |     scanf("%d%d%lld", &h, &w, &k);
      |                ~~~^           ~~
      |                   |           |
      |                   |           i64* {aka long int*}
      |                   long long int*
      |                %ld
main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |     scanf("%d%d%lld", &h, &w, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0