답안 #99056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99056 2019-02-28T08:31:28 Z 크리(#2856, kriii) Coin Collecting (JOI19_ho_t4) C++17
0 / 100
3 ms 384 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int N, C[100100][2];

int main()
{
	long long ans = 0;

	scanf ("%d",&N);
	vector<int> U[2];
	for (int i=0;i<N*2;i++){
		int x,y;
		scanf ("%d %d",&x,&y);
		if (x < 1) ans += 1 - x, x = 1;
		if (x > N) ans += x - N, x = N;
		if (y < 1) ans += 1 - y, y = 1;
		if (y > 2) ans += y - 2, y = 2;
		C[x][y-1]++;
		U[y-1].push_back(x);
	}

	for (int y=0;y<2;y++){
		sort(U[y].begin(),U[y].end());
		reverse(U[y].begin(),U[y].end());
	}

	for (int x=1;x<=N;x++){
		int mn = 0x7ffffff, p = 0;
		for (int k : {0,2,1}){
			if (U[0].size() >= k && U[1].size() >= 2-k){
				int sum = 0;
				for (int i=0;i<k;i++) sum += abs(x-*(U[0].rbegin()+i));
				for (int i=0;i<2-k;i++) sum += abs(x-*(U[1].rbegin()+i));
				if (k != 1) sum++;
				if (mn > sum) mn = sum, p = k;
			}
		}
		ans += mn;
		for (int i=0;i<p;i++) U[0].pop_back();
		for (int i=0;i<2-p;i++) U[1].pop_back();
	}

	printf ("%lld\n",ans);

	return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:33:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (U[0].size() >= k && U[1].size() >= 2-k){
        ~~~~~~~~~~~~^~~~
joi2019_ho_t4.cpp:33:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (U[0].size() >= k && U[1].size() >= 2-k){
                            ~~~~~~~~~~~~^~~~~~
joi2019_ho_t4.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&N);
  ~~~~~~^~~~~~~~~
joi2019_ho_t4.cpp:16:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d",&x,&y);
   ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -