Submission #15561

# Submission time Handle Problem Language Result Execution time Memory
15561 2015-07-12T20:02:24 Z Fakeable 빨간 직사각형 (kriii3_QQ) C++
0 / 20
0 ms 1752 KB
#include<iostream>
#include<stack>
#include<memory.h>
#define pi pair<int,int>
#define mp make_pair
using namespace std;
const int max_n = 3030;
int n,m,h[max_n],l[max_n],r[max_n];
long long ans;
char a[max_n];
int main() {
    ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<n;i++) {
        cin>>a;
        for(int j=0;j<m;j++) {
            if(a[j]=='R') h[j]++;
            else h[j] = 0;
        }
        stack<pi> s;
        s.push(mp(-1,-1));
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        for(int j=0;j<m;j++) {
            while(1) {
                pi T = s.top();
                if(T.second >= h[j]) {
                    s.pop();
                    r[T.first] = j;
                }
                else break;
            }
            l[j] = s.top().first;
            s.push(mp(j,h[j]));
        }
        while(!s.empty()) {
            r[s.top().first] = m;
            s.pop();
        }
        for(int j=0;j<m;j++) ans += 1LL * (r[j]-l[j]-1) * h[j];
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1752 KB Output is correct
2 Incorrect 0 ms 1752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -