Submission #891248

# Submission time Handle Problem Language Result Execution time Memory
891248 2023-12-22T15:14:00 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
0 / 100
1 ms 348 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;
////////////////////////////////psd vajno
	n--;
////////////////////////////////
	while(q--){
		int x, ans = 0;
		cin >> x;
		int l = lower_bound(all(v), x) - v.begin();
		int r = l+1;
		bool ok = 1;
		while(ok){
			//~ cout << v[l] << ' ' << v[r] << '\n';
			if(x - v[l] <= v[r] - x){
				int _l = lower_bound(all(v), x-(v[r]-x))-v.begin();
				if(v[_l] < x-(v[r]-x))_l++;
				if(_l > n)_l--;
				//~ cout << "_L   " << _l << '\n';
				ans += x-v[_l];
				if(_l == 0){
					ans += v[n]-v[0];
					ok = 0;
					break;
				}
				x = v[_l];
				l = _l-1;
			}
			else{
				int _r = lower_bound(all(v), x+(x-v[l]))-v.begin();
				if(_r > n)_r--;
				//~ cout << "_R   " << _r << '\n';
				ans += v[_r]-x;
				if(_r == n){
					ans += v[n]-v[0];
					ok = 0;
					break;
				}
				x = v[_r];
				r = _r+1;
			}
			//~ cout << x << ' ' << l << ' ' << r << ' ' << ans << '\n';
		}
		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:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -