Submission #40454

# Submission time Handle Problem Language Result Execution time Memory
40454 2018-02-01T16:38:56 Z Pajaraja Nice sequence (IZhO18_sequence) C++14
76 / 100
2000 ms 31988 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> g[400007];
int pv[400007],deg[400007],parc[400007];
bool provera(int s,int n,int m)
{
	fill(deg,deg+s+1,0);
	for(int i=0;i<=s;i++) g[i].clear();
	for(int i=n;i<=s;i++) 
	{
	    g[i].push_back(i-n);
	    deg[i-n]++;
	}
	for(int i=m;i<=s;i++)
	{
		g[i-m].push_back(i);
		deg[i]++;
	}
	queue<int> q;
	for(int i=0;i<=s;i++) if(deg[i]==0) q.push(i);
	int cnt=0;
	while(!q.empty())
	{
		int u=q.front();
		pv[u]=cnt++;
		q.pop();
		for(int i=0;i<g[u].size();i++) 
		{
			deg[g[u][i]]--;
			if(deg[g[u][i]]==0) q.push(g[u][i]);
		}
	}
	if(cnt<=s) return false;
	return true;
}
int binarna(int l,int r,int n,int m)
{
	if(l==r) return l;
	int s=(l+r)/2;
	if(!provera(s,n,m)) return binarna(l,s,n,m);
	else return binarna(s+1,r,n,m);
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m;
		scanf("%d%d",&n,&m);
		int x=binarna(0,m+n+5,n,m);
		printf("%d\n",x-1);
		provera(x-1,n,m);
		for(int i=1;i<x;i++) printf("%d ",pv[i]-pv[i-1]);
		printf("\n");
	}
}

Compilation message

sequence.cpp: In function 'bool provera(int, int, int)':
sequence.cpp:27:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<g[u].size();i++) 
                ^
sequence.cpp: In function 'int main()':
sequence.cpp:46:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&t);
                ^
