結果

問題 No.2463 ストレートフラッシュ
ユーザー planesplanes
提出日時 2023-09-08 21:55:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 173,380 KB
実行使用メモリ 5,220 KB
最終ジャッジ日時 2023-09-08 21:55:43
合計ジャッジ時間 4,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 70 ms
4,380 KB
testcase_14 AC 80 ms
4,672 KB
testcase_15 AC 78 ms
4,576 KB
testcase_16 AC 83 ms
4,572 KB
testcase_17 AC 96 ms
4,840 KB
testcase_18 AC 104 ms
5,104 KB
testcase_19 AC 104 ms
5,168 KB
testcase_20 AC 105 ms
5,164 KB
testcase_21 AC 91 ms
5,220 KB
testcase_22 AC 100 ms
5,104 KB
testcase_23 AC 98 ms
5,100 KB
testcase_24 AC 95 ms
5,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;


int main() {
    ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll N,M;cin>>N>>M;
  vector<vector<ll>> od(M,vector<ll> (N+1));
  for(ll i=1;i<=N*M;i++) {
    ll n,m;cin>>n>>m;
    m--;
    od[m][n]=i;
  }

  ll ans=INF;
  for(ll i=0;i<M;i++) {
    for(ll j=1;j<=N-3;j++) {
      vector<ll> note(0);
      for(ll h=0;h<5;h++) {
        if(j+h<=N) note.push_back(od[i][j+h]);
        else note.push_back(od[i][1]);
      }
    sort(all(note));
    ll count=0;

    ll ind=0;
    
    ll last=0;

    while(ind<5) {
    count+=(note[ind]-last-1)/(5-ind);
    last+=(note[ind]-last-1)/(5-ind)*(5-ind);

    last+=(5-ind);
    count++;

    while(ind<5&&last>=note[ind]) {
      ind++;
    }
    }

    count--;
    ans=min(ans,count);
    }
  }

  cout<<ans<<endl;
}




  
0