結果
問題 | No.2114 01 Matching |
ユーザー | kotatsugame |
提出日時 | 2022-10-28 22:40:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,128 bytes |
コンパイル時間 | 1,070 ms |
コンパイル使用メモリ | 95,204 KB |
実行使用メモリ | 53,548 KB |
最終ジャッジ日時 | 2023-09-20 05:49:00 |
合計ジャッジ時間 | 16,340 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 175 ms
5,660 KB |
testcase_03 | AC | 89 ms
13,952 KB |
testcase_04 | AC | 130 ms
18,216 KB |
testcase_05 | WA | - |
testcase_06 | AC | 154 ms
5,392 KB |
testcase_07 | AC | 156 ms
5,260 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 177 ms
5,136 KB |
testcase_11 | AC | 571 ms
53,376 KB |
testcase_12 | AC | 574 ms
53,384 KB |
testcase_13 | WA | - |
testcase_14 | AC | 159 ms
5,396 KB |
testcase_15 | AC | 160 ms
5,436 KB |
testcase_16 | WA | - |
testcase_17 | AC | 169 ms
5,776 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 589 ms
53,312 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 592 ms
53,328 KB |
testcase_27 | AC | 587 ms
53,344 KB |
testcase_28 | AC | 297 ms
30,932 KB |
testcase_29 | AC | 594 ms
53,368 KB |
testcase_30 | AC | 154 ms
5,336 KB |
testcase_31 | AC | 592 ms
53,440 KB |
testcase_32 | WA | - |
testcase_33 | AC | 177 ms
5,652 KB |
testcase_34 | AC | 156 ms
5,116 KB |
testcase_35 | AC | 207 ms
23,764 KB |
testcase_36 | AC | 592 ms
53,548 KB |
testcase_37 | WA | - |
testcase_38 | AC | 157 ms
5,216 KB |
testcase_39 | WA | - |
testcase_40 | AC | 194 ms
23,284 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 169 ms
5,584 KB |
testcase_44 | WA | - |
testcase_45 | AC | 354 ms
53,220 KB |
testcase_46 | WA | - |
testcase_47 | AC | 585 ms
53,508 KB |
testcase_48 | AC | 585 ms
53,324 KB |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 152 ms
5,084 KB |
testcase_52 | AC | 159 ms
5,668 KB |
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type] 9 | main() | ^~~~
ソースコード
#include<iostream> #include<map> #include<vector> #include<algorithm> #include<queue> 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); else mp[A%K].second.push_back(A); } 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()); sort(R.begin(),R.end()); queue<int>RQ; for(int r:R)RQ.push(r); priority_queue<int>Q; for(int b:B) { while(!RQ.empty()&&RQ.front()<=b) { Q.push(RQ.front()); RQ.pop(); } if(RQ.empty()) { ans+=(b-Q.top())/K; Q.pop(); } else if(Q.empty()) { ans+=(RQ.front()-b)/K; RQ.pop(); } else { int l=b-Q.top(),r=RQ.front()-b; if(l<=r) { ans+=l/K; Q.pop(); } else { ans+=r/K; Q.push(RQ.front()-(l-r)); RQ.pop(); } } } } cout<<ans<<endl; }