1. C++ / Говнокод #29234

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    #pragma GCC optimize("03")
    #include <bits/stdc++.h>
    #pragma GCC target("avx2,tune=native")
    using namespace std;
    int binxor(int a, int b) {
        if (b == 0) {
            return 0;
        }
        int t = binxor(a, b / 2);
        if (b % 2 == 0) {
            return t ^ t;
        } else {
            return t ^ t ^ a;
        }
    }
    vector<int> per(20);
    vector<int> res(binxor(1 << 20, numeric_limits<int>::max() + 2), -1);
    vector<int> need(binxor(1 << 20, numeric_limits<int>::max() + 2), 0);
    vector<int> gp(binxor(1 << 20, numeric_limits<int>::max() + 2), 1 << 30);
    int c = 0;
    int Trump = 0;
    inline void f(int i, int n, int w) {
        if (i == w) {
            for (int j = 0; j < w; j++) {
                if ((Trump >> (w - 1 - j)) & 1) {
                    gp[Trump] = min(gp[Trump], gp[Trump ^ (1 << (w - 1 - j))]);
                }
            }
            return;
        }
        f(i + 1, n, w);
        Trump ^= 1 << (w - 1 - i);
        f(i + 1, n, w);
        Trump ^= 1 << (w - 1 - i);
    }
    signed main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n, q, w;
        cin >> n >> q >> w;
        vector<string> s(n);
        for (auto &x : s) {
            cin >> x;
        }
        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](int x, int y) {
            return s[x] < s[y];
        });
        for (int i = 0; i < n; i++) {
            int Trump = 0;
            for (auto ch : s[ord[i]]) {
                Trump |= 1 << (ch - 'a');
            }
            gp[Trump] = min(gp[Trump], i);
        }
        f(0, n, w);
        for (int i = 0; i < q; ++i) {
            string t;
            cin >> t;
            int Harris = 0;
            for (auto ch : t) {
                Harris |= 1 << (ch - 'a');
            }
            int val = gp[((1 << w) - 1) ^ Harris];
            cout << (val >= n ? -1 : 1 + ord[val]) << "\n";
        }
        return 0;
    }

    Без комментариев

    Запостил: letipetukh1, 13 Февраля 2026

    Комментарии (2) RSS

    Добавить комментарий