답안 #82993

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

int a[5000];

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

    for(int i=1;i<n;i++){
        int val=query(i+1,n);
        if(val==diff-1){
            ind=i;
            break;
        }
    }

    a[ind]=1;
    a[ind+1]=1+query(ind,ind+1);
    for(int i=ind+2;i<=n;i++){
        int p=query(i-2,i);
        int d=abs(a[i-1]-a[i-2]);

        if(p==d){
            int q=query(i-1,i-2);
            a[i]=a[i-1]-q;
        }else{
            a[i]=a[i-2]+p;
        }
    }

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

        for(int i=ind-2;i>=1;i--){
            int p=query(i,i+2);
            int d=abs(a[i+1]-a[i+2]);

            if(p==d){
                int q=query(i+1,i+2);
                a[i]=a[i+1]-q;
            }else{
                a[i]=a[i+2]+p;
            }
        }
    }

    for(int i=1;i<=n;i++)answer(i,a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:8:9: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int ind;
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -