Submission #581879

# Submission time Handle Problem Language Result Execution time Memory
581879 2022-06-23T07:39:54 Z Koosha_mv Ancient Books (IOI17_books) C++14
0 / 100
96 ms 127392 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
 
const int N=2e6+99;
const ll inf=1e15;
 
ll minimum_walk(vector<int> p, int s){
	int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
	ll Max[N],dist[N],dp[N][N];
	queue<int> q;
	vector<int> vec;
	vector<pair<int,int>> g[N];
	ll sum=0,ans=0;
	n=p.size();
	int l=n,r=0;
	f(i,0,n){
		sum+=abs(p[i]-i);
		if(p[i]!=i) minm(l,i),maxm(r,i);
	}
	minm(l,s);
	maxm(r,s);
	if(l==r) return 0;
	f(i,l,r+1) vec.pb(p[i]-l);
	p=vec;
	n=p.size();
	int mx=0;
	f(i,0,s){
		maxm(mx,p[i]);
		if(mx==i){
			ans+=2;
			l=i+1;
		}
	}
	int mn=n;
	f_(i,n-1,s+1){
		minm(mn,p[i]);
		if(mn==i){
			ans+=2;
			r=i-1;
		}
	}
	if(l==r) return 0;
	vec.clear();
	f(i,l,r+1) vec.pb(p[i]-l);
	p=vec;
	n=p.size();
	f(i,0,n){
		g[i].pb({p[i],0});
	}
	f_(i,s,1){
		g[i].pb({i-1,1});
		g[i-1].pb({i,0});
	}
	f(i,s,n-1){
		g[i].pb({i+1,1});
		g[i+1].pb({i-1,0});
	}
	q.push(s);
	f(i,0,n) dist[i]=(i==s ? 0 : N);
	while(q.size()){
		int u=q.front();
		q.pop();
		for(auto [v,w] : g[u]){
			if(dist[u]+w<dist[v]){
				dist[v]=dist[u]+w;
				q.push(v);
			}
		}
	}
	cout<<ans+2ll*dist[0];
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:83:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   83 |   for(auto [v,w] : g[u]){
      |            ^
books.cpp:28:8: warning: unused variable 'vis' [-Wunused-variable]
   28 |  int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
      |        ^~~
books.cpp:28:15: warning: unused variable 'mx1' [-Wunused-variable]
   28 |  int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
      |               ^~~
books.cpp:28:22: warning: unused variable 'mx2' [-Wunused-variable]
   28 |  int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
      |                      ^~~
books.cpp:28:29: warning: unused variable 'mn1' [-Wunused-variable]
   28 |  int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
      |                             ^~~
books.cpp:28:36: warning: unused variable 'mn2' [-Wunused-variable]
   28 |  int n,vis[N],mx1[N],mx2[N],mn1[N],mn2[N];
      |                                    ^~~
books.cpp:29:5: warning: unused variable 'Max' [-Wunused-variable]
   29 |  ll Max[N],dist[N],dp[N][N];
      |     ^~~
books.cpp:29:20: warning: unused variable 'dp' [-Wunused-variable]
   29 |  ll Max[N],dist[N],dp[N][N];
      |                    ^~
books.cpp:30:13: warning: control reaches end of non-void function [-Wreturn-type]
   30 |  queue<int> q;
      |             ^
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 62900 KB 3rd lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 62900 KB 3rd lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 62900 KB 3rd lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 96 ms 127392 KB Execution killed with signal 7
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 62900 KB 3rd lines differ - on the 1st token, expected: '6', found: '0'
2 Halted 0 ms 0 KB -