# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
307128 |
2020-09-27T07:17:05 Z |
syy |
Xylophone (JOI18_xylophone) |
C++17 |
|
98 ms |
632 KB |
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
int n, arr[5005], adj[5005], tri[5005];
void solve(int N) {
n = N;
FOR(i, 1, n-1) adj[i] = query(i, i+1);
FOR(i, 1, n-2) tri[i] = query(i, i+2);
arr[1] = 1, arr[2] = 1 + adj[1];
FOR(i, 1, n-2) {
if (tri[i] == adj[i] + adj[i+1]) {
if (arr[i+1] > arr[i]) arr[i+2] = arr[i] + tri[i];
else arr[i+2] = arr[i] - tri[i];
} else {
if (arr[i+1] > arr[i]) arr[i+2] = arr[i+1] - adj[i+1];
else arr[i+2] = arr[i+1] + adj[i+1];
}
}
pi s = pi(INF, 0), b = pi(0, 0);
FOR(i, 1, n) s = min(s, pi(arr[i], i)), b = max(b, pi(arr[i], i));
if (s.s > b.s) {
arr[1] = 1, arr[2] = 1 - adj[1];
FOR(i, 1, n-2) {
if (tri[i] == adj[i] + adj[i+1]) {
if (arr[i+1] > arr[i]) arr[i+2] = arr[i] + tri[i];
else arr[i+2] = arr[i] - tri[i];
} else {
if (arr[i+1] > arr[i]) arr[i+2] = arr[i+1] - adj[i+1];
else arr[i+2] = arr[i+1] + adj[i+1];
}
}
s = pi(INF, 0), b = pi(0, 0);
FOR(i, 1, n) s = min(s, pi(arr[i], i)), b = max(b, pi(arr[i], i));
}
FOR(i, 1, n) answer(i, arr[i] + n-b.f);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
8 ms |
384 KB |
Output is correct |
18 |
Correct |
18 ms |
384 KB |
Output is correct |
19 |
Correct |
19 ms |
384 KB |
Output is correct |
20 |
Correct |
18 ms |
504 KB |
Output is correct |
21 |
Correct |
15 ms |
384 KB |
Output is correct |
22 |
Correct |
19 ms |
384 KB |
Output is correct |
23 |
Correct |
10 ms |
384 KB |
Output is correct |
24 |
Correct |
16 ms |
384 KB |
Output is correct |
25 |
Correct |
18 ms |
384 KB |
Output is correct |
26 |
Correct |
23 ms |
384 KB |
Output is correct |
27 |
Correct |
18 ms |
384 KB |
Output is correct |
28 |
Correct |
15 ms |
384 KB |
Output is correct |
29 |
Correct |
17 ms |
504 KB |
Output is correct |
30 |
Correct |
18 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
8 ms |
384 KB |
Output is correct |
18 |
Correct |
18 ms |
384 KB |
Output is correct |
19 |
Correct |
19 ms |
384 KB |
Output is correct |
20 |
Correct |
18 ms |
504 KB |
Output is correct |
21 |
Correct |
15 ms |
384 KB |
Output is correct |
22 |
Correct |
19 ms |
384 KB |
Output is correct |
23 |
Correct |
10 ms |
384 KB |
Output is correct |
24 |
Correct |
16 ms |
384 KB |
Output is correct |
25 |
Correct |
18 ms |
384 KB |
Output is correct |
26 |
Correct |
23 ms |
384 KB |
Output is correct |
27 |
Correct |
18 ms |
384 KB |
Output is correct |
28 |
Correct |
15 ms |
384 KB |
Output is correct |
29 |
Correct |
17 ms |
504 KB |
Output is correct |
30 |
Correct |
18 ms |
384 KB |
Output is correct |
31 |
Correct |
43 ms |
384 KB |
Output is correct |
32 |
Correct |
59 ms |
392 KB |
Output is correct |
33 |
Correct |
47 ms |
396 KB |
Output is correct |
34 |
Correct |
86 ms |
504 KB |
Output is correct |
35 |
Correct |
88 ms |
384 KB |
Output is correct |
36 |
Correct |
95 ms |
384 KB |
Output is correct |
37 |
Correct |
77 ms |
476 KB |
Output is correct |
38 |
Correct |
98 ms |
384 KB |
Output is correct |
39 |
Correct |
96 ms |
384 KB |
Output is correct |
40 |
Correct |
86 ms |
504 KB |
Output is correct |
41 |
Correct |
88 ms |
504 KB |
Output is correct |
42 |
Correct |
90 ms |
384 KB |
Output is correct |
43 |
Correct |
79 ms |
632 KB |
Output is correct |
44 |
Correct |
92 ms |
384 KB |
Output is correct |
45 |
Correct |
85 ms |
384 KB |
Output is correct |
46 |
Correct |
95 ms |
392 KB |
Output is correct |
47 |
Correct |
93 ms |
384 KB |
Output is correct |
48 |
Correct |
85 ms |
384 KB |
Output is correct |
49 |
Correct |
68 ms |
504 KB |
Output is correct |
50 |
Correct |
96 ms |
384 KB |
Output is correct |
51 |
Correct |
97 ms |
384 KB |
Output is correct |
52 |
Correct |
90 ms |
504 KB |
Output is correct |
53 |
Correct |
93 ms |
384 KB |
Output is correct |
54 |
Correct |
96 ms |
384 KB |
Output is correct |
55 |
Correct |
78 ms |
508 KB |
Output is correct |
56 |
Correct |
56 ms |
384 KB |
Output is correct |
57 |
Correct |
90 ms |
384 KB |
Output is correct |
58 |
Correct |
86 ms |
512 KB |
Output is correct |
59 |
Correct |
94 ms |
384 KB |
Output is correct |
60 |
Correct |
87 ms |
384 KB |
Output is correct |