# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
227943 |
2020-04-29T09:46:13 Z |
Vimmer |
Strah (COCI18_strah) |
C++14 |
|
1000 ms |
22776 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 2005
#define M ll(1e9 + 7)
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
//typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n, m, pr[N][N];
ll ans;
bool gd(int i, int j, int a, int b)
{
int sm = pr[i + a - 1][j + b - 1];
if (i != 0) sm -= pr[i - 1][j + b - 1];
if (j != 0) sm -= pr[i + a - 1][j - 1];
if (i != 0 && j != 0) sm += pr[i - 1][j - 1];
return sm == 0;
}
int opr(int i, int j, int x)
{
int l = 1, r = m - j;
while (l + 1 < r)
{
int md = (l + r) >> 1;
if (gd(i, j, x, md)) l = md; else r = md - 1;
}
while (l > 0 && !gd(i, j, x, l)) l--;
while (l < m - j && gd(i, j, x, l + 1)) l++;
return l;
}
int main()
{
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (i != 0) pr[i][j] += pr[i - 1][j];
if (j != 0) pr[i][j] += pr[i][j - 1];
if (i != 0 && j != 0) pr[i][j] -= pr[i - 1][j - 1];
if (s[i][j] == '#') pr[i][j]++;
}
for (int j = 0; j < m; j++)
{
vector <int> g; g.clear();
ll pr[n + 10];
bool f = 0;
for (int i = 0; i < n; i++)
{
if (s[i][j] == '#') {f = 0; continue;}
if (!f)
{
f = 1;
g.clear();
int a = 1;
g.pb(0);
while (a <= n - i)
{
int val = opr(i, j, a);
if (val == 0) break;
int l = a, r = n - i;
while (l + 1 < r)
{
int md = (l + r) >> 1;
if (opr(i, j, md) == val) l = md; else r = md - 1;
}
while (l > a && opr(i, j, l) != val) l--;
while (l < n - i && opr(i, j, l + 1) == val) l++;
ll lst = a - 1;
lst = (lst * (lst + 1)) / 2;
ll s = l, st = val;
st = (st * (st + 1)) / 2;
s = (s * (s + 1)) / 2;
s -= lst;
ans += s * st;
pr[a] = s * st;
a = l + 1;
g.pb(i + a - 1);
pr[i + a - 1] = 0;
}
int lst = -1;
for (int i = sz(g) - 2; i >= 0; i--)
{
if (lst != -1) pr[g[i]] += pr[lst];
lst = g[i];
}
}
else
{
while (g.back() < i) g.pop_back();
if (sz(g) == 0) break;
int a = 1;
while (i + a - 1 < g.back())
{
int val = opr(i, j, a);
if (val == 0) break;
int l = a, r = g.back() - i;
while (l + 1 < r)
{
int md = (l + r) >> 1;
if (opr(i, j, md) == val) l = md; else r = md - 1;
}
while (l > a && opr(i, j, l) != val) l--;
while (l < g.back() - i && opr(i, j, l + 1) == val) l++;
ll lst = a - 1;
lst = (lst * (lst + 1)) / 2;
ll s = l, st = val;
st = (st * (st + 1)) / 2;
s = (s * (s + 1)) / 2;
s -= lst;
ans += s * st;
a = l + 1;
}
ans += pr[g.back()];
}
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2048 KB |
Output is correct |
2 |
Correct |
123 ms |
2128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
2048 KB |
Output is correct |
2 |
Correct |
73 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
2048 KB |
Output is correct |
2 |
Correct |
72 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
9096 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
16768 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
15736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
10240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
9216 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
20088 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
22776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |