124292024-12-17 18:39:57szabelrSorozat generáláscpp17Wrong answer 16/5035ms828 KiB
#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;
    int 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;
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Wrong answer0/01ms500 KiB
2Wrong answer0/032ms820 KiB
3Partially correct1/21ms320 KiB
4Partially correct1/22ms320 KiB
5Partially correct1/22ms320 KiB
6Partially correct1/21ms320 KiB
7Accepted2/22ms320 KiB
8Partially correct2/43ms320 KiB
9Partially correct2/46ms320 KiB
10Partially correct2/413ms588 KiB
11Partially correct2/410ms576 KiB
12Partially correct2/417ms600 KiB
13Wrong answer0/428ms624 KiB
14Wrong answer0/432ms740 KiB
15Wrong answer0/432ms824 KiB
16Wrong answer0/435ms680 KiB
17Wrong answer0/435ms828 KiB