Submission #889502

# Submission time Handle Problem Language Result Execution time Memory
889502 2023-12-19T20:36:17 Z makrav Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 88368 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
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 = 1000001;
    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 210 ms 59736 KB Ok
2 Correct 223 ms 59740 KB Ok
3 Correct 152 ms 45212 KB Ok
4 Correct 135 ms 46124 KB Ok
5 Correct 166 ms 45456 KB Ok
6 Correct 135 ms 47956 KB Ok
7 Correct 155 ms 44800 KB Ok
8 Correct 147 ms 47968 KB Ok
9 Correct 147 ms 45132 KB Ok
10 Correct 140 ms 51896 KB Ok
11 Correct 146 ms 44868 KB Ok
12 Correct 131 ms 44368 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 191 ms 59744 KB Ok
2 Correct 191 ms 59612 KB Ok
3 Correct 162 ms 59728 KB Ok
4 Correct 193 ms 59744 KB Ok
5 Correct 166 ms 59740 KB Ok
6 Correct 162 ms 59772 KB Ok
7 Correct 227 ms 59772 KB Ok
8 Correct 169 ms 59732 KB Ok
9 Correct 175 ms 60164 KB Ok
10 Correct 173 ms 59692 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 79 ms 59736 KB Ok
2 Correct 195 ms 59740 KB Ok
3 Correct 216 ms 59868 KB Ok
4 Correct 187 ms 59736 KB Ok
5 Correct 207 ms 59740 KB Ok
6 Correct 211 ms 59744 KB Ok
7 Correct 208 ms 59736 KB Ok
8 Correct 240 ms 59744 KB Ok
9 Correct 208 ms 59748 KB Ok
10 Correct 194 ms 59648 KB Ok
11 Correct 193 ms 59852 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 216 ms 59744 KB Ok
2 Correct 210 ms 59740 KB Ok
3 Correct 199 ms 59736 KB Ok
4 Correct 210 ms 59740 KB Ok
5 Correct 206 ms 59740 KB Ok
6 Correct 366 ms 65028 KB Ok
7 Correct 380 ms 64204 KB Ok
8 Correct 479 ms 66728 KB Ok
9 Correct 438 ms 67984 KB Ok
10 Correct 318 ms 64632 KB Ok
11 Correct 453 ms 67376 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 210 ms 59736 KB Ok
2 Correct 223 ms 59740 KB Ok
3 Correct 152 ms 45212 KB Ok
4 Correct 135 ms 46124 KB Ok
5 Correct 166 ms 45456 KB Ok
6 Correct 135 ms 47956 KB Ok
7 Correct 155 ms 44800 KB Ok
8 Correct 147 ms 47968 KB Ok
9 Correct 147 ms 45132 KB Ok
10 Correct 140 ms 51896 KB Ok
11 Correct 146 ms 44868 KB Ok
12 Correct 131 ms 44368 KB Ok
13 Correct 79 ms 59736 KB Ok
14 Correct 195 ms 59740 KB Ok
15 Correct 216 ms 59868 KB Ok
16 Correct 187 ms 59736 KB Ok
17 Correct 207 ms 59740 KB Ok
18 Correct 211 ms 59744 KB Ok
19 Correct 208 ms 59736 KB Ok
20 Correct 240 ms 59744 KB Ok
21 Correct 208 ms 59748 KB Ok
22 Correct 194 ms 59648 KB Ok
23 Correct 193 ms 59852 KB Ok
24 Correct 157 ms 44184 KB Ok
25 Correct 176 ms 44928 KB Ok
26 Correct 178 ms 45164 KB Ok
27 Correct 158 ms 45368 KB Ok
28 Correct 170 ms 44444 KB Ok
29 Correct 154 ms 49336 KB Ok
30 Correct 157 ms 44632 KB Ok
31 Correct 163 ms 44412 KB Ok
32 Correct 185 ms 44288 KB Ok
33 Correct 165 ms 45020 KB Ok
34 Correct 239 ms 59784 KB Ok
35 Correct 247 ms 59768 KB Ok
36 Correct 238 ms 59740 KB Ok
37 Correct 245 ms 60024 KB Ok
38 Correct 236 ms 59812 KB Ok
39 Correct 246 ms 59772 KB Ok
40 Correct 277 ms 59740 KB Ok
41 Correct 242 ms 59748 KB Ok
42 Correct 220 ms 59732 KB Ok
43 Correct 254 ms 59656 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 210 ms 59736 KB Ok
2 Correct 223 ms 59740 KB Ok
3 Correct 152 ms 45212 KB Ok
4 Correct 135 ms 46124 KB Ok
5 Correct 166 ms 45456 KB Ok
6 Correct 135 ms 47956 KB Ok
7 Correct 155 ms 44800 KB Ok
8 Correct 147 ms 47968 KB Ok
9 Correct 147 ms 45132 KB Ok
10 Correct 140 ms 51896 KB Ok
11 Correct 146 ms 44868 KB Ok
12 Correct 131 ms 44368 KB Ok
13 Correct 191 ms 59744 KB Ok
14 Correct 191 ms 59612 KB Ok
15 Correct 162 ms 59728 KB Ok
16 Correct 193 ms 59744 KB Ok
17 Correct 166 ms 59740 KB Ok
18 Correct 162 ms 59772 KB Ok
19 Correct 227 ms 59772 KB Ok
20 Correct 169 ms 59732 KB Ok
21 Correct 175 ms 60164 KB Ok
22 Correct 173 ms 59692 KB Ok
23 Correct 79 ms 59736 KB Ok
24 Correct 195 ms 59740 KB Ok
25 Correct 216 ms 59868 KB Ok
26 Correct 187 ms 59736 KB Ok
27 Correct 207 ms 59740 KB Ok
28 Correct 211 ms 59744 KB Ok
29 Correct 208 ms 59736 KB Ok
30 Correct 240 ms 59744 KB Ok
31 Correct 208 ms 59748 KB Ok
32 Correct 194 ms 59648 KB Ok
33 Correct 193 ms 59852 KB Ok
34 Correct 157 ms 44184 KB Ok
35 Correct 176 ms 44928 KB Ok
36 Correct 178 ms 45164 KB Ok
37 Correct 158 ms 45368 KB Ok
38 Correct 170 ms 44444 KB Ok
39 Correct 154 ms 49336 KB Ok
40 Correct 157 ms 44632 KB Ok
41 Correct 163 ms 44412 KB Ok
42 Correct 185 ms 44288 KB Ok
43 Correct 165 ms 45020 KB Ok
44 Correct 239 ms 59784 KB Ok
45 Correct 247 ms 59768 KB Ok
46 Correct 238 ms 59740 KB Ok
47 Correct 245 ms 60024 KB Ok
48 Correct 236 ms 59812 KB Ok
49 Correct 246 ms 59772 KB Ok
50 Correct 277 ms 59740 KB Ok
51 Correct 242 ms 59748 KB Ok
52 Correct 220 ms 59732 KB Ok
53 Correct 254 ms 59656 KB Ok
54 Correct 236 ms 48636 KB Ok
55 Correct 290 ms 49148 KB Ok
56 Correct 257 ms 49152 KB Ok
57 Correct 204 ms 48360 KB Ok
58 Correct 244 ms 48952 KB Ok
59 Correct 251 ms 48912 KB Ok
60 Correct 215 ms 48480 KB Ok
61 Correct 209 ms 48508 KB Ok
62 Correct 261 ms 49436 KB Ok
63 Correct 236 ms 48676 KB Ok
64 Correct 253 ms 49272 KB Ok
65 Correct 235 ms 48904 KB Ok
66 Correct 219 ms 48712 KB Ok
67 Correct 209 ms 48464 KB Ok
68 Correct 256 ms 48944 KB Ok
69 Correct 602 ms 65616 KB Ok
70 Correct 599 ms 68740 KB Ok
71 Correct 611 ms 65180 KB Ok
72 Correct 614 ms 68176 KB Ok
73 Correct 634 ms 65468 KB Ok
74 Correct 571 ms 65260 KB Ok
75 Correct 606 ms 65076 KB Ok
76 Correct 650 ms 68356 KB Ok
77 Correct 561 ms 65196 KB Ok
78 Correct 581 ms 68188 KB Ok
79 Correct 639 ms 68656 KB Ok
80 Correct 551 ms 68284 KB Ok
81 Correct 575 ms 68544 KB Ok
82 Correct 588 ms 68540 KB Ok
83 Correct 555 ms 65396 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 210 ms 59736 KB Ok
2 Correct 223 ms 59740 KB Ok
3 Correct 152 ms 45212 KB Ok
4 Correct 135 ms 46124 KB Ok
5 Correct 166 ms 45456 KB Ok
6 Correct 135 ms 47956 KB Ok
7 Correct 155 ms 44800 KB Ok
8 Correct 147 ms 47968 KB Ok
9 Correct 147 ms 45132 KB Ok
10 Correct 140 ms 51896 KB Ok
11 Correct 146 ms 44868 KB Ok
12 Correct 131 ms 44368 KB Ok
13 Correct 191 ms 59744 KB Ok
14 Correct 191 ms 59612 KB Ok
15 Correct 162 ms 59728 KB Ok
16 Correct 193 ms 59744 KB Ok
17 Correct 166 ms 59740 KB Ok
18 Correct 162 ms 59772 KB Ok
19 Correct 227 ms 59772 KB Ok
20 Correct 169 ms 59732 KB Ok
21 Correct 175 ms 60164 KB Ok
22 Correct 173 ms 59692 KB Ok
23 Correct 79 ms 59736 KB Ok
24 Correct 195 ms 59740 KB Ok
25 Correct 216 ms 59868 KB Ok
26 Correct 187 ms 59736 KB Ok
27 Correct 207 ms 59740 KB Ok
28 Correct 211 ms 59744 KB Ok
29 Correct 208 ms 59736 KB Ok
30 Correct 240 ms 59744 KB Ok
31 Correct 208 ms 59748 KB Ok
32 Correct 194 ms 59648 KB Ok
33 Correct 193 ms 59852 KB Ok
34 Correct 216 ms 59744 KB Ok
35 Correct 210 ms 59740 KB Ok
36 Correct 199 ms 59736 KB Ok
37 Correct 210 ms 59740 KB Ok
38 Correct 206 ms 59740 KB Ok
39 Correct 366 ms 65028 KB Ok
40 Correct 380 ms 64204 KB Ok
41 Correct 479 ms 66728 KB Ok
42 Correct 438 ms 67984 KB Ok
43 Correct 318 ms 64632 KB Ok
44 Correct 453 ms 67376 KB Ok
45 Correct 157 ms 44184 KB Ok
46 Correct 176 ms 44928 KB Ok
47 Correct 178 ms 45164 KB Ok
48 Correct 158 ms 45368 KB Ok
49 Correct 170 ms 44444 KB Ok
50 Correct 154 ms 49336 KB Ok
51 Correct 157 ms 44632 KB Ok
52 Correct 163 ms 44412 KB Ok
53 Correct 185 ms 44288 KB Ok
54 Correct 165 ms 45020 KB Ok
55 Correct 239 ms 59784 KB Ok
56 Correct 247 ms 59768 KB Ok
57 Correct 238 ms 59740 KB Ok
58 Correct 245 ms 60024 KB Ok
59 Correct 236 ms 59812 KB Ok
60 Correct 246 ms 59772 KB Ok
61 Correct 277 ms 59740 KB Ok
62 Correct 242 ms 59748 KB Ok
63 Correct 220 ms 59732 KB Ok
64 Correct 254 ms 59656 KB Ok
65 Correct 236 ms 48636 KB Ok
66 Correct 290 ms 49148 KB Ok
67 Correct 257 ms 49152 KB Ok
68 Correct 204 ms 48360 KB Ok
69 Correct 244 ms 48952 KB Ok
70 Correct 251 ms 48912 KB Ok
71 Correct 215 ms 48480 KB Ok
72 Correct 209 ms 48508 KB Ok
73 Correct 261 ms 49436 KB Ok
74 Correct 236 ms 48676 KB Ok
75 Correct 253 ms 49272 KB Ok
76 Correct 235 ms 48904 KB Ok
77 Correct 219 ms 48712 KB Ok
78 Correct 209 ms 48464 KB Ok
79 Correct 256 ms 48944 KB Ok
80 Correct 602 ms 65616 KB Ok
81 Correct 599 ms 68740 KB Ok
82 Correct 611 ms 65180 KB Ok
83 Correct 614 ms 68176 KB Ok
84 Correct 634 ms 65468 KB Ok
85 Correct 571 ms 65260 KB Ok
86 Correct 606 ms 65076 KB Ok
87 Correct 650 ms 68356 KB Ok
88 Correct 561 ms 65196 KB Ok
89 Correct 581 ms 68188 KB Ok
90 Correct 639 ms 68656 KB Ok
91 Correct 551 ms 68284 KB Ok
92 Correct 575 ms 68544 KB Ok
93 Correct 588 ms 68540 KB Ok
94 Correct 555 ms 65396 KB Ok
95 Correct 401 ms 52712 KB Ok
96 Correct 532 ms 56888 KB Ok
97 Correct 537 ms 55172 KB Ok
98 Correct 392 ms 53320 KB Ok
99 Correct 453 ms 54036 KB Ok
100 Correct 497 ms 55072 KB Ok
101 Correct 464 ms 54240 KB Ok
102 Correct 474 ms 54628 KB Ok
103 Correct 511 ms 55072 KB Ok
104 Correct 550 ms 56016 KB Ok
105 Correct 511 ms 57068 KB Ok
106 Correct 461 ms 54216 KB Ok
107 Correct 506 ms 55032 KB Ok
108 Correct 587 ms 56104 KB Ok
109 Correct 507 ms 55036 KB Ok
110 Correct 1837 ms 86464 KB Ok
111 Correct 1925 ms 88028 KB Ok
112 Correct 1917 ms 88368 KB Ok
113 Execution timed out 2045 ms 86880 KB Time limit exceeded
114 Halted 0 ms 0 KB -