Submission #469220

# Submission time Handle Problem Language Result Execution time Memory
469220 2021-08-31T07:26:20 Z ala2 Bob (COCI14_bob) C++14
120 / 120
772 ms 18132 KB
#include <iostream>
#define int long long
using namespace std;
int a[1010][1010];
int dp[1010][1010];
signed main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
            dp[i][j]=1;
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(a[i][j]==a[i-1][j])
            {
                dp[i][j]=dp[i-1][j]+1;
            }
        }
    }// cout<<endl;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {//cout<<dp[i][j]<<" ";
            int mn=1e9;
            for(int k=j;k>=0;k--)
            {  // cout<<"       "<<i<<"  "<<j<<"   "<<k<<"    ";
                if(k<j&&a[i][k]!=a[i][k+1])
                    break;
                mn=min(mn,dp[i][k]);
                ans+=mn;
              //  cout<<"      "<<1<<endl;

            }
           // cout<<ans<<" ";
        }
       // cout<<endl;
    }
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 8480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 8452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 8512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 16372 KB Output is correct
2 Correct 707 ms 17940 KB Output is correct
3 Correct 763 ms 18048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 16376 KB Output is correct
2 Correct 395 ms 18044 KB Output is correct
3 Correct 772 ms 18004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 511 ms 16448 KB Output is correct
2 Correct 760 ms 18116 KB Output is correct
3 Correct 764 ms 17936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 470 ms 16448 KB Output is correct
2 Correct 739 ms 18132 KB Output is correct
3 Correct 752 ms 18116 KB Output is correct