Submission #525214

# Submission time Handle Problem Language Result Execution time Memory
525214 2022-02-11T05:21:40 Z AA_Surely Xylophone (JOI18_xylophone) C++17
100 / 100
416 ms 20984 KB
#include <bits/stdc++.h>
#include "xylophone.h"

#define FOR(i,x,n) for(int i = x; i < n; i++)
#define F0R(i,n) FOR(i, 0, n)
#define ROF(i,x,n) for(int i = n - 1; i >= x; i--)
#define R0F(i,n) ROF(i, 0, n)

#define pb push_back

using namespace std;

const int MAXN = 5000 + 7;
int keep[MAXN][MAXN], ans[MAXN];
int fake_ans[MAXN], cnt[MAXN];

void haveLfindR(int x) {
    //x is the place of first -> with arr[x] = p1, arr[x + 1] = p2 we have to find arr[x + 2] = ?

    if (fake_ans[x] > fake_ans[x + 1]) {
        if (abs(-keep[x][x + 1] - keep[x + 1][x + 2]) == keep[x][x + 2]) {
            //cout << "HERE FOR FINDING: " << x + 3 << endl;
            fake_ans[x + 2] = fake_ans[x + 1] - keep[x + 1][x + 2];
        }
        
        else {
            //cout << "GOOD" << endl;
            fake_ans[x + 2] = fake_ans[x + 1] + keep[x + 1][x + 2];
        }
    }

    else {
        if (keep[x][x + 1] + keep[x + 1][x + 2] == keep[x][x + 2]) {
            //cout << "SHIT FOR: " << x + 3 << endl;
            fake_ans[x + 2] = fake_ans[x + 1] + keep[x + 1][x + 2];
        }

        else {
            //cout << "WTF BRO: " << x + 3 << endl;
            fake_ans[x + 2] = fake_ans[x + 1] - keep[x + 1][x + 2];
        }
    }
    
    return;
}

void haveRfindL(int x) {
    if (fake_ans[x + 2] > fake_ans[x + 1]) {
        if (abs(-keep[x + 2][x + 1] - keep[x + 1][x]) == keep[x + 2][x]) 
            fake_ans[x] = fake_ans[x + 1] - keep[x + 1][x];
        
        else
            fake_ans[x] = fake_ans[x + 1] + keep[x + 1][x];
    }

    else {
        if (keep[x + 2][x + 1] + keep[x + 1][x] == keep[x + 2][x])
            fake_ans[x] = fake_ans[x + 1] + keep[x + 1][x];

        else
            fake_ans[x] = fake_ans[x + 1] - keep[x + 1][x];
    }
    
    return;
}

inline bool check(int n) {
    fill(cnt, cnt + n, 0);
    F0R(i, n) if(fake_ans[i] <= 0 || fake_ans[i] > n) return 0;
    F0R(i, n) cnt[fake_ans[i]]++;
    FOR(i, 1, n + 1) if (cnt[i] > 1 || !cnt[i]) return 0;

    return 1;
}

void solve(int n) {
    F0R(i, n - 1) 
        keep[i][i + 1] = keep[i + 1][i] = query(i + 1, i + 2);

    F0R(i, n - 2)
        keep[i][i + 2] = keep[i + 2][i] = query(i + 1, i + 3);
    
    /*
    FOR(i, 1, 3) {
        F0R(j, n) cout << keep[j][j + i] << ' ';
        cout << endl;
    }
    */

    //cout << endl;
    F0R(i, n) {
        //guessing this is the minimum
        fake_ans[i] = 1;
        if (i > 0) fake_ans[i - 1] = 1 + keep[i][i - 1];
        if (i < n - 1) fake_ans[i + 1] = 1 + keep[i][i + 1];

        FOR(j, i, n - 2) haveLfindR(j);
        R0F(j, i - 1) haveRfindL(j);
        
        /*
        F0R(j, n) cout << fake_ans[j] << ' ';
        cout << endl;
        */
        

        if (check(n)) {
            F0R(j, n) ans[j] = fake_ans[j];
            break;
        }
    }

    F0R(i, n) answer(i + 1, ans[i]);
    return;
}

