# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
549988 | fcmalkcin | DEL13 (info1cup18_del13) | C++17 | 11 ms | 4556 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
}
컴파일 시 표준 에러 (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... |