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)
  2. C++ / Говнокод #29233

    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
    const std::string programPath =
        "/root/CLionProjects/PetukhPlusPlus/program.petukh";
    
    const std::string lexerOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_lexer.txt";
    
    const std::string syntaxOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_syntax.txt";
    
    const std::string semanticOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_semantic.txt";
    
    const std::string polizOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_poliz.txt";

    Классика говнокода

    letipetukh1, 12 Февраля 2026

    Комментарии (2)
  3. C++ / Говнокод #29224

    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
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    cin >> N >> L >> T;
      total = 0;
      for (int i = 0; i < N; i++) {
        cin >> S[i] >> H[i] >> P[i];
        total += H[i] * P[i];
      }
      fix_order();
      for (int ind = 0; ind < N; ind++) {
        int len = ind + 1;
        set<pair<long long, int>> events, comps;
        vector<long long> sum_hp(len);
        copy(H, H + len, sum_hp.begin());
        sum_hp[ind] = 0;
        vector<int> ord(len);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](int i, int j) {
          return S[i] < S[j];
        });
        comps.emplace(T, -1);
        for (int i = 0; i < len; i++) {
          int j = i + 1;
          while (j < len && S[ord[i]] == S[ord[j]]) {
            sum_hp[ord[i]] += sum_hp[ord[j]];
            ++j;
          }
          comps.emplace(S[ord[i]], ord[i]);
          i = j - 1;
        }
        for (auto it = comps.begin(); next(it) != comps.end(); ++it) {
          long long dist = next(it)->first - it->first;
          int idx = it->second;
          if (sum_hp[idx] > 0) {
            events.emplace((dist + sum_hp[idx] - 1) / sum_hp[idx], idx);
          }
        }
        vector<bool> visited(len);
        vector<bool> added(len);
        long long good_sum = 0, last_time = 0, govno = T, rakom_bokom = 0;
        for (auto [spawn, i] : comps) {
          if (spawn >= S[ind] && i != -1) {
            good_sum += sum_hp[i];
            added[i] = true;
          }
        }
        auto Upd = [&](long long time) -> void {
          long long F = govno - S[ind] - rakom_bokom;
          if (F <= 0) {
            return;
          }
          long long r1 = clamp(F / (H[ind] + good_sum) + 1, last_time, time);
          long long r2 = good_sum == 0 ? time : clamp(F / good_sum + 1, last_time, time);
          dp_diff_i[last_time] += H[ind] * P[ind];
          dp_diff_i[r1] -= H[ind] * P[ind];
          dp_diff[r1] += F * P[ind];
          dp_diff[r2] -= F * P[ind];
          dp_diff_i[r1] -= good_sum * P[ind];
          dp_diff_i[r2] += good_sum * P[ind];
          last_time = time;
        };
        vector<bool> skip(len), finished(len);
        while (!events.empty()) {
          auto [time, i] = *events.begin();
          events.erase(events.begin());
          if (time > L) {
            break;
          }
          if (skip[i] || sum_hp[i] == 0) {
            continue;
          }
          Upd(time);
          auto it = comps.upper_bound({S[i], INT_MAX});
          if (it->second == -1 || finished[it->second]) {
            good_sum -= sum_hp[i];
            finished[i] = true;
            govno = S[i];
            continue;
          }
          if (!added[i] && it->second + sum_hp[i] * time >= S[ind]) {
            added[i] = true;
            good_sum += sum_hp[i];
            rakom_bokom += S[i] - S[ind];
          }
          sum_hp[i] += sum_hp[it->second];
          skip[it->second] = true;
          long long next_pos = next(it)->first;
          comps.erase(it);
          events.emplace(time + (next_pos - S[i] - sum_hp[i] * time + sum_hp[i] - 1) / sum_hp[i], i);
        }
        Upd(L + 1);
      }
      long long cur_diff = 0, cur_diff_i = 0;
      for (int i = 0; i <= L; i++) {
        cur_diff += dp_diff[i];
        cur_diff_i += dp_diff_i[i];
        dp[i] = cur_diff + cur_diff_i * i;
      }

    олимпиадное говно

    letipetukh1, 26 Января 2026

    Комментарии (1)
  4. C++ / Говнокод #29207

    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
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    #include <iostream>
    #include <type_traits>
    #include <mutex>
    #include <string>
    #include <memory>
    #include <vector>
    #include <chrono>
    
    void bad_function(void* data) {
       ///  НИКОГДА ТАК НЕ ПИШИ
        if (data) {
            std::cout << *(std::string*)data << "\n";
        }
    }
    
    template<typename T = std::string,
             typename Alloc = std::allocator<T>,
             typename = std::enable_if_t<std::is_constructible_v<T, const char*>>,
             typename Clock = std::chrono::high_resolution_clock,
             typename TimePoint = typename Clock::time_point>
    class GoodFunctionImpl {
    private:
        static std::recursive_mutex mtx_;
        Alloc alloc_;
        std::vector<T, Alloc> buffer_;
        std::string context_;
        TimePoint init_time_;
        
        template<typename U>
        using is_valid_type = std::conjunction<
            std::is_same<std::decay_t<U>, T>,
            std::is_constructible<T, U>
        >;
        
        void internal_log(const std::string& msg) {
            buffer_.push_back(T(msg.c_str()));
        }
        
    public:
        GoodFunctionImpl() : init_time_(Clock::now()) {
            internal_log("GoodFunctionImpl initialized");
        }
        
        template<typename U,
                 typename = std::enable_if_t<is_valid_type<U>::value>>
        decltype(auto) execute(U&& input) {
            std::lock_guard<std::recursive_mutex> lock(mtx_);
            
            internal_log("Processing started");
            
            T processed = std::forward<U>(input);
            
            auto duration = Clock::now() - init_time_;
            auto duration_ms = std::chrono::duration_cast<
                std::chrono::milliseconds>(duration).count();
            
            std::cout << processed << " (runtime: " 
                      << duration_ms << "ms)\n";
            
            internal_log("Processing completed");
            
            return processed;
        }
        
        size_t get_buffer_size() const { return buffer_.size(); }
    };
    
    template<typename T, typename Alloc, typename, typename Clock, typename TimePoint>
    std::recursive_mutex GoodFunctionImpl<T, Alloc, Clock, TimePoint>::mtx_;
    
    void good_function(const std::string& input) {
        // Пиши ВОТ ТАК
        // так делают все
        // это стабильно и надежно
        // так надо
        GoodFunctionImpl<> impl;
        auto result = impl.execute(input);
        
        std::cout << "Buffer entries: " 
                  << impl.get_buffer_size() << "\n";
    }

    lisp-worst-code, 06 Декабря 2025

    Комментарии (8)
  5. C++ / Говнокод #29202

    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
    void makeShape(ShapeArguments shape)
    {
        if (shape.type == ShapeType::Square)
        {
            throw Square(shape);
        }
    
        if (shape.type == ShapeType::Cicle)
        {
            throw Circle(shape);
        }
    }
    
    void handleShape(ShapeArguments shape)
    {
        try
        {
            makeShape(shape);
        }
        catch (const Square& square)
        {
            // Work with square
        }
        catch (const Circle& circle)
        {
            // Work with circle
        }
    }

    factory

    kcalbCube, 25 Ноября 2025

    Комментарии (2)
  6. C++ / Говнокод #29176

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    SparseMatrix<double> mat(rows,cols);
    for (int k=0; k<mat.outerSize(); ++k)
      for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
      {
        it.value();
        it.row();   // row index
        it.col();   // col index (here it is equal to k)
        it.index(); // inner index, here it is equal to it.row()
      }

    Random access to the elements of a sparse object can be done through the coeffRef(i,j) function. However, this function involves a quite expensive binary search. In most cases, one only wants to iterate over the non-zeros elements. This is achieved by a standard loop over the outer dimension, and then by iterating over the non-zeros of the current inner vector via an InnerIterator. Thus, the non-zero entries have to be visited in the same order than the storage order.

    CHayT, 03 Сентября 2025

    Комментарии (4)
  7. C++ / Говнокод #29105

    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
    // https://github.com/ggml-org/llama.cpp/blob/f4c3dd5daa3a79f713813cf1aabdc5886071061d/examples/simple/simple.cpp#L23
    
        // parse command line arguments
    
        {
            int i = 1;
            for (; i < argc; i++) {
                if (strcmp(argv[i], "-m") == 0) {
                    if (i + 1 < argc) {
                        model_path = argv[++i];
                    } else {
                        print_usage(argc, argv);
                        return 1;
                    }
                } else if (strcmp(argv[i], "-n") == 0) {
                    if (i + 1 < argc) {
                        try {
                            n_predict = std::stoi(argv[++i]);
                        } catch (...) {
                            print_usage(argc, argv);
                            return 1;
                        }
                    } else {
                        print_usage(argc, argv);
                        return 1;
                    }
                } else if (strcmp(argv[i], "-ngl") == 0) {
                    if (i + 1 < argc) {
                        try {
                            ngl = std::stoi(argv[++i]);
                        } catch (...) {
                            print_usage(argc, argv);
                            return 1;
                        }
                    } else {
                        print_usage(argc, argv);
                        return 1;
                    }
                } else {
                    // prompt starts here
                    break;
                }
            }
            if (model_path.empty()) {
                print_usage(argc, argv);
                return 1;
            }
            if (i < argc) {
                prompt = argv[i++];
                for (; i < argc; i++) {
                    prompt += " ";
                    prompt += argv[i];
                }
            }
        }

    Парсинг аргументов командной строки

    j123123, 16 Марта 2025

    Комментарии (8)
  8. C++ / Говнокод #29097

    0

    1. 1
    Мда... Какое же всё таки говнецо это Ваше США.

    3uMuCTOH, 04 Марта 2025

    Комментарии (3)
  9. C++ / Говнокод #29056

    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
    #include <iostream>
    
    union is_odd {
      long long int number;
      bool yes : sizeof(long long int);
    };
    
    int main() {
      std::boolalpha(std::cout);
      for (long long int i = -10; i < 10; ++i) {
        std::cout << i << " is odd? "
                  << is_odd{ .number = i }.yes
                  << "\n";
      }
    }

    DEMO:
    https://godbolt.org/z/5exc84eYK

    shittycode43, 15 Ноября 2024

    Комментарии (2)
  10. C++ / Говнокод #29054

    +1

    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
    xxx: Теперь сделайте так, чтобы цифры выводились следующим образом (используя программу из предыдущего задания):
                1
             2 1
          3 2 1
       4 3 2 1
    5 4 3 2 1
    
    yyy:
    
    #include <print>
    
    inline constexpr std::size_t kSize = 5;
    
    template <std::size_t N, std::size_t NN>
    constexpr auto operator+(const std::array<char, N>& first, const std::array<char, NN>& second) -> std::array<char, N + NN> {
      std::array<char, N + NN> response;  // NOLINT
      std::ranges::copy(first, response.begin());
      std::ranges::copy(second, response.begin() + first.size());
      return response;
    };
    
    auto main() -> int {
      []<std::size_t... Is>(std::index_sequence<Is...>) {
        // clang-format off
        ([&]<std::size_t... IIs, std::size_t... IIIs>(std::index_sequence<IIs...>, std::index_sequence<IIIs...>) {
          constexpr std::format_string<decltype(IIs)...> fmt = [] {
            static constexpr auto response = ((std::ignore = IIIs, std::array{' ', ' '}) + ... + ((std::ignore = IIs, std::array{'{', '}', ' '}) + ... + std::array{'\0'}));
            return response.begin();
          }();
          constexpr auto v = Is;
          std::println(fmt, (v - IIs + 1)...);
        }(std::make_index_sequence<Is + 1>(), std::make_index_sequence<kSize - Is - 1>()), ...);
        // clang-format on
      }(std::make_index_sequence<kSize>());
    };

    Fluttie, 07 Ноября 2024

    Комментарии (1)