답안 #258583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258583 2020-08-06T07:34:50 Z 문홍윤(#5064) Swap (BOI16_swap) C++17
21 / 100
1000 ms 356 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[50], nw[50];
int n;

void dfs(int lv){
    if(2*lv>n){
        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;
    }
    int tmp=min(nw[2*lv], nw[2*lv+1]);
    if(tmp==nw[2*lv]){
        swap(nw[lv], nw[2*lv]);
        dfs(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]);
    }
    else{
        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]);
        swap(nw[lv], nw[2*lv+1]);
        dfs(lv+1);
        swap(nw[lv], nw[2*lv+1]);
    }
}

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:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:67: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 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 25 ms 356 KB Output is correct
10 Correct 10 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 25 ms 356 KB Output is correct
10 Correct 10 ms 256 KB Output is correct
11 Execution timed out 1083 ms 256 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 25 ms 356 KB Output is correct
10 Correct 10 ms 256 KB Output is correct
11 Execution timed out 1083 ms 256 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 25 ms 356 KB Output is correct
10 Correct 10 ms 256 KB Output is correct
11 Execution timed out 1083 ms 256 KB Time limit exceeded
12 Halted 0 ms 0 KB -