Submission #151680

# Submission time Handle Problem Language Result Execution time Memory
151680 2019-09-04T06:31:55 Z phillip Strah (COCI18_strah) C++14
66 / 110
1000 ms 67080 KB
#include <bits/stdc++.h>

using namespace std;
int n,m;
long double l[2009][2009];
char gr[2009][2009];
long long ans;
int main()
{
    cin>>n>>m;
    for(int i=0; i<n; i++)
    {
        cin>>gr[i];
    }
    if(n>m)
    {
        for(int i=0; i<n; i++)
        {
            for(int j=m-1; j>=0; j--)
            {
                if(gr[i][j]=='#')continue;
                l[i][j]=1+l[i][j+1];
            }
        }
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                if(l[i][j]==0)continue;
                long double mn=l[i][j];
                for(int k=i; k<n; k++)
                {
                    mn=min(mn,l[k][j]);
                    if(mn==0)break;
                    long double r=(k-i+1);
                    //if(r==1)ans+=(mn*(mn+1))/2;
                    ans+=(((mn*r)+r)/2.0)*mn;
                }
                //       cout<<i<<" "<<j<<"-> "<<ans<<"\n";
            }
        }
    }
    else
    {
        for(int i=0; i<m; i++)
        {
            for(int j=n-1; j>=0; j--)
            {
                if(gr[j][i]=='#')continue;
                l[j][i]=1+l[j+1][i];
            }
        }
        for(int j=0; j<m; j++)
        {
            for(int i=0; i<n; i++)
            {
                if(l[i][j]==0)continue;
                long double mn=l[i][j];
                for(int k=j; k<m; k++)
                {
                    mn=min(mn,l[i][k]);
                    if(mn==0)break;
                    long double r=(k-j+1);
                    //if(r==1)ans+=(mn*(mn+1))/2;
                    ans+=(((mn*r)+r)/2.0)*mn;
                }
                //       cout<<i<<" "<<j<<"-> "<<ans<<"\n";
            }
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3576 KB Output is correct
2 Correct 25 ms 3580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3576 KB Output is correct
2 Correct 26 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 3612 KB Output is correct
2 Correct 26 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 21756 KB Output is correct
2 Correct 723 ms 46752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 422 ms 44808 KB Output is correct
2 Execution timed out 1081 ms 65048 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 28948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 15352 KB Output is correct
2 Execution timed out 1043 ms 57412 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 67080 KB Time limit exceeded
2 Halted 0 ms 0 KB -