Skip to content

Commit

Permalink
ABC356C Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicfred committed Jun 3, 2024
1 parent 6177a6e commit 98ca109
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions atcoder/abc356c_keys.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Vicfred
// https://atcoder.jp/contests/abc356/tasks/abc356_c
// brute force, bitmask
#include <iostream>
#include <vector>

using namespace std;

int main() {
int N, M, K;
cin >> N >> M >> K;
vector<int> C(M);
vector<char> R(M);
vector<vector<int>> A(M);
for (int i = 0; i < M; ++i) {
cin >> C[i];
A[i] = vector<int>(C[i]);
for (int j = 0; j < C[i]; ++j) {
cin >> A[i][j];
}
cin >> R[i];
}
long long answer = 0LL;
for (int mask = 0; mask < (1 << N); ++mask) {
// cout << "mask: " << mask << endl;
bool valid = true;
for (int i = 0; i < M; ++i) {
int valid_keys = 0;
for (int key = 0; key < C[i]; ++key) {
if (mask & (1 << (A[i][key] - 1))) {
valid_keys += 1;
}
}
// cout << "A[" << i << "]:" << endl;
// for (int idx = 0; idx < C[i]; ++idx) {
// cout << A[i][idx] << " ";
// }
// cout << endl;
// cout << "valid keys: " << valid_keys << endl;
if ((valid_keys >= K and R[i] == 'x') or
(valid_keys < K and R[i] == 'o')) {
valid = false;
break;
}
}
// cout << "=====" << endl;
if (valid) {
answer += 1LL;
}
}
cout << answer << endl;
return 0;
}

0 comments on commit 98ca109

Please sign in to comment.