Submission #513594

# Submission time Handle Problem Language Result Execution time Memory
513594 2022-01-17T09:43:13 Z Killer2501 Nice sequence (IZhO18_sequence) C++14
100 / 100
1345 ms 71112 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 5e5+5;
const int M = (1<<17);
const ll inf = 1e15;
const ll mod = 1e15+7;
int n, t, k, m, d[N], in[N], out[N];
ll ans, tong, a[N], b[N], c[N];
string s[N];
struct node
{
    int x[2];
    set<int> vi;
    node(){}
    node( int _x, int _y)
    {
        x[0] = _x;
        x[1] = _y;
    }

};
vector<node> q;
vector<int> adj[N], kq;
void dfs(int u)
{
    a[u] = ++t;
    if(u+m <= k && a[u+m] == 0)dfs(u+m);
    if(u-n >= 0 && a[u-n] == 0)dfs(u-n);
}
bool check(int mid)
{
    k = mid;
    for(int i = 0; i <= k; i ++)adj[i].clear();
    fill_n(a, k+1, 0);
    t = 0;
    for(int i = 0; i <= k; i ++)
    {
        if(i+m <= k)
        {
            adj[i].pb(i+m);
            ++a[i+m];
        }
        if(i >= n)
        {
            adj[i].pb(i-n);
            ++a[i-n];
        }
    }
    queue<int> q;
    for(int i = 0; i <= k; i ++)if(a[i] == 0)q.push(i);
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        a[u] = ++t;
        for(int v: adj[u])
        {
            --a[v];
            if(a[v] == 0)q.push(v);
        }
    }
    if(t == k+1)return true;
    return false;
}
void sol()
{
    cin >> n >> m;
    ans = n+m-__gcd(m,n)-1;
    check(ans);
    cout << ans << '\n';
    for(int i = 1; i <= ans; i ++)cout << a[i]-a[i-1] <<" ";
    cout << '\n';
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:90:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27724 KB Ok
2 Correct 13 ms 27744 KB Ok
3 Correct 14 ms 27724 KB Ok
4 Correct 15 ms 27724 KB Ok
5 Correct 16 ms 27724 KB Ok
6 Correct 13 ms 27668 KB Ok
7 Correct 13 ms 27724 KB Ok
8 Correct 13 ms 27724 KB Ok
9 Correct 13 ms 27724 KB Ok
10 Correct 13 ms 27724 KB Ok
11 Correct 13 ms 27684 KB Ok
12 Correct 12 ms 27656 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27732 KB Ok
2 Correct 13 ms 27724 KB Ok
3 Correct 12 ms 27724 KB Ok
4 Correct 12 ms 27724 KB Ok
5 Correct 13 ms 27624 KB Ok
6 Correct 13 ms 27792 KB Ok
7 Correct 20 ms 28360 KB Ok
8 Correct 19 ms 28036 KB Ok
9 Correct 23 ms 28508 KB Ok
10 Correct 20 ms 28088 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27652 KB Ok
2 Correct 12 ms 27724 KB Ok
3 Correct 12 ms 27724 KB Ok
4 Correct 13 ms 27724 KB Ok
5 Correct 15 ms 27724 KB Ok
6 Correct 13 ms 27720 KB Ok
7 Correct 13 ms 27684 KB Ok
8 Correct 13 ms 27732 KB Ok
9 Correct 12 ms 27612 KB Ok
10 Correct 13 ms 27704 KB Ok
11 Correct 13 ms 27688 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27724 KB Ok
2 Correct 14 ms 27736 KB Ok
3 Correct 13 ms 27680 KB Ok
4 Correct 13 ms 27736 KB Ok
5 Correct 17 ms 27664 KB Ok
6 Correct 86 ms 36884 KB Ok
7 Correct 73 ms 37428 KB Ok
8 Correct 130 ms 39572 KB Ok
9 Correct 101 ms 38948 KB Ok
10 Correct 67 ms 33860 KB Ok
11 Correct 95 ms 38884 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27724 KB Ok
2 Correct 13 ms 27744 KB Ok
3 Correct 14 ms 27724 KB Ok
4 Correct 15 ms 27724 KB Ok
5 Correct 16 ms 27724 KB Ok
6 Correct 13 ms 27668 KB Ok
7 Correct 13 ms 27724 KB Ok
8 Correct 13 ms 27724 KB Ok
9 Correct 13 ms 27724 KB Ok
10 Correct 13 ms 27724 KB Ok
11 Correct 13 ms 27684 KB Ok
12 Correct 12 ms 27656 KB Ok
13 Correct 13 ms 27652 KB Ok
14 Correct 12 ms 27724 KB Ok
15 Correct 12 ms 27724 KB Ok
16 Correct 13 ms 27724 KB Ok
17 Correct 15 ms 27724 KB Ok
18 Correct 13 ms 27720 KB Ok
19 Correct 13 ms 27684 KB Ok
20 Correct 13 ms 27732 KB Ok
21 Correct 12 ms 27612 KB Ok
22 Correct 13 ms 27704 KB Ok
23 Correct 13 ms 27688 KB Ok
24 Correct 15 ms 27868 KB Ok
25 Correct 15 ms 27852 KB Ok
26 Correct 18 ms 27792 KB Ok
27 Correct 14 ms 27900 KB Ok
28 Correct 15 ms 27816 KB Ok
29 Correct 13 ms 27852 KB Ok
30 Correct 14 ms 27852 KB Ok
31 Correct 14 ms 27852 KB Ok
32 Correct 15 ms 27852 KB Ok
33 Correct 14 ms 27852 KB Ok
34 Correct 15 ms 27968 KB Ok
35 Correct 15 ms 28024 KB Ok
36 Correct 16 ms 27952 KB Ok
37 Correct 15 ms 28040 KB Ok
38 Correct 17 ms 27968 KB Ok
39 Correct 16 ms 27976 KB Ok
40 Correct 20 ms 27992 KB Ok
41 Correct 19 ms 27980 KB Ok
42 Correct 16 ms 27960 KB Ok
43 Correct 16 ms 27980 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27724 KB Ok
2 Correct 13 ms 27744 KB Ok
3 Correct 14 ms 27724 KB Ok
4 Correct 15 ms 27724 KB Ok
5 Correct 16 ms 27724 KB Ok
6 Correct 13 ms 27668 KB Ok
7 Correct 13 ms 27724 KB Ok
8 Correct 13 ms 27724 KB Ok
9 Correct 13 ms 27724 KB Ok
10 Correct 13 ms 27724 KB Ok
11 Correct 13 ms 27684 KB Ok
12 Correct 12 ms 27656 KB Ok
13 Correct 15 ms 27732 KB Ok
14 Correct 13 ms 27724 KB Ok
15 Correct 12 ms 27724 KB Ok
16 Correct 12 ms 27724 KB Ok
17 Correct 13 ms 27624 KB Ok
18 Correct 13 ms 27792 KB Ok
19 Correct 20 ms 28360 KB Ok
20 Correct 19 ms 28036 KB Ok
21 Correct 23 ms 28508 KB Ok
22 Correct 20 ms 28088 KB Ok
23 Correct 13 ms 27652 KB Ok
24 Correct 12 ms 27724 KB Ok
25 Correct 12 ms 27724 KB Ok
26 Correct 13 ms 27724 KB Ok
27 Correct 15 ms 27724 KB Ok
28 Correct 13 ms 27720 KB Ok
29 Correct 13 ms 27684 KB Ok
30 Correct 13 ms 27732 KB Ok
31 Correct 12 ms 27612 KB Ok
32 Correct 13 ms 27704 KB Ok
33 Correct 13 ms 27688 KB Ok
34 Correct 15 ms 27868 KB Ok
35 Correct 15 ms 27852 KB Ok
36 Correct 18 ms 27792 KB Ok
37 Correct 14 ms 27900 KB Ok
38 Correct 15 ms 27816 KB Ok
39 Correct 13 ms 27852 KB Ok
40 Correct 14 ms 27852 KB Ok
41 Correct 14 ms 27852 KB Ok
42 Correct 15 ms 27852 KB Ok
43 Correct 14 ms 27852 KB Ok
44 Correct 15 ms 27968 KB Ok
45 Correct 15 ms 28024 KB Ok
46 Correct 16 ms 27952 KB Ok
47 Correct 15 ms 28040 KB Ok
48 Correct 17 ms 27968 KB Ok
49 Correct 16 ms 27976 KB Ok
50 Correct 20 ms 27992 KB Ok
51 Correct 19 ms 27980 KB Ok
52 Correct 16 ms 27960 KB Ok
53 Correct 16 ms 27980 KB Ok
54 Correct 65 ms 32828 KB Ok
55 Correct 75 ms 32800 KB Ok
56 Correct 76 ms 32984 KB Ok
57 Correct 58 ms 32296 KB Ok
58 Correct 69 ms 32792 KB Ok
59 Correct 65 ms 32604 KB Ok
60 Correct 67 ms 32120 KB Ok
61 Correct 61 ms 32508 KB Ok
62 Correct 75 ms 32912 KB Ok
63 Correct 74 ms 32356 KB Ok
64 Correct 70 ms 32764 KB Ok
65 Correct 90 ms 32856 KB Ok
66 Correct 68 ms 32560 KB Ok
67 Correct 74 ms 32336 KB Ok
68 Correct 63 ms 32784 KB Ok
69 Correct 139 ms 36864 KB Ok
70 Correct 148 ms 38156 KB Ok
71 Correct 121 ms 36140 KB Ok
72 Correct 128 ms 37188 KB Ok
73 Correct 182 ms 36672 KB Ok
74 Correct 141 ms 35704 KB Ok
75 Correct 151 ms 35652 KB Ok
76 Correct 147 ms 37812 KB Ok
77 Correct 127 ms 35300 KB Ok
78 Correct 190 ms 37640 KB Ok
79 Correct 163 ms 36960 KB Ok
80 Correct 150 ms 36676 KB Ok
81 Correct 139 ms 37352 KB Ok
82 Correct 223 ms 36776 KB Ok
83 Correct 146 ms 35732 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27724 KB Ok
2 Correct 13 ms 27744 KB Ok
3 Correct 14 ms 27724 KB Ok
4 Correct 15 ms 27724 KB Ok
5 Correct 16 ms 27724 KB Ok
6 Correct 13 ms 27668 KB Ok
7 Correct 13 ms 27724 KB Ok
8 Correct 13 ms 27724 KB Ok
9 Correct 13 ms 27724 KB Ok
10 Correct 13 ms 27724 KB Ok
11 Correct 13 ms 27684 KB Ok
12 Correct 12 ms 27656 KB Ok
13 Correct 15 ms 27732 KB Ok
14 Correct 13 ms 27724 KB Ok
15 Correct 12 ms 27724 KB Ok
16 Correct 12 ms 27724 KB Ok
17 Correct 13 ms 27624 KB Ok
18 Correct 13 ms 27792 KB Ok
19 Correct 20 ms 28360 KB Ok
20 Correct 19 ms 28036 KB Ok
21 Correct 23 ms 28508 KB Ok
22 Correct 20 ms 28088 KB Ok
23 Correct 13 ms 27652 KB Ok
24 Correct 12 ms 27724 KB Ok
25 Correct 12 ms 27724 KB Ok
26 Correct 13 ms 27724 KB Ok
27 Correct 15 ms 27724 KB Ok
28 Correct 13 ms 27720 KB Ok
29 Correct 13 ms 27684 KB Ok
30 Correct 13 ms 27732 KB Ok
31 Correct 12 ms 27612 KB Ok
32 Correct 13 ms 27704 KB Ok
33 Correct 13 ms 27688 KB Ok
34 Correct 13 ms 27724 KB Ok
35 Correct 14 ms 27736 KB Ok
36 Correct 13 ms 27680 KB Ok
37 Correct 13 ms 27736 KB Ok
38 Correct 17 ms 27664 KB Ok
39 Correct 86 ms 36884 KB Ok
40 Correct 73 ms 37428 KB Ok
41 Correct 130 ms 39572 KB Ok
42 Correct 101 ms 38948 KB Ok
43 Correct 67 ms 33860 KB Ok
44 Correct 95 ms 38884 KB Ok
45 Correct 15 ms 27868 KB Ok
46 Correct 15 ms 27852 KB Ok
47 Correct 18 ms 27792 KB Ok
48 Correct 14 ms 27900 KB Ok
49 Correct 15 ms 27816 KB Ok
50 Correct 13 ms 27852 KB Ok
51 Correct 14 ms 27852 KB Ok
52 Correct 14 ms 27852 KB Ok
53 Correct 15 ms 27852 KB Ok
54 Correct 14 ms 27852 KB Ok
55 Correct 15 ms 27968 KB Ok
56 Correct 15 ms 28024 KB Ok
57 Correct 16 ms 27952 KB Ok
58 Correct 15 ms 28040 KB Ok
59 Correct 17 ms 27968 KB Ok
60 Correct 16 ms 27976 KB Ok
61 Correct 20 ms 27992 KB Ok
62 Correct 19 ms 27980 KB Ok
63 Correct 16 ms 27960 KB Ok
64 Correct 16 ms 27980 KB Ok
65 Correct 65 ms 32828 KB Ok
66 Correct 75 ms 32800 KB Ok
67 Correct 76 ms 32984 KB Ok
68 Correct 58 ms 32296 KB Ok
69 Correct 69 ms 32792 KB Ok
70 Correct 65 ms 32604 KB Ok
71 Correct 67 ms 32120 KB Ok
72 Correct 61 ms 32508 KB Ok
73 Correct 75 ms 32912 KB Ok
74 Correct 74 ms 32356 KB Ok
75 Correct 70 ms 32764 KB Ok
76 Correct 90 ms 32856 KB Ok
77 Correct 68 ms 32560 KB Ok
78 Correct 74 ms 32336 KB Ok
79 Correct 63 ms 32784 KB Ok
80 Correct 139 ms 36864 KB Ok
81 Correct 148 ms 38156 KB Ok
82 Correct 121 ms 36140 KB Ok
83 Correct 128 ms 37188 KB Ok
84 Correct 182 ms 36672 KB Ok
85 Correct 141 ms 35704 KB Ok
86 Correct 151 ms 35652 KB Ok
87 Correct 147 ms 37812 KB Ok
88 Correct 127 ms 35300 KB Ok
89 Correct 190 ms 37640 KB Ok
90 Correct 163 ms 36960 KB Ok
91 Correct 150 ms 36676 KB Ok
92 Correct 139 ms 37352 KB Ok
93 Correct 223 ms 36776 KB Ok
94 Correct 146 ms 35732 KB Ok
95 Correct 159 ms 40956 KB Ok
96 Correct 216 ms 46772 KB Ok
97 Correct 210 ms 43712 KB Ok
98 Correct 170 ms 43896 KB Ok
99 Correct 207 ms 43344 KB Ok
100 Correct 211 ms 42632 KB Ok
101 Correct 212 ms 45624 KB Ok
102 Correct 254 ms 43468 KB Ok
103 Correct 204 ms 44408 KB Ok
104 Correct 287 ms 46068 KB Ok
105 Correct 213 ms 46200 KB Ok
106 Correct 182 ms 46348 KB Ok
107 Correct 226 ms 45724 KB Ok
108 Correct 228 ms 46112 KB Ok
109 Correct 213 ms 47240 KB Ok
110 Correct 768 ms 61284 KB Ok
111 Correct 1223 ms 71112 KB Ok
112 Correct 861 ms 63336 KB Ok
113 Correct 1036 ms 67440 KB Ok
114 Correct 1056 ms 68808 KB Ok
115 Correct 1167 ms 68104 KB Ok
116 Correct 1020 ms 67868 KB Ok
117 Correct 1113 ms 68768 KB Ok
118 Correct 937 ms 64300 KB Ok
119 Correct 1200 ms 70024 KB Ok
120 Correct 916 ms 64468 KB Ok
121 Correct 971 ms 63324 KB Ok
122 Correct 941 ms 66308 KB Ok
123 Correct 1345 ms 71112 KB Ok
124 Correct 747 ms 60172 KB Ok
125 Correct 399 ms 53372 KB Ok