답안 #253529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253529 2020-07-28T07:17:33 Z aggu_01000101 Xylophone (JOI18_xylophone) C++14
100 / 100
66 ms 892 KB
#include <iostream>
#include <xylophone.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <iomanip>
#include <bits/stdc++.h>
#define initrand mt19937 mt_rand(time(0));
#define rand mt_rand()
//#define int long long
#define INF -1
#define mid(l, u) ((l+u)/2)
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
using namespace std;
initrand;
int N;
map<int, bool> seen;
/*int query(int s, int t){
    cout<<"Query asked: "<<s<<" "<<t<<endl;
    int ans;
    cin>>ans;
    return ans;
}
void answer(int i, int a){
    cout<<"Answer for index "<<i<<" is "<<a<<endl;
}*/
int findOne(int n){
    int l = 2;
    int u = n;
    int tr = n-1;
    while(l<=u){
        int m = mid(l, u);
        if(query(m, n) < (n-1)){
            tr = min(tr, m-1);
            u = m-1;
        }
        else l = m+1;
    }
    return tr;
}
int diff(int a, int b, int c){
    return max(a, max(b, c)) - min(a, min(b, c));
}
int findPrev(int i, int prev, int prev1){
    int temp = query(i, i+1);
    int poss1 = prev+temp;
    int poss2 = prev-temp;
    if(seen[poss1] || poss1>N) return poss2;
    if(seen[poss2] || poss2<1) return poss1;
    temp = query(i, i+2);
    if(temp == diff(prev, prev1, poss1)) return poss1;
    return poss2;
}
int findNext(int i, int prev, int prev1){
    int temp = query(i-1, i);
    int poss1 = prev+temp;
    int poss2 = prev-temp;
    if(seen[poss1] || poss1>N) return poss2;
    if(seen[poss2] || poss2<1) return poss1;
    temp = query(i-2, i);
    if(temp == diff(prev, prev1, poss1)) return poss1;
    return poss2;
}
void solve(int n){
    N = n;
    int arr[n+1];
    int oind = findOne(n);
    arr[oind] = 1;
    seen[1] = true;
    arr[oind + 1] = 0;
    for(int j = oind-1;j>=1;j--){
        arr[j] = findPrev(j, arr[j+1], arr[j+2]);
        seen[arr[j]] = true;
    }
    for(int j = oind+1;j<=n;j++){
        arr[j] = findNext(j, arr[j-1], ((j-2)>=1)?arr[j-2]:0);
        seen[arr[j]] = true;
    }
    for(int i = 1;i<=n;i++) answer(i, arr[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 376 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 376 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 12 ms 384 KB Output is correct
20 Correct 12 ms 384 KB Output is correct
21 Correct 13 ms 384 KB Output is correct
22 Correct 16 ms 384 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 10 ms 384 KB Output is correct
25 Correct 10 ms 384 KB Output is correct
26 Correct 15 ms 384 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 9 ms 384 KB Output is correct
29 Correct 10 ms 384 KB Output is correct
30 Correct 9 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 376 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 7 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 12 ms 384 KB Output is correct
20 Correct 12 ms 384 KB Output is correct
21 Correct 13 ms 384 KB Output is correct
22 Correct 16 ms 384 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 10 ms 384 KB Output is correct
25 Correct 10 ms 384 KB Output is correct
26 Correct 15 ms 384 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 9 ms 384 KB Output is correct
29 Correct 10 ms 384 KB Output is correct
30 Correct 9 ms 384 KB Output is correct
31 Correct 20 ms 504 KB Output is correct
32 Correct 48 ms 504 KB Output is correct
33 Correct 50 ms 632 KB Output is correct
34 Correct 64 ms 632 KB Output is correct
35 Correct 57 ms 648 KB Output is correct
36 Correct 49 ms 632 KB Output is correct
37 Correct 48 ms 760 KB Output is correct
38 Correct 45 ms 760 KB Output is correct
39 Correct 64 ms 632 KB Output is correct
40 Correct 62 ms 632 KB Output is correct
41 Correct 54 ms 760 KB Output is correct
42 Correct 42 ms 760 KB Output is correct
43 Correct 48 ms 760 KB Output is correct
44 Correct 46 ms 892 KB Output is correct
45 Correct 63 ms 632 KB Output is correct
46 Correct 63 ms 632 KB Output is correct
47 Correct 58 ms 632 KB Output is correct
48 Correct 64 ms 620 KB Output is correct
49 Correct 60 ms 632 KB Output is correct
50 Correct 57 ms 764 KB Output is correct
51 Correct 57 ms 632 KB Output is correct
52 Correct 56 ms 760 KB Output is correct
53 Correct 65 ms 632 KB Output is correct
54 Correct 62 ms 760 KB Output is correct
55 Correct 65 ms 740 KB Output is correct
56 Correct 59 ms 760 KB Output is correct
57 Correct 66 ms 760 KB Output is correct
58 Correct 55 ms 632 KB Output is correct
59 Correct 56 ms 632 KB Output is correct
60 Correct 61 ms 760 KB Output is correct