結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー 👑 kmjpkmjp
提出日時 2021-01-24 23:52:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,667 ms / 2,000 ms
コード長 3,007 bytes
コンパイル時間 2,486 ms
コンパイル使用メモリ 213,944 KB
実行使用メモリ 24,500 KB
最終ジャッジ日時 2023-09-02 11:00:48
合計ジャッジ時間 40,913 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 71 ms
4,380 KB
testcase_19 AC 29 ms
4,380 KB
testcase_20 AC 79 ms
4,380 KB
testcase_21 AC 18 ms
4,380 KB
testcase_22 AC 35 ms
4,380 KB
testcase_23 AC 55 ms
4,376 KB
testcase_24 AC 46 ms
4,380 KB
testcase_25 AC 52 ms
4,380 KB
testcase_26 AC 65 ms
4,376 KB
testcase_27 AC 42 ms
4,376 KB
testcase_28 AC 498 ms
10,104 KB
testcase_29 AC 460 ms
7,276 KB
testcase_30 AC 431 ms
7,344 KB
testcase_31 AC 541 ms
9,884 KB
testcase_32 AC 386 ms
11,224 KB
testcase_33 AC 390 ms
7,440 KB
testcase_34 AC 540 ms
10,372 KB
testcase_35 AC 742 ms
11,364 KB
testcase_36 AC 995 ms
14,332 KB
testcase_37 AC 186 ms
6,500 KB
testcase_38 AC 590 ms
8,220 KB
testcase_39 AC 335 ms
6,912 KB
testcase_40 AC 407 ms
7,388 KB
testcase_41 AC 566 ms
8,160 KB
testcase_42 AC 1,075 ms
12,704 KB
testcase_43 AC 564 ms
10,240 KB
testcase_44 AC 777 ms
11,404 KB
testcase_45 AC 658 ms
8,904 KB
testcase_46 AC 498 ms
11,480 KB
testcase_47 AC 309 ms
6,488 KB
testcase_48 AC 1,178 ms
23,828 KB
testcase_49 AC 999 ms
21,408 KB
testcase_50 AC 1,272 ms
24,500 KB
testcase_51 AC 1,200 ms
23,276 KB
testcase_52 AC 999 ms
21,992 KB
testcase_53 AC 1,578 ms
19,488 KB
testcase_54 AC 1,524 ms
21,360 KB
testcase_55 AC 1,667 ms
19,628 KB
testcase_56 AC 1,561 ms
19,572 KB
testcase_57 AC 1,035 ms
19,396 KB
testcase_58 AC 799 ms
20,648 KB
testcase_59 AC 799 ms
21,376 KB
testcase_60 AC 796 ms
19,624 KB
testcase_61 AC 797 ms
19,688 KB
testcase_62 AC 797 ms
20,340 KB
testcase_63 AC 36 ms
23,012 KB
testcase_64 AC 37 ms
23,996 KB
testcase_65 AC 34 ms
23,576 KB
testcase_66 AC 34 ms
23,024 KB
testcase_67 AC 36 ms
23,544 KB
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 1 ms
4,384 KB
testcase_70 AC 1 ms
4,380 KB
testcase_71 AC 1 ms
4,380 KB
testcase_72 AC 1 ms
4,380 KB
testcase_73 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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<pair<ll,ll>> X[3],Y[3];

ll hoge(ll v,int a,int b) {
	ll ret=0;
	FORR(x,X[a]) {
		ll y=v/x.first;
		if(y*x.first<=v) y++;
		pair<ll,ll> s={y,-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.first==0) {
		ll y=v/x.first;
		pair<ll,ll> s={y,-1LL<<60};
		int num=lower_bound(ALL(Y[b]),s)-Y[b].begin();
		
		if(num<Y[b].size()&&Y[b][num].first==y) {
			return {v,x.second/100000-50000,x.second%100000-50000,Y[b][num].second/100000-50000,Y[b][num].second%100000-50000};
		}
		
	}
	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];
		ll v=(V[0][a]+50000)*100000+V[1][b]+50000;
		if(c<0) X[0].push_back({-c,v});
		if(c==0) X[1].push_back({c,v});
		if(c>0) X[2].push_back({c,v});
	}
	FOR(a,C) FOR(b,D) {
		ll c=V[2][a]*V[3][b];
		ll v=(V[2][a]+50000)*100000+V[3][b]+50000;
		if(c<0) Y[0].push_back({-c,v});
		if(c==0) Y[1].push_back({c,v});
		if(c>0) Y[2].push_back({c,v});
	}
	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