답안 #931932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931932 2024-02-22T15:33:03 Z Amirreza_Fakhri Xylophone (JOI18_xylophone) C++17
컴파일 오류
0 ms 0 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e4+5;

int a[maxn];
bool mark[maxn];

void solve(int n) {
    // if (n == 2) {
    //     answer(1, 1), answer(2, 2); return;
    // }
    int l = 1, r = n+1;
    while (r-l > 1) {
        int mid = (r+l)/2;
        if (query(1, mid) == n-1) r = mid;
        else l = mid;
    }
    a[++l] = n, mark[n] = 1;
    if (l < n) {
        int x = query(l, l+1);
        a[l+1] = n-x, mark[n-x] = 1;
        for (int i = l+2; i <= n; i++) {
            int p = query(i-1, i);
            if (mark[a[i-1]+p]) {
                a[i] = a[i-1]-p, mark[a[i-1]-p] = 1;
            }
            else if (mark[a[i-1]-p]) {
                a[i] = a[i-1]+p, mark[a[i-1]+p] = 1;
            }
            else if (a[i-2] > a[i-1]) {
                int r = query(i-2, i);
                if (r == a[i-2]-(a[i-1]-p)) {
                    a[i] = a[i-1]-p, mark[a[i-1]-p] = 1;
                }
                else {
                    a[i] = a[i-1]+p, mark[a[i-1]+p] = 1;
                }
            }
            else {
                int r = query(i-2, i);
                if (r == (a[i-1]+p)-a[i-2]) {
                    a[i] = a[i-1]+p, mark[a[i-1]+p] = 1;
                }
                else {
                    a[i] = a[i-1]-p, mark[a[i-1]-p] = 1;
                }
            }
        }
    }
    int x = query(l-1, l);
    a[l-1] = n-x, mark[n-x] = 1;
    for (int i = l-2; i >= 1; i--) {
        int p = query(i, i+1);
        if (mark[a[i+1]+p]) {
            a[i] = a[i+1]-p, mark[a[i+1]-p] = 1;
        }
        else if (mark[a[i+1]-p]) {
            a[i] = a[i+1]+p, mark[a[i+1]+p] = 1;
        }
        else if (a[i+2] > a[i+1]) {
            int r = query(i, i+2);
            if (r == a[i+2]-(a[i+1]-p)) {
                a[i] = a[i+1]-p, mark[a[i+1]-p] = 1;
            }
            else {
                a[i] = a[i+1]+p, mark[a[i+1]+p] = 1;
            }
        }
        else {
            int r = query(i, i+2);
            if (r == (a[i+1]+p)-a[i+2]) {
                a[i] = a[i+1]+p, mark[a[i+1]+p] = 1;
            }
            else {
                a[i] = a[i+1]-p, mark[a[i+1]-p] = 1;
            }
        }
    }
    for (int i = 1; i <= n; i++) answer(i, a[i]);
}

// int32_t main() {
//     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//     return 0;
// }

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:29:13: error: 'query' was not declared in this scope
   29 |         if (query(1, mid) == n-1) r = mid;
      |             ^~~~~
xylophone.cpp:34:17: error: 'query' was not declared in this scope
   34 |         int x = query(l, l+1);
      |                 ^~~~~
xylophone.cpp:64:13: error: 'query' was not declared in this scope
   64 |     int x = query(l-1, l);
      |             ^~~~~
xylophone.cpp:93:34: error: 'answer' was not declared in this scope
   93 |     for (int i = 1; i <= n; i++) answer(i, a[i]);
      |                                  ^~~~~~