답안 #91949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91949 2018-12-31T16:01:06 Z popovicirobert Nice sequence (IZhO18_sequence) C++14
76 / 100
916 ms 73740 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int INF = 5e8;
const int MAXN = (int) 2e5;

vector <int> g[2 * MAXN + 1];
char vis[2 * MAXN + 1];

void dfs(int nod, bool &ok) {
    vis[nod] = 1;
    for(auto it : g[nod]) {
        if(vis[it] == 0) {
            dfs(it, ok);
        }
        else if(vis[it] == 1) {
            ok = 0;
        }
        if(ok == 0) {
            return ;
        }
    }
    vis[nod] = 2;
}

inline bool check(int len, int n, int m) {
    int i;
    for(i = 0; i <= len; i++) {
        g[i].clear();
        vis[i] = 0;
    }
    for(i = 1; i <= len; i++) {
        if(i >= n) {
            g[i - n].push_back(i);
        }
        if(i >= m) {
            g[i].push_back(i - m);
        }
    }
    bool ok = 1;
    for(i = 0; i <= len; i++) {
        if(vis[i] == 0) {
            dfs(i, ok);
        }
    }
    return ok;
}

inline int get(int n, int m) {
    int res = 0;
    for(int step = 1 << 17; step; step >>= 1) {
        if(res + step <= n + m && check(res + step, n, m)) {
            res += step;
        }
    }
    return res;
}

vector <int> aux[2 * MAXN + 1];
vector <int> ord;
int sp[MAXN + 1];

void dfs1(int nod) {
    vis[nod] = 1;
    for(auto it : aux[nod]) {
        if(vis[it] == 0) {
            dfs1(it);
        }
    }
    ord.push_back(nod);
}