/*
int main() {
    int n; cin >> n;
    solve(n);
}
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 3 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 1 ms 680 KB Output is correct
7 Correct 2 ms 808 KB Output is correct
8 Correct 3 ms 584 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 2 ms 712 KB Output is correct
13 Correct 3 ms 584 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 3 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 1 ms 680 KB Output is correct
7 Correct 2 ms 808 KB Output is correct
8 Correct 3 ms 584 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 2 ms 712 KB Output is correct
13 Correct 3 ms 584 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
16 Correct 5 ms 1224 KB Output is correct
17 Correct 11 ms 2264 KB Output is correct
18 Correct 14 ms 3664 KB Output is correct
19 Correct 24 ms 4296 KB Output is correct
20 Correct 18 ms 4392 KB Output is correct
21 Correct 27 ms 4376 KB Output is correct
22 Correct 24 ms 4296 KB Output is correct
23 Correct 21 ms 4392 KB Output is correct
24 Correct 26 ms 4380 KB Output is correct
25 Correct 23 ms 4380 KB Output is correct
26 Correct 19 ms 4392 KB Output is correct
27 Correct 25 ms 4380 KB Output is correct
28 Correct 18 ms 4416 KB Output is correct
29 Correct 23 ms 4336 KB Output is correct
30 Correct 25 ms 4404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 3 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 1 ms 680 KB Output is correct
7 Correct 2 ms 808 KB Output is correct
8 Correct 3 ms 584 KB Output is correct
9 Correct 3 ms 712 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 1 ms 712 KB Output is correct
12 Correct 2 ms 712 KB Output is correct
13 Correct 3 ms 584 KB Output is correct
14 Correct 2 ms 712 KB Output is correct
15 Correct 2 ms 712 KB Output is correct
16 Correct 5 ms 1224 KB Output is correct
17 Correct 11 ms 2264 KB Output is correct
18 Correct 14 ms 3664 KB Output is correct
19 Correct 24 ms 4296 KB Output is correct
20 Correct 18 ms 4392 KB Output is correct
21 Correct 27 ms 4376 KB Output is correct
22 Correct 24 ms 4296 KB Output is correct
23 Correct 21 ms 4392 KB Output is correct
24 Correct 26 ms 4380 KB Output is correct
25 Correct 23 ms 4380 KB Output is correct
26 Correct 19 ms 4392 KB Output is correct
27 Correct 25 ms 4380 KB Output is correct
28 Correct 18 ms 4416 KB Output is correct
29 Correct 23 ms 4336 KB Output is correct
30 Correct 25 ms 4404 KB Output is correct
31 Correct 58 ms 9100 KB Output is correct
32 Correct 90 ms 12944 KB Output is correct
33 Correct 162 ms 18208 KB Output is correct
34 Correct 243 ms 20756 KB Output is correct
35 Correct 228 ms 20892 KB Output is correct
36 Correct 107 ms 20780 KB Output is correct
37 Correct 341 ms 20816 KB Output is correct
38 Correct 106 ms 20828 KB Output is correct
39 Correct 198 ms 20860 KB Output is correct
40 Correct 154 ms 20876 KB Output is correct
41 Correct 189 ms 20812 KB Output is correct
42 Correct 77 ms 20808 KB Output is correct
43 Correct 416 ms 20964 KB Output is correct
44 Correct 90 ms 20772 KB Output is correct
45 Correct 107 ms 20984 KB Output is correct
46 Correct 149 ms 20856 KB Output is correct
47 Correct 100 ms 20776 KB Output is correct
48 Correct 136 ms 20928 KB Output is correct
49 Correct 220 ms 20760 KB Output is correct
50 Correct 217 ms 20852 KB Output is correct
51 Correct 88 ms 20868 KB Output is correct
52 Correct 310 ms 20820 KB Output is correct
53 Correct 213 ms 20796 KB Output is correct
54 Correct 138 ms 20812 KB Output is correct
55 Correct 128 ms 20780 KB Output is correct
56 Correct 176 ms 20860 KB Output is correct
57 Correct 161 ms 20780 KB Output is correct
58 Correct 391 ms 20912 KB Output is correct
59 Correct 163 ms 20864 KB Output is correct
60 Correct 216 ms 20908 KB Output is correct