結果

問題 No.808 Kaiten Sushi?
ユーザー mamekinmamekin
提出日時 2019-03-22 23:27:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,702 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 121,152 KB
実行使用メモリ 12,944 KB
最終ジャッジ日時 2023-10-19 10:49:54
合計ジャッジ時間 6,588 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 54 ms
7,176 KB
testcase_24 AC 43 ms
6,464 KB
testcase_25 AC 47 ms
6,948 KB
testcase_26 AC 46 ms
6,764 KB
testcase_27 AC 148 ms
11,304 KB
testcase_28 AC 42 ms
5,936 KB
testcase_29 AC 138 ms
10,908 KB
testcase_30 AC 84 ms
8,352 KB
testcase_31 AC 156 ms
11,668 KB
testcase_32 AC 179 ms
12,748 KB
testcase_33 AC 87 ms
8,300 KB
testcase_34 AC 96 ms
9,036 KB
testcase_35 AC 122 ms
10,188 KB
testcase_36 AC 84 ms
8,216 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 193 ms
12,108 KB
testcase_40 AC 36 ms
5,652 KB
testcase_41 AC 40 ms
5,896 KB
testcase_42 AC 156 ms
10,640 KB
testcase_43 AC 57 ms
6,664 KB
testcase_44 AC 109 ms
9,032 KB
testcase_45 AC 55 ms
6,672 KB
testcase_46 AC 30 ms
5,304 KB
testcase_47 AC 217 ms
12,944 KB
testcase_48 AC 211 ms
12,944 KB
testcase_49 AC 215 ms
12,944 KB
testcase_50 AC 217 ms
12,944 KB
testcase_51 AC 218 ms
12,944 KB
testcase_52 AC 103 ms
10,236 KB
testcase_53 AC 144 ms
12,740 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 46 ms
6,820 KB
testcase_58 AC 81 ms
8,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

set<int>::iterator nextPosition(const set<int>& x, int curr)
{
    auto it = x.lower_bound(curr);
    if(it == x.end())
        return x.begin();
    else
        return it;
}

set<int>::iterator prevPosition(set<int>& x, int curr)
{
    auto it = x.upper_bound(curr);
    if(it == x.begin())
        return --x.end();
    else
        return --it;
}

int getDiff(int a, int b, int len)
{
    if(a <= b)
        return b - a;
    else
        return len - a + b;
}

int main()
{
    int n, len;
    cin >> n >> len;
    set<int> x, y;
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        x.insert(a);
    }
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        y.insert(a);
    }

    int curr = *x.begin();
    long long ans = curr;
    x.erase(x.begin());
    for(int i=0; i<n-1; ++i){
        auto it1 = nextPosition(y, curr);
        auto it2 = nextPosition(x, *it1);
        it1 = prevPosition(y, *it2);

        ans += getDiff(curr, *it1, len);
        curr = *it1;
        y.erase(it1);
        ans += getDiff(curr, *it2, len);
        curr = *it2;
        x.erase(it2);
    }
    ans += getDiff(curr, *y.begin(), len);
    cout << ans << endl;

    return 0;
}
0