QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#855675#9961. Cowsucup-team3691WA 0ms3892kbC++202.6kb2025-01-13 07:08:462025-01-13 07:08:47

Judging History

你现在查看的是最新测评结果

  • [2025-01-13 07:08:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3892kb
  • [2025-01-13 07:08:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

const int DIM = 1e6 + 5;
const int INF = 1e9;

int n;
int h[DIM];

bool check(int x) {
  ll need = 0;
  ll lft = x;
  ll cap = x;
  // TODO handle case where stuff from the left can be dealt with later
  for (int i = 1; i <= n; ++i) {
    //if (x == 4)
    //  debug(need, lft, cap);
    if (need > 0) {
      // I need 'need' from right
      ll target = lft - need * 2 + 1;
      if (target < 0)
        return 0;

      if (h[i] <= target) {
        cap = x - need;
        lft = h[i];
        need = 0;
      } else {
        lft = min(h[i], x);
        cap = x;
        need = h[i] - target;
      }
    } else {
      ll add = cap - lft;
      ll mid = (h[i] - lft) / 2;
      add = max(0ll, min(add, mid));

      ll y = h[i] - add;
    //  if (x == 4)
    //    debug(y, add);

      if (y <= x) {
        lft = y;
        cap = x;
      } else {
        lft = x;
        cap = x;
        need = y - x;
      }
    }
  }

  if (need > 0)
    return 0;

  return 1;
}

void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }

  int st = 1, dr = INF;
  while (st <= dr) {
    int mij = (st + dr) / 2;
    if (check(mij))
      dr = mij - 1;
    else 
      st = mij + 1;
  }

  cout << st << "\n";
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
//  cin >> t;
  while (t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

8
6 0 5 5 6 3 0 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3816kb

input:

6
7 6 5 2 6 8

output:

6

result:

wrong answer 1st numbers differ - expected: '7', found: '6'