답안 #240310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240310 2020-06-19T08:36:58 Z karma Swap (BOI16_swap) C++14
100 / 100
62 ms 7288 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = int(5e5) + 7;
const int logN = 18;
typedef pair<int, int> pii;

int n, a[N], b[N], can[N];

int get(int x) {
    for(int res = 1e9; ; x >>= 1) {
        if(can[x] != 1) res = min(res, a[x]);
        if(can[x] == 0) return res;
        if((x & 1) && can[x ^ 1]) {
            res = min(res, a[x ^ 1]);
            if(can[x ^ 1] == 1) return res;
        }
    }
    return 1e9;
}

void change(int x, int v) {
    for(;; x >>= 1) {
        if(a[x] == v) {
            can[x] = 0;
            return;
        }
        if(x & 1) {
            if(a[x ^ 1] == v) {
                can[x] = can[x ^ 1] = 1;
                return;
            } else can[x ^ 1] = 0;
        }
        can[x] = 1;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n; fill_n(a, N, 1e9);
    for(int i = 1; i <= n; ++i) cin >> a[i], can[i] = i == 1? 0: 2;
    for(int x, i = 1; i <= n; ++i) {
        b[i] = min({x = get(i), a[i << 1], a[i << 1 | 1]});
        if(b[i] == x) {
           change(i, x);
           can[i << 1] = can[i << 1 | 1] = 0;
        } else if(b[i] == a[i << 1]) can[i << 1] = 1, can[i << 1 | 1] = 0;
        else can[i << 1 | 1] = 1;
    }
    for(int i = 1; i <= n; ++i) cout << b[i] << ' ';
}

Compilation message

swap.cpp: In function 'int32_t main()':
swap.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
swap.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 6 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 6 ms 2304 KB Output is correct
6 Correct 6 ms 2304 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 6 ms 2304 KB Output is correct
9 Correct 6 ms 2304 KB Output is correct
10 Correct 6 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 6 ms 2304 KB Output is correct
6 Correct 6 ms 2304 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 6 ms 2304 KB Output is correct
9 Correct 6 ms 2304 KB Output is correct
10 Correct 6 ms 2304 KB Output is correct
11 Correct 6 ms 2304 KB Output is correct
12 Correct 6 ms 2336 KB Output is correct
13 Correct 6 ms 2304 KB Output is correct
14 Correct 6 ms 2304 KB Output is correct
15 Correct 6 ms 2304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 6 ms 2304 KB Output is correct
6 Correct 6 ms 2304 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 6 ms 2304 KB Output is correct
9 Correct 6 ms 2304 KB Output is correct
10 Correct 6 ms 2304 KB Output is correct
11 Correct 6 ms 2304 KB Output is correct
12 Correct 6 ms 2336 KB Output is correct
13 Correct 6 ms 2304 KB Output is correct
14 Correct 6 ms 2304 KB Output is correct
15 Correct 6 ms 2304 KB Output is correct
16 Correct 17 ms 3456 KB Output is correct
17 Correct 19 ms 3456 KB Output is correct
18 Correct 17 ms 3456 KB Output is correct
19 Correct 19 ms 3456 KB Output is correct
20 Correct 20 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2304 KB Output is correct
2 Correct 6 ms 2304 KB Output is correct
3 Correct 6 ms 2304 KB Output is correct
4 Correct 6 ms 2304 KB Output is correct
5 Correct 6 ms 2304 KB Output is correct
6 Correct 6 ms 2304 KB Output is correct
7 Correct 6 ms 2304 KB Output is correct
8 Correct 6 ms 2304 KB Output is correct
9 Correct 6 ms 2304 KB Output is correct
10 Correct 6 ms 2304 KB Output is correct
11 Correct 6 ms 2304 KB Output is correct
12 Correct 6 ms 2336 KB Output is correct
13 Correct 6 ms 2304 KB Output is correct
14 Correct 6 ms 2304 KB Output is correct
15 Correct 6 ms 2304 KB Output is correct
16 Correct 17 ms 3456 KB Output is correct
17 Correct 19 ms 3456 KB Output is correct
18 Correct 17 ms 3456 KB Output is correct
19 Correct 19 ms 3456 KB Output is correct
20 Correct 20 ms 3456 KB Output is correct
21 Correct 51 ms 7288 KB Output is correct
22 Correct 50 ms 7288 KB Output is correct
23 Correct 52 ms 7160 KB Output is correct
24 Correct 62 ms 7160 KB Output is correct
25 Correct 61 ms 7160 KB Output is correct