Submission #389775

# Submission time Handle Problem Language Result Execution time Memory
389775 2021-04-14T14:05:52 Z BartolM Nice sequence (IZhO18_sequence) C++17
100 / 100
1557 ms 54748 KB
#define DEBUG 1
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=4e5+5;

int n, m;
vector <int> ls[N]; //(i->j) i veci od j
int in[N], bio[N], sol[N];
queue <int> Q;

void reset(int x) {
    for (int i=0; i<=x; ++i) ls[i].clear(), in[i]=0, bio[i]=0;
}

void build(int x) {
    for (int i=1; i<=x; ++i) {
        if (i-n>=0) ls[i-n].pb(i), in[i]++;
        if (i-m>=0) ls[i].pb(i-m), in[i-m]++;
    }
}

int dfs(int node) {
    if (bio[node]==2) return 0;
    if (bio[node]==1) return 1;
    bio[node]=1;
    int ret=0;
    for (int sus:ls[node]) ret|=dfs(sus);
    bio[node]=2;
    return ret;
}

void topo_sort(int gr) {
    for (int i=0; i<=gr; ++i) if (!in[i]) Q.push(i);
    int curr=gr+1;
    while (!Q.empty()) {
        int node=Q.front();
        Q.pop();
        sol[node]=curr--;
        for (int sus:ls[node]) {
            in[sus]--;
            if (!in[sus]) Q.push(sus);
        }
    }
}

void solve() {
//    int lo=0, hi=2*max(n, m), mid;
//    while (lo<hi) {
//        mid=(lo+hi+1)/2;
//        build(mid);
//        int fl=0;
//        for (int i=0; i<=mid && !fl; ++i) fl+=dfs(i);
//        if (fl) hi=mid-1;
//        else lo=mid;
//        reset(mid);
//    }
    int lo=n+m-__gcd(n, m)-1;
    build(lo);
    topo_sort(lo);
    printf("%d\n", lo);
    for (int i=1; i<=lo; ++i) printf("%d ", sol[i]-sol[i-1]);
    printf("\n");
    reset(lo);
}

void load() {
    scanf("%d %d", &n, &m);
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        load();
        solve();
    }
    return 0;
}

Compilation message

