답안 #258577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258577 2020-08-06T07:24:01 Z 문홍윤(#5064) Swap (BOI16_swap) C++17
10 / 100
422 ms 360 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;
    }
    dfs(lv+1);
    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:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:60: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]);
                            ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 422 ms 360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 422 ms 360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 422 ms 360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 422 ms 360 KB Output isn't correct
7 Halted 0 ms 0 KB -