답안 #894540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894540 2023-12-28T12:01:57 Z lunaTu Xylophone (JOI18_xylophone) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#include "xylophone.h"
typedef long long ll;
using namespace std;

static int A[5000];

/*int query(int i, int j) {
    cout << i << " " << j << endl;
    int x;
    cin >> x;
    return x;
}

void answer(int i, int x) {
    A[i] = x;
}*/

void solve(int N) {

	/*int value = query(1, N);

	for(int i = 1; i <= N; i++) {
		answer(i, i);
	}*/

    vector<int> a(N + 1);
    //u(N + 1);
    int l = 1, r = N + 1;
    while (r - l > 1) {
        int m = (l + r) / 2;

        int get = query(m, N);

        if (get != N - 1) r = m;
        else l = m;
    }

    answer(l, 1);
    a[l] = 1;
    if (l != N) {
        a[l + 1] = 1 + query(l, l + 1);
        answer(l + 1, a[l + 1]);
    }

    for (int i = l + 2; i <= N; i++) {
        int x = query(i - 2, i);
        if (x == abs(a[i - 1] - a[i - 2])) {
            int y = query(i - 1, i);
            if (a[i - 1] < a[i - 2]) a[i] = a[i - 1] + y;
            else a[i] = a[i - 1] - y;
        }
        else if (a[i - 1] < a[i - 2]) a[i] = a[i - 1] + x;
        else a[i] = a[i - 2] + x;

        answer(i, a[i]);
    }

    if (l != 1) {
        a[l - 1] = 1 + query(l - 1, l);
        answer(l - 1, a[l - 1]);
    }

    for (int i = l - 2; i >= 1; i--) {
        int x = query(i, i + 2);
        if (x == abs(a[i + 1] - a[i + 2])) {
            int y = query(i, i + 1);
            if (a[i + 1] < a[i + 2]) a[i] = a[i + 1] + y;
            else a[i] = a[i + 1] - y;
        }
        else if (a[i + 1] < a[i + 2]) a[i] = a[i + 1] + x;
        else a[i] = a[i + 2] + x;

        answer(i, a[i]);
    }

    /*for (auto x : a) cout << x << " ";
    cout << endl;*/
}

Compilation message

xylophone.cpp:9:12: warning: 'A' defined but not used [-Wunused-variable]
    9 | static int A[5000];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -