Submission #40456

# Submission time Handle Problem Language Result Execution time Memory
40456 2018-02-01T17:16:56 Z Pajaraja Nice sequence (IZhO18_sequence) C++14
100 / 100
1612 ms 52904 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> g[400007];
int pv[400007],deg[400007],parc[400007];
int nzd(int a,int b)
{
	if(a==0) return b;
	return nzd(b%a,a);
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,m;
		scanf("%d%d",&n,&m);
		int x=m+n-1-nzd(m,n);
		printf("%d\n",x);
		fill(deg,deg+x+1,0);
	    for(int i=0;i<=x;i++) g[i].clear();
	    for(int i=n;i<=x;i++) 
	    {
	        g[i].push_back(i-n);
	        deg[i-n]++;
	    }
	    for(int i=m;i<=x;i++)
	    {
		    g[i-m].push_back(i);
		    deg[i]++;
	    }
	    queue<int> q;
	    for(int i=0;i<=x;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]);
			}
		}
		for(int i=1;i<=x;i++) printf("%d ",pv[i]-pv[i-1]);
		printf("\n");
	}
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:40:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<g[u].size();i++) 
                 ^
sequence.cpp:13:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&t);
                ^
sequence.cpp:17: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 8 ms 9720 KB Ok
2 Correct 8 ms 9824 KB Ok
3 Correct 9 ms 9904 KB Ok
4 Correct 8 ms 9904 KB Ok
5 Correct 11 ms 9904 KB Ok
6 Correct 9 ms 9920 KB Ok
7 Correct 9 ms 9920 KB Ok
8 Correct 8 ms 9988 KB Ok
9 Correct 9 ms 9988 KB Ok
10 Correct 9 ms 9988 KB Ok
11 Correct 8 ms 9988 KB Ok
12 Correct 9 ms 9988 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9988 KB Ok
2 Correct 9 ms 9988 KB Ok
3 Correct 9 ms 9988 KB Ok
4 Correct 9 ms 9988 KB Ok
5 Correct 9 ms 9988 KB Ok
6 Correct 12 ms 10092 KB Ok
7 Correct 20 ms 10604 KB Ok
8 Correct 16 ms 10604 KB Ok
9 Correct 21 ms 10764 KB Ok
10 Correct 15 ms 10764 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 8 ms 10764 KB Ok
2 Correct 8 ms 10764 KB Ok
3 Correct 8 ms 10764 KB Ok
4 Correct 9 ms 10764 KB Ok
5 Correct 9 ms 10764 KB Ok
6 Correct 8 ms 10764 KB Ok
7 Correct 10 ms 10764 KB Ok
8 Correct 9 ms 10764 KB Ok
9 Correct 9 ms 10764 KB Ok
10 Correct 9 ms 10764 KB Ok
11 Correct 9 ms 10764 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10764 KB Ok
2 Correct 9 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 128 ms 19228 KB Ok
7 Correct 103 ms 19880 KB Ok
8 Correct 239 ms 21700 KB Ok
9 Correct 140 ms 21700 KB Ok
10 Correct 90 ms 21700 KB Ok
11 Correct 175 ms 21700 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9720 KB Ok
2 Correct 8 ms 9824 KB Ok
3 Correct 9 ms 9904 KB Ok
4 Correct 8 ms 9904 KB Ok
5 Correct 11 ms 9904 KB Ok
6 Correct 9 ms 9920 KB Ok
7 Correct 9 ms 9920 KB Ok
8 Correct 8 ms 9988 KB Ok
9 Correct 9 ms 9988 KB Ok
10 Correct 9 ms 9988 KB Ok
11 Correct 8 ms 9988 KB Ok
12 Correct 9 ms 9988 KB Ok
13 Correct 8 ms 10764 KB Ok
14 Correct 8 ms 10764 KB Ok
15 Correct 8 ms 10764 KB Ok
16 Correct 9 ms 10764 KB Ok
17 Correct 9 ms 10764 KB Ok
18 Correct 8 ms 10764 KB Ok
19 Correct 10 ms 10764 KB Ok
20 Correct 9 ms 10764 KB Ok
21 Correct 9 ms 10764 KB Ok
22 Correct 9 ms 10764 KB Ok
23 Correct 9 ms 10764 KB Ok
24 Correct 11 ms 21700 KB Ok
25 Correct 11 ms 21700 KB Ok
26 Correct 10 ms 21700 KB Ok
27 Correct 10 ms 21700 KB Ok
28 Correct 10 ms 21700 KB Ok
29 Correct 10 ms 21700 KB Ok
30 Correct 10 ms 21700 KB Ok
31 Correct 10 ms 21700 KB Ok
32 Correct 10 ms 21700 KB Ok
33 Correct 10 ms 21700 KB Ok
34 Correct 12 ms 21700 KB Ok
35 Correct 13 ms 21700 KB Ok
36 Correct 13 ms 21700 KB Ok
37 Correct 13 ms 21700 KB Ok
38 Correct 14 ms 21700 KB Ok
39 Correct 13 ms 21700 KB Ok
40 Correct 18 ms 21700 KB Ok
41 Correct 13 ms 21700 KB Ok
42 Correct 13 ms 21700 KB Ok
43 Correct 13 ms 21700 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9720 KB Ok
2 Correct 8 ms 9824 KB Ok
3 Correct 9 ms 9904 KB Ok
4 Correct 8 ms 9904 KB Ok
5 Correct 11 ms 9904 KB Ok
6 Correct 9 ms 9920 KB Ok
7 Correct 9 ms 9920 KB Ok
8 Correct 8 ms 9988 KB Ok
9 Correct 9 ms 9988 KB Ok
10 Correct 9 ms 9988 KB Ok
11 Correct 8 ms 9988 KB Ok
12 Correct 9 ms 9988 KB Ok
13 Correct 9 ms 9988 KB Ok
14 Correct 9 ms 9988 KB Ok
15 Correct 9 ms 9988 KB Ok
16 Correct 9 ms 9988 KB Ok
17 Correct 9 ms 9988 KB Ok
18 Correct 12 ms 10092 KB Ok
19 Correct 20 ms 10604 KB Ok
20 Correct 16 ms 10604 KB Ok
21 Correct 21 ms 10764 KB Ok
22 Correct 15 ms 10764 KB Ok
23 Correct 8 ms 10764 KB Ok
24 Correct 8 ms 10764 KB Ok
25 Correct 8 ms 10764 KB Ok
26 Correct 9 ms 10764 KB Ok
27 Correct 9 ms 10764 KB Ok
28 Correct 8 ms 10764 KB Ok
29 Correct 10 ms 10764 KB Ok
30 Correct 9 ms 10764 KB Ok
31 Correct 9 ms 10764 KB Ok
32 Correct 9 ms 10764 KB Ok
33 Correct 9 ms 10764 KB Ok
34 Correct 11 ms 21700 KB Ok
35 Correct 11 ms 21700 KB Ok
36 Correct 10 ms 21700 KB Ok
37 Correct 10 ms 21700 KB Ok
38 Correct 10 ms 21700 KB Ok
39 Correct 10 ms 21700 KB Ok
40 Correct 10 ms 21700 KB Ok
41 Correct 10 ms 21700 KB Ok
42 Correct 10 ms 21700 KB Ok
43 Correct 10 ms 21700 KB Ok
44 Correct 12 ms 21700 KB Ok
45 Correct 13 ms 21700 KB Ok
46 Correct 13 ms 21700 KB Ok
47 Correct 13 ms 21700 KB Ok
48 Correct 14 ms 21700 KB Ok
49 Correct 13 ms 21700 KB Ok
50 Correct 18 ms 21700 KB Ok
51 Correct 13 ms 21700 KB Ok
52 Correct 13 ms 21700 KB Ok
53 Correct 13 ms 21700 KB Ok
54 Correct 87 ms 21700 KB Ok
55 Correct 97 ms 21700 KB Ok
56 Correct 91 ms 21700 KB Ok
57 Correct 69 ms 21700 KB Ok
58 Correct 88 ms 21700 KB Ok
59 Correct 81 ms 21700 KB Ok
60 Correct 97 ms 21700 KB Ok
61 Correct 71 ms 21700 KB Ok
62 Correct 99 ms 21700 KB Ok
63 Correct 82 ms 21700 KB Ok
64 Correct 94 ms 21700 KB Ok
65 Correct 99 ms 21700 KB Ok
66 Correct 83 ms 21700 KB Ok
67 Correct 72 ms 21700 KB Ok
68 Correct 99 ms 21700 KB Ok
69 Correct 189 ms 21700 KB Ok
70 Correct 193 ms 21700 KB Ok
71 Correct 180 ms 21700 KB Ok
72 Correct 176 ms 21700 KB Ok
73 Correct 170 ms 21700 KB Ok
74 Correct 146 ms 21700 KB Ok
75 Correct 155 ms 21700 KB Ok
76 Correct 181 ms 21700 KB Ok
77 Correct 138 ms 21700 KB Ok
78 Correct 213 ms 21700 KB Ok
79 Correct 180 ms 21700 KB Ok
80 Correct 168 ms 21700 KB Ok
81 Correct 170 ms 21700 KB Ok
82 Correct 171 ms 21700 KB Ok
83 Correct 151 ms 21700 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9720 KB Ok
2 Correct 8 ms 9824 KB Ok
3 Correct 9 ms 9904 KB Ok
4 Correct 8 ms 9904 KB Ok
5 Correct 11 ms 9904 KB Ok
6 Correct 9 ms 9920 KB Ok
7 Correct 9 ms 9920 KB Ok
8 Correct 8 ms 9988 KB Ok
9 Correct 9 ms 9988 KB Ok
10 Correct 9 ms 9988 KB Ok
11 Correct 8 ms 9988 KB Ok
12 Correct 9 ms 9988 KB Ok
13 Correct 9 ms 9988 KB Ok
14 Correct 9 ms 9988 KB Ok
15 Correct 9 ms 9988 KB Ok
16 Correct 9 ms 9988 KB Ok
17 Correct 9 ms 9988 KB Ok
18 Correct 12 ms 10092 KB Ok
19 Correct 20 ms 10604 KB Ok
20 Correct 16 ms 10604 KB Ok
21 Correct 21 ms 10764 KB Ok
22 Correct 15 ms 10764 KB Ok
23 Correct 8 ms 10764 KB Ok
24 Correct 8 ms 10764 KB Ok
25 Correct 8 ms 10764 KB Ok
26 Correct 9 ms 10764 KB Ok
27 Correct 9 ms 10764 KB Ok
28 Correct 8 ms 10764 KB Ok
29 Correct 10 ms 10764 KB Ok
30 Correct 9 ms 10764 KB Ok
31 Correct 9 ms 10764 KB Ok
32 Correct 9 ms 10764 KB Ok
33 Correct 9 ms 10764 KB Ok
34 Correct 9 ms 10764 KB Ok
35 Correct 9 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 128 ms 19228 KB Ok
40 Correct 103 ms 19880 KB Ok
41 Correct 239 ms 21700 KB Ok
42 Correct 140 ms 21700 KB Ok
43 Correct 90 ms 21700 KB Ok
44 Correct 175 ms 21700 KB Ok
45 Correct 11 ms 21700 KB Ok
46 Correct 11 ms 21700 KB Ok
47 Correct 10 ms 21700 KB Ok
48 Correct 10 ms 21700 KB Ok
49 Correct 10 ms 21700 KB Ok
50 Correct 10 ms 21700 KB Ok
51 Correct 10 ms 21700 KB Ok
52 Correct 10 ms 21700 KB Ok
53 Correct 10 ms 21700 KB Ok
54 Correct 10 ms 21700 KB Ok
55 Correct 12 ms 21700 KB Ok
56 Correct 13 ms 21700 KB Ok
57 Correct 13 ms 21700 KB Ok
58 Correct 13 ms 21700 KB Ok
59 Correct 14 ms 21700 KB Ok
60 Correct 13 ms 21700 KB Ok
61 Correct 18 ms 21700 KB Ok
62 Correct 13 ms 21700 KB Ok
63 Correct 13 ms 21700 KB Ok
64 Correct 13 ms 21700 KB Ok
65 Correct 87 ms 21700 KB Ok
66 Correct 97 ms 21700 KB Ok
67 Correct 91 ms 21700 KB Ok
68 Correct 69 ms 21700 KB Ok
69 Correct 88 ms 21700 KB Ok
70 Correct 81 ms 21700 KB Ok
71 Correct 97 ms 21700 KB Ok
72 Correct 71 ms 21700 KB Ok
73 Correct 99 ms 21700 KB Ok
74 Correct 82 ms 21700 KB Ok
75 Correct 94 ms 21700 KB Ok
76 Correct 99 ms 21700 KB Ok
77 Correct 83 ms 21700 KB Ok
78 Correct 72 ms 21700 KB Ok
79 Correct 99 ms 21700 KB Ok
80 Correct 189 ms 21700 KB Ok
81 Correct 193 ms 21700 KB Ok
82 Correct 180 ms 21700 KB Ok
83 Correct 176 ms 21700 KB Ok
84 Correct 170 ms 21700 KB Ok
85 Correct 146 ms 21700 KB Ok
86 Correct 155 ms 21700 KB Ok
87 Correct 181 ms 21700 KB Ok
88 Correct 138 ms 21700 KB Ok
89 Correct 213 ms 21700 KB Ok
90 Correct 180 ms 21700 KB Ok
91 Correct 168 ms 21700 KB Ok
92 Correct 170 ms 21700 KB Ok
93 Correct 171 ms 21700 KB Ok
94 Correct 151 ms 21700 KB Ok
95 Correct 194 ms 23136 KB Ok
96 Correct 286 ms 29544 KB Ok
97 Correct 283 ms 29544 KB Ok
98 Correct 226 ms 29544 KB Ok
99 Correct 257 ms 29544 KB Ok
100 Correct 256 ms 29544 KB Ok
101 Correct 289 ms 29544 KB Ok
102 Correct 241 ms 29544 KB Ok
103 Correct 252 ms 29544 KB Ok
104 Correct 315 ms 29544 KB Ok
105 Correct 328 ms 29544 KB Ok
106 Correct 257 ms 29544 KB Ok
107 Correct 269 ms 29544 KB Ok
108 Correct 301 ms 29544 KB Ok
109 Correct 275 ms 29544 KB Ok
110 Correct 969 ms 43332 KB Ok
111 Correct 1469 ms 52808 KB Ok
112 Correct 1214 ms 52808 KB Ok
113 Correct 1416 ms 52808 KB Ok
114 Correct 1421 ms 52808 KB Ok
115 Correct 1554 ms 52808 KB Ok
116 Correct 1362 ms 52808 KB Ok
117 Correct 1327 ms 52808 KB Ok
118 Correct 1136 ms 52808 KB Ok
119 Correct 1387 ms 52808 KB Ok
120 Correct 1183 ms 52808 KB Ok
121 Correct 1227 ms 52808 KB Ok
122 Correct 1196 ms 52808 KB Ok
123 Correct 1612 ms 52904 KB Ok
124 Correct 1043 ms 52904 KB Ok
125 Correct 525 ms 52904 KB Ok