結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 👑 kmjpkmjp
提出日時 2021-01-24 23:48:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,931 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 215,436 KB
実行使用メモリ 41,396 KB
最終ジャッジ日時 2023-09-02 10:55:09
合計ジャッジ時間 25,606 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,432 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 145 ms
5,196 KB
testcase_19 AC 46 ms
4,376 KB
testcase_20 AC 151 ms
5,188 KB
testcase_21 AC 35 ms
4,660 KB
testcase_22 AC 58 ms
4,376 KB
testcase_23 AC 102 ms
5,004 KB
testcase_24 AC 79 ms
5,272 KB
testcase_25 AC 91 ms
5,008 KB
testcase_26 AC 121 ms
5,436 KB
testcase_27 AC 73 ms
4,516 KB
testcase_28 AC 1,640 ms
22,312 KB
testcase_29 AC 1,377 ms
16,052 KB
testcase_30 AC 1,055 ms
15,064 KB
testcase_31 AC 1,838 ms
25,224 KB
testcase_32 AC 1,245 ms
28,220 KB
testcase_33 AC 1,229 ms
15,104 KB
testcase_34 AC 1,747 ms
25,384 KB
testcase_35 TLE -
testcase_36 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int A,B,C,D;
ll S;
ll V[4][1000];
ll Z[4];
vector<vector<ll>> X[3],Y[3];

ll hoge(ll v,int a,int b) {
	ll ret=0;
	FORR(x,X[a]) {
		ll y=v/x[0];
		if(y*x[0]<=v) y++;
		vector<ll>s={y,-1LL<<60,-1LL<<60};
		int num=lower_bound(ALL(Y[b]),s)-Y[b].begin();
		ret+=num;
	}
	return ret;
}
vector<ll> hoge2(ll v,int a,int b) {
	ll ret=0;
	FORR(x,X[a]) if(v%x[0]==0) {
		ll y=v/x[0];
		vector<ll>s={y,-1LL<<60,-1LL<<60};
		int num=lower_bound(ALL(Y[b]),s)-Y[b].begin();
		
		if(num<Y[b].size()&&Y[b][num][0]==y) {
			return {v,x[1],x[2],Y[b][num][1],Y[b][num][2]};
		}
		
	}
	return {};
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C>>D>>S;
	FOR(i,A) {
		cin>>V[0][i];
		if(V[0][i]==0) Z[0]=i;
	}
	FOR(i,B) {
		cin>>V[1][i];
		if(V[1][i]==0) Z[1]=i;
	}
	FOR(i,C) {
		cin>>V[2][i];
		if(V[2][i]==0) Z[2]=i;
	}
	FOR(i,D) {
		cin>>V[3][i];
		if(V[3][i]==0) Z[3]=i;
	}
	int a,b,c,d;
	FOR(a,A) FOR(b,B) {
		ll c=V[0][a]*V[1][b];
		if(c<0) X[0].push_back({-c,V[0][a],V[1][b]});
		if(c==0) X[1].push_back({c,V[0][a],V[1][b]});
		if(c>0) X[2].push_back({c,V[0][a],V[1][b]});
	}
	FOR(a,C) FOR(b,D) {
		ll c=V[2][a]*V[3][b];
		if(c<0) Y[0].push_back({-c,V[2][a],V[3][b]});
		if(c==0) Y[1].push_back({c,V[2][a],V[3][b]});
		if(c>0) Y[2].push_back({c,V[2][a],V[3][b]});
	}
	FOR(i,3) sort(ALL(X[i])),sort(ALL(Y[i]));
	ll mi=X[0].size()*Y[2].size()+X[2].size()*Y[0].size();
	ll pl=X[0].size()*Y[0].size()+X[2].size()*Y[2].size();
	ll zero=1LL*A*B*C*D-mi-pl;
	if(S<=mi) {
		S=mi+1-S;
		
		ll ret=1LL<<60;
		for(i=59;i>=0;i--) if(hoge(ret-(1LL<<i),0,2)+hoge(ret-(1LL<<i),2,0)>=S) ret-=1LL<<i;
		vector<ll> A=hoge2(ret,0,2);
		if(A.empty()) A=hoge2(ret,2,0);
		
		cout<<-A[0]<<endl;
		cout<<A[1]<<" "<<A[2]<<" "<<A[3]<<" "<<A[4]<<endl;
		
	}
	else if(S<=mi+zero) {
		cout<<0<<endl;
		cout<<V[0][Z[0]]<<" "<<V[1][Z[1]]<<" "<<V[2][Z[2]]<<" "<<V[3][Z[3]]<<endl;
	}
	else {
		S-=mi+zero;
		ll ret=1LL<<60;
		for(i=59;i>=0;i--) if(hoge(ret-(1LL<<i),0,0)+hoge(ret-(1LL<<i),2,2)>=S) ret-=1LL<<i;
		vector<ll> A=hoge2(ret,0,0);
		if(A.empty()) A=hoge2(ret,2,2);
		
		cout<<A[0]<<endl;
		cout<<A[1]<<" "<<A[2]<<" "<<A[3]<<" "<<A[4]<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0