답안 #1114446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114446 2024-11-18T22:34:29 Z sunboi Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;



void solve(int n){
    int i = 1;
    while(query(i, n) == n - 1){
        i++;
    }
    i--;
    //cout << i << endl;
    int reference = i;
    vector<int> a(n + 1);
    int x = query(i, i + 1);
    
    a[i] = 1;
    a[i + 1] = x + 1;
    i += 2;
    int last = x;
    
    for (; i <= n; i++){
        int mn = min(a[i - 1], a[i - 2]);
        int mx = max(a[i - 1], a[i - 2]);
        int uno = query(i - 1, i);
        int dos = query(i - 2, i);
        
        if (dos > last){
            if (dos == uno){
                if (a[i - 1] == mn) a[i] = a[i - 1] + uno;
                else a[i] = a[i - 1] - uno;
            }else{
                if (a[i - 2] == mn) a[i] = a[i - 2] + dos;
                else  a[i] = a[i - 2] - dos;
            }
        }else{
            if (a[i - 1] == mn) a[i] = a[i - 1] + uno;
            else a[i] = a[i - 1] - uno;
        }
        last = uno;
    }
    
    i = reference;
    x = query(i - 1, i);
    a[i - 1] = 1 + x;
    last = x;
    i -= 2;
    for (; i >= 1; i--){
        int mn = min(a[i + 1], a[i + 2]);
        int mx = max(a[i + 1], a[i + 2]);
        int uno = query(i, i + 1);
        int dos = query(i, i + 2);
        if (dos > last){
            if (dos == uno){
                if (a[i + 1] == mn) a[i] = a[i + 1] + uno;
                else a[i] = a[i + 1] - uno;
            }else{
                if (a[i + 2] == mn) a[i] = a[i + 2] + dos;
                else  a[i] = a[i + 2] - dos;
            }
        }else{
            if (a[i + 1] == mn) a[i] = a[i + 1] + uno;
            else a[i] = a[i + 1] - uno;
        }
        last = uno;
    }
    for (int i = 1; i <= n; i++) answer(i, a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:25:13: warning: unused variable 'mx' [-Wunused-variable]
   25 |         int mx = max(a[i - 1], a[i - 2]);
      |             ^~
xylophone.cpp:51:13: warning: unused variable 'mx' [-Wunused-variable]
   51 |         int mx = max(a[i + 1], a[i + 2]);
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Wrong Answer [1]
2 Halted 0 ms 0 KB -