Submission details
Task:Blocks
Sender:AKurlavicius
Submission time:2026-04-16 11:45:35 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:42:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   42 |     if ((n%2==0 && (vien.size()!=0  || trys.size()!=0) || vien.size()>1)
      |          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:42:73: error: expected ';' before '{' token
   42 |     if ((n%2==0 && (vien.size()!=0  || trys.size()!=0) || vien.size()>1)
      |                                                                         ^
      |                                                                         ;
   43 |     {
      |     ~                                                                    
input/code.cpp:47:5: error: expected primary-expression before 'if'
   47 |     if (vien.size()==1)
      |     ^~
input/code.cpp:46:6: error: expected ')' before 'if'
   46 |     }
      |      ^
      |      )
   47 |     if (vien.size()==1)
      |     ~~
input/code.cpp:42:8: note: to match this '('
   42 |     if ((...

Code

#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n, k;
    cin>>n>>k;
    int ans[n+1];
    int piv=1;
    vector<int> vien, trys, Cnt(n+1);
    for (int i=1; i<=n; i++)
    {
        int id;
        cin>>id;
        Cnt[id]++;
    }
    for (int i=1; i<=k; i++)
    {
        int cnt=Cnt[i];
        if (cnt%2==0)
            while (cnt>0)
            {
                ans[piv]=i;
                ans[n+1-piv]=i;
                piv++;
                cnt-=2;
            }
        else if (cnt==1)
            vien.push_back(i);
        else
        {
            while (cnt!=3)
            {
                ans[piv]=i;
                ans[n+1-piv]=i;
                piv++;
                cnt-=2;
            }
            trys.push_back(i);
        }
    }
    if ((n%2==0 && (vien.size()!=0  || trys.size()!=0) || vien.size()>1)
    {
        cout<<"NO\n";
        return;
    }
    if (vien.size()==1)
        ans[(n+1)/2]=vien[0];
    piv++;
    for (int sp:trys)
    {
        if (piv<n+1-piv)
        {
            ans[piv-1]=sp;
            piv=n+1-piv;
            ans[piv]=sp;
            ans[piv-1]=sp;
        }
        else
        {
            ans[piv+1]=sp;
            piv=n+1-piv;
            ans[piv]=sp;
            ans[piv+1]=sp;
            piv+=3;
        }
    }
    cout<<"YES\n";
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<' ';
    cout<<'\n';
}

int main()
{
    int t;
    cin>>t;
    while (t--)
        solve();
}