結果

問題 No.2248 max(C)-min(C)
ユーザー publfl2publfl2
提出日時 2023-03-17 21:46:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 673 ms / 3,000 ms
コード長 1,330 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 29,688 KB
最終ジャッジ日時 2023-10-18 14:19:13
合計ジャッジ時間 15,689 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,076 KB
testcase_01 AC 4 ms
8,076 KB
testcase_02 AC 4 ms
8,076 KB
testcase_03 AC 4 ms
8,172 KB
testcase_04 AC 4 ms
8,148 KB
testcase_05 AC 4 ms
8,116 KB
testcase_06 AC 5 ms
8,272 KB
testcase_07 AC 6 ms
8,300 KB
testcase_08 AC 6 ms
8,300 KB
testcase_09 AC 6 ms
8,300 KB
testcase_10 AC 4 ms
8,112 KB
testcase_11 AC 6 ms
8,300 KB
testcase_12 AC 5 ms
8,180 KB
testcase_13 AC 5 ms
8,240 KB
testcase_14 AC 6 ms
8,300 KB
testcase_15 AC 5 ms
8,300 KB
testcase_16 AC 4 ms
8,172 KB
testcase_17 AC 5 ms
8,288 KB
testcase_18 AC 270 ms
27,508 KB
testcase_19 AC 27 ms
10,188 KB
testcase_20 AC 319 ms
29,688 KB
testcase_21 AC 301 ms
28,824 KB
testcase_22 AC 197 ms
23,880 KB
testcase_23 AC 114 ms
16,980 KB
testcase_24 AC 42 ms
11,520 KB
testcase_25 AC 284 ms
28,092 KB
testcase_26 AC 249 ms
26,328 KB
testcase_27 AC 285 ms
27,944 KB
testcase_28 AC 22 ms
9,780 KB
testcase_29 AC 260 ms
26,560 KB
testcase_30 AC 89 ms
15,500 KB
testcase_31 AC 318 ms
29,688 KB
testcase_32 AC 47 ms
11,932 KB
testcase_33 AC 81 ms
13,980 KB
testcase_34 AC 321 ms
29,688 KB
testcase_35 AC 323 ms
29,688 KB
testcase_36 AC 320 ms
29,688 KB
testcase_37 AC 149 ms
18,620 KB
testcase_38 AC 558 ms
29,688 KB
testcase_39 AC 557 ms
29,688 KB
testcase_40 AC 567 ms
29,688 KB
testcase_41 AC 478 ms
27,184 KB
testcase_42 AC 545 ms
29,688 KB
testcase_43 AC 463 ms
27,436 KB
testcase_44 AC 548 ms
29,688 KB
testcase_45 AC 395 ms
25,584 KB
testcase_46 AC 176 ms
16,712 KB
testcase_47 AC 541 ms
29,688 KB
testcase_48 AC 252 ms
29,688 KB
testcase_49 AC 655 ms
29,688 KB
testcase_50 AC 660 ms
29,688 KB
testcase_51 AC 656 ms
29,688 KB
testcase_52 AC 673 ms
29,688 KB
testcase_53 AC 69 ms
11,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define MAX (int)2e9 + 1

int x[200010],y[200010];
std::vector<int> index;
std::map<int,int> hash;
std::set< std::pair<int,int> > S;
std::vector<int> V[200010];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=a;i++) scanf("%d",&y[i]);
	
	for(int i=1;i<=a;i++)
	{
		V[i].push_back(x[i]);
		V[i].push_back(y[i]);
		V[i].push_back((x[i]+y[i])/2);
		V[i].push_back(MAX);
		std::sort(V[i].begin(),V[i].end());
		std::reverse(V[i].begin(),V[i].end());
		S.insert(std::make_pair(V[i].back(),i));
	}
	for(int i=1;i<=a;i++) for(int j=0;j<V[i].size();j++) index.push_back(V[i][j]);
	std::sort(index.begin(),index.end());
	index.erase(std::unique(index.begin(),index.end()),index.end());
	
	int ans = MAX;
	for(int i=0;i<index.size();i++)
	{
		int limit = index[i];
		while(!S.empty())
		{
			std::set< std::pair<int,int> > ::iterator it = S.begin();
			int val = (it->first), ind = (it->second);
			if(val<limit)
			{
				S.erase(it);
				V[ind].pop_back();
				S.insert(std::make_pair(V[ind].back(),ind));
			}
			else break;
		}
		std::set< std::pair<int,int> > ::iterator it = S.end();
		it--;
		int val = (it->first);
		if(val>=MAX) break;
		ans = ans<val-limit?ans:val-limit;
	}
	printf("%d",ans);
}
0