제출 #318601

#제출 시각아이디문제언어결과실행 시간메모리
318601Lemur95고대 책들 (IOI17_books)C++17
42 / 100
1505 ms1048576 KiB
#include <bits/stdc++.h> #include "books.h" #pragma GCC optimize("Ofast") #define x first #define y second #define ld long double #define ll long long using namespace std; int n, s, x; map <pair <int, int>, int> calc; void f(int &l, int &r, vector <int> L, vector <int> R, vector <int> cyc) { int st = min(l, min(L[cyc[l]], L[cyc[r]])), dr = max(r, max(R[cyc[l]], R[cyc[r]])); while(st < l || r < dr) { if(st < l) { l--; st = min(st, L[cyc[l]]); dr = max(dr, R[cyc[l]]); } else { r++; st = min(st, L[cyc[r]]); dr = max(dr, R[cyc[r]]); } } } int dp(int l, int r, vector <int> L, vector <int> R, vector <int> cyc) { f(l, r, L, R, cyc); if(calc.find({l, r}) != calc.end()) return calc[{l, r}]; int ans = (int)1e9; int st, dr; if(l) { st = l - 1; dr = r; f(st, dr, L, R, cyc); ans = 2 + dp(st, dr, L, R, cyc); } if(r < cyc.size() - 1) { st = l; dr = r + 1; f(st, dr, L, R, cyc); ans = min(ans, 2 + dp(st, dr, L, R, cyc)); } calc[{l, r}] = ans; return ans; } ll minimum_walk(vector <int> p, int s) { ll ans = 0; int n = p.size(), c = 0, st = s, dr = s; vector <int> cyc(n + 5, -1), l(n + 5), r(n + 5); for(int i = 0; i < n; i++) { ans += abs(i - p[i]); if(cyc[i] == -1) { l[c] = r[c] = i; int j = i; while(cyc[j] == -1) { cyc[j] = c; r[c] = max(r[c], j); j = p[j]; } if(i != p[i]) { st = min(st, l[c]); dr = max(dr, r[c]); } c++; } } calc[{st, dr}] = 0; return ans + dp(s, s, l, r, cyc); } /*int main() { //ios_base :: sync_with_stdio(false); //cin.tie(0); cout.tie(0); cin >> n >> s; vector <int> p; for(int i = 1; i <= n; i++) cin >> x, p.push_back(x); cout << minimum_walk(p, s); return 0; } */

컴파일 시 표준 에러 (stderr) 메시지

books.cpp: In function 'int dp(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
books.cpp:41:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   if(r < cyc.size() - 1) {
      |      ~~^~~~~~~~~~~~~~~~
#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...