Submission #486137

# Submission time Handle Problem Language Result Execution time Memory
486137 2021-11-10T15:32:32 Z leaked DEL13 (info1cup18_del13) C++14
0 / 100
16 ms 6016 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define vec vector
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m_p make_pair
#define pw(x) (1LL<<x)
#define sz(x) (int)(x).size()
#define pb push_back
#define fast_rmi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

template<class T> bool umin(T &a, const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a, const T &b){return (a<b?a=b,1:0);}
typedef pair<int,int> pii;

signed main(){
    fast_rmi;
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vec<vec<int>>dp(k+2,vec<int>(3,0));
        vec<vec<int>> p(k+2,vec<int>(3,0));
        vec<int>a(k);
        vec<pii>me;
        for(auto &z : a) cin>>z;
        int prv=0;
        for(auto &z : a) me.pb({prv+1,z-1}),prv=z;
        me.pb({prv+1,n});
        vec<int>ans;
        int ok=1;
        for(int i=0;i<sz(me);i++){
            while(i){
                int x=me[i-1].s-me[i-1].f+1;
                int y=me[i].s-me[i].f+1;
                if(x && y){
                    me[i-1].f++;me[i].f++;
                    ans.pb(a[i-1]);
                    continue;
                }
                break;
            }
            int cnt=me[i].s-me[i].f+1;
            vec<int> og;
            for(int j=me[i].f;j<=me[i].s;j++) og.pb(j);
            while(cnt>=3){
                cnt-=2;
                ans.pb(og[sz(og)-2]);
                og.pop_back();
                swap(og[sz(og)-1],og[sz(og)-2]);
                og.pop_back();
                me[i].f+=2;
            }
//            me.f=z.s-cnt+1;
//            cout<<"KEK" <<me[i].f<<' '<<me[i.s<<' '<<cnt<<endl;
        }
        for(auto &z : me) ok&=((z.s-z.f+1)==0);
        if(!ok){
            cout<<-1<<'\n';
            continue;
        }
           set<int>st;
        for(int i=1;i<=n;i++) st.insert(i);
        for(auto &z : ans){
            auto it=st.lower_bound(z);
            if(it==st.begin() || next(it)==st.end()) assert(false);
            int j=*prev(it),k=*next(it);
            st.erase(j);st.erase(k);
        }
        vec<int> byla;
        for(auto &z : st) byla.pb(z);
        assert(byla==a);
        cout<<sz(ans)<<'\n';
        for(auto &z : ans) cout<<z<<' ';
        cout<<'\n';
    }
    return 0;
}
/*
2 3
7 4 3
5 2 5
*/
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Incorrect 7 ms 272 KB Output isn't correct
4 Incorrect 7 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 532 KB Output isn't correct
2 Incorrect 4 ms 1452 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Incorrect 7 ms 272 KB Output isn't correct
4 Incorrect 7 ms 332 KB Output isn't correct
5 Incorrect 2 ms 332 KB Output isn't correct
6 Incorrect 2 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Incorrect 7 ms 272 KB Output isn't correct
4 Incorrect 7 ms 332 KB Output isn't correct
5 Incorrect 2 ms 332 KB Output isn't correct
6 Incorrect 2 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 12 ms 1132 KB Output isn't correct
9 Incorrect 16 ms 3864 KB Output isn't correct
10 Incorrect 13 ms 3232 KB Output isn't correct
11 Incorrect 13 ms 6016 KB Output isn't correct