답안 #61375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61375 2018-07-25T16:39:51 Z the_art_of_war Xylophone (JOI18_xylophone) C++14
100 / 100
111 ms 956 KB
#include "xylophone.h"
#include <bits/stdc++.h>
static int A[5100];
using namespace std;

int get(int x1,int x2,int x3){
    return max(x1,max(x2,x3)) - min(x1,min(x2,x3));
}

void solve(int N) {

     int n = N;
	 int pos = -1; // pos of 1
	 int l = 1, r = n-1;
	 while(l<=r){
        int mid = (l+r)>>1;
        if(query(mid,N) == n-1){
            pos = mid;
       //     cout <<"hre "<<mid<<endl;
            l = mid+1;
        } else{
            r = mid-1;
        }
	 }
	 assert(pos>=1);
//	 cerr <<"POs : "<<pos<<endl;
	 A[pos] = 1;
	 set<int> vals;
	 vals.insert(1);
     for(int i=pos-1;i>=1;--i){
        int x = query(i,i+1);
        int val1 = A[i+1] + x;
        int val2 = A[i+1] - x;
        bool good1 = val1 >=1 && val1<=n && !vals.count(val1);
        bool good2 = val2>=1  && val2<=n && !vals.count(val2);
     //   cerr << i <<"  : " <<val1<<" "<< val2<<endl;
        if(good1 && good2){
            int x = query(i,i+2);
    //        cerr <<" here "<<x<<endl;
            good1 = get(val1,A[i+1],A[i+2]) == x;
            good2 = get(val2,A[i+1],A[i+2]) == x;
  //          cerr << " "<<good1 <<" "<<good2<<endl;
            if(good1 && good2){
         //       assert(false);
            }
            if(good1){
                A[i] = val1;
    //            cerr <<"A[1] " <<A[i]<<endl;
            } else if(good2){
                A[i] = val2;
            }
        } else{
            if(good1){
                A[i] = val1;
            } else if(good2){
                A[i] = val2;
            } else {
           //     assert(false);
            }
        }
        vals.insert(A[i]);
     }

     for(int i=pos+1;i<=n;++i){
        int x = query(i-1,i);
        int val1 = A[i-1] + x;
        int val2 = A[i-1] - x;
        bool good1 = val1 >=1 && val1<=n && !vals.count(val1);
        bool good2 = val2>=1  && val2<=n && !vals.count(val2);
    //    cerr << i << " : " << val1<<" "<<val2<<endl;
        if(good1 && good2){
            int x = query(i-2,i);
            good1 = get(val1,A[i-1],A[i-2]) == x;
            good2 = get(val2,A[i-1],A[i-2]) == x;
            if(good1 && good2)
              assert(false);
            if(good1){
                A[i] = val1;
            } else if(good2){
                A[i] = val2;
            }
        } else{
            if(good1){
                A[i] = val1;
            } else if(good2){
                A[i] = val2;
            } else {
          //      assert(false);
            }
        }
        vals.insert(A[i]);
     }

    /* for(int i=1;i<=n;++i){
        cerr << A[i]<<" ";
     }
     cerr << endl;*/


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



}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
6 Correct 3 ms 496 KB Output is correct
7 Correct 4 ms 552 KB Output is correct
8 Correct 4 ms 552 KB Output is correct
9 Correct 4 ms 552 KB Output is correct
10 Correct 5 ms 568 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 4 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 4 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
6 Correct 3 ms 496 KB Output is correct
7 Correct 4 ms 552 KB Output is correct
8 Correct 4 ms 552 KB Output is correct
9 Correct 4 ms 552 KB Output is correct
10 Correct 5 ms 568 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 4 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 4 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
16 Correct 7 ms 568 KB Output is correct
17 Correct 10 ms 568 KB Output is correct
18 Correct 14 ms 572 KB Output is correct
19 Correct 14 ms 572 KB Output is correct
20 Correct 15 ms 580 KB Output is correct
21 Correct 10 ms 700 KB Output is correct
22 Correct 12 ms 700 KB Output is correct
23 Correct 12 ms 700 KB Output is correct
24 Correct 16 ms 700 KB Output is correct
25 Correct 9 ms 700 KB Output is correct
26 Correct 15 ms 700 KB Output is correct
27 Correct 24 ms 700 KB Output is correct
28 Correct 14 ms 700 KB Output is correct
29 Correct 16 ms 700 KB Output is correct
30 Correct 13 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 4 ms 420 KB Output is correct
6 Correct 3 ms 496 KB Output is correct
7 Correct 4 ms 552 KB Output is correct
8 Correct 4 ms 552 KB Output is correct
9 Correct 4 ms 552 KB Output is correct
10 Correct 5 ms 568 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 4 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 4 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
16 Correct 7 ms 568 KB Output is correct
17 Correct 10 ms 568 KB Output is correct
18 Correct 14 ms 572 KB Output is correct
19 Correct 14 ms 572 KB Output is correct
20 Correct 15 ms 580 KB Output is correct
21 Correct 10 ms 700 KB Output is correct
22 Correct 12 ms 700 KB Output is correct
23 Correct 12 ms 700 KB Output is correct
24 Correct 16 ms 700 KB Output is correct
25 Correct 9 ms 700 KB Output is correct
26 Correct 15 ms 700 KB Output is correct
27 Correct 24 ms 700 KB Output is correct
28 Correct 14 ms 700 KB Output is correct
29 Correct 16 ms 700 KB Output is correct
30 Correct 13 ms 700 KB Output is correct
31 Correct 28 ms 704 KB Output is correct
32 Correct 43 ms 704 KB Output is correct
33 Correct 78 ms 704 KB Output is correct
34 Correct 99 ms 704 KB Output is correct
35 Correct 77 ms 828 KB Output is correct
36 Correct 64 ms 832 KB Output is correct
37 Correct 57 ms 832 KB Output is correct
38 Correct 61 ms 832 KB Output is correct
39 Correct 90 ms 924 KB Output is correct
40 Correct 83 ms 924 KB Output is correct
41 Correct 65 ms 924 KB Output is correct
42 Correct 71 ms 924 KB Output is correct
43 Correct 59 ms 924 KB Output is correct
44 Correct 54 ms 924 KB Output is correct
45 Correct 54 ms 924 KB Output is correct
46 Correct 92 ms 924 KB Output is correct
47 Correct 111 ms 924 KB Output is correct
48 Correct 76 ms 924 KB Output is correct
49 Correct 109 ms 924 KB Output is correct
50 Correct 88 ms 944 KB Output is correct
51 Correct 53 ms 944 KB Output is correct
52 Correct 84 ms 956 KB Output is correct
53 Correct 71 ms 956 KB Output is correct
54 Correct 63 ms 956 KB Output is correct
55 Correct 95 ms 956 KB Output is correct
56 Correct 76 ms 956 KB Output is correct
57 Correct 84 ms 956 KB Output is correct
58 Correct 104 ms 956 KB Output is correct
59 Correct 96 ms 956 KB Output is correct
60 Correct 95 ms 956 KB Output is correct