Submission #575066

# Submission time Handle Problem Language Result Execution time Memory
575066 2022-06-09T15:10:44 Z MadokaMagicaFan Xylophone (JOI18_xylophone) C++14
100 / 100
99 ms 328 KB
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;

#define sz(v)                       ((int)v.size())
#define pb                          push_back

#define pry                         cout << "YES\n"
#define prn                         cout << "NO\n"
#define endl                        '\n'

#define fst                         first
#define scn                         second

int query(int s, int t);
void answer(int i, int a);

void
solve(int n)
{
    if (n < 3) {
        for (int i = 0; i < n; ++i)
            answer(i+1,i+1);
        return;
    }
    vector<int> ans(n,1);
    bool bigger = 1;

    int dif1 = query(1,2);
    int dif2 = query(1,3);
    int dif3;
    ans[0] += dif1;


    for (int i = 1; i < n-1; ++i) {
        dif3 = query(i+1,i+2);
        if (dif3 + dif1 != dif2) 
            bigger = !bigger;

        if (bigger) {
            ans[i+1] = ans[i]-dif3;
            if (ans[i+1] < 1) {
                dif1 = 1 - ans[i+1];
                for (int j = 0; j < i+2; ++j) {
                    ans[j] += dif1;
                }
            }
        } else {
            ans[i+1] = ans[i] + dif3;
        }

        dif1 = dif3;
        if (i < n-2)
            dif2 = query(i+1,i+3);
    }

    int p1, pn;

    for (int i = 0; i < n; ++i) {
        if (ans[i] == 1)
            p1 = i;
        if (ans[i] == n)
            pn = i;
    }

    if (pn < p1) {
        for (int i = 0; i < n; ++i) {
            ans[i] = n + 1 - ans[i];
        }
    }

    for (int i = 0; i < n; ++i) {
        answer(i+1,ans[i]);
    }

    return;
}


#ifdef ONPC
const int N = 5e3;
vector<int> ra;
bitset<N> c;

void
answer(int i, int a)
{
    cout << a << ' ';
    --i;
    if (ra[i] == a)
        c[i] = 1;
}

int
query(int s, int t)
{
    --s;
    int mn,mx;
    mn = inf;
    mx = 0;
    for (int i = s; i < t; ++i) {
        mn = min(mn,ra[i]);
        mx = max(mx,ra[i]);
    }

    printf("Query %d %d %d\n", s+1,t,mx-mn);
    return mx - mn;
}

void
rezolvare()
{
    int n;
    cin >> n;

    ra.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> ra[i];

    solve(n);
}

int32_t
main(int argc, char **argv)
{
    if (argc >= 2) {
        freopen(argv[1], "r", stdin);
    } else
        ios_base::sync_with_stdio(0);cin.tie(0);
    int t = 1;
    /* cin >> t; */
    while(t--)
        rezolvare();
}
#endif

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:71:5: warning: 'pn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |     if (pn < p1) {
      |     ^~
xylophone.cpp:71:5: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 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 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 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 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 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 2 ms 208 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 15 ms 208 KB Output is correct
19 Correct 19 ms 284 KB Output is correct
20 Correct 19 ms 288 KB Output is correct
21 Correct 16 ms 288 KB Output is correct
22 Correct 16 ms 208 KB Output is correct
23 Correct 16 ms 208 KB Output is correct
24 Correct 20 ms 208 KB Output is correct
25 Correct 17 ms 208 KB Output is correct
26 Correct 19 ms 284 KB Output is correct
27 Correct 16 ms 208 KB Output is correct
28 Correct 16 ms 208 KB Output is correct
29 Correct 17 ms 208 KB Output is correct
30 Correct 16 ms 296 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 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 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 2 ms 208 KB Output is correct
17 Correct 9 ms 208 KB Output is correct
18 Correct 15 ms 208 KB Output is correct
19 Correct 19 ms 284 KB Output is correct
20 Correct 19 ms 288 KB Output is correct
21 Correct 16 ms 288 KB Output is correct
22 Correct 16 ms 208 KB Output is correct
23 Correct 16 ms 208 KB Output is correct
24 Correct 20 ms 208 KB Output is correct
25 Correct 17 ms 208 KB Output is correct
26 Correct 19 ms 284 KB Output is correct
27 Correct 16 ms 208 KB Output is correct
28 Correct 16 ms 208 KB Output is correct
29 Correct 17 ms 208 KB Output is correct
30 Correct 16 ms 296 KB Output is correct
31 Correct 41 ms 284 KB Output is correct
32 Correct 46 ms 304 KB Output is correct
33 Correct 78 ms 304 KB Output is correct
34 Correct 79 ms 328 KB Output is correct
35 Correct 70 ms 328 KB Output is correct
36 Correct 95 ms 312 KB Output is correct
37 Correct 99 ms 296 KB Output is correct
38 Correct 69 ms 304 KB Output is correct
39 Correct 82 ms 308 KB Output is correct
40 Correct 90 ms 308 KB Output is correct
41 Correct 86 ms 296 KB Output is correct
42 Correct 93 ms 300 KB Output is correct
43 Correct 79 ms 328 KB Output is correct
44 Correct 83 ms 312 KB Output is correct
45 Correct 85 ms 328 KB Output is correct
46 Correct 82 ms 328 KB Output is correct
47 Correct 73 ms 328 KB Output is correct
48 Correct 70 ms 296 KB Output is correct
49 Correct 82 ms 308 KB Output is correct
50 Correct 81 ms 300 KB Output is correct
51 Correct 91 ms 296 KB Output is correct
52 Correct 94 ms 328 KB Output is correct
53 Correct 74 ms 300 KB Output is correct
54 Correct 92 ms 304 KB Output is correct
55 Correct 51 ms 304 KB Output is correct
56 Correct 78 ms 296 KB Output is correct
57 Correct 96 ms 296 KB Output is correct
58 Correct 94 ms 296 KB Output is correct
59 Correct 76 ms 328 KB Output is correct
60 Correct 84 ms 296 KB Output is correct