結果

問題 No.335 門松宝くじ
ユーザー hirokazu1020hirokazu1020
提出日時 2016-01-16 00:39:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 97,148 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 23:52:09
合計ジャッジ時間 1,592 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 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 3 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:80:17: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   80 |         cout << ans << endl;
      |                 ^~~

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	int ans;
	int a[800];
	int mah[800], mat[800];
	int mih[800], mit[800];
	int maxv = - 1;
	rep(i,m) {
		rep(j, n)cin >> a[j];
		mah[0] = mih[0] = a[0];
		for (int j = 1; j < n;j++) {
			mah[j] = max(mah[j-1],a[j]);
			mih[j] = min(mih[j-1], a[j]);
		}
		mat[n-1] = mit[n-1] = a[n-1];
		for (int j = n - 2; j >= 0; j--) {
			mat[j] = max(mat[j+1], a[j]);
			mit[j] = min(mit[j+1], a[j]);
		}
		int sum = 0;
		rep(j, n) {
			int ma, mi;
			ma = mi = a[j];
			for (int k = j + 1; k < n; k++) {
				int x = 0;
				if (max(a[j], a[k]) < ma) {
					x = ma;
				}else if (min(a[j], a[k]) > mi) {
					x = max(a[j],a[k]);
				}
				if (a[j] < a[k]) {
					if (mah[j] > a[j])x = max(x, max(a[k], mah[j]));
					else if (mit[k] < a[k])x = max(x, a[k]);
				}
				else if (a[j] > a[k]) {
					if (mat[k] > a[k])x = max(x, max(a[j], mat[k]));
					else if (mih[j] < a[j])x = max(x, a[j]);
				}
				sum += x;
				ma = max(ma, a[k]);
				mi = min(mi, a[k]);
			}
		}
		if (maxv < sum) {
			maxv = sum;
			ans = i;
		}
	}
	cout << ans << endl;

	return 0;
}
0