제출 #296724

#제출 시각아이디문제언어결과실행 시간메모리
296724dandrozavr고대 책들 (IOI17_books)C++14
0 / 100
2 ms512 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ld long double #define fi first #define se second #define F first #define S second #define pii pair < int , int > #define _ <<" "<< #define TIME 1.0 * clock() / CLOCKS_PER_SEC vector < int > a; int S, n; map < vector < int > , int > mp[30]; int brute(vector < int > p, int s){ if (mp[s].count(p)) return mp[s][p]; mp[s][p] = 1e7; bool bad = 0; for (int i = 0; i < n; ++i) if (p[i] != i){ bad = 1; break; } if (!bad){ mp[s][p] = abs(s - S); return abs(s - S); } int pos = -1; bool byl[n] = {}; for (int i = 0; i < n; ++i) if (p[i] != n) byl[p[i]] = 1; for (int i = 0; i < n; ++i) if (!byl[i]){ pos = i; break; } int ans = 1e7; // for (int i : p) cout << i << " "; cout << endl; for (int i = 0; i < n; ++i){ int dist = abs(i - s); ans = min(ans, dist + brute(p, i)); } if (pos == -1){ for (int i = 0; i < n; ++i){ int dist = abs(s - i); int temp = p[i]; p[i] = p[s]; p[s] = n; ans = min(ans, dist + brute(p, i)); p[s] = p[i]; p[i] = temp; } } if (pos != -1){ for (int i = 0; i < n; ++i) if (p[i] != n){ int dist = abs(s - i); int temp = p[i]; p[i] = pos; ans = min(ans, dist + brute(p, i)); p[i] = temp; } else { p[i] = pos; int dist = abs(i - s); ans = min(ans, dist + brute(p, i)); p[i] = n; } } // if (p[0] == 0 && p[1] == 2 && p[2] == 2 && p[3] == ){ // for (int i : p) cout << i << " "; // cout << endl; // cout << s _ ans _ pos << endl << endl; // } mp[s][p] = ans; return ans; } long long minimum_walk(std::vector<int> p, int s) { S = s; a = p; n = p.size(); if (n <= 4) return brute(p, s); }

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

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
   90 | }
      | ^
#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...