Submission #889499

# Submission time Handle Problem Language Result Execution time Memory
889499 2023-12-19T20:33:12 Z makrav Nice sequence (IZhO18_sequence) C++14
76 / 100
553 ms 96536 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vei;
typedef vector<vei> vevei;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int) a.size()
#define con cout << "NO\n"
#define coe cout << "YES\n";
#define str string
#define pb push_back
#define ff first
#define sc second
#define ss second
#define pii pair<int, int>
#define mxe max_element
#define mne min_element
#define stf shrink_to_fit
#define f(i, l, r) for (int i = (l); i < (r); i++)
#define double ld
#define int ll

int g[3000001][2];
int used[3000001], cnt[3000001];
int pos[3000001],ppos[3000001];
int cur = 0, step = 1;

void dfs(int v) {
    used[v] = step;
    if (g[v][0]!=-1&&used[g[v][0]]!=step)dfs(g[v][0]);
    if(g[v][1]!=-1&&used[g[v][1]]!=step)dfs(g[v][1]);
    pos[v] = cur++;
}

void solve() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < 3000001; i++) {
        g[i][0] = -1;
        g[i][1] = -1;
        cnt[i] = 0;
    }
    int L = 0, R = 500001;
    while (R - L > 1) {
        int M = (L + R) / 2;
        cur = 0;
        for (int i = 0; i + n <= M; i++) {
            g[i + n][0] = i;
            cnt[i]++;
        }
        for (int i = 0; i + m <= M; i++) {
            g[i][1] = i + m;
            cnt[i + m]++;
        }
        //cout << M << '\n';
        f(i,0,M+1){
            if(used[i]!=step)dfs(i);
        }
        f(i,0,M+1)pos[i] = M - pos[i];
        bool bad = false;
        for (int i = 0; i <= M; i++) {
            if (g[i][0] != -1 && pos[g[i][0]] < pos[i]) { bad = true; break; }
            if (g[i][1] != -1 && pos[g[i][1]] < pos[i]) {bad = true; break; }
        }

        for (int i = 0; i + n <= M; i++) {
            g[i + n][0] = -1;
            cnt[i]--;
        }
        for (int i = 0; i + m <= M; i++) {
            g[i][1] = -1;
            cnt[i + m]--;
        }

        cur = 0;
        step++;
        if (bad) R = M;
        else L = M;
    }
    cout << L << '\n';
    
    int M=L;
    cur = 0;
    for (int i = 0; i + n <= M; i++) {
        g[i + n][0] = i;
        cnt[i]++;
    }
    for (int i = 0; i + m <= M; i++) {
        g[i][1] = i + m;
        cnt[i + m]++;
    }
    //cout << M << '\n';
    f(i, 0, M + 1) {
        if (used[i] != step)dfs(i);
    }
    f(i, 0, M + 1)pos[i] = M - pos[i];
    f(i,0,M+1)ppos[pos[i]] = i;
    vector<int> pref(M+1);
    pref[0]=0;
    for(int j=pos[0]+1;j<=M;j++){
        pref[ppos[j]] = j - pos[0];
    }
    for(int j = pos[0]-1;j>=0;j--){
        pref[ppos[j]]=j-pos[0];
    }
    f(i,1,M+1)cout<<pref[i]-pref[i-1]<<' ';
    cout<<'\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int tt; cin >> tt;
    while (tt--) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 133 ms 87640 KB Ok
