답안 #164380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164380 2019-11-20T05:54:50 Z frodakcin 섬 항해 (CEOI13_adriatic) C++11
100 / 100
379 ms 107288 KB
#include <cstdio>
#include <cstring>

using ll = long long;

const int MN = 2.5e5 + 100;
const int MX = 2.5e3 + 10;
int N;

int nx[MX][MX], ny[MX][MX];
ll v[MX][MX];
ll f[MN];
struct ISL
{
public:
	int x, y;
	void in(void) {scanf("%d%d", &x, &y);}
	void flip(void) {x = MX - x - 1, y = MX - y - 1;}
};
ISL a[MN];

void solve(void)
{
	memset(nx, -1, sizeof(nx));
	memset(ny, -1, sizeof(ny));
	memset(v, 0, sizeof(v));
	for(int i = 0, x, y;i < N;++i)
		x = a[i].x, y = a[i].y,
		v[x][y] = 1LL,
		nx[x+1][y+1] = x, ny[x-1][y-1] = y;
	for(int i = 0;i < MX;++i)
		for(int j = 0;j < MX;++j)
		{
			if(i && ~nx[i-1][j] && (nx[i-1][j] < nx[i][j] || !~nx[i][j]))
				nx[i][j] = nx[i-1][j];
			if(j && ~nx[i][j-1] && (nx[i][j-1] < nx[i][j] || !~nx[i][j]))
				nx[i][j] = nx[i][j-1];
		}
	for(int i = MX-1;i >= 0;--i)
		for(int j = MX-1;j >= 0;--j)
		{
			if(i<MX && ny[i+1][j] > ny[i][j])
				ny[i][j] = ny[i+1][j];
			if(j<MX && ny[i][j+1] > ny[i][j])
				ny[i][j] = ny[i][j+1];
		}
	for(int i = 0;i < MX;++i)
		for(int j = 0;j < MX;++j)
		{
			if(!~nx[i][j] || nx[i][j] > i) nx[i][j] = i;
			if(ny[i][j] < j) ny[i][j] = j;
		}
	for(int i = 0;i < MX;++i)
	{
		for(int j = MX-2;j >= 0;--j)
			v[i][j] += v[i][j+1];
		if(i)
			for(int j = 0;j < MX;++j)
				v[i][j] += v[i-1][j];
	}
	for(int i = 0;i < MX;++i)
		for(int j = MX-1;j >= 0;--j)
			if(v[i][j])
				v[i][j] += v[nx[i][j]][ny[i][j]];
	for(int i = 0;i < N;++i)
		f[i] += v[a[i].x][a[i].y] - 1;
}

int main(void)
{
	scanf("%d", &N);
	for(int i = 0;i < N;++i)
		a[i].in();
	solve();
	for(int i = 0;i < N;++i)
		a[i].flip();
	solve();
	for(int i = 0;i < N;++i)
		printf("%lld\n", f[i]+N-1);
	return 0;
}

Compilation message

adriatic.cpp: In function 'int main()':
adriatic.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
adriatic.cpp: In member function 'void ISL::in()':
adriatic.cpp:17:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  void in(void) {scanf("%d%d", &x, &y);}
                 ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 98972 KB Output is correct
2 Correct 238 ms 98936 KB Output is correct
3 Correct 239 ms 99192 KB Output is correct
4 Correct 223 ms 99072 KB Output is correct
5 Correct 259 ms 98936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 99032 KB Output is correct
2 Correct 237 ms 98936 KB Output is correct
3 Correct 240 ms 99000 KB Output is correct
4 Correct 237 ms 99064 KB Output is correct
5 Correct 245 ms 99064 KB Output is correct
6 Correct 258 ms 99064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 99192 KB Output is correct
2 Correct 243 ms 99116 KB Output is correct
3 Correct 250 ms 99108 KB Output is correct
4 Correct 227 ms 99096 KB Output is correct
5 Correct 245 ms 99120 KB Output is correct
6 Correct 272 ms 99068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 99668 KB Output is correct
2 Correct 257 ms 99832 KB Output is correct
3 Correct 256 ms 99676 KB Output is correct
4 Correct 234 ms 99708 KB Output is correct
5 Correct 245 ms 99908 KB Output is correct
6 Correct 308 ms 99780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 104920 KB Output is correct
2 Correct 375 ms 106872 KB Output is correct
3 Correct 379 ms 106804 KB Output is correct
4 Correct 343 ms 106488 KB Output is correct
5 Correct 348 ms 107128 KB Output is correct
6 Correct 376 ms 107072 KB Output is correct
7 Correct 370 ms 107288 KB Output is correct