結果

問題 No.335 門松宝くじ
ユーザー koprickykopricky
提出日時 2017-10-13 02:35:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,350 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 162,144 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-04-28 17:13:57
合計ジャッジ時間 2,117 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 8 ms
9,856 KB
testcase_06 AC 10 ms
12,800 KB
testcase_07 AC 11 ms
13,568 KB
testcase_08 AC 10 ms
13,440 KB
testcase_09 AC 17 ms
18,376 KB
testcase_10 AC 17 ms
18,508 KB
testcase_11 AC 17 ms
18,432 KB
testcase_12 AC 13 ms
18,560 KB
testcase_13 AC 14 ms
18,432 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:81:13: warning: ‘id’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |     cout << id << endl;
      |             ^~

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 805;

int val[3][MAX_N];
int pos[3][MAX_N];
int mn[3][MAX_N][MAX_N];
int mx[3][MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m){
        rep(j,n){
            cin >> val[i][j];
            pos[i][val[i][j]] = j;
        }
    }
    rep(i,m){
        rep(j,n){
            mn[i][j][j] = INF;
        }
        rep(j,n){
            for(int k=j+1;k<=n;k++){
                mn[i][j][k] = min(mn[i][j][k-1],val[i][k-1]);
                mx[i][j][k] = max(mx[i][j][k-1],val[i][k-1]);
            }
        }
    }
    double ans = 0;
    int id;
    rep(i,m){
        double res = 0;
        for(int j=1;j<n;j++){
            for(int k=j+1;k<=n;k++){
                int cand = 0;
                if(pos[i][j] < pos[i][k]){
                    if(mx[i][0][pos[i][k]] > k){
                        cand = mx[i][0][pos[i][k]];
                    }else if(mx[i][0][pos[i][j]] > j || mn[i][pos[i][j]+1][pos[i][k]] < j || mn[i][pos[i][k]+1][n] < k){
                        cand = k;
                    }
                }else{
                    if(mx[i][pos[i][k]+1][n] > k){
                        cand = mx[i][pos[i][k]+1][n];
                    }else if(mn[i][0][pos[i][k]] < k || mn[i][pos[i][k]+1][pos[i][j]] < j || mx[i][pos[i][j]+1][n] > j){
                        cand = k;
                    }
                }
                res += 2.0*cand/(n*(n-1));
            }
        }
        if(ans + EPS < res){
            ans = res;
            id = i;
        }
    }
    cout << id << endl;
    return 0;
}
0