結果
問題 |
No.335 門松宝くじ
|
ユーザー |
|
提出日時 | 2023-03-21 21:50:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 863 ms / 2,000 ms |
コード長 | 1,195 bytes |
コンパイル時間 | 1,706 ms |
コンパイル使用メモリ | 178,000 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-18 14:31:41 |
合計ジャッジ時間 | 7,917 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 |
ソースコード
#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'; }