제출 #297019

#제출 시각아이디문제언어결과실행 시간메모리
297019TricksterAncient Books (IOI17_books)C++14
0 / 100
1 ms360 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 <int, int> #define sz(a) int(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;} int n; long long minimum_walk(std::vector<int> p, int s) { n = p.size(); int x = s, y = -1, ans = 0; for(int i = 0; i < n; i++) { if(y <= i && y != -1) { ans += abs(x-y); int a = p[x], b = y; y = a, p[x] = b, x = b; } 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...