結果

問題 No.2432 Flip and Move
ユーザー 👑 chro_96chro_96
提出日時 2023-08-19 00:00:58
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,938 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 31,484 KB
実行使用メモリ 18,432 KB
最終ジャッジ日時 2024-05-06 06:54:59
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
18,176 KB
testcase_01 AC 12 ms
18,432 KB
testcase_02 AC 50 ms
18,304 KB
testcase_03 AC 76 ms
18,304 KB
testcase_04 AC 18 ms
18,304 KB
testcase_05 AC 19 ms
18,432 KB
testcase_06 AC 24 ms
18,304 KB
testcase_07 AC 52 ms
18,304 KB
testcase_08 AC 58 ms
18,304 KB
testcase_09 AC 73 ms
18,432 KB
testcase_10 AC 38 ms
18,176 KB
testcase_11 AC 41 ms
18,304 KB
testcase_12 AC 31 ms
18,176 KB
testcase_13 AC 29 ms
18,176 KB
testcase_14 AC 26 ms
18,176 KB
testcase_15 AC 65 ms
18,304 KB
testcase_16 AC 31 ms
18,304 KB
testcase_17 AC 55 ms
18,304 KB
testcase_18 AC 22 ms
18,304 KB
testcase_19 AC 44 ms
18,304 KB
testcase_20 AC 57 ms
18,304 KB
testcase_21 AC 45 ms
18,304 KB
testcase_22 AC 45 ms
18,432 KB
testcase_23 AC 19 ms
18,304 KB
testcase_24 AC 56 ms
18,304 KB
testcase_25 AC 40 ms
18,176 KB
testcase_26 AC 38 ms
18,304 KB
testcase_27 AC 14 ms
18,176 KB
testcase_28 AC 12 ms
18,304 KB
testcase_29 AC 46 ms
18,304 KB
testcase_30 AC 57 ms
18,432 KB
testcase_31 AC 35 ms
18,304 KB
testcase_32 AC 15 ms
18,432 KB
testcase_33 AC 59 ms
18,304 KB
testcase_34 AC 33 ms
18,304 KB
testcase_35 AC 26 ms
18,304 KB
testcase_36 AC 11 ms
18,304 KB
testcase_37 AC 11 ms
18,432 KB
testcase_38 AC 11 ms
18,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int h = 0;
  int w = 0;
  long long k = 0LL;

  int res = 0;
  
  int cnt = 0;
  int flag[1000000][4] = {};
  char ans[1000001] = "";
  int st = 0;
  int pos = 0;
  int s = 0;
  int t = 0;
  
  res = scanf("%d", &h);
  res = scanf("%d", &w);
  res = scanf("%lld", &k);
  
  while (((long long)cnt) < k && flag[pos][st] <= 0) {
    cnt++;
    flag[pos][st] = cnt;
    if (st%2 == 0) {
      pos += w;
      if (pos/w >= h) {
        pos -= w;
        st ^= 1;
      }
    } else {
      pos -= w;
      if (pos < 0) {
        pos += w;
        st ^= 1;
      }
    }
    if (st < 2) {
      if (pos%w == w-1) {
        st ^= 2;
      } else {
        pos++;
      }
    } else {
      if (pos%w == 0) {
        st ^= 2;
      } else {
        pos--;
      }
    }
  }
  
  if ((long long)cnt == k) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        int f = 0;
        for (int l = 0; l < 4; l++) {
          if (flag[i*w+j][l] > 0) {
            f ^= 1;
          }
        }
        if (f == 0) {
          ans[j] = '.';
        } else {
          ans[j] = '#';
        }
      }
      ans[w] = '\0';
      printf("%s\n", ans);
    }
    return 0;
  }
  
  s = flag[pos][st];
  t = cnt+1;
    
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int f = 0;
      for (int l = 0; l < 4; l++) {
        if (flag[i*w+j][l] >= s) {
          long long tmp = k-((long long)(s-1));
          if (flag[i*w+j][l]-s+1 <= tmp%((long long)(t-s))) {
            tmp = 1LL+tmp/((long long)(t-s));
          } else {
            tmp /= ((long long)(t-s));
          }
          if (tmp%2LL == 1LL) {
            f ^= 1;
          }
        } else if (flag[i*w+j][l] > 0) {
          f ^= 1;
        }
      }
      if (f == 0) {
        ans[j] = '.';
      } else {
        ans[j] = '#';
      }
    }
    ans[w] = '\0';
    printf("%s\n", ans);
  }
  
  return 0;
}
0