Submission #890785

# Submission time Handle Problem Language Result Execution time Memory
890785 2023-12-22T03:17:13 Z vjudge1 Bitaro's travel (JOI23_travel) C++17
15 / 100
82 ms 17940 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;

int binpow (int a, int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a;
	else {
		int b = binpow (a, n/2);
		return b * b;
	}
}


void solve(){
	
	int n,m,k;
	cin>>n;
	vector<int>v(n);
	
	for(auto &to:v)cin>>to;
	
	vector<pii>vs(n);
	
	cin>>m>>k;
	
	for(int i = 0;i<n;i++){
		if(i!=0)vs[i].f = i-1;
		if(i!=n-1)vs[i].s = i+1;
	}
	
	map<int,int>vis;
	int cnt = 1;
	int ans = 0;
	int l,r;
	
	int mn = mod,ind = -1;
	for(int i = 0;i<n;i++)
		if(umin(mn,abs(v[i]-k))){
			ind = i;
			l = vs[i].f;
			r = vs[i].s;
		}
	ans += mn;k = ind;
	vis[ind] = 1;
	while(cnt<n){
		//~ cout<<k<<endl;
		//~ cout<<vs[k].f<<" "<<vs[k].s<<endl;
		int disl = mod,disr = mod;
		
		if(k!=0&&vis[vs[k].f]==0)disl =	abs(v[vs[k].f] - v[k]);
		if(k!=n-1&&vis[vs[k].s]==0)disr = abs(v[vs[k].s] - v[k]);
		
		
		if(disl<=disr){
			vs[vs[k].f].s = vs[k].s;
			vis[k] = 1; 
			ans += disl;
			k = vs[k].f;
		
		}
		else{
			vs[vs[k].s].f = vs[k].f;
			vis[k] = 1; 
			ans += disr;
			k = vs[k].s;
		}
		cnt++;
	}
	
	cout<<ans<<endl;
	





}

 signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt;
	while(tt--)solve();

}

Compilation message

travel.cpp: In function 'void solve()':
travel.cpp:55:6: warning: variable 'l' set but not used [-Wunused-but-set-variable]
   55 |  int l,r;
      |      ^
travel.cpp:55:8: warning: variable 'r' set but not used [-Wunused-but-set-variable]
   55 |  int l,r;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 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 77 ms 17652 KB Output is correct
18 Correct 79 ms 17852 KB Output is correct
19 Correct 75 ms 17488 KB Output is correct
20 Correct 73 ms 17488 KB Output is correct
21 Correct 80 ms 17488 KB Output is correct
22 Correct 76 ms 17432 KB Output is correct
23 Correct 82 ms 17800 KB Output is correct
24 Correct 81 ms 17556 KB Output is correct
25 Correct 74 ms 17692 KB Output is correct
26 Correct 76 ms 17488 KB Output is correct
27 Correct 82 ms 17940 KB Output is correct
28 Correct 77 ms 17492 KB Output is correct
29 Correct 75 ms 17620 KB Output is correct
30 Correct 76 ms 17616 KB Output is correct
31 Correct 74 ms 17544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 604 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 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 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 77 ms 17652 KB Output is correct
18 Correct 79 ms 17852 KB Output is correct
19 Correct 75 ms 17488 KB Output is correct
20 Correct 73 ms 17488 KB Output is correct
21 Correct 80 ms 17488 KB Output is correct
22 Correct 76 ms 17432 KB Output is correct
23 Correct 82 ms 17800 KB Output is correct
24 Correct 81 ms 17556 KB Output is correct
25 Correct 74 ms 17692 KB Output is correct
26 Correct 76 ms 17488 KB Output is correct
27 Correct 82 ms 17940 KB Output is correct
28 Correct 77 ms 17492 KB Output is correct
29 Correct 75 ms 17620 KB Output is correct
30 Correct 76 ms 17616 KB Output is correct
31 Correct 74 ms 17544 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Output isn't correct
34 Halted 0 ms 0 KB -