답안 #209715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209715 2020-03-15T11:50:08 Z AM1648 Raspad (COI17_raspad) C++17
0 / 100
87 ms 80168 KB
/* be name khoda */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;

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

#define S second
#define F first
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

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

const ll maxn = 100010;
const ll maxm = 50;

ll n, m;
ll grid[maxn][maxm];
ll dp[maxn][maxm];

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    // ifstream cin("C.in");

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

    ll cc = 0;
    fori (i, m) {
        if (grid[0][i] == 1 && grid[0][i + 1] == 0) dp[0][i] = 1, ++cc;
    }

    ll ans = cc;
    forifrom (i, 1, n) {
        forir (j, m) {
            if (grid[i - 1][j] && grid[i - 1][j + 1] && !grid[i][j + 1]) {
                dp[i - 1][j] = dp[i - 1][j + 1];
                dp[i - 1][j + 1] = 0;
            }
        }
        fori (j, m) {
            if (grid[i][j] && grid[i - 1][j]) {
                dp[i][j] = dp[i - 1][j] + 1;
                ++cc;
                dp[i - 1][j] = 0;
                cc -= dp[i][j - 1];
                dp[i][j - 1] = 0;
            } else if (grid[i][j] && grid[i][j - 1]) {
                dp[i][j] = dp[i][j - 1];
                dp[i][j - 1] = 0;
            } else if (grid[i][j]) {
                dp[i][j] = i + 1;
                cc += i + 1;
            }
        }
        ans += cc;
    }
    cout << ans << '\n';
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 40184 KB Output is correct
2 Incorrect 87 ms 80168 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -