35022023-02-28 13:37:55AGergoAutókódoláscsharpRuntime error 0/5028ms23544 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.WriteLine(51);
            //Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/027ms20608 KiB
2Runtime error0/028ms20032 KiB
3Wrong answer0/226ms21196 KiB
4Wrong answer0/226ms21284 KiB
5Wrong answer0/226ms21908 KiB
6Wrong answer0/226ms22444 KiB
7Wrong answer0/226ms22400 KiB
8Wrong answer0/427ms22412 KiB
9Wrong answer0/427ms22388 KiB
10Wrong answer0/427ms23048 KiB
11Wrong answer0/427ms22944 KiB
12Wrong answer0/426ms22748 KiB
13Runtime error0/428ms21924 KiB
14Wrong answer0/426ms23308 KiB
15Wrong answer0/427ms23044 KiB
16Wrong answer0/426ms23544 KiB
17Runtime error0/428ms22956 KiB