Submission #683108

#TimeUsernameProblemLanguageResultExecution timeMemory
683108Ahmed57Bob (COCI14_bob)C++14
0 / 120
405 ms17852 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #include <bits/stdc++.h> using namespace std; vector<long long> hist(1001,0),col(1001,0); long long n,m; long long sum_area = 0; void getMaxArea(){ stack<long long> s;long long tp;long long i=0; long long la = 0; while(i<m){ if(i>0&&col[i]!=col[i-1]){ while(s.empty()==false) { tp = s.top(); s.pop(); sum_area+=hist[tp]*(s.empty()?i-la:i-s.top()-1); } la = i; } if(s.empty()||hist[s.top()]<=hist[i])s.push(i++); else{ tp = s.top();s.pop(); sum_area+=hist[tp]*(s.empty()?i-la:i-s.top()-1); } } while (s.empty() == false) { tp = s.top(); s.pop(); sum_area+= hist[tp] * (s.empty() ? i-la : i - s.top() - 1); } } signed main(){ cin>>n>>m; long long arr[n][m]; for(int i = 0;i<n;i++){ for(int j = 0;j<m;j++){ cin>>arr[i][j]; } } for(int i = 0;i<n;i++){ if(i==0){ for(int j = 0;j<m;j++){col[j]=arr[i][j];hist[j]=1;} }else{ for(int j = 0;j<m;j++){ col[j] = arr[i][j]; if(arr[i][j]==arr[i-1][j])hist[j]++; else hist[j] = 1; } } getMaxArea(); } cout<<sum_area; }
#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...
#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...