結果

問題 No.1467 Selling Cars
ユーザー Kanten4205Kanten4205
提出日時 2021-03-13 08:11:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 6,075 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 180,100 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 02:25:42
合計ジャッジ時間 7,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 455 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define logn long
#define lnog long
#define lgon long
#define itn int
typedef pair<long long, long long> P;
const long long INF = 1e18;
//省略系
string upper(string S) { // S の全文字を大文字にする. O(N)
    transform(S.begin(), S.end(), S.begin(), ::toupper);
    return S;
}
string lower(string S) { // S の全文字を小文字にする. O(N)
    transform(S.begin(), S.end(), S.begin(), ::tolower);
    return S;
}
long long len(string S) { // S の長さを取得(long long). O(N)
    return (long long)S.size();
}
long long count_str(string S, char ch) { // S 内に文字 ch がいくつ存在するか. O(N)
    long long ans = 0;
    for (long long i = 0; i < len(S); i++) {
        ans += (S.at(i) == ch);
    }
    return ans;
}
vector<string> split(string S, char ch) { //特定の文字 ch で S を分ける. O(N)
    string T;
    vector<string>A;
    for (long long i = 0; i < len(S); i++) {
        if (S[i] != ch) T.push_back(S[i]);
        else {
            A.push_back(T);
            T.clear();
        }
    }
    if (!T.empty()) A.push_back(T);
    return A;
}
template <typename T>
vector<T> rep(vector<T>& A, long long N) {
    vector<T> B;
    for (long long i = 0; i < N; i++) {
        for (long long j = 0; j < A.size(); j++) {
            B.push_back(A[j]);
        }
    }
    return B;
}
template <typename T>
long long count_arr(vector<T>& A, T key) {
    long long ans = 0;
    for (long long i = 0; i < A.size(); i++) {
        ans += (A.at(i) == key);
    }
    return ans;
}
template <typename Q>
string join(vector<Q>& A, char ch) {
    string S;
    for (long long i = 0; i < A.size(); i++) {
        string T = to_string(A.at(i));
        long long j = 0;
        while (j < T.size()) {
            S.push_back(T[j]);
            j++;
        }
        S.push_back(ch);
    }
    return S;
}
template<typename T>
vector<T> sorted(vector<T>& A) {
    sort(A.begin(), A.end());
    return A;
}
template<typename T>
vector<T> reversed(vector<T>& A) {
    reverse(A.begin(), A.end());
    return A;
}
template<typename T>
long long max_arr(vector<T>& A) {
    long long num = -10000000000000007;
    for (long long i = 0; i < A.size(); i++) {
        if (A[i] > num) num = A[i];
    }
    return num;
}
template<typename T>
long long min_arr(vector<T>& A) {
    long long num = 10000000000000007;
    for (long long i = 0; i < A.size(); i++) {
        if (A[i] < num) num = A[i];
    }
    return num;
}
template <typename T>
void input_arr(vector<T>& A, long long N) {
    for (long long i = 0; i < N; i++) {
        cin >> A[i];
    }
}
template <typename T>
void output_arr(vector<T>& A, long long N) {
    for (long long i = 0; i < N; i++) {
        cout << A[i];
        if (i != N - 1) cout << ' ';
    }
    cout << endl;
}
long long ans(const vector<long long>& A, const vector<long long>& B, long long i) {
    long long N = A.size(), M = B.size();
    deque<long long>used[N + 1];
    long long closest = 0;
    for (long long j = 0; j <N; j++) {
        while (closest + 1 < N && !(abs(B[j] - A[closest] < abs(B[j] - A[closest + 1])))) {
            closest++;
        }
        if (used[closest].size() == i) {
            long long right = closest, left = closest;
            while (left != 0 && used[left - 1].size() == i) left--;
            while (right + 1 < N && used[right + 1].size() == i) right++;
            right++;
            used[right].push_back(j);

            long long change = 0;
            for (long long k = left; k <= right; k++) {
                change += abs(A[k - 1] - B[used[k][0]]) - abs(A[k] - B[used[k][0]]);
            }
            if (change < 0) {
                for (long long k = left; k = right; k++) {
                    used[k - 1].push_back(used[j].front());
                    used[k].pop_front();
                }
            }
        }
        else {
            used[closest].push_back(j);
        }
    }
    long long ans = 0;
    for (long long j = 0; j < N; j++) {
        for (auto k : used[j]) {
            ans += abs(A[j] - B[k]);
        }
    }
    return ans;
}
int main() {
    long logn M, N; cin >> M >> N;
    vector<long long>A(M), B(N); input_arr(A, M); input_arr(B, N);
    B.push_back(-INF); B.push_back(INF);
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    A.insert(A.begin(), INF*(-1)); A.insert(A.end(), INF);
    B.insert(B.begin(), INF*(-1)); B.insert(B.end(), INF);
    for (long long i = 1; i <= M; i++) {
        cout << ans(B, A, i) % INF << endl;
    }
}
0