結果

問題 No.1767 BLUE to RED
ユーザー tko919tko919
提出日時 2021-11-26 22:47:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 204,072 KB
実行使用メモリ 12,676 KB
最終ジャッジ日時 2023-09-12 05:19:41
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 99 ms
8,404 KB
testcase_10 AC 127 ms
10,368 KB
testcase_11 AC 109 ms
8,636 KB
testcase_12 AC 100 ms
8,568 KB
testcase_13 AC 138 ms
11,452 KB
testcase_14 AC 174 ms
12,456 KB
testcase_15 AC 175 ms
12,428 KB
testcase_16 AC 174 ms
12,512 KB
testcase_17 AC 175 ms
12,404 KB
testcase_18 AC 175 ms
12,432 KB
testcase_19 AC 175 ms
12,504 KB
testcase_20 AC 175 ms
12,676 KB
testcase_21 AC 175 ms
12,440 KB
testcase_22 AC 175 ms
12,500 KB
testcase_23 AC 175 ms
12,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}



int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(m);
    rep(i,0,n)cin>>a[i];
    rep(i,0,m)cin>>b[i];
    
    ll ret=0;
    vector pos(n+1,vector<int>());
    rep(i,0,m){
        int id=lower_bound(ALL(a),b[i])-a.begin();
        pos[id].push_back(b[i]);
    }
    rep(i,0,n+1){
        if(pos[i].empty())continue;
        if(i==0)ret+=a[0]-pos[i].front();
        else if(i==n)ret+=pos[i].back()-a[n-1];
        else{
            int add=min(a[i]-pos[i].front(),pos[i].back()-a[i-1]);
            rep(j,0,pos[i].size()-1)chmin(add,a[i]-a[i-1]-(pos[i][j+1]-pos[i][j]));
            ret+=add;
        }
    }
    cout<<ret<<'\n';
    return 0;
}
0