답안 #303846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303846 2020-09-20T17:03:30 Z AM1648 Raspad (COI17_raspad) C++17
100 / 100
373 ms 43640 KB
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 100010;
const ll maxm = 51;

ll n, m, ql, qr;
pii q[maxn * maxm];
long long V, E, F, C;
bool A[maxn][maxm], vis[maxn][maxm];
ll adj[8][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m;
    fori (i, n) fori (j, m) {
        char c; cin >> c;
        A[i][j] = c == '1';
    }

    fori (i, n) fori (j, m) {
        if (A[i][j]) {
            V += 1LL * (i + 1) * (n - i);
            if (A[i][j + 1]) E += 1LL * (i + 1) * (n - i);
            if (A[i + 1][j]) E += 1LL * (i + 1) * (n - 1 - i);
            if (A[i][j + 1] && A[i + 1][j] && A[i + 1][j + 1]) F += 1LL * (i + 1) * (n - 1 - i);
        } else if (!vis[i][j]) {
            ll up = i, dw = i, lt = j, rt = j;
            vis[i][j] = 1;
            q[qr++] = {i, j};
            while (ql < qr) {
                auto [x, y] = q[ql++];
                smax(dw, x), smin(up, x);
                smax(rt, y), smin(lt, y);
                fori (k, 8) {
                    ll xx = x + adj[k][0];
                    ll yy = y + adj[k][1];
                    if (0 <= xx && xx < n && 0 <= yy && yy < m && !A[xx][yy] && !vis[xx][yy]) {
                        vis[xx][yy] = 1;
                        q[qr++] = {xx, yy};
                    }
                }
            }
            if (lt > 0 && rt < m - 1) F += 1LL * up * (n - 1 - dw);
        }
    }

    C = V - E + F;
    cout << C << '\n';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2816 KB Output is correct
2 Correct 120 ms 17904 KB Output is correct
3 Correct 93 ms 16120 KB Output is correct
4 Correct 57 ms 15992 KB Output is correct
5 Correct 37 ms 6136 KB Output is correct
6 Correct 109 ms 19196 KB Output is correct
7 Correct 70 ms 19232 KB Output is correct
8 Correct 65 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 18 ms 2816 KB Output is correct
15 Correct 120 ms 17904 KB Output is correct
16 Correct 93 ms 16120 KB Output is correct
17 Correct 57 ms 15992 KB Output is correct
18 Correct 37 ms 6136 KB Output is correct
19 Correct 109 ms 19196 KB Output is correct
20 Correct 70 ms 19232 KB Output is correct
21 Correct 65 ms 14456 KB Output is correct
22 Correct 241 ms 25336 KB Output is correct
23 Correct 277 ms 29052 KB Output is correct
24 Correct 214 ms 25084 KB Output is correct
25 Correct 358 ms 40572 KB Output is correct
26 Correct 186 ms 34956 KB Output is correct
27 Correct 286 ms 34040 KB Output is correct
28 Correct 240 ms 27512 KB Output is correct
29 Correct 373 ms 36696 KB Output is correct
30 Correct 184 ms 34936 KB Output is correct
31 Correct 186 ms 34960 KB Output is correct
32 Correct 227 ms 43640 KB Output is correct
33 Correct 212 ms 30968 KB Output is correct
34 Correct 259 ms 31484 KB Output is correct