답안 #419737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419737 2021-06-07T12:05:05 Z Emin2004 Xylophone (JOI18_xylophone) C++14
100 / 100
98 ms 444 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, ll>
#define F first
#define S second

const int N = 100005;
const int mod = 1e9;

static int a[5005];
int found[N];

void solve(int n) {
    int l = 1, r = n;
    int pos = 1;
    for(int i = 4096; i > 0; i /= 2){
        if(pos + i >= n) continue;
        int x = query(pos + i, n);
        if(x + 1 == n) pos += i;
    }
   // answer(1, pos);
    a[pos] = 1;
    found[1] = 1;
    r = query(pos, pos + 1) + 1;
    a[pos + 1] = r;
    found[r] = 1;
    for(int i = pos + 2; i <= n; i++){
        int x = query(i - 1, i);
        int c1 = a[i - 1] - x;
        int c2 = a[i - 1] + x;
        if(c1 <= 0 || found[c1] == 1){
            a[i] = c2;
            found[c2] = 1;
        }
        else if(c2 > n || found[c2] == 1){
            a[i] = c1;
            found[c1] = 1;
        }
        else{
            int y = query(i - 2, i);
            if(max(abs(a[i - 1] - a[i - 2]), max(abs(a[i - 2] - c1), x)) == y){
                a[i] = c1;
                found[c1] = 1;
            }
            else{
                a[i] = c2;
                found[c2] = 1;
            }
        }
    }
    for(int i = pos - 1; i > 0; i--){
        int x = query(i, i + 1);
        int c1 = a[i + 1] - x;
        int c2 = a[i + 1] + x;
        if(c1 <= 0 || found[c1] == 1){
            a[i] = c2;
            found[c2] = 1;
        }
        else if(c2 > n || found[c2] == 1){
            a[i] = c1;
            found[c1] = 1;
        }
        else{
            int y = query(i, i + 2);
            if(max(abs(a[i + 1] - a[i + 2]), max(abs(a[i + 2] - c1), x)) == y){
                a[i] = c1;
                found[c1] = 1;
            }
            else{
                a[i] = c2;
                found[c2] = 1;
            }
        }
    }
	for(int i = 1; i <= n; i++) {
		answer(i, a[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:18:9: warning: unused variable 'l' [-Wunused-variable]
   18 |     int l = 1, r = n;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 3 ms 308 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 304 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 3 ms 308 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 304 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
16 Correct 6 ms 200 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 14 ms 304 KB Output is correct
19 Correct 16 ms 200 KB Output is correct
20 Correct 18 ms 288 KB Output is correct
21 Correct 10 ms 200 KB Output is correct
22 Correct 15 ms 308 KB Output is correct
23 Correct 13 ms 200 KB Output is correct
24 Correct 14 ms 292 KB Output is correct
25 Correct 10 ms 200 KB Output is correct
26 Correct 14 ms 312 KB Output is correct
27 Correct 13 ms 308 KB Output is correct
28 Correct 15 ms 316 KB Output is correct
29 Correct 17 ms 292 KB Output is correct
30 Correct 17 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 200 KB Output is correct
4 Correct 3 ms 308 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 304 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 2 ms 200 KB Output is correct
9 Correct 2 ms 200 KB Output is correct
10 Correct 2 ms 200 KB Output is correct
11 Correct 2 ms 200 KB Output is correct
12 Correct 2 ms 200 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 2 ms 200 KB Output is correct
15 Correct 2 ms 200 KB Output is correct
16 Correct 6 ms 200 KB Output is correct
17 Correct 4 ms 352 KB Output is correct
18 Correct 14 ms 304 KB Output is correct
19 Correct 16 ms 200 KB Output is correct
20 Correct 18 ms 288 KB Output is correct
21 Correct 10 ms 200 KB Output is correct
22 Correct 15 ms 308 KB Output is correct
23 Correct 13 ms 200 KB Output is correct
24 Correct 14 ms 292 KB Output is correct
25 Correct 10 ms 200 KB Output is correct
26 Correct 14 ms 312 KB Output is correct
27 Correct 13 ms 308 KB Output is correct
28 Correct 15 ms 316 KB Output is correct
29 Correct 17 ms 292 KB Output is correct
30 Correct 17 ms 200 KB Output is correct
31 Correct 28 ms 320 KB Output is correct
32 Correct 39 ms 300 KB Output is correct
33 Correct 64 ms 328 KB Output is correct
34 Correct 98 ms 308 KB Output is correct
35 Correct 68 ms 440 KB Output is correct
36 Correct 33 ms 300 KB Output is correct
37 Correct 51 ms 316 KB Output is correct
38 Correct 29 ms 332 KB Output is correct
39 Correct 36 ms 328 KB Output is correct
40 Correct 72 ms 316 KB Output is correct
41 Correct 73 ms 316 KB Output is correct
42 Correct 51 ms 308 KB Output is correct
43 Correct 63 ms 316 KB Output is correct
44 Correct 65 ms 312 KB Output is correct
45 Correct 39 ms 304 KB Output is correct
46 Correct 42 ms 328 KB Output is correct
47 Correct 83 ms 316 KB Output is correct
48 Correct 70 ms 328 KB Output is correct
49 Correct 57 ms 320 KB Output is correct
50 Correct 48 ms 304 KB Output is correct
51 Correct 59 ms 312 KB Output is correct
52 Correct 74 ms 320 KB Output is correct
53 Correct 71 ms 324 KB Output is correct
54 Correct 69 ms 328 KB Output is correct
55 Correct 71 ms 332 KB Output is correct
56 Correct 59 ms 312 KB Output is correct
57 Correct 79 ms 444 KB Output is correct
58 Correct 47 ms 444 KB Output is correct
59 Correct 37 ms 308 KB Output is correct
60 Correct 75 ms 336 KB Output is correct