Submission #1059464

#TimeUsernameProblemLanguageResultExecution timeMemory
1059464DucNguyen2007Bob (COCI14_bob)C++14
0 / 120
73 ms14056 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...