結果

問題 No.1460 Max of Min
ユーザー 沙耶花沙耶花
提出日時 2021-03-31 22:17:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,717 bytes
コンパイル時間 4,000 ms
コンパイル使用メモリ 271,376 KB
実行使用メモリ 18,752 KB
最終ジャッジ日時 2024-05-09 08:21:09
合計ジャッジ時間 8,811 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 1,158 ms
9,588 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000001

vector<long long> get(vector<long long> a,vector<long long> b){
	long long m = -Inf;
	rep(i,a.size()){
		m = max(m,min(a[i],b[i]));
	}
	a.push_back(m);
	a.erase(a.begin());
	return a;
	
}

int main(){
	
	long long K,N;
	cin>>K>>N;
	
	vector<long long> A(K),B(K);
	rep(i,K)cin>>A[i];
	rep(i,K)cin>>B[i];
	
	vector<long long> X;
	rep(i,K){
		X.push_back(A[i]);
		X.push_back(B[i]);
	}
	
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	
	if(N<K){
		cout<<A[N]<<endl;
		return 0;
	}
	
	N -= K-1;
	
	if(N<=3000){
		
		rep(i,N)A = get(A,B);
		cout<<A.back()<<endl;
	}
	else{
		
		long long ng = X.size(),ok = 0;
		while(ng-ok>1LL){
			long long mid = (ok+ng)/2;
			bitset<1001> a,b;
			rep(i,K){
				if(A[i]>=X[mid]){
					a[i] = 1;
				}
				else{
					a[i] = 0;
				}
				if(B[i]>=X[mid]){
					b[i] = 1;
				}
				else{
					b[i] = 0;
				}
			}
			long long n = N;
			vector<bitset<1001>> temp(1,a);
			bool f = false;
			while(true){
				if(n==0){
					f=true;
					if(temp.back()[K-1])ok = mid;
					else ng = mid;
					break;
				}
				n--;
				
				bitset<1001> t = temp.back();
			
				if((t & b).any()){
					t >>= 1;
					t[K-1] = 1;
				}
				else{
					t >>= 1;
				}
				
				rep(i,temp.size()){
					if(temp[i]==t){
						temp.erase(temp.begin(),temp.begin()+i);
						goto L;
					}
				}
				temp.push_back(t);
			}
			L:;
			if(!f){
				if(temp[n%temp.size()][K-1])ok = mid;
				else ng = mid;
			}
			
			
		}
		cout<<X[ok]<<endl;
		
	}
	
	
    return 0;
}
0