結果
問題 | No.2114 01 Matching |
ユーザー | kotatsugame |
提出日時 | 2022-10-28 23:19:08 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,440 bytes |
コンパイル時間 | 1,996 ms |
コンパイル使用メモリ | 98,292 KB |
実行使用メモリ | 53,408 KB |
最終ジャッジ日時 | 2023-09-20 06:34:05 |
合計ジャッジ時間 | 20,757 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 322 ms
14,196 KB |
testcase_03 | AC | 94 ms
13,932 KB |
testcase_04 | AC | 145 ms
18,188 KB |
testcase_05 | WA | - |
testcase_06 | AC | 156 ms
5,328 KB |
testcase_07 | AC | 158 ms
5,212 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 278 ms
9,380 KB |
testcase_11 | AC | 614 ms
53,332 KB |
testcase_12 | AC | 626 ms
53,356 KB |
testcase_13 | WA | - |
testcase_14 | AC | 288 ms
23,352 KB |
testcase_15 | AC | 286 ms
23,284 KB |
testcase_16 | WA | - |
testcase_17 | AC | 245 ms
11,124 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 623 ms
53,320 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 85 ms
10,284 KB |
testcase_26 | AC | 621 ms
53,356 KB |
testcase_27 | AC | 620 ms
53,404 KB |
testcase_28 | AC | 306 ms
30,948 KB |
testcase_29 | AC | 629 ms
53,396 KB |
testcase_30 | AC | 157 ms
5,552 KB |
testcase_31 | AC | 628 ms
53,408 KB |
testcase_32 | WA | - |
testcase_33 | AC | 295 ms
14,256 KB |
testcase_34 | AC | 157 ms
5,052 KB |
testcase_35 | AC | 216 ms
23,764 KB |
testcase_36 | AC | 618 ms
53,352 KB |
testcase_37 | WA | - |
testcase_38 | AC | 159 ms
5,332 KB |
testcase_39 | WA | - |
testcase_40 | AC | 208 ms
23,348 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 235 ms
11,128 KB |
testcase_44 | WA | - |
testcase_45 | AC | 362 ms
53,228 KB |
testcase_46 | WA | - |
testcase_47 | AC | 629 ms
53,240 KB |
testcase_48 | AC | 633 ms
53,332 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 154 ms
5,228 KB |
testcase_52 | AC | 285 ms
23,280 KB |
コンパイルメッセージ
main.cpp:10:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type] 10 | main() | ^~~~
ソースコード
#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)); RSS.insert(make_pair(p.first-p.second+l-r,l-r)); LQ.pop(); } } } } cout<<ans<<endl; }