Submission #1048407

# Submission time Handle Problem Language Result Execution time Memory
1048407 2024-08-08T07:24:44 Z LittleOrange Ancient Books (IOI17_books) C++17
50 / 100
126 ms 101576 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct obj{
	ll i,w;
	bool operator<(const obj &o)const{
		return w>o.w;
	}
};
struct BIT{
	ll n;
	vector<ll> a;
	BIT(ll N):n(N),a(N+5,0){}
	void add(ll i, ll v){
		for(;i<=n;i+=i&-i) a[i] += v;
	}
	ll get(ll i){
		ll v = 0;
		for(;i>0;i-=i&-i) v += a[i];
		return v;
	}
};
long long minimum_walk(std::vector<int> p, int s) {
	ll ans = 0;
	ll n = p.size();
	/*
	if (s == 0){
		vector<ll> u(n,0);
		for(ll i = 0;i<n;i++){
			if(p[i]!=i){
				ans += i-s;
				s = i;
				ll x = i;
				do{
					ans += abs(p[x]-x);
					ll y = x;
					x = p[x];
					p[y] = y;
				} while(x!=i);
			}
		}
		ans += s;
	}*/
	ll gpc = 0;
	vector<ll> gp(n,-1);
	vector<ll> L,R;
	vector<vector<ll>> gps;
	for(ll i = 0;i<n;i++){
		if (gp[i]==-1){
			ll cur = gpc++;
			gps.emplace_back();
			L.push_back(n);
			R.push_back(0);
			ll x = i;
			do{
				L[cur] = min(x,L[cur]);
				R[cur] = max(x,R[cur]);
				gp[x] = cur;
				gps[cur].push_back(x);
				ans += abs(p[x]-x);
				x = p[x];
			} while(x!=i);
		}
	}/*
	for(ll i = 0;i<gpc;i++){
		cout << L[i] << "~" << R[i] << " " << gps[i].size() << endl;
	}*/
	/*
	vector<ll> cost(n,n);
	priority_queue<obj> q;
	q.push({s,0});
	vector<ll> vis(gpc,0);
	BIT t(n+5);
	while(!q.empty()){
		auto [i,w] = q.top();q.pop();
		if(t.get(i+1)) w = 0;
		if (cost[i]<=w) continue;
		cost[i] = w;
		ll l = n,r = 0;
		if (!vis[gp[i]]){
			vis[gp[i]] = 1;
			if (gps[gp[i]].size()>1) ans += cost[i]*2;
			for(ll j : gps[gp[i]]){
				q.push({j,0});
			}
			l = L[gp[i]];
			r = R[gp[i]];
			t.add(l+1,1);
			t.add(r+2,-1);
		}
		//cerr << i << " " << w << " " << l << " " << r << endl;
		if(i>0) q.push({i-1,w+1});
		if(i<n-1) q.push({i+1,w+1});
	}*/
	vector<ll> v(n,0);
	for(ll i : L) v[i]++;
	for(ll i : R) v[i]--;
	for(ll i = 1;i<n;i++) v[i] += v[i-1];
	ll rf = n-1;
	while(rf&&p[rf]==rf) rf--;
	for(ll i = 0;i<rf;i++) if(!v[i]) ans += 2;
	return ans;
}
# 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 348 KB Output is correct
4 Correct 0 ms 596 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 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 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 348 KB Output is correct
4 Correct 0 ms 596 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 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 432 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 436 KB Output is correct
29 Correct 0 ms 348 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 348 KB Output is correct
4 Correct 0 ms 596 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 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 432 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 436 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 79 ms 40892 KB Output is correct
31 Correct 79 ms 41408 KB Output is correct
32 Correct 126 ms 101576 KB Output is correct
33 Correct 107 ms 88328 KB Output is correct
34 Correct 106 ms 90096 KB Output is correct
35 Correct 121 ms 82920 KB Output is correct
36 Correct 102 ms 55596 KB Output is correct
37 Correct 68 ms 43684 KB Output is correct
38 Correct 66 ms 41552 KB Output is correct
39 Correct 70 ms 41296 KB Output is correct
40 Correct 67 ms 39884 KB Output is correct
41 Correct 78 ms 40064 KB Output is correct
42 Correct 98 ms 39524 KB Output is correct
43 Correct 112 ms 90136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 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 348 KB Output is correct
4 Correct 0 ms 596 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 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 432 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 436 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 79 ms 40892 KB Output is correct
31 Correct 79 ms 41408 KB Output is correct
32 Correct 126 ms 101576 KB Output is correct
33 Correct 107 ms 88328 KB Output is correct
34 Correct 106 ms 90096 KB Output is correct
35 Correct 121 ms 82920 KB Output is correct
36 Correct 102 ms 55596 KB Output is correct
37 Correct 68 ms 43684 KB Output is correct
38 Correct 66 ms 41552 KB Output is correct
39 Correct 70 ms 41296 KB Output is correct
40 Correct 67 ms 39884 KB Output is correct
41 Correct 78 ms 40064 KB Output is correct
42 Correct 98 ms 39524 KB Output is correct
43 Correct 112 ms 90136 KB Output is correct
44 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -