Блог пользователя Kogut_Ivan

Автор Kogut_Ivan, история, 13 месяцев назад, По-русски

Привет, Codeforces!

Команда ТГ канала @KogutIvanTutoring рада позвать вас принять участие в Codeforces Round 1016 (Div. 3) во Apr/08/2025 17:35 (Moscow time) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 7 задач, которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов, после её завершения все успешные попытки будут перетестированы на успешных взломах. Мы постарались сделать приличные тесты — так же как и вы, мы будем расстроены, если у многих будут падать решения после окончания контеста.

Вам будет предложено 7 задач и 2 часа 15 минут на их решение.

Штраф за неверную попытку в этом раунде будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в пяти рейтинговых раундах (и решить в каждом из них хотя бы одну задачу)
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Задачи были придуманы и подготовлены частью нашей команды: fstilus, EzikBro, _icy_, Boodoochai, pskobx, gravitsapa

Также большое спасибо:

Всем удачи!

UPD. Разбор выложен!

  • Проголосовать: нравится
  • +136
  • Проголосовать: не нравится

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +34 Проголосовать: не нравится

As a tester, problems are very interesting!

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

As a tester, I can assure you that the problemset is interesting, and the round will be enjoyable.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

cry disappeared

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

As a tester, you will enjoy solving the problems..

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится -23 Проголосовать: не нравится

why isn't there any grey(gray) testing of the round considering its div3?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +33 Проголосовать: не нравится

Finally

Out-of-Competition

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Good Luck for every specialist contestants to reach expert

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Finally excited for my first unrated contest

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Yes, I’m ready to be back to CYAN, inshaAllah!

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I'll try imitate rainboy in this round.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

As a tester, problems are very interesting!

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

As a tester, problems are very interesting!

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

hopefully my journey of ending failure will start from this contest

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

I am excited to participate with my new monitor set-up today..!

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why did this dude TrinhTranPhuongTuan banned? Cause he got top 1???

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In G are the sample testcases correct?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

first time ak div3! ヾ(^∀^)ノ

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Perfecto

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Perfecto

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

I am never writing a div3 or div4 again.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится -14 Проголосовать: не нравится

Although i didn't participate in this round, i've read the problems and i think it is one of the best div3s i remember

»
13 месяцев назад, скрыть # |
Rev. 5  
Проголосовать: нравится +4 Проголосовать: не нравится

The hardest div3 I have ever seen(for me)... can't solve G, get plenty on C E and F stuck on B for 10min, F for 1 hour, I'm too weak :(

So can anyone tell me how to solve G?

UPD: now I know why I can't solve G.

Well, I now know why I couldn't solve G. I was stuck on calculating the maximal dissimilarity group and kept thinking about the following:

maintains a ds such that it supports the following operations:

  • inserts an element
  • deletes an element
  • queries for the maximal value of the xor of each pair of elements in the set

But really, you just need to two pointer scan the array, and then deal with the contribution to the answer from the element currently pointed to by the right pointer, which is a classic 01-Trie problem. Regardless, the quality of the questions in this game was very high and I love it very much!

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Is O(N * M * M) solution feasible in problem F ?? This is equivalent to 1e8 operations. One of the codes passed the TCs but I doubt about strength of TCs.

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

Good quality problems. I made so many stupid mistakes lol and so I didn't get time for G, but I knew immediately that we can just use a trie to get the max XOR, then iterate over l and find the nearest r such that a[l]^a[r] = max_xor.

I do have one contention though -- tries in div 3 problems. It's not that tries are too difficult for div 3, but rather there are much better alternatives, like some graph problem or something. This is probably the third time I've seen a trie in div 3.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

D was very wrong placed , i spend my entire time on d why there are lots of ac in d ??

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why my 314649703 for E — Min Max MEX TLE?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

I wonder, don’t you have any testers to tell you that this contest is bad? I’d like to know what you were thinking when you included problems C and D. Problem E was much easier, except for the text of problem F. Are we here so you can test our ability to read English?

This contest was a waste of time.

When I’m not good at something, I leave it to someone else.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится
4 5
a s k A
d s D t
O R i A
a X b Y
b a k A
u s k J  
why is answer to this 8 not 10
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

wtf was D bro I wasted 1.5hrs on it. I should have solved E before it was simple binary search

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

I feel like my solution for E is hackable because I used sets instead of arrays to track which elements have been filled so far. More than 1000ms in C++ is not good news...

Link to my submission

Hacks appreciated

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

E was easier than B

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится +19 Проголосовать: не нравится

It was more of a div4 than a div3.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Why the authors in recent div3's have removed the notes section from problem statement $$$?$$$ In today's contest, there were no notes except for task $$$D$$$.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is the corner case in G? I'm creating a trie of all seen numbers and searching as follows:

if k has this bit 0 and we can make this bit 1, then simply return the max index of any number seen so far that does so, otherwise continue down the tree.

if k has bit 1, make sure to take the branch which makes this bit 1, if there is no such branch, then return -1. If we reach end of the tree then return the max idx as we must have atleast matched the value of k.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

I read this probelm is very intersting but i found some cheater in this contest. How can report them?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem c, is there exist any prime number greater than 1000? someone pls help...:(

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Problem D is litteraly to toxic to put in a D div 3 i think even G is more straight forward and easier than D (although i didn't solve G cause i ran out of time)

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Why the problems dont have notes to explain the example test

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

nice Codeforces round!!!

Bruh
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Was problem $$$G$$$ solvable using Trie and two-pointers ?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Today's G was so similar to this problem: https://oj.uz/problem/view/IZhO12_xor

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Here is my screencast of this contest along with the solution ideas and thought process: https://youtu.be/6suW6LZyYtY

I am planning to do more of these videos if my schedule allows it.

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Lol this absolute bruteforce passed for C

Code
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

what is the possibility that using unordered_map in E causes hack?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

We have numerous "unexpected verdict" E hacks, which usually indicates std also fails lmao

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hope to reach pupil after rating changes.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi friends, it was a good contest, thanks to all friends

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Hoping to reach pupil after rating changes. Wasted too much time debugging D.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится
Funny C thing, and why k <= 7
Extra Details
  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    This is exactly what I found during the contest as well as I thought there must be some corner cases with n = 1. Fortunately, I later saw that k is restricted to just 7 and I could just use the naive is_prime routine for all cases.

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    • »
      »
      »
      13 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      This is why I specifically mentioned "basic and direct bruteforce".

      This manages to run in polynomial time relative to the length of the number, rather than the expected exponential for the intended solution (which uses the fact that the number does not have to be iterated over.)

      I'm not sure if those bases alone are enough to catch the edge cases (since the solution is actually probabilistic in nature and is only guaranteed to work because of the usual compprog bounds) but this solution would in theory be able to catch the edge cases I mentioned. If k instead allows for the 4th edge case to happen (see the sequence for what k this is), you might need a slight improvement in the code to get this to work (or they need to set t <= 10). Either way, this version of the problem would be around Div3F because you either need to googleforces or run this optimized bruteforce.

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Here's a list of valid k's with x = 1

»
13 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится -10 Проголосовать: не нравится

Please make Div3 and Div4 contests unrated. Today, most of the D problem solvers used AI, and on the other hand, G was also solved by AI. With this rising amount of piracy, most of the noobs are just rushing for ratings.Or use some ide so that copying statement becomes impossible.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

One of the best div3s <3

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

the writers of problems can't get the time complexity right and exclude wrong solution, but let others hack the accepted codes after contest, this is so rediculous

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    I mean, I am doing ACM, not OI. If my solution is completely wrong in time complexity, I get penalty, not first "Accepted" but then "solved -1". Try to imagine that if a question tells you to calculate a * b, but you mistakenly put a + b. However all of tests of "a b" are "2 2" or "0 0", and you got accepted and didn't notice the mistake. Then after the contest, you code is hacked. Of course it's partly my own fault, but don't you think that's a little bit irresponsible?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

how the hell did this submission get hacked? Isn't it n(logn)(logn) Link

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    maybe not TLE but WA

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    There are a lot of solutions using std::set<> or std::map<> getting hacked.

    Not sure what the case is exactly. The slowest case I can think of is $$$n=2×10^5$$$, $$$k=1$$$, $$$a = [0, 1, 2, 3, ..., n-1]$$$ but if I run your code locally it only takes like 800 ms.

    Maybe the CodeForces judging machines are especially slow when it comes to dynamic memory allocation or something like that.

    • »
      »
      »
      13 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Yes exactly, at worst there are n elements in the map taking logn time and the binary search adds another log factor. 2×10⁵×(log(2×10⁵))²~~10⁷. Are the machines this slow?

      • »
        »
        »
        »
        13 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        creating multiple sets requires more overhead space(setup cost is higher) as compared to creating single one storing it all, also using unordered_set was a much better choice over given n and max value of a[i].

        • »
          »
          »
          »
          »
          13 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          I just made a single map for each search, I can understand it is a bit inefficient but I looked at the boundaries and did not much care about these little things. Looking at the number of hacks in E, something seems wrong

    • »
      »
      »
      13 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      For reference, here is a similar submission but in python look at the difference in execution time

    • »
      »
      »
      13 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      While practicing problems on Codeforces, I’ve noticed that in some cases, especially when there are many duplicates, using set & map often gives better TC than unordered_set & unordered_map, so I’ve generally preferred them. However, in this contest's E, my solution got a TLE on test case 67 during internal testing, possibly due to test cases added through hacks. After system testing, I tried replacing set with unordered_set, and surprisingly, it got accepted. It felt a bit odd, and I’m still not entirely sure why that happened.

      • »
        »
        »
        »
        13 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        std::unordered_set<> and std::unordered_map<> are backed by hashtables so insertion and deletion take $$$O(1)$$$ time on average, which is faster than std::set<> and std::map<>, which are backed by balanced binary search trees, which take $$$O(\log n)$$$ time on average.

        Usually the unordered variants are also faster in practice. However, the unordered versions are vulnerable to hacking due to hash collisions, see e.g. this blog post: https://mirror.codeforces.com/blog/entry/62393

        For this particular problem it's not really a concern, because the attack requires inserting elements that are a multiple of the bucket count, while in this problem, the elements of the set are smaller than the maximum size of the set, so the attacker cannot create many collision.

        However, in general, it's best to avoid using plain std::unordered_set<> and std::unordered_map<> in contests that allow hacking. (Or at least harden them with randomization as explained in the blog post.)

        Python doesn't suffer from this because its hash tables have randomization built in. Java's hash tables revert to using balanced search trees when too many keys collide, so e.g. HashMap eventually reverts to the performance of TreeMap in the worst case.

        • »
          »
          »
          »
          »
          13 месяцев назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          So, in general, what's the thumb rule (or is it entirely constraint dependent) for these kinds of problems? I usually stick to using set and map instead of their unordered variants, but in this case it was topsy turvy.

          • »
            »
            »
            »
            »
            »
            13 месяцев назад, скрыть # ^ |
             
            Проголосовать: нравится 0 Проголосовать: не нравится

            For this problem, you could just use a vector<char> or vector<bool> to mark elements which you've already seen.

            That's what I did: 314567229, search for can_solve().

            This technique is generally useful when you have a set or map where the keys are a small range of integers, or something that can easily be mapped to a small range of integers.

            You just have to be careful about how you initialize/clear the vector, since it can be larger than the input you are processing.

            For example, suppose you are given a problem where you get arrays of integers, and you have to output for each array how many distinct values it contains. It's easy to implement this with a std::set or std::unordered_set. But you can also maintain the set in a vector or bool array.

            C++ code

            The solution is strictly O(n) per case, and while that's technically the same as if you'd used a std::unordered_set<>, you'll find that it's much faster in practice because indexing an array has a significantly lower constant overhead than finding an entry in a hash table.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

with due respect, problems $$$D$$$ is not a good problem

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

great contest, A-E were great, the only nitpick is that i wish D was placed at E

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

I have huge problems with Problem D...

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Never saw such an easy F. Literally it was easier than C

»
13 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится +7 Проголосовать: не нравится

I think future problem authors could notice a small problem.

When we think about the MEX of an array $$$a$$$ of length $$$n$$$, it is obvious that we only need to focus on value $$$a_i$$$, which is less than $$$n$$$.

So problems like E have no necessity to make $$$a_i\le 10^9$$$.

Some participants, like me, may ignore the range, using int c[200005] to save the occurrence of a value. And get RE as a result.

But I don't think this is an interesting thing.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Could anyone please explain problem D? Spent so much time on it but still couldn't figure it out :( TIA

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Автокомментарий: текст был обновлен пользователем Kogut_Ivan (предыдущая версия, новая версия, сравнить).

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Kogut_Ivan (previous revision, new revision, compare).

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

yehhh, this is a first contest i can clear on time

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Got hacked in E

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Who thought F should be F among the testers (and D be D). Meet me personally

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Fucking E, set got TLE :)?

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I personally found particularly D, F and G really fun and educational. Thank you :)

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

i feel F is the easiest of all C,D,E,F

»
13 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

E is exactly the type of codeforces question that makes me want to quit sometimes. I used a (properly randomized) set to keep track of items in the current subarray, and I got AC, with a runtime of 1700ms. I assumed that the test setters had created strong test cases, so I moved on to F, and after getting it I finished 180th in the contest. This morning, I found out that I had been hacked.
Apparently, the intended solution was to use a boolean array instead of set. However, both solutions worked during the contest, and they both have the optimal space/time complexity. Is there any way during the contest to figure out that a set is in fact slightly too slow, or is it just luck of the draw? Kogut_Ivan y'all need to make better testcases...

  • »
    »
    13 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    no in div-3 you can't expect the perfect test cases , it test cases had to be perfect there would have been no point of hacking phase , as your solution(1700 ms) was too close to time limit , you should have optimised your solution during contest

    • »
      »
      »
      13 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      What's the point of having a time limit then? With the weak testcases they had, even a 1000ms solution wouldn't have been guaranteed to pass. If they're going to set the time limit low enough that a very natural solution to the problem (with the right space/time complexity) doesn't pass, they should at least make testcases that exclude that type of solution instead of letting us find out 10 hours later during the hacking phase, with no chance to correct our code.

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Accidentally spotted very suspicious participant: https://mirror.codeforces.com/submissions/KS_star/contest/2093 Obfuscated code with names a,b,c,...: 314628685 314630580 314632645, and all solutions submitted within couple minutes

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D giving TLE in test case 4...can anyone help me with this recursive approach.

#include <bits/stdc++.h>
using namespace std;




long long solveCoords(int n, long long start,int row, int col, int& i, int& j,int len){
    if(n==1){
        if(row==i && col==j) return start;
        else if(row+1==i && col+1==j) return start+1;
        else if(row+1==i && col==j) return start+2;
        else return start+3;
    }

  
    long long total = len*len;
    long long subTotal = total/4;

    
    
    int x = len/2 -1;
    int y = len/2 -1;
    if(i<=row+x && j<=col+y) return solveCoords(n-1,start,row,col,i,j,len/2);

    x = len/2;
    y = len/2;
    if(i>=row+x && j>=col+y) return solveCoords(n-1,start+subTotal,row+x,col+y,i,j,len/2);

    x = len/2;
    y = len/2-1;
    
    if(i>=row+x && j<=col+y) return solveCoords(n-1,start+2*subTotal,row+x,col,i,j,len/2);

    x = len/2-1;
    y = len/2;
    if(i<=row+x && j>=col+y) return solveCoords(n-1,start + 3*subTotal,row,col+y,i,j,len/2);

    return -1;
}



pair<int,int> solveNum(int n, long long start, int row, int col, long long& d,int len){
    if(n==1){
       if(d==start) return {row,col};
       else if(d==start+1) return {row+1,col+1};
       else if(d==start+2) return {row+1,col};
       else if(d==start+3) return {row,col+1}; 
    }

    long long total = len*len;
    long long subTotal = total/4;

    if(d < start + subTotal) return solveNum(n-1, start, row, col, d, len/2); // Q0
    else if(d < start + 2*subTotal) return solveNum(n-1, start + subTotal, row + len/2, col + len/2, d, len/2); // Q1
    else if(d < start + 3*subTotal) return solveNum(n-1, start + 2*subTotal, row + len/2, col, d, len/2); // Q2
    else return solveNum(n-1, start + 3*subTotal, row, col + len/2, d, len/2); // Q3
}


int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n,q;
        cin>>n>>q;
        int len = 1<<n;
        for(int j=0;j<q;j++){
            string s;
            cin>>s;
            if(s[0]=='-'){    
                int x,y;
                cin>>x>>y;
                int i = x-1;
                int j = y-1;
                cout<<solveCoords(n,1,0,0,i,j,len)<<endl;
            }
            else{
                long long num=0;
                cin>>num;
                auto it = solveNum(n,1,0,0,num,len);
                cout<<it.first+1<<" "<<it.second+1<<endl;
            }
        }
    }
    
}
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

thanks for such interesting problems . i just love this contest

»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello Codeforces Team,

I am writing to sincerely apologize for unintentionally violating the rules during Codeforces Round 1016 (Div. 3), significantly coincides with solutions Samad_2g/314636123, RubayetRafsan/314640595.specifically for problem 2093D.

Both of the accounts Samad_2g and RubayetRafsan belong to me. I submitted the same type solution from both accounts during the contest without realizing that this was a rules violation. It was a mistake from my side due to a lack of understanding, and I had no intention to gain an unfair advantage.

I now fully understand that participating with multiple accounts is strictly prohibited. I assure you that I will never repeat such a mistake again.

I kindly request that you keep my main account "RubayetRafsan" active, and I’m completely okay with "Samad_2g" being blocked or deactivated if necessary.

Please accept my sincere apologies, and thank you for your time and understanding.

Sincerely, RubayetRafsan