# | User | Rating |
---|---|---|
1 | ecnerwala | 3648 |
2 | Benq | 3580 |
3 | orzdevinwang | 3570 |
4 | cnnfls_csy | 3569 |
5 | Geothermal | 3568 |
6 | tourist | 3565 |
7 | maroonrk | 3530 |
8 | Radewoosh | 3520 |
9 | Um_nik | 3481 |
10 | jiangly | 3467 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
2 | adamant | 164 |
4 | TheScrasse | 159 |
4 | nor | 159 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 150 |
8 | SecondThread | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
Name |
---|
You have to flush your output. Write: fflush(stdout); After everytime you print something. Also, for interactive problems, I don't advise using ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); because it might interfere with reading input and output. You won't need the speed gains anyway for interactive problems.
Absence of flush causes IL, not TL. And TS uses endl, which flushes output
Still TLE, please look at this submission
(i've added flush and removed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0))
Your first for should be
for (int i = 0; (1 << i) < n * n; ++i)
, what a great typo :)I'm calculating row and column using (i / n) and (i % n). So I think
i < n * n
is right. I've wronged somewhere else.Please Please look once again.
No, I'm talking about first for, right after reading n. You output all powers of two for all i from 0 to n, not all powers of two, which are less than n
The question requires doing just that, Also he's getting TLE at case 6(not 1). Please, look at the editorial if you don't want to read the whole question.
Ah, sorry, I was just seeing output on tc 6 and was guessing it's overflow. And I was right, but in other place. If n is 6, n * n is 36 and TS gets bit up to 36, which causes overflow. It can be fixed by changing to 1ll << i, but n is up to 25
Ouch, I was right. He prints powers of two till n * n, which is big enough to overflow
Your issue seems to be overflow. On the following lines:
$$$i \in [0, n^2 - 1]$$$, so $$$2^{i + 1}$$$ can be up to order of magnitude $$$10^{188}$$$ far overflowing any bit integer data type in C++. The reason why you get TLE instead of something else like WA is likely because your terminating condition is specifically
i != n * n - 1
, and because the if statement is now essentially gibberish since1 << (i + 1)
is just overflowed gibberish, youri
might exceedn * n - 1
without ever beingn * n - 1
exactly, so the while loop runs forever.To confirm this, I changed
1 << (i + 1)
to1LL << (i + 1)
to increase size up to 64-bit integer, so now it doesn't overflow for $$$n = 6$$$ and makes it to test 8.