Submission #683109

# Submission time Handle Problem Language Result Execution time Memory
683109 2023-01-17T17:20:49 Z Ahmed57 Bob (COCI14_bob) C++14
0 / 120
124 ms 8148 KB
#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()){
        tp = s.top();s.pop();
        sum_area+= hist[tp] * (s.empty() ? i-la : i - s.top() - 1);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    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 time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -