Submission #568989

# Submission time Handle Problem Language Result Execution time Memory
568989 2022-05-26T12:18:24 Z MilosMilutinovic Nice sequence (IZhO18_sequence) C++14
100 / 100
1419 ms 53252 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=400505;
int n,m,_,deg[N],v[N],t;
VI e[N];

void check(int x) {
	rep(i,0,x+1) deg[i]=0,e[i].clear();
	rep(i,n,x+1) {
		e[i].pb(i-n);
		deg[i-n]++;
	}
	rep(i,m,x+1) {
		e[i-m].pb(i);
		deg[i]++;
	}
	t=0;
	deque<int> q;
	rep(i,0,x+1) if (deg[i]==0) q.pb(i);
	while (!q.empty()) {
		int x=q[0];
		q.pop_front();
		v[x]=++t;
		for (int y:e[x]) {
			deg[y]--;
			if (deg[y]==0) q.pb(y);
		}
	}
	per(i,1,x+1) v[i]-=v[i-1];
	rep(i,1,x+1) printf("%d ",v[i]); printf("\n");
}
void solve() {
	scanf("%d%d",&n,&m);
	int ans=n+m-1-__gcd(n,m);
	printf("%d\n",ans);
	check(ans);
}

int main() {
	for (scanf("%d",&_);_;_--) {
		solve();
	}
	return 0;
}

Compilation message

sequence.cpp: In function 'void check(int)':
sequence.cpp:3:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define rep(i,a,n) for (int i=a;i<n;i++)
      |                    ^~~
sequence.cpp:51:2: note: in expansion of macro 'rep'
   51 |  rep(i,1,x+1) printf("%d ",v[i]); printf("\n");
      |  ^~~
sequence.cpp:51:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   51 |  rep(i,1,x+1) printf("%d ",v[i]); printf("\n");
      |                                   ^~~~~~
