Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

CORNER SUBGRID COUNT CSES : PRAGMA TARGET(POPCNT) V/S PRAGMA O3 OPTIMIZATION

Revision en2, by anaconda666, 2025-09-21 12:24:21

I was stuck on this CSES question : Corner Subgrid Count for nearly 2 months, when I had already got the approach at the first view only. (It's not that I have been trying daily since the last 2 months, I got TLE and I left... bruhh — )

And I just figured out that I was not using the correct compile-time optimization (bruh-, what the hell was that). I was trying with Ofast and O3 optimizations but just do popcnt optimization and you are done. My approach (as obvious) was just break each row into bits of size 64, do pairwise-AND and tally the number of bits set in the pairwise-ANDs. Finally, add (count*(count — 1))/2 to the ans.

But I am amazed to see that how powerful a tool pragma actually is and how it can make your life easy :

TLE-ed Code
Accepted Code

If any of you got it Accepted without Pragma, I would love to hear that too

Tags cses, advanced techniques, corner subgrid count, pragma

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English anaconda666 2025-09-21 12:24:21 111 Tiny change: 'd Code">\nTLE-ed code : \n\n~~~~~\n#include' -> 'd Code">\n#include'
en1 English anaconda666 2025-09-21 11:45:29 4991 Initial revision (published)