UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190608#3382. 切纸带WilliamFranklin100135ms24696kbC++11903b2023-10-06 14:41:192023-10-06 18:34:39

answer

#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp(Tx, Ty) make_pair(Tx, Ty)
#define For(Ti, Ta, Tb) for(auto Ti = (Ta); Ti <= (Tb); Ti++)
#define Dec(Ti, Ta, Tb) for(auto Ti = (Ta); Ti >= (Tb); Ti--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx) 
const int N = 1e6 + 5;
long long l[N], pre[N];
int last[N];
int f[N];
int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	For(i, 1, n) cin >> l[i];
	For(i, 1, n) pre[i] = pre[i - 1] + l[i];
	For(i, 1, n) {
		int w = lower_bound(pre, pre + n + 1, pre[i] - m) - pre;
		if (pre[w] == pre[i] - m) {
			last[i] = w;
		} else {
			last[i] = -1;
		}
	}
	For(i, 1, n) {
		if (last[i] == -1) continue;
		f[i] = f[last[i]] + 1;
	}
	int maxn = 0;
	For(i, 1, n) {
		maxn = max(maxn, f[i]);
	}
	cout << maxn;
	return 0;
} 

详细

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

Test #1:

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

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: 1268kb

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: 1264kb

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: 1264kb

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: 1284kb

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: 0ms
memory: 1392kb

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: 0ms
memory: 2448kb

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: 10ms
memory: 3612kb

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: 16ms
memory: 3612kb

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: 109ms
memory: 24696kb

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"