結果

問題 No.2463 ストレートフラッシュ
ユーザー t98slidert98slider
提出日時 2023-09-08 21:50:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 175,668 KB
実行使用メモリ 6,168 KB
最終ジャッジ日時 2023-09-08 21:50:48
合計ジャッジ時間 3,912 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 44 ms
5,396 KB
testcase_14 AC 50 ms
5,416 KB
testcase_15 AC 48 ms
5,160 KB
testcase_16 AC 52 ms
5,480 KB
testcase_17 AC 61 ms
5,692 KB
testcase_18 AC 65 ms
5,936 KB
testcase_19 AC 66 ms
5,932 KB
testcase_20 AC 65 ms
6,168 KB
testcase_21 AC 59 ms
5,956 KB
testcase_22 AC 61 ms
5,940 KB
testcase_23 AC 60 ms
5,880 KB
testcase_24 AC 61 ms
5,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(m, vector<int>(n));
    vector<pair<int,int>> a(n * m);
    for(int i = 0; i < n * m; i++){
        int u, v;
        cin >> u >> v;
        u--, v--;
        a[i] = make_pair(u, v);
        A[v][u] = i + 1;
    }
    int ans = 1 << 30;
    auto f = [&](vector<int> b){
        sort(b.begin(), b.end());
        int cur = 5, s = 0;
        for(int i = 0; i < 5; i++){
            if(cur >= b[i]) continue;
            int d = (b[i] - cur + 4 - i) / (5 - i);
            cur += d * (5 - i);
            s += d; 
        }
        return s;
    };
    vector<int> c(5);
    for(int i = 0; i < m; i++){
        for(int j = 0; j + 5 <= n; j++){
            for(int k = 0; k < 5; k++){
                c[k] = A[i][j + k];
            }
            ans = min(ans, f(c));
        }
        c[0] = A[i][0];
        for(int j = 0; j < 4; j++){
            c[j + 1] = A[i][n - 1 - j];
        }
        ans = min(ans, f(c));
    }
    cout << ans << '\n';
}
0