Submission #528294

#TimeUsernameProblemLanguageResultExecution timeMemory
528294dooweySandcastle 2 (JOI22_ho_t5)C++14
80 / 100
5055 ms17100 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); vector<vector<int>> A; vector<vector<ll>> S4; vector<vector<ll>> S5; vector<vector<ll>> S6; vector<vector<ll>> S7; vector<vector<ll>> S8; int n, m; const int inf = 1e6; int calc(int i, int j, int mode){ vector<int> V; if(mode == 0){ V = {A[i + 1][j], A[i][j+1]}; } else if(mode == 1){ V = {A[i + 1][j], A[i][j-1]}; } else if(mode == 2){ V = {A[i - 1][j], A[i][j+1]}; } else if(mode == 3){ V = {A[i - 1][j], A[i][j-1]}; } else if(mode == 4){ V = {A[i][j-1], A[i+1][j], A[i][j+1]}; } else if(mode == 5){ V = {A[i-1][j], A[i+1][j], A[i][j-1]}; } else if(mode == 6){ V = {A[i-1][j], A[i][j-1], A[i][j+1]}; } else if(mode == 7){ V = {A[i-1][j], A[i+1][j], A[i][j+1]}; } else{ V = {A[i-1][j], A[i+1][j], A[i][j+1],A[i][j-1]}; } int maxi = 0; for(auto x : V){ if(x < A[i][j]){ maxi = max(maxi, x); } } int high = inf; for(auto x : V){ if(x > A[i][j]){ high = min(high, x); } } int cum = high - A[i][j]; if(maxi == 0) cum += A[i][j]; return cum; } int main(){ fastIO; cin >> n >> m; A.resize(n); S4.resize(n); S5.resize(n); S6.resize(n); S7.resize(n); S8.resize(n); for(int i = 0 ; i < n; i ++ ){ A[i].resize(m); S4[i].resize(m); S5[i].resize(m); S6[i].resize(m); S7[i].resize(m); S8[i].resize(m); } vector<int> C; for(int i = 0 ; i < n; i ++ ){ for(int j = 0 ; j < m ; j ++ ){ cin >> A[i][j]; C.push_back(A[i][j]); } } sort(C.begin(), C.end()); C.resize(unique(C.begin(), C.end()) - C.begin()); int id; for(int i = 0 ; i < n; i ++ ){ for(int j = 0 ; j < m; j ++ ){ A[i][j] = upper_bound(C.begin(), C.end(), A[i][j]) - C.begin(); } } for(int i = 0; i < n; i ++ ){ for(int j = 0; j < m; j ++ ){ if(j > 0 && j + 1 < m && i + 1 < n)S4[i][j] = calc(i, j, 4); if(i > 0 && i + 1 < n && j > 0) S5[i][j] = calc(i, j, 5); if(i > 0 && j > 0 && j + 1 < m) S6[i][j] = calc(i, j, 6); if(j + 1 < m && i > 0 && i + 1 < n) S7[i][j] = calc(i, j, 7); if(i > 0 && j > 0 && i + 1 < n && j + 1 < m)S8[i][j] = calc(i, j, 8); if(i){ S5[i][j] += S5[i-1][j]; S7[i][j] += S7[i-1][j]; S8[i][j] += S8[i-1][j]; } if(j){ S4[i][j] += S4[i][j-1]; S6[i][j] += S6[i][j-1]; S8[i][j] += S8[i][j-1]; } if(i && j){ S8[i][j] -= S8[i-1][j-1]; } } } ll res = 0; res += n * m; for(int i = 0 ; i < n; i ++ ){ for(int j = 0 ; j < m ; j ++ ){ for(int k = j + 1 ; k < m ; k ++ ){ if(A[i][k] > A[i][k - 1]){ break; } res ++ ; } for(int k = j - 1; k >= 0 ; k -- ){ if(A[i][k] > A[i][k + 1]){ break; } res ++ ; } for(int k = i + 1; k < n; k ++ ){ if(A[k][j] > A[k - 1][j]){ break; } res ++ ; } for(int k = i - 1; k >= 0; k -- ){ if(A[k][j] > A[k + 1][j]){ break; } res ++ ; } } } ll cummy; for(int i = 0 ; i < n; i ++ ){ for(int j = 0 ; j < m ; j ++ ){ for(int ii = i + 1; ii < n; ii ++ ){ for(int jj = j + 1; jj < m ; jj ++ ){ cummy = 0; cummy += S8[ii-1][jj-1] + S8[i][j] - S8[i][jj-1] - S8[ii-1][j]; cummy += calc(i,j,0); cummy += calc(ii,jj,3); cummy += calc(i,jj,1); cummy += calc(ii,j,2); cummy += S4[i][jj-1]-S4[i][j]; cummy += S6[ii][jj-1]-S6[ii][j]; cummy += S5[ii-1][jj]-S5[i][jj]; cummy += S7[ii-1][j]-S7[i][j]; if(cummy == inf){ res ++ ; } } } } } cout << res << "\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:97:9: warning: unused variable 'id' [-Wunused-variable]
   97 |     int id;
      |         ^~
#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...