123362024-12-12 17:47:29szabelrSorozat generáláscpp17Runtime error 1/502ms604 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()
{
    int m, x, a, b, n, k;
    cin >> m >> x >> a >> b >> n >> k;
    int sor[1001];
    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)) {
            // Számítsuk ki a távolságot
            min_distance = min(min_distance, i - seen[jo]);
        }
        seen[jo] = i;
        sor[i] = jo;
    }
    /*for(int i=1; i<=n; i++){
        cout<<sor[i]<<" ";
    }*/
    cout << min_distance << endl;
	sort(sor, sor + n + 1, h);
	cout << sor[k - 1] << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/01ms320 KiB
2Runtime error0/02ms508 KiB
3Partially correct1/21ms320 KiB
4Runtime error0/22ms320 KiB
5Runtime error0/21ms568 KiB
6Runtime error0/21ms320 KiB
7Runtime error0/22ms604 KiB
8Runtime error0/41ms320 KiB
9Runtime error0/42ms320 KiB
10Runtime error0/41ms320 KiB
11Runtime error0/41ms320 KiB
12Runtime error0/41ms320 KiB
13Runtime error0/42ms320 KiB
14Runtime error0/42ms540 KiB
15Runtime error0/42ms320 KiB
16Runtime error0/42ms320 KiB
17Runtime error0/42ms320 KiB