19082022-12-09 12:59:34bzsofiaSorozat generáláscpp11Accepted 50/5050ms5736 KiB
// Rendőrjárőr (patrol).cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

long long a, b, k, n, m, i, szam, j, kezd, tavszam;
string s;
vector <long long> x;
map <long long, long long> mp;

bool comp(long long a, long long b)
{
	return a > b;
}

int main()
{
	cin >> m >> szam >> a >> b >> n >> k;
	long long tav = n;
	for (i = 1; i <= n; ++i)
	{
		szam = szam * a + b;
		s = to_string(szam);
		szam = 0;
		if (s.length() <= 3 * m) kezd = 0;
		else kezd = s.length() - 3 * m;
		
		for (j = kezd; j < s.length() - m; ++j)
		{
			szam = szam * 10 + (s[j]-48);
		}

		if (mp[szam] > 0 && i - mp[szam] < tav)
		{
			tav = i - mp[szam];
		}
		mp[szam] = i;
		x.push_back(szam);
	}

	sort(x.begin(), x.end(), comp);

	cout << tav<< "\n"<<x[k - 1];

	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
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1872 KiB
2Accepted0/046ms4340 KiB
3Accepted2/22ms2280 KiB
4Accepted2/23ms2720 KiB
5Accepted2/23ms2628 KiB
6Accepted2/23ms2832 KiB
7Accepted2/23ms3100 KiB
8Accepted4/44ms3076 KiB
9Accepted4/48ms3556 KiB
10Accepted4/412ms4280 KiB
11Accepted4/49ms4596 KiB
12Accepted4/423ms5372 KiB
13Accepted4/428ms5668 KiB
14Accepted4/439ms5736 KiB
15Accepted4/420ms5572 KiB
16Accepted4/450ms5668 KiB
17Accepted4/450ms5700 KiB