#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[50013];
int h, w;
int id(int i, int j){
return i * w + j;
}
int32_t main(){
cin >> h >> w;
for(int i = 0; i < h * w; i++){
cin >> a[i];
}
int cnt = 1;
int st = 0;
int ans = 1;
for(int i = 1; i < w; i++){
if(a[i] > a[i - 1]){
if(st > 0){
cnt++;
}else{
cnt = 1;
}
ans += cnt + 1;
st = 1;
}else{
if(st < 0){
cnt++;
}else{
cnt = 1;
}
ans += cnt + 1;
st = -1;
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
1060 KB |
Output is correct |
3 |
Correct |
15 ms |
980 KB |
Output is correct |
4 |
Correct |
18 ms |
1012 KB |
Output is correct |
5 |
Correct |
16 ms |
1068 KB |
Output is correct |
6 |
Correct |
23 ms |
1032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |