This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
const int INF = 1e18;
vector<vector<int>> A;
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N>> M;
A.resize(N);
int i, j;
for(i=0;i<N;i++) {
A[i].resize(M);
for(j=0;j<M;j++) cin >> A[i][j];
}
int ans = N*M;
for(i=0;i<N;i++) {
int pt = 0;
while(pt+1<M) {
if(A[i][pt]<A[i][pt+1]) {
int cnt = 1;
while(pt+1<M&&A[i][pt]<A[i][pt+1]) {
pt++;
cnt++;
}
ans += cnt * (cnt - 1) / 2;
}
else {
int cnt = 1;
while(pt+1<M&&A[i][pt]>A[i][pt+1]) {
pt++;
cnt++;
}
ans += cnt * (cnt - 1) / 2;
}
//cout << pt << ' ' << ans << '\n';
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |