結果

問題 No.2114 01 Matching
ユーザー kotatsugamekotatsugame
提出日時 2022-10-28 23:33:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,458 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 100,648 KB
実行使用メモリ 53,460 KB
最終ジャッジ日時 2023-09-20 06:51:23
合計ジャッジ時間 22,105 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 359 ms
17,456 KB
testcase_03 AC 98 ms
14,180 KB
testcase_04 AC 147 ms
18,156 KB
testcase_05 WA -
testcase_06 AC 155 ms
5,520 KB
testcase_07 AC 158 ms
5,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 299 ms
10,916 KB
testcase_11 AC 638 ms
53,312 KB
testcase_12 AC 646 ms
53,332 KB
testcase_13 WA -
testcase_14 AC 310 ms
29,636 KB
testcase_15 AC 310 ms
29,572 KB
testcase_16 WA -
testcase_17 AC 270 ms
13,272 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 645 ms
53,260 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 108 ms
12,576 KB
testcase_26 AC 635 ms
53,460 KB
testcase_27 AC 634 ms
53,324 KB
testcase_28 AC 314 ms
30,928 KB
testcase_29 AC 640 ms
53,316 KB
testcase_30 AC 158 ms
5,600 KB
testcase_31 AC 636 ms
53,360 KB
testcase_32 WA -
testcase_33 AC 333 ms
17,236 KB
testcase_34 AC 156 ms
4,908 KB
testcase_35 AC 219 ms
23,728 KB
testcase_36 AC 648 ms
53,372 KB
testcase_37 WA -
testcase_38 AC 157 ms
5,244 KB
testcase_39 WA -
testcase_40 AC 215 ms
23,404 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 258 ms
13,300 KB
testcase_44 WA -
testcase_45 AC 358 ms
53,188 KB
testcase_46 WA -
testcase_47 AC 635 ms
53,216 KB
testcase_48 AC 638 ms
53,292 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 154 ms
5,060 KB
testcase_52 AC 311 ms
29,560 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
int N,M,K;
map<int,pair<vector<int>,vector<int> > >mp;
main()
{
	cin>>N>>M>>K;
	for(int i=0;i<N+M;i++)
	{
		int A;cin>>A;
		if(i<N)mp[A%K].first.push_back(A/K);
		else mp[A%K].second.push_back(A/K);
	}
	long ans=0;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		vector<int>B,R;
		B.swap(it->second.first);
		R.swap(it->second.second);
		if(N>M)B.swap(R);
		if(B.size()>R.size()||N==M&&B.size()!=R.size())
		{
			cout<<-1<<endl;
			return 0;
		}
		sort(B.begin(),B.end());
		priority_queue<long>LQ;
		multiset<pair<long,long> >RS,RSS;
		for(int r:R)
		{
			RS.insert(make_pair(r,0));
			RSS.insert(make_pair(r+0,0));
		}
		for(int b:B)
		{
			while(!RS.empty()&&RS.begin()->first<=b)
			{
				pair<long,long>p=*RS.begin();
				RS.erase(RS.begin());
				RSS.erase(RSS.find(make_pair(p.first+p.second,p.second)));
				LQ.push(p.first-p.second);
			}
			long l=1e15,r=1e15;
			if(!LQ.empty())l=b-LQ.top();
			if(!RSS.empty())r=RSS.begin()->first-b;
			if(l<=r)
			{
				ans+=l;
				LQ.pop();
			}
			else
			{
				ans+=r;
				pair<long,long>p=*RSS.begin();
				RSS.erase(RSS.begin());
				RS.erase(RS.find(make_pair(p.first-p.second,p.second)));
				if(l<(long)1e15)
				{
					int v=p.first-p.second;
					RS.insert(make_pair(v,l-(v-b)));
					RSS.insert(make_pair(v+l-(v-b),l-(v-b)));
					LQ.pop();
				}
			}
		}
	}
	cout<<ans<<endl;
}
0