답안 #1114462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114462 2024-11-18T23:41:38 Z sunboi Xylophone (JOI18_xylophone) C++17
100 / 100
137 ms 508 KB
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#include "xylophone.h"
 
static int A[5000];
 
 
void solve(int N){
    int n = N;
    int i = 1, fin = n;
    while(i < fin){
        int m = (i + fin) / 2;
        if (query(m, n) == n - 1){
            i = m + 1; 
        }else fin = m;
    }
    i--;
    int reference = i;
    vector<int> a(n + 1), vis(n + 1);
    int x = query(i, i + 1);
    a[i] = 1;
    a[i + 1] = x + 1;
    i += 2;
    vis[1] = vis[x + 1] = 1;
    int last = x;
    
    for (; i <= n; i++){
        int mn = min(a[i - 1], a[i - 2]);
        int uno = query(i - 1, i);
        
        if (a[i - 1] + uno > n) a[i] = a[i - 1] - uno;
        else if (a[i - 1] + uno < 1) a[i] = a[i - 1] + uno;
        else if (vis[a[i - 1] + uno]) a[i] = a[i - 1] - uno;
        else if (vis[a[i - 1] - uno]) a[i] = a[i - 1] + uno;
        else{
            int dos = query(i - 2, i);
        
            if (dos > last){
                if (dos == uno){
                    if (a[i - 1] == mn) a[i] = a[i - 1] + uno;
                    else a[i] = a[i - 1] - uno;
                }else{
                    if (a[i - 2] == mn) a[i] = a[i - 2] + dos;
                    else  a[i] = a[i - 2] - dos;
                }
            }else{
                if (a[i - 1] == mn) a[i] = a[i - 1] + uno;
                else a[i] = a[i - 1] - uno;
            }
        }
        vis[a[i]] = 1;
        last = uno;
    }
    i = reference;
	if (i > 1){
		x = query(i - 1, i);
		a[i - 1] = 1 + x;
		vis[1 + x] = 1;
		last = x;
		i -= 2;
		for (; i >= 1; i--){
			int mn = min(a[i + 1], a[i + 2]);
			int uno = query(i, i + 1);
			if (a[i + 1] + uno > n) a[i] = a[i + 1] - uno;
            else if (a[i + 1] + uno < 1) a[i] = a[i + 1] + uno;
            else if (vis[a[i + 1] + uno]) a[i] = a[i + 1] - uno;
            else if (vis[a[i + 1] - uno]) a[i] = a[i + 1] + uno;
			else{
			    int dos = query(i, i + 2);
			    if (dos > last){
    				if (dos == uno){
    					if (a[i + 1] == mn) a[i] = a[i + 1] + uno;
    					else a[i] = a[i + 1] - uno;
    				}else{
    					if (a[i + 2] == mn) a[i] = a[i + 2] + dos;
    					else  a[i] = a[i + 2] - dos;
    				}
    			}else{
    				if (a[i + 1] == mn) a[i] = a[i + 1] + uno;
    				else a[i] = a[i + 1] - uno;
    			}
			}
			
			vis[a[i]] = 1;
			last = uno;
		}
	}
    for(int i = 1;i<=n;i++) answer(i, a[i]);
	return;
}

Compilation message

xylophone.cpp:8:12: warning: 'A' defined but not used [-Wunused-variable]
    8 | static int A[5000];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 3 ms 508 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 3 ms 508 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
16 Correct 6 ms 336 KB Output is correct
17 Correct 8 ms 336 KB Output is correct
18 Correct 18 ms 336 KB Output is correct
19 Correct 23 ms 336 KB Output is correct
20 Correct 20 ms 336 KB Output is correct
21 Correct 21 ms 336 KB Output is correct
22 Correct 20 ms 504 KB Output is correct
23 Correct 16 ms 336 KB Output is correct
24 Correct 21 ms 336 KB Output is correct
25 Correct 21 ms 336 KB Output is correct
26 Correct 19 ms 336 KB Output is correct
27 Correct 15 ms 336 KB Output is correct
28 Correct 20 ms 336 KB Output is correct
29 Correct 22 ms 336 KB Output is correct
30 Correct 19 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 336 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 3 ms 508 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 3 ms 336 KB Output is correct
16 Correct 6 ms 336 KB Output is correct
17 Correct 8 ms 336 KB Output is correct
18 Correct 18 ms 336 KB Output is correct
19 Correct 23 ms 336 KB Output is correct
20 Correct 20 ms 336 KB Output is correct
21 Correct 21 ms 336 KB Output is correct
22 Correct 20 ms 504 KB Output is correct
23 Correct 16 ms 336 KB Output is correct
24 Correct 21 ms 336 KB Output is correct
25 Correct 21 ms 336 KB Output is correct
26 Correct 19 ms 336 KB Output is correct
27 Correct 15 ms 336 KB Output is correct
28 Correct 20 ms 336 KB Output is correct
29 Correct 22 ms 336 KB Output is correct
30 Correct 19 ms 336 KB Output is correct
31 Correct 44 ms 336 KB Output is correct
32 Correct 69 ms 460 KB Output is correct
33 Correct 113 ms 336 KB Output is correct
34 Correct 109 ms 468 KB Output is correct
35 Correct 103 ms 336 KB Output is correct
36 Correct 80 ms 336 KB Output is correct
37 Correct 90 ms 336 KB Output is correct
38 Correct 103 ms 336 KB Output is correct
39 Correct 120 ms 504 KB Output is correct
40 Correct 128 ms 336 KB Output is correct
41 Correct 117 ms 336 KB Output is correct
42 Correct 65 ms 472 KB Output is correct
43 Correct 117 ms 468 KB Output is correct
44 Correct 114 ms 336 KB Output is correct
45 Correct 112 ms 336 KB Output is correct
46 Correct 96 ms 468 KB Output is correct
47 Correct 128 ms 468 KB Output is correct
48 Correct 124 ms 336 KB Output is correct
49 Correct 109 ms 464 KB Output is correct
50 Correct 120 ms 336 KB Output is correct
51 Correct 137 ms 336 KB Output is correct
52 Correct 113 ms 336 KB Output is correct
53 Correct 130 ms 336 KB Output is correct
54 Correct 135 ms 336 KB Output is correct
55 Correct 116 ms 336 KB Output is correct
56 Correct 131 ms 336 KB Output is correct
57 Correct 118 ms 336 KB Output is correct
58 Correct 119 ms 336 KB Output is correct
59 Correct 124 ms 336 KB Output is correct
60 Correct 133 ms 336 KB Output is correct