Submission #17431

#TimeUsernameProblemLanguageResultExecution timeMemory
17431choyi0521Bob (COCI14_bob)C++98
0 / 120
556 ms9536 KiB
#include<iostream> #include<algorithm> using namespace std; const int MAX_N=1000; int n,m,a[MAX_N][MAX_N],h[MAX_N][MAX_N+1]; long long int ans; int main(){ cin >> n >> m; for(int i=0; i<n; i++) for(int j=0; j<m; j++) cin >> a[i][j]; fill(h[0],h[0]+m,1); for(int i=1; i<n; i++) for(int j=0; j<m; j++) h[i][j]=(a[i][j]==a[i-1][j])*h[i-1][j]+1; int st1[MAX_N],st2[MAX_N]; for(int i=0; i<n; i++){ for(int j=0,top=0; j<=n; j++){ while(top&&(st1[top-1]>h[i][j]||a[i][st2[top-1]]!=a[i][j])) ans+=st1[--top]*(j-st2[top]); st1[top]=h[i][j]; st2[top++]=j; } } 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...