Submission #469134

# Submission time Handle Problem Language Result Execution time Memory
469134 2021-08-30T21:30:41 Z ala2 Bob (COCI14_bob) C++14
0 / 120
532 ms 49548 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
using namespace std;
int a[1010][1010];
int dpr[1010][1010];
int dpc[1010][1010];
pair<int,int> dp3[1010][1010];
signed main()
{
    int n;
    cin>>n;
    int m;
    cin>>m;
    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++)
        {
            dpc[i][j]=1;
            dpr[i][j]=1;
            dp3[i][j].ff=1;
            dp3[i][j].ss=1;
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i>0)
            {
                if(a[i][j]==a[i-1][j])
                {
                    dpr[i][j]=dpr[i-1][j]+1;
                }
            }
            if(j>0)
            {
                if(a[i][j]==a[i][j-1])
                {
                    dpc[i][j]=dpc[i][j-1]+1;
                }
            }
        }
    }//   ff for c    ss for r
    for(int i=0;i<n;i++)
    {
        dp3[i][0].ss=dpr[i][0];
    }
    for(int j=0;j<m;j++)
    {
        dp3[0][j].ff=dpc[0][j];
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(a[i][j]==a[i][j-1])
            {
                dp3[i][j].ff=min(dp3[i][j-1].ff+1,dpc[i][j]);
              //  cout<<"      "<<i<<"  "<<j<<"  "<<dp3[i][j-1].ff+1<<"  "<<  dpc[i][j]<<endl;
            }
            if(a[i][j]==a[i-1][j])
            {
                dp3[i][j].ss=min(dp3[i-1][j].ss+1,dpr[i][j]);
            }
        }
    }
     int ans=0;
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<m;j++)
         { //cout<<dpr[i][j]<<" ";
             for(int k=j;k>=0;k--)
             {
                 if(a[i][k]!=a[i][k+1]&&k!=j)
                    break;
                 ans+=dpr[i][k];
             }
           //  cout<<" :"<<ans<<"   ";
         }
       //  cout<<endl;
     }
     cout<<""<<ans<<endl;

}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 18572 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 18964 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 19200 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 19116 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 368 ms 46536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 459 ms 49548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 532 ms 49500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 481 ms 49460 KB Output isn't correct
2 Halted 0 ms 0 KB -