Submission #258591

# Submission time Handle Problem Language Result Execution time Memory
258591 2020-08-06T07:50:11 Z 반딧불(#5073) Swap (BOI16_swap) C++17
21 / 100
1000 ms 384 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], arr[i+1]);
        swap(arr[i/2], arr[i+1]);
    }
}

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:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
swap.cpp:53: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]);
                             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 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 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 21 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 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 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 21 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Execution timed out 1094 ms 384 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 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 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 21 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Execution timed out 1094 ms 384 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 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 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 21 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Execution timed out 1094 ms 384 KB Time limit exceeded
12 Halted 0 ms 0 KB -