Submission #951280

# Submission time Handle Problem Language Result Execution time Memory
951280 2024-03-21T14:32:25 Z quanlt206 Xylophone (JOI18_xylophone) C++17
100 / 100
149 ms 1256 KB
#include "xylophone.h"
#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
 
template<class A, class B>
    bool maximize(A& x, B y) {
        if (x < y) return x = y, true; else return false;
    }
template<class A, class B>
    bool minimize(A& x, B y) {
        if (x > y) return x = y, true; else return false;
    }
/* END OF TEMPLATE */
 
const int N = 5007;
 
int n, b[N], a[N];
 
int cntQuery = 0;
 
int relation[N], diff[N];
 
int c[N], cnt[N];
 
vector<int> get_permutation() {
    vector<int> tmp;
    FOR(t, 1, n) {
        c[1] = t;
        FOR(i, 2, n)
            if (relation[i - 1] == 0) c[i] = c[i - 1] + diff[i - 1]; else c[i] = c[i - 1] - diff[i - 1];
        FOR(i, 1, n) cnt[i] = 0;
        bool kt = true;
        FOR(i, 1, n)
            if (c[i] < 1 || c[i] > n || (++cnt[c[i]]) > 1) kt = false;
        if (kt) return vector<int>(c + 1, c + 1 + n);
    }
    return tmp;
}
 
bool check(vector<int> node) {
    if (node.empty()) return false;
    int pos_1 = 0, pos_n = 0;
    REP(i, 0, n)
        if (node[i] == 1) pos_1 = i + 1; else
        if (node[i] == n) pos_n = i + 1;
    if (pos_1 > pos_n) return false;
    return query(pos_1, pos_n) == n - 1 && query(pos_1, pos_n - 1) != n - 1;
}
 
void solve(int m) {
    n = m;
    FOR(i, 1, n) a[i] = 0, relation[i] = 0;
    REP(i, 1, n) diff[i] = query(i, i + 1);
    REP(i, 1, n - 1)
        if (query(i, i + 2) != diff[i] + diff[i + 1]) relation[i + 1] = relation[i] ^ 1; else relation[i + 1] = relation[i];
    vector<int> node = get_permutation();
//    REP(i, 1, n) cout<<relation[i]<<" "; cout<<"\n";
//    for (auto x : node) cout<<x<<" "; cout<<"\n";
//    exit(0);
    if (check(node)) {
        REP(i, 0, n) a[i + 1] = node[i];
    }
    else {
        REP(i, 1, n) relation[i]^=1;
        node = get_permutation();
        REP(i, 0, n) a[i + 1] = node[i];
    }
    FOR(i, 1, n) answer(i, a[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 456 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 712 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 456 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 712 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 4 ms 712 KB Output is correct
18 Correct 7 ms 452 KB Output is correct
19 Correct 14 ms 972 KB Output is correct
20 Correct 12 ms 720 KB Output is correct
21 Correct 10 ms 968 KB Output is correct
22 Correct 10 ms 720 KB Output is correct
23 Correct 10 ms 464 KB Output is correct
24 Correct 10 ms 716 KB Output is correct
25 Correct 7 ms 716 KB Output is correct
26 Correct 11 ms 720 KB Output is correct
27 Correct 9 ms 716 KB Output is correct
28 Correct 8 ms 728 KB Output is correct
29 Correct 12 ms 716 KB Output is correct
30 Correct 8 ms 968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 456 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 1 ms 452 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 712 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 452 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 4 ms 712 KB Output is correct
18 Correct 7 ms 452 KB Output is correct
19 Correct 14 ms 972 KB Output is correct
20 Correct 12 ms 720 KB Output is correct
21 Correct 10 ms 968 KB Output is correct
22 Correct 10 ms 720 KB Output is correct
23 Correct 10 ms 464 KB Output is correct
24 Correct 10 ms 716 KB Output is correct
25 Correct 7 ms 716 KB Output is correct
26 Correct 11 ms 720 KB Output is correct
27 Correct 9 ms 716 KB Output is correct
28 Correct 8 ms 728 KB Output is correct
29 Correct 12 ms 716 KB Output is correct
30 Correct 8 ms 968 KB Output is correct
31 Correct 22 ms 468 KB Output is correct
32 Correct 58 ms 768 KB Output is correct
33 Correct 61 ms 996 KB Output is correct
34 Correct 130 ms 1248 KB Output is correct
35 Correct 145 ms 980 KB Output is correct
36 Correct 50 ms 912 KB Output is correct
37 Correct 91 ms 996 KB Output is correct
38 Correct 68 ms 728 KB Output is correct
39 Correct 61 ms 740 KB Output is correct
40 Correct 137 ms 996 KB Output is correct
41 Correct 149 ms 556 KB Output is correct
42 Correct 45 ms 736 KB Output is correct
43 Correct 82 ms 900 KB Output is correct
44 Correct 41 ms 996 KB Output is correct
45 Correct 64 ms 1000 KB Output is correct
46 Correct 101 ms 804 KB Output is correct
47 Correct 89 ms 1252 KB Output is correct
48 Correct 104 ms 736 KB Output is correct
49 Correct 109 ms 740 KB Output is correct
50 Correct 107 ms 996 KB Output is correct
51 Correct 65 ms 996 KB Output is correct
52 Correct 50 ms 1000 KB Output is correct
53 Correct 140 ms 752 KB Output is correct
54 Correct 119 ms 1252 KB Output is correct
55 Correct 136 ms 1000 KB Output is correct
56 Correct 132 ms 1256 KB Output is correct
57 Correct 112 ms 1024 KB Output is correct
58 Correct 141 ms 840 KB Output is correct
59 Correct 135 ms 736 KB Output is correct
60 Correct 77 ms 996 KB Output is correct