답안 #389561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389561 2021-04-14T07:28:04 Z maximath_1 Xylophone (JOI18_xylophone) C++11
100 / 100
161 ms 456 KB
#include "xylophone.h"
#include <vector>
#include <math.h>
#include <iostream>
#include <assert.h>
using namespace std;

int diff[5005];
int ans[5005];

void solve(int N){
	for(int i = 2; i <= N; i ++){
		if(i == 2) diff[i] = query(i - 1, i);
		else{
			int nw = query(i - 1, i), bf = query(i - 2, i);
			if(abs(nw) + abs(diff[i - 1]) == bf){
				diff[i] = nw;
				if(diff[i - 1] < 0) diff[i] *= -1;
				assert(abs(abs(diff[i - 1]) + abs(diff[i])) == bf);
			}else{
				diff[i] = nw;
				if(diff[i - 1] > 0) diff[i] *= -1;
				assert(max(abs(diff[i - 1]), abs(diff[i])) == bf);
			}
		}
	}

	ans[1] = 1;
	for(int i = 2; i <= N; i ++)
		ans[i] = diff[i] + ans[i - 1];

	int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0;
	for(int i = 1; i <= N; i ++){
		if(mn > ans[i]){
			mn = ans[i]; mnid = i;
		}
		if(mx < ans[i]){
			mx = ans[i]; mxid = i;
		}
	}

	for(int i = 1; i <= N; i ++)
		ans[i] += -mn + 1;

	if(mnid > mxid){
		ans[1] = 1;
		for(int i = 2; i <= N; i ++)
			ans[i] = -diff[i] + ans[i - 1];

		int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0;
		for(int i = 1; i <= N; i ++){
			if(mn > ans[i]){
				mn = ans[i]; mnid = i;
			}
			if(mx < ans[i]){
				mx = ans[i]; mxid = i;
			}
		}

		for(int i = 1; i <= N; i ++)
			ans[i] += -mn + 1;
	}

	for(int i = 1; i <= N; i ++)
		answer(i, ans[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:50:38: warning: variable 'mnid' set but not used [-Wunused-but-set-variable]
   50 |   int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0;
      |                                      ^~~~
xylophone.cpp:50:48: warning: variable 'mxid' set but not used [-Wunused-but-set-variable]
   50 |   int mn = 69696969, mx = -69696969, mnid = 0, mxid = 0;
      |                                                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 3 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 3 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 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 3 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 3 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 6 ms 200 KB Output is correct
17 Correct 14 ms 200 KB Output is correct
18 Correct 13 ms 200 KB Output is correct
19 Correct 25 ms 200 KB Output is correct
20 Correct 25 ms 272 KB Output is correct
21 Correct 22 ms 320 KB Output is correct
22 Correct 25 ms 200 KB Output is correct
23 Correct 25 ms 284 KB Output is correct
24 Correct 26 ms 200 KB Output is correct
25 Correct 21 ms 288 KB Output is correct
26 Correct 15 ms 200 KB Output is correct
27 Correct 24 ms 284 KB Output is correct
28 Correct 25 ms 200 KB Output is correct
29 Correct 22 ms 320 KB Output is correct
30 Correct 26 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 3 ms 200 KB Output is correct
4 Correct 3 ms 200 KB Output is correct
5 Correct 2 ms 200 KB Output is correct
6 Correct 3 ms 200 KB Output is correct
7 Correct 2 ms 200 KB Output is correct
8 Correct 3 ms 200 KB Output is correct
9 Correct 3 ms 200 KB Output is correct
10 Correct 3 ms 200 KB Output is correct
11 Correct 3 ms 200 KB Output is correct
12 Correct 3 ms 200 KB Output is correct
13 Correct 3 ms 200 KB Output is correct
14 Correct 3 ms 200 KB Output is correct
15 Correct 3 ms 200 KB Output is correct
16 Correct 6 ms 200 KB Output is correct
17 Correct 14 ms 200 KB Output is correct
18 Correct 13 ms 200 KB Output is correct
19 Correct 25 ms 200 KB Output is correct
20 Correct 25 ms 272 KB Output is correct
21 Correct 22 ms 320 KB Output is correct
22 Correct 25 ms 200 KB Output is correct
23 Correct 25 ms 284 KB Output is correct
24 Correct 26 ms 200 KB Output is correct
25 Correct 21 ms 288 KB Output is correct
26 Correct 15 ms 200 KB Output is correct
27 Correct 24 ms 284 KB Output is correct
28 Correct 25 ms 200 KB Output is correct
29 Correct 22 ms 320 KB Output is correct
30 Correct 26 ms 200 KB Output is correct
31 Correct 47 ms 304 KB Output is correct
32 Correct 76 ms 412 KB Output is correct
33 Correct 83 ms 300 KB Output is correct
34 Correct 108 ms 284 KB Output is correct
35 Correct 126 ms 320 KB Output is correct
36 Correct 109 ms 292 KB Output is correct
37 Correct 140 ms 296 KB Output is correct
38 Correct 108 ms 324 KB Output is correct
39 Correct 93 ms 280 KB Output is correct
40 Correct 92 ms 296 KB Output is correct
41 Correct 109 ms 428 KB Output is correct
42 Correct 160 ms 300 KB Output is correct
43 Correct 130 ms 284 KB Output is correct
44 Correct 104 ms 420 KB Output is correct
45 Correct 161 ms 300 KB Output is correct
46 Correct 79 ms 316 KB Output is correct
47 Correct 104 ms 292 KB Output is correct
48 Correct 49 ms 296 KB Output is correct
49 Correct 125 ms 292 KB Output is correct
50 Correct 155 ms 292 KB Output is correct
51 Correct 89 ms 292 KB Output is correct
52 Correct 89 ms 288 KB Output is correct
53 Correct 131 ms 332 KB Output is correct
54 Correct 135 ms 296 KB Output is correct
55 Correct 98 ms 424 KB Output is correct
56 Correct 50 ms 296 KB Output is correct
57 Correct 110 ms 300 KB Output is correct
58 Correct 122 ms 452 KB Output is correct
59 Correct 103 ms 456 KB Output is correct
60 Correct 74 ms 296 KB Output is correct