結果

問題 No.808 Kaiten Sushi?
ユーザー fumiphysfumiphys
提出日時 2019-03-28 00:23:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,732 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 121,324 KB
実行使用メモリ 14,996 KB
最終ジャッジ日時 2024-04-19 13:49:57
合計ジャッジ時間 3,803 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 16 ms
6,260 KB
testcase_24 AC 12 ms
5,376 KB
testcase_25 AC 17 ms
8,252 KB
testcase_26 AC 15 ms
8,200 KB
testcase_27 AC 39 ms
13,824 KB
testcase_28 AC 12 ms
6,076 KB
testcase_29 AC 37 ms
13,840 KB
testcase_30 AC 24 ms
9,236 KB
testcase_31 AC 39 ms
14,036 KB
testcase_32 AC 46 ms
14,816 KB
testcase_33 AC 23 ms
8,972 KB
testcase_34 AC 26 ms
9,400 KB
testcase_35 AC 35 ms
13,144 KB
testcase_36 AC 26 ms
8,948 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 44 ms
14,400 KB
testcase_40 AC 11 ms
6,132 KB
testcase_41 AC 13 ms
6,324 KB
testcase_42 AC 36 ms
13,396 KB
testcase_43 AC 16 ms
8,048 KB
testcase_44 AC 27 ms
9,400 KB
testcase_45 AC 16 ms
8,176 KB
testcase_46 AC 10 ms
5,924 KB
testcase_47 AC 46 ms
14,780 KB
testcase_48 AC 44 ms
14,868 KB
testcase_49 AC 44 ms
14,992 KB
testcase_50 AC 46 ms
14,996 KB
testcase_51 AC 46 ms
14,864 KB
testcase_52 AC 33 ms
13,160 KB
testcase_53 AC 46 ms
14,824 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 14 ms
6,168 KB
testcase_58 AC 25 ms
6,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}

bool comp(const Pl &x, const Pl &y){
  return x.first < y.first;
}

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll l;
  cin >> n >> l;
  vector<ll> x(n), y(n);
  rep(i, n)cin >> x[i];
  rep(i, n)cin >> y[i];
  vector<int> d(2 * n, 0);
  int mini = inf, maxi = -1;
  int mi = 0, ma = 0;
  vector<Pl> vec;
  rep(i, n){
    vec.pb(mk(x[i], 1));
    vec.pb(mk(y[i], -1));
  }
  sort(all(vec), comp);
  rep(i, 2 * n){
    d[i] = vec[i].second;
    if(i > 0)d[i] += d[i-1];
    if(maxi <= d[i]){
      maxi = d[i];
      ma = i;
    }
    if(mini > d[i]){
      mini = d[i];
      mi = i;
    }
  }
  ll tmp = 0;
  if(mini < 0){
    tmp = vec[mi].first;
    vector<Pl> v;
    bool flag = true;
    for(int i = mi + 1; i < 2 * n; i++){
      v.pb(mk(vec[i].first - tmp, vec[i].second));
    }
    for(int i = 0; i < mi; i++){
      if(flag && vec[i].second == 1){
        flag = false;
        continue;
      }
      v.pb(mk(vec[i].first - tmp + l, vec[i].second));
    }
    if(sz(v) == 2 * n - 1){
      v.insert(v.end(), mk(l, -1));
    }
    d.assign(sz(v), 0);
    maxi = -1, mini = inf, ma = 0, mi = 0;
    rep(i, sz(v)){
      d[i] = v[i].second;
      if(i > 0)d[i] += d[i-1];
      if(maxi <= d[i]){
        maxi = d[i];
        ma = i;
      }
      if(mini > d[i]){
        mini = d[i];
        mi = i;
      }
    }
    ll res = (maxi - 1) * l + v[ma+1].first;
    cout << res + tmp << endl;
  }else{
    ll res = (maxi - 1) * l + vec[ma+1].first;
    cout << res + tmp << endl;
  }
	return 0;
}
0