답안 #549988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549988 2022-04-17T02:32:05 Z fcmalkcin DEL13 (info1cup18_del13) C++17
100 / 100
11 ms 4556 KB
#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

del13.cpp: In function 'int main()':
del13.cpp:121:23: warning: unused variable 'to' [-Wunused-variable]
  121 |             for (auto to:vt1)
      |                       ^~
del13.cpp:127:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |             for (int i=0; i<vt1.size(); i++)
      |                           ~^~~~~~~~~~~
del13.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
del13.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 5 ms 372 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 596 KB Output is correct
2 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 5 ms 372 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 5 ms 372 KB Output is correct
4 Correct 5 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 8 ms 2768 KB Output is correct
9 Correct 8 ms 3348 KB Output is correct
10 Correct 8 ms 3376 KB Output is correct
11 Correct 11 ms 4556 KB Output is correct