#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
#define temp(T) template<class T>
temp(T) using V = vector<T>;
using vi = V<int>;
using vl = V<ll>;
using vvi = V<vi>;
using vpi = V<pi>;
using vb = V<bool>;
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
using str = string;
const int MOD = 1e9 + 7;
const ll BIG = 1e18;
const int INF = 1e9 + 2;
temp(T) bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
temp(T) bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; } // set a = max(a,b)
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s = "") {
unsyncIO();
if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO
}
#define read(x) int x; cin >> x;
temp(T) void pr(T x) {
cout << to_string(x);
}
temp(T) void prln(T x) {
cout << to_string(x) << "\n";
}
vi readV(int n) {
vi input(n);
F0R(i,n)
cin >> input[i];
return input;
}
int rand(int a, int b) {
return a + rand() % (b - a + 1);
}
#define gen(x,a,b) int x = rand(a,b)
vi genArr(int n, int a, int b) {
vi generated(n);
F0R(i,n) {
generated[i] = rand(a,b);
}
return generated;
}
vvi genTree(int n) {
vvi g(n + 1);
F0R(i,n) {
gen(p,0,i);
g[p].pb(i + 1);
g[i + 1].pb(p);
}
return g;
}
int countSum(vi arr) {
int ans = 0;
F0R(i,sz(arr))
ans += arr[i];
return ans;
}
void computeNearest(vi &arr, vi &nearest) {
int l = -1;
F0R(i,sz(arr)) {
if (arr[i] == -1) l = i;
if (arr[i] > 0 && l != -1) ckmin(nearest[i], i - l);
}
l = -1;
R0F(i,sz(arr)) {
if (arr[i] == -1) l = i;
if (arr[i] > 0 && l != -1) ckmin(nearest[i], l - i);
}
}
int main() {
setIO();
read(n);
vi arr = readV(n);
int sum = 0;
F0R(i, sz(arr))
if (arr[i] > 0) sum += arr[i];
vi nearest(n,INF);
computeNearest(arr,nearest);
int l = -1;
int ans = 0;
vi bonus(n,-1);
F0R(i,n) {
if (arr[i] > 0) l = i;
if (arr[i] == -1) {
if (l != -1) {
arr[l]--;
bonus[i] = (l) * 2 + (i - l);
}
l = -1;
}
}
int MAX_TIME = 3 * n + 1;
vvi dp(n + 1,vi(MAX_TIME,-INF));
dp[0][0] = 0;
FOR(i,1,n + 1) {
FOR(t,1,MAX_TIME) {
dp[i][t] = dp[i - 1][t - 1];
}
if (i == 1) dp[i] = dp[i - 1];
if (arr[i - 1] != -1) {
FOR(t,0,MAX_TIME) {
int time = nearest[i - 1] * 2;
FOR(k,0,arr[i - 1] + 1) {
int takeTime = k == 0 ? t : t - time;
if (t - time * k - 1 < 0) continue;
if (takeTime > (i - 1) * 2) continue;
if (k > 1) {
int stop = 25;
}
ckmax(dp[i][t], dp[i - 1][t - time * k - (i == 1 ? 0 : 1)] + k);
}
}
}
FOR(t,1,MAX_TIME) {
if (t <= bonus[i - 1]) dp[i][t]++;
}
}
int results = 0;
F0R(i,MAX_TIME) {
ckmax(results, dp[n][i]);
}
prln(sum - (results + ans));
return 0;
}
Compilation message
tortoise.cpp: In function 'int countSum(vi)':
tortoise.cpp:29:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
tortoise.cpp:30:18: note: in expansion of macro 'FOR'
30 | #define F0R(i,a) FOR(i,0,a)
| ^~~
tortoise.cpp:100:5: note: in expansion of macro 'F0R'
100 | F0R(i,sz(arr))
| ^~~
tortoise.cpp: In function 'void computeNearest(vi&, vi&)':
tortoise.cpp:29:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
tortoise.cpp:30:18: note: in expansion of macro 'FOR'
30 | #define F0R(i,a) FOR(i,0,a)
| ^~~
tortoise.cpp:107:5: note: in expansion of macro 'F0R'
107 | F0R(i,sz(arr)) {
| ^~~
tortoise.cpp: In function 'int main()':
tortoise.cpp:29:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
tortoise.cpp:30:18: note: in expansion of macro 'FOR'
30 | #define F0R(i,a) FOR(i,0,a)
| ^~~
tortoise.cpp:124:5: note: in expansion of macro 'F0R'
124 | F0R(i, sz(arr))
| ^~~
tortoise.cpp:161:29: warning: unused variable 'stop' [-Wunused-variable]
161 | int stop = 25;
| ^~~~
tortoise.cpp: In function 'void setIn(str)':
tortoise.cpp:49:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
tortoise.cpp: In function 'void setOut(str)':
tortoise.cpp:50:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |