QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646961#508. Nice sequencesyxsyx15 5ms5972kbC++141.4kb2024-10-17 10:30:592024-10-17 10:30:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 10:30:59]
  • 评测
  • 测评结果:15
  • 用时:5ms
  • 内存:5972kb
  • [2024-10-17 10:30:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=200005,V=5e8;
int T;
int n,m;
bool tag;
int gcd(int x,int y)
{
	if(y==0) return x;
	return gcd(y,x%y);
}
int res[N];
long long sum[N];
bool check(int len)
{
	for(int i=1;i<=len;i++) sum[i]=sum[i-1]+res[i];
	for(int i=0;i<=len-n;i++) if(sum[i+n]-sum[i]>=0) return false;
//	for(int i=0;i<=len-m;i++) if(sum[i+m]-sum[i]<=0) return false;
	return true;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		if(n==m)
		{
			printf("%d\n",n-1);
			for(int i=1;i<n;i++) printf("1 ");
			printf("\n");
			continue;
		}
		if(n>m) swap(n,m),tag=1;
		else tag=0;
		int g=gcd(n,m);
		int len=n+m-g-1;
		printf("%d\n",len);
		if(n==g)
		{
			for(int i=1;i<=len;i++) res[i]=-1;
		}
		else
		{
			int lim=V/len;
			int val1=lim*(n-1)-1;
			int val2=val1*2-lim*(n-3)+1;
			int nowl=len-m+1;
			int nowr=m;
			for(int i=1;i<=n+m-1;i++) res[i]=-lim;
			if((nowr-nowl)%n==0)
			{
				for(int i=nowl;i<=nowr;i+=n) res[i]=val1;
			}
			else
			{
				for(int i=nowl;i<=len;i+=n) res[i]=val1;
				for(int i=nowr;i>=1;i-=n) res[i]=val1;
				for(int i=nowl+1;i<=len;i+=n) res[i]=-val2;
			}
		}
//		for(int i=1;i<=len;i++) printf("%d ",res[i]);
//		printf("\n");
//		assert(check(len));
		if(tag) for(int i=1;i<=len;i++) res[i]=-res[i];
		for(int i=1;i<=len;i++) printf("%d ",res[i]);
		printf("\n");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 1ms
memory: 3896kb

input:

3
3 1
2 3
1 1

output:

2
1 1 
3
166666665 -166666666 166666665 
0


result:

ok Ok

Test #2:

score: 6
Accepted
time: 1ms
memory: 3920kb

input:

10
1 1
1 2
1 3
1 4
1 5
6 1
7 1
8 1
9 1
100 1

output:

0

1
-1 
2
-1 -1 
3
-1 -1 -1 
4
-1 -1 -1 -1 
5
1 1 1 1 1 
6
1 1 1 1 1 1 
7
1 1 1 1 1 1 1 
8
1 1 1 1 1 1 1 1 
99
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok Ok

Test #3:

score: 6
Accepted
time: 0ms
memory: 3964kb

input:

10
60 1
70 1
1 60
1 70
1 50
39 1
41 1
23 1
1 99
87 3

output:

59
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
69
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
59
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

result:

ok Ok

Test #4:

score: 6
Accepted
time: 0ms
memory: 3832kb

input:

10
94 94
27 54
31 31
28 28
76 76
35 35
89 89
57 57
90 18
13 39

output:

93
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
53
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

result:

ok Ok

Test #5:

score: 6
Accepted
time: 0ms
memory: 3924kb

input:

10
67 67
64 64
82 82
16 96
74 74
37 37
90 90
59 59
66 66
14 7

output:

66
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
63
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
81
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok Ok

Test #6:

score: 6
Accepted
time: 0ms
memory: 3960kb

input:

10
49 98
15 90
14 56
54 18
67 67
50 100
90 90
85 85
94 94
65 65

output:

97
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
89
-1...

result:

ok Ok

Test #7:

score: 6
Accepted
time: 0ms
memory: 3904kb

input:

10
19 19
77 77
85 17
4 4
80 80
98 98
94 94
100 100
88 22
77 77

output:

18
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
76
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
84
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok Ok

Test #8:

score: 6
Accepted
time: 0ms
memory: 3904kb

input:

10
36 36
21 84
51 51
72 24
88 44
29 29
20 20
67 67
82 82
92 92

output:

35
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
83
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

result:

ok Ok

Test #9:

score: 6
Accepted
time: 0ms
memory: 3780kb

input:

10
4 12
95 95
59 59
48 48
23 23
76 76
35 5
97 97
89 89
58 58

output:

11
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
94
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
58
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok Ok

Test #10:

score: 6
Accepted
time: 1ms
memory: 5828kb

input:

10
74 74
71 71
95 95
90 15
35 35
88 88
58 58
49 98
84 84
67 67

output:

73
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
70
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
94
1 1...

result:

ok Ok

Test #11:

score: 6
Accepted
time: 1ms
memory: 5972kb

input:

10
78 78
59 59
40 40
49 49
74 37
2 56
77 77
33 33
93 93
11 11

output:

77
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
58
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
39
1 1 1 1 1 1 1 1 1 1...

result:

ok Ok

Test #12:

score: 6
Accepted
time: 0ms
memory: 3856kb

input:

10
52 52
20 100
95 95
91 91
41 82
50 50
89 89
78 78
80 80
44 22

output:

51
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
99
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

result:

ok Ok

Test #13:

score: 6
Accepted
time: 0ms
memory: 3916kb

input:

10
69 69
36 36
48 48
32 32
55 55
69 69
80 80
75 75
71 71
62 62

output:

68
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
35
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
47
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok Ok

Subtask #2:

score: 9
Accepted

Test #14:

score: 9
Accepted
time: 0ms
memory: 3960kb

input:

10
2 2
3 2
4 2
5 2
2 6
2 7
2 8
9 2
10 2
2 11

output:

1
1 
3
-166666665 166666666 -166666665 
3
1 1 1 
5
-99999999 100000000 -99999999 100000000 -99999999 
5
-1 -1 -1 -1 -1 
7
71428570 -71428571 71428570 -71428571 71428570 -71428571 71428570 
7
-1 -1 -1 -1 -1 -1 -1 
9
-55555554 55555555 -55555554 55555555 -55555554 55555555 -55555554 55555555 -55555554...

result:

ok Ok

Test #15:

score: 9
Accepted
time: 0ms
memory: 3776kb

input:

10
12 2
2 13
14 2
2 15
2 16
17 2
18 2
19 2
20 2
21 2

output:

11
1 1 1 1 1 1 1 1 1 1 1 
13
38461537 -38461538 38461537 -38461538 38461537 -38461538 38461537 -38461538 38461537 -38461538 38461537 -38461538 38461537 
13
1 1 1 1 1 1 1 1 1 1 1 1 1 
15
33333332 -33333333 33333332 -33333333 33333332 -33333333 33333332 -33333333 33333332 -33333333 33333332 -33333333 ...

result:

ok Ok

Test #16:

score: 9
Accepted
time: 1ms
memory: 5856kb

input:

10
2 22
2 23
2 24
2 25
26 2
2 27
28 2
2 29
30 2
31 2

output:

21
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
23
21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 -21739130 21739129 
23
-1 -1 -1...

result:

ok Ok

Test #17:

score: 9
Accepted
time: 0ms
memory: 3960kb

input:

10
32 2
2 33
34 2
35 2
2 36
2 37
2 38
39 2
40 2
41 2

output:

31
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
33
15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 15151514 -15151515 151...

result:

ok Ok

Test #18:

score: 9
Accepted
time: 0ms
memory: 3824kb

input:

10
2 42
43 2
2 44
45 2
46 2
2 47
48 2
2 49
50 2
2 51

output:

41
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 
43
-11627905 11627906 -11627905 11627906 -11627905 11627906 -11627905 11627906 -11627905 11627906 -11627905 11627906 -11627905 11627906 -11627905 11627906 -11627905 11627906...

result:

ok Ok

Test #19:

score: 9
Accepted
time: 1ms
memory: 3964kb

input:

10
2 1727
1728 2
1729 2
1730 2
1731 2
1732 2
2 1733
2 1734
2 1735
2 1736

output:

1727
289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -289519 289518 -28...

result:

ok Ok

Test #20:

score: 9
Accepted
time: 4ms
memory: 5964kb

input:

10
2 8495
2 8496
2 8497
2 8498
8499 2
8500 2
2 8501
8502 2
8503 2
2 8504

output:

8495
58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58858 58857 -58...

result:

ok Ok

Test #21:

score: 9
Accepted
time: 2ms
memory: 3976kb

input:

10
2 3989
2 3990
2 3991
2 3992
2 3993
3994 2
3995 2
3996 2
2 3997
2 3998

output:

3989
125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -125344 125343 -12...

result:

ok Ok

Test #22:

score: 9
Accepted
time: 5ms
memory: 3876kb

input:

10
9991 2
2 9992
2 9993
9994 2
9995 2
2 9996
2 9997
9998 2
9999 2
10000 2

output:

9991
-50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50045 -50044 50...

result:

ok Ok

Test #23:

score: 9
Accepted
time: 3ms
memory: 3948kb

input:

10
2 5682
5683 2
5684 2
2 5685
2 5686
5687 2
2 5688
2 5689
2 5690
2 5691

output:

5681
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

result:

ok Ok

Subtask #3:

score: 0
Wrong Answer

Test #24:

score: 14
Accepted
time: 0ms
memory: 3908kb

input:

10
7 1
1 5
1 1
10 1
1 4
3 1
1 6
1 2
1 9
8 1

output:

6
1 1 1 1 1 1 
4
-1 -1 -1 -1 
0

9
1 1 1 1 1 1 1 1 1 
3
-1 -1 -1 
2
1 1 
5
-1 -1 -1 -1 -1 
1
-1 
8
-1 -1 -1 -1 -1 -1 -1 -1 
7
1 1 1 1 1 1 1 

result:

ok Ok

Test #25:

score: 14
Accepted
time: 0ms
memory: 3964kb

input:

10
6 2
2 4
2 2
2 5
3 2
7 2
2 10
2 1
2 8
2 9

output:

5
1 1 1 1 1 
3
-1 -1 -1 
1
1 
5
99999999 -100000000 99999999 -100000000 99999999 
3
-166666665 166666666 -166666665 
7
-71428570 71428571 -71428570 71428571 -71428570 71428571 -71428570 
9
-1 -1 -1 -1 -1 -1 -1 -1 -1 
1
1 
7
-1 -1 -1 -1 -1 -1 -1 
9
55555554 -55555555 55555554 -55555555 55555554 -5555...

result:

ok Ok

Test #26:

score: 14
Accepted
time: 0ms
memory: 3952kb

input:

10
3 8
10 3
3 3
9 3
3 7
3 4
3 6
3 1
3 5
3 2

output:

9
-55555555 111111109 -55555555 -55555555 111111109 -55555555 -55555555 111111109 -55555555 
11
-90909089 -90909089 181818179 -90909089 -90909089 181818179 -90909089 -90909089 181818179 -90909089 -90909089 
2
1 1 
8
1 1 1 1 1 1 1 1 
8
124999999 124999999 -249999999 124999999 124999999 -249999999 124...

result:

ok Ok

Test #27:

score: 0
Wrong Answer
time: 0ms
memory: 3960kb

input:

10
1 4
8 4
9 4
7 4
4 6
2 4
4 4
4 3
4 10
5 4

output:

3
-1 -1 -1 
7
1 1 1 1 1 1 1 
11
-136363634 45454545 -136363634 227272724 -136363634 45454545 -136363634 227272724 -136363634 45454545 -136363634 
9
55555555 55555555 -166666664 55555555 55555555 55555555 -166666664 55555555 55555555 
7
-71428571 214285712 -71428571 -71428571 -71428571 214285712 -714...

result:

wrong answer there is incorrect sequence

Subtask #4:

score: 0
Wrong Answer

Test #34:

score: 0
Wrong Answer
time: 0ms
memory: 3900kb

input:

10
2 3
2 4
4 3
5 3
5 4
6 4
6 5
5 7
7 6
6 8

output:

3
166666665 -166666666 166666665 
3
-1 -1 -1 
5
-199999999 -199999999 399999999 -199999999 -199999999 
6
83333333 -166666665 83333333 83333333 -166666665 83333333 
7
-214285712 71428571 -214285712 357142854 -214285712 71428571 -214285712 
7
71428571 -214285712 71428571 71428571 71428571 -214285712 7...

result:

wrong answer there is incorrect sequence

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%