Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

spookywooky's blog

By spookywooky, history, 8 months ago, In English,

Hello,

I am trying to solve https://cses.fi/problemset/task/1163, but got some problem to understand it. It states that "There is a street of length x whose positions are numbered 0,1,…,n. " That should be "0, 1,..., x", not n, isn't it?

Then the example:

Input:
8 3
3 6 2

Output:
5 3 3

I think output should be 5, 3, 2, not 5, 3, 3. Since obviously the longest segment without a traffic light is 2, not 3.

0 1 2 3 4 5 6 7 8
    x x     x

Can somebody explain? A lot of people solved that problem, I think I am missing something. Thanks.

Read more »

 
 
 
 
  • Vote: I like it
  • +4
  • Vote: I do not like it

By spookywooky, history, 12 months ago, In English,

Hi,

I have got a hard time understanding the problems given in the Quantum contest. So, to understand the sentence I first have to understand the words. To understand the words, I have to recognize the characters... kind of like starting at zero.

So, where is the entrance, the "Hello World" tutorial which makes me understanding even the notation of the problems, described for example here: Wikipedia Bra-Ket

Thanks

Read more »

 
 
 
 
  • Vote: I like it
  • +12
  • Vote: I do not like it

By spookywooky, history, 13 months ago, In English,

Working with fractions usually we get a hint like "You should compute P⋅Q−1 modulo 109+7, where Q−1 denotes the multiplicative inverse of Q modulo 109+7."

So, I more (or less) understood what that means. I can express, say 1/5 by the number 400000003. I can calculate that number using https://www.geeksforgeeks.org/fermats-little-theorem/ implemented by some code I found somewhere (see below).

BUT: How do I add (and/or multiply) fractions with huge values?

i.e. how to calculate and express something like this: Let E=10e9+7 Then, how to express: ((E+1) / (E+2)) + ((E+3) / (E+4))

Any hint or link to an understandable explenation would be really helpfull. Thanks.

The code I use so far, based on that fermat thing: ' class Inv { companion object { val defaultMod = 1000000007L var MOD = defaultMod

fun toPower(a: Long, p: Long, mod: Long = MOD): Long {
            var a = a
            var p = p
            var res = 1L
            while (p != 0L) {
                if (p and 1 == 1L)
                    res = res * a % mod
                p = p shr 1
                a = a * a % mod
            }
            return res
        }

        fun inv(x: Long, mod: Long = MOD): Long {
            return toPower(x, mod - 2)
        }

        fun simpleInf(nenner: Long, zaehler: Long): Long {
            return nenner * Inv.inv(zaehler) % Inv.MOD
        }
    }
}

'

Read more »

 
 
 
 
  • Vote: I like it
  • +14
  • Vote: I do not like it