답안 #498984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498984 2021-12-26T21:52:14 Z Victor Selotejp (COCI20_selotejp) C++17
110 / 110
186 ms 81728 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

int rows, cols, memo[1001][1 << 10][10][2];
string grid[1001];

int turn_off(int mask, int col) { return mask & ((1 << cols) - 1 - (1 << col)); }

int dp(int row, int mask, int col, int prev) {
    if (row == rows) return 0;

    int &ans = memo[row][mask][col][prev];
    if (ans != -1) return ans;

    int ncol = col + 1, nrow = row;
    if (ncol == cols) {
        ncol = 0;
        ++nrow;
    }

    if (grid[row][col] == '.') {
        ans = dp(nrow, turn_off(mask, col), ncol, 0);

    } else {
        int add = !prev;
        ans = dp(nrow, turn_off(mask, col), ncol, 1 && ncol) + add;

        add = (mask & (1 << col)) == 0;
        ans = min(ans, dp(nrow, mask | (1 << col), ncol, 0) + add);
        //cout << "row = " << row << " mask = " << mask << " col = " << col << " prev = " << prev<<" ans = "<<ans << endl;
    }

    return ans;
}

void print_dp(int row, int mask,int col,int prev) {
    if(row==rows)return;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    memset(memo, -1, sizeof(memo));
    cin >> rows >> cols;
    rep(i, 0, rows) cin >> grid[i];
    cout << dp(0, 0, 0, 0) << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 80588 KB Output is correct
2 Correct 40 ms 81472 KB Output is correct
3 Correct 32 ms 81304 KB Output is correct
4 Correct 34 ms 81532 KB Output is correct
5 Correct 35 ms 81620 KB Output is correct
6 Correct 35 ms 81648 KB Output is correct
7 Correct 34 ms 81628 KB Output is correct
8 Correct 32 ms 81524 KB Output is correct
9 Correct 33 ms 81524 KB Output is correct
10 Correct 84 ms 81600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 80460 KB Output is correct
2 Correct 29 ms 80528 KB Output is correct
3 Correct 32 ms 80452 KB Output is correct
4 Correct 30 ms 80492 KB Output is correct
5 Correct 34 ms 80544 KB Output is correct
6 Correct 42 ms 80492 KB Output is correct
7 Correct 37 ms 80564 KB Output is correct
8 Correct 29 ms 80544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 80588 KB Output is correct
2 Correct 40 ms 81472 KB Output is correct
3 Correct 32 ms 81304 KB Output is correct
4 Correct 34 ms 81532 KB Output is correct
5 Correct 35 ms 81620 KB Output is correct
6 Correct 35 ms 81648 KB Output is correct
7 Correct 34 ms 81628 KB Output is correct
8 Correct 32 ms 81524 KB Output is correct
9 Correct 33 ms 81524 KB Output is correct
10 Correct 84 ms 81600 KB Output is correct
11 Correct 29 ms 80460 KB Output is correct
12 Correct 29 ms 80528 KB Output is correct
13 Correct 32 ms 80452 KB Output is correct
14 Correct 30 ms 80492 KB Output is correct
15 Correct 34 ms 80544 KB Output is correct
16 Correct 42 ms 80492 KB Output is correct
17 Correct 37 ms 80564 KB Output is correct
18 Correct 29 ms 80544 KB Output is correct
19 Correct 30 ms 81080 KB Output is correct
20 Correct 35 ms 81392 KB Output is correct
21 Correct 37 ms 81508 KB Output is correct
22 Correct 31 ms 81608 KB Output is correct
23 Correct 34 ms 81520 KB Output is correct
24 Correct 36 ms 81592 KB Output is correct
25 Correct 45 ms 81568 KB Output is correct
26 Correct 101 ms 81572 KB Output is correct
27 Correct 137 ms 81512 KB Output is correct
28 Correct 186 ms 81728 KB Output is correct