Submission #590492

# Submission time Handle Problem Language Result Execution time Memory
590492 2022-07-06T03:50:30 Z Do_you_copy Xylophone (JOI18_xylophone) C++14
100 / 100
91 ms 440 KB
#include <bits/stdc++.h>
#include <xylophone.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
 
using ll = long long;
using pii = pair <int, int>;
 
ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}
 
ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}
 
const ll Mod = 1000000007;
const int maxN = 1e5 + 1;
int n;
int a[maxN];
 
bool counted[maxN];
 
void solve(int N){
    n = N;
    int l = 1, r = n - 1;
    while (l <= r){
        int m = (l + r) / 2;
        if (query(m, n) == n - 1) l = m + 1;
        else r = m - 1;
    }
    a[r] = 1;
    answer(r, a[r]);
  	counted[a[r]] = 1;
    a[r + 1] = a[r] + query(r, r + 1);
    answer(r + 1, a[r + 1]);
  	counted[a[r + 1]] = 1;
    for (int i = r + 2; i <= n; ++i){
        int x = a[i - 2];
        int y = a[i - 1];
        int d2 = query(i - 1, i);
        if (a[i - 1] + d2 > n || counted[a[i - 1] + d2]){
            a[i] = a[i - 1] - d2;
            answer(i, a[i]);
          	counted[a[i]] = 1;
            continue;
        }
        if (a[i - 1] - d2 < 1 || counted[a[i - 1] - d2]){
            a[i] = a[i - 1] + d2;
            answer(i, a[i]);
          	counted[a[i]] = 1;
            continue;
        }
        int d1 = query(i - 2, i);
        int c = a[i - 1] - d2;
        int minn = min(min(c, a[i - 1]), a[i - 2]);
        int maxx = max(max(c, a[i - 1]), a[i - 2]);
        if (query(i - 2, i) == maxx - minn){
            a[i] = c;
            answer(i, c);
        }
        else{
            a[i] = a[i - 1] + d2;
            answer(i, a[i]);
        }
        counted[a[i]] = 1;
    }
    if (r > 1){
        a[r - 1] = a[r] + query(r - 1, r);
        answer(r - 1, a[r - 1]);
        counted[a[r - 1]] = 1;
    }
    for (int i = r - 2; i >= 1; --i){
        int x = a[i + 2];
        int y = a[i + 1];
        int d2 = query(i, i + 1);
        if (a[i + 1] + d2 > n || counted[a[i + 1] + d2]){
            a[i] = a[i + 1] - d2;
            answer(i, a[i]);
          	counted[a[i]] = 1;
            continue;
        }
        if (a[i + 1] - d2 < 1 || counted[a[i + 1] - d2]){
            a[i] = a[i + 1] + d2;
            answer(i, a[i]);
          	counted[a[i]] = 1;
            continue;
        }
        int d1 = query(i, i + 2);
        int c = a[i + 1] - d2;
        int minn = min(min(c, a[i + 1]), a[i + 2]);
        int maxx = max(max(c, a[i + 1]), a[i + 2]);
        if (query(i, i + 2) == maxx - minn){
            a[i] = c;
            answer(i, c);
        }
        else{
            a[i] = a[i + 1] + d2;
            answer(i, a[i]);
        }
        counted[a[i]] = 1;
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:43:13: warning: unused variable 'x' [-Wunused-variable]
   43 |         int x = a[i - 2];
      |             ^
xylophone.cpp:44:13: warning: unused variable 'y' [-Wunused-variable]
   44 |         int y = a[i - 1];
      |             ^
xylophone.cpp:58:13: warning: unused variable 'd1' [-Wunused-variable]
   58 |         int d1 = query(i - 2, i);
      |             ^~
xylophone.cpp:78:13: warning: unused variable 'x' [-Wunused-variable]
   78 |         int x = a[i + 2];
      |             ^
xylophone.cpp:79:13: warning: unused variable 'y' [-Wunused-variable]
   79 |         int y = a[i + 1];
      |             ^
xylophone.cpp:93:13: warning: unused variable 'd1' [-Wunused-variable]
   93 |         int d1 = query(i, i + 2);
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 9 ms 308 KB Output is correct
18 Correct 13 ms 208 KB Output is correct
19 Correct 17 ms 208 KB Output is correct
20 Correct 14 ms 312 KB Output is correct
21 Correct 13 ms 208 KB Output is correct
22 Correct 9 ms 208 KB Output is correct
23 Correct 7 ms 208 KB Output is correct
24 Correct 9 ms 308 KB Output is correct
25 Correct 10 ms 208 KB Output is correct
26 Correct 17 ms 208 KB Output is correct
27 Correct 7 ms 316 KB Output is correct
28 Correct 8 ms 308 KB Output is correct
29 Correct 8 ms 308 KB Output is correct
30 Correct 6 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 2 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 208 KB Output is correct
12 Correct 2 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 9 ms 308 KB Output is correct
18 Correct 13 ms 208 KB Output is correct
19 Correct 17 ms 208 KB Output is correct
20 Correct 14 ms 312 KB Output is correct
21 Correct 13 ms 208 KB Output is correct
22 Correct 9 ms 208 KB Output is correct
23 Correct 7 ms 208 KB Output is correct
24 Correct 9 ms 308 KB Output is correct
25 Correct 10 ms 208 KB Output is correct
26 Correct 17 ms 208 KB Output is correct
27 Correct 7 ms 316 KB Output is correct
28 Correct 8 ms 308 KB Output is correct
29 Correct 8 ms 308 KB Output is correct
30 Correct 6 ms 320 KB Output is correct
31 Correct 30 ms 316 KB Output is correct
32 Correct 30 ms 304 KB Output is correct
33 Correct 43 ms 312 KB Output is correct
34 Correct 40 ms 424 KB Output is correct
35 Correct 59 ms 308 KB Output is correct
36 Correct 50 ms 208 KB Output is correct
37 Correct 26 ms 316 KB Output is correct
38 Correct 35 ms 316 KB Output is correct
39 Correct 82 ms 316 KB Output is correct
40 Correct 82 ms 316 KB Output is correct
41 Correct 65 ms 316 KB Output is correct
42 Correct 49 ms 324 KB Output is correct
43 Correct 42 ms 440 KB Output is correct
44 Correct 37 ms 312 KB Output is correct
45 Correct 56 ms 312 KB Output is correct
46 Correct 52 ms 428 KB Output is correct
47 Correct 91 ms 308 KB Output is correct
48 Correct 66 ms 304 KB Output is correct
49 Correct 62 ms 308 KB Output is correct
50 Correct 64 ms 316 KB Output is correct
51 Correct 74 ms 208 KB Output is correct
52 Correct 66 ms 328 KB Output is correct
53 Correct 61 ms 308 KB Output is correct
54 Correct 66 ms 208 KB Output is correct
55 Correct 72 ms 300 KB Output is correct
56 Correct 60 ms 312 KB Output is correct
57 Correct 47 ms 300 KB Output is correct
58 Correct 50 ms 312 KB Output is correct
59 Correct 75 ms 308 KB Output is correct
60 Correct 33 ms 316 KB Output is correct