結果

問題 No.808 Kaiten Sushi?
ユーザー parukiparuki
提出日時 2019-04-06 10:26:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 172,952 KB
実行使用メモリ 22,228 KB
最終ジャッジ日時 2023-09-05 21:05:44
合計ジャッジ時間 10,062 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,508 KB
testcase_23 AC 73 ms
10,560 KB
testcase_24 AC 58 ms
9,300 KB
testcase_25 AC 65 ms
10,352 KB
testcase_26 AC 58 ms
9,748 KB
testcase_27 AC 212 ms
18,832 KB
testcase_28 AC 57 ms
8,140 KB
testcase_29 AC 200 ms
18,152 KB
testcase_30 AC 125 ms
13,040 KB
testcase_31 AC 226 ms
19,652 KB
testcase_32 AC 257 ms
21,764 KB
testcase_33 AC 122 ms
12,936 KB
testcase_34 AC 142 ms
14,280 KB
testcase_35 AC 176 ms
16,728 KB
testcase_36 AC 119 ms
12,648 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 275 ms
20,488 KB
testcase_40 AC 56 ms
7,640 KB
testcase_41 AC 57 ms
8,068 KB
testcase_42 AC 214 ms
17,588 KB
testcase_43 AC 79 ms
9,668 KB
testcase_44 AC 158 ms
14,276 KB
testcase_45 AC 80 ms
9,556 KB
testcase_46 AC 40 ms
6,860 KB
testcase_47 AC 298 ms
22,100 KB
testcase_48 AC 314 ms
22,228 KB
testcase_49 AC 313 ms
22,204 KB
testcase_50 AC 293 ms
22,092 KB
testcase_51 AC 295 ms
22,088 KB
testcase_52 AC 145 ms
16,728 KB
testcase_53 AC 201 ms
21,696 KB
testcase_54 AC 1 ms
4,384 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 62 ms
9,832 KB
testcase_58 AC 102 ms
13,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int N, L;
    cin >> N >> L;
    set<int> S[2];
    rep(i, 2) {
        rep(j, N) {
            int x;
            cin >> x;
            S[i].insert(x);
            S[i].insert(x + L);
        }
        S[i].insert((int)2e9 + 9);
    }

    ll ans = 0;
    int pos = 0;
    rep(i, 2 * N - 1) {
        int mod = i % 2;
        int x = *S[mod].lower_bound(pos);
        int y = *S[!mod].lower_bound(x);
        int z = *--S[mod].lower_bound(y);
        ans += z - pos;
        pos = z % L;
        S[mod].erase(pos);
        S[mod].erase(pos + L);
    }
    ans += *S[1].lower_bound(pos) - pos;
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0