답안 #141056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141056 2019-08-06T12:37:17 Z meatrow Xylophone (JOI18_xylophone) C++17
47 / 100
114 ms 444 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

using ll = long long;
using ld = long double;

const int N = 5000;

int a[N];
int b[N];
/*
int query(int l, int r) {
    return *max_element(b + l - 1, b + r) - *min_element(b + l - 1, b + r);
}
*/
void solve(int n) {
    int l = 1, r = n;
    while (l + 1 < r) {
        int mid = (l + r) / 2;
        int t = query(1, mid);
        if (t == n - 1) {
            r = mid;
        } else {
            l = mid;
        }
    }
    a[r] = n;
    for (int i = r + 1; i <= n; i++) {
        int t = query(i - 1, i);
        if (a[i - 1] + t >= n) {
            a[i] = a[i - 1] - t;
            continue;
        }
        if (a[i - 1] - t < 1) {
            a[i] = a[i - 1] + t;
            continue;
        }
        int u = query(i - 2, i);
        if (u == abs(a[i - 2] - a[i - 1])) {
            if (a[i - 2] < a[i - 1]) {
                a[i] = a[i - 1] - t;
            } else {
                a[i] = a[i - 1] + t;
            }
            continue;
        }
        if (u != t) {
            int cand = a[i - 2] + u;
            if (cand == a[i - 1] - t || cand == a[i - 1] + t) {
                a[i] = cand;
            } else {
                a[i] = cand - 2 * u;
            }
            continue;
        }
        if (a[i - 2] < a[i - 1]) {
            a[i] = a[i - 1] - t;
        } else {
            a[i] = a[i - 1] + t;
        }
    }
    for (int i = r - 1; i >= 1; i--) {
        int t = query(i, i + 1);
        if (a[i + 1] + t >= n) {
            a[i] = a[i + 1] - t;
            continue;
        }
        if (a[i + 1] - t < 1) {
            a[i] = a[i + 1] + t;
            continue;
        }
        int u = query(i, i + 2);
        if (u == abs(a[i + 2] - a[i + 1])) {
            if (a[i + 2] < a[i + 1]) {
                a[i] = a[i + 1] - t;
            } else {
                a[i] = a[i + 1] + t;
            }
            continue;
        }
        if (u != t) {
            int cand = a[i + 2] + u;
            if (cand == a[i + 1] - t || cand == a[i + 1] + t) {
                a[i] = cand;
            } else {
                a[i] = cand - 2 * u;
            }
            continue;
        }
        if (a[i + 2] < a[i + 1]) {
            a[i] = a[i + 1] - t;
        } else {
            a[i] = a[i + 1] + t;
        }
    }
    for (int i = 1; i <= n; i++) {
        answer(i, a[i]);
    }
}

/*int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    iota(b, b + n, 1);
    random_shuffle(b, b + n);
    for (int i = 0; i < n; i++) {
        cout << b[i] << " \n"[i + 1 == n];
    }
    solve(n);
    return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 320 KB Output is correct
4 Correct 3 ms 316 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 316 KB Output is correct
7 Correct 3 ms 252 KB Output is correct
8 Correct 4 ms 248 KB Output is correct
9 Correct 3 ms 252 KB Output is correct
10 Correct 3 ms 420 KB Output is correct
11 Correct 4 ms 248 KB Output is correct
12 Correct 4 ms 324 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 248 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 320 KB Output is correct
4 Correct 3 ms 316 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 316 KB Output is correct
7 Correct 3 ms 252 KB Output is correct
8 Correct 4 ms 248 KB Output is correct
9 Correct 3 ms 252 KB Output is correct
10 Correct 3 ms 420 KB Output is correct
11 Correct 4 ms 248 KB Output is correct
12 Correct 4 ms 324 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 248 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 14 ms 376 KB Output is correct
18 Correct 16 ms 320 KB Output is correct
19 Correct 18 ms 248 KB Output is correct
20 Correct 12 ms 336 KB Output is correct
21 Correct 10 ms 316 KB Output is correct
22 Correct 16 ms 248 KB Output is correct
23 Correct 13 ms 320 KB Output is correct
24 Correct 15 ms 444 KB Output is correct
25 Correct 10 ms 316 KB Output is correct
26 Correct 12 ms 320 KB Output is correct
27 Correct 12 ms 312 KB Output is correct
28 Correct 10 ms 380 KB Output is correct
29 Correct 13 ms 316 KB Output is correct
30 Correct 18 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 3 ms 320 KB Output is correct
4 Correct 3 ms 316 KB Output is correct
5 Correct 3 ms 312 KB Output is correct
6 Correct 3 ms 316 KB Output is correct
7 Correct 3 ms 252 KB Output is correct
8 Correct 4 ms 248 KB Output is correct
9 Correct 3 ms 252 KB Output is correct
10 Correct 3 ms 420 KB Output is correct
11 Correct 4 ms 248 KB Output is correct
12 Correct 4 ms 324 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 248 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 14 ms 376 KB Output is correct
18 Correct 16 ms 320 KB Output is correct
19 Correct 18 ms 248 KB Output is correct
20 Correct 12 ms 336 KB Output is correct
21 Correct 10 ms 316 KB Output is correct
22 Correct 16 ms 248 KB Output is correct
23 Correct 13 ms 320 KB Output is correct
24 Correct 15 ms 444 KB Output is correct
25 Correct 10 ms 316 KB Output is correct
26 Correct 12 ms 320 KB Output is correct
27 Correct 12 ms 312 KB Output is correct
28 Correct 10 ms 380 KB Output is correct
29 Correct 13 ms 316 KB Output is correct
30 Correct 18 ms 316 KB Output is correct
31 Correct 26 ms 320 KB Output is correct
32 Correct 52 ms 332 KB Output is correct
33 Correct 47 ms 328 KB Output is correct
34 Correct 83 ms 336 KB Output is correct
35 Correct 48 ms 416 KB Output is correct
36 Incorrect 114 ms 332 KB Wrong Answer [2]
37 Halted 0 ms 0 KB -