제출 #744720

#제출 시각아이디문제언어결과실행 시간메모리
744720pavementBitaro's travel (JOI23_travel)C++17
15 / 100
3065 ms12980 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define int long long

using ii = pair<int, int>;
using iii = tuple<int, int, int>;

int N, Q, X[200005];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> X[i];
	}
	cin >> Q;
	for (int S; Q--; ) {
		cin >> S;
		set<int> T;
		for (int i = 1; i <= N; i++) {
			T.insert(X[i]);
		}
		int cur = 0, chng = 0;
		bool dir = 0;
		for (int i = 1; i <= N; i++) {
			auto it = T.lower_bound(S);
			int x = (int)-1e16, y = (int)1e16;
			if (it != T.end()) {
				y = *it;
			}
			if (it != T.begin()) {
				--it;
				x = *it;
				++it;
			}
			cur += min(S - x, y - S);
			if (S - x <= y - S) {
				if (dir == 1) chng++;
				dir = 0;
				T.erase(x);
				S = x;
			} else {
				if (dir == 0) chng++;
				dir = 1;
				T.erase(y);
				S = y;
			}
		}
		cout << cur << '\n';
		assert(chng <= 60);
	}
}

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

travel.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...