sequence.cpp: In function 'void load()':
sequence.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   80 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   85 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 7 ms 9676 KB Ok
4 Correct 7 ms 9712 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 6 ms 9676 KB Ok
7 Correct 6 ms 9676 KB Ok
8 Correct 7 ms 9676 KB Ok
9 Correct 6 ms 9608 KB Ok
10 Correct 6 ms 9676 KB Ok
11 Correct 6 ms 9676 KB Ok
12 Correct 6 ms 9676 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9640 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 7 ms 9676 KB Ok
4 Correct 7 ms 9676 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 9 ms 9824 KB Ok
7 Correct 18 ms 10372 KB Ok
8 Correct 12 ms 9932 KB Ok
9 Correct 21 ms 10548 KB Ok
10 Correct 15 ms 10188 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 7 ms 9804 KB Ok
4 Correct 6 ms 9644 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 7 ms 9604 KB Ok
7 Correct 6 ms 9716 KB Ok
8 Correct 6 ms 9676 KB Ok
9 Correct 6 ms 9712 KB Ok
10 Correct 7 ms 9676 KB Ok
11 Correct 6 ms 9676 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 7 ms 9676 KB Ok
3 Correct 6 ms 9680 KB Ok
4 Correct 7 ms 9600 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 127 ms 19872 KB Ok
7 Correct 112 ms 20172 KB Ok
8 Correct 208 ms 22424 KB Ok
9 Correct 161 ms 21624 KB Ok
10 Correct 109 ms 16452 KB Ok
11 Correct 152 ms 21772 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 7 ms 9676 KB Ok
4 Correct 7 ms 9712 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 6 ms 9676 KB Ok
7 Correct 6 ms 9676 KB Ok
8 Correct 7 ms 9676 KB Ok
9 Correct 6 ms 9608 KB Ok
10 Correct 6 ms 9676 KB Ok
11 Correct 6 ms 9676 KB Ok
12 Correct 6 ms 9676 KB Ok
13 Correct 6 ms 9676 KB Ok
14 Correct 6 ms 9676 KB Ok
15 Correct 7 ms 9804 KB Ok
16 Correct 6 ms 9644 KB Ok
17 Correct 6 ms 9676 KB Ok
18 Correct 7 ms 9604 KB Ok
19 Correct 6 ms 9716 KB Ok
20 Correct 6 ms 9676 KB Ok
21 Correct 6 ms 9712 KB Ok
22 Correct 7 ms 9676 KB Ok
23 Correct 6 ms 9676 KB Ok
24 Correct 9 ms 9804 KB Ok
25 Correct 11 ms 9804 KB Ok
26 Correct 9 ms 9804 KB Ok
27 Correct 9 ms 9840 KB Ok
28 Correct 8 ms 9804 KB Ok
29 Correct 8 ms 9804 KB Ok
30 Correct 9 ms 9804 KB Ok
31 Correct 9 ms 9904 KB Ok
32 Correct 9 ms 9876 KB Ok
33 Correct 9 ms 9804 KB Ok
34 Correct 11 ms 9932 KB Ok
35 Correct 11 ms 9932 KB Ok
36 Correct 11 ms 9932 KB Ok
37 Correct 11 ms 9932 KB Ok
38 Correct 11 ms 10032 KB Ok
39 Correct 14 ms 9976 KB Ok
40 Correct 12 ms 9932 KB Ok
41 Correct 12 ms 9932 KB Ok
42 Correct 12 ms 9984 KB Ok
43 Correct 11 ms 10020 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 7 ms 9676 KB Ok
4 Correct 7 ms 9712 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 6 ms 9676 KB Ok
7 Correct 6 ms 9676 KB Ok
8 Correct 7 ms 9676 KB Ok
9 Correct 6 ms 9608 KB Ok
10 Correct 6 ms 9676 KB Ok
11 Correct 6 ms 9676 KB Ok
12 Correct 6 ms 9676 KB Ok
13 Correct 6 ms 9640 KB Ok
14 Correct 6 ms 9676 KB Ok
15 Correct 7 ms 9676 KB Ok
16 Correct 7 ms 9676 KB Ok
17 Correct 6 ms 9676 KB Ok
18 Correct 9 ms 9824 KB Ok
19 Correct 18 ms 10372 KB Ok
20 Correct 12 ms 9932 KB Ok
21 Correct 21 ms 10548 KB Ok
22 Correct 15 ms 10188 KB Ok
23 Correct 6 ms 9676 KB Ok
24 Correct 6 ms 9676 KB Ok
25 Correct 7 ms 9804 KB Ok
26 Correct 6 ms 9644 KB Ok
27 Correct 6 ms 9676 KB Ok
28 Correct 7 ms 9604 KB Ok
29 Correct 6 ms 9716 KB Ok
30 Correct 6 ms 9676 KB Ok
31 Correct 6 ms 9712 KB Ok
32 Correct 7 ms 9676 KB Ok
33 Correct 6 ms 9676 KB Ok
34 Correct 9 ms 9804 KB Ok
35 Correct 11 ms 9804 KB Ok
36 Correct 9 ms 9804 KB Ok
37 Correct 9 ms 9840 KB Ok
38 Correct 8 ms 9804 KB Ok
39 Correct 8 ms 9804 KB Ok
40 Correct 9 ms 9804 KB Ok
41 Correct 9 ms 9904 KB Ok
42 Correct 9 ms 9876 KB Ok
43 Correct 9 ms 9804 KB Ok
44 Correct 11 ms 9932 KB Ok
45 Correct 11 ms 9932 KB Ok
46 Correct 11 ms 9932 KB Ok
47 Correct 11 ms 9932 KB Ok
48 Correct 11 ms 10032 KB Ok
49 Correct 14 ms 9976 KB Ok
50 Correct 12 ms 9932 KB Ok
51 Correct 12 ms 9932 KB Ok
52 Correct 12 ms 9984 KB Ok
53 Correct 11 ms 10020 KB Ok
54 Correct 98 ms 15852 KB Ok
55 Correct 112 ms 15984 KB Ok
56 Correct 110 ms 16148 KB Ok
57 Correct 86 ms 15164 KB Ok
58 Correct 101 ms 15812 KB Ok
59 Correct 105 ms 15528 KB Ok
60 Correct 90 ms 15044 KB Ok
61 Correct 87 ms 15452 KB Ok
62 Correct 113 ms 15940 KB Ok
63 Correct 91 ms 15324 KB Ok
64 Correct 109 ms 15872 KB Ok
65 Correct 106 ms 15852 KB Ok
66 Correct 97 ms 15556 KB Ok
67 Correct 90 ms 15284 KB Ok
68 Correct 97 ms 15812 KB Ok
69 Correct 206 ms 19400 KB Ok
70 Correct 223 ms 20496 KB Ok
71 Correct 208 ms 19012 KB Ok
72 Correct 210 ms 19652 KB Ok
73 Correct 198 ms 19396 KB Ok
74 Correct 187 ms 18500 KB Ok
75 Correct 185 ms 18500 KB Ok
76 Correct 227 ms 20216 KB Ok
77 Correct 186 ms 18244 KB Ok
78 Correct 205 ms 19900 KB Ok
79 Correct 208 ms 19652 KB Ok
80 Correct 201 ms 19396 KB Ok
81 Correct 220 ms 20004 KB Ok
82 Correct 236 ms 19524 KB Ok
83 Correct 190 ms 18584 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 7 ms 9676 KB Ok
4 Correct 7 ms 9712 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 6 ms 9676 KB Ok
7 Correct 6 ms 9676 KB Ok
8 Correct 7 ms 9676 KB Ok
9 Correct 6 ms 9608 KB Ok
10 Correct 6 ms 9676 KB Ok
11 Correct 6 ms 9676 KB Ok
12 Correct 6 ms 9676 KB Ok
13 Correct 6 ms 9640 KB Ok
14 Correct 6 ms 9676 KB Ok
15 Correct 7 ms 9676 KB Ok
16 Correct 7 ms 9676 KB Ok
17 Correct 6 ms 9676 KB Ok
18 Correct 9 ms 9824 KB Ok
19 Correct 18 ms 10372 KB Ok
20 Correct 12 ms 9932 KB Ok
21 Correct 21 ms 10548 KB Ok
22 Correct 15 ms 10188 KB Ok
23 Correct 6 ms 9676 KB Ok
24 Correct 6 ms 9676 KB Ok
25 Correct 7 ms 9804 KB Ok
26 Correct 6 ms 9644 KB Ok
27 Correct 6 ms 9676 KB Ok
28 Correct 7 ms 9604 KB Ok
29 Correct 6 ms 9716 KB Ok
30 Correct 6 ms 9676 KB Ok
31 Correct 6 ms 9712 KB Ok
32 Correct 7 ms 9676 KB Ok
33 Correct 6 ms 9676 KB Ok
34 Correct 6 ms 9676 KB Ok
35 Correct 7 ms 9676 KB Ok
36 Correct 6 ms 9680 KB Ok
37 Correct 7 ms 9600 KB Ok
38 Correct 6 ms 9676 KB Ok
39 Correct 127 ms 19872 KB Ok
40 Correct 112 ms 20172 KB Ok
41 Correct 208 ms 22424 KB Ok
42 Correct 161 ms 21624 KB Ok
43 Correct 109 ms 16452 KB Ok
44 Correct 152 ms 21772 KB Ok
45 Correct 9 ms 9804 KB Ok
46 Correct 11 ms 9804 KB Ok
47 Correct 9 ms 9804 KB Ok
48 Correct 9 ms 9840 KB Ok
49 Correct 8 ms 9804 KB Ok
50 Correct 8 ms 9804 KB Ok
51 Correct 9 ms 9804 KB Ok
52 Correct 9 ms 9904 KB Ok
53 Correct 9 ms 9876 KB Ok
54 Correct 9 ms 9804 KB Ok
55 Correct 11 ms 9932 KB Ok
56 Correct 11 ms 9932 KB Ok
57 Correct 11 ms 9932 KB Ok
58 Correct 11 ms 9932 KB Ok
59 Correct 11 ms 10032 KB Ok
60 Correct 14 ms 9976 KB Ok
61 Correct 12 ms 9932 KB Ok
62 Correct 12 ms 9932 KB Ok
63 Correct 12 ms 9984 KB Ok
64 Correct 11 ms 10020 KB Ok
65 Correct 98 ms 15852 KB Ok
66 Correct 112 ms 15984 KB Ok
67 Correct 110 ms 16148 KB Ok
68 Correct 86 ms 15164 KB Ok
69 Correct 101 ms 15812 KB Ok
70 Correct 105 ms 15528 KB Ok
71 Correct 90 ms 15044 KB Ok
72 Correct 87 ms 15452 KB Ok
73 Correct 113 ms 15940 KB Ok
74 Correct 91 ms 15324 KB Ok
75 Correct 109 ms 15872 KB Ok
76 Correct 106 ms 15852 KB Ok
77 Correct 97 ms 15556 KB Ok
78 Correct 90 ms 15284 KB Ok
79 Correct 97 ms 15812 KB Ok
80 Correct 206 ms 19400 KB Ok
81 Correct 223 ms 20496 KB Ok
82 Correct 208 ms 19012 KB Ok
83 Correct 210 ms 19652 KB Ok
84 Correct 198 ms 19396 KB Ok
85 Correct 187 ms 18500 KB Ok
86 Correct 185 ms 18500 KB Ok
87 Correct 227 ms 20216 KB Ok
88 Correct 186 ms 18244 KB Ok
89 Correct 205 ms 19900 KB Ok
90 Correct 208 ms 19652 KB Ok
91 Correct 201 ms 19396 KB Ok
92 Correct 220 ms 20004 KB Ok
93 Correct 236 ms 19524 KB Ok
94 Correct 190 ms 18584 KB Ok
95 Correct 236 ms 25584 KB Ok
96 Correct 386 ms 33064 KB Ok
97 Correct 335 ms 29220 KB Ok
98 Correct 264 ms 29224 KB Ok
99 Correct 309 ms 28548 KB Ok
100 Correct 308 ms 28100 KB Ok
101 Correct 319 ms 31332 KB Ok
102 Correct 303 ms 29176 KB Ok
103 Correct 301 ms 29872 KB Ok
104 Correct 351 ms 32208 KB Ok
105 Correct 335 ms 32056 KB Ok
106 Correct 281 ms 31968 KB Ok
107 Correct 328 ms 31328 KB Ok
108 Correct 384 ms 32096 KB Ok
109 Correct 357 ms 33212 KB Ok
110 Correct 964 ms 46876 KB Ok
111 Correct 1314 ms 54748 KB Ok
112 Correct 1055 ms 48728 KB Ok
113 Correct 1172 ms 51596 KB Ok
114 Correct 1209 ms 53076 KB Ok
115 Correct 1264 ms 52196 KB Ok
116 Correct 1234 ms 52292 KB Ok
117 Correct 1249 ms 52792 KB Ok
118 Correct 1161 ms 49432 KB Ok
119 Correct 1329 ms 53412 KB Ok
120 Correct 1120 ms 49352 KB Ok
121 Correct 1144 ms 48368 KB Ok
122 Correct 1147 ms 50900 KB Ok
123 Correct 1557 ms 54596 KB Ok
124 Correct 928 ms 46000 KB Ok
125 Correct 566 ms 36944 KB Ok