856A - Set Theory - CodeForces Solution


brute force constructive algorithms *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
//for math u can observe something related to gcd or something related to even or odd to draw some conclusions
//if your answer is lieing in a range then binary search is the best approach to solve that problem
//for errors check out of bound and overflow of integers
//sorting,binary search,dynamic programming,greedy are some of the most used techniques to solve the problems
//until some element it is good and then next it is bad u should use binary search 
//to find the first good element or to find the first bad element we use binary search
//if there are digits then remember that the digits are just from 0-9 so u can use two loops the same for character a-z they are just 26
const int M=998244353;
const int INF=1e9+5;
void dfs(int currentNode,vector<vector<int>>& adj,int parent,vector<int>& ans)
{
    ans.push_back(currentNode);
    for(int neighbour : adj[currentNode])
    {
        if(neighbour!=parent)
        {
            dfs(neighbour,adj,currentNode,ans);
        }
    }
}
ll mod(ll x)
{
    return (((x%M)+M)%M);
}
ll add(ll a,ll b)
{
    return mod(mod(a)+mod(b));
}
ll mul(ll a,ll b)
{
    return mod(mod(a)*mod(b));
}
int sumd(ll a)
{
    int res=0;
    while(a!=0)
    {
        res+=a%10;
        a/=10;
    }
    return res;
}
int main() {
	// your code goes here
	int t;
    cin>>t;
	while(t--)
	{
	  int n;
	  cin>>n;
	  int a[n];
	  for(int i=0;i<n;i++)
	  {
	      cin>>a[i];
	  }
	  if(n==1)
	  {
	      cout<<"YES"<<endl;
	      cout<<1<<endl;
	  }
	  else
	  {
	      cout<<"YES"<<endl;
	   int b[n];
	   b[0]=1;
	   vector<int>diff(1000005,0);
	   for(int i=0;i<n;i++)
	   {
	     int x=abs(a[i]-1);
	     diff[x]=1;
	   }
	   int i=1;
	   int k=2;
	   while(i<n)
	   {
	       bool ok=true;
	       int p=0;
	       while(p==0)
	       {
	         for(int j=0;j<n;j++)
	         {
	             int x=abs(a[j]-k);
	             if(diff[x]==1)
	             {
	                 p=0;
	                 break;
	             }
	             else
	             {
	                 p=1;
	             }
	         }
	         if(p==0) k++;
	         else
	         {
	             b[i]=k;
	             for(int j=0;j<n;j++)
	             {
	                 int x=abs(a[j]-k);
	                 diff[x]=1;
	             }
	             
	             k++;
	             p=1;
	         }
	       }
	       i++;
	   }
	   for(int z=0;z<n;z++)
	   {
	       cout<<b[z]<<" ";
	   }
	   cout<<endl;
	  }
	  
	  }
	

	return 0;

}


Comments

Submit
0 Comments
More Questions

1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL