답안 #338667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338667 2020-12-23T15:53:53 Z Dymo Nice sequence (IZhO18_sequence) C++14
100 / 100
1870 ms 47040 KB
#include<bits/stdc++.h>
using namespace std;


#define pb  push_back
#define ll  int
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=8e5+5;
const ll mod =998244353 ;
const ll maxn1=51;
const ll base=1e9;

ll n, m;
vector<ll> tp;
bool dd[maxn];
ll ans[maxn];
ll ans1[maxn];

void dfs(ll u,ll mid)
{
    //  cout <<u<<endl;
    dd[u]=1;
    if (u+n<=mid&&!dd[u+n])
        dfs(u+n,mid);
    if (u-m>=0&&!dd[u-m])
        dfs(u-m,mid);
    tp.pb(u);
}
bool chk(ll mid)
{
    tp.clear();
    for (int i=0; i<=mid; i++)
    {
        dd[i]=0;
    }
    for (int i=0; i<=mid; i++)
    {
        if (dd[i])
            continue;
        dfs(i,mid);
    }
    for (int i=0; i<tp.size(); i++)
    {
        ans1[tp[i]]=i;
    }

    for (int i=0; i<=mid; i++)
    {
        if (i+n<=mid&&ans1[i+n]>ans1[i])
            return false;
        if (i-m>=0&&ans1[i-m]>ans1[i])
            return false;
    }
    for (int i=1;i<=mid;i++)
    {
        ans[i]=ans1[i]-ans1[i-1];
    }


    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("GIFT11.inp","r"))
    {
        freopen("GIFT11.inp","r",stdin);
        freopen("GIFT11.out","w",stdout);
    }
    ll t;
    cin>> t;
    while (t--)
    {
        cin>> n>>m ;
        ll l=0, h=maxn/2;
        while (l<=h)
        {
            ll mid=(l+h)/2;
            if (chk(mid))
                l=mid+1;
            else
                h=mid-1;
        }
        cout <<h<<endl;
        for (int i=1; i<=h; i++)
        {
            cout <<ans[i]<<" ";
        }
        cout <<endl;
        //  cout <<chk(100000);


    }


}

Compilation message

sequence.cpp: In function 'bool chk(int)':
sequence.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=0; i<tp.size(); i++)
      |                   ~^~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   72 |         freopen("GIFT11.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         freopen("GIFT11.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8552 KB Ok
2 Correct 54 ms 8552 KB Ok
3 Correct 49 ms 2664 KB Ok
4 Correct 51 ms 2664 KB Ok
5 Correct 50 ms 2664 KB Ok
6 Correct 52 ms 3816 KB Ok
7 Correct 53 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 49 ms 2428 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 50 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 5352 KB Ok
2 Correct 52 ms 5372 KB Ok
3 Correct 61 ms 5352 KB Ok
4 Correct 56 ms 5352 KB Ok
5 Correct 56 ms 5352 KB Ok
6 Correct 54 ms 5480 KB Ok
7 Correct 73 ms 5992 KB Ok
8 Correct 62 ms 5736 KB Ok
9 Correct 75 ms 5992 KB Ok
10 Correct 70 ms 5736 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 8552 KB Ok
2 Correct 59 ms 8552 KB Ok
3 Correct 61 ms 5352 KB Ok
4 Correct 52 ms 4328 KB Ok
5 Correct 59 ms 8552 KB Ok
6 Correct 57 ms 8552 KB Ok
7 Correct 54 ms 8552 KB Ok
8 Correct 54 ms 8684 KB Ok
9 Correct 51 ms 8700 KB Ok
10 Correct 54 ms 5352 KB Ok
11 Correct 53 ms 4328 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 5352 KB Ok
2 Correct 50 ms 3176 KB Ok
3 Correct 51 ms 2664 KB Ok
4 Correct 58 ms 2664 KB Ok
5 Correct 49 ms 2536 KB Ok
6 Correct 351 ms 11320 KB Ok
7 Correct 315 ms 11496 KB Ok
8 Correct 628 ms 14264 KB Ok
9 Correct 420 ms 12776 KB Ok
10 Correct 251 ms 7272 KB Ok
11 Correct 396 ms 12884 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8552 KB Ok
2 Correct 54 ms 8552 KB Ok
3 Correct 49 ms 2664 KB Ok
4 Correct 51 ms 2664 KB Ok
5 Correct 50 ms 2664 KB Ok
6 Correct 52 ms 3816 KB Ok
7 Correct 53 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 49 ms 2428 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 50 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
13 Correct 21 ms 8552 KB Ok
14 Correct 59 ms 8552 KB Ok
15 Correct 61 ms 5352 KB Ok
16 Correct 52 ms 4328 KB Ok
17 Correct 59 ms 8552 KB Ok
18 Correct 57 ms 8552 KB Ok
19 Correct 54 ms 8552 KB Ok
20 Correct 54 ms 8684 KB Ok
21 Correct 51 ms 8700 KB Ok
22 Correct 54 ms 5352 KB Ok
23 Correct 53 ms 4328 KB Ok
24 Correct 53 ms 2280 KB Ok
25 Correct 56 ms 2324 KB Ok
26 Correct 57 ms 2408 KB Ok
27 Correct 54 ms 2280 KB Ok
28 Correct 52 ms 2408 KB Ok
29 Correct 51 ms 2280 KB Ok
30 Correct 52 ms 2280 KB Ok
31 Correct 53 ms 2280 KB Ok
32 Correct 54 ms 2280 KB Ok
33 Correct 54 ms 2280 KB Ok
34 Correct 61 ms 2536 KB Ok
35 Correct 61 ms 2536 KB Ok
36 Correct 61 ms 2536 KB Ok
37 Correct 60 ms 2536 KB Ok
38 Correct 66 ms 2536 KB Ok
39 Correct 61 ms 2684 KB Ok
40 Correct 68 ms 2684 KB Ok
41 Correct 61 ms 2588 KB Ok
42 Correct 62 ms 2536 KB Ok
43 Correct 61 ms 2536 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8552 KB Ok
2 Correct 54 ms 8552 KB Ok
3 Correct 49 ms 2664 KB Ok
4 Correct 51 ms 2664 KB Ok
5 Correct 50 ms 2664 KB Ok
6 Correct 52 ms 3816 KB Ok
7 Correct 53 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 49 ms 2428 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 50 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
13 Correct 53 ms 5352 KB Ok
14 Correct 52 ms 5372 KB Ok
15 Correct 61 ms 5352 KB Ok
16 Correct 56 ms 5352 KB Ok
17 Correct 56 ms 5352 KB Ok
18 Correct 54 ms 5480 KB Ok
19 Correct 73 ms 5992 KB Ok
20 Correct 62 ms 5736 KB Ok
21 Correct 75 ms 5992 KB Ok
22 Correct 70 ms 5736 KB Ok
23 Correct 21 ms 8552 KB Ok
24 Correct 59 ms 8552 KB Ok
25 Correct 61 ms 5352 KB Ok
26 Correct 52 ms 4328 KB Ok
27 Correct 59 ms 8552 KB Ok
28 Correct 57 ms 8552 KB Ok
29 Correct 54 ms 8552 KB Ok
30 Correct 54 ms 8684 KB Ok
31 Correct 51 ms 8700 KB Ok
32 Correct 54 ms 5352 KB Ok
33 Correct 53 ms 4328 KB Ok
34 Correct 53 ms 2280 KB Ok
35 Correct 56 ms 2324 KB Ok
36 Correct 57 ms 2408 KB Ok
37 Correct 54 ms 2280 KB Ok
38 Correct 52 ms 2408 KB Ok
39 Correct 51 ms 2280 KB Ok
40 Correct 52 ms 2280 KB Ok
41 Correct 53 ms 2280 KB Ok
42 Correct 54 ms 2280 KB Ok
43 Correct 54 ms 2280 KB Ok
44 Correct 61 ms 2536 KB Ok
45 Correct 61 ms 2536 KB Ok
46 Correct 61 ms 2536 KB Ok
47 Correct 60 ms 2536 KB Ok
48 Correct 66 ms 2536 KB Ok
49 Correct 61 ms 2684 KB Ok
50 Correct 68 ms 2684 KB Ok
51 Correct 61 ms 2588 KB Ok
52 Correct 62 ms 2536 KB Ok
53 Correct 61 ms 2536 KB Ok
54 Correct 237 ms 4328 KB Ok
55 Correct 276 ms 4584 KB Ok
56 Correct 270 ms 4712 KB Ok
57 Correct 207 ms 3944 KB Ok
58 Correct 231 ms 4200 KB Ok
59 Correct 226 ms 4072 KB Ok
60 Correct 202 ms 3816 KB Ok
61 Correct 242 ms 3944 KB Ok
62 Correct 254 ms 4328 KB Ok
63 Correct 221 ms 4200 KB Ok
64 Correct 258 ms 4584 KB Ok
65 Correct 239 ms 4456 KB Ok
66 Correct 227 ms 4072 KB Ok
67 Correct 202 ms 4072 KB Ok
68 Correct 232 ms 4200 KB Ok
69 Correct 421 ms 11752 KB Ok
70 Correct 426 ms 12460 KB Ok
71 Correct 436 ms 11880 KB Ok
72 Correct 421 ms 11880 KB Ok
73 Correct 395 ms 11752 KB Ok
74 Correct 407 ms 11624 KB Ok
75 Correct 427 ms 11368 KB Ok
76 Correct 434 ms 12136 KB Ok
77 Correct 399 ms 11240 KB Ok
78 Correct 427 ms 11752 KB Ok
79 Correct 421 ms 12008 KB Ok
80 Correct 413 ms 12008 KB Ok
81 Correct 421 ms 11880 KB Ok
82 Correct 426 ms 12100 KB Ok
83 Correct 407 ms 11368 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8552 KB Ok
2 Correct 54 ms 8552 KB Ok
3 Correct 49 ms 2664 KB Ok
4 Correct 51 ms 2664 KB Ok
5 Correct 50 ms 2664 KB Ok
6 Correct 52 ms 3816 KB Ok
7 Correct 53 ms 2536 KB Ok
8 Correct 54 ms 3816 KB Ok
9 Correct 49 ms 2428 KB Ok
10 Correct 52 ms 5352 KB Ok
11 Correct 50 ms 2536 KB Ok
12 Correct 50 ms 2408 KB Ok
13 Correct 53 ms 5352 KB Ok
14 Correct 52 ms 5372 KB Ok
15 Correct 61 ms 5352 KB Ok
16 Correct 56 ms 5352 KB Ok
17 Correct 56 ms 5352 KB Ok
18 Correct 54 ms 5480 KB Ok
19 Correct 73 ms 5992 KB Ok
20 Correct 62 ms 5736 KB Ok
21 Correct 75 ms 5992 KB Ok
22 Correct 70 ms 5736 KB Ok
23 Correct 21 ms 8552 KB Ok
24 Correct 59 ms 8552 KB Ok
25 Correct 61 ms 5352 KB Ok
26 Correct 52 ms 4328 KB Ok
27 Correct 59 ms 8552 KB Ok
28 Correct 57 ms 8552 KB Ok
29 Correct 54 ms 8552 KB Ok
30 Correct 54 ms 8684 KB Ok
31 Correct 51 ms 8700 KB Ok
32 Correct 54 ms 5352 KB Ok
33 Correct 53 ms 4328 KB Ok
34 Correct 52 ms 5352 KB Ok
35 Correct 50 ms 3176 KB Ok
36 Correct 51 ms 2664 KB Ok
37 Correct 58 ms 2664 KB Ok
38 Correct 49 ms 2536 KB Ok
39 Correct 351 ms 11320 KB Ok
40 Correct 315 ms 11496 KB Ok
41 Correct 628 ms 14264 KB Ok
42 Correct 420 ms 12776 KB Ok
43 Correct 251 ms 7272 KB Ok
44 Correct 396 ms 12884 KB Ok
45 Correct 53 ms 2280 KB Ok
46 Correct 56 ms 2324 KB Ok
47 Correct 57 ms 2408 KB Ok
48 Correct 54 ms 2280 KB Ok
49 Correct 52 ms 2408 KB Ok
50 Correct 51 ms 2280 KB Ok
51 Correct 52 ms 2280 KB Ok
52 Correct 53 ms 2280 KB Ok
53 Correct 54 ms 2280 KB Ok
54 Correct 54 ms 2280 KB Ok
55 Correct 61 ms 2536 KB Ok
56 Correct 61 ms 2536 KB Ok
57 Correct 61 ms 2536 KB Ok
58 Correct 60 ms 2536 KB Ok
59 Correct 66 ms 2536 KB Ok
60 Correct 61 ms 2684 KB Ok
61 Correct 68 ms 2684 KB Ok
62 Correct 61 ms 2588 KB Ok
63 Correct 62 ms 2536 KB Ok
64 Correct 61 ms 2536 KB Ok
65 Correct 237 ms 4328 KB Ok
66 Correct 276 ms 4584 KB Ok
67 Correct 270 ms 4712 KB Ok
68 Correct 207 ms 3944 KB Ok
69 Correct 231 ms 4200 KB Ok
70 Correct 226 ms 4072 KB Ok
71 Correct 202 ms 3816 KB Ok
72 Correct 242 ms 3944 KB Ok
73 Correct 254 ms 4328 KB Ok
74 Correct 221 ms 4200 KB Ok
75 Correct 258 ms 4584 KB Ok
76 Correct 239 ms 4456 KB Ok
77 Correct 227 ms 4072 KB Ok
78 Correct 202 ms 4072 KB Ok
79 Correct 232 ms 4200 KB Ok
80 Correct 421 ms 11752 KB Ok
81 Correct 426 ms 12460 KB Ok
82 Correct 436 ms 11880 KB Ok
83 Correct 421 ms 11880 KB Ok
84 Correct 395 ms 11752 KB Ok
85 Correct 407 ms 11624 KB Ok
86 Correct 427 ms 11368 KB Ok
87 Correct 434 ms 12136 KB Ok
88 Correct 399 ms 11240 KB Ok
89 Correct 427 ms 11752 KB Ok
90 Correct 421 ms 12008 KB Ok
91 Correct 413 ms 12008 KB Ok
92 Correct 421 ms 11880 KB Ok
93 Correct 426 ms 12100 KB Ok
94 Correct 407 ms 11368 KB Ok
95 Correct 537 ms 8532 KB Ok
96 Correct 776 ms 10980 KB Ok
97 Correct 735 ms 9444 KB Ok
98 Correct 557 ms 8804 KB Ok
99 Correct 659 ms 8908 KB Ok
100 Correct 687 ms 8992 KB Ok
101 Correct 692 ms 9700 KB Ok
102 Correct 672 ms 9444 KB Ok
103 Correct 668 ms 10084 KB Ok
104 Correct 788 ms 10848 KB Ok
105 Correct 746 ms 10988 KB Ok
106 Correct 658 ms 10508 KB Ok
107 Correct 723 ms 10084 KB Ok
108 Correct 794 ms 10852 KB Ok
109 Correct 740 ms 11108 KB Ok
110 Correct 1758 ms 43236 KB Ok
111 Correct 1846 ms 46180 KB Ok
112 Correct 1803 ms 45928 KB Ok
113 Correct 1768 ms 45200 KB Ok
114 Correct 1740 ms 47040 KB Ok
115 Correct 1800 ms 45084 KB Ok
116 Correct 1838 ms 46248 KB Ok
117 Correct 1857 ms 44980 KB Ok
118 Correct 1756 ms 44760 KB Ok
119 Correct 1800 ms 44644 KB Ok
120 Correct 1751 ms 44516 KB Ok
121 Correct 1758 ms 43096 KB Ok
122 Correct 1772 ms 45516 KB Ok
123 Correct 1870 ms 46044 KB Ok
124 Correct 1777 ms 43384 KB Ok
125 Correct 1632 ms 28260 KB Ok