# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1173945 | 12345678 | Swap (BOI16_swap) | C++20 | 12 ms | 12104 KiB |
#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, a[nx], lvl[nx];
map<int, int> dp[nx];
int getdp(int u, int vl)
{
if (dp[u].find(vl)!=dp[u].end()) return dp[u][vl];
if (2*u>n) return dp[u][vl]=lvl[u];
if (2*u==n)
{
if (a[u]<a[2*u]) return dp[u][vl]=lvl[u];
else return dp[u][vl]=lvl[u]+1;
}
int mn=min({vl, a[2*u], a[2*u+1]});
if (vl==mn) return dp[u][vl]=lvl[u];
else if (a[2*u]==mn) return dp[u][vl]=getdp(2*u, vl);
else
{
if (vl<a[2*u])
{
if (getdp(2*u, vl)<=getdp(2*u+1, vl)) return dp[u][vl]=getdp(2*u, vl);
else return dp[u][vl]=getdp(2*u+1, vl);
}
else
{
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |