Submission #60158138


Source Code Expand

#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <iostream>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

// ll pw(ll a, ll b) {
//   ll ans = 1;
//   while (b) {
//     while (!(b & 1))
//       b >>= 1, a = (a * a) % MOD;
//     ans = (ans * a) % MOD, --b;
//   }
//   return ans;
// }

struct Res {
  ll start;
  ll r;

  vector<pair<ll, ll>> df;
};

Res merge(Res a, Res b) {
  Res res;
  res.start = a.start + b.start;
  res.r = max(a.r, b.r);

  ll d = 0;
  int l = 0;
  int r = 0;
  while (l < a.df.size() || r < b.df.size()) {
    ll t = 1e9 + 100;
    if (l < a.df.size()) {
      t = min(t, a.df[l].first);
    }
    if (r < b.df.size()) {
      t = min(t, b.df[r].first);
    }
    ll add = 0;
    if (l < a.df.size() && a.df[l].first == t) {
      add += a.df[l].second;
      ++l;
    }
    if (r < b.df.size() && b.df[r].first == t) {
      add += b.df[r].second;
      ++r;
    }
    if (d + add > 0) {
      add = -d;
    }
    if (add != 0) {
      res.df.emplace_back(t, add);
    }
    d += add;
  }
  if (res.df.size() && res.df.back().first == res.r) {
    res.df.back().second += 1;
  } else {
    res.df.emplace_back(res.r, 1);
  }

  return res;
}

int n;
vector<pair<ll, ll>> vv;

Res solve(int l, int r) {
  if (l + 1 == r) {
    Res res;
    res.start = vv[l].first;
    res.r = vv[l].second;
    res.df.emplace_back(0, -1);
    res.df.emplace_back(vv[l].first, 1);
    res.df.emplace_back(vv[l].second, 1);
    return res;
  }
  int m = (l + r) / 2;
  return merge(solve(l, m), solve(m, r));
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  cin >> n;
  n = (1 << n);
  for (int i = 0; i < n; ++i) {
    ll l, r;
    cin >> l >> r;
    vv.emplace_back(l, r);
  }

  Res res = solve(0, n);
  ll cur = res.start;
  ll ans = cur;
  ll t = 0;
  ll d = 0;
  for (auto [x, y] : res.df) {
    cur += d * (x - t);
    d += y;
    t = x;
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task A - Schedule Optimization
User LHiC
Language C++ 20 (gcc 12.2)
Score 900
Code Size 2284 Byte
Status AC
Exec Time 110 ms
Memory 21568 KiB

Compile Error

Main.cpp: In function ‘Res merge(Res, Res)’:
Main.cpp:41:12: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   41 |   while (l < a.df.size() || r < b.df.size()) {
      |          ~~^~~~~~~~~~~~~
Main.cpp:41:31: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   41 |   while (l < a.df.size() || r < b.df.size()) {
      |                             ~~^~~~~~~~~~~~~
Main.cpp:43:11: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   43 |     if (l < a.df.size()) {
      |         ~~^~~~~~~~~~~~~
Main.cpp:46:11: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   46 |     if (r < b.df.size()) {
      |         ~~^~~~~~~~~~~~~
Main.cpp:50:11: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   50 |     if (l < a.df.size() && a.df[l].first == t) {
      |         ~~^~~~~~~~~~~~~
Main.cpp:54:11: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   54 |     if (r < b.df.size() && b.df[r].first == t) {
      |         ~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 53
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_srand_00.txt, 01_srand_01.txt, 01_srand_02.txt, 01_srand_03.txt, 01_srand_04.txt, 01_srand_05.txt, 01_srand_06.txt, 01_srand_07.txt, 01_srand_08.txt, 01_srand_09.txt, 02_lrand_00.txt, 02_lrand_01.txt, 02_lrand_02.txt, 02_lrand_03.txt, 02_lrand_04.txt, 02_lrand_05.txt, 02_lrand_06.txt, 02_lrand_07.txt, 02_lrand_08.txt, 02_lrand_09.txt, 02_lrand_10.txt, 02_lrand_11.txt, 02_lrand_12.txt, 02_lrand_13.txt, 02_lrand_14.txt, 02_lrand_15.txt, 02_lrand_16.txt, 02_lrand_17.txt, 02_lrand_18.txt, 02_lrand_19.txt, 03_short_00.txt, 03_short_01.txt, 03_short_02.txt, 03_short_03.txt, 03_short_04.txt, 03_short_05.txt, 03_short_06.txt, 03_short_07.txt, 04_hand_00.txt, 04_hand_01.txt, 04_hand_02.txt, 04_hand_03.txt, 04_hand_04.txt, 04_hand_05.txt, 04_hand_06.txt, 04_hand_07.txt, 05_same_00.txt, 05_same_01.txt, 05_same_02.txt, 05_same_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3480 KiB
00_sample_01.txt AC 1 ms 3468 KiB
00_sample_02.txt AC 1 ms 3416 KiB
01_srand_00.txt AC 1 ms 3460 KiB
01_srand_01.txt AC 1 ms 3516 KiB
01_srand_02.txt AC 1 ms 3408 KiB
01_srand_03.txt AC 1 ms 3412 KiB
01_srand_04.txt AC 1 ms 3532 KiB
01_srand_05.txt AC 1 ms 3516 KiB
01_srand_06.txt AC 1 ms 3428 KiB
01_srand_07.txt AC 1 ms 3420 KiB
01_srand_08.txt AC 1 ms 3532 KiB
01_srand_09.txt AC 1 ms 3480 KiB
02_lrand_00.txt AC 108 ms 21052 KiB
02_lrand_01.txt AC 110 ms 19324 KiB
02_lrand_02.txt AC 108 ms 19228 KiB
02_lrand_03.txt AC 108 ms 21432 KiB
02_lrand_04.txt AC 108 ms 21056 KiB
02_lrand_05.txt AC 109 ms 19988 KiB
02_lrand_06.txt AC 107 ms 19332 KiB
02_lrand_07.txt AC 108 ms 19324 KiB
02_lrand_08.txt AC 108 ms 19396 KiB
02_lrand_09.txt AC 108 ms 21416 KiB
02_lrand_10.txt AC 53 ms 11328 KiB
02_lrand_11.txt AC 53 ms 11688 KiB
02_lrand_12.txt AC 54 ms 11292 KiB
02_lrand_13.txt AC 54 ms 11476 KiB
02_lrand_14.txt AC 54 ms 12632 KiB
02_lrand_15.txt AC 54 ms 11584 KiB
02_lrand_16.txt AC 54 ms 11612 KiB
02_lrand_17.txt AC 54 ms 11808 KiB
02_lrand_18.txt AC 54 ms 11308 KiB
02_lrand_19.txt AC 56 ms 11860 KiB
03_short_00.txt AC 50 ms 11292 KiB
03_short_01.txt AC 99 ms 21424 KiB
03_short_02.txt AC 100 ms 19404 KiB
03_short_03.txt AC 99 ms 20608 KiB
03_short_04.txt AC 50 ms 11296 KiB
03_short_05.txt AC 25 ms 6764 KiB
03_short_06.txt AC 101 ms 21568 KiB
03_short_07.txt AC 25 ms 6648 KiB
04_hand_00.txt AC 49 ms 7208 KiB
04_hand_01.txt AC 25 ms 5260 KiB
04_hand_02.txt AC 104 ms 19752 KiB
04_hand_03.txt AC 104 ms 19596 KiB
04_hand_04.txt AC 104 ms 19676 KiB
04_hand_05.txt AC 103 ms 19672 KiB
04_hand_06.txt AC 104 ms 19748 KiB
04_hand_07.txt AC 105 ms 19748 KiB
05_same_00.txt AC 1 ms 3472 KiB
05_same_01.txt AC 1 ms 3476 KiB
05_same_02.txt AC 1 ms 3536 KiB
05_same_03.txt AC 54 ms 7360 KiB