# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
582537 |
2022-06-24T04:35:36 Z |
vuavisao |
Bob (COCI14_bob) |
C++14 |
|
1000 ms |
17936 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 <= n && 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 |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
4768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
5380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
5360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
14900 KB |
Output is correct |
2 |
Correct |
65 ms |
10184 KB |
Output is correct |
3 |
Correct |
55 ms |
10160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
17936 KB |
Output is correct |
2 |
Correct |
73 ms |
10196 KB |
Output is correct |
3 |
Execution timed out |
1077 ms |
6220 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
17776 KB |
Output is correct |
2 |
Correct |
58 ms |
10228 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
6220 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
17880 KB |
Output is correct |
2 |
Correct |
71 ms |
10188 KB |
Output is correct |
3 |
Execution timed out |
1079 ms |
6096 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |