124302024-12-17 18:47:22szabelrSorozat generáláscpp17Partially correct 49/5032ms1332 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;
    vector<long long> sor(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)) {
            min_distance = min(min_distance, i - seen[jo]);
        }
        seen[jo] = i;
        sor[i] = jo;
    }
    cout << min_distance << endl;
    sort(sor.begin() + 1, sor.end(), h);
    cout << sor[k - 1] << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base49/50
1Accepted0/01ms320 KiB
2Accepted0/030ms1080 KiB
3Partially correct1/21ms320 KiB
4Accepted2/22ms320 KiB
5Accepted2/22ms320 KiB
6Accepted2/21ms320 KiB
7Accepted2/22ms320 KiB
8Accepted4/43ms320 KiB
9Accepted4/46ms592 KiB
10Accepted4/413ms828 KiB
11Accepted4/412ms824 KiB
12Accepted4/417ms976 KiB
13Accepted4/421ms1204 KiB
14Accepted4/430ms1212 KiB
15Accepted4/428ms1268 KiB
16Accepted4/430ms1280 KiB
17Accepted4/432ms1332 KiB