Submission #612413

#TimeUsernameProblemLanguageResultExecution timeMemory
612413cheissmartGiraffes (JOI22_giraffes)C++14
10 / 100
1885 ms1048576 KiB
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(v) int((v).size()) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m"; void DBG() { cerr << "]" << _reset << endl; } template<class H, class...T> void DBG(H h, T ...t) { cerr << to_string(h); if(sizeof ...(t)) cerr << ", "; DBG(t...); } #ifdef CHEISSMART #define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define debug(...) #endif const int INF = 1e9 + 7; signed main() { IO_OP; int n; cin >> n; vi p(n); for(int i = 0; i < n; i++) { cin >> p[i]; p[i]--; } int ans = INF; auto go = [&] (vi q) { vi iq(n); for(int i = 0; i < n; i++) iq[q[i]] = i; vi pp; for(int i:p) pp.PB(iq[i]); int tt = 0; for(int i = 0; i < n; i++) { if(pp[i] != i) { tt++; } } ans = min(ans, tt); }; auto ok = [&] (vi a) { int l = 0, r = n - 1, lb = 0, rb = n - 1; while(r - l + 1 >= 4) { if(a[l] != lb && a[l] != rb && a[r] != lb && a[r] != rb) return false; if(a[l] == lb) l++, lb++; else if(a[l] == rb) l++, rb--; else if(a[r] == lb) r--, lb++; else r--, rb--; } return true; }; V<V<vi>> dp(n, V<vi>()); dp[0].PB(vi{0}); for(int len = 1; len < n; len++) { for(vi q:dp[len - 1]) { { vi qq = q; qq.PB(len); dp[len].PB(qq); } { vi qq = q; qq.insert(qq.begin(), len); dp[len].PB(qq); } } for(vi q:dp[len - 1]) { for(int&e:q) e++; { vi qq = q; qq.PB(0); dp[len].PB(qq); } { vi qq = q; qq.insert(qq.begin(), 0); dp[len].PB(qq); } } } for(vi q:dp[n - 1]) go(q); cout << ans << '\n'; }

Compilation message (stderr)

giraffes.cpp: In function 'int main()':
giraffes.cpp:62:7: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   62 |  auto ok = [&] (vi a) {
      |       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...