#include "xylophone.h"
using namespace std;
#include <bits/stdc++.h>
static int A[5005];
int n;
int d2[5005], d3[5005];
void pr(const vector<int>& a) {
cout << "VEC:\n";
for (int i: a) cout << i << ' ';
cout << '\n';
}
bool check(const vector<int>& v) {
//pr(v);
for (int i = 0; i < n; i++) if (v[i] <= 0 || v[i] > n) return false;
for (int i = 0; i < n - 1; i++) {
if (abs(v[i+1]-v[i]) != d2[i+1]) return false;
}
for (int i = 0; i < n - 2; i++) {
int d = max(abs(v[i+2]-v[i+1]),max(abs(v[i+1]-v[i]),abs(v[i+2]-v[i])));
if (d != d3[i+1]) return false;
}
//sanity checks
int pos1 = -1, posn = -1;
for (int i = 0; i < n; i++) {
if (v[i] == 1) pos1 = i;
else if (v[i] == n) posn = i;
}
if (pos1 == -1 || pos1 == -1) return false;
if (pos1 > posn) return false;
return true;
}
bool tr(int i) {
//cout << "starting " << i << endl;
vector<int> a, b;
a.push_back(i);
b.push_back(i);
if (d3[1] == d2[1] + d2[2]) {
a.push_back(a.back()+d2[1]);
a.push_back(a.back()+d2[2]);
b.push_back(b.back()-d2[1]);
b.push_back(b.back()-d2[2]);
}
else {
a.push_back(a.back()+d2[1]);
a.push_back(a.back()-d2[2]);
b.push_back(b.back()-d2[1]);
b.push_back(b.back()+d2[2]);
}
for (int j = 2; j <= n - 2; j++) {
vector<int>& aa = a;
vector<int>& bb = b;
if (a.back() < a[a.size()-2]) swap(a,b);
if (d3[j] == d2[j] + d2[j+1]) {
a.push_back(a.back()+d2[j+1]);
b.push_back(b.back()-d2[j+1]);
}
else {
a.push_back(a.back()-d2[j+1]);
b.push_back(b.back()+d2[j+1]);
}
}
if (check(a)) {
for (int i = 0; i < n; i++) {
answer(i+1,a[i]);
//cout << (i+1) << ": " << a[i] << endl;
}
return true;
}
else if (check(b)) {
for (int i = 0; i < n; i++) {
answer(i+1,b[i]);
//cout << (i+1) << ": " << b[i] << endl;
}
return true;
}
return false;
}
void solve(int N) {
n = N;
for (int i = 1; i <= N - 1; i++) {
d2[i] = query(i,i+1);
//cout << i << ' ' << i+1 << ": " << d2[i] << '\n';
}
for (int i = 1; i <= N - 2; i++) {
d3[i] = query(i,i+2);
//cout << i << ' ' << i+2 << ": " << d3[i] << '\n';
}
for (int i = 1; i <= N; i++) {
if (tr(i)) break;
}
}
Compilation message
xylophone.cpp: In function 'bool tr(int)':
xylophone.cpp:56:22: warning: unused variable 'aa' [-Wunused-variable]
vector<int>& aa = a;
^~
xylophone.cpp:57:22: warning: unused variable 'bb' [-Wunused-variable]
vector<int>& bb = b;
^~
xylophone.cpp: At global scope:
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[5005];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
320 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
320 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
256 KB |
Output is correct |
17 |
Correct |
10 ms |
424 KB |
Output is correct |
18 |
Correct |
18 ms |
324 KB |
Output is correct |
19 |
Correct |
23 ms |
336 KB |
Output is correct |
20 |
Correct |
20 ms |
392 KB |
Output is correct |
21 |
Correct |
28 ms |
324 KB |
Output is correct |
22 |
Correct |
26 ms |
384 KB |
Output is correct |
23 |
Correct |
20 ms |
328 KB |
Output is correct |
24 |
Correct |
21 ms |
384 KB |
Output is correct |
25 |
Correct |
19 ms |
256 KB |
Output is correct |
26 |
Correct |
26 ms |
256 KB |
Output is correct |
27 |
Correct |
14 ms |
412 KB |
Output is correct |
28 |
Correct |
21 ms |
304 KB |
Output is correct |
29 |
Correct |
49 ms |
256 KB |
Output is correct |
30 |
Correct |
20 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
320 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
256 KB |
Output is correct |
17 |
Correct |
10 ms |
424 KB |
Output is correct |
18 |
Correct |
18 ms |
324 KB |
Output is correct |
19 |
Correct |
23 ms |
336 KB |
Output is correct |
20 |
Correct |
20 ms |
392 KB |
Output is correct |
21 |
Correct |
28 ms |
324 KB |
Output is correct |
22 |
Correct |
26 ms |
384 KB |
Output is correct |
23 |
Correct |
20 ms |
328 KB |
Output is correct |
24 |
Correct |
21 ms |
384 KB |
Output is correct |
25 |
Correct |
19 ms |
256 KB |
Output is correct |
26 |
Correct |
26 ms |
256 KB |
Output is correct |
27 |
Correct |
14 ms |
412 KB |
Output is correct |
28 |
Correct |
21 ms |
304 KB |
Output is correct |
29 |
Correct |
49 ms |
256 KB |
Output is correct |
30 |
Correct |
20 ms |
384 KB |
Output is correct |
31 |
Correct |
37 ms |
376 KB |
Output is correct |
32 |
Correct |
135 ms |
392 KB |
Output is correct |
33 |
Correct |
148 ms |
552 KB |
Output is correct |
34 |
Correct |
209 ms |
376 KB |
Output is correct |
35 |
Correct |
284 ms |
504 KB |
Output is correct |
36 |
Correct |
77 ms |
344 KB |
Output is correct |
37 |
Correct |
201 ms |
428 KB |
Output is correct |
38 |
Correct |
42 ms |
552 KB |
Output is correct |
39 |
Correct |
92 ms |
460 KB |
Output is correct |
40 |
Correct |
227 ms |
468 KB |
Output is correct |
41 |
Correct |
240 ms |
552 KB |
Output is correct |
42 |
Correct |
54 ms |
376 KB |
Output is correct |
43 |
Correct |
176 ms |
652 KB |
Output is correct |
44 |
Correct |
64 ms |
524 KB |
Output is correct |
45 |
Correct |
101 ms |
448 KB |
Output is correct |
46 |
Correct |
240 ms |
504 KB |
Output is correct |
47 |
Correct |
235 ms |
504 KB |
Output is correct |
48 |
Correct |
83 ms |
340 KB |
Output is correct |
49 |
Correct |
242 ms |
508 KB |
Output is correct |
50 |
Correct |
258 ms |
392 KB |
Output is correct |
51 |
Correct |
161 ms |
428 KB |
Output is correct |
52 |
Correct |
81 ms |
528 KB |
Output is correct |
53 |
Correct |
252 ms |
444 KB |
Output is correct |
54 |
Correct |
250 ms |
584 KB |
Output is correct |
55 |
Correct |
253 ms |
348 KB |
Output is correct |
56 |
Correct |
305 ms |
572 KB |
Output is correct |
57 |
Correct |
261 ms |
380 KB |
Output is correct |
58 |
Correct |
352 ms |
504 KB |
Output is correct |
59 |
Correct |
201 ms |
424 KB |
Output is correct |
60 |
Correct |
178 ms |
576 KB |
Output is correct |