UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198887#3461. 环形序列ptezhy100117ms1588kbC++514b2023-12-03 09:41:472023-12-03 12:06:45

answer

#include<bits/stdc++.h>
using namespace std;
int n,x;
int a[100001],b=0,c=1,ans;
int main()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>a[++b];
		if(b>=2)
		{
			if(a[b]==a[b-1])
			{
				b-=2;
				ans+=1;
			}
			else if(a[b]+a[b-1]==x)
			{
				b-=2;
				ans+=1;
			}
		}
	}
	c=1;
	while(c<b)
	{
		if(a[c]==a[b])
		{
			c+=1;
			b-=1;
			ans+=1;
		}
		else if(a[c]+a[b]==x)
		{
			c+=1;
			b-=1;
			ans+=1;
		}
		else
		{
			break;
		}
	}
	cout<<ans;
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

10 22290
22800 77879 28533 66905 22602 35763 49872 60532 40526 49904

output:

0

result:

ok single line: '0'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

10 1000000000
845947692 700125935 700125935 845947692 913127267 913127267 784712817 784712817 197800...

output:

4

result:

ok single line: '4'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

10 1000
521 860 60 940 860 521 155 96 96 155

output:

5

result:

ok single line: '5'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

1000 1359
44877 48392 84311 16267 29255 52276 20511 75195 95522 64489 52229 74478 69766 41777 25148 ...

output:

0

result:

ok single line: '0'

Test #5:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

1000 1000000000
756436126 734753540 160431987 924829345 924829345 494288318 4281705 20516045 1102758...

output:

456

result:

ok single line: '456'

Test #6:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

999 1000
285 715 319 58 282 15 64 39 661 222 705 494 258 471 831 920 847 124 525 14 884 884 526 114 ...

output:

499

result:

ok single line: '499'

Test #7:

score: 10
Accepted
time: 22ms
memory: 1588kb

input:

100000 13036
23902 71466 9482 98728 78471 22915 2470 5999 53211 25994 3996 11349 30511 56448 17277 7...

output:

2

result:

ok single line: '2'

Test #8:

score: 10
Accepted
time: 20ms
memory: 1484kb

input:

98245 1000
155 937 591 386 662 268 448 538 715 4 124 798 35 66 552 678 14 412 372 941 941 93 226 90 ...

output:

49122

result:

ok single line: '49122'

Test #9:

score: 10
Accepted
time: 41ms
memory: 1444kb

input:

99999 1000000000
4691050 337369475 163943451 680210784 535852492 815500578 995715858 919611614 45540...

output:

49999

result:

ok single line: '49999'

Test #10:

score: 10
Accepted
time: 34ms
memory: 1304kb

input:

100000 10000000
3350847 6649153 6727419 4244727 28285370 64225897 1520717 84820290 83748267 2604198 ...

output:

37127

result:

ok single line: '37127'

Extra Test:

score: 0
Extra Test Passed