Submission #768234

#TimeUsernameProblemLanguageResultExecution timeMemory
768234goodbyehanbyeolAdriatic (CEOI13_adriatic)C++17
100 / 100
244 ms228492 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 250101 #define MAXS 20 #define INF 1000000000000000001 #define bb ' ' #define ln '\n' #define Ln '\n' #define MX 2520 typedef pair<short, short> pss; int sum[MX][MX]; pss arr[MAX]; short u[MX][MX]; short d[MX][MX]; short l[MX][MX]; short r[MX][MX]; int X = 2510; inline int get(int r1, int c1, int r2, int c2) { return sum[r2][c2] - sum[r1 - 1][c2] - sum[r2][c1 - 1] + sum[r1 - 1][c1 - 1]; } inline int get(pss p1, pss p2) { if (p1.first > p2.first) swap(p1.first, p2.first); if (p1.second > p2.second) swap(p1.second, p2.second); return get(p1.first, p1.second, p2.first, p2.second); } pss unxt[MX][MX]; pss dnxt[MX][MX]; ll udp[MX][MX]; ll ddp[MX][MX]; signed main() { ios::sync_with_stdio(false), cin.tie(0); int N; cin >> N; int i, j; for (i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second, sum[arr[i].first][arr[i].second]++; for (i = 0; i <= X + 1; i++) for (j = 0; j <= X + 1; j++) l[i][j] = u[i][j] = 10101010; for (i = 1; i <= X; i++) for (j = 1; j <= X; j++) { if (sum[i][j]) { u[i][j] = d[i][j] = i; l[i][j] = r[i][j] = j; } sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; } for (i = 1; i <= X; i++) for (j = 1; j <= X; j++) { u[i][j] = min(u[i][j], min(u[i - 1][j], u[i][j - 1])); l[i][j] = min(l[i][j], min(l[i - 1][j], l[i][j - 1])); } for (i = X; i >= 1; i--) for (j = X; j >= 0; j--) { d[i][j] = max(d[i][j], max(d[i + 1][j], d[i][j + 1])); r[i][j] = max(r[i][j], max(r[i + 1][j], r[i][j + 1])); } for (i = 1; i <= X; i++) for (j = 1; j <= X; j++) { unxt[i][j] = pii(min((short)i, u[i - 1][j - 1]), max((short)j, r[i + 1][j + 1])); dnxt[i][j] = pii(max((short)i, d[i + 1][j + 1]), min((short)j, l[i - 1][j - 1])); } for (i = 1; i <= X; i++) for (j = X; j >= 1; j--) udp[i][j] = get(pii(1, X), pii(i, j)) + udp[unxt[i][j].first][unxt[i][j].second]; for (i = X; i >= 1; i--) for (j = 1; j <= X; j++) ddp[i][j] = get(pii(X, 1), pii(i, j)) + ddp[dnxt[i][j].first][dnxt[i][j].second]; for (i = 1; i <= N; i++) cout << N - 3 + udp[arr[i].first][arr[i].second] + ddp[arr[i].first][arr[i].second] << ln; }

Compilation message (stderr)

adriatic.cpp: In function 'int main()':
adriatic.cpp:37:80: warning: overflow in conversion from 'int' to 'short int' changes value from '10101010' to '8466' [-Woverflow]
   37 |  for (i = 0; i <= X + 1; i++) for (j = 0; j <= X + 1; j++) l[i][j] = u[i][j] = 10101010;
      |                                                                                ^~~~~~~~
#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...