답안 #1080924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080924 2024-08-29T16:01:53 Z horiaboeriu Norela (info1cup18_norela) C++17
100 / 100
85 ms 604 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 && 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 cartiel 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:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
norela.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d", &nr);
      |         ~~~~~^~~~~~~~~~~
norela.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 6 ms 416 KB Output is correct
9 Correct 6 ms 416 KB Output is correct
10 Correct 11 ms 344 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 6 ms 416 KB Output is correct
9 Correct 6 ms 416 KB Output is correct
10 Correct 11 ms 344 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 7 ms 348 KB Output is correct
13 Correct 13 ms 348 KB Output is correct
14 Correct 11 ms 416 KB Output is correct
15 Correct 14 ms 604 KB Output is correct
16 Correct 13 ms 348 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 6 ms 416 KB Output is correct
9 Correct 6 ms 416 KB Output is correct
10 Correct 11 ms 344 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 7 ms 348 KB Output is correct
13 Correct 13 ms 348 KB Output is correct
14 Correct 11 ms 416 KB Output is correct
15 Correct 14 ms 604 KB Output is correct
16 Correct 13 ms 348 KB Output is correct
17 Correct 11 ms 348 KB Output is correct
18 Correct 22 ms 348 KB Output is correct
19 Correct 22 ms 348 KB Output is correct
20 Correct 85 ms 348 KB Output is correct
21 Correct 85 ms 344 KB Output is correct
22 Correct 43 ms 348 KB Output is correct
23 Correct 45 ms 344 KB Output is correct