Submission #595210

#TimeUsernameProblemLanguageResultExecution timeMemory
595210ApiramSandcastle 2 (JOI22_ho_t5)C++14
0 / 100
17 ms6140 KiB
#include<bits/stdc++.h> using namespace std; struct node{ int x,y,cost,dir; }; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,m;cin>>n>>m; vector<vector<int>>arr(n,vector<int>(m)); vector<vector<vector<int>>>deg(n,vector<vector<int>>(m,vector<int>(4,0))); for (int i = 0;i<n;++i){ for (int j = 0;j<m;++j){ cin>>arr[i][j]; } } vector<int>dx = {1,-1,0,0}; vector<int>dy = {0,0,1,-1}; for (int i = 0;i<n;++i){ for (int j = 0;j < m;++j){ for (int k = 0;k<4;++k){ int nx = i + dx[k]; int ny = j + dy[k]; if (nx>=0 && nx < n&& ny>=0 && ny < m){ if (arr[nx][ny] < arr[i][j]){ deg[nx][ny][k]++; } } } } } queue<node>q; for (int i = 0;i<n;++i){ for (int j = 0;j<m;++j){ for (int k = 0;k<4;++k){ if (deg[i][j][k] == 0){ q.push({i,j,1,k}); } } } } long long ans = n * m; while(!q.empty()){ auto u = q.front(); q.pop(); int nx = dx[u.dir] + u.x; int ny = dy[u.dir] + u.y; bool ok = false; if (nx>=0 && nx < n&& ny>=0 && ny < m){ if (arr[nx][ny] < arr[u.x][u.y]){ q.push({nx,ny,u.cost + 1,u.dir}); ok = true; } } if (!ok){ ans+=u.cost * (u.cost + 1) / 2 - u.cost; } } cout<<ans<<'\n'; return 0; }
#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...