제출 #201262

#제출 시각아이디문제언어결과실행 시간메모리
201262abilCoin Collecting (JOI19_ho_t4)C++14
100 / 100
100 ms6088 KiB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int N = (1e5 + 12);
const int mod = (1e9 + 7);
const int inf = (1e9 + 7);

int a[N][3];

main(){
	int n, x, y;
	long long ans = 0;
	cin >> n;
	for(int i = 1;i <= 2 * n; i++){
		scanf("%lld%lld", &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;
		}
		a[x][y]++;
	}
	int cnt1 = 0, cnt2 = 0;
	for(int i = 1;i <= n; i++){
		cnt1 += a[i][1] - 1;
		cnt2 += a[i][2] - 1;
		if(cnt1 > 0 && cnt2 < 0){
			int x = min(cnt1, -cnt2);
			ans += x;
			cnt1 -= x;
			cnt2 += x;
		}
		if(cnt2 > 0 && cnt1 < 0){
			int x = min(cnt2, -cnt1);
			ans += x;
			cnt2 -= x;
			cnt1 += x;
		}
		ans += abs(cnt1);
		ans += abs(cnt2);
	}
	cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

joi2019_ho_t4.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...