Submission #1100888

# Submission time Handle Problem Language Result Execution time Memory
1100888 2024-10-15T01:28:11 Z huantran Selotejp (COCI20_selotejp) C++17
110 / 110
21 ms 528 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <numeric>
#include <random>
#include <chrono>
#include <fstream>
#include <stack>
#include <cmath>
#define bit(x, i) (((x) >> (i)) & 1LL)
#define rand rd
#define PI acos(-1)

using namespace std;
typedef long long int ll;
const int maxn = 1e5 + 5;
const ll mod = 998244353;
const int inf = 1e9 + 7;
const ll base = 1e5 + 7;
using pll = pair<ll, ll>;

const string NAME = "LOCO";
const int NTEST = 100;

mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());

ll Rand(ll l, ll r) {
    return l + rd() % (r - l + 1);
}

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

    int n, m;   
    cin >> n >> m;

    vector<int> dp(1100, inf), ans(1100);
    vector<vector<char>> adj(n, vector<char>(m));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)
            cin >> adj[i][j];
    }

    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int mask = 0; mask < (1 << m); mask++) {
                if (bit(mask, j) == 0) {
                    ans[mask] = min(dp[mask], dp[mask ^ (1 << j)]);
                    if ((j == 0 || (bit(mask, j - 1) == 1) || adj[i][j - 1] == '.') && adj[i][j] == '#')
                        ans[mask]++;
                }
                else {
                    if(adj[i][j] == '.') 
                        ans[mask] = inf;
					else 
                        ans[mask] = min(dp[mask], dp[mask ^ (1 << j)] + 1);
                }
                // cout << mask << ' ' << dp[mask] << '\n';
            }
            dp = ans;
            // cout << "Check: " << j << ' ' << *min_element(dp.begin(), dp.end()) << ' ' << dp[0] << dp[1] << dp[2] << dp[3] << '\n';
        }
        // cout << "Check: " << *min_element(dp.begin(), dp.end()) << '\n';
    }

    int res = inf;
    for (int i = 0; i < (1 << m); i++) 
        res = min(res, dp[i]);

    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 15 ms 520 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Correct 8 ms 336 KB Output is correct
5 Correct 19 ms 336 KB Output is correct
6 Correct 17 ms 520 KB Output is correct
7 Correct 17 ms 508 KB Output is correct
8 Correct 17 ms 352 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
10 Correct 21 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 15 ms 520 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Correct 8 ms 336 KB Output is correct
5 Correct 19 ms 336 KB Output is correct
6 Correct 17 ms 520 KB Output is correct
7 Correct 17 ms 508 KB Output is correct
8 Correct 17 ms 352 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
10 Correct 21 ms 528 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 4 ms 336 KB Output is correct
21 Correct 8 ms 528 KB Output is correct
22 Correct 18 ms 336 KB Output is correct
23 Correct 17 ms 336 KB Output is correct
24 Correct 17 ms 336 KB Output is correct
25 Correct 17 ms 336 KB Output is correct
26 Correct 16 ms 524 KB Output is correct
27 Correct 19 ms 336 KB Output is correct
28 Correct 16 ms 336 KB Output is correct