Submission #335334

# Submission time Handle Problem Language Result Execution time Memory
335334 2020-12-12T01:46:04 Z limabeans Nice sequence (IZhO18_sequence) C++17
76 / 100
2000 ms 40060 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;





int n, m;

bool viz[maxn];
int p[maxn]; //p[i-m] < p[i] > p[i+n]
vector<int> topo;



void dfs(int i, int len) {
    assert(!viz[i]);
    viz[i]=true;
    if (i-m>=0 && !viz[i-m]) dfs(i-m,len);
    if (i+n<=len && !viz[i+n]) dfs(i+n,len);
    topo.push_back(i);
}

bool test(int len) {

    topo.clear();
    for (int i=0; i<=len; i++) {
	viz[i]=false;
	p[i]=0;
    }

    for (int i=0; i<=len; i++) {
	if (!viz[i]) dfs(i,len);
    }
    for (int i=0; i<=len; i++) {
	p[topo[i]]=i;
    }

    for (int i=0; i<=len; i++) {
	if (i-n>=0 && p[i]>=p[i-n]) return false;
	if (i+m<=len && p[i+m]<=p[i]) return false;
    }
    return true;
}

void solve() {
    cin>>n>>m;
    int lo=0;
    int hi=1e6;
    while (hi-lo>1) {
	int mid=(lo+hi)/2;
	if (test(mid)) {
	    lo=mid;
	} else {
	    hi=mid;
	}
    }

    test(lo);
    cout<<lo<<"\n";
    if (lo) {
	for (int i=1; i<=lo; i++) {
	    cout<<p[i]-p[i-1]<<" ";
	}
	cout<<"\n";
    }
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);


    int t;
    cin>>t;
    while (t--) {
	solve();
    }	    
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 206 ms 20584 KB Ok
2 Correct 212 ms 20584 KB Ok
3 Correct 147 ms 6116 KB Ok
4 Correct 147 ms 7140 KB Ok
5 Correct 145 ms 5988 KB Ok
6 Correct 151 ms 8840 KB Ok
7 Correct 149 ms 5604 KB Ok
8 Correct 157 ms 8936 KB Ok
9 Correct 146 ms 5860 KB Ok
10 Correct 151 ms 12920 KB Ok
11 Correct 143 ms 5604 KB Ok
12 Correct 140 ms 5348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 216 ms 20580 KB Ok
2 Correct 207 ms 20580 KB Ok
3 Correct 194 ms 20580 KB Ok
4 Correct 199 ms 20580 KB Ok
5 Correct 208 ms 20580 KB Ok
6 Correct 200 ms 20584 KB Ok
7 Correct 216 ms 20964 KB Ok
8 Correct 196 ms 20708 KB Ok
9 Correct 208 ms 20964 KB Ok
10 Correct 212 ms 20836 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 79 ms 20584 KB Ok
2 Correct 200 ms 20720 KB Ok
3 Correct 206 ms 20580 KB Ok
4 Correct 223 ms 20584 KB Ok
5 Correct 219 ms 20584 KB Ok
6 Correct 221 ms 20580 KB Ok
7 Correct 202 ms 20584 KB Ok
8 Correct 230 ms 20584 KB Ok
9 Correct 205 ms 20580 KB Ok
10 Correct 217 ms 20580 KB Ok
11 Correct 230 ms 20708 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 223 ms 20584 KB Ok
2 Correct 243 ms 20584 KB Ok
3 Correct 242 ms 20584 KB Ok
4 Correct 233 ms 20584 KB Ok
5 Correct 237 ms 20584 KB Ok
6 Correct 507 ms 24292 KB Ok
7 Correct 495 ms 22756 KB Ok
8 Correct 775 ms 26300 KB Ok
9 Correct 593 ms 25444 KB Ok
10 Correct 428 ms 21988 KB Ok
11 Correct 578 ms 24036 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 206 ms 20584 KB Ok
2 Correct 212 ms 20584 KB Ok
3 Correct 147 ms 6116 KB Ok
4 Correct 147 ms 7140 KB Ok
5 Correct 145 ms 5988 KB Ok
6 Correct 151 ms 8840 KB Ok
7 Correct 149 ms 5604 KB Ok
8 Correct 157 ms 8936 KB Ok
9 Correct 146 ms 5860 KB Ok
10 Correct 151 ms 12920 KB Ok
11 Correct 143 ms 5604 KB Ok
12 Correct 140 ms 5348 KB Ok
13 Correct 79 ms 20584 KB Ok
14 Correct 200 ms 20720 KB Ok
15 Correct 206 ms 20580 KB Ok
16 Correct 223 ms 20584 KB Ok
17 Correct 219 ms 20584 KB Ok
18 Correct 221 ms 20580 KB Ok
19 Correct 202 ms 20584 KB Ok
20 Correct 230 ms 20584 KB Ok
21 Correct 205 ms 20580 KB Ok
22 Correct 217 ms 20580 KB Ok
23 Correct 230 ms 20708 KB Ok
24 Correct 167 ms 5112 KB Ok
25 Correct 164 ms 5348 KB Ok
26 Correct 168 ms 5992 KB Ok
27 Correct 168 ms 6116 KB Ok
28 Correct 169 ms 5384 KB Ok
29 Correct 160 ms 10084 KB Ok
30 Correct 177 ms 5608 KB Ok
31 Correct 174 ms 5220 KB Ok
32 Correct 173 ms 5096 KB Ok
33 Correct 171 ms 5732 KB Ok
34 Correct 235 ms 20836 KB Ok
35 Correct 254 ms 20708 KB Ok
36 Correct 234 ms 20688 KB Ok
37 Correct 251 ms 20708 KB Ok
38 Correct 248 ms 20708 KB Ok
39 Correct 224 ms 20708 KB Ok
40 Correct 254 ms 20820 KB Ok
41 Correct 251 ms 20708 KB Ok
42 Correct 228 ms 20712 KB Ok
43 Correct 249 ms 20708 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 206 ms 20584 KB Ok
2 Correct 212 ms 20584 KB Ok
3 Correct 147 ms 6116 KB Ok
4 Correct 147 ms 7140 KB Ok
5 Correct 145 ms 5988 KB Ok
6 Correct 151 ms 8840 KB Ok
7 Correct 149 ms 5604 KB Ok
8 Correct 157 ms 8936 KB Ok
9 Correct 146 ms 5860 KB Ok
10 Correct 151 ms 12920 KB Ok
11 Correct 143 ms 5604 KB Ok
12 Correct 140 ms 5348 KB Ok
13 Correct 216 ms 20580 KB Ok
14 Correct 207 ms 20580 KB Ok
15 Correct 194 ms 20580 KB Ok
16 Correct 199 ms 20580 KB Ok
17 Correct 208 ms 20580 KB Ok
18 Correct 200 ms 20584 KB Ok
19 Correct 216 ms 20964 KB Ok
20 Correct 196 ms 20708 KB Ok
21 Correct 208 ms 20964 KB Ok
22 Correct 212 ms 20836 KB Ok
23 Correct 79 ms 20584 KB Ok
24 Correct 200 ms 20720 KB Ok
25 Correct 206 ms 20580 KB Ok
26 Correct 223 ms 20584 KB Ok
27 Correct 219 ms 20584 KB Ok
28 Correct 221 ms 20580 KB Ok
29 Correct 202 ms 20584 KB Ok
30 Correct 230 ms 20584 KB Ok
31 Correct 205 ms 20580 KB Ok
32 Correct 217 ms 20580 KB Ok
33 Correct 230 ms 20708 KB Ok
34 Correct 167 ms 5112 KB Ok
35 Correct 164 ms 5348 KB Ok
36 Correct 168 ms 5992 KB Ok
37 Correct 168 ms 6116 KB Ok
38 Correct 169 ms 5384 KB Ok
39 Correct 160 ms 10084 KB Ok
40 Correct 177 ms 5608 KB Ok
41 Correct 174 ms 5220 KB Ok
42 Correct 173 ms 5096 KB Ok
43 Correct 171 ms 5732 KB Ok
44 Correct 235 ms 20836 KB Ok
45 Correct 254 ms 20708 KB Ok
46 Correct 234 ms 20688 KB Ok
47 Correct 251 ms 20708 KB Ok
48 Correct 248 ms 20708 KB Ok
49 Correct 224 ms 20708 KB Ok
50 Correct 254 ms 20820 KB Ok
51 Correct 251 ms 20708 KB Ok
52 Correct 228 ms 20712 KB Ok
53 Correct 249 ms 20708 KB Ok
54 Correct 368 ms 6628 KB Ok
55 Correct 409 ms 7112 KB Ok
56 Correct 395 ms 7268 KB Ok
57 Correct 316 ms 6244 KB Ok
58 Correct 362 ms 6500 KB Ok
59 Correct 343 ms 6244 KB Ok
60 Correct 320 ms 6116 KB Ok
61 Correct 323 ms 6244 KB Ok
62 Correct 392 ms 6756 KB Ok
63 Correct 345 ms 6372 KB Ok
64 Correct 396 ms 6884 KB Ok
65 Correct 371 ms 6628 KB Ok
66 Correct 348 ms 6372 KB Ok
67 Correct 322 ms 6372 KB Ok
68 Correct 351 ms 6500 KB Ok
69 Correct 630 ms 26724 KB Ok
70 Correct 643 ms 27364 KB Ok
71 Correct 599 ms 26724 KB Ok
72 Correct 628 ms 26468 KB Ok
73 Correct 607 ms 26724 KB Ok
74 Correct 601 ms 26452 KB Ok
75 Correct 625 ms 26084 KB Ok
76 Correct 658 ms 27108 KB Ok
77 Correct 590 ms 26212 KB Ok
78 Correct 633 ms 26548 KB Ok
79 Correct 618 ms 26980 KB Ok
80 Correct 610 ms 26724 KB Ok
81 Correct 629 ms 26724 KB Ok
82 Correct 611 ms 26852 KB Ok
83 Correct 607 ms 26084 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 206 ms 20584 KB Ok
2 Correct 212 ms 20584 KB Ok
3 Correct 147 ms 6116 KB Ok
4 Correct 147 ms 7140 KB Ok
5 Correct 145 ms 5988 KB Ok
6 Correct 151 ms 8840 KB Ok
7 Correct 149 ms 5604 KB Ok
8 Correct 157 ms 8936 KB Ok
9 Correct 146 ms 5860 KB Ok
10 Correct 151 ms 12920 KB Ok
11 Correct 143 ms 5604 KB Ok
12 Correct 140 ms 5348 KB Ok
13 Correct 216 ms 20580 KB Ok
14 Correct 207 ms 20580 KB Ok
15 Correct 194 ms 20580 KB Ok
16 Correct 199 ms 20580 KB Ok
17 Correct 208 ms 20580 KB Ok
18 Correct 200 ms 20584 KB Ok
19 Correct 216 ms 20964 KB Ok
20 Correct 196 ms 20708 KB Ok
21 Correct 208 ms 20964 KB Ok
22 Correct 212 ms 20836 KB Ok
23 Correct 79 ms 20584 KB Ok
24 Correct 200 ms 20720 KB Ok
25 Correct 206 ms 20580 KB Ok
26 Correct 223 ms 20584 KB Ok
27 Correct 219 ms 20584 KB Ok
28 Correct 221 ms 20580 KB Ok
29 Correct 202 ms 20584 KB Ok
30 Correct 230 ms 20584 KB Ok
31 Correct 205 ms 20580 KB Ok
32 Correct 217 ms 20580 KB Ok
33 Correct 230 ms 20708 KB Ok
34 Correct 223 ms 20584 KB Ok
35 Correct 243 ms 20584 KB Ok
36 Correct 242 ms 20584 KB Ok
37 Correct 233 ms 20584 KB Ok
38 Correct 237 ms 20584 KB Ok
39 Correct 507 ms 24292 KB Ok
40 Correct 495 ms 22756 KB Ok
41 Correct 775 ms 26300 KB Ok
42 Correct 593 ms 25444 KB Ok
43 Correct 428 ms 21988 KB Ok
44 Correct 578 ms 24036 KB Ok
45 Correct 167 ms 5112 KB Ok
46 Correct 164 ms 5348 KB Ok
47 Correct 168 ms 5992 KB Ok
48 Correct 168 ms 6116 KB Ok
49 Correct 169 ms 5384 KB Ok
50 Correct 160 ms 10084 KB Ok
51 Correct 177 ms 5608 KB Ok
52 Correct 174 ms 5220 KB Ok
53 Correct 173 ms 5096 KB Ok
54 Correct 171 ms 5732 KB Ok
55 Correct 235 ms 20836 KB Ok
56 Correct 254 ms 20708 KB Ok
57 Correct 234 ms 20688 KB Ok
58 Correct 251 ms 20708 KB Ok
59 Correct 248 ms 20708 KB Ok
60 Correct 224 ms 20708 KB Ok
61 Correct 254 ms 20820 KB Ok
62 Correct 251 ms 20708 KB Ok
63 Correct 228 ms 20712 KB Ok
64 Correct 249 ms 20708 KB Ok
65 Correct 368 ms 6628 KB Ok
66 Correct 409 ms 7112 KB Ok
67 Correct 395 ms 7268 KB Ok
68 Correct 316 ms 6244 KB Ok
69 Correct 362 ms 6500 KB Ok
70 Correct 343 ms 6244 KB Ok
71 Correct 320 ms 6116 KB Ok
72 Correct 323 ms 6244 KB Ok
73 Correct 392 ms 6756 KB Ok
74 Correct 345 ms 6372 KB Ok
75 Correct 396 ms 6884 KB Ok
76 Correct 371 ms 6628 KB Ok
77 Correct 348 ms 6372 KB Ok
78 Correct 322 ms 6372 KB Ok
79 Correct 351 ms 6500 KB Ok
80 Correct 630 ms 26724 KB Ok
81 Correct 643 ms 27364 KB Ok
82 Correct 599 ms 26724 KB Ok
83 Correct 628 ms 26468 KB Ok
84 Correct 607 ms 26724 KB Ok
85 Correct 601 ms 26452 KB Ok
86 Correct 625 ms 26084 KB Ok
87 Correct 658 ms 27108 KB Ok
88 Correct 590 ms 26212 KB Ok
89 Correct 633 ms 26548 KB Ok
90 Correct 618 ms 26980 KB Ok
91 Correct 610 ms 26724 KB Ok
92 Correct 629 ms 26724 KB Ok
93 Correct 611 ms 26852 KB Ok
94 Correct 607 ms 26084 KB Ok
95 Correct 654 ms 9368 KB Ok
96 Correct 940 ms 10724 KB Ok
97 Correct 906 ms 10244 KB Ok
98 Correct 684 ms 9060 KB Ok
99 Correct 814 ms 9572 KB Ok
100 Correct 826 ms 9956 KB Ok
101 Correct 854 ms 9828 KB Ok
102 Correct 850 ms 9828 KB Ok
103 Correct 810 ms 9956 KB Ok
104 Correct 965 ms 11108 KB Ok
105 Correct 916 ms 10596 KB Ok
106 Correct 807 ms 10212 KB Ok
107 Correct 883 ms 10112 KB Ok
108 Correct 958 ms 10852 KB Ok
109 Correct 888 ms 10640 KB Ok
110 Execution timed out 2083 ms 40060 KB Time limit exceeded
111 Halted 0 ms 0 KB -