# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549988 | fcmalkcin | DEL13 (info1cup18_del13) | C++17 | 11 ms | 4556 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 ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)
const ll maxn=3e5+10 ;
const ll base=1e9;
const ll mod= 1e9+7 ;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
/// have medal in APIO
/// goal 2/8
ll dp[maxn][3];
ll a[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("test.inp","r"))
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
ll t;
cin>> t;
while (t--)
{
ll n, k;
cin>> n>> k;
vector<ll> vt;
ll pre=0;
for (int i=1; i<=k; i++)
{
cin>> a[i];
vt.pb(a[i]-pre-1);
pre=a[i];
}
vt.pb(n-pre);
if (vt[0]%2==1)
dp[0][1]=1;
else if (vt[0]==0)
dp[0][0]=1;
else
dp[0][2]=1;
for (int i=1; i<=k; i++)
{
for (int t=0; t<=2; t++)
{
if (dp[i-1][t]&&vt[i]>=t)
{
if (t==0)
{
if (vt[i]%2==0)
{
if (vt[i])
dp[i][2]=t+1;
else
dp[i][0]=t+1;
}
else
dp[i][1]=t+1;
}
else if (t==1)
{
if (vt[i]%2==1)
{
if (vt[i]>=3)
dp[i][0]=t+1,dp[i][2]=t+1;
else
dp[i][0]=t+1;
}
else
{
dp[i][1]=t+1;
}
}
else
{
if (vt[i]%2==1)
{
dp[i][1]=t+1;
}
else
{
if (vt[i]==2)
{
dp[i][0]=t+1;
}
else
{
dp[i][0]=t+1;
dp[i][2]=t+1;
}
}
}
}
}
}
if (dp[k][0])
{
vector<ll> vt1;
vt1.pb(0);
ll nw=0;
for (int i=k; i>=1; i--)
{
nw=dp[i][nw]-1;
vt1.pb(nw);
}
reverse(vt1.begin(),vt1.end());
for (auto to:vt1)
{
// cout <<to<<" chk1"<<endl;
}
ll st=0;
vector<ll> res;
for (int i=0; i<vt1.size(); i++)
{
ll pre=0;
if (i)
pre=vt1[i-1];
if (pre==0)
{
ll sl=(vt[i]-vt1[i])/2;
ll nw=st+2;
while (sl--)
{
res.pb(nw);
nw+=2;
}
}
else if (pre==1)
{
ll sl=(vt[i]-vt1[i]-pre)/2;
ll nw=st+2;
while (sl--)
{
res.pb(nw);
nw+=2;
}
res.pb(st);
}
else
{
if (vt1[i]>=1)
{
res.pb(st);
res.pb(st);
ll sl=(vt[i]-1)/2-1;
ll nw=st+4;
while (sl--)
{
res.pb(nw);
nw+=2;
}
}
else
{
ll sl=(vt[i])/2-1;
ll nw=st+2;
while (sl--)
{
res.pb(nw);
nw+=2;
}
res.pb(st);
res.pb(st);
}
}
st+=vt[i]+1;
}
// cout <<1<<endl;
cout <<res.size()<<endl;
for (auto to:res)
cout <<to<<" ";
cout <<endl;
}
else
{
cout <<-1<<endl;
}
for (int i=0; i<=n; i++)
{
for (int t=0; t<=2; t++)
dp[i][t]=0;
}
}
}
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... |