Xiaohuba's blog

By Xiaohuba, history, 2 months ago, In English

UPD: I've reduced the code size.

I've recently found that the following code will generate wrong output.

#include <bitset>
#include <iostream>
const int N = 105;
std::bitset<N> ok[N][N];
int n = 5;
int main() {
  ok[2][2].set(2);
  for (int i = n; i; i--)
    for (int j = i; j <= n; j++) {
      ok[i][j] = ok[i][j] | ok[i + 1][j] | ok[i][j - 1];
    }
  std::cout << ok[2][5][2] << '\n';
  return 0;
}

Compiled with -O3 -mtune=skylake -march=skylake, the code outputs 0.

However if you simulate the code you will know that the correct answer should be 1.

Note that the compiler seems to generate wrong sse instruction.

Godbolt link

Again, I believe this code is ub-free, and has nothing to do with implementation-defined stuff.

Full text and comments »

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

By Xiaohuba, history, 3 months ago, In English

UPD: It is a compiler bug, and is resolved since gcc 12.3. Further information is on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116459.

[Apologize for my poor English.]

The code at https://godbolt.org/z/PP1TTdhxf outputs 1. However, if you simulate the code, the answer is obviously 20.

Further exploration showed that the compiler compiled function qpw, but did not call it. Uncomment line 22 solves the issue, surprisingly. Further more, the bug seems to only occur on gcc12.1 and gcc12.2, with -O2 enabled.

I believe the code does not contain any undefined / unspecified behavior.

Full text and comments »

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

By Xiaohuba, 9 months ago, In English

Today is December 30th in Chinese Lunar Calendar (a.k.a Chinese New Year Eve).

We will enter the Year of Dragon in a few hours. Quite different from western culture, dragon (which sounds like "loong 龙" in Chinese), is an animal that symbolizes power, wisdom and strength.

The CF community has been passing through a hard time. We've experienced an explosive Goodbye 2023 Round, and there are more contentious topics. But anyway, we hope we will come into a entirely new, wonderful Chinese New Year! Hope that Codeforces will be a platform purely for competitive programming, where contests of good quality are held frequently, and people around the world are able to discuss academic problems freely.

Let's wait for the moment that the Year of Dragon comes!

UPD: The Year of Dragon has arrived. Happy Chinese New Year!

Full text and comments »

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

By Xiaohuba, history, 18 months ago, In English

These days I'm trying to compile the following c++ code:

#include<vector>

const int MAXN=1e5+5;
std::vector<int> factor[MAXN];

signed main() {return 0;}

This code works while I'm using g++ 11.3.0. However, if I use g++ 13.1.0 or 12.1.0, I'll receive a compile error:

/var/folders/v7/yk8tz4j54cl2lhp1f80nyz700000gn/T//cc2HpyzP.s:371:29: error: unexpected token in '.section' directive
        .section .data.rel.ro.local

Reinstalling the compiler doesn't works. What should I do?

Note I use Apple M1 with MacOS 13.2.1 (22D68).

Full text and comments »

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