답안 #475594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475594 2021-09-23T07:32:17 Z abc864197532 Selotejp (COCI20_selotejp) C++17
110 / 110
147 ms 364 KB
/*
 *   ##   #####   ####      ####  #    #  ####
 *  #  #  #    # #    #    #    # #    # #    #
 * #    # #####  #         #    # #    # #    #
 * ###### #    # #         #    # # ## # #    #
 * #    # #    # #    #    #    # ##  ## #    #
 * #    # #####   ####      ####  #    #  ####
 */
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define info() cout << __PRETTY_FUNCTION__ << ": " << __LINE__ << endl
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    if (a.empty()) return o << "{}";
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
    vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
    vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
    vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
    vvv() {}
};
#ifdef Doludu
#define test(args...) info(), abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); 
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 998244353, N = 300001, logN = 20, K = 111;

int main () {
    owo;
    int n, m;
    cin >> n >> m;
    vector <string> t(n);
    for (int i = 0; i < n; ++i)
        cin >> t[i];
    vector <int> pre(1 << m + 1, 1 << 30), dp;
    pre[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            dp.assign(1 << m + 1, 1 << 30);
            for (int s = 0; s < 1 << m + 1; ++s) {
                if (t[i][j] == '#') {
                    if (s >> m & 1 && s >> j & 1) {
                        dp[s ^ (1 << m)] = min(dp[s ^ (1 << m)], pre[s]);
                        dp[s ^ (1 << j)] = min(dp[s ^ (1 << j)], pre[s]);
                    } else if (s >> m & 1 || s >> j & 1)
                        dp[s] = min(dp[s], pre[s]);
                    else {
                        dp[s ^ (1 << m)] = min(dp[s ^ (1 << m)], pre[s] + 1);
                        dp[s ^ (1 << j)] = min(dp[s ^ (1 << j)], pre[s] + 1);
                    }
                } else {
                    int nxt = s;
                    if (s >> m & 1)
                        nxt ^= 1 << m;
                    if (s >> j & 1)
                        nxt ^= 1 << j;
                    dp[nxt] = min(dp[nxt], pre[s]);
                }
            }
            pre = dp;
        }
        for (int s = 0; s < 1 << m; ++s)
            pre[s] = min(pre[s], pre[s ^ (1 << m)]), pre[s ^ (1 << m)] = 1 << 30;
    }
    int ans = 1 << 30;
    for (int i : pre)
        ans = min(ans, i);
    cout << ans << endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:64:29: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   64 |     vector <int> pre(1 << m + 1, 1 << 30), dp;
      |                           ~~^~~
Main.cpp:68:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   68 |             dp.assign(1 << m + 1, 1 << 30);
      |                            ~~^~~
Main.cpp:69:40: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   69 |             for (int s = 0; s < 1 << m + 1; ++s) {
      |                                      ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 147 ms 332 KB Output is correct
3 Correct 25 ms 332 KB Output is correct
4 Correct 61 ms 332 KB Output is correct
5 Correct 135 ms 344 KB Output is correct
6 Correct 135 ms 332 KB Output is correct
7 Correct 130 ms 348 KB Output is correct
8 Correct 131 ms 336 KB Output is correct
9 Correct 127 ms 336 KB Output is correct
10 Correct 126 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 308 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 147 ms 332 KB Output is correct
3 Correct 25 ms 332 KB Output is correct
4 Correct 61 ms 332 KB Output is correct
5 Correct 135 ms 344 KB Output is correct
6 Correct 135 ms 332 KB Output is correct
7 Correct 130 ms 348 KB Output is correct
8 Correct 131 ms 336 KB Output is correct
9 Correct 127 ms 336 KB Output is correct
10 Correct 126 ms 332 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 308 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 29 ms 332 KB Output is correct
21 Correct 60 ms 344 KB Output is correct
22 Correct 146 ms 352 KB Output is correct
23 Correct 144 ms 348 KB Output is correct
24 Correct 135 ms 348 KB Output is correct
25 Correct 127 ms 348 KB Output is correct
26 Correct 118 ms 344 KB Output is correct
27 Correct 100 ms 364 KB Output is correct
28 Correct 102 ms 356 KB Output is correct