답안 #429916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429916 2021-06-16T10:27:54 Z Nicholas_Patrick Coin Collecting (JOI19_ho_t4) C++17
0 / 100
2 ms 256 KB
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;

int diff(int x, int y){
	return x<y?y-x:x-y;
}
struct point{
	int x, y;
};
int main(){
	int n;
	scanf("%d", &n);
	vector<int> top, bot;
	long long ans=0;
	for(int i=n*2; i--;){
		int x, y;
		scanf("%d%d", &x, &y);
		if(y>2){
			ans+=y-2;
			y=2;
		}
		if(y<1){
			ans+=1-y;
			y=1;
		}
		if(x<1){
			ans+=1-x;
			x=1;
		}
		if(x>n){
			ans+=x-n;
			x=n;
		}
		if(y==2)
			top.push_back(x-1);
		else
			bot.push_back(x-1);
	}

	sort(top.begin(), top.end());
	sort(bot.begin(), bot.end());
	for(int i=n; i--;){
		if(top.empty() or not bot.empty() and top.back()<bot.back()){
			ans+=diff(bot.back(), i);
			bot.pop_back();
			if(bot.empty() or not top.empty() and top.back()>=bot.back()){
				ans+=diff(top.back(), i);
				top.pop_back();
			}else{
				ans+=diff(bot.back(), i);
				bot.pop_back();
				ans++;
			}
		}else{
			ans+=diff(top.back(), i);
			top.pop_back();
			if(top.empty() or not bot.empty() and bot.back()>=top.back()){
				ans+=diff(bot.back(), i);
				bot.pop_back();
			}else{
				ans+=diff(top.back(), i);
				top.pop_back();
				ans++;
			}
		}
	}
	printf("%lld\n", ans);
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:45:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   45 |   if(top.empty() or not bot.empty() and top.back()<bot.back()){
      |                     ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:48:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   48 |    if(bot.empty() or not top.empty() and top.back()>=bot.back()){
      |                      ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:59:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   59 |    if(top.empty() or not bot.empty() and bot.back()>=top.back()){
      |                      ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 240 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 2 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 240 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 2 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 240 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 2 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -