結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 342 ms
14,212 KB
testcase_03 AC 104 ms
14,032 KB
testcase_04 AC 154 ms
18,196 KB
testcase_05 WA -
testcase_06 AC 157 ms
5,328 KB
testcase_07 AC 158 ms
5,284 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 291 ms
9,252 KB
testcase_11 AC 629 ms
53,284 KB
testcase_12 AC 628 ms
53,428 KB
testcase_13 WA -
testcase_14 AC 284 ms
23,412 KB
testcase_15 AC 290 ms
23,224 KB
testcase_16 WA -
testcase_17 AC 249 ms
11,132 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 637 ms
53,324 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 93 ms
10,192 KB
testcase_26 AC 629 ms
53,364 KB
testcase_27 AC 635 ms
53,588 KB
testcase_28 AC 354 ms
30,952 KB
testcase_29 AC 621 ms
53,420 KB
testcase_30 AC 157 ms
5,280 KB
testcase_31 AC 626 ms
53,364 KB
testcase_32 WA -
testcase_33 AC 301 ms
14,204 KB
testcase_34 AC 157 ms
4,936 KB
testcase_35 AC 212 ms
23,864 KB
testcase_36 AC 608 ms
53,424 KB
testcase_37 WA -
testcase_38 AC 157 ms
5,360 KB
testcase_39 WA -
testcase_40 AC 208 ms
23,304 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 239 ms
11,196 KB
testcase_44 WA -
testcase_45 AC 359 ms
53,296 KB
testcase_46 WA -
testcase_47 AC 635 ms
53,264 KB
testcase_48 AC 622 ms
53,364 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 155 ms
5,092 KB
testcase_52 AC 285 ms
23,216 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<int>LQ;
		multiset<pair<int,int> >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<int,int>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<int,int>p=*RSS.begin();
				RSS.erase(RSS.begin());
				RS.erase(RS.find(make_pair(p.first-p.second,p.second)));
				if(l<(long)1e15)
				{
					RS.insert(make_pair(p.first-p.second,l-r+p.second));
					RSS.insert(make_pair(p.first+l-r,l-r+p.second));
					LQ.pop();
				}
			}
		}
	}
	cout<<ans<<endl;
}
0