sequence.cpp:50:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&n,&m);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9824 KB Ok
3 Correct 9 ms 9896 KB Ok
4 Correct 9 ms 9896 KB Ok
5 Correct 9 ms 9896 KB Ok
6 Correct 9 ms 9904 KB Ok
7 Correct 9 ms 9904 KB Ok
8 Correct 9 ms 10008 KB Ok
9 Correct 9 ms 10008 KB Ok
10 Correct 9 ms 10008 KB Ok
11 Correct 8 ms 10008 KB Ok
12 Correct 9 ms 10008 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10008 KB Ok
2 Correct 9 ms 10008 KB Ok
3 Correct 9 ms 10008 KB Ok
4 Correct 9 ms 10008 KB Ok
5 Correct 9 ms 10008 KB Ok
6 Correct 15 ms 10220 KB Ok
7 Correct 39 ms 10604 KB Ok
8 Correct 25 ms 10604 KB Ok
9 Correct 45 ms 10764 KB Ok
10 Correct 28 ms 10764 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10764 KB Ok
2 Correct 8 ms 10764 KB Ok
3 Correct 8 ms 10764 KB Ok
4 Correct 8 ms 10764 KB Ok
5 Correct 8 ms 10764 KB Ok
6 Correct 8 ms 10764 KB Ok
7 Correct 9 ms 10764 KB Ok
8 Correct 8 ms 10764 KB Ok
9 Correct 9 ms 10764 KB Ok
10 Correct 10 ms 10764 KB Ok
11 Correct 8 ms 10764 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10764 KB Ok
2 Correct 10 ms 10764 KB Ok
3 Correct 9 ms 10764 KB Ok
4 Correct 9 ms 10764 KB Ok
5 Correct 10 ms 10764 KB Ok
6 Correct 382 ms 19388 KB Ok
7 Correct 383 ms 19964 KB Ok
8 Correct 645 ms 21960 KB Ok
9 Correct 442 ms 21960 KB Ok
10 Correct 266 ms 21960 KB Ok
11 Correct 457 ms 21960 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9824 KB Ok
3 Correct 9 ms 9896 KB Ok
4 Correct 9 ms 9896 KB Ok
5 Correct 9 ms 9896 KB Ok
6 Correct 9 ms 9904 KB Ok
7 Correct 9 ms 9904 KB Ok
8 Correct 9 ms 10008 KB Ok
9 Correct 9 ms 10008 KB Ok
10 Correct 9 ms 10008 KB Ok
11 Correct 8 ms 10008 KB Ok
12 Correct 9 ms 10008 KB Ok
13 Correct 9 ms 10764 KB Ok
14 Correct 8 ms 10764 KB Ok
15 Correct 8 ms 10764 KB Ok
16 Correct 8 ms 10764 KB Ok
17 Correct 8 ms 10764 KB Ok
18 Correct 8 ms 10764 KB Ok
19 Correct 9 ms 10764 KB Ok
20 Correct 8 ms 10764 KB Ok
21 Correct 9 ms 10764 KB Ok
22 Correct 10 ms 10764 KB Ok
23 Correct 8 ms 10764 KB Ok
24 Correct 14 ms 21960 KB Ok
25 Correct 14 ms 21960 KB Ok
26 Correct 15 ms 21960 KB Ok
27 Correct 13 ms 21960 KB Ok
28 Correct 12 ms 21960 KB Ok
29 Correct 12 ms 21960 KB Ok
30 Correct 13 ms 21960 KB Ok
31 Correct 13 ms 21960 KB Ok
32 Correct 13 ms 21960 KB Ok
33 Correct 18 ms 21960 KB Ok
34 Correct 23 ms 21960 KB Ok
35 Correct 20 ms 21960 KB Ok
36 Correct 19 ms 21960 KB Ok
37 Correct 19 ms 21960 KB Ok
38 Correct 19 ms 21960 KB Ok
39 Correct 18 ms 21960 KB Ok
40 Correct 22 ms 21960 KB Ok
41 Correct 19 ms 21960 KB Ok
42 Correct 19 ms 21960 KB Ok
43 Correct 26 ms 21960 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9824 KB Ok
3 Correct 9 ms 9896 KB Ok
4 Correct 9 ms 9896 KB Ok
5 Correct 9 ms 9896 KB Ok
6 Correct 9 ms 9904 KB Ok
7 Correct 9 ms 9904 KB Ok
8 Correct 9 ms 10008 KB Ok
9 Correct 9 ms 10008 KB Ok
10 Correct 9 ms 10008 KB Ok
11 Correct 8 ms 10008 KB Ok
12 Correct 9 ms 10008 KB Ok
13 Correct 11 ms 10008 KB Ok
14 Correct 9 ms 10008 KB Ok
15 Correct 9 ms 10008 KB Ok
16 Correct 9 ms 10008 KB Ok
17 Correct 9 ms 10008 KB Ok
18 Correct 15 ms 10220 KB Ok
19 Correct 39 ms 10604 KB Ok
20 Correct 25 ms 10604 KB Ok
21 Correct 45 ms 10764 KB Ok
22 Correct 28 ms 10764 KB Ok
23 Correct 9 ms 10764 KB Ok
24 Correct 8 ms 10764 KB Ok
25 Correct 8 ms 10764 KB Ok
26 Correct 8 ms 10764 KB Ok
27 Correct 8 ms 10764 KB Ok
28 Correct 8 ms 10764 KB Ok
29 Correct 9 ms 10764 KB Ok
30 Correct 8 ms 10764 KB Ok
31 Correct 9 ms 10764 KB Ok
32 Correct 10 ms 10764 KB Ok
33 Correct 8 ms 10764 KB Ok
34 Correct 14 ms 21960 KB Ok
35 Correct 14 ms 21960 KB Ok
36 Correct 15 ms 21960 KB Ok
37 Correct 13 ms 21960 KB Ok
38 Correct 12 ms 21960 KB Ok
39 Correct 12 ms 21960 KB Ok
40 Correct 13 ms 21960 KB Ok
41 Correct 13 ms 21960 KB Ok
42 Correct 13 ms 21960 KB Ok
43 Correct 18 ms 21960 KB Ok
44 Correct 23 ms 21960 KB Ok
45 Correct 20 ms 21960 KB Ok
46 Correct 19 ms 21960 KB Ok
47 Correct 19 ms 21960 KB Ok
48 Correct 19 ms 21960 KB Ok
49 Correct 18 ms 21960 KB Ok
50 Correct 22 ms 21960 KB Ok
51 Correct 19 ms 21960 KB Ok
52 Correct 19 ms 21960 KB Ok
53 Correct 26 ms 21960 KB Ok
54 Correct 265 ms 21960 KB Ok
55 Correct 333 ms 21960 KB Ok
56 Correct 300 ms 21960 KB Ok
57 Correct 231 ms 21960 KB Ok
58 Correct 263 ms 21960 KB Ok
59 Correct 287 ms 21960 KB Ok
60 Correct 215 ms 21960 KB Ok
61 Correct 213 ms 21960 KB Ok
62 Correct 316 ms 21960 KB Ok
63 Correct 224 ms 21960 KB Ok
64 Correct 291 ms 21960 KB Ok
65 Correct 289 ms 21960 KB Ok
66 Correct 244 ms 21960 KB Ok
67 Correct 201 ms 21960 KB Ok
68 Correct 285 ms 21960 KB Ok
69 Correct 582 ms 21960 KB Ok
70 Correct 583 ms 21960 KB Ok
71 Correct 556 ms 21960 KB Ok
72 Correct 592 ms 21960 KB Ok
73 Correct 530 ms 21960 KB Ok
74 Correct 518 ms 21960 KB Ok
75 Correct 533 ms 21960 KB Ok
76 Correct 634 ms 21960 KB Ok
77 Correct 515 ms 21960 KB Ok
78 Correct 576 ms 21960 KB Ok
79 Correct 570 ms 21960 KB Ok
80 Correct 516 ms 21960 KB Ok
81 Correct 550 ms 21960 KB Ok
82 Correct 555 ms 21960 KB Ok
83 Correct 528 ms 21960 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9720 KB Ok
2 Correct 9 ms 9824 KB Ok
3 Correct 9 ms 9896 KB Ok
4 Correct 9 ms 9896 KB Ok
5 Correct 9 ms 9896 KB Ok
6 Correct 9 ms 9904 KB Ok
7 Correct 9 ms 9904 KB Ok
8 Correct 9 ms 10008 KB Ok
9 Correct 9 ms 10008 KB Ok
10 Correct 9 ms 10008 KB Ok
11 Correct 8 ms 10008 KB Ok
12 Correct 9 ms 10008 KB Ok
13 Correct 11 ms 10008 KB Ok
14 Correct 9 ms 10008 KB Ok
15 Correct 9 ms 10008 KB Ok
16 Correct 9 ms 10008 KB Ok
17 Correct 9 ms 10008 KB Ok
18 Correct 15 ms 10220 KB Ok
19 Correct 39 ms 10604 KB Ok
20 Correct 25 ms 10604 KB Ok
21 Correct 45 ms 10764 KB Ok
22 Correct 28 ms 10764 KB Ok
23 Correct 9 ms 10764 KB Ok
24 Correct 8 ms 10764 KB Ok
25 Correct 8 ms 10764 KB Ok
26 Correct 8 ms 10764 KB Ok
27 Correct 8 ms 10764 KB Ok
28 Correct 8 ms 10764 KB Ok
29 Correct 9 ms 10764 KB Ok
30 Correct 8 ms 10764 KB Ok
31 Correct 9 ms 10764 KB Ok
32 Correct 10 ms 10764 KB Ok
33 Correct 8 ms 10764 KB Ok
34 Correct 10 ms 10764 KB Ok
35 Correct 10 ms 10764 KB Ok
36 Correct 9 ms 10764 KB Ok
37 Correct 9 ms 10764 KB Ok
38 Correct 10 ms 10764 KB Ok
39 Correct 382 ms 19388 KB Ok
40 Correct 383 ms 19964 KB Ok
41 Correct 645 ms 21960 KB Ok
42 Correct 442 ms 21960 KB Ok
43 Correct 266 ms 21960 KB Ok
44 Correct 457 ms 21960 KB Ok
45 Correct 14 ms 21960 KB Ok
46 Correct 14 ms 21960 KB Ok
47 Correct 15 ms 21960 KB Ok
48 Correct 13 ms 21960 KB Ok
49 Correct 12 ms 21960 KB Ok
50 Correct 12 ms 21960 KB Ok
51 Correct 13 ms 21960 KB Ok
52 Correct 13 ms 21960 KB Ok
53 Correct 13 ms 21960 KB Ok
54 Correct 18 ms 21960 KB Ok
55 Correct 23 ms 21960 KB Ok
56 Correct 20 ms 21960 KB Ok
57 Correct 19 ms 21960 KB Ok
58 Correct 19 ms 21960 KB Ok
59 Correct 19 ms 21960 KB Ok
60 Correct 18 ms 21960 KB Ok
61 Correct 22 ms 21960 KB Ok
62 Correct 19 ms 21960 KB Ok
63 Correct 19 ms 21960 KB Ok
64 Correct 26 ms 21960 KB Ok
65 Correct 265 ms 21960 KB Ok
66 Correct 333 ms 21960 KB Ok
67 Correct 300 ms 21960 KB Ok
68 Correct 231 ms 21960 KB Ok
69 Correct 263 ms 21960 KB Ok
70 Correct 287 ms 21960 KB Ok
71 Correct 215 ms 21960 KB Ok
72 Correct 213 ms 21960 KB Ok
73 Correct 316 ms 21960 KB Ok
74 Correct 224 ms 21960 KB Ok
75 Correct 291 ms 21960 KB Ok
76 Correct 289 ms 21960 KB Ok
77 Correct 244 ms 21960 KB Ok
78 Correct 201 ms 21960 KB Ok
79 Correct 285 ms 21960 KB Ok
80 Correct 582 ms 21960 KB Ok
81 Correct 583 ms 21960 KB Ok
82 Correct 556 ms 21960 KB Ok
83 Correct 592 ms 21960 KB Ok
84 Correct 530 ms 21960 KB Ok
85 Correct 518 ms 21960 KB Ok
86 Correct 533 ms 21960 KB Ok
87 Correct 634 ms 21960 KB Ok
88 Correct 515 ms 21960 KB Ok
89 Correct 576 ms 21960 KB Ok
90 Correct 570 ms 21960 KB Ok
91 Correct 516 ms 21960 KB Ok
92 Correct 550 ms 21960 KB Ok
93 Correct 555 ms 21960 KB Ok
94 Correct 528 ms 21960 KB Ok
95 Correct 667 ms 23080 KB Ok
96 Correct 1094 ms 29552 KB Ok
97 Correct 984 ms 29552 KB Ok
98 Correct 681 ms 29552 KB Ok
99 Correct 886 ms 29552 KB Ok
100 Correct 899 ms 29552 KB Ok
101 Correct 993 ms 29552 KB Ok
102 Correct 906 ms 29552 KB Ok
103 Correct 898 ms 29552 KB Ok
104 Correct 1075 ms 29552 KB Ok
105 Correct 1064 ms 29552 KB Ok
106 Correct 805 ms 29552 KB Ok
107 Correct 964 ms 29552 KB Ok
108 Correct 1162 ms 29552 KB Ok
109 Correct 1020 ms 29552 KB Ok
110 Execution timed out 2051 ms 31988 KB Time limit exceeded
111 Halted 0 ms 0 KB -