結果

問題 No.2114 01 Matching
ユーザー yamakeyamake
提出日時 2022-10-28 23:10:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,246 bytes
コンパイル時間 3,986 ms
コンパイル使用メモリ 211,764 KB
実行使用メモリ 51,416 KB
最終ジャッジ日時 2023-09-20 06:25:00
合計ジャッジ時間 22,469 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 109 ms
13,964 KB
testcase_04 AC 144 ms
18,000 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 523 ms
51,416 KB
testcase_12 AC 530 ms
51,316 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 568 ms
51,224 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 511 ms
51,316 KB
testcase_27 AC 508 ms
51,284 KB
testcase_28 AC 263 ms
30,220 KB
testcase_29 AC 546 ms
51,388 KB
testcase_30 WA -
testcase_31 AC 532 ms
51,316 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 211 ms
14,088 KB
testcase_35 AC 193 ms
23,804 KB
testcase_36 AC 506 ms
51,400 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 228 ms
23,928 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 359 ms
51,364 KB
testcase_46 WA -
testcase_47 AC 610 ms
51,324 KB
testcase_48 AC 544 ms
51,220 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
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 it=mp[a[i]%k].lower_bound(a[i]);
        int mn=inf;
        if(it!=mp[a[i]%k].end())chmin(mn,(*it-a[i])/k);
        if(it!=mp[a[i]%k].begin()){
            --it;
            chmin(mn,(a[i]-*(it))/k);
        }
        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