답안 #83000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83000 2018-11-03T15:05:52 Z Vasiljko Xylophone (JOI18_xylophone) C++14
0 / 100
2 ms 504 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

int a[5000];
bool vis[5000];

void solve(int n) {
    int diff=n-1;
    int ind;

    int lo=2;
    int hi=n-1;

    while(lo<=hi){
        int mid=(lo+hi)>>1;
        if(query(mid,n)==diff){
            ind=mid;
            lo=mid+1;
        }else{
            hi=mid-1;
        }
    }

    a[ind]=1;
    a[ind+1]=1+query(ind,ind+1);

    vis[a[ind]]=true;
    vis[a[ind+1]]=true;

    for(int i=ind+2;i<=n;i++){
        int q=query(i-1,i);

        if(vis[a[i-1]+q]){
            a[i]=a[i-1]-q;
            continue;
        }
        if(vis[a[i-1]-q]){
            a[i]=a[i-1]+q;
            continue;
        }

        int p=query(i-2,i);

        int val=a[i-1]+q;
        if(max(val,max(a[i-1],a[i-2]))-min(val,min(a[i-1],a[i-2]))==p){
            a[i]=val;
        }else{
            a[i]=a[i-1]-q;
        }
        vis[a[i]]=true;
    }

    if(ind>1){
        a[ind-1]=1+query(ind-1,ind);
        vis[a[ind-1]]=true;

        for(int i=ind-2;i>=1;i--){
            int q=query(i,i+1);

            if(vis[a[i+1]+q]){
                a[i]=a[i+1]-q;
                continue;
            }
            if(vis[a[i+1]-q]){
                a[i]=a[i+1]+q;
                continue;
            }

            int p=query(i,i+2);

            int val=a[i+1]+q;
            if(max(val,max(a[i+1],a[i+2]))-min(val,min(a[i+1],a[i+2]))==p){
                a[i]=val;
            }else{
                a[i]=a[i+1]-q;
            }
            vis[a[i]]=true;
        }
    }
    for(int i=1;i<=n;i++)answer(i,a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:55:25: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
         a[ind-1]=1+query(ind-1,ind);
                    ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -