3477 2023. 02. 28 12:11:17 Dora Autókódolás csharp Időlimit túllépés 38/50 277ms 24400 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace autokodolas_gyorsabb
{
    internal class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            // Count the number of 1 bits in the binary representation of n
            int oneBits = CountOneBits(n);

            // Find the previous code with the same number of 1 bits
            long prevCode = n - 1;
            while (prevCode >= 1 && CountOneBits(prevCode) != oneBits)
            {
                prevCode--;
            }

            // Find the next code with the same number of 1 bits
            long nextCode = n + 1;
            while (CountOneBits(nextCode) != oneBits)
            {
                nextCode++;
            }

            Console.WriteLine(prevCode >= 1 ? prevCode.ToString() : "-1");
            Console.WriteLine(nextCode.ToString());
            Console.ReadKey();
        }

        static int CountOneBits(long n)
        {
            int count = 0;
            while (n > 0)
            {
                count += (int)(n & 1);
                n >>= 1;
            }
            return count;
        }
    }
}
Részfeladat Összpont Teszt Verdikt Idő Memória
base 38/50
1 Elfogadva 0/0 27ms 20604 KiB
2 Időlimit túllépés 0/0 261ms 4468 KiB
3 Elfogadva 2/2 28ms 21508 KiB
4 Elfogadva 2/2 27ms 21448 KiB
5 Elfogadva 2/2 27ms 21856 KiB
6 Elfogadva 2/2 27ms 21976 KiB
7 Elfogadva 2/2 27ms 22120 KiB
8 Elfogadva 4/4 27ms 22052 KiB
9 Elfogadva 4/4 26ms 22444 KiB
10 Elfogadva 4/4 26ms 22896 KiB
11 Elfogadva 4/4 26ms 22788 KiB
12 Elfogadva 4/4 27ms 23048 KiB
13 Időlimit túllépés 0/4 275ms 6840 KiB
14 Elfogadva 4/4 26ms 23716 KiB
15 Elfogadva 4/4 41ms 24400 KiB
16 Időlimit túllépés 0/4 232ms 7384 KiB
17 Időlimit túllépés 0/4 277ms 7632 KiB