結果

問題 No.335 門松宝くじ
ユーザー kotatsugamekotatsugame
提出日時 2020-02-24 15:50:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 69,616 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 09:51:46
合計ジャッジ時間 1,448 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 6 ms
6,944 KB
testcase_09 AC 10 ms
6,944 KB
testcase_10 AC 10 ms
6,944 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 10 ms
6,944 KB
testcase_13 AC 10 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~
main.cpp: In function 'int main()':
main.cpp:71:15: warning: 'id' may be used uninitialized [-Wmaybe-uninitialized]
   71 |         cout<<id<<endl;
      |               ^~
main.cpp:10:20: note: 'id' was declared here
   10 |         int ans=-1,id;
      |                    ^~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
int E[800];
int LM[808],Lm[808],RM[808],Rm[808];
main()
{
	cin>>N>>M;
	int ans=-1,id;
	for(int I=0;I<M;I++)
	{
		for(int i=0;i<N;i++)cin>>E[i];
		LM[0]=Lm[0]=E[0];
		for(int i=1;i<N;i++)
		{
			LM[i]=max(LM[i-1],E[i]);
			Lm[i]=min(Lm[i-1],E[i]);
		}
		RM[N-1]=Rm[N-1]=E[N-1];
		for(int i=N-1;i--;)
		{
			RM[i]=max(RM[i+1],E[i]);
			Rm[i]=min(Rm[i+1],E[i]);
		}
		int now=0;
		for(int i=0;i<N-1;i++)
		{
			int L=E[i+1],U=E[i+1];
			for(int j=i+1;j<N;j++)
			{
				int tmp=0;
				if(i>0)
				{
					if(E[i]<E[j])
					{
						if(LM[i-1]>E[i])tmp=max(LM[i-1],E[j]);
					}
					else
					{
						if(Lm[i-1]<E[i])tmp=E[i];
					}
				}
				if(j+1<N)
				{
					if(E[i]<E[j])
					{
						if(Rm[j+1]<E[j])tmp=max(tmp,E[j]);
					}
					else
					{
						if(RM[j+1]>E[j])tmp=max(tmp,max(RM[j+1],E[i]));
					}
				}
				if(i+1<j)
				{
					if(U>E[i]&&U>E[j])tmp=max(tmp,U);
					else if(L<E[i]&&L<E[j])tmp=max(tmp,max(E[i],E[j]));
				}
				now+=tmp;
				U=max(U,E[j]);
				L=min(L,E[j]);
			}
		}
		if(ans<now)
		{
			ans=now;
			id=I;
		}
	}
	cout<<id<<endl;
}
0