UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190606#3382. 切纸带Harry2718210077ms32496kbC++11527b2023-10-06 14:37:212023-10-06 18:34:32

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[1000005],sum[1000005],nxt[1000005],ans,f[1000005];
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i],sum[i]=sum[i-1]+a[i];
	for(int i=1,j=1;i<=n;i++)
	{
		while(sum[j]-sum[i-1]<m&&j<=n)j++;
		if(j<=n&&sum[j]-sum[i-1]==m)nxt[i]=j;
		else nxt[i]=-1;
	}
	for(int i=n;i>=1;i--)
	{
		if(nxt[i]!=-1)f[i]=f[nxt[i]+1]+1;
		else f[i]=0;
		ans=max(ans,f[i]);
	}
	cout<<ans;
	return 0;
}

详细

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

Test #1:

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

input:

10 8
7 6 1 1 1 2 2 1 1 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

20 15
15 15 15 6 5 4 3 1 2 1 4 3 1 2 1 1 3 2 5 1

output:

6

result:

ok 1 number(s): "6"

Test #3:

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

input:

50 150
30 83 136 11 2 94 137 127 111 27 150 150 150 150 150 47 150 145 67 150 150 59 143 142 150 18 ...

output:

5

result:

ok 1 number(s): "5"

Test #4:

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

input:

100 10000
2397 9666 164 4643 8586 5876 4272 2648 1874 1206 6920 1732 107 35 778 428 6920 262 888 582...

output:

8

result:

ok 1 number(s): "8"

Test #5:

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

input:

500 278529
33329 243449 856 45 557 153 52 68 9 11 15965 25498 110413 69087 26846 16166 3236 4561 127...

output:

12

result:

ok 1 number(s): "12"

Test #6:

score: 10
Accepted
time: 1ms
memory: 1420kb

input:

5000 1024
369 299 338 137 12 186 10 180 97 117 148 16 8 169 31 44 17 111 24 7 42 12 45 276 67 6 1 2 ...

output:

26

result:

ok 1 number(s): "26"

Test #7:

score: 10
Accepted
time: 3ms
memory: 2828kb

input:

50000 2
1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 1 2 2 1 1 1 1 2 1 1 1 1 ...

output:

1435

result:

ok 1 number(s): "1435"

Test #8:

score: 10
Accepted
time: 5ms
memory: 4384kb

input:

100000 2
2 2 1 1 2 2 1 1 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 1 1 2 2 1 2 2 2 2 1 1 2 1 1 2 2 2...

output:

1065

result:

ok 1 number(s): "1065"

Test #9:

score: 10
Accepted
time: 12ms
memory: 4384kb

input:

100000 594914243
32593384 70791539 466102281 5146792 10441404 6860910 391592 109128 1123315 1345154 ...

output:

121

result:

ok 1 number(s): "121"

Test #10:

score: 10
Accepted
time: 56ms
memory: 32496kb

input:

1000000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

850

result:

ok 1 number(s): "850"