Submission #234118

# Submission time Handle Problem Language Result Execution time Memory
234118 2020-05-23T08:06:05 Z davitmarg Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 150120 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)
{
    while (a && b)
    {
        a %= b;
        swap(a, b);
    }
    return a + 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--)
    {
        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:44: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:77: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 56 ms 94328 KB Ok
2 Correct 57 ms 94328 KB Ok
3 Correct 58 ms 94212 KB Ok
4 Correct 57 ms 94328 KB Ok
5 Correct 58 ms 94328 KB Ok
6 Correct 56 ms 94328 KB Ok
7 Correct 56 ms 94328 KB Ok
8 Correct 56 ms 94328 KB Ok
9 Correct 55 ms 94328 KB Ok
10 Correct 58 ms 94272 KB Ok
11 Correct 57 ms 94336 KB Ok
12 Correct 56 ms 94328 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 57 ms 94328 KB Ok
2 Correct 57 ms 94328 KB Ok
3 Correct 56 ms 94328 KB Ok
4 Correct 57 ms 94328 KB Ok
5 Correct 56 ms 94332 KB Ok
6 Correct 59 ms 94456 KB Ok
7 Correct 66 ms 95352 KB Ok
8 Correct 60 ms 94712 KB Ok
9 Correct 68 ms 95480 KB Ok
10 Correct 64 ms 94968 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 94328 KB Ok
2 Correct 61 ms 94332 KB Ok
3 Correct 55 ms 94328 KB Ok
4 Correct 56 ms 94328 KB Ok
5 Correct 56 ms 94328 KB Ok
6 Correct 56 ms 94328 KB Ok
7 Correct 57 ms 94336 KB Ok
8 Correct 56 ms 94328 KB Ok
9 Correct 58 ms 94328 KB Ok
10 Correct 57 ms 94328 KB Ok
11 Correct 58 ms 94328 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 94328 KB Ok
2 Correct 56 ms 94336 KB Ok
3 Correct 58 ms 94328 KB Ok
4 Correct 55 ms 94328 KB Ok
5 Correct 56 ms 94328 KB Ok
6 Correct 162 ms 109932 KB Ok
7 Correct 143 ms 109420 KB Ok
8 Correct 218 ms 112728 KB Ok
9 Correct 186 ms 109928 KB Ok
10 Correct 131 ms 105072 KB Ok
11 Correct 204 ms 113768 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 94328 KB Ok
2 Correct 57 ms 94328 KB Ok
3 Correct 58 ms 94212 KB Ok
4 Correct 57 ms 94328 KB Ok
5 Correct 58 ms 94328 KB Ok
6 Correct 56 ms 94328 KB Ok
7 Correct 56 ms 94328 KB Ok
8 Correct 56 ms 94328 KB Ok
9 Correct 55 ms 94328 KB Ok
10 Correct 58 ms 94272 KB Ok
11 Correct 57 ms 94336 KB Ok
12 Correct 56 ms 94328 KB Ok
13 Correct 56 ms 94328 KB Ok
14 Correct 61 ms 94332 KB Ok
15 Correct 55 ms 94328 KB Ok
16 Correct 56 ms 94328 KB Ok
17 Correct 56 ms 94328 KB Ok
18 Correct 56 ms 94328 KB Ok
19 Correct 57 ms 94336 KB Ok
20 Correct 56 ms 94328 KB Ok
21 Correct 58 ms 94328 KB Ok
22 Correct 57 ms 94328 KB Ok
23 Correct 58 ms 94328 KB Ok
24 Correct 58 ms 94456 KB Ok
25 Correct 59 ms 94456 KB Ok
26 Correct 58 ms 94456 KB Ok
27 Correct 62 ms 94456 KB Ok
28 Correct 57 ms 94456 KB Ok
29 Correct 56 ms 94456 KB Ok
30 Correct 57 ms 94456 KB Ok
31 Correct 57 ms 94456 KB Ok
32 Correct 59 ms 94456 KB Ok
33 Correct 57 ms 94456 KB Ok
34 Correct 62 ms 94712 KB Ok
35 Correct 61 ms 94644 KB Ok
36 Correct 60 ms 94712 KB Ok
37 Correct 59 ms 94712 KB Ok
38 Correct 60 ms 94712 KB Ok
39 Correct 61 ms 94712 KB Ok
40 Correct 63 ms 94840 KB Ok
41 Correct 62 ms 94712 KB Ok
42 Correct 61 ms 94712 KB Ok
43 Correct 60 ms 94712 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 94328 KB Ok
2 Correct 57 ms 94328 KB Ok
3 Correct 58 ms 94212 KB Ok
4 Correct 57 ms 94328 KB Ok
5 Correct 58 ms 94328 KB Ok
6 Correct 56 ms 94328 KB Ok
7 Correct 56 ms 94328 KB Ok
8 Correct 56 ms 94328 KB Ok
9 Correct 55 ms 94328 KB Ok
10 Correct 58 ms 94272 KB Ok
11 Correct 57 ms 94336 KB Ok
12 Correct 56 ms 94328 KB Ok
13 Correct 57 ms 94328 KB Ok
14 Correct 57 ms 94328 KB Ok
15 Correct 56 ms 94328 KB Ok
16 Correct 57 ms 94328 KB Ok
17 Correct 56 ms 94332 KB Ok
18 Correct 59 ms 94456 KB Ok
19 Correct 66 ms 95352 KB Ok
20 Correct 60 ms 94712 KB Ok
21 Correct 68 ms 95480 KB Ok
22 Correct 64 ms 94968 KB Ok
23 Correct 56 ms 94328 KB Ok
24 Correct 61 ms 94332 KB Ok
25 Correct 55 ms 94328 KB Ok
26 Correct 56 ms 94328 KB Ok
27 Correct 56 ms 94328 KB Ok
28 Correct 56 ms 94328 KB Ok
29 Correct 57 ms 94336 KB Ok
30 Correct 56 ms 94328 KB Ok
31 Correct 58 ms 94328 KB Ok
32 Correct 57 ms 94328 KB Ok
33 Correct 58 ms 94328 KB Ok
34 Correct 58 ms 94456 KB Ok
35 Correct 59 ms 94456 KB Ok
36 Correct 58 ms 94456 KB Ok
37 Correct 62 ms 94456 KB Ok
38 Correct 57 ms 94456 KB Ok
39 Correct 56 ms 94456 KB Ok
40 Correct 57 ms 94456 KB Ok
41 Correct 57 ms 94456 KB Ok
42 Correct 59 ms 94456 KB Ok
43 Correct 57 ms 94456 KB Ok
44 Correct 62 ms 94712 KB Ok
45 Correct 61 ms 94644 KB Ok
46 Correct 60 ms 94712 KB Ok
47 Correct 59 ms 94712 KB Ok
48 Correct 60 ms 94712 KB Ok
49 Correct 61 ms 94712 KB Ok
50 Correct 63 ms 94840 KB Ok
51 Correct 62 ms 94712 KB Ok
52 Correct 61 ms 94712 KB Ok
53 Correct 60 ms 94712 KB Ok
54 Correct 132 ms 100464 KB Ok
55 Correct 144 ms 100852 KB Ok
56 Correct 136 ms 100852 KB Ok
57 Correct 121 ms 99828 KB Ok
58 Correct 137 ms 100592 KB Ok
59 Correct 131 ms 100336 KB Ok
60 Correct 124 ms 99824 KB Ok
61 Correct 121 ms 100212 KB Ok
62 Correct 156 ms 101104 KB Ok
63 Correct 129 ms 100084 KB Ok
64 Correct 144 ms 100724 KB Ok
65 Correct 142 ms 100724 KB Ok
66 Correct 124 ms 100340 KB Ok
67 Correct 120 ms 100108 KB Ok
68 Correct 133 ms 100588 KB Ok
69 Correct 317 ms 108016 KB Ok
70 Correct 375 ms 107888 KB Ok
71 Correct 272 ms 106352 KB Ok
72 Correct 368 ms 107888 KB Ok
73 Correct 385 ms 106736 KB Ok
74 Correct 328 ms 107120 KB Ok
75 Correct 319 ms 107632 KB Ok
76 Correct 355 ms 108112 KB Ok
77 Correct 323 ms 107012 KB Ok
78 Correct 378 ms 107756 KB Ok
79 Correct 308 ms 107376 KB Ok
80 Correct 277 ms 106480 KB Ok
81 Correct 351 ms 107968 KB Ok
82 Correct 320 ms 107248 KB Ok
83 Correct 311 ms 107888 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 56 ms 94328 KB Ok
2 Correct 57 ms 94328 KB Ok
3 Correct 58 ms 94212 KB Ok
4 Correct 57 ms 94328 KB Ok
5 Correct 58 ms 94328 KB Ok
6 Correct 56 ms 94328 KB Ok
7 Correct 56 ms 94328 KB Ok
8 Correct 56 ms 94328 KB Ok
9 Correct 55 ms 94328 KB Ok
10 Correct 58 ms 94272 KB Ok
11 Correct 57 ms 94336 KB Ok
12 Correct 56 ms 94328 KB Ok
13 Correct 57 ms 94328 KB Ok
14 Correct 57 ms 94328 KB Ok
15 Correct 56 ms 94328 KB Ok
16 Correct 57 ms 94328 KB Ok
17 Correct 56 ms 94332 KB Ok
18 Correct 59 ms 94456 KB Ok
19 Correct 66 ms 95352 KB Ok
20 Correct 60 ms 94712 KB Ok
21 Correct 68 ms 95480 KB Ok
22 Correct 64 ms 94968 KB Ok
23 Correct 56 ms 94328 KB Ok
24 Correct 61 ms 94332 KB Ok
25 Correct 55 ms 94328 KB Ok
26 Correct 56 ms 94328 KB Ok
27 Correct 56 ms 94328 KB Ok
28 Correct 56 ms 94328 KB Ok
29 Correct 57 ms 94336 KB Ok
30 Correct 56 ms 94328 KB Ok
31 Correct 58 ms 94328 KB Ok
32 Correct 57 ms 94328 KB Ok
33 Correct 58 ms 94328 KB Ok
34 Correct 56 ms 94328 KB Ok
35 Correct 56 ms 94336 KB Ok
36 Correct 58 ms 94328 KB Ok
37 Correct 55 ms 94328 KB Ok
38 Correct 56 ms 94328 KB Ok
39 Correct 162 ms 109932 KB Ok
40 Correct 143 ms 109420 KB Ok
41 Correct 218 ms 112728 KB Ok
42 Correct 186 ms 109928 KB Ok
43 Correct 131 ms 105072 KB Ok
44 Correct 204 ms 113768 KB Ok
45 Correct 58 ms 94456 KB Ok
46 Correct 59 ms 94456 KB Ok
47 Correct 58 ms 94456 KB Ok
48 Correct 62 ms 94456 KB Ok
49 Correct 57 ms 94456 KB Ok
50 Correct 56 ms 94456 KB Ok
51 Correct 57 ms 94456 KB Ok
52 Correct 57 ms 94456 KB Ok
53 Correct 59 ms 94456 KB Ok
54 Correct 57 ms 94456 KB Ok
55 Correct 62 ms 94712 KB Ok
56 Correct 61 ms 94644 KB Ok
57 Correct 60 ms 94712 KB Ok
58 Correct 59 ms 94712 KB Ok
59 Correct 60 ms 94712 KB Ok
60 Correct 61 ms 94712 KB Ok
61 Correct 63 ms 94840 KB Ok
62 Correct 62 ms 94712 KB Ok
63 Correct 61 ms 94712 KB Ok
64 Correct 60 ms 94712 KB Ok
65 Correct 132 ms 100464 KB Ok
66 Correct 144 ms 100852 KB Ok
67 Correct 136 ms 100852 KB Ok
68 Correct 121 ms 99828 KB Ok
69 Correct 137 ms 100592 KB Ok
70 Correct 131 ms 100336 KB Ok
71 Correct 124 ms 99824 KB Ok
72 Correct 121 ms 100212 KB Ok
73 Correct 156 ms 101104 KB Ok
74 Correct 129 ms 100084 KB Ok
75 Correct 144 ms 100724 KB Ok
76 Correct 142 ms 100724 KB Ok
77 Correct 124 ms 100340 KB Ok
78 Correct 120 ms 100108 KB Ok
79 Correct 133 ms 100588 KB Ok
80 Correct 317 ms 108016 KB Ok
81 Correct 375 ms 107888 KB Ok
82 Correct 272 ms 106352 KB Ok
83 Correct 368 ms 107888 KB Ok
84 Correct 385 ms 106736 KB Ok
85 Correct 328 ms 107120 KB Ok
86 Correct 319 ms 107632 KB Ok
87 Correct 355 ms 108112 KB Ok
88 Correct 323 ms 107012 KB Ok
89 Correct 378 ms 107756 KB Ok
90 Correct 308 ms 107376 KB Ok
91 Correct 277 ms 106480 KB Ok
92 Correct 351 ms 107968 KB Ok
93 Correct 320 ms 107248 KB Ok
94 Correct 311 ms 107888 KB Ok
95 Correct 264 ms 110324 KB Ok
96 Correct 339 ms 117992 KB Ok
97 Correct 349 ms 114020 KB Ok
98 Correct 263 ms 113644 KB Ok
99 Correct 295 ms 113124 KB Ok
100 Correct 303 ms 113512 KB Ok
101 Correct 311 ms 115824 KB Ok
102 Correct 307 ms 114264 KB Ok
103 Correct 307 ms 115428 KB Ok
104 Correct 337 ms 116972 KB Ok
105 Correct 346 ms 117732 KB Ok
106 Correct 286 ms 116712 KB Ok
107 Correct 330 ms 116456 KB Ok
108 Correct 360 ms 117860 KB Ok
109 Correct 315 ms 118244 KB Ok
110 Correct 1845 ms 150120 KB Ok
111 Execution timed out 2090 ms 148456 KB Time limit exceeded
112 Halted 0 ms 0 KB -