Submission #891211

# Submission time Handle Problem Language Result Execution time Memory
891211 2023-12-22T12:03:08 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
3000 ms 2356 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.back() - x);
				break;
			}else if(it >= n){
				sum+= abs(a[0] - x);
				break;
			}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 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 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 348 KB Output is correct
14 Correct 1 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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 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 348 KB Output is correct
14 Correct 1 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 14 ms 1884 KB Output is correct
18 Correct 15 ms 1884 KB Output is correct
19 Correct 16 ms 1880 KB Output is correct
20 Correct 15 ms 1880 KB Output is correct
21 Correct 15 ms 1880 KB Output is correct
22 Correct 15 ms 1884 KB Output is correct
23 Correct 15 ms 1884 KB Output is correct
24 Correct 14 ms 1880 KB Output is correct
25 Correct 15 ms 1884 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 1884 KB Output is correct
29 Correct 14 ms 1884 KB Output is correct
30 Correct 14 ms 1884 KB Output is correct
31 Correct 15 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 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 Execution timed out 3072 ms 2356 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 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 348 KB Output is correct
14 Correct 1 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 14 ms 1884 KB Output is correct
18 Correct 15 ms 1884 KB Output is correct
19 Correct 16 ms 1880 KB Output is correct
20 Correct 15 ms 1880 KB Output is correct
21 Correct 15 ms 1880 KB Output is correct
22 Correct 15 ms 1884 KB Output is correct
23 Correct 15 ms 1884 KB Output is correct
24 Correct 14 ms 1880 KB Output is correct
25 Correct 15 ms 1884 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 1884 KB Output is correct
29 Correct 14 ms 1884 KB Output is correct
30 Correct 14 ms 1884 KB Output is correct
31 Correct 15 ms 1884 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 348 KB Output is correct
35 Correct 0 ms 348 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 3072 ms 2356 KB Time limit exceeded
39 Halted 0 ms 0 KB -