# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338667 | Dymo | Nice sequence (IZhO18_sequence) | C++14 | 1870 ms | 47040 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |