답안 #890796

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890796 2023-12-22T03:31:18 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 19416 KB
#include <bits/stdc++.h>
using namespace std;/*
<<<<It's never too late for a new beginning in your life>>>>
Today is hard
  tomorrow will worse
  but the day after tomorrow will be the sunshine..
 
HARD WORK BEATS TALENT WHEN TALENT DOESN'T WORK HARD............
Never give up  */
//The most CHALISHKANCHIK
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vii;
const long long N = 1e5+50, inf = 1e18, mod = 1e9+7;
void solve(){int n;
	cin >> n;
	set<int> ps, st;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		ps.insert(x);
	}
	st = ps;
	int q, x, ans = 0;
	cin >> q;
	while(q--){
		cin >> x;
		while(!ps.empty()){
			auto l = ps.lower_bound(x);
			auto r = ps.upper_bound(x);
			if(l == ps.end() || *l > *--ps.end())l--;
			if(r == ps.end() || *r > *--ps.end())r--;
			if(l == r){
				if(l != ps.begin())l--;
				else if(r != --ps.end())r++;
			}
			//~ cout << *l << ' ' << *r << ' ' << x << '\n';
			//~ cout << abs(x-*l) << ' ' << abs(*r-x) << '\n';
			if(abs(x-*l) <= abs(*r-x)){
				ans += abs(x-*l);
				x = *l;
				ps.erase(*l);
			}else{
				ans += abs(*r-x);
				x = *r;
				ps.erase(*r);
			}
			//~ for(auto i:ps)cout << i << ' ';
			//~ cout << '\n';
		}
		cout << ans << '\n';
		ans = 0;
		ps = st;
	}
}
main(){
	//~ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	//~ cin >> t;
	while(t--){
		solve();
	}
}

Compilation message

travel.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 124 ms 19416 KB Output is correct
18 Correct 134 ms 19136 KB Output is correct
19 Correct 125 ms 19284 KB Output is correct
20 Correct 124 ms 19144 KB Output is correct
21 Correct 130 ms 19024 KB Output is correct
22 Correct 133 ms 19192 KB Output is correct
23 Correct 129 ms 19284 KB Output is correct
24 Correct 141 ms 19192 KB Output is correct
25 Correct 133 ms 19200 KB Output is correct
26 Correct 133 ms 19024 KB Output is correct
27 Correct 130 ms 19028 KB Output is correct
28 Correct 128 ms 18956 KB Output is correct
29 Correct 129 ms 19028 KB Output is correct
30 Correct 126 ms 19024 KB Output is correct
31 Correct 127 ms 19192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 3085 ms 19072 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 124 ms 19416 KB Output is correct
18 Correct 134 ms 19136 KB Output is correct
19 Correct 125 ms 19284 KB Output is correct
20 Correct 124 ms 19144 KB Output is correct
21 Correct 130 ms 19024 KB Output is correct
22 Correct 133 ms 19192 KB Output is correct
23 Correct 129 ms 19284 KB Output is correct
24 Correct 141 ms 19192 KB Output is correct
25 Correct 133 ms 19200 KB Output is correct
26 Correct 133 ms 19024 KB Output is correct
27 Correct 130 ms 19028 KB Output is correct
28 Correct 128 ms 18956 KB Output is correct
29 Correct 129 ms 19028 KB Output is correct
30 Correct 126 ms 19024 KB Output is correct
31 Correct 127 ms 19192 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 600 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 3085 ms 19072 KB Time limit exceeded
39 Halted 0 ms 0 KB -