Submission #67659662
Source Code Expand
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,sse4a,avx,avx2,popcnt,tune=native")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <climits>
using namespace std;
#ifdef LOCAL
#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define mp make_pair
#define all(x) (x).begin(),(x).end()
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
ll floor_div(ll x, ll y) {
assert(y != 0);
if (y < 0) {
y = -y;
x = -x;
}
if (x >= 0) return x / y;
return (x + 1) / y - 1;
}
ll ceil_div(ll x, ll y) {
assert(y != 0);
if (y < 0) {
y = -y;
x = -x;
}
if (x <= 0) return x / y;
return (x - 1) / y + 1;
}
template<typename T>
T sqr(T x) {
return x * x;
}
const ll INF = (ll)1e15;
const int N = 250250;
int n;
ll a[N];
ll S;
bool solve(ll d) {
ll bal = 0, minBal = 0;
for (int i = 0; i < n; i++) {
minBal = min(minBal, bal);
bal += a[i] - d;
if (bal - minBal > d) return false;
}
bal = minBal = 0;
ll lft = S;
for (int i = 0; i < n; i++) {
lft -= a[i];
if (3 * (bal - minBal) + a[i] > lft + 2 * d) return false;
minBal = min(minBal, bal);
bal += a[i] - d;
if (bal - minBal > lft) return false;
}
bal = minBal = 0;
lft = S;
for (int i = n - 1; i >= 0; i--) {
lft -= a[i];
if (3 * (bal - minBal) + a[i] > lft + 2 * d) return false;
minBal = min(minBal, bal);
bal += a[i] - d;
if (bal - minBal > lft) return false;
}
bal = minBal = 0;
for (int i = 0; i < n; i++) {
minBal = min(minBal, bal);
bal += 2 * a[i] - d;
if (bal - minBal > S - d) return false;
}
ll A = 0, B = S - a[0] - a[1];
for (int i = 0; i < n - 1; i++) {
if (2 * a[i] - 2 * A - B > d) return false;
if (2 * a[i + 1] - A - 2 * B > d) return false;
A += a[i];
B -= a[i + 2];
}
return true;
}
void solve() {
scanf("%d", &n);
S = 0;
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
S += a[i];
}
ll l = 0, r = S;
while(r - l > 1) {
ll d = (l + r) / 2;
if (solve(d))
r = d;
else
l = d;
}
printf("%lld\n", r);
}
int main() {
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
eprintf("--- Case #%d start ---\n", i);
//printf("Case #%d: ", i);
solve();
//printf("%lld\n", (ll)solve());
/*
if (solve()) {
printf("Yes\n");
} else {
printf("No\n");
}
*/
eprintf("--- Case #%d end ---\n", i);
eprintf("time = %.5lf\n", getCurrentTime());
eprintf("++++++++++++++++++++\n");
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Get Closer |
| User |
Um_nik |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
3467 Byte |
| Status |
WA |
| Exec Time |
81 ms |
| Memory |
5944 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:30:30: warning: statement has no effect [-Wunused-value]
30 | #define eprintf(...) 42
| ^~
Main.cpp:149:17: note: in expansion of macro ‘eprintf’
149 | eprintf("--- Case #%d start ---\n", i);
| ^~~~~~~
Main.cpp:30:30: warning: statement has no effect [-Wunused-value]
30 | #define eprintf(...) 42
| ^~
Main.cpp:164:17: note: in expansion of macro ‘eprintf’
164 | eprintf("--- Case #%d end ---\n", i);
| ^~~~~~~
Main.cpp:30:30: warning: statement has no effect [-Wunused-value]
30 | #define eprintf(...) 42
| ^~
Main.cpp:165:17: note: in expansion of macro ‘eprintf’
165 | eprintf("time = %.5lf\n", getCurrentTime());
| ^~~~~~~
Main.cpp:30:30: warning: statement has no effect [-Wunused-value]
30 | #define eprintf(...) 42
| ^~
Main.cpp:166:17: note: in expansion of macro ‘eprintf’
166 | eprintf("++++++++++++++++++++\n");
| ^~~~~~~
Main.cpp: In function ‘void solve()’:
Main.cpp:124:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
124 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:127:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
127 | scanf("%lld", &a[i]);
| ~~~~~^~~~~~~~~~~~~~~
Main.cpp: In function ‘int main()’:
Main.cpp:147:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
147 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 1400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt |
| All |
00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
1 ms |
3904 KiB |
| 01-001.txt |
WA |
74 ms |
3912 KiB |
| 01-002.txt |
WA |
75 ms |
3820 KiB |
| 01-003.txt |
WA |
63 ms |
3756 KiB |
| 01-004.txt |
WA |
63 ms |
3940 KiB |
| 01-005.txt |
WA |
64 ms |
3824 KiB |
| 01-006.txt |
WA |
64 ms |
3840 KiB |
| 01-007.txt |
AC |
67 ms |
4104 KiB |
| 01-008.txt |
WA |
67 ms |
3944 KiB |
| 01-009.txt |
AC |
78 ms |
4828 KiB |
| 01-010.txt |
AC |
72 ms |
4308 KiB |
| 01-011.txt |
AC |
14 ms |
5772 KiB |
| 01-012.txt |
AC |
36 ms |
5752 KiB |
| 01-013.txt |
AC |
41 ms |
5888 KiB |
| 01-014.txt |
AC |
48 ms |
5824 KiB |
| 01-015.txt |
AC |
58 ms |
5636 KiB |
| 01-016.txt |
AC |
67 ms |
5868 KiB |
| 01-017.txt |
WA |
35 ms |
5888 KiB |
| 01-018.txt |
WA |
21 ms |
5708 KiB |
| 01-019.txt |
WA |
23 ms |
5792 KiB |
| 01-020.txt |
WA |
23 ms |
5768 KiB |
| 01-021.txt |
WA |
24 ms |
5788 KiB |
| 01-022.txt |
WA |
26 ms |
5784 KiB |
| 01-023.txt |
WA |
25 ms |
5700 KiB |
| 01-024.txt |
WA |
25 ms |
5892 KiB |
| 01-025.txt |
WA |
27 ms |
5888 KiB |
| 01-026.txt |
WA |
26 ms |
5768 KiB |
| 01-027.txt |
WA |
27 ms |
5788 KiB |
| 01-028.txt |
WA |
27 ms |
5892 KiB |
| 01-029.txt |
WA |
27 ms |
5884 KiB |
| 01-030.txt |
AC |
81 ms |
3752 KiB |
| 01-031.txt |
WA |
70 ms |
5944 KiB |
| 01-032.txt |
WA |
71 ms |
5888 KiB |
| 01-033.txt |
WA |
69 ms |
5888 KiB |
| 01-034.txt |
WA |
71 ms |
5852 KiB |
| 01-035.txt |
WA |
26 ms |
5776 KiB |
| 01-036.txt |
WA |
25 ms |
5856 KiB |
| 01-037.txt |
WA |
26 ms |
5856 KiB |
| 01-038.txt |
WA |
64 ms |
5748 KiB |
| 01-039.txt |
WA |
26 ms |
5884 KiB |
| 01-040.txt |
WA |
26 ms |
5728 KiB |
| 01-041.txt |
WA |
70 ms |
5784 KiB |
| 01-042.txt |
WA |
27 ms |
5700 KiB |