#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, l, sum = 0;
cin >> n >> l;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> p(n);
for (int i = 0; i < n; i++) p[i] = i;
vector<int> ct(n);
for (int i = 0; i < n; i++) ct[i] = true;
while (true) {
int s = 0;
for (int i = 0; i < n-1; i++) {
s += abs(a[p[i]] - a[p[i+1]]);
}
if (s <= l) sum++;
int ptr = n-1;
while (ptr >= 0) {
ct[p[ptr]] = false;
p[ptr]++;
while (p[ptr] < n && ct[p[ptr]]) {
p[ptr]++;
}
if (p[ptr] < n) break;
ptr--;
}
if (ptr < 0) break;
ct[p[ptr]] = true;
for (int i = 0; i < n; i++) {
if (!ct[i]) {
ct[i] = true;
p[++ptr] = i;
}
}
}
cout << sum << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
392 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2067 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
392 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
2067 ms |
348 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |