Submission #693024

#TimeUsernameProblemLanguageResultExecution timeMemory
693024whqkrtk04Ancient Books (IOI17_books)C++17
12 / 100
2 ms300 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; #define fi first #define se second const int INF = 1e9+1; const int P = 1000000007; const ll LLINF = (ll)1e18+1; template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; } void f(int i, int j, bool &x, int &idx) { if(x) return; if(i != j) { idx = i; x = true; } } ll minimum_walk(vector<int> p, int s) { int idx = s, hand = p[s]; ll ans = 0LL; do { int tmp = hand; if(tmp == s) { bool x = false; if(idx > s) { for(int i = idx-1; i > s; i--) f(i, p[i], x, tmp); for(int i = idx+1; i < p.size(); i++) f(i, p[i], x, tmp); for(int i = s-1; i >= 0; i--) f(i, p[i], x, tmp); } else { for(int i = idx+1; i < s; i++) f(i, p[i], x, tmp); for(int i = idx-1; i >= 0; i--) f(i, p[i], x, tmp); for(int i = s+1; i < p.size(); i++) f(i, p[i], x, tmp); } } swap(p[tmp], hand); ans += abs(idx-tmp); idx = tmp; } while(idx != s); return ans; }

Compilation message (stderr)

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = idx+1; i < p.size(); i++) f(i, p[i], x, tmp);
      |                        ~~^~~~~~~~~~
books.cpp:41:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = s+1; i < p.size(); i++) f(i, p[i], x, tmp);
      |                      ~~^~~~~~~~~~
#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...