답안 #440899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440899 2021-07-03T12:58:03 Z leaked Nice sequence (IZhO18_sequence) C++14
100 / 100
1750 ms 72128 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC opimize(-O3)
//#pragma GCC opimize(Ofast)
//#pragma GCC opimize(unroll-loops)
//#pragma GCC target("avx,avx2,popcnt,sse,sse2,sse3,sse4,abm,tune=native")
#define m_p make_pair
#define vec vector
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)
#define f first
#define s second

using namespace std;
using namespace __gnu_pbds;
typedef long double ld;
typedef pair<int,int> pii;
const int N=4e5+1;
int ok=1;
int used[N];
vec<int>g[N];
int pref[N];
vec<int>ord;
void dfs(int v){
    used[v]=1;
    for(auto &z : g[v]){
        if(used[z]==1){
            ok=0;
        }
        else if(!used[z]){
            dfs(z);
        }
    }
    used[v]=2;
}
void dfs1(int v){
    used[v]=1;
    for(auto &z : g[v]){
        if(!used[z]){
            dfs1(z);
        }
    }
    ord.pb(v);
}
int getlen(int n,int m){
    return n+m-__gcd(n,m)-1;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int q=10;
    scanf("%d",&q);
//    cin>>q;
//    ofstream cout("out.txt");
    while(q--){
        int n,m;
//        n=199999;m=200000;
        ord.clear();
        scanf("%d%d",&n,&m);
        int wow=getlen(n,m);
        auto check=[&](int mid){
            for(int i=0;i<=mid;i++) g[i].clear(),used[i]=0;
            for(int i=0;i<=mid;i++){
                if(i>=n){
                    g[i-n].pb(i);
                }
                if(i>=m){
                    g[i].pb(i-m);
                }
            }
            ok=1;
            for(int i=0;i<=mid;i++){
                if(!used[i]){
                    dfs(i);
                }
            }
            return ok;
        };
        int l=getlen(n,m)+1,r=l;
        while(l!=r){
            int tm=(l+r)>>1;
            if(check(tm)){
                l=tm+1;
            }
            else{
                r=tm;
            }
        }
        l--;
        assert(l==wow);
        for(int i=0;i<=l;i++) g[i].clear(),used[i]=0;
        for(int i=0;i<=l;i++){
            if(i>=n){
                g[i-n].pb(i);
            }
            if(i>=m){
                g[i].pb(i-m);
            }
        }
        for(int i=0;i<=l;i++){
            if(!used[i]){
                dfs1(i);
            }
        }
//        reverse(all(ord));
        int i=1;
        for(auto &z : ord) pref[z]=i++;
//        cout<<l<<'\n';
        printf("%d%c",l,'\n');
//        cout<<l<<'\n';
        for(int i=1;i<=l;i++){
//            cout<<pref[i]-pref[i-1]<<' ';
            printf("%d%c",pref[i]-pref[i-1],' ');
        }

         printf("%c",'\n');
//        cout<<'\n';
    }
    return 0;
}
/*
5 1
1 1 2
1 3 5
3 2 3 1
2 1
3 0 3 1

*/

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
sequence.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 6 ms 9724 KB Ok
4 Correct 6 ms 9676 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 7 ms 9616 KB Ok
10 Correct 6 ms 9676 KB Ok
11 Correct 6 ms 9676 KB Ok
12 Correct 6 ms 9676 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9724 KB Ok
3 Correct 6 ms 9612 KB Ok
4 Correct 6 ms 9604 KB Ok
5 Correct 7 ms 9676 KB Ok
6 Correct 9 ms 9804 KB Ok
7 Correct 20 ms 10700 KB Ok
8 Correct 13 ms 10188 KB Ok
9 Correct 22 ms 10876 KB Ok
10 Correct 15 ms 10380 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 6 ms 9676 KB Ok
4 Correct 6 ms 9676 KB Ok
5 Correct 6 ms 9676 KB Ok
6 Correct 6 ms 9720 KB Ok
7 Correct 6 ms 9728 KB Ok
8 Correct 6 ms 9676 KB Ok
9 Correct 6 ms 9676 KB Ok
10 Correct 6 ms 9636 KB Ok
11 Correct 7 ms 9680 KB Ok
# 결과 실행 시간 메모리 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 6 ms 9676 KB Ok
5 Correct 7 ms 9676 KB Ok
6 Correct 142 ms 23272 KB Ok
7 Correct 122 ms 29536 KB Ok
8 Correct 233 ms 32300 KB Ok
9 Correct 174 ms 29496 KB Ok
10 Correct 97 ms 20040 KB Ok
11 Correct 159 ms 26112 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 6 ms 9724 KB Ok
4 Correct 6 ms 9676 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 7 ms 9616 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 6 ms 9676 KB Ok
16 Correct 6 ms 9676 KB Ok
17 Correct 6 ms 9676 KB Ok
18 Correct 6 ms 9720 KB Ok
19 Correct 6 ms 9728 KB Ok
20 Correct 6 ms 9676 KB Ok
21 Correct 6 ms 9676 KB Ok
22 Correct 6 ms 9636 KB Ok
23 Correct 7 ms 9680 KB Ok
24 Correct 8 ms 9804 KB Ok
25 Correct 8 ms 9848 KB Ok
26 Correct 9 ms 9804 KB Ok
27 Correct 8 ms 9816 KB Ok
28 Correct 9 ms 9804 KB Ok
29 Correct 9 ms 9804 KB Ok
30 Correct 8 ms 9804 KB Ok
31 Correct 9 ms 9804 KB Ok
32 Correct 9 ms 9804 KB Ok
33 Correct 8 ms 9804 KB Ok
34 Correct 11 ms 10060 KB Ok
35 Correct 13 ms 10060 KB Ok
36 Correct 11 ms 10112 KB Ok
37 Correct 12 ms 10160 KB Ok
38 Correct 11 ms 10188 KB Ok
39 Correct 12 ms 10112 KB Ok
40 Correct 12 ms 10112 KB Ok
41 Correct 11 ms 10060 KB Ok
42 Correct 12 ms 9984 KB Ok
43 Correct 11 ms 10148 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 6 ms 9724 KB Ok
4 Correct 6 ms 9676 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 7 ms 9616 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 9724 KB Ok
15 Correct 6 ms 9612 KB Ok
16 Correct 6 ms 9604 KB Ok
17 Correct 7 ms 9676 KB Ok
18 Correct 9 ms 9804 KB Ok
19 Correct 20 ms 10700 KB Ok
20 Correct 13 ms 10188 KB Ok
21 Correct 22 ms 10876 KB Ok
22 Correct 15 ms 10380 KB Ok
23 Correct 6 ms 9676 KB Ok
24 Correct 6 ms 9676 KB Ok
25 Correct 6 ms 9676 KB Ok
26 Correct 6 ms 9676 KB Ok
27 Correct 6 ms 9676 KB Ok
28 Correct 6 ms 9720 KB Ok
29 Correct 6 ms 9728 KB Ok
30 Correct 6 ms 9676 KB Ok
31 Correct 6 ms 9676 KB Ok
32 Correct 6 ms 9636 KB Ok
33 Correct 7 ms 9680 KB Ok
34 Correct 8 ms 9804 KB Ok
35 Correct 8 ms 9848 KB Ok
36 Correct 9 ms 9804 KB Ok
37 Correct 8 ms 9816 KB Ok
38 Correct 9 ms 9804 KB Ok
39 Correct 9 ms 9804 KB Ok
40 Correct 8 ms 9804 KB Ok
41 Correct 9 ms 9804 KB Ok
42 Correct 9 ms 9804 KB Ok
43 Correct 8 ms 9804 KB Ok
44 Correct 11 ms 10060 KB Ok
45 Correct 13 ms 10060 KB Ok
46 Correct 11 ms 10112 KB Ok
47 Correct 12 ms 10160 KB Ok
48 Correct 11 ms 10188 KB Ok
49 Correct 12 ms 10112 KB Ok
50 Correct 12 ms 10112 KB Ok
51 Correct 11 ms 10060 KB Ok
52 Correct 12 ms 9984 KB Ok
53 Correct 11 ms 10148 KB Ok
54 Correct 105 ms 15292 KB Ok
55 Correct 120 ms 15652 KB Ok
56 Correct 117 ms 15648 KB Ok
57 Correct 91 ms 14660 KB Ok
58 Correct 105 ms 15064 KB Ok
59 Correct 100 ms 14652 KB Ok
60 Correct 88 ms 14324 KB Ok
61 Correct 89 ms 14912 KB Ok
62 Correct 118 ms 15416 KB Ok
63 Correct 96 ms 14736 KB Ok
64 Correct 115 ms 15640 KB Ok
65 Correct 108 ms 15224 KB Ok
66 Correct 103 ms 15048 KB Ok
67 Correct 89 ms 14788 KB Ok
68 Correct 101 ms 15084 KB Ok
69 Correct 222 ms 24556 KB Ok
70 Correct 236 ms 25148 KB Ok
71 Correct 241 ms 24580 KB Ok
72 Correct 256 ms 24588 KB Ok
73 Correct 226 ms 23880 KB Ok
74 Correct 220 ms 23696 KB Ok
75 Correct 211 ms 23868 KB Ok
76 Correct 243 ms 24764 KB Ok
77 Correct 224 ms 23228 KB Ok
78 Correct 254 ms 23588 KB Ok
79 Correct 227 ms 24280 KB Ok
80 Correct 226 ms 24640 KB Ok
81 Correct 267 ms 23912 KB Ok
82 Correct 273 ms 24256 KB Ok
83 Correct 211 ms 23852 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9676 KB Ok
2 Correct 6 ms 9676 KB Ok
3 Correct 6 ms 9724 KB Ok
4 Correct 6 ms 9676 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 7 ms 9616 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 9724 KB Ok
15 Correct 6 ms 9612 KB Ok
16 Correct 6 ms 9604 KB Ok
17 Correct 7 ms 9676 KB Ok
18 Correct 9 ms 9804 KB Ok
19 Correct 20 ms 10700 KB Ok
20 Correct 13 ms 10188 KB Ok
21 Correct 22 ms 10876 KB Ok
22 Correct 15 ms 10380 KB Ok
23 Correct 6 ms 9676 KB Ok
24 Correct 6 ms 9676 KB Ok
25 Correct 6 ms 9676 KB Ok
26 Correct 6 ms 9676 KB Ok
27 Correct 6 ms 9676 KB Ok
28 Correct 6 ms 9720 KB Ok
29 Correct 6 ms 9728 KB Ok
30 Correct 6 ms 9676 KB Ok
31 Correct 6 ms 9676 KB Ok
32 Correct 6 ms 9636 KB Ok
33 Correct 7 ms 9680 KB Ok
34 Correct 6 ms 9676 KB Ok
35 Correct 6 ms 9676 KB Ok
36 Correct 7 ms 9676 KB Ok
37 Correct 6 ms 9676 KB Ok
38 Correct 7 ms 9676 KB Ok
39 Correct 142 ms 23272 KB Ok
40 Correct 122 ms 29536 KB Ok
41 Correct 233 ms 32300 KB Ok
42 Correct 174 ms 29496 KB Ok
43 Correct 97 ms 20040 KB Ok
44 Correct 159 ms 26112 KB Ok
45 Correct 8 ms 9804 KB Ok
46 Correct 8 ms 9848 KB Ok
47 Correct 9 ms 9804 KB Ok
48 Correct 8 ms 9816 KB Ok
49 Correct 9 ms 9804 KB Ok
50 Correct 9 ms 9804 KB Ok
51 Correct 8 ms 9804 KB Ok
52 Correct 9 ms 9804 KB Ok
53 Correct 9 ms 9804 KB Ok
54 Correct 8 ms 9804 KB Ok
55 Correct 11 ms 10060 KB Ok
56 Correct 13 ms 10060 KB Ok
57 Correct 11 ms 10112 KB Ok
58 Correct 12 ms 10160 KB Ok
59 Correct 11 ms 10188 KB Ok
60 Correct 12 ms 10112 KB Ok
61 Correct 12 ms 10112 KB Ok
62 Correct 11 ms 10060 KB Ok
63 Correct 12 ms 9984 KB Ok
64 Correct 11 ms 10148 KB Ok
65 Correct 105 ms 15292 KB Ok
66 Correct 120 ms 15652 KB Ok
67 Correct 117 ms 15648 KB Ok
68 Correct 91 ms 14660 KB Ok
69 Correct 105 ms 15064 KB Ok
70 Correct 100 ms 14652 KB Ok
71 Correct 88 ms 14324 KB Ok
72 Correct 89 ms 14912 KB Ok
73 Correct 118 ms 15416 KB Ok
74 Correct 96 ms 14736 KB Ok
75 Correct 115 ms 15640 KB Ok
76 Correct 108 ms 15224 KB Ok
77 Correct 103 ms 15048 KB Ok
78 Correct 89 ms 14788 KB Ok
79 Correct 101 ms 15084 KB Ok
80 Correct 222 ms 24556 KB Ok
81 Correct 236 ms 25148 KB Ok
82 Correct 241 ms 24580 KB Ok
83 Correct 256 ms 24588 KB Ok
84 Correct 226 ms 23880 KB Ok
85 Correct 220 ms 23696 KB Ok
86 Correct 211 ms 23868 KB Ok
87 Correct 243 ms 24764 KB Ok
88 Correct 224 ms 23228 KB Ok
89 Correct 254 ms 23588 KB Ok
90 Correct 227 ms 24280 KB Ok
91 Correct 226 ms 24640 KB Ok
92 Correct 267 ms 23912 KB Ok
93 Correct 273 ms 24256 KB Ok
94 Correct 211 ms 23852 KB Ok
95 Correct 268 ms 24200 KB Ok
96 Correct 385 ms 30516 KB Ok
97 Correct 353 ms 26860 KB Ok
98 Correct 271 ms 27012 KB Ok
99 Correct 322 ms 26516 KB Ok
100 Correct 321 ms 25956 KB Ok
101 Correct 328 ms 29104 KB Ok
102 Correct 320 ms 27192 KB Ok
103 Correct 317 ms 28152 KB Ok
104 Correct 381 ms 29944 KB Ok
105 Correct 359 ms 30388 KB Ok
106 Correct 322 ms 30640 KB Ok
107 Correct 346 ms 29436 KB Ok
108 Correct 399 ms 30280 KB Ok
109 Correct 374 ms 31548 KB Ok
110 Correct 1309 ms 69236 KB Ok
111 Correct 1499 ms 71424 KB Ok
112 Correct 1464 ms 67728 KB Ok
113 Correct 1408 ms 72128 KB Ok
114 Correct 1545 ms 71756 KB Ok
115 Correct 1593 ms 69156 KB Ok
116 Correct 1695 ms 71584 KB Ok
117 Correct 1540 ms 71148 KB Ok
118 Correct 1700 ms 71528 KB Ok
119 Correct 1550 ms 70352 KB Ok
120 Correct 1485 ms 70356 KB Ok
121 Correct 1622 ms 70240 KB Ok
122 Correct 1482 ms 69844 KB Ok
123 Correct 1750 ms 71836 KB Ok
124 Correct 1423 ms 65580 KB Ok
125 Correct 622 ms 55860 KB Ok