Submission #889504

# Submission time Handle Problem Language Result Execution time Memory
889504 2023-12-19T20:38:40 Z makrav Nice sequence (IZhO18_sequence) C++14
76 / 100
890 ms 64264 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 = 750001;
    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]++;
        }
        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 163 ms 55760 KB Ok
2 Correct 143 ms 55644 KB Ok
3 Correct 114 ms 44884 KB Ok
4 Correct 113 ms 45520 KB Ok
5 Correct 126 ms 44796 KB Ok
6 Correct 114 ms 46948 KB Ok
7 Correct 138 ms 44576 KB Ok
8 Correct 127 ms 46956 KB Ok
9 Correct 121 ms 44804 KB Ok
10 Correct 108 ms 49868 KB Ok
11 Correct 126 ms 44376 KB Ok
12 Correct 107 ms 44372 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 153 ms 55764 KB Ok
2 Correct 142 ms 55892 KB Ok
3 Correct 134 ms 55632 KB Ok
4 Correct 156 ms 55756 KB Ok
5 Correct 125 ms 55524 KB Ok
6 Correct 125 ms 55748 KB Ok
7 Correct 138 ms 56056 KB Ok
8 Correct 132 ms 55700 KB Ok
9 Correct 143 ms 56316 KB Ok
10 Correct 160 ms 55656 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 52 ms 55644 KB Ok
2 Correct 152 ms 55760 KB Ok
3 Correct 144 ms 55644 KB Ok
4 Correct 141 ms 55640 KB Ok
5 Correct 166 ms 55640 KB Ok
6 Correct 152 ms 55860 KB Ok
7 Correct 143 ms 55760 KB Ok
8 Correct 155 ms 55640 KB Ok
9 Correct 144 ms 55888 KB Ok
10 Correct 160 ms 55760 KB Ok
11 Correct 132 ms 55756 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 151 ms 55756 KB Ok
2 Correct 154 ms 55764 KB Ok
3 Correct 151 ms 55764 KB Ok
4 Correct 165 ms 55760 KB Ok
5 Correct 155 ms 55780 KB Ok
6 Correct 316 ms 61136 KB Ok
7 Correct 301 ms 60236 KB Ok
8 Correct 442 ms 63396 KB Ok
9 Correct 391 ms 64264 KB Ok
10 Correct 281 ms 60268 KB Ok
11 Correct 402 ms 62780 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 163 ms 55760 KB Ok
2 Correct 143 ms 55644 KB Ok
3 Correct 114 ms 44884 KB Ok
4 Correct 113 ms 45520 KB Ok
5 Correct 126 ms 44796 KB Ok
6 Correct 114 ms 46948 KB Ok
7 Correct 138 ms 44576 KB Ok
8 Correct 127 ms 46956 KB Ok
9 Correct 121 ms 44804 KB Ok
10 Correct 108 ms 49868 KB Ok
11 Correct 126 ms 44376 KB Ok
12 Correct 107 ms 44372 KB Ok
13 Correct 52 ms 55644 KB Ok
14 Correct 152 ms 55760 KB Ok
15 Correct 144 ms 55644 KB Ok
16 Correct 141 ms 55640 KB Ok
17 Correct 166 ms 55640 KB Ok
18 Correct 152 ms 55860 KB Ok
19 Correct 143 ms 55760 KB Ok
20 Correct 155 ms 55640 KB Ok
21 Correct 144 ms 55888 KB Ok
22 Correct 160 ms 55760 KB Ok
23 Correct 132 ms 55756 KB Ok
24 Correct 135 ms 44112 KB Ok
25 Correct 132 ms 44276 KB Ok
26 Correct 156 ms 44836 KB Ok
27 Correct 132 ms 44880 KB Ok
28 Correct 140 ms 44116 KB Ok
29 Correct 135 ms 47924 KB Ok
30 Correct 128 ms 44556 KB Ok
31 Correct 141 ms 44292 KB Ok
32 Correct 138 ms 44180 KB Ok
33 Correct 131 ms 44616 KB Ok
34 Correct 176 ms 55728 KB Ok
35 Correct 198 ms 55892 KB Ok
36 Correct 178 ms 55948 KB Ok
37 Correct 195 ms 56140 KB Ok
38 Correct 173 ms 55636 KB Ok
39 Correct 177 ms 55600 KB Ok
40 Correct 186 ms 56056 KB Ok
41 Correct 177 ms 55888 KB Ok
42 Correct 168 ms 55892 KB Ok
43 Correct 203 ms 56200 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 163 ms 55760 KB Ok
2 Correct 143 ms 55644 KB Ok
3 Correct 114 ms 44884 KB Ok
4 Correct 113 ms 45520 KB Ok
5 Correct 126 ms 44796 KB Ok
6 Correct 114 ms 46948 KB Ok
7 Correct 138 ms 44576 KB Ok
8 Correct 127 ms 46956 KB Ok
9 Correct 121 ms 44804 KB Ok
10 Correct 108 ms 49868 KB Ok
11 Correct 126 ms 44376 KB Ok
12 Correct 107 ms 44372 KB Ok
13 Correct 153 ms 55764 KB Ok
14 Correct 142 ms 55892 KB Ok
15 Correct 134 ms 55632 KB Ok
16 Correct 156 ms 55756 KB Ok
17 Correct 125 ms 55524 KB Ok
18 Correct 125 ms 55748 KB Ok
19 Correct 138 ms 56056 KB Ok
20 Correct 132 ms 55700 KB Ok
21 Correct 143 ms 56316 KB Ok
22 Correct 160 ms 55656 KB Ok
23 Correct 52 ms 55644 KB Ok
24 Correct 152 ms 55760 KB Ok
25 Correct 144 ms 55644 KB Ok
26 Correct 141 ms 55640 KB Ok
27 Correct 166 ms 55640 KB Ok
28 Correct 152 ms 55860 KB Ok
29 Correct 143 ms 55760 KB Ok
30 Correct 155 ms 55640 KB Ok
31 Correct 144 ms 55888 KB Ok
32 Correct 160 ms 55760 KB Ok
33 Correct 132 ms 55756 KB Ok
34 Correct 135 ms 44112 KB Ok
35 Correct 132 ms 44276 KB Ok
36 Correct 156 ms 44836 KB Ok
37 Correct 132 ms 44880 KB Ok
38 Correct 140 ms 44116 KB Ok
39 Correct 135 ms 47924 KB Ok
40 Correct 128 ms 44556 KB Ok
41 Correct 141 ms 44292 KB Ok
42 Correct 138 ms 44180 KB Ok
43 Correct 131 ms 44616 KB Ok
44 Correct 176 ms 55728 KB Ok
45 Correct 198 ms 55892 KB Ok
46 Correct 178 ms 55948 KB Ok
47 Correct 195 ms 56140 KB Ok
48 Correct 173 ms 55636 KB Ok
49 Correct 177 ms 55600 KB Ok
50 Correct 186 ms 56056 KB Ok
51 Correct 177 ms 55888 KB Ok
52 Correct 168 ms 55892 KB Ok
53 Correct 203 ms 56200 KB Ok
54 Correct 204 ms 48740 KB Ok
55 Correct 234 ms 49120 KB Ok
56 Correct 220 ms 48900 KB Ok
57 Correct 179 ms 48368 KB Ok
58 Correct 233 ms 48868 KB Ok
59 Correct 215 ms 48924 KB Ok
60 Correct 189 ms 48408 KB Ok
61 Correct 187 ms 48376 KB Ok
62 Correct 240 ms 49468 KB Ok
63 Correct 197 ms 48716 KB Ok
64 Correct 246 ms 49104 KB Ok
65 Correct 218 ms 49040 KB Ok
66 Correct 192 ms 48624 KB Ok
67 Correct 189 ms 48468 KB Ok
68 Correct 232 ms 48900 KB Ok
69 Correct 525 ms 59128 KB Ok
70 Correct 543 ms 62748 KB Ok
71 Correct 559 ms 59020 KB Ok
72 Correct 515 ms 61960 KB Ok
73 Correct 595 ms 59384 KB Ok
74 Correct 535 ms 58892 KB Ok
75 Correct 553 ms 58816 KB Ok
76 Correct 541 ms 62132 KB Ok
77 Correct 517 ms 58792 KB Ok
78 Correct 517 ms 61836 KB Ok
79 Correct 552 ms 62468 KB Ok
80 Correct 506 ms 62140 KB Ok
81 Correct 509 ms 62396 KB Ok
82 Correct 521 ms 62244 KB Ok
83 Correct 516 ms 58968 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 163 ms 55760 KB Ok
2 Correct 143 ms 55644 KB Ok
3 Correct 114 ms 44884 KB Ok
4 Correct 113 ms 45520 KB Ok
5 Correct 126 ms 44796 KB Ok
6 Correct 114 ms 46948 KB Ok
7 Correct 138 ms 44576 KB Ok
8 Correct 127 ms 46956 KB Ok
9 Correct 121 ms 44804 KB Ok
10 Correct 108 ms 49868 KB Ok
11 Correct 126 ms 44376 KB Ok
12 Correct 107 ms 44372 KB Ok
13 Correct 153 ms 55764 KB Ok
14 Correct 142 ms 55892 KB Ok
15 Correct 134 ms 55632 KB Ok
16 Correct 156 ms 55756 KB Ok
17 Correct 125 ms 55524 KB Ok
18 Correct 125 ms 55748 KB Ok
19 Correct 138 ms 56056 KB Ok
20 Correct 132 ms 55700 KB Ok
21 Correct 143 ms 56316 KB Ok
22 Correct 160 ms 55656 KB Ok
23 Correct 52 ms 55644 KB Ok
24 Correct 152 ms 55760 KB Ok
25 Correct 144 ms 55644 KB Ok
26 Correct 141 ms 55640 KB Ok
27 Correct 166 ms 55640 KB Ok
28 Correct 152 ms 55860 KB Ok
29 Correct 143 ms 55760 KB Ok
30 Correct 155 ms 55640 KB Ok
31 Correct 144 ms 55888 KB Ok
32 Correct 160 ms 55760 KB Ok
33 Correct 132 ms 55756 KB Ok
34 Correct 151 ms 55756 KB Ok
35 Correct 154 ms 55764 KB Ok
36 Correct 151 ms 55764 KB Ok
37 Correct 165 ms 55760 KB Ok
38 Correct 155 ms 55780 KB Ok
39 Correct 316 ms 61136 KB Ok
40 Correct 301 ms 60236 KB Ok
41 Correct 442 ms 63396 KB Ok
42 Correct 391 ms 64264 KB Ok
43 Correct 281 ms 60268 KB Ok
44 Correct 402 ms 62780 KB Ok
45 Correct 135 ms 44112 KB Ok
46 Correct 132 ms 44276 KB Ok
47 Correct 156 ms 44836 KB Ok
48 Correct 132 ms 44880 KB Ok
49 Correct 140 ms 44116 KB Ok
50 Correct 135 ms 47924 KB Ok
51 Correct 128 ms 44556 KB Ok
52 Correct 141 ms 44292 KB Ok
53 Correct 138 ms 44180 KB Ok
54 Correct 131 ms 44616 KB Ok
55 Correct 176 ms 55728 KB Ok
56 Correct 198 ms 55892 KB Ok
57 Correct 178 ms 55948 KB Ok
58 Correct 195 ms 56140 KB Ok
59 Correct 173 ms 55636 KB Ok
60 Correct 177 ms 55600 KB Ok
61 Correct 186 ms 56056 KB Ok
62 Correct 177 ms 55888 KB Ok
63 Correct 168 ms 55892 KB Ok
64 Correct 203 ms 56200 KB Ok
65 Correct 204 ms 48740 KB Ok
66 Correct 234 ms 49120 KB Ok
67 Correct 220 ms 48900 KB Ok
68 Correct 179 ms 48368 KB Ok
69 Correct 233 ms 48868 KB Ok
70 Correct 215 ms 48924 KB Ok
71 Correct 189 ms 48408 KB Ok
72 Correct 187 ms 48376 KB Ok
73 Correct 240 ms 49468 KB Ok
74 Correct 197 ms 48716 KB Ok
75 Correct 246 ms 49104 KB Ok
76 Correct 218 ms 49040 KB Ok
77 Correct 192 ms 48624 KB Ok
78 Correct 189 ms 48468 KB Ok
79 Correct 232 ms 48900 KB Ok
80 Correct 525 ms 59128 KB Ok
81 Correct 543 ms 62748 KB Ok
82 Correct 559 ms 59020 KB Ok
83 Correct 515 ms 61960 KB Ok
84 Correct 595 ms 59384 KB Ok
85 Correct 535 ms 58892 KB Ok
86 Correct 553 ms 58816 KB Ok
87 Correct 541 ms 62132 KB Ok
88 Correct 517 ms 58792 KB Ok
89 Correct 517 ms 61836 KB Ok
90 Correct 552 ms 62468 KB Ok
91 Correct 506 ms 62140 KB Ok
92 Correct 509 ms 62396 KB Ok
93 Correct 521 ms 62244 KB Ok
94 Correct 516 ms 58968 KB Ok
95 Correct 385 ms 53072 KB Ok
96 Correct 505 ms 56608 KB Ok
97 Correct 465 ms 54996 KB Ok
98 Correct 377 ms 52884 KB Ok
99 Correct 420 ms 54212 KB Ok
100 Correct 468 ms 54808 KB Ok
101 Correct 451 ms 54480 KB Ok
102 Correct 440 ms 54792 KB Ok
103 Correct 455 ms 54720 KB Ok
104 Correct 508 ms 55768 KB Ok
105 Correct 497 ms 56996 KB Ok
106 Correct 422 ms 54036 KB Ok
107 Correct 464 ms 55180 KB Ok
108 Correct 555 ms 56084 KB Ok
109 Correct 502 ms 55280 KB Ok
110 Incorrect 890 ms 62128 KB Jury has the better answer : jans = 394739, pans = 374999
111 Halted 0 ms 0 KB -