1205A - Almost Equal - CodeForces Solution


constructive algorithms greedy math *1200

Please click on ads to support us..

Python Code:

from collections import deque,defaultdict
import sys
def inp(): return int(sys.stdin.readline())
def mpp(): return map(int,sys.stdin.readline().rstrip().split())
def lis(): return list(map(int,sys.stdin.readline().rstrip().split()))

def main():
    n=inp()
    if n%2:
        arr=[0]*(2*n)
        for i in range(n):
            if i%2:
                arr[i]=2*i+1
                arr[i+n]=arr[i]+1
            else:
                arr[i]=2*i+2
                arr[i+n]=arr[i]-1
        sys.stdout.write("YES\n")
        for i in arr:
            sys.stdout.write(str(i)+" ")
    else:
        sys.stdout.write("NO")
    
if __name__=="__main__":
    main()

C++ Code:

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
 
 
ll Count_digit(ll N)
{
    ll Count = 0;
    while(N > 0)
    {
        Count++;
        N = N / 10;
    }
    return Count;
}
 
 
int Mod(ll N)
{
    return N % 1000000007;
}
bool isprime(ll N)
{
    if(N == 1)
        return false;
    for(ll i = 2; i*i <= N; i++)
        if(N % i == 0)
            return false;
    return true;
}
bool cmp(ll a, ll b)
{
    return a>b;
}
ll power(ll a,ll b)
{
    ll temp=1;
    while(b--)
        temp*=a;
    return temp;
}

ll stringToInt(const string &s)
{
    stringstream om(s);
    ll num=-1;
    om>>num;
    return num;
}

string intToString(ll n)
{
    ostringstream ostr;
    ostr<<n;
    return ostr.str();
}

void PrintVf(vector<ll> Arr)
{
    for(int i = 0; i < Arr.size(); i++)
        cout <<Arr[i] <<" ";
    cout << endl;
}


void PrintVb(vector<ll> Arr)
{
    for(int i = Arr.size() - 1; i >= 0; i--)
        cout <<Arr[i] <<" ";
    cout << endl;
}

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
 
void solve()
{
    ll N;
    cin >> N;
    if(N % 2 == 0)
        NO
    else
    {
        YES
        for(int i = 0; i < N; i++)
        {
            if(i % 2 == 0)
                cout << 2 * i + 1 << " ";
            else
                cout << 2 * i + 2 << " ";
        }
        for(int i = 0; i < N; i++)
        {
            if(i % 2 == 0)
                cout << 2 * i + 2 << " ";
            else
                cout << 2 * i + 1 << " ";
        }
    }
    cout << endl;


}
 
 
int main()
{
 
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha