# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258553 | 2020-08-06T06:13:49 Z | 반딧불(#5073) | Swap (BOI16_swap) | C++17 | 0 ms | 256 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int arr[200002]; vector<int> ans; bool cmp(vector<int> s, vector<int> t){ for(int i=0; i<n; i++){ if(s[i] < t[i]) return true; if(s[i] > t[i]) return false; } return false; } void dfs(int i){ if(i==n+1){ if(ans.empty()) ans = vector<int> (arr+1, arr+n+1); else if(cmp(vector<int> (arr+1, arr+n+1), ans)) ans = vector<int> (arr+1, arr+n+1); return; } if(i==n){ bool swp = 0; if(arr[i/2] > arr[i]) swap(arr[i/2], arr[i]), swp = 1; dfs(i+1); if(swp) swap(arr[i/2], arr[i]); return; } int tmin = min({arr[i/2], arr[i], arr[i+1]}); if(tmin == arr[i/2]) dfs(i+2); else if(tmin == arr[i]){ swap(arr[i/2], arr[i]); dfs(i+2); swap(arr[i/2], arr[i]); } else{ swap(arr[i/2], arr[i+1]); dfs(i+2); swap(arr[i], arr[i+1]); dfs(i+2); swap(arr[i/2], arr[i]); } } int main(){ scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &arr[i]); dfs(2); for(auto &x: ans) printf("%d ", x); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |