답안 #258553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258553 2020-08-06T06:13:49 Z 반딧불(#5073) Swap (BOI16_swap) C++17
0 / 100
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

swap.cpp: In function 'int main()':
swap.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:52:34: 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", &arr[i]);
                             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -