Submission #234117

# Submission time Handle Problem Language Result Execution time Memory
234117 2020-05-23T08:02:52 Z davitmarg Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 150124 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 4000006;

int gcd(int a, int b)
{
    if (!a || !b)
        return a + b;
    return gcd(b, a % b);
}

int lca(int a, int b)
{
    return a / gcd(a, b) * b;
}

int q, n, m, k, a[N], used[N], tin[N];
vector<int> t, g[N];

void dfs(int v)
{
    used[v] = 1;
    for (int i = 0; i < g[v].size(); i++)
    {
        int to = g[v][i];
        if (used[to])
            continue;
        dfs(to);
    }
    //tin[v] = -t.size();
    t.PB(v);
}

void check(int x)
{
    t.clear();
    for (int i = 0; i <= x; i++)
        g[i].clear();

    for (int i = 0; i <= x; i++)
    {
        if (i - m >= 0)
            g[i - m].PB(i);
        if (i + n <= x)
            g[i + n].PB(i);
    }
    for (int i = 0; i <= x; i++)
        if (!used[i])
            dfs(i);

    int v, to;
    for (int i = t.size() - 1; i >= 0; i--)
    {
        v = t[i];
        a[v] = t.size() - i;
        for (int j = 0; j < g[v].size(); j++)
        {
            to = g[v][j];
            a[to] = a[v] + 1;
        }
    }
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> q;
    while (q--)
    {
        k = 0;
        cin >> n >> m;
        k = n + m - gcd(n, m) - 1;
        check(k);
        cout << k << "\n";
        for (int i = 1; i <= k; i++)
        {
            cout << (a[i] - a[i - 1]) << " ";
            used[i] = 0;
        }
        used[0] = 0;
        cout << "\n";
    }
    return 0;
}

/*



*/

Compilation message

sequence.cpp: In function 'void dfs(int)':
sequence.cpp:46:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++)
                     ~~^~~~~~~~~~~~~
sequence.cpp: In function 'void check(int)':
sequence.cpp:79:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < g[v].size(); j++)
                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94328 KB Ok
2 Correct 54 ms 94332 KB Ok
3 Correct 57 ms 94328 KB Ok
4 Correct 57 ms 94456 KB Ok
5 Correct 53 ms 94328 KB Ok
6 Correct 54 ms 94328 KB Ok
7 Correct 55 ms 94328 KB Ok
8 Correct 56 ms 94332 KB Ok
9 Correct 54 ms 94328 KB Ok
10 Correct 58 ms 94336 KB Ok
11 Correct 55 ms 94328 KB Ok
12 Correct 56 ms 94328 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 54 ms 94328 KB Ok
2 Correct 56 ms 94300 KB Ok
3 Correct 55 ms 94328 KB Ok
4 Correct 55 ms 94328 KB Ok
5 Correct 56 ms 94328 KB Ok
6 Correct 57 ms 94456 KB Ok
7 Correct 63 ms 95224 KB Ok
8 Correct 58 ms 94712 KB Ok
9 Correct 68 ms 95480 KB Ok
10 Correct 61 ms 94968 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 54 ms 94332 KB Ok
2 Correct 57 ms 94332 KB Ok
3 Correct 55 ms 94336 KB Ok
4 Correct 55 ms 94336 KB Ok
5 Correct 54 ms 94328 KB Ok
6 Correct 55 ms 94328 KB Ok
7 Correct 55 ms 94328 KB Ok
8 Correct 55 ms 94332 KB Ok
9 Correct 55 ms 94328 KB Ok
10 Correct 60 ms 94328 KB Ok
11 Correct 55 ms 94328 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 55 ms 94328 KB Ok
2 Correct 56 ms 94328 KB Ok
3 Correct 57 ms 94328 KB Ok
4 Correct 55 ms 94328 KB Ok
5 Correct 55 ms 94328 KB Ok
6 Correct 163 ms 109936 KB Ok
7 Correct 137 ms 109420 KB Ok
8 Correct 219 ms 112632 KB Ok
9 Correct 178 ms 109800 KB Ok
10 Correct 130 ms 105072 KB Ok
11 Correct 186 ms 113768 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94328 KB Ok
2 Correct 54 ms 94332 KB Ok
3 Correct 57 ms 94328 KB Ok
4 Correct 57 ms 94456 KB Ok
5 Correct 53 ms 94328 KB Ok
6 Correct 54 ms 94328 KB Ok
7 Correct 55 ms 94328 KB Ok
8 Correct 56 ms 94332 KB Ok
9 Correct 54 ms 94328 KB Ok
10 Correct 58 ms 94336 KB Ok
11 Correct 55 ms 94328 KB Ok
12 Correct 56 ms 94328 KB Ok
13 Correct 54 ms 94332 KB Ok
14 Correct 57 ms 94332 KB Ok
15 Correct 55 ms 94336 KB Ok
16 Correct 55 ms 94336 KB Ok
17 Correct 54 ms 94328 KB Ok
18 Correct 55 ms 94328 KB Ok
19 Correct 55 ms 94328 KB Ok
20 Correct 55 ms 94332 KB Ok
21 Correct 55 ms 94328 KB Ok
22 Correct 60 ms 94328 KB Ok
23 Correct 55 ms 94328 KB Ok
24 Correct 57 ms 94456 KB Ok
25 Correct 57 ms 94456 KB Ok
26 Correct 57 ms 94456 KB Ok
27 Correct 57 ms 94456 KB Ok
28 Correct 56 ms 94456 KB Ok
29 Correct 58 ms 94456 KB Ok
30 Correct 56 ms 94456 KB Ok
31 Correct 59 ms 94456 KB Ok
32 Correct 57 ms 94460 KB Ok
33 Correct 57 ms 94456 KB Ok
34 Correct 60 ms 94840 KB Ok
35 Correct 61 ms 94712 KB Ok
36 Correct 60 ms 94712 KB Ok
37 Correct 59 ms 94712 KB Ok
38 Correct 59 ms 94716 KB Ok
39 Correct 58 ms 94712 KB Ok
40 Correct 59 ms 94780 KB Ok
41 Correct 59 ms 94712 KB Ok
42 Correct 60 ms 94712 KB Ok
43 Correct 58 ms 94588 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94328 KB Ok
2 Correct 54 ms 94332 KB Ok
3 Correct 57 ms 94328 KB Ok
4 Correct 57 ms 94456 KB Ok
5 Correct 53 ms 94328 KB Ok
6 Correct 54 ms 94328 KB Ok
7 Correct 55 ms 94328 KB Ok
8 Correct 56 ms 94332 KB Ok
9 Correct 54 ms 94328 KB Ok
10 Correct 58 ms 94336 KB Ok
11 Correct 55 ms 94328 KB Ok
12 Correct 56 ms 94328 KB Ok
13 Correct 54 ms 94328 KB Ok
14 Correct 56 ms 94300 KB Ok
15 Correct 55 ms 94328 KB Ok
16 Correct 55 ms 94328 KB Ok
17 Correct 56 ms 94328 KB Ok
18 Correct 57 ms 94456 KB Ok
19 Correct 63 ms 95224 KB Ok
20 Correct 58 ms 94712 KB Ok
21 Correct 68 ms 95480 KB Ok
22 Correct 61 ms 94968 KB Ok
23 Correct 54 ms 94332 KB Ok
24 Correct 57 ms 94332 KB Ok
25 Correct 55 ms 94336 KB Ok
26 Correct 55 ms 94336 KB Ok
27 Correct 54 ms 94328 KB Ok
28 Correct 55 ms 94328 KB Ok
29 Correct 55 ms 94328 KB Ok
30 Correct 55 ms 94332 KB Ok
31 Correct 55 ms 94328 KB Ok
32 Correct 60 ms 94328 KB Ok
33 Correct 55 ms 94328 KB Ok
34 Correct 57 ms 94456 KB Ok
35 Correct 57 ms 94456 KB Ok
36 Correct 57 ms 94456 KB Ok
37 Correct 57 ms 94456 KB Ok
38 Correct 56 ms 94456 KB Ok
39 Correct 58 ms 94456 KB Ok
40 Correct 56 ms 94456 KB Ok
41 Correct 59 ms 94456 KB Ok
42 Correct 57 ms 94460 KB Ok
43 Correct 57 ms 94456 KB Ok
44 Correct 60 ms 94840 KB Ok
45 Correct 61 ms 94712 KB Ok
46 Correct 60 ms 94712 KB Ok
47 Correct 59 ms 94712 KB Ok
48 Correct 59 ms 94716 KB Ok
49 Correct 58 ms 94712 KB Ok
50 Correct 59 ms 94780 KB Ok
51 Correct 59 ms 94712 KB Ok
52 Correct 60 ms 94712 KB Ok
53 Correct 58 ms 94588 KB Ok
54 Correct 134 ms 100460 KB Ok
55 Correct 145 ms 100852 KB Ok
56 Correct 145 ms 100852 KB Ok
57 Correct 119 ms 99828 KB Ok
58 Correct 135 ms 100600 KB Ok
59 Correct 132 ms 100332 KB Ok
60 Correct 121 ms 99824 KB Ok
61 Correct 119 ms 100212 KB Ok
62 Correct 145 ms 101104 KB Ok
63 Correct 129 ms 100084 KB Ok
64 Correct 149 ms 100724 KB Ok
65 Correct 137 ms 100720 KB Ok
66 Correct 121 ms 100340 KB Ok
67 Correct 117 ms 100084 KB Ok
68 Correct 127 ms 100592 KB Ok
69 Correct 348 ms 107888 KB Ok
70 Correct 394 ms 107888 KB Ok
71 Correct 285 ms 106352 KB Ok
72 Correct 354 ms 107888 KB Ok
73 Correct 397 ms 106736 KB Ok
74 Correct 350 ms 107376 KB Ok
75 Correct 285 ms 107616 KB Ok
76 Correct 371 ms 107972 KB Ok
77 Correct 320 ms 106984 KB Ok
78 Correct 338 ms 107864 KB Ok
79 Correct 395 ms 107376 KB Ok
80 Correct 282 ms 106608 KB Ok
81 Correct 294 ms 107884 KB Ok
82 Correct 325 ms 107248 KB Ok
83 Correct 316 ms 108116 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 53 ms 94328 KB Ok
2 Correct 54 ms 94332 KB Ok
3 Correct 57 ms 94328 KB Ok
4 Correct 57 ms 94456 KB Ok
5 Correct 53 ms 94328 KB Ok
6 Correct 54 ms 94328 KB Ok
7 Correct 55 ms 94328 KB Ok
8 Correct 56 ms 94332 KB Ok
9 Correct 54 ms 94328 KB Ok
10 Correct 58 ms 94336 KB Ok
11 Correct 55 ms 94328 KB Ok
12 Correct 56 ms 94328 KB Ok
13 Correct 54 ms 94328 KB Ok
14 Correct 56 ms 94300 KB Ok
15 Correct 55 ms 94328 KB Ok
16 Correct 55 ms 94328 KB Ok
17 Correct 56 ms 94328 KB Ok
18 Correct 57 ms 94456 KB Ok
19 Correct 63 ms 95224 KB Ok
20 Correct 58 ms 94712 KB Ok
21 Correct 68 ms 95480 KB Ok
22 Correct 61 ms 94968 KB Ok
23 Correct 54 ms 94332 KB Ok
24 Correct 57 ms 94332 KB Ok
25 Correct 55 ms 94336 KB Ok
26 Correct 55 ms 94336 KB Ok
27 Correct 54 ms 94328 KB Ok
28 Correct 55 ms 94328 KB Ok
29 Correct 55 ms 94328 KB Ok
30 Correct 55 ms 94332 KB Ok
31 Correct 55 ms 94328 KB Ok
32 Correct 60 ms 94328 KB Ok
33 Correct 55 ms 94328 KB Ok
34 Correct 55 ms 94328 KB Ok
35 Correct 56 ms 94328 KB Ok
36 Correct 57 ms 94328 KB Ok
37 Correct 55 ms 94328 KB Ok
38 Correct 55 ms 94328 KB Ok
39 Correct 163 ms 109936 KB Ok
40 Correct 137 ms 109420 KB Ok
41 Correct 219 ms 112632 KB Ok
42 Correct 178 ms 109800 KB Ok
43 Correct 130 ms 105072 KB Ok
44 Correct 186 ms 113768 KB Ok
45 Correct 57 ms 94456 KB Ok
46 Correct 57 ms 94456 KB Ok
47 Correct 57 ms 94456 KB Ok
48 Correct 57 ms 94456 KB Ok
49 Correct 56 ms 94456 KB Ok
50 Correct 58 ms 94456 KB Ok
51 Correct 56 ms 94456 KB Ok
52 Correct 59 ms 94456 KB Ok
53 Correct 57 ms 94460 KB Ok
54 Correct 57 ms 94456 KB Ok
55 Correct 60 ms 94840 KB Ok
56 Correct 61 ms 94712 KB Ok
57 Correct 60 ms 94712 KB Ok
58 Correct 59 ms 94712 KB Ok
59 Correct 59 ms 94716 KB Ok
60 Correct 58 ms 94712 KB Ok
61 Correct 59 ms 94780 KB Ok
62 Correct 59 ms 94712 KB Ok
63 Correct 60 ms 94712 KB Ok
64 Correct 58 ms 94588 KB Ok
65 Correct 134 ms 100460 KB Ok
66 Correct 145 ms 100852 KB Ok
67 Correct 145 ms 100852 KB Ok
68 Correct 119 ms 99828 KB Ok
69 Correct 135 ms 100600 KB Ok
70 Correct 132 ms 100332 KB Ok
71 Correct 121 ms 99824 KB Ok
72 Correct 119 ms 100212 KB Ok
73 Correct 145 ms 101104 KB Ok
74 Correct 129 ms 100084 KB Ok
75 Correct 149 ms 100724 KB Ok
76 Correct 137 ms 100720 KB Ok
77 Correct 121 ms 100340 KB Ok
78 Correct 117 ms 100084 KB Ok
79 Correct 127 ms 100592 KB Ok
80 Correct 348 ms 107888 KB Ok
81 Correct 394 ms 107888 KB Ok
82 Correct 285 ms 106352 KB Ok
83 Correct 354 ms 107888 KB Ok
84 Correct 397 ms 106736 KB Ok
85 Correct 350 ms 107376 KB Ok
86 Correct 285 ms 107616 KB Ok
87 Correct 371 ms 107972 KB Ok
88 Correct 320 ms 106984 KB Ok
89 Correct 338 ms 107864 KB Ok
90 Correct 395 ms 107376 KB Ok
91 Correct 282 ms 106608 KB Ok
92 Correct 294 ms 107884 KB Ok
93 Correct 325 ms 107248 KB Ok
94 Correct 316 ms 108116 KB Ok
95 Correct 264 ms 110316 KB Ok
96 Correct 343 ms 117992 KB Ok
97 Correct 345 ms 114148 KB Ok
98 Correct 269 ms 113680 KB Ok
99 Correct 288 ms 113232 KB Ok
100 Correct 309 ms 113604 KB Ok
101 Correct 304 ms 115744 KB Ok
102 Correct 299 ms 114152 KB Ok
103 Correct 309 ms 115428 KB Ok
104 Correct 337 ms 116968 KB Ok
105 Correct 344 ms 117664 KB Ok
106 Correct 290 ms 116712 KB Ok
107 Correct 323 ms 116456 KB Ok
108 Correct 360 ms 117732 KB Ok
109 Correct 309 ms 118116 KB Ok
110 Correct 1871 ms 150124 KB Ok
111 Execution timed out 2088 ms 148584 KB Time limit exceeded
112 Halted 0 ms 0 KB -