Submission #575093

# Submission time Handle Problem Language Result Execution time Memory
575093 2022-06-09T16:37:58 Z SlavicG Xylophone (JOI18_xylophone) C++17
100 / 100
133 ms 20920 KB
#include "xylophone.h"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 5005;
int Paiu[N][N];

void solve(int n) {
    vector<int> dif(n, 0);
    for(int i = 0; i + 1 < n; ++i) {
        Paiu[i][i + 1] = query(i + 1, i + 2);
        if(i + 2 < n) Paiu[i][i + 2] = query(i + 1, i + 3);
    }

    vector<int> type(n, 1);
    for(int i = 0; i + 2 < n; ++i) {
        if(Paiu[i][i + 1] + Paiu[i + 1][i + 2] != Paiu[i][i + 2]) {
            type[i + 2] = -type[i + 1];
        } else {
            type[i + 2] = type[i + 1];
        }
    }

    {
        vector<int> a(n, 0);
        for(int i = 1; i < n; ++i) {
            if(type[i] == 1) a[i] = a[i - 1] + Paiu[i - 1][i];
            else a[i] = a[i - 1] - Paiu[i - 1][i];
        }
        int mn = *min_element(all(a));
        forn(i, n) a[i] += 1 - mn;
        set<int> st;
        forn(i, n) st.insert(i + 1);
        forn(i, n) st.erase(a[i]);
        if(!sz(st)) {
            map<int, int> pos;
            forn(i, n) pos[a[i]] = i;
            if(pos[1] < pos[n]) {
                for(int i = 0; i < n; ++i) {
                    answer(i + 1, a[i]);
                } 
                return;
            }
        }
    }

    forn(i, n) type[i] = -type[i];

    {
        vector<int> a(n, 0);
        for(int i = 1; i < n; ++i) {
            if(type[i] == 1) a[i] = a[i - 1] + Paiu[i - 1][i];
            else a[i] = a[i - 1] - Paiu[i - 1][i];
        }
        int mn = *min_element(all(a));
        forn(i, n) a[i] += 1 - mn;
        set<int> st;
        forn(i, n) st.insert(i + 1);
        forn(i, n) st.erase(a[i]);
        if(!sz(st)) {
            map<int, int> pos;
            forn(i, n) pos[a[i]] = i;
            if(pos[1] < pos[n]) {
                for(int i = 0; i < n; ++i) {
                    answer(i + 1, a[i]);
                } 
                return;
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 592 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 592 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 580 KB Output is correct
16 Correct 6 ms 1104 KB Output is correct
17 Correct 9 ms 2152 KB Output is correct
18 Correct 23 ms 3636 KB Output is correct
19 Correct 21 ms 4376 KB Output is correct
20 Correct 23 ms 4360 KB Output is correct
21 Correct 24 ms 4284 KB Output is correct
22 Correct 18 ms 4336 KB Output is correct
23 Correct 17 ms 4268 KB Output is correct
24 Correct 22 ms 4340 KB Output is correct
25 Correct 20 ms 4348 KB Output is correct
26 Correct 12 ms 4356 KB Output is correct
27 Correct 23 ms 4336 KB Output is correct
28 Correct 22 ms 4296 KB Output is correct
29 Correct 17 ms 4320 KB Output is correct
30 Correct 17 ms 4388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 592 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 580 KB Output is correct
16 Correct 6 ms 1104 KB Output is correct
17 Correct 9 ms 2152 KB Output is correct
18 Correct 23 ms 3636 KB Output is correct
19 Correct 21 ms 4376 KB Output is correct
20 Correct 23 ms 4360 KB Output is correct
21 Correct 24 ms 4284 KB Output is correct
22 Correct 18 ms 4336 KB Output is correct
23 Correct 17 ms 4268 KB Output is correct
24 Correct 22 ms 4340 KB Output is correct
25 Correct 20 ms 4348 KB Output is correct
26 Correct 12 ms 4356 KB Output is correct
27 Correct 23 ms 4336 KB Output is correct
28 Correct 22 ms 4296 KB Output is correct
29 Correct 17 ms 4320 KB Output is correct
30 Correct 17 ms 4388 KB Output is correct
31 Correct 21 ms 9140 KB Output is correct
32 Correct 77 ms 12960 KB Output is correct
33 Correct 98 ms 18144 KB Output is correct
34 Correct 92 ms 20760 KB Output is correct
35 Correct 118 ms 20876 KB Output is correct
36 Correct 87 ms 20740 KB Output is correct
37 Correct 119 ms 20756 KB Output is correct
38 Correct 103 ms 20796 KB Output is correct
39 Correct 110 ms 20748 KB Output is correct
40 Correct 93 ms 20808 KB Output is correct
41 Correct 111 ms 20752 KB Output is correct
42 Correct 91 ms 20896 KB Output is correct
43 Correct 96 ms 20820 KB Output is correct
44 Correct 72 ms 20920 KB Output is correct
45 Correct 98 ms 20788 KB Output is correct
46 Correct 108 ms 20780 KB Output is correct
47 Correct 97 ms 20808 KB Output is correct
48 Correct 102 ms 20856 KB Output is correct
49 Correct 66 ms 20844 KB Output is correct
50 Correct 97 ms 20824 KB Output is correct
51 Correct 96 ms 20792 KB Output is correct
52 Correct 117 ms 20800 KB Output is correct
53 Correct 113 ms 20820 KB Output is correct
54 Correct 96 ms 20808 KB Output is correct
55 Correct 101 ms 20728 KB Output is correct
56 Correct 102 ms 20800 KB Output is correct
57 Correct 81 ms 20780 KB Output is correct
58 Correct 86 ms 20812 KB Output is correct
59 Correct 133 ms 20828 KB Output is correct
60 Correct 66 ms 20828 KB Output is correct