124282024-12-17 18:34:27szabelrSorozat generáláscpp17Compilation error
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>

int h(int x, int y) {
    return x > y;
}

using namespace std;

int main() {
    long long m, x, a, b, n, k;
    cin >> m >> x >> a >> b >> n >> k;

    int* sor = new int[n + 1];
    unordered_map<int, int> seen;
    long long min_distance = n + 1;

    sor[0] = x;
    for (int i = 1; i <= n; i++) {
        sor[i] = sor[i - 1] * a + b;
        string szam = to_string(sor[i]);
        while (szam.length() < 4 * m) {
            szam = '0' + szam;
        }
        szam = szam.substr(m, 2 * m);
        int jo = stoi(szam);

        if (seen.count(jo)) {
            // Calculate the distance
            min_distance = min(min_distance, i - seen[jo]);
        }
        seen[jo] = i;
        sor[i] = jo;
    }

    cout << min_distance << endl;

    sort(sor, sor + n + 1, h);
    cout << sor[k - 1] << endl;

    delete[] sor;
    return 0;
}
Compilation error
open /var/local/lib/isolate/411/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:33:31: error: no matching function for call to 'min(long long int&, int)'
   33 |             min_distance = min(min_distance, i - seen[jo]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/string:50,
                 from /usr/include/c++/12/bits/locale_classes.h:40,
                 from /usr/include/c++/12/bits/ios_base.h:41,
                 from /usr/include/c++/12/ios:42,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/iostream:39,
                 from main.cpp:1:
/usr/include/c++/12/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/12/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
main.cpp:33:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |             min_distance = min(min_distance, i - seen[jo]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/12/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
main.cpp:33:31: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |             min_distance = min(min_distance, i - seen[jo]);
      |                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/algorithm:61,
                 from main.cpp:5:
/usr/include/c++/12/bits/stl_algo.h:5726:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list...