結果

問題 No.2114 01 Matching
ユーザー kotatsugamekotatsugame
提出日時 2022-10-28 22:16:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,188 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 115,480 KB
実行使用メモリ 131,396 KB
最終ジャッジ日時 2023-09-20 05:17:23
合計ジャッジ時間 9,815 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,500 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<atcoder/mincostflow>
using namespace std;
int N,M,K;
map<int,vector<pair<int,int> > >mp;
main()
{
	cin>>N>>M>>K;
	vector<int>vs;
	for(int i=0;i<N+M;i++)
	{
		int A;cin>>A;
		mp[A%K].push_back(make_pair(A,i));
		vs.push_back(A);
	}
	sort(vs.begin(),vs.end());
	vs.erase(unique(vs.begin(),vs.end()),vs.end());
	auto id=[&vs](int x){return lower_bound(vs.begin(),vs.end(),x)-vs.begin();};
	atcoder::mcf_graph<int,int>mf(vs.size()+2);
	int source=vs.size(),sink=source+1;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		vector<pair<int,int> >now;
		now.swap(it->second);
		sort(now.begin(),now.end());
		for(int i=0;i<now.size();i++)
		{
			int u=id(now[i].first);
			if(now[i].second<N)mf.add_edge(source,u,1,0);
			else mf.add_edge(u,sink,1,0);
			now[i].second=u;
		}
		for(int i=1;i<now.size();i++)if(now[i-1].first<now[i].first)
		{
			int u=now[i-1].second,v=now[i].second;
			mf.add_edge(u,v,1e9,(now[i].first-now[i-1].first)/K);
			mf.add_edge(v,u,1e9,(now[i].first-now[i-1].first)/K);
		}
	}
	pair<int,int>ans=mf.flow(source,sink);
	if(ans.first==min(N,M))cout<<ans.second<<endl;
	else cout<<-1<<endl;
}
0