Submission #891209

# Submission time Handle Problem Language Result Execution time Memory
891209 2023-12-22T12:01:36 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 3928 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 120000;


signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n; i++){
		cin >> a[i];
	}
	int q; cin >> q;
	while(q--){
		int x; cin >> x;
		int it = upper_bound(all(a), x) - a.begin();
		int it1 = it - 1;
		int sum = 0;
		while(true){
			if(it >= n && it1 < 0) break;
			if(it1 < 0){
				sum+= abs(a[it] - x);
				x = a[it];
				it++;
			}else if(it >= n){
				sum+= abs(a[it1] - x);
				x = a[it1];
				it1--;
			}else if(abs(a[it1] - x) > abs(a[it] - x)){
				sum+= abs(a[it] - x);
				x = a[it];
				it++;
			}else{
				sum+= abs(a[it1] - x);
				x = a[it1];
				it1--;
			}
		}
		cout << sum << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
10 Correct 0 ms 344 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 344 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
10 Correct 0 ms 344 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 344 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 16 ms 3688 KB Output is correct
18 Correct 16 ms 3676 KB Output is correct
19 Correct 19 ms 3672 KB Output is correct
20 Correct 16 ms 3680 KB Output is correct
21 Correct 16 ms 3668 KB Output is correct
22 Correct 16 ms 3668 KB Output is correct
23 Correct 16 ms 3548 KB Output is correct
24 Correct 16 ms 3676 KB Output is correct
25 Correct 16 ms 3676 KB Output is correct
26 Correct 16 ms 3792 KB Output is correct
27 Correct 16 ms 3816 KB Output is correct
28 Correct 16 ms 3672 KB Output is correct
29 Correct 16 ms 3676 KB Output is correct
30 Correct 15 ms 3928 KB Output is correct
31 Correct 15 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 3085 ms 3700 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 348 KB Output is correct
10 Correct 0 ms 344 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 344 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 16 ms 3688 KB Output is correct
18 Correct 16 ms 3676 KB Output is correct
19 Correct 19 ms 3672 KB Output is correct
20 Correct 16 ms 3680 KB Output is correct
21 Correct 16 ms 3668 KB Output is correct
22 Correct 16 ms 3668 KB Output is correct
23 Correct 16 ms 3548 KB Output is correct
24 Correct 16 ms 3676 KB Output is correct
25 Correct 16 ms 3676 KB Output is correct
26 Correct 16 ms 3792 KB Output is correct
27 Correct 16 ms 3816 KB Output is correct
28 Correct 16 ms 3672 KB Output is correct
29 Correct 16 ms 3676 KB Output is correct
30 Correct 15 ms 3928 KB Output is correct
31 Correct 15 ms 3672 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 452 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Execution timed out 3085 ms 3700 KB Time limit exceeded
39 Halted 0 ms 0 KB -