답안 #860891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860891 2023-10-14T18:15:08 Z vjudge1 Xylophone (JOI18_xylophone) C++17
47 / 100
79 ms 98580 KB
#include <bits/stdc++.h>
#include "xylophone.h"

#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

void setIO() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int dp[5001][5001];

int ask(int l, int r) {
    if(dp[l][r] != -1) return dp[l][r];
    return dp[l][r] = query(l, r);
}

void solve(int n) {
    memset(dp, -1, sizeof(dp));

    int l=1, r=n;
    int p1 = 0;

    while(l <= r) {
        int mid = (l + r) / 2;

        if(ask(mid, n) == n-1) {
            p1 = mid;
            l = mid + 1;
        } else r = mid - 1;
    }

    vector<int> ans(n+1, 0);
    ans[p1] = 1;

    if(p1 < n) ans[p1+1] = ans[p1] + ask(p1, p1+1);
    if(p1 > 1) ans[p1-1] = ans[p1] + ask(p1-1, p1);

    for(int i=p1-2; i>=1; i--) {
        int diff = ask(i, i+1);

        if(ans[i+1] + diff > n) {
            ans[i] = ans[i+1] - diff;
        } else if(ans[i+1] - diff < 1) {
            ans[i] = ans[i+1] + diff;
        } else if(ans[i+2] > ans[i+1]) {
            if(ask(i, i+2) == ask(i, i+1) || ask(i, i+2) == ask(i+1, i+2))
                ans[i] = ans[i+1] + diff;
            else 
                ans[i] = ans[i+1] - diff;
        } else {
            if(ask(i, i+2) == ask(i, i+1) || ask(i, i+2) == ask(i+1, i+2))
                ans[i] = ans[i+1] - diff;
            else 
                ans[i] = ans[i+1] + diff;
        }
    }

    for(int i=p1+2; i<=n; i++) {
        int diff = ask(i-1, i);

        if(ans[i-1] + diff > n) {
            ans[i] = ans[i-1] - diff;
        } else if(ans[i-1] - diff < 1) {
            ans[i] = ans[i-1] + diff;
        } else if(ans[i-2] > ans[i-1]) {
            if(ask(i-2, i) == ask(i-1, i) || ask(i-2, i) == ask(i-2, i-1))
                ans[i] = ans[i-1] + diff;
            else 
                ans[i] = ans[i-1] - diff;
        } else {
            if(ask(i-2, i) == ask(i-1, i) || ask(i-2, i) == ask(i-2, i-1))
                ans[i] = ans[i-1] - diff;
            else 
                ans[i] = ans[i-1] + diff;
        }
    }

    for(int i=1; i<=n; i++)
        answer(i, ans[i]);
}

// int32_t main() {
//     setIO();

//     //code starts here

//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 98136 KB Output is correct
2 Correct 11 ms 98136 KB Output is correct
3 Correct 11 ms 98136 KB Output is correct
4 Correct 11 ms 98136 KB Output is correct
5 Correct 12 ms 98136 KB Output is correct
6 Correct 12 ms 98136 KB Output is correct
7 Correct 13 ms 98260 KB Output is correct
8 Correct 12 ms 98136 KB Output is correct
9 Correct 12 ms 98196 KB Output is correct
10 Correct 13 ms 98136 KB Output is correct
11 Correct 12 ms 98284 KB Output is correct
12 Correct 12 ms 98136 KB Output is correct
13 Correct 12 ms 98212 KB Output is correct
14 Correct 11 ms 98132 KB Output is correct
15 Correct 12 ms 98136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 98136 KB Output is correct
2 Correct 11 ms 98136 KB Output is correct
3 Correct 11 ms 98136 KB Output is correct
4 Correct 11 ms 98136 KB Output is correct
5 Correct 12 ms 98136 KB Output is correct
6 Correct 12 ms 98136 KB Output is correct
7 Correct 13 ms 98260 KB Output is correct
8 Correct 12 ms 98136 KB Output is correct
9 Correct 12 ms 98196 KB Output is correct
10 Correct 13 ms 98136 KB Output is correct
11 Correct 12 ms 98284 KB Output is correct
12 Correct 12 ms 98136 KB Output is correct
13 Correct 12 ms 98212 KB Output is correct
14 Correct 11 ms 98132 KB Output is correct
15 Correct 12 ms 98136 KB Output is correct
16 Correct 13 ms 98136 KB Output is correct
17 Correct 15 ms 98200 KB Output is correct
18 Correct 16 ms 98328 KB Output is correct
19 Correct 18 ms 98324 KB Output is correct
20 Correct 18 ms 98320 KB Output is correct
21 Correct 16 ms 98328 KB Output is correct
22 Correct 18 ms 98576 KB Output is correct
23 Correct 21 ms 98320 KB Output is correct
24 Correct 16 ms 98328 KB Output is correct
25 Correct 19 ms 98320 KB Output is correct
26 Correct 18 ms 98576 KB Output is correct
27 Correct 18 ms 98580 KB Output is correct
28 Correct 18 ms 98576 KB Output is correct
29 Correct 17 ms 98324 KB Output is correct
30 Correct 17 ms 98580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 98136 KB Output is correct
2 Correct 11 ms 98136 KB Output is correct
3 Correct 11 ms 98136 KB Output is correct
4 Correct 11 ms 98136 KB Output is correct
5 Correct 12 ms 98136 KB Output is correct
6 Correct 12 ms 98136 KB Output is correct
7 Correct 13 ms 98260 KB Output is correct
8 Correct 12 ms 98136 KB Output is correct
9 Correct 12 ms 98196 KB Output is correct
10 Correct 13 ms 98136 KB Output is correct
11 Correct 12 ms 98284 KB Output is correct
12 Correct 12 ms 98136 KB Output is correct
13 Correct 12 ms 98212 KB Output is correct
14 Correct 11 ms 98132 KB Output is correct
15 Correct 12 ms 98136 KB Output is correct
16 Correct 13 ms 98136 KB Output is correct
17 Correct 15 ms 98200 KB Output is correct
18 Correct 16 ms 98328 KB Output is correct
19 Correct 18 ms 98324 KB Output is correct
20 Correct 18 ms 98320 KB Output is correct
21 Correct 16 ms 98328 KB Output is correct
22 Correct 18 ms 98576 KB Output is correct
23 Correct 21 ms 98320 KB Output is correct
24 Correct 16 ms 98328 KB Output is correct
25 Correct 19 ms 98320 KB Output is correct
26 Correct 18 ms 98576 KB Output is correct
27 Correct 18 ms 98580 KB Output is correct
28 Correct 18 ms 98576 KB Output is correct
29 Correct 17 ms 98324 KB Output is correct
30 Correct 17 ms 98580 KB Output is correct
31 Correct 26 ms 98324 KB Output is correct
32 Correct 27 ms 98320 KB Output is correct
33 Correct 45 ms 98572 KB Output is correct
34 Correct 49 ms 98320 KB Output is correct
35 Correct 51 ms 98320 KB Output is correct
36 Incorrect 79 ms 98324 KB Wrong Answer [2]
37 Halted 0 ms 0 KB -