답안 #119290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
119290 2019-06-21T00:04:00 Z OptxPrime Strah (COCI18_strah) C++11
99 / 110
524 ms 39764 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include<stack>

using namespace std;

#define pb push_back
#define mp make_pair

int h[2010],levo[2010],desno[2010];
char a[2010][2010];
long long dp[2010][2010];

int main()
{
   int n,m;
   long long res=0;
   cin>>n>>m;
   for(int i=0;i<m;i++) h[i]=n;
   for( int i=1;i<=n;i++ ) dp[i][1]=i*(i+1)/2;

   for( int i=1;i<=n;i++ ){
    for( int j=2;j<=m;j++ ) dp[i][j] = dp[i][j-1] + ( i*(i+1)*j*(j+1) )/4;
   }

   stack<int> s;
   for(int i=0;i<n;i++ ){
    for( int j=0;j<m;j++ )cin>>a[i][j];
   }

   for( int i=0;i<n;i++ ){
    for( int j=0;j<m;j++ ){
    //    cin>>a[i][j];
        if( a[i][j] == '#' ){
            h[j]=n-i-1;
            s.push(j);
            continue;
        }
        if( s.empty() ){
            levo[j]=-1;
            s.push(j);
            continue;
        }
        int curr=s.top();
       // cout << " skaka " <<endl;
        while( h[curr] > h[j] ){
            s.pop();
            if( s.empty() ) break;
            else curr=s.top();
        }
      //  cout<< " ee  " <<endl;
        if( s.empty() ) levo[j]=-1;
       else levo[j] = curr;
        s.push(j);
    }
        while( !s.empty() ) s.pop();
        for( int j=m-1;j>=0;j-- ){
                if( a[i][j] =='#' ){
                   // h[j]=n-i-1;
                    s.push(j);
                    continue;
                }
            if( s.empty() ) {
                    desno[j] = m;
                    s.push(j);
                    continue;
            }
            int curr=s.top();
            while( h[curr] >= h[j] ){
                s.pop();
                if( s.empty() ) break;
                else curr=s.top();
            }
            if( s.empty() ) desno[j] = m;
            else desno[j] = curr;
            s.push(j);
        }
       /* for( int j=0;j<m;j++ ){
            cout << i << " " << j << " " << levo[j] << " " << desno[j] << " hehe " <<endl;
        }*/

        while( !s.empty() ) s.pop();
        for( int j=0;j<m;j++ ){
                if( a[i][j] == '#' ) continue;
       //         cout << i << " " << j << " " <<" " << h[j] << " "<<h[j]-( n-i-1 ) << " dosta " <<endl;
        long long vis =(long long)( h[j]-( n-i-1 ) );
        long long velka= (long long)(desno[j]-levo[j]-1);
        long long mala1=(long long)(desno[j]-j-1);
        long long mala2=(long long)j-levo[j]-1;
       // cout << i << " " << j << " " << " " << vis << " " << velka << " " << mala1 << " " << mala2 << " " << dp[vis][velka] << " rahib " <<endl;
        res+=dp[vis][velka];
        res-=dp[vis][mala1];
        res-=dp[vis][mala2];
        //    cout << dp[1][2] << " bratee " <<endl;
        }


   }
        cout<<res<<endl;

    return 0;
}





















# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2944 KB Output is correct
2 Correct 11 ms 3044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2944 KB Output is correct
2 Correct 11 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 2984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 14636 KB Output is correct
2 Correct 209 ms 29464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 26232 KB Output is correct
2 Correct 322 ms 38264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 16960 KB Output is correct
2 Correct 231 ms 31464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 13560 KB Output is correct
2 Correct 246 ms 36600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 327 ms 39672 KB Output is correct
2 Correct 524 ms 39764 KB Output is correct