답안 #689770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
689770 2023-01-29T10:49:23 Z alexdd DEL13 (info1cup18_del13) C++17
30 / 100
8 ms 1876 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,q;
int v[100005];
int gap[100005];
vector<int> sol;
vector<int> sol2;
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        sol.clear();
        sol2.clear();
        cin>>n>>q;
        for(int i=1;i<=q;i++)
        {
            cin>>v[i];
            gap[i-1]=v[i]-v[i-1]-1;
        }
        if(q==0)
        {
            cout<<-1<<"\n";
            continue;
        }
        gap[q] = n - v[q];
        q++;
        v[q] = n+1;
        bool impossible=0;
        for(int i=1;i<q;i++)
        {
            if(impossible)
                break;
            if(gap[i-1]==0 || gap[i]==0)
                continue;
            if(gap[i-1]%2==1 && gap[i]>=1 && gap[i-1]>=0)///daca trebuie sa scad 1
            {
                sol.push_back(v[i]);
                gap[i]--;
                gap[i-1]--;
            }
            else if(gap[i-1]==v[i]-v[i-1]-1 && gap[i]>=2 && gap[i-1]>=2)///daca trebuie sa scad 2
            {
                sol.push_back(v[i]);
                sol.push_back(v[i]);
                gap[i]-=2;
                gap[i-1]-=2;
            }
        }
        for(int i=q-1;i>0;i--)
        {
            if(impossible)
                break;
            if(gap[i-1]==0 || gap[i]==0)
                continue;
            if(gap[i]%2==1 && gap[i]>0 && gap[i-1]>0)///daca trebuie sa scad 1
            {
                sol.push_back(v[i]);
                gap[i]--;
                gap[i-1]--;
            }
            else if(gap[i]==v[i+1]-v[i]-1 && gap[i]>1 && gap[i-1]>1)///daca trebuie sa scad 2
            {
                sol.push_back(v[i]);
                sol.push_back(v[i]);
                gap[i]-=2;
                gap[i-1]-=2;
            }
        }
        if(!impossible)
        {
            for(int i=0;i<q;i++)
            {
                if(gap[i]==0)
                    continue;
                if(gap[i]<0 || gap[i]%2==1 || gap[i]==v[i+1]-v[i]-1)
                {
                    impossible=1;
                    break;
                }
                int mij=(v[i+1]+v[i])/2;
                while(gap[i]>0)
                {
                    sol2.push_back(mij);
                    gap[i]-=2;
                }
            }
        }

        if(impossible)
        {
            cout<<-1<<"\n";
            continue;
        }
        cout<<sol.size() + sol2.size()<<"\n";
        for(int i=0;i<sol2.size();i++)
            cout<<sol2[i]<<" ";
        for(int i=0;i<sol.size();i++)
            cout<<sol[i]<<" ";
        cout<<"\n";
    }
    return 0;
}
/**
cazuri pe care nu merge solutia:
1
16 4
2 8 13 15
 my solution: -1

16 4
5 10 13 15
 my solution: -1

16 4
4 10 13 15
 my solution: -1

16 4
2 8 11 13
 my solution: -1

*/

Compilation message

del13.cpp: In function 'int main()':
del13.cpp:99:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |         for(int i=0;i<sol2.size();i++)
      |                     ~^~~~~~~~~~~~
del13.cpp:101:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int i=0;i<sol.size();i++)
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 3 ms 340 KB Output isn't correct
4 Incorrect 3 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 3 ms 340 KB Output isn't correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 3 ms 340 KB Output isn't correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 5 ms 468 KB Output isn't correct
9 Incorrect 5 ms 596 KB Output isn't correct
10 Incorrect 5 ms 764 KB Output isn't correct
11 Incorrect 8 ms 1876 KB Output isn't correct