Submission #965646

#TimeUsernameProblemLanguageResultExecution timeMemory
965646phoenix0423Garden (JOI23_garden)C++17
0 / 100
128 ms26324 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #pragma GCC optimize("Ofast,unroll-loops,O3") #pragma GCC target("avx,avx2") #define pb push_back #define eb emplace_back #define f first #define s second // #define int long long #define lowbit(x) x&-x namespace{ const int maxn = 5000 + 5; int a[maxn][maxn], dp[maxn][maxn], h[maxn], c[maxn], mx[maxn * 2], st[maxn * 2]; signed main1(void){ fastio; int n, m, d; cin>>n>>m>>d; set<int> cx, cy; for(int i = 0; i < n; i++){ int x, y; cin>>x>>y; h[x] |= 1; c[y] |= 1; } for(int i = 0; i < m; i++){ int x, y; cin>>x>>y; a[x][y] = 2; } auto cal = [&](int x, int y) -> int { if(x <= 0 || y <= 0) return 0; // cout<<"cal : "<<x<<" "<<y<<"\n"; y = min(y, d - 1); x = min(x, d - 1); return (x + y) * d - x * y; }; int ans = 0; for(int j = 2 * d - 1; j >= 0; j--){ int tj = j; if(j >= d) j -= d; if(c[j]){ j = tj; continue; } for(int i = 0; i < d; i++){ if(h[i] || a[i][j]) continue; int nxt = j == d - 1 ? 0 : j + 1; dp[i][j] = dp[i][nxt] + 1; // cout<<"ok : "<<i<<" "<<j<<" "<<dp[i][j]<<"\n"; } int top = 0; for(int i = 0; i < 2 * d; i++){ while(top && dp[st[top] - (st[top] >= d ? d : 0)][j] > dp[i - (i >= d ? d : 0)][j]){ int id = st[top] - (st[top] >= d ? d : 0), org = st[top]; top--; ans = max(ans, cal(dp[id][j], mx[org] + (i - org) - 1)); } mx[i] = (top ? i - st[top] : i + 1); st[++top] = i; } while(top){ // cout<<"put : "<<st.back() - (st.back() >= d) * d<<"\n"; ans = max(ans, cal(dp[st[top] - (st[top] >= d ? d : 0)][j], mx[st[top]] + 2 * d - st[top] - 1)); top--; } j = tj; } ans = d * d - ans; int cur = 0; for(int i = 0; i < d; i++){ if(h[i]) cur = i + 1; } for(int i = 0; i < d; i++){ ans = min(ans, d * cur); if(!h[i]) cur--; else cur = d; } cur = 0; for(int i = 0; i < d; i++){ if(c[i]) cur = i + 1; } for(int i = 0; i < d; i++){ ans = min(ans, d * cur); if(!c[i]) cur--; else cur = d; } ans = min(ans, d * cur); cout<<ans<<"\n"; } } int main(){ main1(); }

Compilation message (stderr)

garden.cpp: In function 'int {anonymous}::main1()':
garden.cpp:93:1: warning: no return statement in function returning non-void [-Wreturn-type]
   93 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...