結果

問題 No.1460 Max of Min
ユーザー kotatsugame
提出日時 2021-03-31 22:50:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 819 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 88,916 KB
実行使用メモリ 391,424 KB
最終ジャッジ日時 2024-12-15 21:15:22
合計ジャッジ時間 17,696 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 85 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
long N;
int K;
long A[1010],B[1010];
const int LIM=50000;
long T[LIM];
vector<long>succ(vector<long>F)
{
	long nxt=-9e18;
	for(int j=0;j<K;j++)nxt=max(nxt,min(F[j],B[j]));
	F.erase(F.begin());
	F.push_back(nxt);
	return F;
}
main()
{
	cin>>K>>N;
	for(int i=0;i<K;i++)cin>>A[i];
	for(int i=0;i<K;i++)cin>>B[i];
	for(int i=0;i<K;i++)T[i]=A[i];
	if(N<K)
	{
		cout<<A[N]<<endl;
		return 0;
	}
	vector<long>F(A,A+K);
	long U=N-K;
	map<vector<long>,int>mp;
	int now=K;
	mp[F]=now;
	while(U>0&&now<LIM)
	{
		U--;
		F=succ(F);
		T[now]=F[K-1];
		now++;
		if(mp.find(F)!=mp.end())U%=now-mp[F];
		else mp[F]=now;
	}
	if(U==0)cout<<succ(F)[K-1]<<endl;
	else
	{
		if(N>=LIM)
		{
			N-=LIM;
			N%=K;
			N+=LIM-K;
		}
		cout<<T[N]<<endl;
	}
}
0