답안 #996058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996058 2024-06-10T07:40:14 Z khanhtb Xylophone (JOI18_xylophone) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 2e5+8;
const ll buff = 1e5+1;
ll a[N],dist[N][2];
bool check(){
    set<ll> s;
    bool meetn = 0;
    for(ll i = 1; i <= n; i++){
        cout << a[i] << ' ';
        s.insert(a[i]);
        if(a[i] == 1 && meetn) return 0;
        if(a[i] == n) meetn = 1;
    }
    cout << '\n';
    if(s.size() != n) return 0;
    if(*s.begin() != 1) return 0;
    if(*s.rbegin() != n) return 0;
    return 1;
}
void solve(int n){
    cin >> n;
    for(ll i = 2; i <= n; i++){
        if(i > 1) dist[i][0] = query(i-1,i);
        if(i > 2) dist[i][1] = query(i-2,i);
    }
    for(ll x = 1; x <= n; x++){
        a[1] = x;
        a[2] = x+dist[2][0];
        for(ll i = 3; i <= n; i++){
            if(a[i-2] > a[i-1]){
                if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0];
                else a[i] = a[i-1]+dist[i][0];
            }
            else{
                if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0];
                else a[i] = a[i-1]-dist[i][0];
            }
        }
        if(check()) break;
        a[1] = x;
        a[2] = x-dist[2][0];
        for(ll i = 3; i <= n; i++){
            if(a[i-2] > a[i-1]){
                if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0];
                else a[i] = a[i-1]+dist[i][0];
            }
            else{
                if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0];
                else a[i] = a[i-1]-dist[i][0];
            }
        }
        if(check()) break;
    }
    for(ll i = 1; i <= n; i++) answer(i,a[i]);
}

Compilation message

xylophone.cpp: In function 'bool check()':
xylophone.cpp:26:24: error: 'n' was not declared in this scope
   26 |     for(ll i = 1; i <= n; i++){
      |                        ^
xylophone.cpp:33:20: error: 'n' was not declared in this scope
   33 |     if(s.size() != n) return 0;
      |                    ^
xylophone.cpp:35:23: error: 'n' was not declared in this scope
   35 |     if(*s.rbegin() != n) return 0;
      |                       ^