답안 #135036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135036 2019-07-23T14:48:00 Z osaaateiasavtnl Xylophone (JOI18_xylophone) C++14
100 / 100
284 ms 644 KB
#include<bits/stdc++.h>
using namespace std;
#ifdef HOME
#else
#include "xylophone.h"
#endif

const int N = 5001;

#ifdef HOME
const int INF = 1e9 + 7;
int n;
int a[N];
int query(int l, int r) {
    int mn = INF, mx = -INF;
    for (int i = l; i <= r; ++i) {
        mn = min(mn, a[i]);
        mx = max(mx, a[i]);
    }   
    return mx - mn;
}   
void answer(int i, int x) {

}   
#endif

int ans[N];
int mem[2][N];
bool t[N], r[N];
int cnt[N];
bool check(int n) {
    for (int i = 1; i <= n; ++i) {
        if (ans[i] < 1 || ans[i] > n) return 0;
    }   
    for (int i = 1; i <= n; ++i) {
        cnt[i] = 0;
    }   
    for (int i = 1; i <= n; ++i) {
        ++cnt[ans[i]];
    }   
    for (int i = 1; i <= n; ++i) {
        if (cnt[i] != 1) {
            return 0;
        }
    }   
    int p1, pn;
    for (int i = 1; i <= n; ++i) {
        if (ans[i] == 1) p1 = i;
        if (ans[i] == n) pn = i;
    }   
    if (pn < p1) return 0;
    return 1;
}   
void solve(int n) {
    for (int i = 1; i + 1 <= n; ++i) {
        mem[0][i] = query(i, i + 1);
    }           
    for (int i = 1; i + 2 <= n; ++i) {
        mem[1][i] = query(i, i + 2);
    }   
    for (int i = 1; i + 2 <= n; ++i) {
        t[i + 2] = (mem[0][i] + mem[0][i + 1]) != mem[1][i];
    }   
    for (int i = 1; i <= n; ++i) {
        r[i] = r[i - 1] ^ t[i];
    }
    #ifdef HOME
    for (int i = 1; i <= n; ++i) {
        cout << r[i] << ' ';
    }   
    cout << '\n';
    #endif
    for (int f = 1; f <= n; ++f) {
        ans[1] = f;
        for (int i = 2; i <= n; ++i) {
            if (r[i]) {
                ans[i] = ans[i - 1] + mem[0][i - 1];
            }   
            else {
                ans[i] = ans[i - 1] - mem[0][i - 1];
            }   
        }   
        if (check(n)) {
            for (int i = 1; i <= n; ++i) {
                answer(i, ans[i]);
            }   
            return;
        }   
        ans[1] = f;
        for (int i = 2; i <= n; ++i) {
            if (r[i]) {
                ans[i] = ans[i - 1] - mem[0][i - 1];
            }   
            else {
                ans[i] = ans[i - 1] + mem[0][i - 1];
            }   
        }   
        if (check(n)) {
            for (int i = 1; i <= n; ++i) {
                answer(i, ans[i]);
            }   
            return;
        }   
    }
}   
#ifdef HOME
signed main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }   
    solve(n);
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << ' ';
    }   
    cout << '\n';
}   
#endif

Compilation message

xylophone.cpp: In function 'bool check(int)':
xylophone.cpp:51:5: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (pn < p1) return 0;
     ^~
xylophone.cpp:51:5: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 248 KB Output is correct
5 Correct 3 ms 248 KB Output is correct
6 Correct 4 ms 248 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 3 ms 320 KB Output is correct
9 Correct 4 ms 248 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 4 ms 248 KB Output is correct
13 Correct 3 ms 320 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 3 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 248 KB Output is correct
5 Correct 3 ms 248 KB Output is correct
6 Correct 4 ms 248 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 3 ms 320 KB Output is correct
9 Correct 4 ms 248 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 4 ms 248 KB Output is correct
13 Correct 3 ms 320 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 3 ms 408 KB Output is correct
16 Correct 7 ms 248 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 19 ms 452 KB Output is correct
19 Correct 33 ms 420 KB Output is correct
20 Correct 25 ms 324 KB Output is correct
21 Correct 27 ms 328 KB Output is correct
22 Correct 28 ms 248 KB Output is correct
23 Correct 23 ms 248 KB Output is correct
24 Correct 21 ms 320 KB Output is correct
25 Correct 23 ms 376 KB Output is correct
26 Correct 17 ms 404 KB Output is correct
27 Correct 14 ms 400 KB Output is correct
28 Correct 14 ms 400 KB Output is correct
29 Correct 29 ms 328 KB Output is correct
30 Correct 25 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 248 KB Output is correct
5 Correct 3 ms 248 KB Output is correct
6 Correct 4 ms 248 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 3 ms 320 KB Output is correct
9 Correct 4 ms 248 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 4 ms 248 KB Output is correct
13 Correct 3 ms 320 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 3 ms 408 KB Output is correct
16 Correct 7 ms 248 KB Output is correct
17 Correct 9 ms 376 KB Output is correct
18 Correct 19 ms 452 KB Output is correct
19 Correct 33 ms 420 KB Output is correct
20 Correct 25 ms 324 KB Output is correct
21 Correct 27 ms 328 KB Output is correct
22 Correct 28 ms 248 KB Output is correct
23 Correct 23 ms 248 KB Output is correct
24 Correct 21 ms 320 KB Output is correct
25 Correct 23 ms 376 KB Output is correct
26 Correct 17 ms 404 KB Output is correct
27 Correct 14 ms 400 KB Output is correct
28 Correct 14 ms 400 KB Output is correct
29 Correct 29 ms 328 KB Output is correct
30 Correct 25 ms 376 KB Output is correct
31 Correct 54 ms 336 KB Output is correct
32 Correct 131 ms 516 KB Output is correct
33 Correct 157 ms 340 KB Output is correct
34 Correct 179 ms 452 KB Output is correct
35 Correct 186 ms 320 KB Output is correct
36 Correct 100 ms 340 KB Output is correct
37 Correct 161 ms 512 KB Output is correct
38 Correct 54 ms 452 KB Output is correct
39 Correct 117 ms 352 KB Output is correct
40 Correct 180 ms 408 KB Output is correct
41 Correct 217 ms 388 KB Output is correct
42 Correct 101 ms 376 KB Output is correct
43 Correct 153 ms 400 KB Output is correct
44 Correct 54 ms 472 KB Output is correct
45 Correct 144 ms 424 KB Output is correct
46 Correct 224 ms 404 KB Output is correct
47 Correct 183 ms 404 KB Output is correct
48 Correct 115 ms 376 KB Output is correct
49 Correct 181 ms 448 KB Output is correct
50 Correct 193 ms 376 KB Output is correct
51 Correct 159 ms 448 KB Output is correct
52 Correct 129 ms 376 KB Output is correct
53 Correct 271 ms 452 KB Output is correct
54 Correct 228 ms 516 KB Output is correct
55 Correct 272 ms 344 KB Output is correct
56 Correct 284 ms 644 KB Output is correct
57 Correct 252 ms 456 KB Output is correct
58 Correct 267 ms 488 KB Output is correct
59 Correct 218 ms 376 KB Output is correct
60 Correct 198 ms 436 KB Output is correct