답안 #82997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82997 2018-11-03T14:47:46 Z Vasiljko Xylophone (JOI18_xylophone) C++14
47 / 100
73 ms 600 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 val=query(2,n);
    for(int i=1;i<n;i++){
        int val=query(i+1,n);
        if(val!=diff){
            ind=i;
            break;
        }
    }

    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:11:9: warning: unused variable 'val' [-Wunused-variable]
     int val=query(2,n);
         ^~~
xylophone.cpp:10:9: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int ind;
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 3 ms 400 KB Output is correct
4 Correct 3 ms 400 KB Output is correct
5 Correct 4 ms 548 KB Output is correct
6 Correct 4 ms 580 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 4 ms 580 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 3 ms 580 KB Output is correct
12 Correct 4 ms 580 KB Output is correct
13 Correct 3 ms 580 KB Output is correct
14 Correct 15 ms 580 KB Output is correct
15 Correct 4 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 3 ms 400 KB Output is correct
4 Correct 3 ms 400 KB Output is correct
5 Correct 4 ms 548 KB Output is correct
6 Correct 4 ms 580 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 4 ms 580 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 3 ms 580 KB Output is correct
12 Correct 4 ms 580 KB Output is correct
13 Correct 3 ms 580 KB Output is correct
14 Correct 15 ms 580 KB Output is correct
15 Correct 4 ms 580 KB Output is correct
16 Correct 6 ms 580 KB Output is correct
17 Correct 9 ms 588 KB Output is correct
18 Correct 16 ms 588 KB Output is correct
19 Correct 18 ms 592 KB Output is correct
20 Correct 18 ms 592 KB Output is correct
21 Correct 19 ms 592 KB Output is correct
22 Correct 22 ms 592 KB Output is correct
23 Correct 16 ms 592 KB Output is correct
24 Correct 23 ms 592 KB Output is correct
25 Correct 10 ms 592 KB Output is correct
26 Correct 23 ms 592 KB Output is correct
27 Correct 20 ms 592 KB Output is correct
28 Correct 20 ms 592 KB Output is correct
29 Correct 16 ms 592 KB Output is correct
30 Correct 16 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 392 KB Output is correct
3 Correct 3 ms 400 KB Output is correct
4 Correct 3 ms 400 KB Output is correct
5 Correct 4 ms 548 KB Output is correct
6 Correct 4 ms 580 KB Output is correct
7 Correct 4 ms 580 KB Output is correct
8 Correct 4 ms 580 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 3 ms 580 KB Output is correct
12 Correct 4 ms 580 KB Output is correct
13 Correct 3 ms 580 KB Output is correct
14 Correct 15 ms 580 KB Output is correct
15 Correct 4 ms 580 KB Output is correct
16 Correct 6 ms 580 KB Output is correct
17 Correct 9 ms 588 KB Output is correct
18 Correct 16 ms 588 KB Output is correct
19 Correct 18 ms 592 KB Output is correct
20 Correct 18 ms 592 KB Output is correct
21 Correct 19 ms 592 KB Output is correct
22 Correct 22 ms 592 KB Output is correct
23 Correct 16 ms 592 KB Output is correct
24 Correct 23 ms 592 KB Output is correct
25 Correct 10 ms 592 KB Output is correct
26 Correct 23 ms 592 KB Output is correct
27 Correct 20 ms 592 KB Output is correct
28 Correct 20 ms 592 KB Output is correct
29 Correct 16 ms 592 KB Output is correct
30 Correct 16 ms 592 KB Output is correct
31 Correct 35 ms 592 KB Output is correct
32 Correct 58 ms 600 KB Output is correct
33 Correct 73 ms 600 KB Output is correct
34 Incorrect 38 ms 600 KB Wrong Answer [2]
35 Halted 0 ms 0 KB -