When I was doing the problem C. Pokémon Arena in the last Div. 1 round, I submitted my solution and got a TLE on test 20.
- GNU C++20 (64), TLE 3000ms 248951083
I thought there may be some degenerate issue, undefined behavior or some constant issue, but nothing really found. After some unsuccessful attempts, I was able to pass the pretest using fast IO. It's weird since it only takes a few hundred milliseconds, which is contradictory to intuition: cin with sync_with_stdio(false)
is fairly fast and it should not take up at least 10x more time.
After the contest, I submit exactly the same code with different language. You know what?
- GNU C++17, AC 280ms 248983571
It's not only me, and some other participants also encountered such issue. For example:
- GNU C++20 (64), TLE 248946386 by fallleaves01.
But there are also some successful cin submission using GNU C++20 (64).
Here's snippet for the key code:
int n, m;
cin >> n >> m;
vector a(n, vector (m, 0));
vector c(n, 0);
for (int i = 0; i < n; i++) cin >> c[i];
vector ranks (m, vector < pii >());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
ranks[j].push_back({a[i][j], i});
}
}
After some investigation by (including but not limit to) Sugar_fan, Boboge, -skyline-, the key components of TLE is:
- The language must be GNU C++20 (64).
vector
must be ofint
. If the elements arelong long
, it passed. 249004456- The definition of 2D vector must be before reading
c
. If swap these two lines, it passed. 249004217
So here's the thing. It could not even be interpreted as some branch mispredictions or cache misses, it seems something is completely broken, but we still do not understand what is happening.