結果

問題 No.335 門松宝くじ
ユーザー h_nosonh_noson
提出日時 2016-05-04 00:37:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 2,876 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 61,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 11:09:54
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 115 ms
5,376 KB
testcase_06 AC 171 ms
5,376 KB
testcase_07 AC 310 ms
5,376 KB
testcase_08 AC 300 ms
5,376 KB
testcase_09 AC 464 ms
5,376 KB
testcase_10 AC 463 ms
5,376 KB
testcase_11 AC 465 ms
5,376 KB
testcase_12 AC 464 ms
5,376 KB
testcase_13 AC 461 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

int segmax[2048];
int segmin[2048];
int sz;

void update_max(int k, int a) {
    k += sz - 1;
    segmax[k] = a;
    while (k > 0) {
        k = (k - 1) / 2;
        segmax[k] = max(segmax[2*k+1],segmax[2*k+2]);
    }
}

void update_min(int k, int a) {
    k += sz - 1;
    segmax[k] = a;
    while (k > 0) {
        k = (k - 1) / 2;
        segmin[k] = min(segmin[2*k+1],segmin[2*k+2]);
    }
}

int query_max(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
        return 0;
    if (a <= l && r <= b)
        return segmax[k];
    else
        return max(query_max(a,b,2*k+1,l,(l+r)/2),query_max(a,b,2*k+2,(l+r)/2,r));
}

int query_min(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l)
        return INF;
    if (a <= l && r <= b)
        return segmin[k];
    else
        return min(query_min(a,b,2*k+1,l,(l+r)/2),query_min(a,b,2*k+2,(l+r)/2,r));
}

int main() {
    int i, j, k, l, n, m, ans;
    double mx;
    int e[3][800];
    cin >> n >> m;
    rep (i,m) rep (j,n) cin >> e[i][j];
    mx = ans = 0;
    sz = 1;
    while (sz < n) sz *= 2;
    rep (i,m) {
        rep (j,2*sz-1) {
            segmax[j] = 0;
            segmin[j] = INF;
        }
        rep (j,n) {
            update_max(j,e[i][j]);
            update_min(j,e[i][j]);
        }
        double sum = 0, cnt = 0;
        rep (j,n) REP (k,j+1,n-1) {
            int x, p = 0;
            if (e[i][j] < e[i][k]) {
                x = query_max(0,j,0,0,sz);
                if (x > e[i][j])
                    p = max(x,e[i][k]);
                x = query_max(j+1,k,0,0,sz);
                if (x > e[i][k])
                    p = max(p,x);
                x = query_min(j+1,k,0,0,sz);
                if (x < e[i][j])
                    p = max(p,e[i][k]);
                x = query_min(k+1,n,0,0,sz);
                if (x < e[i][k])
                    p = max(p,e[i][k]);
            }
            else {
                x = query_min(0,j,0,0,sz);
                if (x < e[i][j])
                    p = e[i][j];
                x = query_max(j+1,k,0,0,sz);
                if (x > e[i][j])
                    p = max(p,x);
                x = query_min(j+1,k,0,0,sz);
                if (x < e[i][k])
                    p = max(p,e[i][j]);
                x = query_max(k+1,n,0,0,sz);
                if (x > e[i][k])
                    p = max({p,e[i][k],x});
            }
            sum += p;
            cnt++;
        }
        sum /= cnt;
        if (mx < sum) {
            mx = sum;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}
0