Submission #1073739

# Submission time Handle Problem Language Result Execution time Memory
1073739 2024-08-24T19:39:32 Z Sputnik123 Nice sequence (IZhO18_sequence) C++17
100 / 100
694 ms 52672 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define in insert
#define pll pair<ll,ll>
#define vpl vector<pll>
#define vll vector <ll>
#define vl vector<ll>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()
#define endl "\n"
#define ull unsigned long long
#define ld long double
using namespace std;
//using namespace __gnu_pbds;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,fma")
const ll sz= 9e5 + 5;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;
const ll eps = 1e-12;
const ll P1=47; // for hashing 
const ll P2=41; // for hashing 
//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// ll idx = 1;
ll n, m, ln, pref[sz], a[sz];
bool used[sz];
vll order;
void dfs(ll node)
{
    if(used[node])
        return;
    used[node] = 1;
    if(node + n <= ln)
        dfs(node + n);
    if(node - m >= 0)
        dfs(node - m);
    order.push_back(node);
}
bool check(ll mid)
{
    order.clear();
    ln = mid;
    memset(used, 0, sizeof(used));
    for(ll i = 0 ; i <= ln; i++)
        dfs(i);
    for(ll i = 0; i <= ln; i++)
        pref[order[i]] = i + 1;
    for(ll i = n; i <= ln; i++)
        if(pref[i] - pref[i - n] >= 0)
            return 0;
    for(ll i = m; i <= ln; i++)
        if(pref[i] - pref[i - m] <= 0)
            return 0;
    for(ll i = 1; i <= ln; i++)
        a[i] = pref[i] - pref[i - 1];
    return 1;
}
void solve()
{
    cin >> n >> m;
    ll l = 1, r = max(n, m) * 2;
    while(l <= r)
    {
        ll mid = (l + r) / 2;
        if(check(mid))
            l = mid + 1;
        else
            r = mid - 1;
    }
    cout << l - 1 << "\n";
    for(ll i = 1; i <= l - 1; ++i)
        cout << a[i] << " ";
    cout << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long t = 1;
    cin >> t;
    while(t--)
    {	   
        // cout << "Case " << (int) ix <<":\n";
        solve();
        ///idx++;
    }
}
/* 
Note : don`t use fast input in interactive questions
Note : Compare long double with eps = 1e-12
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Ok
2 Correct 2 ms 4752 KB Ok
3 Correct 2 ms 4752 KB Ok
4 Correct 2 ms 4700 KB Ok
5 Correct 2 ms 4700 KB Ok
6 Correct 2 ms 4700 KB Ok
7 Correct 2 ms 4700 KB Ok
8 Correct 2 ms 4700 KB Ok
9 Correct 2 ms 4700 KB Ok
10 Correct 2 ms 4700 KB Ok
11 Correct 2 ms 4700 KB Ok
12 Correct 2 ms 4700 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Ok
2 Correct 2 ms 4696 KB Ok
3 Correct 2 ms 4744 KB Ok
4 Correct 2 ms 4748 KB Ok
5 Correct 2 ms 4700 KB Ok
6 Correct 4 ms 4700 KB Ok
7 Correct 14 ms 5468 KB Ok
8 Correct 7 ms 4956 KB Ok
9 Correct 13 ms 5724 KB Ok
10 Correct 10 ms 5212 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Ok
2 Correct 1 ms 4700 KB Ok
3 Correct 1 ms 4700 KB Ok
4 Correct 1 ms 4700 KB Ok
5 Correct 1 ms 4564 KB Ok
6 Correct 1 ms 4700 KB Ok
7 Correct 1 ms 4700 KB Ok
8 Correct 1 ms 4700 KB Ok
9 Correct 1 ms 4700 KB Ok
10 Correct 1 ms 4700 KB Ok
11 Correct 1 ms 4700 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Ok
2 Correct 2 ms 4700 KB Ok
3 Correct 2 ms 4700 KB Ok
4 Correct 2 ms 4700 KB Ok
5 Correct 2 ms 4700 KB Ok
6 Correct 82 ms 15144 KB Ok
7 Correct 73 ms 17100 KB Ok
8 Correct 152 ms 20164 KB Ok
9 Correct 106 ms 16604 KB Ok
10 Correct 63 ms 11472 KB Ok
11 Correct 103 ms 18632 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Ok
2 Correct 2 ms 4752 KB Ok
3 Correct 2 ms 4752 KB Ok
4 Correct 2 ms 4700 KB Ok
5 Correct 2 ms 4700 KB Ok
6 Correct 2 ms 4700 KB Ok
7 Correct 2 ms 4700 KB Ok
8 Correct 2 ms 4700 KB Ok
9 Correct 2 ms 4700 KB Ok
10 Correct 2 ms 4700 KB Ok
11 Correct 2 ms 4700 KB Ok
12 Correct 2 ms 4700 KB Ok
13 Correct 1 ms 4700 KB Ok
14 Correct 1 ms 4700 KB Ok
15 Correct 1 ms 4700 KB Ok
16 Correct 1 ms 4700 KB Ok
17 Correct 1 ms 4564 KB Ok
18 Correct 1 ms 4700 KB Ok
19 Correct 1 ms 4700 KB Ok
20 Correct 1 ms 4700 KB Ok
21 Correct 1 ms 4700 KB Ok
22 Correct 1 ms 4700 KB Ok
23 Correct 1 ms 4700 KB Ok
24 Correct 4 ms 4696 KB Ok
25 Correct 4 ms 4700 KB Ok
26 Correct 4 ms 4824 KB Ok
27 Correct 4 ms 4700 KB Ok
28 Correct 4 ms 4700 KB Ok
29 Correct 4 ms 4700 KB Ok
30 Correct 4 ms 4700 KB Ok
31 Correct 4 ms 4700 KB Ok
32 Correct 4 ms 4700 KB Ok
33 Correct 4 ms 4700 KB Ok
34 Correct 6 ms 4956 KB Ok
35 Correct 7 ms 4956 KB Ok
36 Correct 7 ms 4956 KB Ok
37 Correct 6 ms 4956 KB Ok
38 Correct 7 ms 4952 KB Ok
39 Correct 6 ms 4852 KB Ok
40 Correct 7 ms 4956 KB Ok
41 Correct 7 ms 4956 KB Ok
42 Correct 6 ms 4956 KB Ok
43 Correct 7 ms 4956 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Ok
2 Correct 2 ms 4752 KB Ok
3 Correct 2 ms 4752 KB Ok
4 Correct 2 ms 4700 KB Ok
5 Correct 2 ms 4700 KB Ok
6 Correct 2 ms 4700 KB Ok
7 Correct 2 ms 4700 KB Ok
8 Correct 2 ms 4700 KB Ok
9 Correct 2 ms 4700 KB Ok
10 Correct 2 ms 4700 KB Ok
11 Correct 2 ms 4700 KB Ok
12 Correct 2 ms 4700 KB Ok
13 Correct 1 ms 4700 KB Ok
14 Correct 2 ms 4696 KB Ok
15 Correct 2 ms 4744 KB Ok
16 Correct 2 ms 4748 KB Ok
17 Correct 2 ms 4700 KB Ok
18 Correct 4 ms 4700 KB Ok
19 Correct 14 ms 5468 KB Ok
20 Correct 7 ms 4956 KB Ok
21 Correct 13 ms 5724 KB Ok
22 Correct 10 ms 5212 KB Ok
23 Correct 1 ms 4700 KB Ok
24 Correct 1 ms 4700 KB Ok
25 Correct 1 ms 4700 KB Ok
26 Correct 1 ms 4700 KB Ok
27 Correct 1 ms 4564 KB Ok
28 Correct 1 ms 4700 KB Ok
29 Correct 1 ms 4700 KB Ok
30 Correct 1 ms 4700 KB Ok
31 Correct 1 ms 4700 KB Ok
32 Correct 1 ms 4700 KB Ok
33 Correct 1 ms 4700 KB Ok
34 Correct 4 ms 4696 KB Ok
35 Correct 4 ms 4700 KB Ok
36 Correct 4 ms 4824 KB Ok
37 Correct 4 ms 4700 KB Ok
38 Correct 4 ms 4700 KB Ok
39 Correct 4 ms 4700 KB Ok
40 Correct 4 ms 4700 KB Ok
41 Correct 4 ms 4700 KB Ok
42 Correct 4 ms 4700 KB Ok
43 Correct 4 ms 4700 KB Ok
44 Correct 6 ms 4956 KB Ok
45 Correct 7 ms 4956 KB Ok
46 Correct 7 ms 4956 KB Ok
47 Correct 6 ms 4956 KB Ok
48 Correct 7 ms 4952 KB Ok
49 Correct 6 ms 4852 KB Ok
50 Correct 7 ms 4956 KB Ok
51 Correct 7 ms 4956 KB Ok
52 Correct 6 ms 4956 KB Ok
53 Correct 7 ms 4956 KB Ok
54 Correct 70 ms 9168 KB Ok
55 Correct 74 ms 9420 KB Ok
56 Correct 74 ms 9512 KB Ok
57 Correct 58 ms 8924 KB Ok
58 Correct 65 ms 8928 KB Ok
59 Correct 63 ms 8912 KB Ok
60 Correct 55 ms 8648 KB Ok
61 Correct 61 ms 8912 KB Ok
62 Correct 74 ms 9196 KB Ok
63 Correct 61 ms 8876 KB Ok
64 Correct 73 ms 9640 KB Ok
65 Correct 67 ms 9148 KB Ok
66 Correct 64 ms 9036 KB Ok
67 Correct 59 ms 8804 KB Ok
68 Correct 64 ms 9164 KB Ok
69 Correct 142 ms 15824 KB Ok
70 Correct 145 ms 16584 KB Ok
71 Correct 140 ms 16076 KB Ok
72 Correct 141 ms 15820 KB Ok
73 Correct 148 ms 16080 KB Ok
74 Correct 139 ms 15820 KB Ok
75 Correct 148 ms 15308 KB Ok
76 Correct 145 ms 16172 KB Ok
77 Correct 138 ms 15568 KB Ok
78 Correct 141 ms 15824 KB Ok
79 Correct 140 ms 16072 KB Ok
80 Correct 137 ms 16084 KB Ok
81 Correct 144 ms 16076 KB Ok
82 Correct 142 ms 16180 KB Ok
83 Correct 137 ms 15568 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Ok
2 Correct 2 ms 4752 KB Ok
3 Correct 2 ms 4752 KB Ok
4 Correct 2 ms 4700 KB Ok
5 Correct 2 ms 4700 KB Ok
6 Correct 2 ms 4700 KB Ok
7 Correct 2 ms 4700 KB Ok
8 Correct 2 ms 4700 KB Ok
9 Correct 2 ms 4700 KB Ok
10 Correct 2 ms 4700 KB Ok
11 Correct 2 ms 4700 KB Ok
12 Correct 2 ms 4700 KB Ok
13 Correct 1 ms 4700 KB Ok
14 Correct 2 ms 4696 KB Ok
15 Correct 2 ms 4744 KB Ok
16 Correct 2 ms 4748 KB Ok
17 Correct 2 ms 4700 KB Ok
18 Correct 4 ms 4700 KB Ok
19 Correct 14 ms 5468 KB Ok
20 Correct 7 ms 4956 KB Ok
21 Correct 13 ms 5724 KB Ok
22 Correct 10 ms 5212 KB Ok
23 Correct 1 ms 4700 KB Ok
24 Correct 1 ms 4700 KB Ok
25 Correct 1 ms 4700 KB Ok
26 Correct 1 ms 4700 KB Ok
27 Correct 1 ms 4564 KB Ok
28 Correct 1 ms 4700 KB Ok
29 Correct 1 ms 4700 KB Ok
30 Correct 1 ms 4700 KB Ok
31 Correct 1 ms 4700 KB Ok
32 Correct 1 ms 4700 KB Ok
33 Correct 1 ms 4700 KB Ok
34 Correct 2 ms 4696 KB Ok
35 Correct 2 ms 4700 KB Ok
36 Correct 2 ms 4700 KB Ok
37 Correct 2 ms 4700 KB Ok
38 Correct 2 ms 4700 KB Ok
39 Correct 82 ms 15144 KB Ok
40 Correct 73 ms 17100 KB Ok
41 Correct 152 ms 20164 KB Ok
42 Correct 106 ms 16604 KB Ok
43 Correct 63 ms 11472 KB Ok
44 Correct 103 ms 18632 KB Ok
45 Correct 4 ms 4696 KB Ok
46 Correct 4 ms 4700 KB Ok
47 Correct 4 ms 4824 KB Ok
48 Correct 4 ms 4700 KB Ok
49 Correct 4 ms 4700 KB Ok
50 Correct 4 ms 4700 KB Ok
51 Correct 4 ms 4700 KB Ok
52 Correct 4 ms 4700 KB Ok
53 Correct 4 ms 4700 KB Ok
54 Correct 4 ms 4700 KB Ok
55 Correct 6 ms 4956 KB Ok
56 Correct 7 ms 4956 KB Ok
57 Correct 7 ms 4956 KB Ok
58 Correct 6 ms 4956 KB Ok
59 Correct 7 ms 4952 KB Ok
60 Correct 6 ms 4852 KB Ok
61 Correct 7 ms 4956 KB Ok
62 Correct 7 ms 4956 KB Ok
63 Correct 6 ms 4956 KB Ok
64 Correct 7 ms 4956 KB Ok
65 Correct 70 ms 9168 KB Ok
66 Correct 74 ms 9420 KB Ok
67 Correct 74 ms 9512 KB Ok
68 Correct 58 ms 8924 KB Ok
69 Correct 65 ms 8928 KB Ok
70 Correct 63 ms 8912 KB Ok
71 Correct 55 ms 8648 KB Ok
72 Correct 61 ms 8912 KB Ok
73 Correct 74 ms 9196 KB Ok
74 Correct 61 ms 8876 KB Ok
75 Correct 73 ms 9640 KB Ok
76 Correct 67 ms 9148 KB Ok
77 Correct 64 ms 9036 KB Ok
78 Correct 59 ms 8804 KB Ok
79 Correct 64 ms 9164 KB Ok
80 Correct 142 ms 15824 KB Ok
81 Correct 145 ms 16584 KB Ok
82 Correct 140 ms 16076 KB Ok
83 Correct 141 ms 15820 KB Ok
84 Correct 148 ms 16080 KB Ok
85 Correct 139 ms 15820 KB Ok
86 Correct 148 ms 15308 KB Ok
87 Correct 145 ms 16172 KB Ok
88 Correct 138 ms 15568 KB Ok
89 Correct 141 ms 15824 KB Ok
90 Correct 140 ms 16072 KB Ok
91 Correct 137 ms 16084 KB Ok
92 Correct 144 ms 16076 KB Ok
93 Correct 142 ms 16180 KB Ok
94 Correct 137 ms 15568 KB Ok
95 Correct 177 ms 14988 KB Ok
96 Correct 230 ms 19392 KB Ok
97 Correct 230 ms 17600 KB Ok
98 Correct 177 ms 18620 KB Ok
99 Correct 219 ms 15808 KB Ok
100 Correct 227 ms 15956 KB Ok
101 Correct 213 ms 19392 KB Ok
102 Correct 214 ms 17008 KB Ok
103 Correct 208 ms 19136 KB Ok
104 Correct 258 ms 19652 KB Ok
105 Correct 232 ms 20416 KB Ok
106 Correct 200 ms 19512 KB Ok
107 Correct 231 ms 19776 KB Ok
108 Correct 257 ms 19904 KB Ok
109 Correct 229 ms 19908 KB Ok
110 Correct 656 ms 48576 KB Ok
111 Correct 684 ms 51240 KB Ok
112 Correct 648 ms 51444 KB Ok
113 Correct 660 ms 50624 KB Ok
114 Correct 632 ms 52672 KB Ok
115 Correct 670 ms 50624 KB Ok
116 Correct 647 ms 51604 KB Ok
117 Correct 680 ms 50112 KB Ok
118 Correct 654 ms 50000 KB Ok
119 Correct 694 ms 50556 KB Ok
120 Correct 644 ms 49704 KB Ok
121 Correct 671 ms 49088 KB Ok
122 Correct 675 ms 50988 KB Ok
123 Correct 685 ms 51236 KB Ok
124 Correct 657 ms 49088 KB Ok
125 Correct 469 ms 33548 KB Ok