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

Автор 123gjweq2, 15 месяцев назад, По-английски

I thought of this problem a while back, but I'm not sure if it has been created before. Anyway, I think that it is a pretty fun (possibly easier) problem, but I might be a bit biased. I'd appreciate it if you could give it a try and rate it. Also, maybe someone can find a simpler proof for it.

Problem statement:

A derangement of length $$$n$$$ is a permutation $$$p$$$ where $$$p_i \ne i$$$ for all $$$1 \le i \le n$$$.

You are given an integer $$$n$$$. You have to count the number of permutations $$$p$$$ of length $$$n$$$ that can be converted into a derangement using the following operation some (possibly $$$0$$$) number of times:

  • Choose any two integers $$$l, r$$$ such that $$$1 \le l \lt r \le n$$$ and sort the subarray $$$p_{l...r}$$$ in descending order.

For example, $$$p = [1, 2]$$$ would be counted for $$$n = 2$$$ as you can pick $$$l = 1,\,r = 2$$$ and transform the permutation into $$$[2, 1]$$$.

Constraints: $$$10$$$ testcases per test, each consisting of a single integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$.

Examples:

$$$n = 1$$$ gives $$$0$$$, as $$$[1]$$$ cannot be converted into a derangement.

$$$n = 2$$$ gives $$$2$$$, as each permutation can be converted into a derangement.

$$$n = 3$$$ gives $$$5$$$. The only permutation that cannot be converted is $$$[3, 2, 1]$$$.

Solution

Vote:

Good problem

Mid problem

Bad problem

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

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

The problem is quite nice, but you could try proposing these problems for actual contests, you will even get paid for them ;-;

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

    Thanks brosef, that would actually be pretty cool to have a problem in a contest like that. Hopefully another idea will strike me again.

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

      I also have a very nice result, although it's very trivial. Try proving it:

      "Let N be a positive integer. Suppose there exist two primes smaller than N, p1 and p2, such that p1 is the smallest prime smaller than and coprime to N and p2 is the second-smallest prime smaller than and coprime to N. Then N-p1 and N-p2 are always coprime with each other."

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

        Nice statement, here is my attempt at a proof for it:

        So let's say that $$$\gcd(N - p_1, N - p_2) = d$$$. By the Euclidean algorithm, this means that $$$\gcd(N - p_2, p_2 - p_1) = d$$$ or $$$d | p_2 - p_1$$$.

        Okay, so we know that $$$p_2 - p_1 \lt p_2$$$ and $$$p_1 \nmid p_2 - p_1$$$. This means that, in order for $$$d \gt 1$$$ to hold, it must be the case that $$$d$$$ has some prime factor $$$ \lt p_2$$$ that isn't $$$p_1$$$.

        We know that $$$d$$$ can't have a prime factor $$$ \lt p_1$$$ or else $$$d \nmid N - p_1$$$ and $$$d \nmid N - p_2$$$ because all prime factors below $$$p_1$$$ go into $$$N$$$. And $$$d$$$ can't have a prime factor between $$$p_1$$$ and $$$p_2$$$ or else that prime factor would also be coprime to $$$N$$$, meaning we'd have to move $$$p_2$$$ down. So I think $$$d = 1$$$.

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

    Hey DeadMan69 can u please share some knowledge on "HOW" and "WHERE" can I share such problem ideas for actual contest say div2/3 .... Please if you would know or anyone seeing this message knows!

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

      I'm not a 100% sure, but as per my knowledge, you will have to be good friends with some 2100+ rated guy, who is willing to host a contest, and offer him the problem, and then once the contest is done, the 2100+ (the one who organised) gets paid and ... . Other alternative is codechef, goforgold, iicpc, you might have seen their blogs even asking for problems and willing to pay.

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

I am curious. How do u solve it?

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

Seems pretty fun, but do you think you'd need to take the results modulo M? Or else it might be harder due to BigNum implementations.

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

Div. 2 F tbh

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

how n=2 gives 2 shouldn't it be 1 ohh got it no of operation can be 0

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

div2b i think, sloved it after writing a permutation

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

div.1D is not too high for the problem.

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

the formula is so simple so many people can guess it.

it's not on oeis, but discover that it is close to n! then you can find the pattern after check the different.