#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e3 + 10;
const int mod = 1e9 + 7;
int a[maxn], b[maxn], par[maxn];
int main() {
srand (time (NULL));
int n;
cin >> n;
int M = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
M = max (M, a[i]);
b[i] = 1;
par[i] = 1;
}
if (M == 1)
return cout << 1 << endl, 0;
int cnt = 1;
bool eq = false;
while (!eq) {
cnt ++;
for (int i = n; i >= 1; i--) {
if (b[i] != par[i - 1] + 1) {
b[i] ++;
par[i] = max (par[i], b[i]);
for (int j = i + 1; j <= n; j++) {
par[j] = par[j - 1];
b[j] = 1;
}
break;
}
}
eq = true;
for (int i = 1; i <= n; i++)
if (a[i] != b[i])
eq = false;
}
cout << cnt << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
664 KB |
Output is correct |
2 |
Correct |
2 ms |
664 KB |
Output is correct |
3 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
218 ms |
664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
664 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
880 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
908 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |