84302024-01-16 09:35:02naHhhhhhhellooBináris fa magassága (50 pont)csharpTime limit exceeded 4/50601ms24956 KiB
    using System;
    using System.Collections.Generic;
    namespace Binarisfa {
    
        class Program {
            struct muvelet {
                public int hely;
                public int hossz;
            }
            struct node {
                public List<int> links; //=new List<int>();
                public List<int> tavolsag;// = new List<int>();
                public int magassag;
                public int index;
            }
            static node generateNode(int index, bool links = true) {
                node n = new node();
                if(index == 1) {
                    n.magassag = 1;
                    n.links = new List<int>(new int[] { 2, 3 });
                    n.tavolsag = new List<int>(new int[] { 1, 1 });
                    n.index = index;
                } else {
                    n.magassag = (int)MathF.Ceiling( MathF.Sqrt(index));
                    n.tavolsag = new List<int>(new int[] { 1, 1 });
                    n.index = index;
                    if (links) {
                        n.links = new List<int>(new int[] { index * 2, index * 2 + 1 });

                    } else {
                        n.links = new List<int>();
                    }
                }
                return n;
            }
        
            static int faMagassag(List<node> fa) {
                int ism = (int)MathF.Floor(MathF.Sqrt(fa.Count));
                int best = 0;
                for (int i = fa.Count; i > 0; i--) {

                    if (fa[i-1].magassag > best) {
                        best = fa[i-1].magassag;
                    }
                }
                        return best;
            }
            static void recalcMag(ref List<node> fa, int honnan) {
            
            }
            static void Main(string[] args) {
                string bement = Console.ReadLine();
                int N = Convert.ToInt32(bement.Split()[0]);
                int M = Convert.ToInt32(bement.Split()[1]);
            
                List<node> fa = new List<node>();
                List<muvelet> muveletek = new List<muvelet>();
                for (int i = 0; i < M; i++) {
                    string dolog = Console.ReadLine();
                    muveletek.Add(new muvelet { hossz = Convert.ToInt32(dolog.Split()[1]), hely = Convert.ToInt32(dolog.Split()[0]) });
                }
                for (int i = 0; i < MathF.Pow(2,N); i++) {
                    if((int)MathF.Ceiling(MathF.Sqrt(i+1)) >= N) {
                        fa.Add(generateNode(i,false));
                        continue;
                    }
                    fa.Add(generateNode(i));

                }
                for (int i = 0; i < muveletek.Count; i++) {
                    if (muveletek[i].hely % 2 == 0) {
                        fa[(int)MathF.Floor(muveletek[i].hely / 2)].tavolsag[0] = muveletek[i].hossz;
                    } else {
                        int teszt = (int)MathF.Floor(muveletek[i].hely / 2);
                        fa[(int)MathF.Floor(muveletek[i].hely / 2)].tavolsag[1] = muveletek[i].hossz;

                    }
                    int honnan = muveletek[i].hely;
                    List<int> queue = new List<int> { honnan };
                    while (queue.Count != 0 && queue[0] <=fa.Count) {
                        int tavol = 0;
                        if(queue[0] == 1) {
                            tavol = 1;
                        } else {
                            if (queue[0] % 2 == 0) {
                                tavol = fa[(int)MathF.Floor(queue[0] / 2) - 0].tavolsag[0];
                            } else {
                                tavol = fa[(int)MathF.Floor(queue[0] / 2) - 0].tavolsag[1];
                            }
                        }

                        //    Console.WriteLine(fa.Count + " is count, queue:" + queue[0]);
                        int magass = fa[(int)Math.Clamp(MathF.Floor(queue[0] / 2), 0, 1000000)].magassag + tavol;

                        if (queue[0] == 1) {
                            magass = 1;
                        }
                        fa[queue[0]] = new node { tavolsag = fa[queue[0]].tavolsag, magassag =magass, index = fa[queue[0]].index, links = fa[queue[0]].links };
                        foreach (var item in fa[queue[0]].links) {
                            queue.Add(item);
                        
                        }
                        queue.Remove(queue[0]);

                    }
                    Console.WriteLine(faMagassag(fa)-1);
                }
            }
        }
    }
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/035ms20868 KiB
2Time limit exceeded0/0559ms19476 KiB
3Accepted2/243ms22592 KiB
4Accepted2/243ms22820 KiB
5Runtime error0/239ms23112 KiB
6Runtime error0/241ms23376 KiB
7Wrong answer0/346ms23916 KiB
8Wrong answer0/348ms24520 KiB
9Wrong answer0/352ms24944 KiB
10Wrong answer0/350ms24956 KiB
11Time limit exceeded0/2566ms22088 KiB
12Time limit exceeded0/2582ms22264 KiB
13Time limit exceeded0/2586ms22536 KiB
14Time limit exceeded0/2578ms22240 KiB
15Time limit exceeded0/2556ms22556 KiB
16Time limit exceeded0/2574ms22732 KiB
17Time limit exceeded0/2560ms22752 KiB
18Time limit exceeded0/2577ms22792 KiB
19Time limit exceeded0/2580ms23096 KiB
20Time limit exceeded0/3601ms22796 KiB
21Time limit exceeded0/3582ms23088 KiB
22Time limit exceeded0/3565ms23532 KiB
23Time limit exceeded0/3569ms23360 KiB