답안 #121084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121084 2019-06-26T05:19:30 Z 임유진(#2971) Coin Collecting (JOI19_ho_t4) C++14
0 / 100
2 ms 384 KB
#include<stdio.h>
#include<algorithm>

using namespace std;

#define MAXN 100005

typedef long long lint;
typedef pair<lint, lint> pll;

pll c[2*MAXN];

int main(){
	int N;
	lint ans=0;

	scanf("%d", &N);
	for(int i=0; i<2*N; i++) scanf("%lld%lld", &c[i].first, &c[i].second);

	sort(c, c+2*N);
	for(int i=0; i<2*N; i++){
		int k;
		for(k=0; i+k<2*N&&c[i].first==c[i+k].first; k++);
		k--;
		if(k%2==1) k--;
		//printf("(%d %d)", i, k);
		for(int j=0; j<=k/2; j++) swap(c[i+j], c[i+k-j]);
		i+=k;
	}
	//for(int i=0; i<2*N; i++) printf("[%d %d]\n", c[i].first, c[i].second);
	for(int i=0; i<N; i++)
		ans+=abs(c[i*2].first-i-1)+abs(min(c[i*2].second, c[i*2+1].second)-1)+abs(c[i*2+1].first-i-1)+abs(max(c[i*2].second, c[i*2+1].second)-2);

	printf("%lld", ans);
	return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:18:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<2*N; i++) scanf("%lld%lld", &c[i].first, &c[i].second);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -