# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163721 | beso123 | Bob (COCI14_bob) | C++14 | 1090 ms | 38484 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[1001][1001],ans;
void NOW(int x){
int dp[n+1][m+1],w[n+1][m+1];
dp[0][0]=0;
for(int k=1;k<=n;k++){
stack <int> st;
for(int i=1;i<=m;i++){
dp[k][0]=0;
dp[0][i]=0;
dp[k][i]=0;
w[k][i]=0;
if(a[k][i]!=x)
continue;
if(a[k-1][i]!=x)
w[k][i]=1;
else w[k][i]=w[k-1][i]+1;
int h=i-1;
if(st.size()!=0){
while(st.size()>0 && w[k][st.top()]>=w[k][i]){
st.pop();
}
if(st.size()!=0)
h=st.top();
}
st.push(i);
dp[k][i]=(i-h)*w[k][i]+dp[k][h];
ans+=dp[k][i];
}
}
}
main(){
cin>>n>>m;
set<int> s;
for(int k=1;k<=n;k++)
for(int i=1;i<=m;i++){
cin>>a[k][i];
s.insert(a[k][i]);
}
for(auto it=s.begin();it!=s.end();it++){
NOW(*it);
}
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |