124322024-12-17 18:53:07szabelrSorozat generáláscpp17Elfogadva 50/5030ms1340 KiB
// Sorozat generálás.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#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;
    //seen[x] = 0;
    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 ] << endl;
    return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms512 KiB
2Elfogadva0/030ms1080 KiB
3Elfogadva2/21ms320 KiB
4Elfogadva2/22ms320 KiB
5Elfogadva2/22ms320 KiB
6Elfogadva2/21ms320 KiB
7Elfogadva2/22ms320 KiB
8Elfogadva4/43ms524 KiB
9Elfogadva4/46ms596 KiB
10Elfogadva4/414ms828 KiB
11Elfogadva4/412ms832 KiB
12Elfogadva4/417ms976 KiB
13Elfogadva4/423ms1200 KiB
14Elfogadva4/430ms1080 KiB
15Elfogadva4/428ms1268 KiB
16Elfogadva4/430ms1280 KiB
17Elfogadva4/430ms1340 KiB