結果

問題 No.2463 ストレートフラッシュ
ユーザー 👑 Nachia
提出日時 2025-01-13 03:51:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 8,330 ms
コンパイル使用メモリ 243,176 KB
実行使用メモリ 12,832 KB
最終ジャッジ日時 2025-01-13 03:51:48
合計ジャッジ時間 11,119 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"

#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int N,M;
int pos[501][500]={};
int sfPos[5]={};

int solve_per_sfPos(){
  int ans=0;
  int remain=0, p=0;
  rep(i,5){
    remain+=sfPos[i]-p; p=sfPos[i]+1;
    ans+=remain/(5-i);
    remain%=(5-i);
  }
  return ans;
}

int main(){
  registerValidation();
  N = inf.readInt(5,500);
  inf.readSpace();
  M = inf.readInt(1,500);
  inf.readEoln();
  rep(n,N) rep(m,M) pos[n][m] = -1;
  rep(i,N*M){
    int n = inf.readInt(1,N);
    inf.readSpace();
    int m = inf.readInt(1,M);
    inf.readEoln();
    n--; m--;
    if(pos[n][m] != -1){
      string errmsg = string("") + "Pair of same cards found : " + 
                          "card " + vtos(pos[n][m]+1) + " and card " + vtos(i+1);
      inf.quit(_wa, errmsg.c_str());
    }
    pos[n][m]=i;
  }
  rep(i,M) pos[N][i]=pos[0][i];
  inf.readEof();

  int ans=1000000000;
  for(int ns=0; ns<=N-4; ns++) rep(m,M) {
    rep(i,5) sfPos[i]=pos[ns+i][m];
    sort(sfPos,sfPos+5);
    ans=min(ans,solve_per_sfPos());
  }
  cout<<ans<<"\n";

  return 0;
}
0