Submission #421525

#TimeUsernameProblemLanguageResultExecution timeMemory
421525Knps4422고대 책들 (IOI17_books)C++14
50 / 100
2068 ms15940 KiB
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(int x = 1 ; x <= (int)y ; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
 
using namespace std;
 
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll,ll> pll;
typedef complex<int> point;
const int nmax = 2005;
const ll linf = 1e18;
const ll mod = 998244353;
const int inf = 1e9+10;
const int sq = 5000;

ll minimum_walk(vec <int> p , int s){
	int n = p.size();
	ll rs = 0;
	int limit = 0;
	for(int i = 0; i < p.size(); i++){
		rs += abs(p[i] - i);
		if(p[i] != i)limit = i;
	}
	vec <int> viz (n), maxi(n);
	for(int i = 0; i < p.size(); i++){
		if(viz[i] == 0){
			viz[i] = 1;
			int q = p[i] , mx = i;
			while(q != i){
				mx = max(mx,q);
				viz[q] = 1;
				q = p[q];
			}
			maxi[i] = mx;
		}
	}
	int q = s , lq = maxi[s];
	while(q < limit){
		while(q < lq){
			q++;
			lq = max(lq,maxi[q]);
		}
		if(q == lq && q != limit){
			rs += 2;
			q++;
			lq = max(lq,maxi[q]);
		}

	}
	return rs;
}

Compilation message (stderr)

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i = 0; i < p.size(); i++){
      |                 ~~^~~~~~~~~~
books.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i = 0; i < p.size(); i++){
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...