2 Correct 133 ms 87640 KB Ok
3 Correct 125 ms 80548 KB Ok
4 Correct 126 ms 80876 KB Ok
5 Correct 136 ms 80552 KB Ok
6 Correct 117 ms 81744 KB Ok
7 Correct 137 ms 80384 KB Ok
8 Correct 121 ms 81956 KB Ok
9 Correct 135 ms 80468 KB Ok
10 Correct 125 ms 83904 KB Ok
11 Correct 126 ms 80220 KB Ok
12 Correct 127 ms 80364 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 146 ms 87820 KB Ok
2 Correct 130 ms 87644 KB Ok
3 Correct 143 ms 87892 KB Ok
4 Correct 139 ms 87632 KB Ok
5 Correct 137 ms 87632 KB Ok
6 Correct 141 ms 88076 KB Ok
7 Correct 150 ms 88148 KB Ok
8 Correct 128 ms 87896 KB Ok
9 Correct 135 ms 88400 KB Ok
10 Correct 164 ms 87892 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 43 ms 87644 KB Ok
2 Correct 134 ms 87640 KB Ok
3 Correct 137 ms 87888 KB Ok
4 Correct 147 ms 87644 KB Ok
5 Correct 131 ms 87640 KB Ok
6 Correct 146 ms 87636 KB Ok
7 Correct 149 ms 87816 KB Ok
8 Correct 157 ms 87816 KB Ok
9 Correct 148 ms 87740 KB Ok
10 Correct 145 ms 87820 KB Ok
11 Correct 130 ms 87576 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 146 ms 87824 KB Ok
2 Correct 144 ms 87820 KB Ok
3 Correct 143 ms 87836 KB Ok
4 Correct 150 ms 87820 KB Ok
5 Correct 154 ms 87644 KB Ok
6 Correct 332 ms 93860 KB Ok
7 Correct 296 ms 92916 KB Ok
8 Correct 461 ms 95984 KB Ok
9 Correct 371 ms 96536 KB Ok
10 Correct 287 ms 93528 KB Ok
11 Correct 442 ms 96284 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 133 ms 87640 KB Ok
2 Correct 133 ms 87640 KB Ok
3 Correct 125 ms 80548 KB Ok
4 Correct 126 ms 80876 KB Ok
5 Correct 136 ms 80552 KB Ok
6 Correct 117 ms 81744 KB Ok
7 Correct 137 ms 80384 KB Ok
8 Correct 121 ms 81956 KB Ok
9 Correct 135 ms 80468 KB Ok
10 Correct 125 ms 83904 KB Ok
11 Correct 126 ms 80220 KB Ok
12 Correct 127 ms 80364 KB Ok
13 Correct 43 ms 87644 KB Ok
14 Correct 134 ms 87640 KB Ok
15 Correct 137 ms 87888 KB Ok
16 Correct 147 ms 87644 KB Ok
17 Correct 131 ms 87640 KB Ok
18 Correct 146 ms 87636 KB Ok
19 Correct 149 ms 87816 KB Ok
20 Correct 157 ms 87816 KB Ok
21 Correct 148 ms 87740 KB Ok
22 Correct 145 ms 87820 KB Ok
23 Correct 130 ms 87576 KB Ok
24 Correct 135 ms 80140 KB Ok
25 Correct 140 ms 80268 KB Ok
26 Correct 143 ms 80604 KB Ok
27 Correct 131 ms 80572 KB Ok
28 Correct 146 ms 80036 KB Ok
29 Correct 138 ms 82516 KB Ok
30 Correct 137 ms 80728 KB Ok
31 Correct 137 ms 80188 KB Ok
32 Correct 139 ms 80216 KB Ok
33 Correct 135 ms 80316 KB Ok
34 Correct 177 ms 87832 KB Ok
35 Correct 183 ms 87828 KB Ok
36 Correct 167 ms 87872 KB Ok
37 Correct 191 ms 87928 KB Ok
38 Correct 164 ms 87972 KB Ok
39 Correct 215 ms 87636 KB Ok
40 Correct 170 ms 87884 KB Ok
41 Correct 175 ms 87956 KB Ok
42 Correct 174 ms 87888 KB Ok
43 Correct 166 ms 87888 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 133 ms 87640 KB Ok
2 Correct 133 ms 87640 KB Ok
3 Correct 125 ms 80548 KB Ok
4 Correct 126 ms 80876 KB Ok
5 Correct 136 ms 80552 KB Ok
6 Correct 117 ms 81744 KB Ok
7 Correct 137 ms 80384 KB Ok
8 Correct 121 ms 81956 KB Ok
9 Correct 135 ms 80468 KB Ok
10 Correct 125 ms 83904 KB Ok
11 Correct 126 ms 80220 KB Ok
12 Correct 127 ms 80364 KB Ok
13 Correct 146 ms 87820 KB Ok
14 Correct 130 ms 87644 KB Ok
15 Correct 143 ms 87892 KB Ok
16 Correct 139 ms 87632 KB Ok
17 Correct 137 ms 87632 KB Ok
18 Correct 141 ms 88076 KB Ok
19 Correct 150 ms 88148 KB Ok
20 Correct 128 ms 87896 KB Ok
21 Correct 135 ms 88400 KB Ok
22 Correct 164 ms 87892 KB Ok
23 Correct 43 ms 87644 KB Ok
24 Correct 134 ms 87640 KB Ok
25 Correct 137 ms 87888 KB Ok
26 Correct 147 ms 87644 KB Ok
27 Correct 131 ms 87640 KB Ok
28 Correct 146 ms 87636 KB Ok
29 Correct 149 ms 87816 KB Ok
30 Correct 157 ms 87816 KB Ok
31 Correct 148 ms 87740 KB Ok
32 Correct 145 ms 87820 KB Ok
33 Correct 130 ms 87576 KB Ok
34 Correct 135 ms 80140 KB Ok
35 Correct 140 ms 80268 KB Ok
36 Correct 143 ms 80604 KB Ok
37 Correct 131 ms 80572 KB Ok
38 Correct 146 ms 80036 KB Ok
39 Correct 138 ms 82516 KB Ok
40 Correct 137 ms 80728 KB Ok
41 Correct 137 ms 80188 KB Ok
42 Correct 139 ms 80216 KB Ok
43 Correct 135 ms 80316 KB Ok
44 Correct 177 ms 87832 KB Ok
45 Correct 183 ms 87828 KB Ok
46 Correct 167 ms 87872 KB Ok
47 Correct 191 ms 87928 KB Ok
48 Correct 164 ms 87972 KB Ok
49 Correct 215 ms 87636 KB Ok
50 Correct 170 ms 87884 KB Ok
51 Correct 175 ms 87956 KB Ok
52 Correct 174 ms 87888 KB Ok
53 Correct 166 ms 87888 KB Ok
54 Correct 206 ms 84824 KB Ok
55 Correct 223 ms 85436 KB Ok
56 Correct 216 ms 85296 KB Ok
57 Correct 195 ms 84540 KB Ok
58 Correct 222 ms 85188 KB Ok
59 Correct 213 ms 85244 KB Ok
60 Correct 188 ms 84752 KB Ok
61 Correct 182 ms 84740 KB Ok
62 Correct 245 ms 85652 KB Ok
63 Correct 220 ms 84940 KB Ok
64 Correct 232 ms 85300 KB Ok
65 Correct 213 ms 85240 KB Ok
66 Correct 195 ms 84864 KB Ok
67 Correct 187 ms 84964 KB Ok
68 Correct 262 ms 85124 KB Ok
69 Correct 519 ms 92220 KB Ok
70 Correct 498 ms 95600 KB Ok
71 Correct 517 ms 92476 KB Ok
72 Correct 472 ms 95404 KB Ok
73 Correct 543 ms 92472 KB Ok
74 Correct 495 ms 91988 KB Ok
75 Correct 515 ms 92132 KB Ok
76 Correct 536 ms 95284 KB Ok
77 Correct 513 ms 92252 KB Ok
78 Correct 527 ms 95208 KB Ok
79 Correct 543 ms 95612 KB Ok
80 Correct 478 ms 95240 KB Ok
81 Correct 518 ms 95656 KB Ok
82 Correct 502 ms 95284 KB Ok
83 Correct 553 ms 92220 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 133 ms 87640 KB Ok
2 Correct 133 ms 87640 KB Ok
3 Correct 125 ms 80548 KB Ok
4 Correct 126 ms 80876 KB Ok
5 Correct 136 ms 80552 KB Ok
6 Correct 117 ms 81744 KB Ok
7 Correct 137 ms 80384 KB Ok
8 Correct 121 ms 81956 KB Ok
9 Correct 135 ms 80468 KB Ok
10 Correct 125 ms 83904 KB Ok
11 Correct 126 ms 80220 KB Ok
12 Correct 127 ms 80364 KB Ok
13 Correct 146 ms 87820 KB Ok
14 Correct 130 ms 87644 KB Ok
15 Correct 143 ms 87892 KB Ok
16 Correct 139 ms 87632 KB Ok
17 Correct 137 ms 87632 KB Ok
18 Correct 141 ms 88076 KB Ok
19 Correct 150 ms 88148 KB Ok
20 Correct 128 ms 87896 KB Ok
21 Correct 135 ms 88400 KB Ok
22 Correct 164 ms 87892 KB Ok
23 Correct 43 ms 87644 KB Ok
24 Correct 134 ms 87640 KB Ok
25 Correct 137 ms 87888 KB Ok
26 Correct 147 ms 87644 KB Ok
27 Correct 131 ms 87640 KB Ok
28 Correct 146 ms 87636 KB Ok
29 Correct 149 ms 87816 KB Ok
30 Correct 157 ms 87816 KB Ok
31 Correct 148 ms 87740 KB Ok
32 Correct 145 ms 87820 KB Ok
33 Correct 130 ms 87576 KB Ok
34 Correct 146 ms 87824 KB Ok
35 Correct 144 ms 87820 KB Ok
36 Correct 143 ms 87836 KB Ok
37 Correct 150 ms 87820 KB Ok
38 Correct 154 ms 87644 KB Ok
39 Correct 332 ms 93860 KB Ok
40 Correct 296 ms 92916 KB Ok
41 Correct 461 ms 95984 KB Ok
42 Correct 371 ms 96536 KB Ok
43 Correct 287 ms 93528 KB Ok
44 Correct 442 ms 96284 KB Ok
45 Correct 135 ms 80140 KB Ok
46 Correct 140 ms 80268 KB Ok
47 Correct 143 ms 80604 KB Ok
48 Correct 131 ms 80572 KB Ok
49 Correct 146 ms 80036 KB Ok
50 Correct 138 ms 82516 KB Ok
51 Correct 137 ms 80728 KB Ok
52 Correct 137 ms 80188 KB Ok
53 Correct 139 ms 80216 KB Ok
54 Correct 135 ms 80316 KB Ok
55 Correct 177 ms 87832 KB Ok
56 Correct 183 ms 87828 KB Ok
57 Correct 167 ms 87872 KB Ok
58 Correct 191 ms 87928 KB Ok
59 Correct 164 ms 87972 KB Ok
60 Correct 215 ms 87636 KB Ok
61 Correct 170 ms 87884 KB Ok
62 Correct 175 ms 87956 KB Ok
63 Correct 174 ms 87888 KB Ok
64 Correct 166 ms 87888 KB Ok
65 Correct 206 ms 84824 KB Ok
66 Correct 223 ms 85436 KB Ok
67 Correct 216 ms 85296 KB Ok
68 Correct 195 ms 84540 KB Ok
69 Correct 222 ms 85188 KB Ok
70 Correct 213 ms 85244 KB Ok
71 Correct 188 ms 84752 KB Ok
72 Correct 182 ms 84740 KB Ok
73 Correct 245 ms 85652 KB Ok
74 Correct 220 ms 84940 KB Ok
75 Correct 232 ms 85300 KB Ok
76 Correct 213 ms 85240 KB Ok
77 Correct 195 ms 84864 KB Ok
78 Correct 187 ms 84964 KB Ok
79 Correct 262 ms 85124 KB Ok
80 Correct 519 ms 92220 KB Ok
81 Correct 498 ms 95600 KB Ok
82 Correct 517 ms 92476 KB Ok
83 Correct 472 ms 95404 KB Ok
84 Correct 543 ms 92472 KB Ok
85 Correct 495 ms 91988 KB Ok
86 Correct 515 ms 92132 KB Ok
87 Correct 536 ms 95284 KB Ok
88 Correct 513 ms 92252 KB Ok
89 Correct 527 ms 95208 KB Ok
90 Correct 543 ms 95612 KB Ok
91 Correct 478 ms 95240 KB Ok
92 Correct 518 ms 95656 KB Ok
93 Correct 502 ms 95284 KB Ok
94 Correct 553 ms 92220 KB Ok
95 Correct 377 ms 89560 KB Ok
96 Incorrect 423 ms 92068 KB Jury has the better answer : jans = 311847, pans = 249999
97 Halted 0 ms 0 KB -