Submission #894653

#TimeUsernameProblemLanguageResultExecution timeMemory
894653DEQKGiraffes (JOI22_giraffes)C++17
0 / 100
0 ms348 KiB
#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() { const int inf = 2e9; vector<vector<int>> dp(4, vector<int> (n, 0)); int ans = 1; while(1) { vector<pair<int, pair<int, int>>> sq; for(int i = 0; i < 4; i++) { for(int j = 0; j < n; j++) { if(dp[i][j] == inf) 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, inf)); for(int i = 0; i < 4; i++) { for(int j = 0; j < n; j++) { int len = inf; 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 : N - j - 1); int b = (i % 2 ? p[j] : N - p[j] - 1); if(len <= min(a, b)) { dp[i][j] = len; } } } if(dp == vector<vector<int>> (4, vector<int> (n, inf))) { break; } ans += 1; } cout << n - ans << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> p[i]; p[i]--; } solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...