Submission #121086

# Submission time Handle Problem Language Result Execution time Memory
121086 2019-06-26T05:25: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];
pll d[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++);
		int cnt=i;
		for(int j=i+i%2; j<i+k; j+=2) d[j]=c[cnt++];
		for(int j=i+1-i%2; j<i+k; j+=2) d[j]=c[cnt++];
		for(int j=i; j<i+k; j++) c[j]=d[j];
		i+=k-1;
	}
	//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:18: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:19: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);
                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -