제출 #297028

#제출 시각아이디문제언어결과실행 시간메모리
297028Trickster고대 책들 (IOI17_books)C++14
0 / 100
1 ms256 KiB
#include "books.h" #include <algorithm> #include <string.h> #include <iostream> #include <stdio.h> #include <vector> #include <queue> #include <cmath> #include <set> #include <map> using namespace std; #define N 100 #define ff first #define ss second #define ll long long #define pb push_back #define mod 1000000007 #define pii pair <ll, ll> #define sz(a) ll(a.size()) // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;} ll n; long long minimum_walk(vector<int> p, int s) { n = p.size(); int x = s, y = -1; ll ans = 0; for(ll i = 0; i < n; i++) { if(y <= i && y != -1) { ans += abs(x-y); x = y; swap(p[y], y); } if(i == n-1) { ans += abs(x); break; } ans += abs(i+1-x); if(y == -1 && p[x] != i) { y = p[x]; swap(p[x], p[i+1]); p[x] = -1; } else swap(y, p[i+1]); x = i+1; } return ans; }
#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...