Submission #3299

# Submission time Handle Problem Language Result Execution time Memory
3299 2013-08-30T10:53:25 Z movie_jo 두 섬간의 연결 (kriii1_2) C
0 / 1
44 ms 3432 KB
#include <stdio.h>

struct SUM {
	int f;
	int l;
	struct SUM *bef;
	struct SUM *aft;
} s[100001];

int main(void)
{
	int N, I, i, x, y;
	long long A = 0, B = 0, a, b;

	scanf("%d", &N);

	for(i = 1; i < N; i++)
	{
		s[i].f = i;
		s[i].l = i;
		s[i].aft = &s[i + 1];
		s[i + 1].bef = &s[i];
	}

	s[N].f = N;
	s[N].l = N;

	while(--N)
	{
		scanf("%d", &I);

		x = s[I].l - s[I].f + 1;
		y = s[I].aft->l - s[I].aft->f + 1;

		for(a = 0, i = 1; i < x; i++)
			a += i;
		for(b = 0, i = 1; i < y; i++)
			b += i;
		
		A += x*y;
		B += x*b + y*a + x*y;

		s[I].aft->f = s[I].f;
		s[I].aft->bef = s[I].bef;

		if(s[I].bef != NULL)
			s[I].bef->aft = s[I].aft;

		printf("%lld %lld\n", A, B);
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 3432 KB Output isn't correct
2 Halted 0 ms 0 KB -