답안 #229008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229008 2020-05-03T08:57:29 Z davitmarg Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 65768 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 = 2 * 200005;

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

LL lca(LL a, LL b)
{
    return a * b / gcd(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()
{
    cin >> q;
    while (q--)
    {
        k = 0;
        scanf("%d%d", &n, &m);
        k = n + m - gcd(n, m) - 1;
        check(k);
        printf("%d\n", k);
        for (int i = 1; i <= k; i++)
        {
            printf("%d ",a[i] - a[i - 1]);
            used[i] = 0;
        }
        used[0] = 0;
        printf("\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++)
                         ~~^~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &n, &m);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 11 ms 9728 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 11 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 12 ms 9984 KB Ok
7 Correct 21 ms 10752 KB Ok
8 Correct 15 ms 10112 KB Ok
9 Correct 23 ms 10880 KB Ok
10 Correct 20 ms 10368 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 11 ms 9728 KB Ok
7 Correct 12 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 11 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9780 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 125 ms 25320 KB Ok
7 Correct 102 ms 24944 KB Ok
8 Correct 185 ms 28012 KB Ok
9 Correct 147 ms 25324 KB Ok
10 Correct 91 ms 20464 KB Ok
11 Correct 162 ms 29288 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 11 ms 9728 KB Ok
13 Correct 10 ms 9728 KB Ok
14 Correct 10 ms 9728 KB Ok
15 Correct 10 ms 9728 KB Ok
16 Correct 10 ms 9728 KB Ok
17 Correct 10 ms 9728 KB Ok
18 Correct 11 ms 9728 KB Ok
19 Correct 12 ms 9728 KB Ok
20 Correct 10 ms 9728 KB Ok
21 Correct 10 ms 9728 KB Ok
22 Correct 11 ms 9728 KB Ok
23 Correct 10 ms 9728 KB Ok
24 Correct 13 ms 9984 KB Ok
25 Correct 13 ms 9984 KB Ok
26 Correct 13 ms 9856 KB Ok
27 Correct 13 ms 9984 KB Ok
28 Correct 13 ms 9856 KB Ok
29 Correct 12 ms 9856 KB Ok
30 Correct 12 ms 9856 KB Ok
31 Correct 14 ms 9856 KB Ok
32 Correct 12 ms 9856 KB Ok
33 Correct 12 ms 9856 KB Ok
34 Correct 15 ms 10112 KB Ok
35 Correct 15 ms 10112 KB Ok
36 Correct 15 ms 10112 KB Ok
37 Correct 17 ms 10112 KB Ok
38 Correct 15 ms 10112 KB Ok
39 Correct 15 ms 10112 KB Ok
40 Correct 16 ms 10112 KB Ok
41 Correct 16 ms 10112 KB Ok
42 Correct 15 ms 10112 KB Ok
43 Correct 15 ms 10112 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 11 ms 9728 KB Ok
13 Correct 10 ms 9728 KB Ok
14 Correct 11 ms 9728 KB Ok
15 Correct 10 ms 9728 KB Ok
16 Correct 10 ms 9728 KB Ok
17 Correct 10 ms 9728 KB Ok
18 Correct 12 ms 9984 KB Ok
19 Correct 21 ms 10752 KB Ok
20 Correct 15 ms 10112 KB Ok
21 Correct 23 ms 10880 KB Ok
22 Correct 20 ms 10368 KB Ok
23 Correct 10 ms 9728 KB Ok
24 Correct 10 ms 9728 KB Ok
25 Correct 10 ms 9728 KB Ok
26 Correct 10 ms 9728 KB Ok
27 Correct 10 ms 9728 KB Ok
28 Correct 11 ms 9728 KB Ok
29 Correct 12 ms 9728 KB Ok
30 Correct 10 ms 9728 KB Ok
31 Correct 10 ms 9728 KB Ok
32 Correct 11 ms 9728 KB Ok
33 Correct 10 ms 9728 KB Ok
34 Correct 13 ms 9984 KB Ok
35 Correct 13 ms 9984 KB Ok
36 Correct 13 ms 9856 KB Ok
37 Correct 13 ms 9984 KB Ok
38 Correct 13 ms 9856 KB Ok
39 Correct 12 ms 9856 KB Ok
40 Correct 12 ms 9856 KB Ok
41 Correct 14 ms 9856 KB Ok
42 Correct 12 ms 9856 KB Ok
43 Correct 12 ms 9856 KB Ok
44 Correct 15 ms 10112 KB Ok
45 Correct 15 ms 10112 KB Ok
46 Correct 15 ms 10112 KB Ok
47 Correct 17 ms 10112 KB Ok
48 Correct 15 ms 10112 KB Ok
49 Correct 15 ms 10112 KB Ok
50 Correct 16 ms 10112 KB Ok
51 Correct 16 ms 10112 KB Ok
52 Correct 15 ms 10112 KB Ok
53 Correct 15 ms 10112 KB Ok
54 Correct 93 ms 15988 KB Ok
55 Correct 119 ms 16244 KB Ok
56 Correct 101 ms 16236 KB Ok
57 Correct 76 ms 15216 KB Ok
58 Correct 103 ms 16112 KB Ok
59 Correct 102 ms 15728 KB Ok
60 Correct 88 ms 15216 KB Ok
61 Correct 81 ms 15600 KB Ok
62 Correct 120 ms 16500 KB Ok
63 Correct 97 ms 15468 KB Ok
64 Correct 108 ms 16236 KB Ok
65 Correct 111 ms 16088 KB Ok
66 Correct 86 ms 15856 KB Ok
67 Correct 77 ms 15432 KB Ok
68 Correct 94 ms 15984 KB Ok
69 Correct 341 ms 23408 KB Ok
70 Correct 357 ms 23412 KB Ok
71 Correct 276 ms 21852 KB Ok
72 Correct 296 ms 23284 KB Ok
73 Correct 339 ms 22260 KB Ok
74 Correct 378 ms 22768 KB Ok
75 Correct 324 ms 23028 KB Ok
76 Correct 345 ms 23412 KB Ok
77 Correct 322 ms 22512 KB Ok
78 Correct 352 ms 23284 KB Ok
79 Correct 290 ms 23160 KB Ok
80 Correct 307 ms 21992 KB Ok
81 Correct 344 ms 23284 KB Ok
82 Correct 409 ms 22768 KB Ok
83 Correct 371 ms 23536 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 11 ms 9728 KB Ok
13 Correct 10 ms 9728 KB Ok
14 Correct 11 ms 9728 KB Ok
15 Correct 10 ms 9728 KB Ok
16 Correct 10 ms 9728 KB Ok
17 Correct 10 ms 9728 KB Ok
18 Correct 12 ms 9984 KB Ok
19 Correct 21 ms 10752 KB Ok
20 Correct 15 ms 10112 KB Ok
21 Correct 23 ms 10880 KB Ok
22 Correct 20 ms 10368 KB Ok
23 Correct 10 ms 9728 KB Ok
24 Correct 10 ms 9728 KB Ok
25 Correct 10 ms 9728 KB Ok
26 Correct 10 ms 9728 KB Ok
27 Correct 10 ms 9728 KB Ok
28 Correct 11 ms 9728 KB Ok
29 Correct 12 ms 9728 KB Ok
30 Correct 10 ms 9728 KB Ok
31 Correct 10 ms 9728 KB Ok
32 Correct 11 ms 9728 KB Ok
33 Correct 10 ms 9728 KB Ok
34 Correct 13 ms 9728 KB Ok
35 Correct 10 ms 9728 KB Ok
36 Correct 10 ms 9728 KB Ok
37 Correct 10 ms 9780 KB Ok
38 Correct 10 ms 9728 KB Ok
39 Correct 125 ms 25320 KB Ok
40 Correct 102 ms 24944 KB Ok
41 Correct 185 ms 28012 KB Ok
42 Correct 147 ms 25324 KB Ok
43 Correct 91 ms 20464 KB Ok
44 Correct 162 ms 29288 KB Ok
45 Correct 13 ms 9984 KB Ok
46 Correct 13 ms 9984 KB Ok
47 Correct 13 ms 9856 KB Ok
48 Correct 13 ms 9984 KB Ok
49 Correct 13 ms 9856 KB Ok
50 Correct 12 ms 9856 KB Ok
51 Correct 12 ms 9856 KB Ok
52 Correct 14 ms 9856 KB Ok
53 Correct 12 ms 9856 KB Ok
54 Correct 12 ms 9856 KB Ok
55 Correct 15 ms 10112 KB Ok
56 Correct 15 ms 10112 KB Ok
57 Correct 15 ms 10112 KB Ok
58 Correct 17 ms 10112 KB Ok
59 Correct 15 ms 10112 KB Ok
60 Correct 15 ms 10112 KB Ok
61 Correct 16 ms 10112 KB Ok
62 Correct 16 ms 10112 KB Ok
63 Correct 15 ms 10112 KB Ok
64 Correct 15 ms 10112 KB Ok
65 Correct 93 ms 15988 KB Ok
66 Correct 119 ms 16244 KB Ok
67 Correct 101 ms 16236 KB Ok
68 Correct 76 ms 15216 KB Ok
69 Correct 103 ms 16112 KB Ok
70 Correct 102 ms 15728 KB Ok
71 Correct 88 ms 15216 KB Ok
72 Correct 81 ms 15600 KB Ok
73 Correct 120 ms 16500 KB Ok
74 Correct 97 ms 15468 KB Ok
75 Correct 108 ms 16236 KB Ok
76 Correct 111 ms 16088 KB Ok
77 Correct 86 ms 15856 KB Ok
78 Correct 77 ms 15432 KB Ok
79 Correct 94 ms 15984 KB Ok
80 Correct 341 ms 23408 KB Ok
81 Correct 357 ms 23412 KB Ok
82 Correct 276 ms 21852 KB Ok
83 Correct 296 ms 23284 KB Ok
84 Correct 339 ms 22260 KB Ok
85 Correct 378 ms 22768 KB Ok
86 Correct 324 ms 23028 KB Ok
87 Correct 345 ms 23412 KB Ok
88 Correct 322 ms 22512 KB Ok
89 Correct 352 ms 23284 KB Ok
90 Correct 290 ms 23160 KB Ok
91 Correct 307 ms 21992 KB Ok
92 Correct 344 ms 23284 KB Ok
93 Correct 409 ms 22768 KB Ok
94 Correct 371 ms 23536 KB Ok
95 Correct 237 ms 25704 KB Ok
96 Correct 332 ms 33460 KB Ok
97 Correct 341 ms 29612 KB Ok
98 Correct 234 ms 29028 KB Ok
99 Correct 261 ms 28648 KB Ok
100 Correct 291 ms 29028 KB Ok
101 Correct 278 ms 31332 KB Ok
102 Correct 275 ms 29640 KB Ok
103 Correct 279 ms 30820 KB Ok
104 Correct 326 ms 32356 KB Ok
105 Correct 316 ms 33128 KB Ok
106 Correct 262 ms 32100 KB Ok
107 Correct 303 ms 31844 KB Ok
108 Correct 351 ms 33252 KB Ok
109 Correct 301 ms 33644 KB Ok
110 Correct 1858 ms 65768 KB Ok
111 Execution timed out 2083 ms 63924 KB Time limit exceeded
112 Halted 0 ms 0 KB -