結果

問題 No.808 Kaiten Sushi?
ユーザー T1610T1610
提出日時 2019-03-22 22:35:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,971 bytes
コンパイル時間 1,774 ms
コンパイル使用メモリ 175,136 KB
実行使用メモリ 14,136 KB
最終ジャッジ日時 2023-10-19 09:50:02
合計ジャッジ時間 7,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 3 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 2 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 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 55 ms
7,536 KB
testcase_24 AC 44 ms
6,744 KB
testcase_25 AC 49 ms
7,272 KB
testcase_26 AC 47 ms
7,008 KB
testcase_27 AC 160 ms
12,288 KB
testcase_28 AC 43 ms
6,024 KB
testcase_29 AC 150 ms
11,760 KB
testcase_30 AC 91 ms
8,856 KB
testcase_31 AC 165 ms
12,816 KB
testcase_32 AC 191 ms
14,136 KB
testcase_33 AC 91 ms
8,856 KB
testcase_34 AC 104 ms
9,648 KB
testcase_35 AC 128 ms
10,968 KB
testcase_36 AC 92 ms
8,856 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 212 ms
13,344 KB
testcase_40 AC 39 ms
5,740 KB
testcase_41 AC 44 ms
5,984 KB
testcase_42 AC 165 ms
11,496 KB
testcase_43 AC 59 ms
7,008 KB
testcase_44 AC 117 ms
9,648 KB
testcase_45 AC 59 ms
7,008 KB
testcase_46 AC 32 ms
5,424 KB
testcase_47 AC 233 ms
14,136 KB
testcase_48 AC 225 ms
14,136 KB
testcase_49 AC 234 ms
14,136 KB
testcase_50 AC 228 ms
14,136 KB
testcase_51 AC 246 ms
14,136 KB
testcase_52 AC 111 ms
10,968 KB
testcase_53 AC 156 ms
14,136 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 3 ms
4,348 KB
testcase_57 AC 52 ms
7,008 KB
testcase_58 AC 89 ms
9,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
    ll N, L;
    cin >> N >> L;
    vector<ll> x(N), y(N);
    rep(i, N) cin >> x[i];
    rep(i, N) cin >> y[i];
    set<ll> X, Y;
    rep(i, N) {
        X.insert(x[i]);
        Y.insert(y[i]);
    }

    auto getIt = [](const set<ll>& st, ll val) {
        auto it = st.upper_bound(val);
        if (it != st.end()) return it;
        return st.begin();
    };

    ll ans = 0LL;
    ll cur = 0LL;

    rep(i, N) {
        {
            auto itX = getIt(X, cur);
            if (cur < *itX) ans += (*itX - cur);
            else ans += (L - cur + *itX);
            cur = *itX;
            X.erase(itX);
        }
        // cout << " " << cur;
        {
            auto itY = getIt(Y, cur);
            // cout << "(first itY " << *itY << "), ";
            if(X.size() > 0) {
                auto itX = getIt(X, *itY);
                // cout << " (nxt itX " << *itX << "), "; 
                {
                    itY = getIt(Y, *itX);
                    // cout << "(nxt itY " << *itY << "), ";
                    if(itY == Y.begin()) {
                        itY = Y.end();
                    }
                    --itY;
                }
            }
            if (cur < *itY) ans += (*itY - cur);
            else ans += (L - cur + *itY);
            cur = *itY;
            Y.erase(itY);
        }
        // cout << " " << cur << " -> " << ans << endl;
    }

    cout << ans << endl;
    return 0;
}
0