Submission #891504

# Submission time Handle Problem Language Result Execution time Memory
891504 2023-12-23T06:17:18 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
100 / 100
412 ms 4200 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;
	vi v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}
	int q;
	cin >> q;
	while(q--){
		int x, ans = 0;
		cin >> x;
		int l = lower_bound(all(v),x) - v.begin();
		int r = l;
		while(1){
			if(l == 0){
				ans += abs(v[n-1] - x);
				break;
			}
			if(r == n){
				ans += abs(x - v[0]);
				break;
			}
			if(x - v[l-1] <= v[r] - x){
			    int i = lower_bound(all(v), 2*x-v[r]) - v.begin();
				ans += x-v[i];
				x = v[i];
				l = i;
			}
			else{
				int i = lower_bound(all(v), 2*x - v[l-1]) - v.begin() - 1;
				ans += v[i]-x;
				x = v[i];
				r = i+1;
			}
		}
		cout << ans << '\n';
	}
}
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:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 15 ms 1880 KB Output is correct
18 Correct 19 ms 1884 KB Output is correct
19 Correct 14 ms 1880 KB Output is correct
20 Correct 15 ms 1888 KB Output is correct
21 Correct 14 ms 1884 KB Output is correct
22 Correct 22 ms 1892 KB Output is correct
23 Correct 17 ms 1892 KB Output is correct
24 Correct 16 ms 1892 KB Output is correct
25 Correct 17 ms 1888 KB Output is correct
26 Correct 15 ms 1880 KB Output is correct
27 Correct 15 ms 1884 KB Output is correct
28 Correct 15 ms 1880 KB Output is correct
29 Correct 15 ms 1884 KB Output is correct
30 Correct 14 ms 1888 KB Output is correct
31 Correct 22 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 352 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 356 ms 3224 KB Output is correct
8 Correct 353 ms 3216 KB Output is correct
9 Correct 363 ms 3412 KB Output is correct
10 Correct 350 ms 3244 KB Output is correct
11 Correct 349 ms 3176 KB Output is correct
12 Correct 351 ms 3224 KB Output is correct
13 Correct 29 ms 2392 KB Output is correct
14 Correct 22 ms 856 KB Output is correct
15 Correct 230 ms 3808 KB Output is correct
16 Correct 236 ms 3920 KB Output is correct
17 Correct 236 ms 4176 KB Output is correct
18 Correct 30 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 15 ms 1880 KB Output is correct
18 Correct 19 ms 1884 KB Output is correct
19 Correct 14 ms 1880 KB Output is correct
20 Correct 15 ms 1888 KB Output is correct
21 Correct 14 ms 1884 KB Output is correct
22 Correct 22 ms 1892 KB Output is correct
23 Correct 17 ms 1892 KB Output is correct
24 Correct 16 ms 1892 KB Output is correct
25 Correct 17 ms 1888 KB Output is correct
26 Correct 15 ms 1880 KB Output is correct
27 Correct 15 ms 1884 KB Output is correct
28 Correct 15 ms 1880 KB Output is correct
29 Correct 15 ms 1884 KB Output is correct
30 Correct 14 ms 1888 KB Output is correct
31 Correct 22 ms 1884 KB Output is correct
32 Correct 0 ms 356 KB Output is correct
33 Correct 0 ms 360 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 352 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 356 ms 3224 KB Output is correct
39 Correct 353 ms 3216 KB Output is correct
40 Correct 363 ms 3412 KB Output is correct
41 Correct 350 ms 3244 KB Output is correct
42 Correct 349 ms 3176 KB Output is correct
43 Correct 351 ms 3224 KB Output is correct
44 Correct 29 ms 2392 KB Output is correct
45 Correct 22 ms 856 KB Output is correct
46 Correct 230 ms 3808 KB Output is correct
47 Correct 236 ms 3920 KB Output is correct
48 Correct 236 ms 4176 KB Output is correct
49 Correct 30 ms 2132 KB Output is correct
50 Correct 327 ms 4124 KB Output is correct
51 Correct 268 ms 4200 KB Output is correct
52 Correct 246 ms 4176 KB Output is correct
53 Correct 412 ms 4076 KB Output is correct
54 Correct 404 ms 4176 KB Output is correct
55 Correct 403 ms 4144 KB Output is correct
56 Correct 58 ms 3960 KB Output is correct
57 Correct 56 ms 4072 KB Output is correct
58 Correct 61 ms 3924 KB Output is correct