inline void solve(int sz, int n, int m) {
    int i;
    for(i = 0; i <= sz; i++) {
        aux[i].clear();
        vis[i] = 0;
        if(i - n >= 0) {
            aux[i - n].push_back(i);
        }
        if(i - m >= 0) {
            aux[i].push_back(i - m);
        }
    }
    ord.clear();
    for(i = 0; i <= sz; i++) {
        if(vis[i] == 0) {
            dfs1(i);
        }
    }
    int val = -INF;
    for(auto it : ord) {
        if(it == 0) {
            val = max(val, 0);
            sp[it] = 0;
            val++;
            continue;
        }
        for(auto itr : aux[it]) {
            val = max(val, sp[itr] + 1);
        }
        sp[it] = val;
        val++;
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int t, i, j;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> t;
    while(t > 0) {
        t--;
        int n, m;
        cin >> n >> m;
        int mn = min(n, m), mx = max(n, m);
        if(mx % mn == 0) {
            cout << mx - 1 << "\n";
            int sign = 1;
            if(mn == n) {
                sign = -1;
            }
            for(i = 1; i < mx; i++) {
                cout << sign << " ";
            }
            if(mx > 1) {
                cout << "\n";
            }
            continue;
        }
        int sz = get(n, m);
        solve(sz, n, m);
        cout << sz << "\n";
        for(i = 1; i <= sz; i++) {
            cout << sp[i] - sp[i - 1] << " ";
        }
        cout << "\n";
    }
    //cin.close();
    //cout.close();
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:117:15: warning: unused variable 'j' [-Wunused-variable]
     int t, i, j;
               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 19148 KB Ok
2 Correct 16 ms 19192 KB Ok
3 Correct 16 ms 19108 KB Ok
4 Correct 16 ms 19064 KB Ok
5 Correct 15 ms 19064 KB Ok
6 Correct 16 ms 19068 KB Ok
7 Correct 15 ms 18936 KB Ok
8 Correct 15 ms 19064 KB Ok
9 Correct 15 ms 19064 KB Ok
10 Correct 15 ms 19064 KB Ok
11 Correct 16 ms 19064 KB Ok
12 Correct 16 ms 19064 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19064 KB Ok
2 Correct 15 ms 19064 KB Ok
3 Correct 15 ms 19064 KB Ok
4 Correct 18 ms 19064 KB Ok
5 Correct 18 ms 19064 KB Ok
6 Correct 18 ms 19576 KB Ok
7 Correct 30 ms 20800 KB Ok
8 Correct 23 ms 19876 KB Ok
9 Correct 31 ms 20956 KB Ok
10 Correct 26 ms 20244 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19064 KB Ok
2 Correct 15 ms 19064 KB Ok
3 Correct 20 ms 19060 KB Ok
4 Correct 18 ms 19064 KB Ok
5 Correct 19 ms 19064 KB Ok
6 Correct 19 ms 19064 KB Ok
7 Correct 16 ms 19064 KB Ok
8 Correct 15 ms 19064 KB Ok
9 Correct 16 ms 19064 KB Ok
10 Correct 16 ms 19204 KB Ok
11 Correct 16 ms 19064 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19068 KB Ok
2 Correct 16 ms 19192 KB Ok
3 Correct 16 ms 19192 KB Ok
4 Correct 16 ms 19064 KB Ok
5 Correct 16 ms 19124 KB Ok
6 Correct 295 ms 43320 KB Ok
7 Correct 278 ms 44880 KB Ok
8 Correct 525 ms 49516 KB Ok
9 Correct 356 ms 45840 KB Ok
10 Correct 209 ms 33820 KB Ok
11 Correct 373 ms 47336 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 19148 KB Ok
2 Correct 16 ms 19192 KB Ok
3 Correct 16 ms 19108 KB Ok
4 Correct 16 ms 19064 KB Ok
5 Correct 15 ms 19064 KB Ok
6 Correct 16 ms 19068 KB Ok
7 Correct 15 ms 18936 KB Ok
8 Correct 15 ms 19064 KB Ok
9 Correct 15 ms 19064 KB Ok
10 Correct 15 ms 19064 KB Ok
11 Correct 16 ms 19064 KB Ok
12 Correct 16 ms 19064 KB Ok
13 Correct 15 ms 19064 KB Ok
14 Correct 15 ms 19064 KB Ok
15 Correct 20 ms 19060 KB Ok
16 Correct 18 ms 19064 KB Ok
17 Correct 19 ms 19064 KB Ok
18 Correct 19 ms 19064 KB Ok
19 Correct 16 ms 19064 KB Ok
20 Correct 15 ms 19064 KB Ok
21 Correct 16 ms 19064 KB Ok
22 Correct 16 ms 19204 KB Ok
23 Correct 16 ms 19064 KB Ok
24 Correct 22 ms 19448 KB Ok
25 Correct 21 ms 19448 KB Ok
26 Correct 21 ms 19416 KB Ok
27 Correct 22 ms 19448 KB Ok
28 Correct 21 ms 19448 KB Ok
29 Correct 20 ms 19320 KB Ok
30 Correct 21 ms 19372 KB Ok
31 Correct 23 ms 19448 KB Ok
32 Correct 24 ms 19320 KB Ok
33 Correct 22 ms 19320 KB Ok
34 Correct 29 ms 19832 KB Ok
35 Correct 29 ms 19832 KB Ok
36 Correct 30 ms 19804 KB Ok
37 Correct 29 ms 19832 KB Ok
38 Correct 26 ms 19840 KB Ok
39 Correct 26 ms 19704 KB Ok
40 Correct 31 ms 19832 KB Ok
41 Correct 30 ms 19832 KB Ok
42 Correct 27 ms 19960 KB Ok
43 Correct 30 ms 19832 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 19148 KB Ok
2 Correct 16 ms 19192 KB Ok
3 Correct 16 ms 19108 KB Ok
4 Correct 16 ms 19064 KB Ok
5 Correct 15 ms 19064 KB Ok
6 Correct 16 ms 19068 KB Ok
7 Correct 15 ms 18936 KB Ok
8 Correct 15 ms 19064 KB Ok
9 Correct 15 ms 19064 KB Ok
10 Correct 15 ms 19064 KB Ok
11 Correct 16 ms 19064 KB Ok
12 Correct 16 ms 19064 KB Ok
13 Correct 15 ms 19064 KB Ok
14 Correct 15 ms 19064 KB Ok
15 Correct 15 ms 19064 KB Ok
16 Correct 18 ms 19064 KB Ok
17 Correct 18 ms 19064 KB Ok
18 Correct 18 ms 19576 KB Ok
19 Correct 30 ms 20800 KB Ok
20 Correct 23 ms 19876 KB Ok
21 Correct 31 ms 20956 KB Ok
22 Correct 26 ms 20244 KB Ok
23 Correct 15 ms 19064 KB Ok
24 Correct 15 ms 19064 KB Ok
25 Correct 20 ms 19060 KB Ok
26 Correct 18 ms 19064 KB Ok
27 Correct 19 ms 19064 KB Ok
28 Correct 19 ms 19064 KB Ok
29 Correct 16 ms 19064 KB Ok
30 Correct 15 ms 19064 KB Ok
31 Correct 16 ms 19064 KB Ok
32 Correct 16 ms 19204 KB Ok
33 Correct 16 ms 19064 KB Ok
34 Correct 22 ms 19448 KB Ok
35 Correct 21 ms 19448 KB Ok
36 Correct 21 ms 19416 KB Ok
37 Correct 22 ms 19448 KB Ok
38 Correct 21 ms 19448 KB Ok
39 Correct 20 ms 19320 KB Ok
40 Correct 21 ms 19372 KB Ok
41 Correct 23 ms 19448 KB Ok
42 Correct 24 ms 19320 KB Ok
43 Correct 22 ms 19320 KB Ok
44 Correct 29 ms 19832 KB Ok
45 Correct 29 ms 19832 KB Ok
46 Correct 30 ms 19804 KB Ok
47 Correct 29 ms 19832 KB Ok
48 Correct 26 ms 19840 KB Ok
49 Correct 26 ms 19704 KB Ok
50 Correct 31 ms 19832 KB Ok
51 Correct 30 ms 19832 KB Ok
52 Correct 27 ms 19960 KB Ok
53 Correct 30 ms 19832 KB Ok
54 Correct 340 ms 27636 KB Ok
55 Correct 406 ms 27888 KB Ok
56 Correct 399 ms 27888 KB Ok
57 Correct 216 ms 26608 KB Ok
58 Correct 292 ms 27288 KB Ok
59 Correct 238 ms 26996 KB Ok
60 Correct 193 ms 26228 KB Ok
61 Correct 239 ms 27120 KB Ok
62 Correct 340 ms 27632 KB Ok
63 Correct 266 ms 26744 KB Ok
64 Correct 390 ms 27764 KB Ok
65 Correct 311 ms 27612 KB Ok
66 Correct 252 ms 27224 KB Ok
67 Correct 211 ms 26996 KB Ok
68 Correct 274 ms 27400 KB Ok
69 Correct 764 ms 38204 KB Ok
70 Correct 716 ms 39592 KB Ok
71 Correct 796 ms 39064 KB Ok
72 Correct 792 ms 38248 KB Ok
73 Correct 611 ms 39104 KB Ok
74 Correct 742 ms 38360 KB Ok
75 Correct 867 ms 37696 KB Ok
76 Correct 671 ms 38976 KB Ok
77 Correct 724 ms 37760 KB Ok
78 Correct 741 ms 38644 KB Ok
79 Correct 799 ms 39352 KB Ok
80 Correct 864 ms 39408 KB Ok
81 Correct 916 ms 38896 KB Ok
82 Correct 809 ms 39284 KB Ok
83 Correct 768 ms 37744 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 19148 KB Ok
2 Correct 16 ms 19192 KB Ok
3 Correct 16 ms 19108 KB Ok
4 Correct 16 ms 19064 KB Ok
5 Correct 15 ms 19064 KB Ok
6 Correct 16 ms 19068 KB Ok
7 Correct 15 ms 18936 KB Ok
8 Correct 15 ms 19064 KB Ok
9 Correct 15 ms 19064 KB Ok
10 Correct 15 ms 19064 KB Ok
11 Correct 16 ms 19064 KB Ok
12 Correct 16 ms 19064 KB Ok
13 Correct 15 ms 19064 KB Ok
14 Correct 15 ms 19064 KB Ok
15 Correct 15 ms 19064 KB Ok
16 Correct 18 ms 19064 KB Ok
17 Correct 18 ms 19064 KB Ok
18 Correct 18 ms 19576 KB Ok
19 Correct 30 ms 20800 KB Ok
20 Correct 23 ms 19876 KB Ok
21 Correct 31 ms 20956 KB Ok
22 Correct 26 ms 20244 KB Ok
23 Correct 15 ms 19064 KB Ok
24 Correct 15 ms 19064 KB Ok
25 Correct 20 ms 19060 KB Ok
26 Correct 18 ms 19064 KB Ok
27 Correct 19 ms 19064 KB Ok
28 Correct 19 ms 19064 KB Ok
29 Correct 16 ms 19064 KB Ok
30 Correct 15 ms 19064 KB Ok
31 Correct 16 ms 19064 KB Ok
32 Correct 16 ms 19204 KB Ok
33 Correct 16 ms 19064 KB Ok
34 Correct 16 ms 19068 KB Ok
35 Correct 16 ms 19192 KB Ok
36 Correct 16 ms 19192 KB Ok
37 Correct 16 ms 19064 KB Ok
38 Correct 16 ms 19124 KB Ok
39 Correct 295 ms 43320 KB Ok
40 Correct 278 ms 44880 KB Ok
41 Correct 525 ms 49516 KB Ok
42 Correct 356 ms 45840 KB Ok
43 Correct 209 ms 33820 KB Ok
44 Correct 373 ms 47336 KB Ok
45 Correct 22 ms 19448 KB Ok
46 Correct 21 ms 19448 KB Ok
47 Correct 21 ms 19416 KB Ok
48 Correct 22 ms 19448 KB Ok
49 Correct 21 ms 19448 KB Ok
50 Correct 20 ms 19320 KB Ok
51 Correct 21 ms 19372 KB Ok
52 Correct 23 ms 19448 KB Ok
53 Correct 24 ms 19320 KB Ok
54 Correct 22 ms 19320 KB Ok
55 Correct 29 ms 19832 KB Ok
56 Correct 29 ms 19832 KB Ok
57 Correct 30 ms 19804 KB Ok
58 Correct 29 ms 19832 KB Ok
59 Correct 26 ms 19840 KB Ok
60 Correct 26 ms 19704 KB Ok
61 Correct 31 ms 19832 KB Ok
62 Correct 30 ms 19832 KB Ok
63 Correct 27 ms 19960 KB Ok
64 Correct 30 ms 19832 KB Ok
65 Correct 340 ms 27636 KB Ok
66 Correct 406 ms 27888 KB Ok
67 Correct 399 ms 27888 KB Ok
68 Correct 216 ms 26608 KB Ok
69 Correct 292 ms 27288 KB Ok
70 Correct 238 ms 26996 KB Ok
71 Correct 193 ms 26228 KB Ok
72 Correct 239 ms 27120 KB Ok
73 Correct 340 ms 27632 KB Ok
74 Correct 266 ms 26744 KB Ok
75 Correct 390 ms 27764 KB Ok
76 Correct 311 ms 27612 KB Ok
77 Correct 252 ms 27224 KB Ok
78 Correct 211 ms 26996 KB Ok
79 Correct 274 ms 27400 KB Ok
80 Correct 764 ms 38204 KB Ok
81 Correct 716 ms 39592 KB Ok
82 Correct 796 ms 39064 KB Ok
83 Correct 792 ms 38248 KB Ok
84 Correct 611 ms 39104 KB Ok
85 Correct 742 ms 38360 KB Ok
86 Correct 867 ms 37696 KB Ok
87 Correct 671 ms 38976 KB Ok
88 Correct 724 ms 37760 KB Ok
89 Correct 741 ms 38644 KB Ok
90 Correct 799 ms 39352 KB Ok
91 Correct 864 ms 39408 KB Ok
92 Correct 916 ms 38896 KB Ok
93 Correct 809 ms 39284 KB Ok
94 Correct 768 ms 37744 KB Ok
95 Runtime error 342 ms 73740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
96 Halted 0 ms 0 KB -