#include "xylophone.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x.size() )
#define all(x) x.begin(),x.end()
const int MAX = 5010 ;
using namespace std ;
map< pair<int,int> , int > mp ;
void trying(vector<int> &vec )
{
for(int i = 3 ; i < sz(vec) ; i++ )
{
int val12 = abs(vec[i-1]-vec[i-2] ) ;
int val23 = mp[ make_pair(i-1,i) ] ;
int val13 = mp[ make_pair(i-2,i) ] ;
if(val12 + val23 == val13 )
{
vec[i] = vec[i-2] + val13 ;
if( vec[i-1] < vec[i-2] ) vec[i] = vec[i-2] - val13 ;
}
else
{
vec[i] = vec[i-1] + val23 ;
if( vec[i-1] > vec[i-2] ) vec[i] = vec[i-1] - val23 ;
}
}
int mn = *min_element(all(vec) ) ;
for(int &i : vec ) i += 1-mn ;
}
void giveAns(vector<int> vec)
{
for(int i = 1 ; i < sz(vec) ; i++ ) answer(i,vec[i] ) ;
}
void solve(int n)
{
int firstAbs = query(1,2) ;
vector<int> seq1(n+1,0) ; //a[1] < a[2]
vector<int> seq2(n+1, 0) ; //a[1] > a[2]
seq1[2] = firstAbs ;
seq2[2] = -firstAbs ;
for(int i = 3 ; i <= n ; i++ )
{
mp[ make_pair(i-2,i) ] = query(i-2, i) ;
mp[ make_pair(i-1,i) ] = query(i-1,i) ;
}
trying(seq1) ;
trying(seq2) ;
int idx1 = -1, idx2 = -1 ;
for(int i = 1 ; i <= n ; i++ )
if(seq1[i] == 1 ) idx1 = i ;
for(int i = 1 ; i <= n ; i++ )
if(seq2[i] == 1 ) idx2 =i ;
if(idx1 == -1 ) giveAns(seq2) ;
if(idx2 == -1 ) giveAns(seq1) ;
if(idx2 > idx1 )
{
if(query(idx2, n) == n-1 ) giveAns(seq2) ;
else giveAns(seq1) ;
}
else
{
if(query(idx1, n) == n-1 ) giveAns(seq1);
else giveAns(seq2) ;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
63 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
364 KB |
Output is correct |
6 |
Correct |
84 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
92 ms |
364 KB |
Output is correct |
11 |
Correct |
92 ms |
364 KB |
Output is correct |
12 |
Correct |
28 ms |
492 KB |
Output is correct |
13 |
Correct |
93 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
63 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
364 KB |
Output is correct |
6 |
Correct |
84 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
92 ms |
364 KB |
Output is correct |
11 |
Correct |
92 ms |
364 KB |
Output is correct |
12 |
Correct |
28 ms |
492 KB |
Output is correct |
13 |
Correct |
93 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
56 ms |
364 KB |
Output is correct |
17 |
Correct |
10 ms |
364 KB |
Output is correct |
18 |
Correct |
15 ms |
364 KB |
Output is correct |
19 |
Correct |
21 ms |
492 KB |
Output is correct |
20 |
Correct |
20 ms |
492 KB |
Output is correct |
21 |
Correct |
94 ms |
396 KB |
Output is correct |
22 |
Correct |
94 ms |
492 KB |
Output is correct |
23 |
Correct |
113 ms |
504 KB |
Output is correct |
24 |
Correct |
32 ms |
512 KB |
Output is correct |
25 |
Correct |
27 ms |
492 KB |
Output is correct |
26 |
Correct |
46 ms |
492 KB |
Output is correct |
27 |
Correct |
15 ms |
492 KB |
Output is correct |
28 |
Correct |
106 ms |
492 KB |
Output is correct |
29 |
Correct |
26 ms |
492 KB |
Output is correct |
30 |
Correct |
18 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
63 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
3 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
364 KB |
Output is correct |
6 |
Correct |
84 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
92 ms |
364 KB |
Output is correct |
11 |
Correct |
92 ms |
364 KB |
Output is correct |
12 |
Correct |
28 ms |
492 KB |
Output is correct |
13 |
Correct |
93 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
56 ms |
364 KB |
Output is correct |
17 |
Correct |
10 ms |
364 KB |
Output is correct |
18 |
Correct |
15 ms |
364 KB |
Output is correct |
19 |
Correct |
21 ms |
492 KB |
Output is correct |
20 |
Correct |
20 ms |
492 KB |
Output is correct |
21 |
Correct |
94 ms |
396 KB |
Output is correct |
22 |
Correct |
94 ms |
492 KB |
Output is correct |
23 |
Correct |
113 ms |
504 KB |
Output is correct |
24 |
Correct |
32 ms |
512 KB |
Output is correct |
25 |
Correct |
27 ms |
492 KB |
Output is correct |
26 |
Correct |
46 ms |
492 KB |
Output is correct |
27 |
Correct |
15 ms |
492 KB |
Output is correct |
28 |
Correct |
106 ms |
492 KB |
Output is correct |
29 |
Correct |
26 ms |
492 KB |
Output is correct |
30 |
Correct |
18 ms |
492 KB |
Output is correct |
31 |
Correct |
37 ms |
620 KB |
Output is correct |
32 |
Correct |
81 ms |
876 KB |
Output is correct |
33 |
Correct |
66 ms |
876 KB |
Output is correct |
34 |
Correct |
95 ms |
1004 KB |
Output is correct |
35 |
Correct |
183 ms |
1004 KB |
Output is correct |
36 |
Correct |
164 ms |
1004 KB |
Output is correct |
37 |
Correct |
200 ms |
1004 KB |
Output is correct |
38 |
Correct |
113 ms |
1004 KB |
Output is correct |
39 |
Correct |
266 ms |
1132 KB |
Output is correct |
40 |
Correct |
231 ms |
1004 KB |
Output is correct |
41 |
Correct |
267 ms |
1004 KB |
Output is correct |
42 |
Correct |
120 ms |
920 KB |
Output is correct |
43 |
Correct |
247 ms |
1004 KB |
Output is correct |
44 |
Correct |
130 ms |
1048 KB |
Output is correct |
45 |
Correct |
295 ms |
996 KB |
Output is correct |
46 |
Correct |
87 ms |
1004 KB |
Output is correct |
47 |
Correct |
247 ms |
1004 KB |
Output is correct |
48 |
Correct |
245 ms |
1012 KB |
Output is correct |
49 |
Correct |
211 ms |
1004 KB |
Output is correct |
50 |
Correct |
240 ms |
1132 KB |
Output is correct |
51 |
Correct |
155 ms |
1004 KB |
Output is correct |
52 |
Correct |
98 ms |
996 KB |
Output is correct |
53 |
Correct |
250 ms |
1132 KB |
Output is correct |
54 |
Correct |
123 ms |
1004 KB |
Output is correct |
55 |
Correct |
106 ms |
1004 KB |
Output is correct |
56 |
Correct |
279 ms |
1192 KB |
Output is correct |
57 |
Correct |
240 ms |
1004 KB |
Output is correct |
58 |
Correct |
95 ms |
1004 KB |
Output is correct |
59 |
Correct |
229 ms |
1004 KB |
Output is correct |
60 |
Correct |
235 ms |
1116 KB |
Output is correct |