結果

問題 No.335 門松宝くじ
ユーザー mamekinmamekin
提出日時 2016-02-06 13:49:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 2,063 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 99,592 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 19:27:13
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 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 50 ms
4,348 KB
testcase_06 AC 75 ms
4,348 KB
testcase_07 AC 131 ms
4,348 KB
testcase_08 AC 63 ms
4,348 KB
testcase_09 AC 195 ms
4,348 KB
testcase_10 AC 195 ms
4,348 KB
testcase_11 AC 196 ms
4,348 KB
testcase_12 AC 195 ms
4,348 KB
testcase_13 AC 196 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int solve(const vector<int>& e)
{
    int n = e.size();
    int minLeft = INT_MAX;
    int maxLeft = INT_MIN;

    int ans = 0;
    for(int i=0; i<n; ++i){
        set<int> right;
        for(int j=i+1; j<n; ++j)
            right.insert(e[j]);

        int minMiddle = INT_MAX;
        int maxMiddle = INT_MIN;
        for(int j=i+1; j<n; ++j){
            right.erase(e[j]);

            int value = 0;
            if(e[i] < e[j]){
                if(maxLeft > e[i])
                    value = max(value, max(e[j], maxLeft));
                if(!right.empty() && *right.begin() < e[j])
                    value = max(value, e[j]);
            }
            else{
                if(minLeft < e[i])
                    value = max(value, e[i]);
                if(!right.empty() && *right.rbegin() > e[j])
                    value = max(value, max(e[i], *right.rbegin()));
            }
            if(minMiddle < min(e[i], e[j]))
                value = max(value, max(e[i], e[j]));
            if(max(e[i], e[j]) < maxMiddle)
                value = max(value, maxMiddle);
            ans += value;

            minMiddle = min(minMiddle, e[j]);
            maxMiddle = max(maxMiddle, e[j]);
        }

        minLeft = min(minLeft, e[i]);
        maxLeft = max(maxLeft, e[i]);
    }

    return ans;
}

int main()
{
    int n, m;
    cin >> n >> m;

    int ans = -1;
    int maxValue = -1;
    for(int i=0; i<m; ++i){
        vector<int> e(n);
        for(int j=0; j<n; ++j)
            cin >> e[j];

        int value = solve(e);
        if(value > maxValue){
            ans = i;
            maxValue = value;
        }
    }
    cout << ans << endl;

    return 0;
}
0