답안 #239585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239585 2020-06-16T13:36:28 Z ctziapo Xylophone (JOI18_xylophone) C++14
100 / 100
112 ms 512 KB
#include "xylophone.h"
#include<cmath>
#include<map>
static int A[5000];

using namespace std;

void solve(int N) {
    int n=N;
	int value = query(1, N);
    int pf;
  // cout<<" find first "<<endl;
	//for(int i=1;i<=n;i++){
   //     int t=query(i,N);
   //     if(t!=n-1){
    //       pf=i-1;
   //        break;
     //   }
	//}
	int l=1;
	int r=n;
	while(l<r){
        int mid = (l+r)/2;
        int t=query(mid,n);

        if(t==n-1){
            l=mid+1;
        }
        else
            r=mid-1;

	}
	if(query(l,n)!=n-1)
        l--;
//	cout<<"ssssssss "<<l<<endl;
    pf=l;
	int f[10000]={};

	//cout<<pf<<endl;
    answer(pf,1);
    f[1]=1;
  //  cout<<"os edo"<<endl;
    int a[n+3]={};
    a[pf]=1;
    if(pf!=1){
        a[pf-1] = query(pf-1,pf)+1;
        answer(pf-1,a[pf-1]);
        f[a[pf-1]]=1;
    }
    if(pf!=N){
        a[pf+1] = query(pf,pf+1)+1;
        answer(pf+1,a[pf+1]);
        f[a[pf+1]]=1;
    }

   // cout<<"my answer "<<endl;
	//for(int i = 1; i <= N; i++) {
	//	cout<<a[i]<<" ";
	//}


    int s=pf+2;

    while(s<=n){

        int t=query(s-1,s);
        if(f[a[s-1]+t]==1){
            a[s]=a[s-1]-t;
            answer(s,a[s]);
            f[a[s]]=1;
            s++;
            continue;
        }
        if(f[a[s-1]-t]==1){
            a[s]=a[s-1]+t;
            answer(s,a[s]);
            f[a[s]]=1;
            s++;
            continue;
        }
        int t2=query(s-2,s);

        if(abs(a[s-1]-a[s-2])==t2){
            if(a[s-1] > a[s-2]){
                a[s]=a[s-1]-t;
                answer(s,a[s]);
                f[a[s]]=1;
            }
            else{
                a[s]=a[s-1]+t;
                answer(s,a[s]);
                f[a[s]]=1;
            }
        }
        else
        {
            if(a[s-1] > a[s-2]){
                if(a[s-1]-a[s-2] + t == t2){
                a[s]=a[s-1]+t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
                else
                {
                a[s]=a[s-1]-t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
            }
            else{
                if(a[s-2]-a[s-1] + t == t2){
                a[s]=a[s-1]-t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
                else
                {
                a[s]=a[s-1]+t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
            }
        }

    //    cout<<"my answer "<<endl;
	//for(int i = 1; i <= N; i++) {
	//	cout<<a[i]<<" ";
	//}


        s++;
    }




    s=pf-2;

    while(s>=1){

        int t=query(s,s+1);
        if(f[a[s+1]+t]==1){
            a[s]=a[s+1]-t;
            answer(s,a[s]);
            f[a[s]]=1;
            s--;
            continue;
        }
        if(f[a[s+1]-t]==1){
            a[s]=a[s+1]+t;
            answer(s,a[s]);
            f[a[s]]=1;
            s--;
            continue;
        }
        int t2=query(s,s+2);

        if(abs(a[s+1]-a[s+2])==t2){
            if(a[s+1] > a[s+2]){
                a[s]=a[s+1]-t;
                answer(s,a[s]);
                f[a[s]]=1;
            }
            else{
                a[s]=a[s+1]+t;
                answer(s,a[s]);
                f[a[s]]=1;
            }
        }
        else
        {
            if(a[s+1] > a[s+2]){
                if(a[s+1]-a[s+2] + t == t2){
                a[s]=a[s+1]+t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
                else
                {
                a[s]=a[s+1]-t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
            }
            else{
                if(a[s+2]-a[s+1] + t == t2){
                a[s]=a[s+1]-t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
                else
                {
                a[s]=a[s+1]+t;
                answer(s,a[s]);
                f[a[s]]=1;
                }
            }
        }

    //    cout<<"my answer "<<endl;
//	for(int i = 1; i <= N; i++) {
//		cout<<a[i]<<" ";
//	}


        s--;
    }




  //  cout<<"my answer "<<endl;
	//for(int i = 1; i <= N; i++) {
//		cout<<a[i]<<" ";
	//}

}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:10:6: warning: unused variable 'value' [-Wunused-variable]
  int value = query(1, N);
      ^~~~~
xylophone.cpp: At global scope:
xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
 static int A[5000];
            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 368 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 6 ms 416 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 368 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 6 ms 416 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 10 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 21 ms 384 KB Output is correct
19 Correct 24 ms 384 KB Output is correct
20 Correct 21 ms 436 KB Output is correct
21 Correct 24 ms 384 KB Output is correct
22 Correct 17 ms 384 KB Output is correct
23 Correct 13 ms 384 KB Output is correct
24 Correct 19 ms 384 KB Output is correct
25 Correct 27 ms 384 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 12 ms 364 KB Output is correct
28 Correct 21 ms 384 KB Output is correct
29 Correct 16 ms 288 KB Output is correct
30 Correct 20 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 368 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 6 ms 416 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 10 ms 384 KB Output is correct
17 Correct 11 ms 384 KB Output is correct
18 Correct 21 ms 384 KB Output is correct
19 Correct 24 ms 384 KB Output is correct
20 Correct 21 ms 436 KB Output is correct
21 Correct 24 ms 384 KB Output is correct
22 Correct 17 ms 384 KB Output is correct
23 Correct 13 ms 384 KB Output is correct
24 Correct 19 ms 384 KB Output is correct
25 Correct 27 ms 384 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 12 ms 364 KB Output is correct
28 Correct 21 ms 384 KB Output is correct
29 Correct 16 ms 288 KB Output is correct
30 Correct 20 ms 384 KB Output is correct
31 Correct 35 ms 384 KB Output is correct
32 Correct 30 ms 392 KB Output is correct
33 Correct 73 ms 384 KB Output is correct
34 Correct 70 ms 384 KB Output is correct
35 Correct 81 ms 384 KB Output is correct
36 Correct 69 ms 384 KB Output is correct
37 Correct 80 ms 384 KB Output is correct
38 Correct 69 ms 384 KB Output is correct
39 Correct 61 ms 384 KB Output is correct
40 Correct 46 ms 360 KB Output is correct
41 Correct 75 ms 384 KB Output is correct
42 Correct 62 ms 384 KB Output is correct
43 Correct 74 ms 384 KB Output is correct
44 Correct 73 ms 384 KB Output is correct
45 Correct 65 ms 384 KB Output is correct
46 Correct 64 ms 384 KB Output is correct
47 Correct 67 ms 384 KB Output is correct
48 Correct 94 ms 384 KB Output is correct
49 Correct 79 ms 384 KB Output is correct
50 Correct 79 ms 384 KB Output is correct
51 Correct 71 ms 384 KB Output is correct
52 Correct 75 ms 384 KB Output is correct
53 Correct 70 ms 512 KB Output is correct
54 Correct 76 ms 384 KB Output is correct
55 Correct 77 ms 384 KB Output is correct
56 Correct 96 ms 384 KB Output is correct
57 Correct 71 ms 384 KB Output is correct
58 Correct 112 ms 384 KB Output is correct
59 Correct 95 ms 384 KB Output is correct
60 Correct 77 ms 384 KB Output is correct