結果

問題 No.808 Kaiten Sushi?
ユーザー ei1333333
提出日時 2019-03-22 23:26:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 199,468 KB
最終ジャッジ日時 2025-01-07 00:05:07
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;

int main() {
  int N, L;
  cin >> N >> L;
  vector< pair< int, int > > mp2[2], mp;
  for(int z = 0; z < 2; z++) {
    for(int i = 0; i < N; i++) {
      int p;
      cin >> p;
      mp2[z].emplace_back(p, z);
    }
  }
  std::merge(mp2[0].begin(), mp2[0].end(),
             mp2[1].begin(), mp2[1].end(),
             std::back_inserter(mp));

  vector< int > st[2];
  int match_min = inf;
  for(auto &p : mp) {
    if(p.second == 0) {
      if(st[1].empty()) {
        st[p.second].emplace_back(p.first);
        continue;
      }
      st[1].pop_back();
      st[0].emplace_back(p.first);
    } else {
      if(st[0].empty()) {
        match_min = min(match_min, p.first);
        st[p.second].emplace_back(p.first);
        continue;
      }
      st[0].pop_back();
      st[1].emplace_back(p.first);
    }
  }
  if(st[1].empty()) cout << 1LL * L * (st[0].size() + st[1].size() - 1) + L + match_min << endl;
  else cout << 1LL * L * (st[0].size() + st[1].size() - 1) + st[1][0] << endl;
}

0