Submission #594157

#TimeUsernameProblemLanguageResultExecution timeMemory
594157Cross_RatioSandcastle 2 (JOI22_ho_t5)C++14
9 / 100
7 ms596 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...