제출 #1299277

#제출 시각아이디문제언어결과실행 시간메모리
1299277biankXylophone (JOI18_xylophone)C++20
100 / 100
28 ms448 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
 
using namespace std;

using vi = vector<int>;

#define all(x) begin(x), end(x)

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)

void solve(int N) {
    vi diff(N - 1);
    forn(i, N - 1) diff[i] = query(i + 1, i + 2);
    vi type(N - 1, 0);
    forsn(i, 1, N - 1) {
        if (diff[i - 1] + diff[i] == query(i, i + 2)) type[i] = type[i - 1];
        else type[i] = type[i - 1] ^ 1;
    }
    forn(_, 2) {
        forn(i, N - 1) type[i] ^= 1;
        vi ret(N);
        ret[0] = 0;
        forn(i, N - 1) {
            if (type[i]) ret[i + 1] = ret[i] + diff[i];
            else ret[i + 1] = ret[i] - diff[i];
        }
        int mini = int(min_element(all(ret)) - begin(ret));
        int maxi = int(max_element(all(ret)) - begin(ret));
        assert(mini != maxi);
        if (mini > maxi) continue;
        int offset = 1 - ret[mini];
        forn(i, N) ret[i] += offset;
        forn(i, N) answer(i + 1, ret[i]);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...