Submission #1059464

# Submission time Handle Problem Language Result Execution time Memory
1059464 2024-08-15T01:45:19 Z DucNguyen2007 Bob (COCI14_bob) C++14
0 / 120
73 ms 14056 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=1e3+5;
const ll inf=2e18;
int n,m,f[maxN+1],g[maxN+1];
int a[maxN+1][maxN+1];
stack<int> st;
void clr()
{
    while(!st.empty())
    {
        st.pop();
    }
}
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    ll ans=0;
    for(int h=1;h<=n;h++)
    {
        for(int i=1;i<=m;i++)
        {
            if(a[h][i]!=a[h-1][i])
            {
                f[i]=1;
                g[i]=a[h][i];
            }
            else f[i]++;
        }
        //cout<<h<<'\n';
        for(int i=1;i<=m;i++)
        {
            while(!st.empty()&&g[st.top()]==g[i])
            {
                st.pop();
            }
            int tmp;
            if(st.empty())
            {
                tmp=0;
            }
            else tmp=st.top();
            ans+=(i-tmp);
            //cout<<i<<" "<<tmp<<" "<<f[i]<<'\n';
            st.push(i);
        }
        clr();
        for(int i=1;i<=m;i++)
        {
            while(!st.empty()&&f[st.top()]>=f[i])
            {
                st.pop();
            }
            int tmp;
            if(st.empty())
            {
                tmp=0;
            }
            else tmp=st.top();
            ans+=1LL*(i-tmp)*(f[i]-1);
            st.push(i);
        }
        clr();
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 3696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 10868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 14056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 13908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 13908 KB Output isn't correct
2 Halted 0 ms 0 KB -