Submission #338667

#TimeUsernameProblemLanguageResultExecution timeMemory
338667DymoNice sequence (IZhO18_sequence)C++14
100 / 100
1870 ms47040 KiB
#include<bits/stdc++.h>
using namespace std;


#define pb  push_back
#define ll  int
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=8e5+5;
const ll mod =998244353 ;
const ll maxn1=51;
const ll base=1e9;

ll n, m;
vector<ll> tp;
bool dd[maxn];
ll ans[maxn];
ll ans1[maxn];

void dfs(ll u,ll mid)
{
    //  cout <<u<<endl;
    dd[u]=1;
    if (u+n<=mid&&!dd[u+n])
        dfs(u+n,mid);
    if (u-m>=0&&!dd[u-m])
        dfs(u-m,mid);
    tp.pb(u);
}
bool chk(ll mid)
{
    tp.clear();
    for (int i=0; i<=mid; i++)
    {
        dd[i]=0;
    }
    for (int i=0; i<=mid; i++)
    {
        if (dd[i])
            continue;
        dfs(i,mid);
    }
    for (int i=0; i<tp.size(); i++)
    {
        ans1[tp[i]]=i;
    }

    for (int i=0; i<=mid; i++)
    {
        if (i+n<=mid&&ans1[i+n]>ans1[i])
            return false;
        if (i-m>=0&&ans1[i-m]>ans1[i])
            return false;
    }
    for (int i=1;i<=mid;i++)
    {
        ans[i]=ans1[i]-ans1[i-1];
    }


    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("GIFT11.inp","r"))
    {
        freopen("GIFT11.inp","r",stdin);
        freopen("GIFT11.out","w",stdout);
    }
    ll t;
    cin>> t;
    while (t--)
    {
        cin>> n>>m ;
        ll l=0, h=maxn/2;
        while (l<=h)
        {
            ll mid=(l+h)/2;
            if (chk(mid))
                l=mid+1;
            else
                h=mid-1;
        }
        cout <<h<<endl;
        for (int i=1; i<=h; i++)
        {
            cout <<ans[i]<<" ";
        }
        cout <<endl;
        //  cout <<chk(100000);


    }


}

Compilation message (stderr)

sequence.cpp: In function 'bool chk(int)':
sequence.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=0; i<tp.size(); i++)
      |                   ~^~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   72 |         freopen("GIFT11.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         freopen("GIFT11.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...