Submission #378914

# Submission time Handle Problem Language Result Execution time Memory
378914 2021-03-17T07:28:33 Z balbit Nice sequence (IZhO18_sequence) C++14
100 / 100
970 ms 44596 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT


#define REP(i,n) for (int i = 0; i<n; ++i)
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

int a,b,L;
const int maxn = 4e5+5;
int seen[maxn];

bool dfs(int v, int c) {
    seen[v] = c;
    if (v-a>=0) {
        if (seen[v-a]) {
            if (seen[v-a] == c) return 0;
        }else{
            if (!dfs(v-a,c)) return 0;
        }
    }
    if (v+b<=L) {
        if (seen[v+b]) {
            if (seen[v+b] == c) return 0;
        }else{
            if (!dfs(v+b,c)) return 0;
        }
    }
    return 1;
}
vector<int> po;
bool dfs2(int v, int c) {
    seen[v] = c;
//    bug("try",v);
    if (v-a>=0) {
        if (seen[v-a]) {
            if (seen[v-a] == c) return 0;
        }else{
            if (!dfs2(v-a,c)) return 0;
        }
    }
    if (v+b<=L) {
        if (seen[v+b]) {
            if (seen[v+b] == c) return 0;
        }else{
            if (!dfs2(v+b,c)) return 0;
        }
    }
//    bug("wtf",v);
    po.pb(v);
    return 1;
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);

    bug(1,2);
    int t; cin>>t;
    while (t--) {
        cin>>a>>b;
        int l = max(a,b)-1, r = a+b+1;
        while (l!=r) {
            int mid = (l+r)/2;
            L = mid;
            memset(seen, 0, sizeof seen);
            bool ok = 1;
            REP(i,L+1) {
                if (!seen[i]) {
                    if (!dfs(i, i+1)) {
                        ok = 0;
//                        bug(i);
                        break;
                    }
                }
            }
            if (ok ) {
                l = mid+1;
            }else{
                r=mid;
            }
            bug(mid, ok);
        }
        --l;
        L = l;
        cout<<l<<endl;
        memset(seen, 0,sizeof seen);
        po.clear();
        REP(i,l+1) {
            if (!seen[i]) {
                assert(dfs2(i,i+1));
            }
        }
//        bug(SZ(po));
        vector<int> re(l+1);
        REP(i, SZ(po)) {
            re[po[i]] = i;
        }
        REP(i, SZ(po)) {
            if (i) {
                cout<<re[i-1]-re[i]<<' ';
            }
        }
        cout<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1900 KB Ok
2 Correct 4 ms 1900 KB Ok
3 Correct 5 ms 1900 KB Ok
4 Correct 6 ms 1900 KB Ok
5 Correct 6 ms 1900 KB Ok
6 Correct 6 ms 1936 KB Ok
7 Correct 6 ms 1900 KB Ok
8 Correct 6 ms 1900 KB Ok
9 Correct 6 ms 1900 KB Ok
10 Correct 5 ms 1900 KB Ok
11 Correct 5 ms 1900 KB Ok
12 Correct 6 ms 1900 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1900 KB Ok
2 Correct 4 ms 1900 KB Ok
3 Correct 3 ms 2028 KB Ok
4 Correct 4 ms 2028 KB Ok
5 Correct 3 ms 1900 KB Ok
6 Correct 13 ms 2028 KB Ok
7 Correct 14 ms 2668 KB Ok
8 Correct 9 ms 2284 KB Ok
9 Correct 15 ms 2796 KB Ok
10 Correct 10 ms 2412 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1900 KB Ok
2 Correct 3 ms 1900 KB Ok
3 Correct 3 ms 1900 KB Ok
4 Correct 5 ms 1900 KB Ok
5 Correct 4 ms 1900 KB Ok
6 Correct 3 ms 1900 KB Ok
7 Correct 4 ms 1900 KB Ok
8 Correct 5 ms 1900 KB Ok
9 Correct 4 ms 2028 KB Ok
10 Correct 4 ms 1900 KB Ok
11 Correct 4 ms 1900 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1900 KB Ok
2 Correct 5 ms 1900 KB Ok
3 Correct 4 ms 2028 KB Ok
4 Correct 5 ms 1900 KB Ok
5 Correct 5 ms 1900 KB Ok
6 Correct 199 ms 11432 KB Ok
7 Correct 134 ms 9924 KB Ok
8 Correct 250 ms 13232 KB Ok
9 Correct 208 ms 12008 KB Ok
10 Correct 132 ms 8444 KB Ok
11 Correct 254 ms 14460 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1900 KB Ok
2 Correct 4 ms 1900 KB Ok
3 Correct 5 ms 1900 KB Ok
4 Correct 6 ms 1900 KB Ok
5 Correct 6 ms 1900 KB Ok
6 Correct 6 ms 1936 KB Ok
7 Correct 6 ms 1900 KB Ok
8 Correct 6 ms 1900 KB Ok
9 Correct 6 ms 1900 KB Ok
10 Correct 5 ms 1900 KB Ok
11 Correct 5 ms 1900 KB Ok
12 Correct 6 ms 1900 KB Ok
13 Correct 2 ms 1900 KB Ok
14 Correct 3 ms 1900 KB Ok
15 Correct 3 ms 1900 KB Ok
16 Correct 5 ms 1900 KB Ok
17 Correct 4 ms 1900 KB Ok
18 Correct 3 ms 1900 KB Ok
19 Correct 4 ms 1900 KB Ok
20 Correct 5 ms 1900 KB Ok
21 Correct 4 ms 2028 KB Ok
22 Correct 4 ms 1900 KB Ok
23 Correct 4 ms 1900 KB Ok
24 Correct 9 ms 2028 KB Ok
25 Correct 9 ms 2028 KB Ok
26 Correct 9 ms 2028 KB Ok
27 Correct 9 ms 2028 KB Ok
28 Correct 9 ms 2028 KB Ok
29 Correct 9 ms 2028 KB Ok
30 Correct 8 ms 2028 KB Ok
31 Correct 10 ms 2028 KB Ok
32 Correct 10 ms 2028 KB Ok
33 Correct 9 ms 2028 KB Ok
34 Correct 14 ms 2156 KB Ok
35 Correct 13 ms 2156 KB Ok
36 Correct 13 ms 2284 KB Ok
37 Correct 13 ms 2284 KB Ok
38 Correct 13 ms 2156 KB Ok
39 Correct 14 ms 2156 KB Ok
40 Correct 14 ms 2156 KB Ok
41 Correct 13 ms 2156 KB Ok
42 Correct 13 ms 2156 KB Ok
43 Correct 13 ms 2156 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1900 KB Ok
2 Correct 4 ms 1900 KB Ok
3 Correct 5 ms 1900 KB Ok
4 Correct 6 ms 1900 KB Ok
5 Correct 6 ms 1900 KB Ok
6 Correct 6 ms 1936 KB Ok
7 Correct 6 ms 1900 KB Ok
8 Correct 6 ms 1900 KB Ok
9 Correct 6 ms 1900 KB Ok
10 Correct 5 ms 1900 KB Ok
11 Correct 5 ms 1900 KB Ok
12 Correct 6 ms 1900 KB Ok
13 Correct 3 ms 1900 KB Ok
14 Correct 4 ms 1900 KB Ok
15 Correct 3 ms 2028 KB Ok
16 Correct 4 ms 2028 KB Ok
17 Correct 3 ms 1900 KB Ok
18 Correct 13 ms 2028 KB Ok
19 Correct 14 ms 2668 KB Ok
20 Correct 9 ms 2284 KB Ok
21 Correct 15 ms 2796 KB Ok
22 Correct 10 ms 2412 KB Ok
23 Correct 2 ms 1900 KB Ok
24 Correct 3 ms 1900 KB Ok
25 Correct 3 ms 1900 KB Ok
26 Correct 5 ms 1900 KB Ok
27 Correct 4 ms 1900 KB Ok
28 Correct 3 ms 1900 KB Ok
29 Correct 4 ms 1900 KB Ok
30 Correct 5 ms 1900 KB Ok
31 Correct 4 ms 2028 KB Ok
32 Correct 4 ms 1900 KB Ok
33 Correct 4 ms 1900 KB Ok
34 Correct 9 ms 2028 KB Ok
35 Correct 9 ms 2028 KB Ok
36 Correct 9 ms 2028 KB Ok
37 Correct 9 ms 2028 KB Ok
38 Correct 9 ms 2028 KB Ok
39 Correct 9 ms 2028 KB Ok
40 Correct 8 ms 2028 KB Ok
41 Correct 10 ms 2028 KB Ok
42 Correct 10 ms 2028 KB Ok
43 Correct 9 ms 2028 KB Ok
44 Correct 14 ms 2156 KB Ok
45 Correct 13 ms 2156 KB Ok
46 Correct 13 ms 2284 KB Ok
47 Correct 13 ms 2284 KB Ok
48 Correct 13 ms 2156 KB Ok
49 Correct 14 ms 2156 KB Ok
50 Correct 14 ms 2156 KB Ok
51 Correct 13 ms 2156 KB Ok
52 Correct 13 ms 2156 KB Ok
53 Correct 13 ms 2156 KB Ok
54 Correct 100 ms 4776 KB Ok
55 Correct 114 ms 5296 KB Ok
56 Correct 116 ms 5220 KB Ok
57 Correct 89 ms 4392 KB Ok
58 Correct 108 ms 5012 KB Ok
59 Correct 125 ms 4936 KB Ok
60 Correct 89 ms 4672 KB Ok
61 Correct 102 ms 4548 KB Ok
62 Correct 129 ms 5448 KB Ok
63 Correct 96 ms 4728 KB Ok
64 Correct 122 ms 5148 KB Ok
65 Correct 127 ms 5064 KB Ok
66 Correct 95 ms 4756 KB Ok
67 Correct 88 ms 4484 KB Ok
68 Correct 104 ms 5108 KB Ok
69 Correct 207 ms 11876 KB Ok
70 Correct 214 ms 11876 KB Ok
71 Correct 215 ms 10512 KB Ok
72 Correct 209 ms 11748 KB Ok
73 Correct 209 ms 10596 KB Ok
74 Correct 235 ms 11236 KB Ok
75 Correct 203 ms 11768 KB Ok
76 Correct 208 ms 11876 KB Ok
77 Correct 205 ms 11092 KB Ok
78 Correct 216 ms 11880 KB Ok
79 Correct 209 ms 11364 KB Ok
80 Correct 202 ms 10596 KB Ok
81 Correct 206 ms 12200 KB Ok
82 Correct 207 ms 11236 KB Ok
83 Correct 211 ms 11876 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1900 KB Ok
2 Correct 4 ms 1900 KB Ok
3 Correct 5 ms 1900 KB Ok
4 Correct 6 ms 1900 KB Ok
5 Correct 6 ms 1900 KB Ok
6 Correct 6 ms 1936 KB Ok
7 Correct 6 ms 1900 KB Ok
8 Correct 6 ms 1900 KB Ok
9 Correct 6 ms 1900 KB Ok
10 Correct 5 ms 1900 KB Ok
11 Correct 5 ms 1900 KB Ok
12 Correct 6 ms 1900 KB Ok
13 Correct 3 ms 1900 KB Ok
14 Correct 4 ms 1900 KB Ok
15 Correct 3 ms 2028 KB Ok
16 Correct 4 ms 2028 KB Ok
17 Correct 3 ms 1900 KB Ok
18 Correct 13 ms 2028 KB Ok
19 Correct 14 ms 2668 KB Ok
20 Correct 9 ms 2284 KB Ok
21 Correct 15 ms 2796 KB Ok
22 Correct 10 ms 2412 KB Ok
23 Correct 2 ms 1900 KB Ok
24 Correct 3 ms 1900 KB Ok
25 Correct 3 ms 1900 KB Ok
26 Correct 5 ms 1900 KB Ok
27 Correct 4 ms 1900 KB Ok
28 Correct 3 ms 1900 KB Ok
29 Correct 4 ms 1900 KB Ok
30 Correct 5 ms 1900 KB Ok
31 Correct 4 ms 2028 KB Ok
32 Correct 4 ms 1900 KB Ok
33 Correct 4 ms 1900 KB Ok
34 Correct 4 ms 1900 KB Ok
35 Correct 5 ms 1900 KB Ok
36 Correct 4 ms 2028 KB Ok
37 Correct 5 ms 1900 KB Ok
38 Correct 5 ms 1900 KB Ok
39 Correct 199 ms 11432 KB Ok
40 Correct 134 ms 9924 KB Ok
41 Correct 250 ms 13232 KB Ok
42 Correct 208 ms 12008 KB Ok
43 Correct 132 ms 8444 KB Ok
44 Correct 254 ms 14460 KB Ok
45 Correct 9 ms 2028 KB Ok
46 Correct 9 ms 2028 KB Ok
47 Correct 9 ms 2028 KB Ok
48 Correct 9 ms 2028 KB Ok
49 Correct 9 ms 2028 KB Ok
50 Correct 9 ms 2028 KB Ok
51 Correct 8 ms 2028 KB Ok
52 Correct 10 ms 2028 KB Ok
53 Correct 10 ms 2028 KB Ok
54 Correct 9 ms 2028 KB Ok
55 Correct 14 ms 2156 KB Ok
56 Correct 13 ms 2156 KB Ok
57 Correct 13 ms 2284 KB Ok
58 Correct 13 ms 2284 KB Ok
59 Correct 13 ms 2156 KB Ok
60 Correct 14 ms 2156 KB Ok
61 Correct 14 ms 2156 KB Ok
62 Correct 13 ms 2156 KB Ok
63 Correct 13 ms 2156 KB Ok
64 Correct 13 ms 2156 KB Ok
65 Correct 100 ms 4776 KB Ok
66 Correct 114 ms 5296 KB Ok
67 Correct 116 ms 5220 KB Ok
68 Correct 89 ms 4392 KB Ok
69 Correct 108 ms 5012 KB Ok
70 Correct 125 ms 4936 KB Ok
71 Correct 89 ms 4672 KB Ok
72 Correct 102 ms 4548 KB Ok
73 Correct 129 ms 5448 KB Ok
74 Correct 96 ms 4728 KB Ok
75 Correct 122 ms 5148 KB Ok
76 Correct 127 ms 5064 KB Ok
77 Correct 95 ms 4756 KB Ok
78 Correct 88 ms 4484 KB Ok
79 Correct 104 ms 5108 KB Ok
80 Correct 207 ms 11876 KB Ok
81 Correct 214 ms 11876 KB Ok
82 Correct 215 ms 10512 KB Ok
83 Correct 209 ms 11748 KB Ok
84 Correct 209 ms 10596 KB Ok
85 Correct 235 ms 11236 KB Ok
86 Correct 203 ms 11768 KB Ok
87 Correct 208 ms 11876 KB Ok
88 Correct 205 ms 11092 KB Ok
89 Correct 216 ms 11880 KB Ok
90 Correct 209 ms 11364 KB Ok
91 Correct 202 ms 10596 KB Ok
92 Correct 206 ms 12200 KB Ok
93 Correct 207 ms 11236 KB Ok
94 Correct 211 ms 11876 KB Ok
95 Correct 233 ms 9384 KB Ok
96 Correct 341 ms 13796 KB Ok
97 Correct 366 ms 11876 KB Ok
98 Correct 273 ms 9864 KB Ok
99 Correct 276 ms 10692 KB Ok
100 Correct 344 ms 11904 KB Ok
101 Correct 316 ms 11360 KB Ok
102 Correct 308 ms 11532 KB Ok
103 Correct 316 ms 11920 KB Ok
104 Correct 356 ms 12860 KB Ok
105 Correct 372 ms 13024 KB Ok
106 Correct 274 ms 11264 KB Ok
107 Correct 344 ms 12328 KB Ok
108 Correct 393 ms 13316 KB Ok
109 Correct 334 ms 12328 KB Ok
110 Correct 862 ms 43512 KB Ok
111 Correct 942 ms 44596 KB Ok
112 Correct 898 ms 40316 KB Ok
113 Correct 916 ms 43640 KB Ok
114 Correct 899 ms 40024 KB Ok
115 Correct 893 ms 44592 KB Ok
116 Correct 945 ms 43988 KB Ok
117 Correct 893 ms 44372 KB Ok
118 Correct 970 ms 39872 KB Ok
119 Correct 919 ms 43692 KB Ok
120 Correct 930 ms 44328 KB Ok
121 Correct 886 ms 42048 KB Ok
122 Correct 912 ms 44332 KB Ok
123 Correct 968 ms 42468 KB Ok
124 Correct 869 ms 40016 KB Ok
125 Correct 846 ms 27888 KB Ok