結果

問題 No.335 門松宝くじ
ユーザー eitahoeitaho
提出日時 2016-03-22 02:27:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,148 ms / 2,000 ms
コード長 2,371 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 21:41:04
合計ジャッジ時間 8,736 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 177 ms
6,676 KB
testcase_06 AC 268 ms
6,676 KB
testcase_07 AC 767 ms
6,676 KB
testcase_08 AC 81 ms
6,676 KB
testcase_09 AC 1,148 ms
6,676 KB
testcase_10 AC 1,142 ms
6,676 KB
testcase_11 AC 1,147 ms
6,676 KB
testcase_12 AC 1,133 ms
6,676 KB
testcase_13 AC 1,116 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }

const int MaxN = 800, MaxM = 3;
int N, M;
int Table[MaxM][MaxN];
int bestVal[MaxN + 1][MaxN + 1];

void solve() {
    double maxEx = -1;
    int bestIndex = 0;

    for (int i = 0; i < M; i++) {

        rep(a, N + 1) rep(b, N + 1) bestVal[a][b] = 0;
        int ex = 0;

        rep(a, N) FOR(b, a + 1, N - 1) {
            if (Table[i][a] < Table[i][b]) {
                FOR(c, b + 1, N - 1) if (Table[i][b] > Table[i][c]) {
                    checkmax(bestVal[Table[i][a]][Table[i][b]], Table[i][b]);
                    checkmax(bestVal[Table[i][c]][Table[i][b]], Table[i][b]);
                    if (Table[i][a] < Table[i][c])
                        checkmax(bestVal[Table[i][a]][Table[i][c]], Table[i][b]);
                    else
                        checkmax(bestVal[Table[i][c]][Table[i][a]], Table[i][b]);
                }
            } else {
                FOR(c, b + 1, N - 1) if (Table[i][b] < Table[i][c]) {
                    int val = max(Table[i][a], Table[i][c]);
                    checkmax(bestVal[Table[i][b]][Table[i][a]], val);
                    checkmax(bestVal[Table[i][b]][Table[i][c]], val);
                    if (Table[i][a] < Table[i][c])
                        checkmax(bestVal[Table[i][a]][Table[i][c]], val);
                    else
                        checkmax(bestVal[Table[i][a]][Table[i][a]], val);
                }
            }
        }
        FOR(a, 1, N) FOR(b, a + 1, N) ex += bestVal[a][b];
        if (ex > maxEx) {
            maxEx = ex;
            bestIndex = i;
        }
    }

    cout << bestIndex << endl;
}

int main() {
    cin >> N >> M;
    rep(i, M) rep(x, N) {
        cin >> Table[i][x];
    }
    solve();
    return 0;
}
0