#include <stdio.h>
#define MAX_M 24
struct aaa {
int usedSpells;
long long xor;
};
struct aaa v[1 << (MAX_M / 2)];
long long spell[MAX_M];
int main() {
int n, m, k, p, minUsedSpells, usedSpells, solMask, mask1, mask2, i, j;
long long xor;
scanf( "%d%d", &n, &m );
for ( i = 0; i < m; i++ ) {
scanf( "%d", &k );
spell[i] = 0;
for ( j = 0; j < k; j++ ) {
scanf( "%d", &p );
spell[i] += ((long long)1 << (p - 1));
}
}
for ( mask1 = 0; mask1 < (1 << (m / 2)); mask1++ ) {
xor = 0;
usedSpells = 0;
for ( i = 0; i < m / 2; i++ ) {
if ( ((mask1 >> i) & 1) == 1 ) {
xor ^= spell[m - 1 - i];
usedSpells++;
}
}
v[mask1].xor = xor;
v[mask1].usedSpells = usedSpells;
}
minUsedSpells = m + 1;
solMask = -1;
for ( mask2 = 0; mask2 < (1 << (m - m / 2)); mask2++ ) {
xor = 0;
usedSpells = 0;
for ( i = 0; i < m - m / 2; i++ ) {
if ( ((mask2 >> i) & 1) == 1 ) {
xor ^= spell[m - m / 2 - 1 - i];
usedSpells++;
}
}
for ( mask1 = 0; mask1 < (1 << (m / 2)); mask1++ ) {
if ( (v[mask1].xor ^ xor) == ((long long)1 << n) - 1 ) {
if ( v[mask1].usedSpells + usedSpells < minUsedSpells ) {
minUsedSpells = v[mask1].usedSpells + usedSpells;
solMask = mask1 + mask2 * (1 << (m / 2));
}
else if ( v[mask1].usedSpells + usedSpells == minUsedSpells ) {
if ( mask1 + mask2 * (1 << (m / 2)) > solMask )
solMask = mask1 + mask2 * (1 << (m / 2));
}
}
}
}
printf( "%d\n", minUsedSpells );
for ( i = m - 1; i >= 0; i-- ) {
if ( ((solMask >> i) & 1) == 1 )
printf( "%d ", m - i );
}
return 0;
}
Compilation message
norela.c: In function 'main':
norela.c:18:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf( "%d%d", &n, &m );
| ^~~~~~~~~~~~~~~~~~~~~~~
norela.c:20:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf( "%d", &k );
| ^~~~~~~~~~~~~~~~~
norela.c:23:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf( "%d", &p );
| ^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
204 KB |
Output is correct |
9 |
Correct |
3 ms |
292 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
204 KB |
Output is correct |
9 |
Correct |
3 ms |
292 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
12 |
Correct |
3 ms |
288 KB |
Output is correct |
13 |
Correct |
5 ms |
204 KB |
Output is correct |
14 |
Correct |
5 ms |
204 KB |
Output is correct |
15 |
Correct |
5 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
304 KB |
Output is correct |
17 |
Correct |
5 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
3 ms |
204 KB |
Output is correct |
9 |
Correct |
3 ms |
292 KB |
Output is correct |
10 |
Correct |
3 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
204 KB |
Output is correct |
12 |
Correct |
3 ms |
288 KB |
Output is correct |
13 |
Correct |
5 ms |
204 KB |
Output is correct |
14 |
Correct |
5 ms |
204 KB |
Output is correct |
15 |
Correct |
5 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
304 KB |
Output is correct |
17 |
Correct |
5 ms |
204 KB |
Output is correct |
18 |
Correct |
10 ms |
204 KB |
Output is correct |
19 |
Correct |
10 ms |
204 KB |
Output is correct |
20 |
Correct |
19 ms |
384 KB |
Output is correct |
21 |
Correct |
18 ms |
344 KB |
Output is correct |
22 |
Correct |
19 ms |
280 KB |
Output is correct |
23 |
Correct |
19 ms |
332 KB |
Output is correct |