Submission #369942

# Submission time Handle Problem Language Result Execution time Memory
369942 2021-02-22T19:21:50 Z nicolaalexandra Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 82012 KB
#include <bits/stdc++.h>
#define DIM 2000010
using namespace std;

vector <int> L[DIM];
int v[DIM],g[DIM];
int n,m,k,t,i,j,idx,ok;

void dfs (int nod){
    v[nod] = ++idx;
    for (auto vecin : L[nod]){
        if (v[vecin])
            ok = 0;
        else dfs (vecin);
    }
}

int verif (int k){
    int i;

    for (i=0;i<=k;i++){
        L[i].clear();
        v[i] = g[i] = 0;
    }

    for (i=n;i<=k;i++){
        L[i].push_back(i-n);
        g[i-n]++;
    }

    for (i=m;i<=k;i++){
        L[i-m].push_back(i);
        g[i]++;
    }

    idx = 0, ok = 1;
    for (i=0;i<=k;i++){
        if (!g[i])
            dfs (i);
    }

    if (!idx || !ok)
        return 0;

    for (i=1;i<=k;i++){
        if (i >= n && v[i] >= v[i-n])
            return 0;
        if (i >= m && v[i] <= v[i-m])
            return 0;
    }

    return 1;
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>t;
    for (;t--;){
        cin>>n>>m;
        if (n % m == 0){
            cout<<n-1<<"\n";
            for (i=1;i<=n-1;i++)
                cout<<"1 ";
            if (n > 1)
                cout<<"\n";
            continue;
        }

        if (m % n == 0){
            cout<<m-1<<"\n";
            for (i=1;i<=m-1;i++)
                cout<<"-1 ";
            if (m > 1)
                cout<<"\n";
            continue;
        }

        int st = min(n,m)-1, dr = 1000000, sol = 0;
        while (st <= dr){
            int mid = (st+dr)>>1;
            if (verif(mid)){
                sol = mid;
                st = mid+1;
            } else dr = mid-1;
        }

        verif (sol);

        cout<<sol<<"\n";
        for (i=1;i<=sol;i++)
            cout<<v[i]-v[i-1]<<" ";
        if (sol)
            cout<<"\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47340 KB Ok
2 Correct 29 ms 47340 KB Ok
3 Correct 29 ms 47340 KB Ok
4 Correct 29 ms 47340 KB Ok
5 Correct 32 ms 47340 KB Ok
6 Correct 31 ms 47340 KB Ok
7 Correct 37 ms 47340 KB Ok
8 Correct 32 ms 47340 KB Ok
9 Correct 31 ms 47340 KB Ok
10 Correct 31 ms 47232 KB Ok
11 Correct 31 ms 47340 KB Ok
12 Correct 31 ms 47340 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 154 ms 66924 KB Ok
2 Correct 156 ms 66924 KB Ok
3 Correct 155 ms 66924 KB Ok
4 Correct 155 ms 66944 KB Ok
5 Correct 155 ms 66924 KB Ok
6 Correct 153 ms 66924 KB Ok
7 Correct 166 ms 67436 KB Ok
8 Correct 160 ms 67212 KB Ok
9 Correct 168 ms 67528 KB Ok
10 Correct 161 ms 67320 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 82 ms 66924 KB Ok
2 Correct 31 ms 47340 KB Ok
3 Correct 136 ms 66924 KB Ok
4 Correct 170 ms 66924 KB Ok
5 Correct 170 ms 66924 KB Ok
6 Correct 210 ms 66924 KB Ok
7 Correct 171 ms 66924 KB Ok
8 Correct 208 ms 66924 KB Ok
9 Correct 172 ms 66924 KB Ok
10 Correct 190 ms 66924 KB Ok
11 Correct 173 ms 66924 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 227 ms 66884 KB Ok
2 Correct 244 ms 66944 KB Ok
3 Correct 241 ms 66924 KB Ok
4 Correct 240 ms 66924 KB Ok
5 Correct 242 ms 66924 KB Ok
6 Correct 569 ms 77420 KB Ok
7 Correct 494 ms 77292 KB Ok
8 Correct 859 ms 80620 KB Ok
9 Correct 659 ms 79852 KB Ok
10 Correct 479 ms 73836 KB Ok
11 Correct 679 ms 80108 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47340 KB Ok
2 Correct 29 ms 47340 KB Ok
3 Correct 29 ms 47340 KB Ok
4 Correct 29 ms 47340 KB Ok
5 Correct 32 ms 47340 KB Ok
6 Correct 31 ms 47340 KB Ok
7 Correct 37 ms 47340 KB Ok
8 Correct 32 ms 47340 KB Ok
9 Correct 31 ms 47340 KB Ok
10 Correct 31 ms 47232 KB Ok
11 Correct 31 ms 47340 KB Ok
12 Correct 31 ms 47340 KB Ok
13 Correct 82 ms 66924 KB Ok
14 Correct 31 ms 47340 KB Ok
15 Correct 136 ms 66924 KB Ok
16 Correct 170 ms 66924 KB Ok
17 Correct 170 ms 66924 KB Ok
18 Correct 210 ms 66924 KB Ok
19 Correct 171 ms 66924 KB Ok
20 Correct 208 ms 66924 KB Ok
21 Correct 172 ms 66924 KB Ok
22 Correct 190 ms 66924 KB Ok
23 Correct 173 ms 66924 KB Ok
24 Correct 122 ms 66960 KB Ok
25 Correct 143 ms 66912 KB Ok
26 Correct 140 ms 67200 KB Ok
27 Correct 155 ms 66924 KB Ok
28 Correct 143 ms 67052 KB Ok
29 Correct 101 ms 66924 KB Ok
30 Correct 138 ms 66924 KB Ok
31 Correct 173 ms 66924 KB Ok
32 Correct 175 ms 67052 KB Ok
33 Correct 155 ms 66924 KB Ok
34 Correct 250 ms 67180 KB Ok
35 Correct 248 ms 67180 KB Ok
36 Correct 250 ms 67180 KB Ok
37 Correct 249 ms 67180 KB Ok
38 Correct 233 ms 67180 KB Ok
39 Correct 249 ms 67180 KB Ok
40 Correct 254 ms 67452 KB Ok
41 Correct 247 ms 67180 KB Ok
42 Correct 251 ms 67180 KB Ok
43 Correct 251 ms 67308 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47340 KB Ok
2 Correct 29 ms 47340 KB Ok
3 Correct 29 ms 47340 KB Ok
4 Correct 29 ms 47340 KB Ok
5 Correct 32 ms 47340 KB Ok
6 Correct 31 ms 47340 KB Ok
7 Correct 37 ms 47340 KB Ok
8 Correct 32 ms 47340 KB Ok
9 Correct 31 ms 47340 KB Ok
10 Correct 31 ms 47232 KB Ok
11 Correct 31 ms 47340 KB Ok
12 Correct 31 ms 47340 KB Ok
13 Correct 154 ms 66924 KB Ok
14 Correct 156 ms 66924 KB Ok
15 Correct 155 ms 66924 KB Ok
16 Correct 155 ms 66944 KB Ok
17 Correct 155 ms 66924 KB Ok
18 Correct 153 ms 66924 KB Ok
19 Correct 166 ms 67436 KB Ok
20 Correct 160 ms 67212 KB Ok
21 Correct 168 ms 67528 KB Ok
22 Correct 161 ms 67320 KB Ok
23 Correct 82 ms 66924 KB Ok
24 Correct 31 ms 47340 KB Ok
25 Correct 136 ms 66924 KB Ok
26 Correct 170 ms 66924 KB Ok
27 Correct 170 ms 66924 KB Ok
28 Correct 210 ms 66924 KB Ok
29 Correct 171 ms 66924 KB Ok
30 Correct 208 ms 66924 KB Ok
31 Correct 172 ms 66924 KB Ok
32 Correct 190 ms 66924 KB Ok
33 Correct 173 ms 66924 KB Ok
34 Correct 122 ms 66960 KB Ok
35 Correct 143 ms 66912 KB Ok
36 Correct 140 ms 67200 KB Ok
37 Correct 155 ms 66924 KB Ok
38 Correct 143 ms 67052 KB Ok
39 Correct 101 ms 66924 KB Ok
40 Correct 138 ms 66924 KB Ok
41 Correct 173 ms 66924 KB Ok
42 Correct 175 ms 67052 KB Ok
43 Correct 155 ms 66924 KB Ok
44 Correct 250 ms 67180 KB Ok
45 Correct 248 ms 67180 KB Ok
46 Correct 250 ms 67180 KB Ok
47 Correct 249 ms 67180 KB Ok
48 Correct 233 ms 67180 KB Ok
49 Correct 249 ms 67180 KB Ok
50 Correct 254 ms 67452 KB Ok
51 Correct 247 ms 67180 KB Ok
52 Correct 251 ms 67180 KB Ok
53 Correct 251 ms 67308 KB Ok
54 Correct 442 ms 69612 KB Ok
55 Correct 572 ms 70124 KB Ok
56 Correct 519 ms 69996 KB Ok
57 Correct 350 ms 69228 KB Ok
58 Correct 485 ms 69612 KB Ok
59 Correct 423 ms 69484 KB Ok
60 Correct 355 ms 69228 KB Ok
61 Correct 387 ms 69356 KB Ok
62 Correct 588 ms 69868 KB Ok
63 Correct 403 ms 69496 KB Ok
64 Correct 544 ms 70148 KB Ok
65 Correct 498 ms 69996 KB Ok
66 Correct 412 ms 69740 KB Ok
67 Correct 328 ms 69296 KB Ok
68 Correct 465 ms 69484 KB Ok
69 Correct 1272 ms 77164 KB Ok
70 Correct 1371 ms 77548 KB Ok
71 Correct 1446 ms 77292 KB Ok
72 Correct 1165 ms 76908 KB Ok
73 Correct 1448 ms 77292 KB Ok
74 Correct 1387 ms 77488 KB Ok
75 Correct 1190 ms 77164 KB Ok
76 Correct 1197 ms 77420 KB Ok
77 Correct 1183 ms 77420 KB Ok
78 Correct 1080 ms 77292 KB Ok
79 Correct 1208 ms 77664 KB Ok
80 Correct 1101 ms 77512 KB Ok
81 Correct 1084 ms 77548 KB Ok
82 Correct 1131 ms 77548 KB Ok
83 Correct 1245 ms 77404 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47340 KB Ok
2 Correct 29 ms 47340 KB Ok
3 Correct 29 ms 47340 KB Ok
4 Correct 29 ms 47340 KB Ok
5 Correct 32 ms 47340 KB Ok
6 Correct 31 ms 47340 KB Ok
7 Correct 37 ms 47340 KB Ok
8 Correct 32 ms 47340 KB Ok
9 Correct 31 ms 47340 KB Ok
10 Correct 31 ms 47232 KB Ok
11 Correct 31 ms 47340 KB Ok
12 Correct 31 ms 47340 KB Ok
13 Correct 154 ms 66924 KB Ok
14 Correct 156 ms 66924 KB Ok
15 Correct 155 ms 66924 KB Ok
16 Correct 155 ms 66944 KB Ok
17 Correct 155 ms 66924 KB Ok
18 Correct 153 ms 66924 KB Ok
19 Correct 166 ms 67436 KB Ok
20 Correct 160 ms 67212 KB Ok
21 Correct 168 ms 67528 KB Ok
22 Correct 161 ms 67320 KB Ok
23 Correct 82 ms 66924 KB Ok
24 Correct 31 ms 47340 KB Ok
25 Correct 136 ms 66924 KB Ok
26 Correct 170 ms 66924 KB Ok
27 Correct 170 ms 66924 KB Ok
28 Correct 210 ms 66924 KB Ok
29 Correct 171 ms 66924 KB Ok
30 Correct 208 ms 66924 KB Ok
31 Correct 172 ms 66924 KB Ok
32 Correct 190 ms 66924 KB Ok
33 Correct 173 ms 66924 KB Ok
34 Correct 227 ms 66884 KB Ok
35 Correct 244 ms 66944 KB Ok
36 Correct 241 ms 66924 KB Ok
37 Correct 240 ms 66924 KB Ok
38 Correct 242 ms 66924 KB Ok
39 Correct 569 ms 77420 KB Ok
40 Correct 494 ms 77292 KB Ok
41 Correct 859 ms 80620 KB Ok
42 Correct 659 ms 79852 KB Ok
43 Correct 479 ms 73836 KB Ok
44 Correct 679 ms 80108 KB Ok
45 Correct 122 ms 66960 KB Ok
46 Correct 143 ms 66912 KB Ok
47 Correct 140 ms 67200 KB Ok
48 Correct 155 ms 66924 KB Ok
49 Correct 143 ms 67052 KB Ok
50 Correct 101 ms 66924 KB Ok
51 Correct 138 ms 66924 KB Ok
52 Correct 173 ms 66924 KB Ok
53 Correct 175 ms 67052 KB Ok
54 Correct 155 ms 66924 KB Ok
55 Correct 250 ms 67180 KB Ok
56 Correct 248 ms 67180 KB Ok
57 Correct 250 ms 67180 KB Ok
58 Correct 249 ms 67180 KB Ok
59 Correct 233 ms 67180 KB Ok
60 Correct 249 ms 67180 KB Ok
61 Correct 254 ms 67452 KB Ok
62 Correct 247 ms 67180 KB Ok
63 Correct 251 ms 67180 KB Ok
64 Correct 251 ms 67308 KB Ok
65 Correct 442 ms 69612 KB Ok
66 Correct 572 ms 70124 KB Ok
67 Correct 519 ms 69996 KB Ok
68 Correct 350 ms 69228 KB Ok
69 Correct 485 ms 69612 KB Ok
70 Correct 423 ms 69484 KB Ok
71 Correct 355 ms 69228 KB Ok
72 Correct 387 ms 69356 KB Ok
73 Correct 588 ms 69868 KB Ok
74 Correct 403 ms 69496 KB Ok
75 Correct 544 ms 70148 KB Ok
76 Correct 498 ms 69996 KB Ok
77 Correct 412 ms 69740 KB Ok
78 Correct 328 ms 69296 KB Ok
79 Correct 465 ms 69484 KB Ok
80 Correct 1272 ms 77164 KB Ok
81 Correct 1371 ms 77548 KB Ok
82 Correct 1446 ms 77292 KB Ok
83 Correct 1165 ms 76908 KB Ok
84 Correct 1448 ms 77292 KB Ok
85 Correct 1387 ms 77488 KB Ok
86 Correct 1190 ms 77164 KB Ok
87 Correct 1197 ms 77420 KB Ok
88 Correct 1183 ms 77420 KB Ok
89 Correct 1080 ms 77292 KB Ok
90 Correct 1208 ms 77664 KB Ok
91 Correct 1101 ms 77512 KB Ok
92 Correct 1084 ms 77548 KB Ok
93 Correct 1131 ms 77548 KB Ok
94 Correct 1245 ms 77404 KB Ok
95 Correct 752 ms 73836 KB Ok
96 Correct 1328 ms 77132 KB Ok
97 Correct 1242 ms 75628 KB Ok
98 Correct 683 ms 73580 KB Ok
99 Correct 973 ms 75372 KB Ok
100 Correct 1226 ms 75468 KB Ok
101 Correct 1115 ms 75604 KB Ok
102 Correct 1145 ms 75484 KB Ok
103 Correct 1347 ms 75896 KB Ok
104 Correct 1469 ms 77208 KB Ok
105 Correct 1392 ms 76908 KB Ok
106 Correct 1125 ms 75900 KB Ok
107 Correct 1063 ms 76268 KB Ok
108 Correct 1666 ms 77100 KB Ok
109 Correct 1352 ms 76652 KB Ok
110 Execution timed out 2084 ms 82012 KB Time limit exceeded
111 Halted 0 ms 0 KB -