結果

問題 No.2114 01 Matching
ユーザー yamakeyamake
提出日時 2022-10-28 23:16:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,361 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 212,784 KB
実行使用メモリ 51,656 KB
最終ジャッジ日時 2023-09-20 06:31:16
合計ジャッジ時間 19,170 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 293 ms
13,832 KB
testcase_03 AC 99 ms
14,100 KB
testcase_04 AC 129 ms
18,512 KB
testcase_05 WA -
testcase_06 AC 295 ms
13,916 KB
testcase_07 AC 309 ms
13,824 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 310 ms
14,008 KB
testcase_11 AC 500 ms
51,656 KB
testcase_12 AC 470 ms
51,320 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 304 ms
14,020 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 527 ms
51,368 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 474 ms
51,512 KB
testcase_27 AC 463 ms
51,488 KB
testcase_28 AC 241 ms
30,308 KB
testcase_29 AC 504 ms
51,636 KB
testcase_30 AC 301 ms
14,000 KB
testcase_31 AC 481 ms
51,404 KB
testcase_32 WA -
testcase_33 AC 311 ms
14,000 KB
testcase_34 AC 210 ms
13,832 KB
testcase_35 AC 192 ms
23,864 KB
testcase_36 AC 480 ms
51,372 KB
testcase_37 WA -
testcase_38 AC 317 ms
13,876 KB
testcase_39 WA -
testcase_40 AC 209 ms
23,868 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 308 ms
14,004 KB
testcase_44 WA -
testcase_45 AC 334 ms
51,372 KB
testcase_46 WA -
testcase_47 AC 559 ms
51,640 KB
testcase_48 AC 514 ms
51,316 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 310 ms
13,884 KB
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<"\n";
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const int inf=1.01e9;
constexpr int MOD=1000000007;
template<class T>bool chmax(T &a, const T &b) { if(a <= b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }

void solve(vector<int>& a,vector<int>& b,int k){
    int n=a.size();int m=b.size();
    map<int,multiset<int>> mp;
    rep(i,m)mp[b[i]%k].insert(b[i]);
    lint res=0;
    sort(a.begin(),a.end());
    rep(i,n){
        auto& v=mp[a[i]%k];
        auto it=v.lower_bound(a[i]);
        int mn=inf;
        if(it!=v.end())chmin(mn,(*it-a[i])/k);
        if(it!=v.begin()){
            --it;
            if(chmin(mn,(a[i]-*(it))/k))v.erase(it);
            else{
                ++it;
                if(it!=v.end())v.erase(it);
            }
        }
        res+=mn;
    }
    if(res>=inf)res=-1;
    cout<<res<<"\n";
}

signed main(){
    int n,m,k;cin>>n>>m>>k;
    vector<int> a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    if(n>m)swap(a,b);
    solve(a,b,k);
    return 0;
}
0