結果

問題 No.335 門松宝くじ
ユーザー t98slidert98slider
提出日時 2023-03-21 21:50:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 906 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 177,480 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 18:36:25
合計ジャッジ時間 8,825 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 150 ms
4,348 KB
testcase_06 AC 225 ms
4,348 KB
testcase_07 AC 602 ms
4,348 KB
testcase_08 AC 613 ms
4,348 KB
testcase_09 AC 906 ms
4,348 KB
testcase_10 AC 904 ms
4,348 KB
testcase_11 AC 904 ms
4,348 KB
testcase_12 AC 906 ms
4,348 KB
testcase_13 AC 904 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<pair<int,int>> b(m);
    auto f = [&](int l, int r){
        int mx = 0, coef = max(a[l], a[r]);
        for(int i = 0; i < l; i++){
            if(a[i] > a[l] && a[l] < a[r]) mx = max(mx, max(a[i], coef));
            if(a[i] < a[l] && a[l] > a[r]) mx = max(mx, max(a[i], coef));
        }
        for(int i = l + 1; i < r; i++){
            if(a[l] > a[i] && a[i] < a[r]) mx = max(mx, max(a[i], coef));
            if(a[l] < a[i] && a[i] > a[r]) mx = max(mx, max(a[i], coef));
        }
        for(int i = r + 1; i < n; i++){
            if(a[l] > a[r] && a[r] < a[i]) mx = max(mx, max(a[i], coef));
            if(a[l] < a[r] && a[r] > a[i]) mx = max(mx, max(a[i], coef));
        }
        return mx;
    };
    for(int i = 0; i < m; i++){
        for(auto &&v: a) cin >> v;
        b[i] = {0, -i};
        for(int j = 0; j < n; j++){
            for(int k = j + 1; k < n; k++){
                b[i].first += f(j, k);
            }
        }
    }
    sort(b.rbegin(), b.rend());
    cout << -b[0].second << '\n';
}
0