답안 #258600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258600 2020-08-06T08:13:42 Z 반딧불(#5073) Swap (BOI16_swap) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int arr[1000002];

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
    for(int i=n+1; i<=5*n; i++) arr[i] = i;
    for(int i=2; i<=n; i+=2){
        if(i==n){
            if(arr[i/2] > arr[i]) swap(arr[i/2], arr[i]);
        }
        else{
            int tmin = min({arr[i/2], arr[i], arr[i+1]});
            if(tmin == arr[i/2]) continue;
            else if(tmin == arr[i]) swap(arr[i/2], arr[i]);
            else{
                if(arr[i] > arr[i/2]) swap(arr[i], arr[i/2]);

                if(arr[i*2] > arr[i] && arr[i*2+1] > arr[i]){
                    swap(arr[i/2], arr[i+1]);
                }
                else if(arr[i*2+2] > arr[i/2] && arr[i*2+3] > arr[i/2]){
                    swap(arr[i/2], arr[i]);
                    swap(arr[i/2], arr[i+1]);
                }
                else{
                    swap(arr[i/2], arr[i+1]);
                }
            }
        }
    }
    for(int i=1; i<=n; i++) printf("%d ", arr[i]);
}

Compilation message

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