AlveRahman's blog

By AlveRahman, history, 3 years ago, In English

Why the same code, when submitted using GNU C++17 got accepted but when submitted using GNU C++17 (64) gave wrong answer ? This is the accepted one https://codeforces.net/contest/1365/submission/122433105 and this is the wrong one https://codeforces.net/contest/1365/submission/122431881 .

  • Vote: I like it
  • +9
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

You have UB somewhere

»
3 years ago, # |
Rev. 3   Vote: I like it +4 Vote: I do not like it

more like compiler bug...

I tried your code in customtest with this test

1 2 2 #B G.

added some print before final two loops

cout<<s[1][0]<<endl;
cout<<vis[1][0]<<endl;
rep(i,0,n){
    rep(j,0,m){
        if((s[i][j]=='G' and not vis[i][j]) or (s[i][j]=='B' and vis[i][j])){
            ok=0; break;
        }
    }
    if(not ok) break;
}
if(ok) cout<<"Yes\n";
else cout<<"No\n";

it prints

G

0

Yes

Removing one of break; (or both) gives correct behavior