結果

問題 No.2463 ストレートフラッシュ
ユーザー tnakao0123
提出日時 2024-06-21 17:55:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 43,644 KB
最終ジャッジ日時 2025-02-21 23:41:16
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:52:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   52 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:56:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |     scanf("%d%d", rs + i, ss + i), rs[i]--, ss[i]--;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2463.cc:  No.2463 繧ケ繝医Ξ繝シ繝医ヵ繝ゥ繝・す繝・ - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_M = 500;
const int MAX_NM = MAX_N * MAX_M;
const int H = 5;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int rs[MAX_NM], ss[MAX_NM];
int aps[MAX_M][MAX_N + 1];

/* subroutines */

int check(int ps[], int l) {
  int qs[H];
  copy(ps + l, ps + l + H, qs);
  sort(qs, qs + H);

  int op = 0, i = 0;
  while (i < H && qs[i] < H) i++;

  int x = H;
  while (i < H) {
    int d = H - i;
    int dop = (qs[i] - x) / d + 1;
    op += dop;
    x += d * dop;
    while (i < H && qs[i] < x) i++;
  }

  return op;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int nm = n * m;

  for (int i = 0; i < nm; i++) {
    scanf("%d%d", rs + i, ss + i), rs[i]--, ss[i]--;
    aps[ss[i]][rs[i]] = i;
    if (rs[i] == 0) aps[ss[i]][n] = i;
  }

  int minop = INF;
  for (int si = 0; si < m; si++) {
    for (int l = 0; l + H - 1 <= n; l++)
      minop = min(minop, check(aps[si], l));
  }

  printf("%d\n", minop);
  
  return 0;
}
0