sequence.cpp: In function 'void solve()':
sequence.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:61:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  for (scanf("%d",&_);_;_--) {
      |       ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9712 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9720 KB Ok
5 Correct 6 ms 9724 KB Ok
6 Correct 6 ms 9684 KB Ok
7 Correct 6 ms 9716 KB Ok
8 Correct 6 ms 9720 KB Ok
9 Correct 7 ms 9684 KB Ok
10 Correct 7 ms 9716 KB Ok
11 Correct 6 ms 9720 KB Ok
12 Correct 6 ms 9684 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 6 ms 9684 KB Ok
3 Correct 6 ms 9720 KB Ok
4 Correct 6 ms 9720 KB Ok
5 Correct 6 ms 9684 KB Ok
6 Correct 10 ms 9812 KB Ok
7 Correct 15 ms 10324 KB Ok
8 Correct 10 ms 9940 KB Ok
9 Correct 18 ms 10436 KB Ok
10 Correct 12 ms 10104 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9684 KB Ok
5 Correct 6 ms 9708 KB Ok
6 Correct 5 ms 9684 KB Ok
7 Correct 5 ms 9676 KB Ok
8 Correct 5 ms 9716 KB Ok
9 Correct 6 ms 9684 KB Ok
10 Correct 7 ms 9684 KB Ok
11 Correct 6 ms 9684 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 6 ms 9684 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 6 ms 9684 KB Ok
5 Correct 5 ms 9724 KB Ok
6 Correct 95 ms 18872 KB Ok
7 Correct 88 ms 19432 KB Ok
8 Correct 153 ms 21580 KB Ok
9 Correct 130 ms 20852 KB Ok
10 Correct 74 ms 15924 KB Ok
11 Correct 117 ms 20880 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9712 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9720 KB Ok
5 Correct 6 ms 9724 KB Ok
6 Correct 6 ms 9684 KB Ok
7 Correct 6 ms 9716 KB Ok
8 Correct 6 ms 9720 KB Ok
9 Correct 7 ms 9684 KB Ok
10 Correct 7 ms 9716 KB Ok
11 Correct 6 ms 9720 KB Ok
12 Correct 6 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 5 ms 9684 KB Ok
15 Correct 5 ms 9684 KB Ok
16 Correct 5 ms 9684 KB Ok
17 Correct 6 ms 9708 KB Ok
18 Correct 5 ms 9684 KB Ok
19 Correct 5 ms 9676 KB Ok
20 Correct 5 ms 9716 KB Ok
21 Correct 6 ms 9684 KB Ok
22 Correct 7 ms 9684 KB Ok
23 Correct 6 ms 9684 KB Ok
24 Correct 7 ms 9844 KB Ok
25 Correct 7 ms 9812 KB Ok
26 Correct 8 ms 9852 KB Ok
27 Correct 8 ms 9852 KB Ok
28 Correct 8 ms 9852 KB Ok
29 Correct 7 ms 9848 KB Ok
30 Correct 8 ms 9812 KB Ok
31 Correct 7 ms 9812 KB Ok
32 Correct 8 ms 9812 KB Ok
33 Correct 8 ms 9848 KB Ok
34 Correct 9 ms 9972 KB Ok
35 Correct 10 ms 9976 KB Ok
36 Correct 9 ms 9968 KB Ok
37 Correct 9 ms 9972 KB Ok
38 Correct 10 ms 9940 KB Ok
39 Correct 9 ms 9940 KB Ok
40 Correct 12 ms 10016 KB Ok
41 Correct 9 ms 9940 KB Ok
42 Correct 9 ms 9968 KB Ok
43 Correct 9 ms 9940 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9712 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9720 KB Ok
5 Correct 6 ms 9724 KB Ok
6 Correct 6 ms 9684 KB Ok
7 Correct 6 ms 9716 KB Ok
8 Correct 6 ms 9720 KB Ok
9 Correct 7 ms 9684 KB Ok
10 Correct 7 ms 9716 KB Ok
11 Correct 6 ms 9720 KB Ok
12 Correct 6 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 6 ms 9684 KB Ok
15 Correct 6 ms 9720 KB Ok
16 Correct 6 ms 9720 KB Ok
17 Correct 6 ms 9684 KB Ok
18 Correct 10 ms 9812 KB Ok
19 Correct 15 ms 10324 KB Ok
20 Correct 10 ms 9940 KB Ok
21 Correct 18 ms 10436 KB Ok
22 Correct 12 ms 10104 KB Ok
23 Correct 5 ms 9684 KB Ok
24 Correct 5 ms 9684 KB Ok
25 Correct 5 ms 9684 KB Ok
26 Correct 5 ms 9684 KB Ok
27 Correct 6 ms 9708 KB Ok
28 Correct 5 ms 9684 KB Ok
29 Correct 5 ms 9676 KB Ok
30 Correct 5 ms 9716 KB Ok
31 Correct 6 ms 9684 KB Ok
32 Correct 7 ms 9684 KB Ok
33 Correct 6 ms 9684 KB Ok
34 Correct 7 ms 9844 KB Ok
35 Correct 7 ms 9812 KB Ok
36 Correct 8 ms 9852 KB Ok
37 Correct 8 ms 9852 KB Ok
38 Correct 8 ms 9852 KB Ok
39 Correct 7 ms 9848 KB Ok
40 Correct 8 ms 9812 KB Ok
41 Correct 7 ms 9812 KB Ok
42 Correct 8 ms 9812 KB Ok
43 Correct 8 ms 9848 KB Ok
44 Correct 9 ms 9972 KB Ok
45 Correct 10 ms 9976 KB Ok
46 Correct 9 ms 9968 KB Ok
47 Correct 9 ms 9972 KB Ok
48 Correct 10 ms 9940 KB Ok
49 Correct 9 ms 9940 KB Ok
50 Correct 12 ms 10016 KB Ok
51 Correct 9 ms 9940 KB Ok
52 Correct 9 ms 9968 KB Ok
53 Correct 9 ms 9940 KB Ok
54 Correct 75 ms 14816 KB Ok
55 Correct 88 ms 14796 KB Ok
56 Correct 79 ms 15028 KB Ok
57 Correct 67 ms 14368 KB Ok
58 Correct 95 ms 14740 KB Ok
59 Correct 77 ms 14588 KB Ok
60 Correct 62 ms 14080 KB Ok
61 Correct 67 ms 14680 KB Ok
62 Correct 83 ms 14932 KB Ok
63 Correct 69 ms 14284 KB Ok
64 Correct 80 ms 14740 KB Ok
65 Correct 77 ms 14776 KB Ok
66 Correct 80 ms 14608 KB Ok
67 Correct 60 ms 14296 KB Ok
68 Correct 71 ms 14804 KB Ok
69 Correct 178 ms 18904 KB Ok
70 Correct 185 ms 20212 KB Ok
71 Correct 161 ms 18152 KB Ok
72 Correct 177 ms 19260 KB Ok
73 Correct 182 ms 18636 KB Ok
74 Correct 149 ms 17624 KB Ok
75 Correct 171 ms 17720 KB Ok
76 Correct 207 ms 19756 KB Ok
77 Correct 136 ms 17236 KB Ok
78 Correct 257 ms 19668 KB Ok
79 Correct 177 ms 18940 KB Ok
80 Correct 164 ms 18604 KB Ok
81 Correct 204 ms 19288 KB Ok
82 Correct 178 ms 18888 KB Ok
83 Correct 140 ms 17828 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Ok
2 Correct 5 ms 9712 KB Ok
3 Correct 5 ms 9684 KB Ok
4 Correct 5 ms 9720 KB Ok
5 Correct 6 ms 9724 KB Ok
6 Correct 6 ms 9684 KB Ok
7 Correct 6 ms 9716 KB Ok
8 Correct 6 ms 9720 KB Ok
9 Correct 7 ms 9684 KB Ok
10 Correct 7 ms 9716 KB Ok
11 Correct 6 ms 9720 KB Ok
12 Correct 6 ms 9684 KB Ok
13 Correct 5 ms 9684 KB Ok
14 Correct 6 ms 9684 KB Ok
15 Correct 6 ms 9720 KB Ok
16 Correct 6 ms 9720 KB Ok
17 Correct 6 ms 9684 KB Ok
18 Correct 10 ms 9812 KB Ok
19 Correct 15 ms 10324 KB Ok
20 Correct 10 ms 9940 KB Ok
21 Correct 18 ms 10436 KB Ok
22 Correct 12 ms 10104 KB Ok
23 Correct 5 ms 9684 KB Ok
24 Correct 5 ms 9684 KB Ok
25 Correct 5 ms 9684 KB Ok
26 Correct 5 ms 9684 KB Ok
27 Correct 6 ms 9708 KB Ok
28 Correct 5 ms 9684 KB Ok
29 Correct 5 ms 9676 KB Ok
30 Correct 5 ms 9716 KB Ok
31 Correct 6 ms 9684 KB Ok
32 Correct 7 ms 9684 KB Ok
33 Correct 6 ms 9684 KB Ok
34 Correct 5 ms 9684 KB Ok
35 Correct 6 ms 9684 KB Ok
36 Correct 5 ms 9684 KB Ok
37 Correct 6 ms 9684 KB Ok
38 Correct 5 ms 9724 KB Ok
39 Correct 95 ms 18872 KB Ok
40 Correct 88 ms 19432 KB Ok
41 Correct 153 ms 21580 KB Ok
42 Correct 130 ms 20852 KB Ok
43 Correct 74 ms 15924 KB Ok
44 Correct 117 ms 20880 KB Ok
45 Correct 7 ms 9844 KB Ok
46 Correct 7 ms 9812 KB Ok
47 Correct 8 ms 9852 KB Ok
48 Correct 8 ms 9852 KB Ok
49 Correct 8 ms 9852 KB Ok
50 Correct 7 ms 9848 KB Ok
51 Correct 8 ms 9812 KB Ok
52 Correct 7 ms 9812 KB Ok
53 Correct 8 ms 9812 KB Ok
54 Correct 8 ms 9848 KB Ok
55 Correct 9 ms 9972 KB Ok
56 Correct 10 ms 9976 KB Ok
57 Correct 9 ms 9968 KB Ok
58 Correct 9 ms 9972 KB Ok
59 Correct 10 ms 9940 KB Ok
60 Correct 9 ms 9940 KB Ok
61 Correct 12 ms 10016 KB Ok
62 Correct 9 ms 9940 KB Ok
63 Correct 9 ms 9968 KB Ok
64 Correct 9 ms 9940 KB Ok
65 Correct 75 ms 14816 KB Ok
66 Correct 88 ms 14796 KB Ok
67 Correct 79 ms 15028 KB Ok
68 Correct 67 ms 14368 KB Ok
69 Correct 95 ms 14740 KB Ok
70 Correct 77 ms 14588 KB Ok
71 Correct 62 ms 14080 KB Ok
72 Correct 67 ms 14680 KB Ok
73 Correct 83 ms 14932 KB Ok
74 Correct 69 ms 14284 KB Ok
75 Correct 80 ms 14740 KB Ok
76 Correct 77 ms 14776 KB Ok
77 Correct 80 ms 14608 KB Ok
78 Correct 60 ms 14296 KB Ok
79 Correct 71 ms 14804 KB Ok
80 Correct 178 ms 18904 KB Ok
81 Correct 185 ms 20212 KB Ok
82 Correct 161 ms 18152 KB Ok
83 Correct 177 ms 19260 KB Ok
84 Correct 182 ms 18636 KB Ok
85 Correct 149 ms 17624 KB Ok
86 Correct 171 ms 17720 KB Ok
87 Correct 207 ms 19756 KB Ok
88 Correct 136 ms 17236 KB Ok
89 Correct 257 ms 19668 KB Ok
90 Correct 177 ms 18940 KB Ok
91 Correct 164 ms 18604 KB Ok
92 Correct 204 ms 19288 KB Ok
93 Correct 178 ms 18888 KB Ok
94 Correct 140 ms 17828 KB Ok
95 Correct 183 ms 22932 KB Ok
96 Correct 247 ms 29244 KB Ok
97 Correct 254 ms 25832 KB Ok
98 Correct 186 ms 26128 KB Ok
99 Correct 220 ms 25384 KB Ok
100 Correct 219 ms 24756 KB Ok
101 Correct 227 ms 27708 KB Ok
102 Correct 226 ms 25464 KB Ok
103 Correct 220 ms 26628 KB Ok
104 Correct 262 ms 28388 KB Ok
105 Correct 246 ms 28192 KB Ok
106 Correct 210 ms 28520 KB Ok
107 Correct 226 ms 27732 KB Ok
108 Correct 254 ms 28104 KB Ok
109 Correct 246 ms 29204 KB Ok
110 Correct 836 ms 43260 KB Ok
111 Correct 1348 ms 53252 KB Ok
112 Correct 981 ms 45320 KB Ok
113 Correct 1127 ms 49476 KB Ok
114 Correct 1146 ms 50848 KB Ok
115 Correct 1325 ms 50268 KB Ok
116 Correct 1169 ms 49828 KB Ok
117 Correct 1317 ms 50596 KB Ok
118 Correct 1020 ms 46160 KB Ok
119 Correct 1419 ms 51588 KB Ok
120 Correct 1105 ms 46416 KB Ok
121 Correct 1010 ms 45328 KB Ok
122 Correct 1054 ms 48168 KB Ok
123 Correct 1373 ms 52892 KB Ok
124 Correct 801 ms 42240 KB Ok
125 Correct 435 ms 35592 KB Ok