8152022-01-17 07:10:16Halasz EszterSorozat generáláscpp11Accepted 50/5020ms4840 KiB
#include <iostream>
//#include <fstream>
#include <deque>
#include <vector>
#include <algorithm>

#define ll long long
using namespace std;

//ifstream cin("sorozat.in");
//ofstream cout("sorozat.out");

deque<ll>y;

vector<pair<ll,ll> >x;

ll m,s,a,b,p,j,i,n,k,t,mini=999999,maxi=-1,db=0;

int has(pair<ll,ll >a ,pair<ll,ll>b)
{
    if (a.first<b.first) return 1;
    else return 0;
}
int main()
{
    cin>>m>>s>>a>>b>>n>>k;
    x.resize(n+1);

    x[0]={s,0};

    for(i=1;i<=n;++i)
    {
        p=x[i-1].first*a+b;
        while(p>0 &&y.size()<=4*m)
        {
            y.push_front(p%10);
            p=p/10;
        }
        if(y.size()<4*m)
        {
            while(y.size()!=4*m) y.push_front(0);
        }
        t=((m*4)-(m*2))/2;

        p=0;
        for(j=t;j<t+(m*2);++j)
            p=p*10+y[j];
        x[i]={p,i};
        y.clear();
    }

    //for(i=1;i<=n;++i)
       // cout<<x[i].first<<" "<<x[i].second<<"\n";
    sort(x.begin()+1,x.end(),has);

    //for(i=1;i<=n;++i)
      //  cout<<x[i].first<<" "<<x[i].second<<"\n";

    for(i=1;i<=n-1;++i)
    {
        if(x[i].first==x[i+1].first)
        {
            t=abs(x[i+1].second-x[i].second);
            if(t<mini) mini=t;
        }
    }


    for(i=n;i>=1;--i)
    {
        db++;
        if(db==k)
        {
            maxi=x[i].first;
            break;
        }
    }

    cout<<mini<<"\n"<<maxi;


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1784 KiB
2Accepted0/020ms4724 KiB
3Accepted2/21ms1844 KiB
4Accepted2/22ms1928 KiB
5Accepted2/22ms1932 KiB
6Accepted2/21ms1900 KiB
7Accepted2/22ms2116 KiB
8Accepted4/42ms2116 KiB
9Accepted4/44ms2204 KiB
10Accepted4/413ms3248 KiB
11Accepted4/48ms3252 KiB
12Accepted4/412ms3776 KiB
13Accepted4/417ms4440 KiB
14Accepted4/417ms4428 KiB
15Accepted4/417ms4824 KiB
16Accepted4/419ms4836 KiB
17Accepted4/420ms4840 KiB