29702023-02-06 18:02:35CWMSorozat generáláscpp11Wrong answer 1/503ms4292 KiB
// SorozatGen.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
int GenNextElement(int Base, int A, int B) {
    Base = Base * A + B;
    Base %= 1000;
    Base /= 10;
    return Base;
}

int main()
{
    int M, BeginningNum, A, B, Lenght, K;
    cin >> M >> BeginningNum >> A >> B >> Lenght >> K;
    vector<int> LastElementMet(100);
    int Looplenght = 0;
    int NumbersBeforeLoopLenght = 0;
    int OG = BeginningNum;
    int OGL = Lenght;
    for (size_t i = 1; i < 100; i++)
    {
        BeginningNum = GenNextElement(BeginningNum, A, B);
        if (LastElementMet[BeginningNum] == 0) {
            LastElementMet[BeginningNum] = i;
        }
        else {
            NumbersBeforeLoopLenght = LastElementMet[BeginningNum];
            Looplenght = i - LastElementMet[BeginningNum];
            break;
        }
    }
    cout << BeginningNum << "\n";
    vector<int> Loop;
    for (size_t i = 0; i < Looplenght; i++)
    {
        Loop.push_back(BeginningNum);
        BeginningNum = GenNextElement(BeginningNum, A, B);
    }
    vector<int> CountTillLenght(100);
    BeginningNum = OG;
    for (size_t i = 0; i < NumbersBeforeLoopLenght-1; i++)
    {
        BeginningNum = GenNextElement(BeginningNum, A, B);
        CountTillLenght[BeginningNum]++;
    }
    Lenght -= NumbersBeforeLoopLenght;
    int Repeated = Lenght % Looplenght;
    for (size_t i = 0; i < Repeated; i++)
    {
        CountTillLenght[Loop[i]]++;
    }
    Lenght -= Repeated;
    int smallloop = Lenght / Looplenght;
    for (size_t i = 0; i < Looplenght; i++)
    {
        CountTillLenght[Loop[i]] += smallloop;
    }
    int CCount = 0;
    for (int i = 99; i >= 0; i--)
    {
        CCount += CountTillLenght[i];
        if (CCount >= OGL-K-1) {
            cout << i << "\n";
            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
base1/50
1Accepted0/03ms1684 KiB
2Wrong answer0/03ms1848 KiB
3Wrong answer0/23ms2060 KiB
4Wrong answer0/22ms2272 KiB
5Wrong answer0/23ms2480 KiB
6Wrong answer0/22ms2608 KiB
7Partially correct1/23ms2732 KiB
8Wrong answer0/43ms2904 KiB
9Wrong answer0/42ms2996 KiB
10Wrong answer0/43ms3120 KiB
11Wrong answer0/43ms3332 KiB
12Wrong answer0/42ms3576 KiB
13Wrong answer0/42ms3624 KiB
14Wrong answer0/43ms3760 KiB
15Wrong answer0/42ms3964 KiB
16Wrong answer0/42ms4180 KiB
17Wrong answer0/42ms4292 KiB