結果

問題 No.808 Kaiten Sushi?
ユーザー tsutajtsutaj
提出日時 2019-03-23 03:41:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 601 ms / 2,000 ms
コード長 2,938 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 114,400 KB
実行使用メモリ 42,408 KB
最終ジャッジ日時 2023-10-19 21:50:54
合計ジャッジ時間 11,430 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 4 ms
4,348 KB
testcase_08 AC 5 ms
4,372 KB
testcase_09 AC 8 ms
4,792 KB
testcase_10 AC 6 ms
4,424 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 6 ms
4,440 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 7 ms
4,692 KB
testcase_16 AC 6 ms
4,508 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 120 ms
18,384 KB
testcase_24 AC 93 ms
15,480 KB
testcase_25 AC 103 ms
17,340 KB
testcase_26 AC 98 ms
16,584 KB
testcase_27 AC 327 ms
35,544 KB
testcase_28 AC 88 ms
13,224 KB
testcase_29 AC 312 ms
33,960 KB
testcase_30 AC 193 ms
23,400 KB
testcase_31 AC 346 ms
37,128 KB
testcase_32 AC 401 ms
41,616 KB
testcase_33 AC 189 ms
23,136 KB
testcase_34 AC 226 ms
26,040 KB
testcase_35 AC 275 ms
31,056 KB
testcase_36 AC 183 ms
22,608 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 464 ms
38,976 KB
testcase_40 AC 88 ms
12,080 KB
testcase_41 AC 90 ms
13,104 KB
testcase_42 AC 391 ms
32,904 KB
testcase_43 AC 135 ms
16,272 KB
testcase_44 AC 303 ms
26,040 KB
testcase_45 AC 126 ms
16,272 KB
testcase_46 AC 64 ms
10,692 KB
testcase_47 AC 588 ms
42,408 KB
testcase_48 AC 594 ms
42,408 KB
testcase_49 AC 601 ms
42,408 KB
testcase_50 AC 596 ms
42,408 KB
testcase_51 AC 594 ms
42,408 KB
testcase_52 AC 217 ms
31,056 KB
testcase_53 AC 306 ms
41,616 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 97 ms
16,804 KB
testcase_58 AC 157 ms
24,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, L;

void set_push(set< pair<int, int> > &S, int pos, int idx) {
    S.emplace(pos +   L, idx);
    S.emplace(pos + 2*L, idx);
    S.emplace(pos + 3*L, idx);
}

void set_erase(set< pair<int, int> > &S, int pos, int idx) {
    S.erase(make_pair(pos +   L, idx));
    S.erase(make_pair(pos + 2*L, idx));
    S.erase(make_pair(pos + 3*L, idx));
}

signed main() {
    scanf("%lld%lld", &N, &L);
    vector<int> x(N), y(N);

    set< pair<int, int> > sx, sy;
    for(int i=0; i<N; i++) {
        scanf("%lld", &x[i]);
        set_push(sx, x[i], i);
    }
    for(int i=0; i<N; i++) {
        scanf("%lld", &y[i]);
        set_push(sy, y[i], i);
    }

    int pos = L, ans = 0;
    while(sx.size() and sy.size()) {
        // 今いるところ -> 寿司 -> お茶 なので
        // 今いるところから最も近い寿司をまず求め、
        // それ以降で最も近いお茶を探すと良い
        // 実際に採用する寿司は、決めたお茶の左にある中で最も近いものにする
        // お茶に関しても同様
        int ini_x_pos, ini_x_idx;
        tie(ini_x_pos, ini_x_idx) = *sx.lower_bound(make_pair(pos, 0));

        int tmp_y_pos, tmp_y_idx;
        tie(tmp_y_pos, tmp_y_idx) = *sy.lower_bound(make_pair(ini_x_pos, 0));

        int tmp_x_pos, tmp_x_idx;
        tie(tmp_x_pos, tmp_x_idx) = *sx.lower_bound(make_pair(tmp_y_pos, 0));
        
        int nxt_y_pos, nxt_y_idx;
        tie(nxt_y_pos, nxt_y_idx) = *(--sy.lower_bound(make_pair(tmp_x_pos, 0)));

        int nxt_x_pos, nxt_x_idx;
        tie(nxt_x_pos, nxt_x_idx) = *(--sx.lower_bound(make_pair(tmp_y_pos, 0)));

        ans += nxt_y_pos - pos;
        pos = nxt_y_pos;
        while(pos <   L) pos += L;
        while(pos > 2*L) pos -= L;
        // fprintf(stderr, "take: x = %lld, y = %lld\n", nxt_x_idx, nxt_y_idx);

        set_erase(sx, x[nxt_x_idx], nxt_x_idx);
        set_erase(sy, y[nxt_y_idx], nxt_y_idx);
    }
    cout << ans << endl;
    return 0;
}
0