답안 #768234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768234 2023-06-27T19:05:02 Z goodbyehanbyeol 섬 항해 (CEOI13_adriatic) C++17
100 / 100
244 ms 228492 KB
#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

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;
      |                                                                                ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 223052 KB Output is correct
2 Correct 150 ms 223124 KB Output is correct
3 Correct 151 ms 223216 KB Output is correct
4 Correct 154 ms 223068 KB Output is correct
5 Correct 150 ms 223180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 223180 KB Output is correct
2 Correct 155 ms 223148 KB Output is correct
3 Correct 150 ms 223184 KB Output is correct
4 Correct 152 ms 223100 KB Output is correct
5 Correct 151 ms 223180 KB Output is correct
6 Correct 158 ms 223340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 223132 KB Output is correct
2 Correct 146 ms 223148 KB Output is correct
3 Correct 149 ms 223212 KB Output is correct
4 Correct 157 ms 223336 KB Output is correct
5 Correct 160 ms 223180 KB Output is correct
6 Correct 162 ms 223132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 223356 KB Output is correct
2 Correct 155 ms 223308 KB Output is correct
3 Correct 155 ms 223380 KB Output is correct
4 Correct 154 ms 223324 KB Output is correct
5 Correct 162 ms 223312 KB Output is correct
6 Correct 164 ms 223472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 226108 KB Output is correct
2 Correct 244 ms 228188 KB Output is correct
3 Correct 236 ms 228116 KB Output is correct
4 Correct 216 ms 227784 KB Output is correct
5 Correct 200 ms 228336 KB Output is correct
6 Correct 210 ms 228308 KB Output is correct
7 Correct 209 ms 228492 KB Output is correct