# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
261964 |
2020-08-12T08:32:02 Z |
Vimmer |
Raspad (COI17_raspad) |
C++14 |
|
420 ms |
41848 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 pf push_front
#define N 100005
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 4> a4;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n, m, mx, mn;
bool mk[N][55];
int a[8][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
bool bad = 0;
string s[N];
void dfs(int x, int y)
{
mx = max(mx, x);
mn = min(mn, x);
mk[x][y] = 1;
if (y == 0 || y == m - 1) bad = 1;
for (int i = 0; i < 8; i++)
{
int cx = x + a[i][0], cy = y + a[i][1];
if (cx >= 0 && cx < n && cy >= 0 && cy < m && !mk[cx][cy] && s[cx][cy] == '0') dfs(cx, cy);
}
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
ll ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (s[i][j] == '1')
{
ans += 1ll * (i + 1) * (n - i);
if (j != 0 && s[i][j - 1] == '1') ans -= 1ll * (i + 1) * (n - i);
}
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < m; j++)
if (s[i][j] == '1' && s[i + 1][j] == '1')
ans -= 1ll * (i + 1) * (n - i - 1);
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < m - 1; j++)
if (s[i][j] == '1' && s[i + 1][j + 1] == '1' && s[i + 1][j] == '1' && s[i][j + 1] == '1') ans += 1ll * (i + 1) * (n - i - 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (!mk[i][j] && s[i][j] == '0')
{
bad = 0; mx = mn = i;
dfs(i, j);
if (!bad) ans += 1ll * mn * (n - mx - 1);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3584 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
2 ms |
3456 KB |
Output is correct |
4 |
Correct |
2 ms |
3456 KB |
Output is correct |
5 |
Correct |
3 ms |
3456 KB |
Output is correct |
6 |
Correct |
3 ms |
3456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3584 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
2 ms |
3456 KB |
Output is correct |
4 |
Correct |
2 ms |
3456 KB |
Output is correct |
5 |
Correct |
3 ms |
3456 KB |
Output is correct |
6 |
Correct |
3 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
4224 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
6 ms |
3584 KB |
Output is correct |
10 |
Correct |
4 ms |
3584 KB |
Output is correct |
11 |
Correct |
6 ms |
3840 KB |
Output is correct |
12 |
Correct |
3 ms |
3584 KB |
Output is correct |
13 |
Correct |
5 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
3456 KB |
Output is correct |
2 |
Correct |
135 ms |
15068 KB |
Output is correct |
3 |
Correct |
93 ms |
8824 KB |
Output is correct |
4 |
Correct |
56 ms |
28284 KB |
Output is correct |
5 |
Correct |
39 ms |
5248 KB |
Output is correct |
6 |
Correct |
116 ms |
8824 KB |
Output is correct |
7 |
Correct |
50 ms |
8824 KB |
Output is correct |
8 |
Correct |
56 ms |
7800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3584 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
2 ms |
3456 KB |
Output is correct |
4 |
Correct |
2 ms |
3456 KB |
Output is correct |
5 |
Correct |
3 ms |
3456 KB |
Output is correct |
6 |
Correct |
3 ms |
3456 KB |
Output is correct |
7 |
Correct |
6 ms |
4224 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
6 ms |
3584 KB |
Output is correct |
10 |
Correct |
4 ms |
3584 KB |
Output is correct |
11 |
Correct |
6 ms |
3840 KB |
Output is correct |
12 |
Correct |
3 ms |
3584 KB |
Output is correct |
13 |
Correct |
5 ms |
3584 KB |
Output is correct |
14 |
Correct |
10 ms |
3456 KB |
Output is correct |
15 |
Correct |
135 ms |
15068 KB |
Output is correct |
16 |
Correct |
93 ms |
8824 KB |
Output is correct |
17 |
Correct |
56 ms |
28284 KB |
Output is correct |
18 |
Correct |
39 ms |
5248 KB |
Output is correct |
19 |
Correct |
116 ms |
8824 KB |
Output is correct |
20 |
Correct |
50 ms |
8824 KB |
Output is correct |
21 |
Correct |
56 ms |
7800 KB |
Output is correct |
22 |
Correct |
272 ms |
26744 KB |
Output is correct |
23 |
Correct |
287 ms |
15096 KB |
Output is correct |
24 |
Correct |
219 ms |
15096 KB |
Output is correct |
25 |
Correct |
371 ms |
41848 KB |
Output is correct |
26 |
Correct |
149 ms |
18248 KB |
Output is correct |
27 |
Correct |
312 ms |
15736 KB |
Output is correct |
28 |
Correct |
281 ms |
15096 KB |
Output is correct |
29 |
Correct |
420 ms |
34296 KB |
Output is correct |
30 |
Correct |
149 ms |
18296 KB |
Output is correct |
31 |
Correct |
171 ms |
21368 KB |
Output is correct |
32 |
Correct |
155 ms |
15096 KB |
Output is correct |
33 |
Correct |
184 ms |
13944 KB |
Output is correct |
34 |
Correct |
257 ms |
14200 KB |
Output is correct |