Submission #686744

# Submission time Handle Problem Language Result Execution time Memory
686744 2023-01-25T21:36:23 Z quinque Nice sequence (IZhO18_sequence) C++17
100 / 100
1985 ms 73800 KB
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4,avx2,fma,avx")
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define unit unsigned int
#define ld double
#define F first
#define S second
// chrono::system_clock::now().time_since_epoch().count());

using namespace std;
const int N = 4e5 + 100, IINF = 1e9 + 10, LOG = 19, K = 1 << 10;
const ll INF = 1e18 + 214;
bitset<N> usd;
int pref[N];
vector<int> g[N];

vector<int> top;
void dfs(int v){
    if (usd[v])
        return;
    usd[v] = 1;
    for (auto i : g[v])
        dfs(i);
    top.push_back(v);
}

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int nw = 0;

void fill(int v){
    if (usd[v])
        return;
    usd[v] = 1;
    nw --;
    for (auto i : g[v]){
        pref[i] = pref[v] - 1;
        fill(i);
    }
}

inline void solve(){
    int n, m;
    cin >> n >> m;
    int start = -1;
    if (n > m)
        swap(n, m), start *= -1;
    int l = n + m - 1 - gcd(n, m);
    cout << l << '\n';
    for (int i = 0; i <= l; i ++){
        g[i].clear();
        if (i + m <= l)
            g[i].push_back(i + m);
        if (i - n >= 0)
            g[i].push_back(i - n);
    }
    usd = 0;
    top.clear();
    for (int i = 0; i <= l; i ++){
        if (usd[i])
            continue;
        dfs(i);
    }
    //cout << "why" << '\n';
    reverse(top.begin(), top.end());
    usd = 0;
    nw = IINF;
    for (auto i: top){
        if (!usd[i]){
            pref[i] = nw;
            fill(i);
        }
    }
    for (int i = 1; i <= l; i ++)
        cout << (pref[i] - pref[i - 1]) * start << ' ';
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Ok
2 Correct 5 ms 9812 KB Ok
3 Correct 5 ms 9812 KB Ok
4 Correct 6 ms 9812 KB Ok
5 Correct 7 ms 9812 KB Ok
6 Correct 5 ms 9812 KB Ok
7 Correct 5 ms 9812 KB Ok
8 Correct 5 ms 9812 KB Ok
9 Correct 5 ms 9812 KB Ok
10 Correct 5 ms 9812 KB Ok
11 Correct 5 ms 9812 KB Ok
12 Correct 5 ms 9684 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9812 KB Ok
3 Correct 5 ms 9812 KB Ok
4 Correct 5 ms 9812 KB Ok
5 Correct 6 ms 9812 KB Ok
6 Correct 7 ms 10052 KB Ok
7 Correct 14 ms 10980 KB Ok
8 Correct 10 ms 10380 KB Ok
9 Correct 18 ms 11220 KB Ok
10 Correct 11 ms 10580 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Ok
2 Correct 6 ms 9736 KB Ok
3 Correct 6 ms 9812 KB Ok
4 Correct 5 ms 9812 KB Ok
5 Correct 5 ms 9684 KB Ok
6 Correct 5 ms 9696 KB Ok
7 Correct 6 ms 9812 KB Ok
8 Correct 5 ms 9812 KB Ok
9 Correct 5 ms 9776 KB Ok
10 Correct 6 ms 9684 KB Ok
11 Correct 5 ms 9812 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9696 KB Ok
3 Correct 6 ms 9812 KB Ok
4 Correct 5 ms 9812 KB Ok
5 Correct 5 ms 9812 KB Ok
6 Correct 114 ms 27784 KB Ok
7 Correct 93 ms 28896 KB Ok
8 Correct 159 ms 32256 KB Ok
9 Correct 152 ms 29888 KB Ok
10 Correct 76 ms 21552 KB Ok
11 Correct 130 ms 31528 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Ok
2 Correct 5 ms 9812 KB Ok
3 Correct 5 ms 9812 KB Ok
4 Correct 6 ms 9812 KB Ok
5 Correct 7 ms 9812 KB Ok
6 Correct 5 ms 9812 KB Ok
7 Correct 5 ms 9812 KB Ok
8 Correct 5 ms 9812 KB Ok
9 Correct 5 ms 9812 KB Ok
10 Correct 5 ms 9812 KB Ok
11 Correct 5 ms 9812 KB Ok
12 Correct 5 ms 9684 KB Ok
13 Correct 5 ms 9812 KB Ok
14 Correct 6 ms 9736 KB Ok
15 Correct 6 ms 9812 KB Ok
16 Correct 5 ms 9812 KB Ok
17 Correct 5 ms 9684 KB Ok
18 Correct 5 ms 9696 KB Ok
19 Correct 6 ms 9812 KB Ok
20 Correct 5 ms 9812 KB Ok
21 Correct 5 ms 9776 KB Ok
22 Correct 6 ms 9684 KB Ok
23 Correct 5 ms 9812 KB Ok
24 Correct 6 ms 9940 KB Ok
25 Correct 6 ms 9940 KB Ok
26 Correct 7 ms 9940 KB Ok
27 Correct 6 ms 9940 KB Ok
28 Correct 6 ms 9940 KB Ok
29 Correct 6 ms 9940 KB Ok
30 Correct 6 ms 9940 KB Ok
31 Correct 6 ms 9940 KB Ok
32 Correct 7 ms 9940 KB Ok
33 Correct 7 ms 9880 KB Ok
34 Correct 10 ms 10284 KB Ok
35 Correct 9 ms 10196 KB Ok
36 Correct 8 ms 10284 KB Ok
37 Correct 9 ms 10264 KB Ok
38 Correct 10 ms 10224 KB Ok
39 Correct 8 ms 10196 KB Ok
40 Correct 9 ms 10196 KB Ok
41 Correct 9 ms 10276 KB Ok
42 Correct 9 ms 10232 KB Ok
43 Correct 9 ms 10228 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Ok
2 Correct 5 ms 9812 KB Ok
3 Correct 5 ms 9812 KB Ok
4 Correct 6 ms 9812 KB Ok
5 Correct 7 ms 9812 KB Ok
6 Correct 5 ms 9812 KB Ok
7 Correct 5 ms 9812 KB Ok
8 Correct 5 ms 9812 KB Ok
9 Correct 5 ms 9812 KB Ok
10 Correct 5 ms 9812 KB Ok
11 Correct 5 ms 9812 KB Ok
12 Correct 5 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 5 ms 9812 KB Ok
15 Correct 5 ms 9812 KB Ok
16 Correct 5 ms 9812 KB Ok
17 Correct 6 ms 9812 KB Ok
18 Correct 7 ms 10052 KB Ok
19 Correct 14 ms 10980 KB Ok
20 Correct 10 ms 10380 KB Ok
21 Correct 18 ms 11220 KB Ok
22 Correct 11 ms 10580 KB Ok
23 Correct 5 ms 9812 KB Ok
24 Correct 6 ms 9736 KB Ok
25 Correct 6 ms 9812 KB Ok
26 Correct 5 ms 9812 KB Ok
27 Correct 5 ms 9684 KB Ok
28 Correct 5 ms 9696 KB Ok
29 Correct 6 ms 9812 KB Ok
30 Correct 5 ms 9812 KB Ok
31 Correct 5 ms 9776 KB Ok
32 Correct 6 ms 9684 KB Ok
33 Correct 5 ms 9812 KB Ok
34 Correct 6 ms 9940 KB Ok
35 Correct 6 ms 9940 KB Ok
36 Correct 7 ms 9940 KB Ok
37 Correct 6 ms 9940 KB Ok
38 Correct 6 ms 9940 KB Ok
39 Correct 6 ms 9940 KB Ok
40 Correct 6 ms 9940 KB Ok
41 Correct 6 ms 9940 KB Ok
42 Correct 7 ms 9940 KB Ok
43 Correct 7 ms 9880 KB Ok
44 Correct 10 ms 10284 KB Ok
45 Correct 9 ms 10196 KB Ok
46 Correct 8 ms 10284 KB Ok
47 Correct 9 ms 10264 KB Ok
48 Correct 10 ms 10224 KB Ok
49 Correct 8 ms 10196 KB Ok
50 Correct 9 ms 10196 KB Ok
51 Correct 9 ms 10276 KB Ok
52 Correct 9 ms 10232 KB Ok
53 Correct 9 ms 10228 KB Ok
54 Correct 74 ms 15652 KB Ok
55 Correct 86 ms 15944 KB Ok
56 Correct 92 ms 15860 KB Ok
57 Correct 60 ms 15004 KB Ok
58 Correct 81 ms 15596 KB Ok
59 Correct 91 ms 15432 KB Ok
60 Correct 65 ms 14944 KB Ok
61 Correct 67 ms 15228 KB Ok
62 Correct 87 ms 16112 KB Ok
63 Correct 74 ms 15336 KB Ok
64 Correct 86 ms 16084 KB Ok
65 Correct 79 ms 15816 KB Ok
66 Correct 93 ms 15512 KB Ok
67 Correct 62 ms 15076 KB Ok
68 Correct 74 ms 15732 KB Ok
69 Correct 235 ms 24648 KB Ok
70 Correct 270 ms 25044 KB Ok
71 Correct 222 ms 25060 KB Ok
72 Correct 241 ms 24660 KB Ok
73 Correct 237 ms 24944 KB Ok
74 Correct 248 ms 24976 KB Ok
75 Correct 240 ms 24676 KB Ok
76 Correct 221 ms 24752 KB Ok
77 Correct 222 ms 24896 KB Ok
78 Correct 246 ms 24472 KB Ok
79 Correct 260 ms 24900 KB Ok
80 Correct 256 ms 24988 KB Ok
81 Correct 222 ms 24868 KB Ok
82 Correct 267 ms 24936 KB Ok
83 Correct 221 ms 25048 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Ok
2 Correct 5 ms 9812 KB Ok
3 Correct 5 ms 9812 KB Ok
4 Correct 6 ms 9812 KB Ok
5 Correct 7 ms 9812 KB Ok
6 Correct 5 ms 9812 KB Ok
7 Correct 5 ms 9812 KB Ok
8 Correct 5 ms 9812 KB Ok
9 Correct 5 ms 9812 KB Ok
10 Correct 5 ms 9812 KB Ok
11 Correct 5 ms 9812 KB Ok
12 Correct 5 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 5 ms 9812 KB Ok
15 Correct 5 ms 9812 KB Ok
16 Correct 5 ms 9812 KB Ok
17 Correct 6 ms 9812 KB Ok
18 Correct 7 ms 10052 KB Ok
19 Correct 14 ms 10980 KB Ok
20 Correct 10 ms 10380 KB Ok
21 Correct 18 ms 11220 KB Ok
22 Correct 11 ms 10580 KB Ok
23 Correct 5 ms 9812 KB Ok
24 Correct 6 ms 9736 KB Ok
25 Correct 6 ms 9812 KB Ok
26 Correct 5 ms 9812 KB Ok
27 Correct 5 ms 9684 KB Ok
28 Correct 5 ms 9696 KB Ok
29 Correct 6 ms 9812 KB Ok
30 Correct 5 ms 9812 KB Ok
31 Correct 5 ms 9776 KB Ok
32 Correct 6 ms 9684 KB Ok
33 Correct 5 ms 9812 KB Ok
34 Correct 5 ms 9684 KB Ok
35 Correct 5 ms 9696 KB Ok
36 Correct 6 ms 9812 KB Ok
37 Correct 5 ms 9812 KB Ok
38 Correct 5 ms 9812 KB Ok
39 Correct 114 ms 27784 KB Ok
40 Correct 93 ms 28896 KB Ok
41 Correct 159 ms 32256 KB Ok
42 Correct 152 ms 29888 KB Ok
43 Correct 76 ms 21552 KB Ok
44 Correct 130 ms 31528 KB Ok
45 Correct 6 ms 9940 KB Ok
46 Correct 6 ms 9940 KB Ok
47 Correct 7 ms 9940 KB Ok
48 Correct 6 ms 9940 KB Ok
49 Correct 6 ms 9940 KB Ok
50 Correct 6 ms 9940 KB Ok
51 Correct 6 ms 9940 KB Ok
52 Correct 6 ms 9940 KB Ok
53 Correct 7 ms 9940 KB Ok
54 Correct 7 ms 9880 KB Ok
55 Correct 10 ms 10284 KB Ok
56 Correct 9 ms 10196 KB Ok
57 Correct 8 ms 10284 KB Ok
58 Correct 9 ms 10264 KB Ok
59 Correct 10 ms 10224 KB Ok
60 Correct 8 ms 10196 KB Ok
61 Correct 9 ms 10196 KB Ok
62 Correct 9 ms 10276 KB Ok
63 Correct 9 ms 10232 KB Ok
64 Correct 9 ms 10228 KB Ok
65 Correct 74 ms 15652 KB Ok
66 Correct 86 ms 15944 KB Ok
67 Correct 92 ms 15860 KB Ok
68 Correct 60 ms 15004 KB Ok
69 Correct 81 ms 15596 KB Ok
70 Correct 91 ms 15432 KB Ok
71 Correct 65 ms 14944 KB Ok
72 Correct 67 ms 15228 KB Ok
73 Correct 87 ms 16112 KB Ok
74 Correct 74 ms 15336 KB Ok
75 Correct 86 ms 16084 KB Ok
76 Correct 79 ms 15816 KB Ok
77 Correct 93 ms 15512 KB Ok
78 Correct 62 ms 15076 KB Ok
79 Correct 74 ms 15732 KB Ok
80 Correct 235 ms 24648 KB Ok
81 Correct 270 ms 25044 KB Ok
82 Correct 222 ms 25060 KB Ok
83 Correct 241 ms 24660 KB Ok
84 Correct 237 ms 24944 KB Ok
85 Correct 248 ms 24976 KB Ok
86 Correct 240 ms 24676 KB Ok
87 Correct 221 ms 24752 KB Ok
88 Correct 222 ms 24896 KB Ok
89 Correct 246 ms 24472 KB Ok
90 Correct 260 ms 24900 KB Ok
91 Correct 256 ms 24988 KB Ok
92 Correct 222 ms 24868 KB Ok
93 Correct 267 ms 24936 KB Ok
94 Correct 221 ms 25048 KB Ok
95 Correct 204 ms 24648 KB Ok
96 Correct 277 ms 31244 KB Ok
97 Correct 288 ms 27896 KB Ok
98 Correct 190 ms 27136 KB Ok
99 Correct 215 ms 27164 KB Ok
100 Correct 251 ms 27808 KB Ok
101 Correct 244 ms 29792 KB Ok
102 Correct 258 ms 28768 KB Ok
103 Correct 257 ms 29324 KB Ok
104 Correct 308 ms 31484 KB Ok
105 Correct 265 ms 31432 KB Ok
106 Correct 274 ms 30636 KB Ok
107 Correct 248 ms 31012 KB Ok
108 Correct 306 ms 31596 KB Ok
109 Correct 296 ms 31528 KB Ok
110 Correct 1700 ms 70840 KB Ok
111 Correct 1900 ms 71972 KB Ok
112 Correct 1952 ms 73800 KB Ok
113 Correct 1697 ms 71812 KB Ok
114 Correct 1807 ms 73484 KB Ok
115 Correct 1985 ms 72332 KB Ok
116 Correct 1930 ms 73236 KB Ok
117 Correct 1758 ms 71372 KB Ok
118 Correct 1898 ms 73664 KB Ok
119 Correct 1792 ms 70816 KB Ok
120 Correct 1805 ms 71960 KB Ok
121 Correct 1764 ms 71988 KB Ok
122 Correct 1733 ms 72400 KB Ok
123 Correct 1901 ms 71984 KB Ok
124 Correct 1785 ms 72248 KB Ok
125 Correct 469 ms 54400 KB Ok