結果

問題 No.1460 Max of Min
ユーザー 沙耶花沙耶花
提出日時 2021-03-31 22:16:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,711 bytes
コンパイル時間 4,010 ms
コンパイル使用メモリ 270,964 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-09 08:20:08
合計ジャッジ時間 6,542 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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<int> 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