結果

問題 No.1950 片道きゃっちぼーる
ユーザー nawawannawawan
提出日時 2022-05-20 23:38:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,354 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 97,664 KB
実行使用メモリ 12,572 KB
最終ジャッジ日時 2023-10-20 14:34:19
合計ジャッジ時間 11,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 433 ms
12,572 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 393 ms
12,572 KB
testcase_07 AC 453 ms
12,572 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 456 ms
12,572 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 412 ms
12,572 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 451 ms
12,572 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<long long> X(N), A(N);
    for (int i = 0; i < N; i++)
        cin >> X[i];
    for (int i = 0; i < N; i++)
        cin >> A[i];
    vector<pair<long long, int>> a(N + 1);
    long long INF = 1000000000000000;
    X.push_back(-INF);
    sort(X.begin(), X.end());
    A.insert(A.begin(), -INF);
    for (int i = 0; i < N + 1; i++)
    {
        a[i] = {A[i] + X[i], i};
    }
    X.push_back(INF);
    A.push_back(INF);
    sort(a.begin(), a.end());
    vector<long long> res(N + 1);
    for (int i = N; i >= 1; i--)
    {
        auto [num, id] = a[i];
        int r = lower_bound(X.begin(), X.end(), A[id] + X[id]) - X.begin();
        int l = lower_bound(X.begin(), X.end(), X[id] - A[id]) - X.begin();
        long long temp = 0;
        if (X[r] == A[id] + X[id])
        {
            temp = max(temp, res[r]);
        }
        if (X[l] == A[id] - X[id])
        {
            temp = max(temp, res[l]);
        }
        if (num < temp)
        {
            res[id] = temp;
        }
        else
        {
            res[id] = num;
        }
    }
    for (int i = 1; i <= N; i++)
    {
        cout << res[i] - X[i] << endl;
    }
}
0