Submission #82239

#TimeUsernameProblemLanguageResultExecution timeMemory
82239ngot23Bob (COCI14_bob)C++11
120 / 120
192 ms24512 KiB
#include<bits/stdc++.h> #define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i) #define Task "" using namespace std; const int N=1005; int f[N][N], m, n, a[N][N], luu[N], dem, s[N], top; long long ans, b[N]; void tinh() { rep(i, 1, dem) b[i]=0; top=0; rep(i, 1, dem) { while(top&&luu[i]<=luu[s[top]]) --top; b[i]=1ll*(i-s[top])*luu[i]+b[s[top]]; ans+=b[i]; s[++top]=i; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(Task".inp", "r", stdin); //freopen(Task".out", "w", stdout); cin >> m >> n; rep(i, 1, m) rep(j, 1, n) { cin >> a[i][j]; f[i][j]=1; if(a[i-1][j]==a[i][j]) f[i][j]+=f[i-1][j]; } rep(i, 1, m) { int ptr=1; a[i][n+1]=-1; while(ptr<=n) { int j=ptr; dem=0; for( ; j<=n ; ++j) { luu[++dem]=f[i][j]; if(a[i][j]!=a[i][j+1]) { tinh(); break; } } ptr=j+1; } } cout << ans; return 0; }
#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...