USACO Training Wrong Output

Problem Broken Necklace https://train.usaco.org/usacoprob2?a=db9DeXdtp4m&S=beads

After Submitting my Code it says my output is 12 and the correct answer is 11,
but if i try it on my own I also get 11.

Any Suggestion what I could be doing wrong?

My Code

   #include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()

{
    string kette;
    int dadad;
    ofstream out ("beads.out");
    ifstream in ("beads.in");
    in >> dadad;
    in >> kette;
    kette = kette + kette;
    int r = 0;
    int b = 0;
   
    char l = 0; 
    char ll = 0;
    
    int tot = 0; int totMax = 0;
    
    bool rb;
    bool bb;
    
    int r_b = 0;
    int b_r = 0;
    
    for(int i = 0; i < kette.length(); i++) {
        
        if(l == 0 && ll == 0 && kette[i] != 'w') {
            if(kette[i] == 'r') {
                l = 'b'; 
                ll = 'b'; 
            }
            
            if(kette[i] == 'b') {
                l = 'r'; 
                ll = 'r'; 
            }
            
        }
        
        if(kette[i] == 'r') {
            rb = 1;
            bb = 0;
        }
        
        if(kette[i] == 'b') {
            bb = 1;
            rb = 0;
        }
        
        if(kette[i] == 'r') {
    
            if(ll != l && l != 'r') {
                r = 0;
                ll = 'b';
            }   
            
            l = 'r';
            r++;
            
        }
        
        if(kette[i]== 'b') {
            
            if(ll != l && l != 'b') {
                b = 0;
                ll = 'r';
                
            }
            
            l = 'b';
            b++;
        }
         
        if(kette[i] == 'w') {
            for(int j = i + 1; j < kette.length(); j++) {
                
                if(kette[j] != 'w') {
                    
                    if(!rb && !bb) {
                        
                        if(kette[j] == 'r') {
                            r++;
                            break;
                        }
                        
                        if(kette[j] == 'b') {
                            b++;
                            break;
                        }
                    }
                   
                    if(rb) {
                        if(kette[j] == 'r') { 
                            r++;
                            
                            break;
                        }
                        
                        if(kette[j] == 'b') { 
                            r_b = 0;
                            r_b++;
                            break;
                        }
                    }
                    
                    if(bb) {
                        if(kette[j] == 'b') { 
                            b++;
                            break;
                        }
                        
                        if(kette[j] == 'r') { 
                            b_r = 0;
                            b_r++;
                            break;
                        }
                    }
                    
                }
            }
           
        }
        
        tot = r + b + r_b + b_r; //r_b + b_r;
        if(tot > totMax) totMax = tot;
        
    }
    if(totMax > dadad) totMax = dadad;    
    out << totMax << endl;
    
    

    return 0;
}

when i compiled ur code w/ flags i got

1163.cpp:112:21: warning: 'bb' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |                     if(bb) {
      |                     ^~
1163.cpp:98:21: warning: 'rb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   98 |                     if(rb) {
1 Like

How do you compile code with flags? Where do you input the flags into the compiler? Note: I am using CodeBlocks.

What flags do you use to get the error messages to pop up?

um i compile with the command line. iā€™m not sure about CodeBlocks though.

the flags i used are

-Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector -DLOCAL

see