제출 #142783

#제출 시각아이디문제언어결과실행 시간메모리
142783DrumpfTheGodEmperorCoin Collecting (JOI19_ho_t4)C++14
0 / 100
2 ms380 KiB
#include <bits/stdc++.h>
#define int long long
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 2e5 + 5;
int n, x[N], y[N], ans = 0, compressY[2], compressX[N];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n * 2) cin >> x[i] >> y[i];
	//Solve for x and y independently.
	//Solving for y.
	fw (i, 0, n * 2) {
		if (y[i] <= 1) {
			compressY[1]++;
			ans += (1 - y[i]);
		} else {
			compressY[2]++;
			ans += (y[i] - 2);
		}
	}
	if (compressY[1] > n) ans += compressY[1] - n;
	if (compressY[2] > n) ans += compressY[2] - n;
	//Transferring extra points from 1 to 2 or vice versa.
	fw (i, 0, n * 2) {
		if (x[i] < 1) {
			compressX[1]++;
			ans += (1 - x[i]);
		} else if (x[i] > n) {
			compressX[n]++;
			ans += (x[i] - n);
		} else {
			compressX[x[i]]++;
		}
	}
	int leftmostGoodColumn = 1;
	fw (i, 1, n + 1) {
		while (compressX[i] > 2) {
			while (leftmostGoodColumn <= n && compressX[leftmostGoodColumn] >= 2) leftmostGoodColumn++;
			if (leftmostGoodColumn <= n) {
				compressX[leftmostGoodColumn]++;
				compressX[i]--;
				ans += abs(leftmostGoodColumn - i);
			}
		}
	}
	cout << ans;
	return 0;
}

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

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:33:15: warning: array subscript is above array bounds [-Warray-bounds]
    compressY[2]++;
    ~~~~~~~~~~~^
joi2019_ho_t4.cpp:33:15: warning: array subscript is above array bounds [-Warray-bounds]
joi2019_ho_t4.cpp:38:17: warning: array subscript is above array bounds [-Warray-bounds]
  if (compressY[2] > n) ans += compressY[2] - n;
      ~~~~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...