結果

問題 No.2463 ストレートフラッシュ
ユーザー 👑 chro_96chro_96
提出日時 2023-09-08 22:08:47
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 29,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 22:08:55
合計ジャッジ時間 2,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 47 ms
4,380 KB
testcase_14 AC 54 ms
4,380 KB
testcase_15 AC 51 ms
4,376 KB
testcase_16 AC 55 ms
4,380 KB
testcase_17 AC 64 ms
4,380 KB
testcase_18 AC 69 ms
4,384 KB
testcase_19 AC 69 ms
4,376 KB
testcase_20 AC 70 ms
4,380 KB
testcase_21 AC 55 ms
4,380 KB
testcase_22 AC 61 ms
4,380 KB
testcase_23 AC 62 ms
4,380 KB
testcase_24 AC 62 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  int ni = 0;
  int mi = 0;
  
  int res = 0;
  
  int ans = 0;
  int pos[500][500] = {};
  int tmp[5] = {};
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < n*m; i++) {
    res = scanf("%d", &ni);
    res = scanf("%d", &mi);
    pos[mi-1][ni-1] = i;
  }
  
  ans = n*m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n-3; j++) {
      int tmpcnt = 0;
      int tmppos = 4;
      for (int k = 0; k < 5; k++) {
        tmp[k] = pos[i][(j+k)%n];
      }
      for (int k = 4; k > 0; k--) {
        for (int l = 0; l < k; l++) {
          if (tmp[l] > tmp[l+1]) {
            int s = tmp[l];
            tmp[l] = tmp[l+1];
            tmp[l+1] = s;
          }
        }
      }
      tmpcnt = tmp[0]/5;
      tmppos = (1+tmp[0]/5)*5-1;
      if (tmppos < tmp[1]) {
        tmpcnt += 1+(tmp[1]-tmppos-1)/4;
        tmppos += (1+(tmp[1]-tmppos-1)/4)*4;
      }
      if (tmppos < tmp[2]) {
        tmpcnt += 1+(tmp[2]-tmppos-1)/3;
        tmppos += (1+(tmp[2]-tmppos-1)/3)*3;
      }
      if (tmppos < tmp[3]) {
        tmpcnt += 1+(tmp[3]-tmppos-1)/2;
        tmppos += (1+(tmp[3]-tmppos-1)/2)*2;
      }
      if (tmppos < tmp[4]) {
        tmpcnt += tmp[4]-tmppos;
        tmppos = tmp[4];
      }
      if (tmpcnt < ans) {
        ans = tmpcnt;
      }
    }
  }
  
  printf("%d\n", ans);
  return 0;
}
0