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

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

Today is pretty much like another day, I choose to grind some codeforces problem here and there... I choose to solve this problem today: Grid XOR

It so happens I wrote a solution and tested on local, works perfectly fine. But when I submitted OJ tell me it's runtime error on test 1 (?)

This never happened to me before so I'm confused. So I happen to submitted mutliple bad subs to test what actually happened, and this is what I've found: Compared this 2 submission: 314967876 vs 314969708

The only difference is this line of code, and it causes RTE:

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

What happened to python fastIO input? Just pretty much yesterday everything works fine and now it doesn't? I tried to scramble blogs updated from yesterday till today and found nothing.

Can anyone fill me up what's happening?

Полный текст и комментарии »

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

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

Today I find that python swap value hack doesn't work as intended all the time. Maybe the best practice is just write code line by line instead of this? If can someone please explain to me is there anything wrong?

Intention: Swap a and b

Python: a, b = b, a (usually works all the time and I actually use this in today div3C)

Expected: b, a = a, b works the same as above

But this time it doesn't work as intended

    for _ in range(int(input())):
        n = int(input())
        a = list(map(int, input().split()))
        a = [x-1 for x in a]
        res = 0
        for i in range(n):
            if a[i]>=0:
                mlen = 0
                ix = i
                while a[ix]>=0:
                    a[ix], ix = -1, a[ix]
                    #ix, a[ix] = a[ix], -1 # doesn't work the same as above
                    mlen+=1
                res += (mlen-1)//2
        print(res)

Полный текст и комментарии »

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