35012023-02-28 13:36:54AGergoAutókódoláscsharpWrong answer 0/5028ms23740 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace auto
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            char[] bin = new char[40];
            int onecount = 0;

            int index = 0;

            while (num != 0)
            {
                onecount += num % 2;
                if (num % 2 == 0)
                {
                    bin[index] = '0';
                }
                else
                {
                    bin[index] = '1';
                }
                num -= num % 2;
                num /= 2;
                index++;
            }
            //bin[index] = 'x';
            char[] lowerbin = bin;
            char[] higherbin = bin;

            if (onecount == bin.Length)
            {
                Console.WriteLine(-1);
            }
            else
            {
                for (int i = 0; i < lowerbin.Length; i++)
                {
                    //if (bin[i] == 'x')
                    //{
                    //    break;
                    //}

                    if (lowerbin[i] == '1')
                    {
                        lowerbin[i] = '0';

                        for (int j = 0; j < i; j++)
                        {
                            lowerbin[j] = '1';

                        }
                        break;
                    }
                }

                //for (int i = 1; i < higherbin.Length; i++)
                //{
                ////    if (bin[i] == 'x')
                ////    {
                ////        break;
                ////    }

                //    if (higherbin[i] == '0')
                //    {
                //        higherbin[i] = '1';

                //        if (bin[0] == '0')

                //            for (int j = 0; j < i; j++)
                //            {
                //                if (i > onecount - i + 1)
                //                {
                //                    higherbin[i] = '1';
                //                }
                //                else
                //                {
                //                    higherbin[i] = '0';
                //                }
                //            }
                //    }
                //    else
                //    {
                //        for (int j = 0; j < i; j++)
                //        {
                //            if (i > onecount - i)
                //            {
                //                higherbin[i] = '1';
                //            }
                //            else
                //            {
                //                higherbin[i] = '0';
                //            }
                //        }
                //    }
                //}
            }


            int low = 0;
            //int high = 0;
            for (int i = 0; i < lowerbin.Length; i++)
            {
                //if (bin[i] == 'x')
                //{
                //    break;
                //}

                if (lowerbin[i] == '1')
                {
                    low += (int)Math.Pow(2, i);
                }
                //if (higherbin[i] == '1')
                //{
                //    high += (int)Math.Pow(2, i);
                //}
            }
            Console.WriteLine(low);

            //Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/026ms20368 KiB
2Runtime error0/028ms19964 KiB
3Wrong answer0/225ms21144 KiB
4Wrong answer0/225ms21404 KiB
5Wrong answer0/227ms22056 KiB
6Wrong answer0/226ms22740 KiB
7Wrong answer0/227ms22768 KiB
8Wrong answer0/426ms22852 KiB
9Wrong answer0/426ms23232 KiB
10Wrong answer0/426ms22996 KiB
11Wrong answer0/425ms23016 KiB
12Wrong answer0/425ms22920 KiB
13Runtime error0/428ms22420 KiB
14Wrong answer0/425ms23252 KiB
15Wrong answer0/425ms23360 KiB
16Wrong answer0/425ms23740 KiB
17Runtime error0/428ms23228 KiB