Submission #261963

# Submission time Handle Problem Language Result Execution time Memory
261963 2020-08-12T08:31:30 Z Vimmer Raspad (COI17_raspad) C++14
100 / 100
399 ms 46840 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;

ll n, m, mx, mn;

bool mk[N][55];

ll 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(ll x, ll y)
{
    mx = max(mx, x);

    mn = min(mn, x);

    mk[x][y] = 1;

    if (y == 0 || y == m - 1) bad = 1;

    for (ll i = 0; i < 8; i++)
    {
        ll 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 (ll i = 0; i < n; i++) cin >> s[i];

    ll ans = 0;

    for (ll i = 0; i < n; i++)
      for (ll 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 (ll i = 0; i < n - 1; i++)
        for (ll j = 0; j < m; j++)
          if (s[i][j] == '1' && s[i + 1][j] == '1')
              ans -= 1ll * (i + 1) * (n - i - 1);

    for (ll i = 0; i < n - 1; i++)
        for (ll 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 (ll i = 0; i < n; i++)
        for (ll j = 0; j < m; j++)
          if (!mk[i][j] && s[i][j] == '0')
          {
              bad = 0; mx = mn = i;

              dfs(i, j);

              if (!bad) ans += 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 3 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 3 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 3 ms 3584 KB Output is correct
11 Correct 7 ms 3840 KB Output is correct
12 Correct 4 ms 3584 KB Output is correct
13 Correct 5 ms 3524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3456 KB Output is correct
2 Correct 130 ms 15096 KB Output is correct
3 Correct 92 ms 10360 KB Output is correct
4 Correct 51 ms 29432 KB Output is correct
5 Correct 37 ms 5684 KB Output is correct
6 Correct 113 ms 10488 KB Output is correct
7 Correct 47 ms 10360 KB Output is correct
8 Correct 54 ms 9080 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 3 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 3 ms 3584 KB Output is correct
11 Correct 7 ms 3840 KB Output is correct
12 Correct 4 ms 3584 KB Output is correct
13 Correct 5 ms 3524 KB Output is correct
14 Correct 11 ms 3456 KB Output is correct
15 Correct 130 ms 15096 KB Output is correct
16 Correct 92 ms 10360 KB Output is correct
17 Correct 51 ms 29432 KB Output is correct
18 Correct 37 ms 5684 KB Output is correct
19 Correct 113 ms 10488 KB Output is correct
20 Correct 47 ms 10360 KB Output is correct
21 Correct 54 ms 9080 KB Output is correct
22 Correct 267 ms 29944 KB Output is correct
23 Correct 278 ms 20088 KB Output is correct
24 Correct 202 ms 20088 KB Output is correct
25 Correct 352 ms 46840 KB Output is correct
26 Correct 149 ms 23288 KB Output is correct
27 Correct 280 ms 19624 KB Output is correct
28 Correct 255 ms 19192 KB Output is correct
29 Correct 399 ms 39160 KB Output is correct
30 Correct 139 ms 23288 KB Output is correct
31 Correct 142 ms 26360 KB Output is correct
32 Correct 144 ms 20176 KB Output is correct
33 Correct 169 ms 18424 KB Output is correct
34 Correct 243 ms 18680 KB Output is correct