結果

問題 No.2596 Christmas Eve (Heuristic ver.)
ユーザー anonymouslyanonymously
提出日時 2023-12-24 23:34:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,785 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 176,744 KB
実行使用メモリ 6,676 KB
スコア 0
最終ジャッジ日時 2023-12-24 23:35:15
合計ジャッジ時間 18,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
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 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 RE -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 RE -
testcase_43 WA -
testcase_44 RE -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 RE -
testcase_49 WA -
testcase_50 WA -
testcase_51 RE -
testcase_52 WA -
testcase_53 WA -
testcase_54 RE -
testcase_55 WA -
testcase_56 WA -
testcase_57 RE -
testcase_58 RE -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 WA -
testcase_80 WA -
testcase_81 RE -
testcase_82 RE -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 RE -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 RE -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 RE -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
testcase_106 RE -
testcase_107 WA -
testcase_108 RE -
testcase_109 WA -
testcase_110 RE -
testcase_111 WA -
testcase_112 RE -
testcase_113 RE -
testcase_114 WA -
testcase_115 WA -
testcase_116 WA -
testcase_117 WA -
testcase_118 WA -
testcase_119 WA -
testcase_120 WA -
testcase_121 RE -
testcase_122 WA -
testcase_123 RE -
testcase_124 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#define DEBUG

typedef struct wood{
	int id;
	int width;
	int height;
}wood;

bool compare(wood a, wood b){
	if(a.width!=b.width){
		return a.width<b.width;
	}else{
		return a.id<b.id;
	}
}

/*
 * とりあえずACを取得する為の解答
 */
int main(){
	int n,k;
	cin >> n >> k;
	
	//高さの合計
	int sum=0;
	
	//「木の先端」
	vector<wood> wooden_head(n);
	
	//「木の先端」の幅
	for(int i=0;i<n;i++){
		wooden_head[i].id=i+1;
		cin >> wooden_head[i].width;
	}
	
	//「木の先端」の高さ
	for(int i=0;i<n;i++){
		cin >> wooden_head[i].height;
		sum+=wooden_head[i].height;
	}
	
	//ソート
	sort(wooden_head.begin(),wooden_head.end(),compare);
	
	//「木の中央」
	vector<wood> wooden_central(2*n);
	
	//「木の中央」の幅
	for(int i=0;i<2*n;i++){
		wooden_central[i].id=i+1;
		cin >> wooden_central[i].width;
	}
	
	//「木の中央」の高さ
	for(int i=0;i<2*n;i++){
		cin >> wooden_central[i].height;
		sum+=wooden_central[i].height;
	}
	
	//ソート
	sort(wooden_central.begin(),wooden_central.end(),compare);
	
	//「木の幹」
	vector<wood> wooden_trunk(n);
	
	//「木の幹」の幅
	for(int i=0;i<n;i++){
		wooden_trunk[i].id=i+1;
		cin >> wooden_trunk[i].width;
	}
	
	//「木の幹」の高さ
	for(int i=0;i<n;i++){
		cin >> wooden_trunk[i].height;
		sum+=wooden_trunk[i].height;
	}

	//ソート
	sort(wooden_trunk.begin(),wooden_trunk.end(),compare);
	
	//木の高さの平均
	int avg=(sum+n/2)/n;
	
#ifdef DEBUG
	for(wood w:wooden_head){
		cout << w.id << ' ';
	}
	cout << endl;
	for(wood w:wooden_central){
		cout << w.id << ' ';
	}
	cout << endl;
	for(wood w:wooden_trunk){
		cout << w.id << ' ';
	}
	cout << endl;
#endif
	
	vector<vector<wood>> woods(k,vector<wood>(4));
	//幹は幅小⇒大、中央は幅大⇒小に確定させていく
	int j=0;
	while(j<k){
		woods[j][3]=wooden_trunk[j];
		j++;
		woods[k-j][2]=wooden_central[2*(n-j)+1];
		woods[k-j][1]=wooden_central[2*(n-j)];
	}
	
	//先端を決める
	j=0;
	while(j<k){
		//中央2個と幹の高さ
		int height=0;
		for(int _=1;_<4;_++)height+=woods[j][_].height;

		//先端探索開始位置
		int c=(j?woods[j-1][0].id:0);
		while(wooden_head[c].width<=woods[j][3].width){//先端の幅>幹の幅になるまでループ
			c++;
		}

		//暫定
		woods[j][0]=wooden_head[c];
		
		while(wooden_head[++c].width<woods[j][1].width){//先端の幅<中央の幅の間ループ
			if(abs(height+wooden_head[c].height-avg)<abs(height+woods[j][0].height-avg)){//高さの合計が平均に近ければ
				woods[j][0]=wooden_head[c];
			}
			if(c+1>=n)break;
		}
		j++;
	}

	j=0;
	while(j<k){
		for(int _=0;_<4;_++){
			if(_)cout << ' ';
			cout << woods[j][_].id;
		}
		cout << endl;
		j++;
	}
	
	return 0;
}
0