結果

問題 No.2463 ストレートフラッシュ
ユーザー ococonomy1ococonomy1
提出日時 2023-09-08 22:11:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,230 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 116,416 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 22:11:55
合計ジャッジ時間 5,142 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 RE -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 53 ms
4,380 KB
testcase_16 RE -
testcase_17 AC 63 ms
4,380 KB
testcase_18 AC 70 ms
4,384 KB
testcase_19 AC 68 ms
4,384 KB
testcase_20 AC 72 ms
4,380 KB
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using lg = long long;
using pii = pair<int, int>;
using pll = pair<lg, lg>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TEMOTO ((sizeof(long double) == 16) ? false : true)
#define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000)
#define el '\n'
#define El '\n'

int func(int a, int b, int c, int d, int e){
    vector<int> dif = {a, b - a, c - b, d - c, e - d};
    int ans = 0,yoryoku = 0;
    for(int i = 0; i < 5; i++){
        if(yoryoku >= dif[i]){
            yoryoku -= dif[i];
            continue;
        }
        dif[i] -= yoryoku;
        ans += (dif[i] - 1) / (5 - i) + 1;
        yoryoku = (5 - i) - dif[i] % (5 - i);
        if(dif[i] % (5 - i) == 0)yoryoku = 0;
    }
    return ans;
}

#define MULTI_TEST_CASE false
void solve(void){
    int n, m;
    cin >> n >> m;
    // basyo[番号][色] := そのカードの場所
    vector<vector<int>> basyo(n, vector<int>(m));
    for (int i = 0; i < n * m; i++){
        int tn, tm;
        cin >> tn >> tm;
        tn--;
        tm--;
        basyo[tn][tm] = i;
    }
    int ans = INT_MAX;
    for (int i = 0; i < m; i++){
        for(int j = 0; j < n - 4; j++){
            vector<int> v = {basyo[j][i],basyo[j + 1][i],basyo[j + 2][i],basyo[j + 3][i],basyo[j + 4][i]};
            sort(v.begin(),v.end());
            ans = min(ans,func(v[0],v[1],v[2],v[3],v[4]));
        }
        vector<int> u = {basyo[i][0],basyo[i][n - 1],basyo[i][n - 2],basyo[i][n - 3],basyo[i][n - 4]};
        sort(u.begin(),u.end());
        ans = min(ans,func(u[0],u[1],u[2],u[3],u[4]));
    }
    cout << ans - 1 << el;
    return;
}

void calc(void){
    return;
}

int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if (MULTI_TEST_CASE)cin >> t;
    while (t--){
        solve();
    }
    return 0;
}
0