#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(a) ((int) a.size())
#define F first
#define S second
const int N = 8e3 + 15;
int n, p[N];
void solve() {
vector<vector<int>> dp(4, vector<int> (n + 1, 0));
int ans = 1;
while(1) {
vector<pair<int, pair<int, int>>> sq;
for(int i = 0; i < 4; i++) {
for(int j = 1; j <= n; j++) {
if(dp[i][j] == 1e9) continue;
int x = j - (i >= 2 ? dp[i][j] : 0);
int y = p[j] - (i % 2 ? dp[i][j] : 0);
sq.pb({dp[i][j], {x, y}});
}
}
dp = vector<vector<int>> (4, vector<int> (n + 1, 1e9));
for(int i = 0; i < 4; i++) {
for(int j = 1; j <= n; j++) {
int len = 1e9;
for(int k = 0; k < sz(sq); k++) {
int dx = (i >= 2 ? j - (sq[k].S.F + sq[k].F) : sq[k].S.F - j);
int dy = (i % 2 ? p[j] - (sq[k].S.S + sq[k].F) : sq[k].S.S - p[j]);
if(dx > 0 && dy > 0) {
len = min(len, sq[k].F + max(dx, dy));
}
}
int a = (i >= 2 ? j - 1 : N - j);
int b = (i % 2 ? p[j] - 1 : N - p[j]);
if(len <= min(a, b)) {
dp[i][j] = len;
}
}
}
if(dp == vector<vector<int>> (4, vector<int> (n + 1, 1e9))) {
break;
}
ans += 1;
}
cout << n - ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> p[i];
}
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |