# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
146131 |
2019-08-22T10:04:25 Z |
bharat2002 |
Bob (COCI14_bob) |
C++14 |
|
207 ms |
35904 KB |
/*input
4 3
1 1 1
1 1 1
2 2 2
2 2 2
*/
#include<bits/stdc++.h>
using namespace std;
const int N=1e3 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second
#define mp make_pair
int grid[N][N], ans[N][N], len[N][N];
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n, m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) cin>>grid[i][j];
}
for(int i=1;i<=n;i++)
{
int prev=m, type=grid[i][m];
for(int j=m;j>=1;j--)
{
if(type!=grid[i][j])
{
prev=j;type=grid[i][j];
}
len[i][j]=prev - j+1;
}
}
int output=0;
for(int j=1;j<=m;j++)
{
stack<int> st;int curt=grid[1][j], prev=1;
for(int i=1;i<=n;i++)
{
while(!st.empty()&&((curt==grid[i][j]&&len[st.top()][j]>len[i][j])||curt!=grid[i][j]))
{
st.pop();
}
if(grid[i][j]!=curt)
{
curt=grid[i][j];prev=i;
}
if(!st.empty())
{
ans[i][j]=len[i][j]*(i-st.top()) + ans[st.top()][j];
}
else
{
ans[i][j]=len[i][j]*(i-prev + 1);
}
st.push(i);output+=ans[i][j];
}
}
cout<<output;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
12792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
13176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
13344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
13408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
32804 KB |
Output is correct |
2 |
Correct |
121 ms |
28192 KB |
Output is correct |
3 |
Correct |
119 ms |
28152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
205 ms |
35892 KB |
Output is correct |
2 |
Correct |
134 ms |
28120 KB |
Output is correct |
3 |
Correct |
120 ms |
28100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
35864 KB |
Output is correct |
2 |
Correct |
121 ms |
28092 KB |
Output is correct |
3 |
Correct |
119 ms |
28024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
35904 KB |
Output is correct |
2 |
Correct |
127 ms |
28164 KB |
Output is correct |
3 |
Correct |
121 ms |
28092 KB |
Output is correct |