結果
問題 | No.2463 ストレートフラッシュ |
ユーザー |
![]() |
提出日時 | 2024-11-06 21:05:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 1,148 bytes |
コンパイル時間 | 2,386 ms |
コンパイル使用メモリ | 203,096 KB |
最終ジャッジ日時 | 2025-02-25 02:25:37 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/modint>using namespace std;//using namespace atcoder;using ll = long long;//using mint = modint998244353;int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);/*ロイヤルストレートフラッシュはO(N*M)通り1枚目を手に入れるまでは5枚..5枚目を手に入れるまでは1枚ずつ捨てる。*/int N, M, n, m, K, ans=1e9, sm, p, x;cin >> N >> M;K = N*M;vector v(N, vector<int>(M));for (int i=0; i<K; i++){cin >> n >> m;n--; m--;v[n][m] = i;}for (int i=0; i<M; i++){for (int j=0; j<=N-4; j++){vector<ll> w;for (int k=0; k<=4; k++){w.push_back(v[(j+k)%N][i]);}sort(w.begin(), w.end());p=0; sm=0; x=0;for (int i=0; i<5; i++){x += w[i]-p;p = w[i]+1;sm += x / (5-i);x %= (5-i);}ans = min(ans, sm);}}cout << ans << endl;return 0;}