結果

問題 No.1767 BLUE to RED
ユーザー saksak
提出日時 2021-10-13 22:13:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 214,560 KB
実行使用メモリ 34,712 KB
最終ジャッジ日時 2023-09-12 04:43:06
合計ジャッジ時間 7,915 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 166 ms
20,836 KB
testcase_10 AC 213 ms
27,940 KB
testcase_11 AC 177 ms
21,180 KB
testcase_12 AC 167 ms
21,268 KB
testcase_13 AC 238 ms
29,068 KB
testcase_14 AC 315 ms
34,544 KB
testcase_15 AC 312 ms
33,316 KB
testcase_16 AC 314 ms
33,292 KB
testcase_17 AC 312 ms
33,440 KB
testcase_18 AC 316 ms
34,168 KB
testcase_19 AC 313 ms
33,960 KB
testcase_20 AC 314 ms
34,208 KB
testcase_21 AC 312 ms
33,764 KB
testcase_22 AC 309 ms
33,916 KB
testcase_23 AC 314 ms
34,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll N, M; cin >> N >> M;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  vector<ll> B(M); rep(i,M) cin >> B[i];

  assert(1<=N && N<=200000);
  assert(1<=M && M<=200000);
  rep(i,N) assert(1<=A[i] && A[i]<=1000000000 && (i==0||A[i-1]<A[i]));
  rep(i,M) assert(1<=B[i] && B[i]<=1000000000 && (i==0||B[i-1]<B[i]));
  set<ll> s; rep(i,N) s.insert(A[i]); rep(i,M) s.insert(B[i]);
  assert(s.size()==N+M);

  vector<p_ll> v;
  v.push_back(make_pair(-1*LLINF, 0));
  v.push_back(make_pair(LLINF, 0));
  rep(i,N) v.push_back(make_pair(A[i],0));
  rep(i,M) v.push_back(make_pair(B[i],1));
  sort(all(v));

  ll result = 2*LLINF+1 - (N+2), m = 0;
  rep(i,N+M+1) {
    m = max(m, v[i+1].first-v[i].first-1);
    if (v[i+1].second==0) {
      result -= m;
      m = 0;
    }
  }
  cout << result << endl;
  return 0;
}
0