▲ 1 r/codeforces
rant on today's div 2
took me way too long to do a and b, mainly cause stuff was happening around me, i skipped C and D because I couldnt figure out an approach, might revisit them later
finally, I figured out what to do for E, wrote a code, then spent an hour debugging the code, first for a sigfpe and then for an answer delivery error. I couldn't find the error, so after the contest ended, I gave it to gemini to see what it was.
ONE IF CONDITION ERROR.
The cherry on the top was that my code got accepted, too late though.
This was my code:
- #include <bits/stdc++.h>
- using namespace std;
- void solve(){
- int l, r, n, x = 0;
- cin >> l >> r >> n;
- vector<bool> a(32, false), b(32, false), c(32, false);
- for(int i = 0; i < 31; i++){
- if(r & (1 << i)) a[i] = true;
- if(l & (1 << i)) b[i] = true;
- //if(a[i] && b[i]) cout << i;
- }
- int i = 32;
- while(i > 0){
- i--;
- if(a[i]==b[i]) c[i] = a[i];
- else{
- c[i] = a[i];
- break;
- }
- }
- for(int i = 31; i >= 0; i--){
- x *= 2;
- if(c[i]) x++;
- //if(c[i]) cout << i << " ";
- }
- int y = l;
- y = max(1 << (31 - __builtin_clzl(x - 1)), l);
- //cout << x << " " << y << endl;
- string s1 = "", s2 = "";
- while(x > 0){
- s1 += (x % 2) ? '1' : '0';
- x /= 2;
- }
- while(y > 0){
- s2 += (y % 2) ? '1' : '0';
- y /= 2;
- }
- if (s1.empty()) s1 = "0";
- if (s2.empty()) s2 = "0";
- reverse(s1.begin(), s1.end());
- reverse(s2.begin(), s2.end());
- int p = s1.size(), q = s2.size();
- for(int i = 0; i < n; i++){
- if((s1[i % p] - '0') && (s2[i % q] - '0')) cout << '1';
- else cout << '0';
- }
- cout << "\n";
- }
- int main() {
- // your code goes here
- int t;
- cin >> t;
- while(t--) solve();
- }
u/TheBoredBot — 1 day ago