QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#855672 | #9961. Cows | ucup-team3691 | WA | 0ms | 3732kb | C++20 | 2.6kb | 2025-01-13 07:06:00 | 2025-01-13 07:06:01 |
Judging History
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 == 6)
// debug(need, lft, cap);
if (need > 0) {
// I need 'need' from right
ll target = lft - need * 2;
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 == 6)
// 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
input:
5 5 4 0 4 6
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 1 4 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
1 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3600kb
input:
8 6 0 5 5 6 3 0 6
output:
5
result:
wrong answer 1st numbers differ - expected: '4', found: '5'