답안 #1080931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080931 2024-08-29T16:05:37 Z horiaboeriu Norela (info1cup18_norela) C++17
100 / 100
26 ms 420 KB
#include <stdio.h>
#include <stdlib.h>
#define MAXM 24
long long v[MAXM];
int m, min, rez;//voi tine trucurile din rezultat tot sub forma unei masti in loc de vector
long long p;
void bkt(int nr, long long x, int stare, int poz) {
    int i;
    if (nr < min) {
        if (x == p) {
            //este prima combinatie gasita cu acest nr de trucuri, deci este prima lexicografica
            rez = stare;
            min = nr;
        } else {
            for (i = poz + 1; i < m; i++) {
                bkt(nr + 1, x ^ v[i], stare ^ (1 << i), i);
            }
        }
    }
}
int main()
{
    int n, x, i, nr, j;
    //tin la fiecare m o masca cu cartile, adica le transform in putrei ale lui 2
    //dupa iau toate combinarile din cele m cu un backtracking si fac xorul mastilor din combinare
    //ca trebuie ca fiecare carte sa apara de un numar impar ca sa fie pe fata
    //si trebuie ca xorul lor sa fie (1 << n) - 1
    scanf("%d%d", &n, &m);
    for (i = 0; i < m; i++) {
        scanf("%d", &nr);
        for (j = 0; j < nr; j++) {
            scanf("%d", &x);
            x--;//indexez cartile de la 0
            v[i] += ((long long)1 << x);
        }
    }
    p = ((long long)1 << n) - 1;//daca xorul este p, atunci toate cartile sunt pe fata
    min = m + 1;
    bkt(0, 0, 0, -1);
    printf("%d\n", min);
    for (i = 0; i < m; i++) {
        if (((1 << i) & rez) > 0) {//daca bitul i face parte din rezultat
            printf("%d ", i + 1);
        }
    }
    fputc('\n', stdout);
    return 0;
}

Compilation message

norela.cpp: In function 'int main()':
norela.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
norela.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d", &nr);
      |         ~~~~~^~~~~~~~~~~
norela.cpp:32:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 416 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 416 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 9 ms 416 KB Output is correct
15 Correct 3 ms 420 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 4 ms 416 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 9 ms 416 KB Output is correct
15 Correct 3 ms 420 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 4 ms 348 KB Output is correct
18 Correct 9 ms 344 KB Output is correct
19 Correct 6 ms 344 KB Output is correct
20 Correct 26 ms 420 KB Output is correct
21 Correct 25 ms 348 KB Output is correct
22 Correct 11 ms 348 KB Output is correct
23 Correct 17 ms 348 KB Output is correct