Submission #258574

# Submission time Handle Problem Language Result Execution time Memory
258574 2020-08-06T07:22:58 Z 문홍윤(#5064) Swap (BOI16_swap) C++17
10 / 100
1 ms 256 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;

int ans[30], nw[30];
int n;

void dfs(int lv){
    if(lv>n/2){
        bool flg=false;
        for(int i=1; i<=n; i++){
            if(nw[i]<ans[i]){
                flg=true;
                break;
            }
            if(nw[i]>ans[i])break;
        }
        if(flg){
            for(int i=1; i<=n; i++)ans[i]=nw[i];
        }
        return;
    }
    if(nw[lv]<nw[2*lv]&&nw[lv]<nw[2*lv+1]){
        dfs(lv+1);
        return;
    }
    if(nw[lv]>nw[2*lv]){
        swap(nw[lv], nw[2*lv]);
        dfs(lv+1);
        swap(nw[lv], nw[2*lv]);
    }
    if(nw[lv]>nw[2*lv+1]){
        swap(nw[lv], nw[2*lv+1]);
        dfs(lv+1);
        swap(nw[lv], nw[2*lv+1]);
    }
    swap(nw[lv], nw[2*lv]);
    swap(nw[lv], nw[2*lv+1]);
    dfs(lv+1);
    swap(nw[lv], nw[2*lv+1]);
    swap(nw[lv], nw[2*lv]);
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++)scanf("%d", &nw[i]);
    for(int i=1; i<=n; i++)ans[i]=nw[i];
    nw[n+1]=inf;
    dfs(1);
    for(int i=1; i<=n; i++)printf("%d ", ans[i]);
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:63:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=n; i++)scanf("%d", &nw[i]);
                            ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 1 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 1 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 1 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Incorrect 1 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -