# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
582538 |
2022-06-24T04:36:56 Z |
vuavisao |
Bob (COCI14_bob) |
C++14 |
|
158 ms |
8296 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;
const int N = 1e3 + 10;
int n, m;
int a[N][N];
int nxt[N][N];
int h[N];
int l[N], r[N];
ll res;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("BOB.inp", "r", stdin);
// freopen("BOB.out", "w", stdout);
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> a[i][j];
for(int _ = 1; _ <= n; _++)
for(int l = 1, r = 1; l <= m;)
{
while(r <= m && a[_][r] == a[_][l]) r++;
nxt[_][l] = r;
l = r;
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
h[j] = (a[i][j] == a[i - 1][j] ? h[j] + 1 : 1);
l[i] = 0;
r[i] = 0;
}
for(int j = 1; j <= m; j = nxt[i][j])
{
stack<int> stk;
for(int k = j; k < nxt[i][j]; k++)
{
while(!stk.empty() && h[stk.top()] >= h[k]) stk.pop();
if(stk.empty()) l[k] = j;
else l[k] = stk.top() + 1;
stk.push(k);
}
while(!stk.empty()) stk.pop();
for(int k = nxt[i][j] - 1; k >= j; k--)
{
while(!stk.empty() && h[stk.top()] > h[k]) stk.pop();
if(stk.empty()) r[k] = nxt[i][j] - 1;
else r[k] = stk.top() - 1;
stk.push(k);
}
}
for(int j = 1; j <= m; j++)
res += 1ll * h[j] * (j - l[j] + 1) * (r[j] - j + 1);
}
cout << res;
return 0;
}
/// Code by vuavisao
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
4288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
4260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
8228 KB |
Output is correct |
2 |
Correct |
59 ms |
8228 KB |
Output is correct |
3 |
Correct |
55 ms |
8232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
8296 KB |
Output is correct |
2 |
Correct |
71 ms |
8208 KB |
Output is correct |
3 |
Correct |
64 ms |
8220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
8232 KB |
Output is correct |
2 |
Correct |
57 ms |
8208 KB |
Output is correct |
3 |
Correct |
58 ms |
8188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
8268 KB |
Output is correct |
2 |
Correct |
75 ms |
8184 KB |
Output is correct |
3 |
Correct |
58 ms |
8136 KB |
Output is correct |