Submission #638775

# Submission time Handle Problem Language Result Execution time Memory
638775 2022-09-07T11:48:54 Z ghostwriter Xylophone (JOI18_xylophone) C++14
100 / 100
116 ms 436 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
#ifndef LOCAL
	static int A[5000];
#endif
const int NMAX = 5e3 + 5;
int a[NMAX], d[NMAX], d2[NMAX], d3[NMAX];
void solve(int N) {
    FOR(i, 2, N) d2[i] = query(i - 1, i);
    FOR(i, 3, N) d3[i] = query(i - 2, i);
    FOR(i, 3, N) {
        int a = d2[i - 1], b = d2[i];
        if (a + b == d3[i]) d[i] = 0;
        else d[i] = 1;
    }
    bool op = 0;
    FOR(i, 2, N) {
        op ^= d[i];
        a[i] = a[i - 1] + d2[i] * (op == 0? 1 : -1);
    }
    int pos1 = -1, posn = -1;
    FOR(i, 1, N) {
        if (pos1 == -1 || a[i] < a[pos1]) pos1 = i;
        if (posn == -1 || a[i] > a[posn]) posn = i;
    }
    // FOR(i, 1, N) {
    //     debug(i, a[i]);
    // }
    // debug(pos1, posn);
    if (pos1 > posn) {
        FOR(i, 2, N) a[i] *= -1;
        swap(pos1, posn);
    }
    // FOR(i, 1, N) {
    //     debug(i, a[i]);
    // }
    int diff = N - a[posn];
    FOR(i, 1, N) a[i] += diff;
    FOR(i, 1, N) answer(i, a[i]);
}
/*
5
2 1 5 3 4
*/

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:44:5: note: in expansion of macro 'FOR'
   44 |     FOR(i, 2, N) d2[i] = query(i - 1, i);
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 3, N) d3[i] = query(i - 2, i);
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:46:5: note: in expansion of macro 'FOR'
   46 |     FOR(i, 3, N) {
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i, 2, N) {
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:57:5: note: in expansion of macro 'FOR'
   57 |     FOR(i, 1, N) {
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:66:9: note: in expansion of macro 'FOR'
   66 |         FOR(i, 2, N) a[i] *= -1;
      |         ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:73:5: note: in expansion of macro 'FOR'
   73 |     FOR(i, 1, N) a[i] += diff;
      |     ^~~
xylophone.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
xylophone.cpp:74:5: note: in expansion of macro 'FOR'
   74 |     FOR(i, 1, N) answer(i, a[i]);
      |     ^~~
xylophone.cpp: At global scope:
xylophone.cpp:39:13: warning: 'A' defined but not used [-Wunused-variable]
   39 |  static int A[5000];
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 312 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 3 ms 316 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 2 ms 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 312 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 3 ms 316 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 2 ms 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 2 ms 312 KB Output is correct
17 Correct 12 ms 208 KB Output is correct
18 Correct 13 ms 324 KB Output is correct
19 Correct 14 ms 300 KB Output is correct
20 Correct 17 ms 316 KB Output is correct
21 Correct 14 ms 324 KB Output is correct
22 Correct 13 ms 316 KB Output is correct
23 Correct 13 ms 320 KB Output is correct
24 Correct 23 ms 308 KB Output is correct
25 Correct 21 ms 300 KB Output is correct
26 Correct 18 ms 208 KB Output is correct
27 Correct 13 ms 304 KB Output is correct
28 Correct 18 ms 312 KB Output is correct
29 Correct 9 ms 316 KB Output is correct
30 Correct 20 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 312 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 3 ms 208 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 3 ms 316 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 2 ms 316 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 2 ms 312 KB Output is correct
17 Correct 12 ms 208 KB Output is correct
18 Correct 13 ms 324 KB Output is correct
19 Correct 14 ms 300 KB Output is correct
20 Correct 17 ms 316 KB Output is correct
21 Correct 14 ms 324 KB Output is correct
22 Correct 13 ms 316 KB Output is correct
23 Correct 13 ms 320 KB Output is correct
24 Correct 23 ms 308 KB Output is correct
25 Correct 21 ms 300 KB Output is correct
26 Correct 18 ms 208 KB Output is correct
27 Correct 13 ms 304 KB Output is correct
28 Correct 18 ms 312 KB Output is correct
29 Correct 9 ms 316 KB Output is correct
30 Correct 20 ms 316 KB Output is correct
31 Correct 43 ms 316 KB Output is correct
32 Correct 28 ms 328 KB Output is correct
33 Correct 68 ms 308 KB Output is correct
34 Correct 80 ms 328 KB Output is correct
35 Correct 89 ms 328 KB Output is correct
36 Correct 39 ms 320 KB Output is correct
37 Correct 97 ms 324 KB Output is correct
38 Correct 104 ms 316 KB Output is correct
39 Correct 99 ms 304 KB Output is correct
40 Correct 100 ms 332 KB Output is correct
41 Correct 95 ms 332 KB Output is correct
42 Correct 91 ms 344 KB Output is correct
43 Correct 99 ms 332 KB Output is correct
44 Correct 88 ms 312 KB Output is correct
45 Correct 84 ms 312 KB Output is correct
46 Correct 116 ms 340 KB Output is correct
47 Correct 71 ms 332 KB Output is correct
48 Correct 81 ms 324 KB Output is correct
49 Correct 67 ms 436 KB Output is correct
50 Correct 37 ms 320 KB Output is correct
51 Correct 52 ms 316 KB Output is correct
52 Correct 86 ms 312 KB Output is correct
53 Correct 76 ms 332 KB Output is correct
54 Correct 84 ms 312 KB Output is correct
55 Correct 76 ms 328 KB Output is correct
56 Correct 91 ms 316 KB Output is correct
57 Correct 62 ms 324 KB Output is correct
58 Correct 79 ms 332 KB Output is correct
59 Correct 84 ms 320 KB Output is correct
60 Correct 99 ms 312 KB Output is correct