Блог пользователя Mr.Whitebird

Автор Mr.Whitebird, история, 5 месяцев назад, По-английски

Hello CodeForces, today I was solving the problem 1985H2 - Maximize the Largest Component (Hard Version) and implemented it with C++. It passes all the tests seperately but throws RE when I try to run multiple tests. I have been debugging for around half an hour but can't find the problem. I would appreciate any help. Here is my submission:268092158

PS: Local compiler also throws RE.

  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Mr.Whitebird (previous revision, new revision, compare).

»
5 месяцев назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

268105858

Your problem was at lines vi rs(n+2,0),cs(m+2,0); and

    for (int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if (grid[i][j] == '.') continue;
            if (find({i,j}) == pii{i,j}) {
                rs[top[i][j]-1]+=sz[i][j];
                rs[bot[i][j]+2]-=sz[i][j]; // this line
                cs[le[i][j]-1]+=sz[i][j];
                cs[ri[i][j]+2]-=sz[i][j]; // and this one 
                update(top[i][j]-1,le[i][j]-1,bot[i][j]+1,ri[i][j]+1,sz[i][j]);
            }
        }
    }

Your array bounds are not correct. Because you are accessing bot[i][j]+2 and ri[i][j]+2 your array bounds are suppose to be n+3 and m+3. This bug was hard to detect because this error does not cause segmentation fault immediately and gets caught many lines later in the loop while (t --> 0) solve(); in main. So the program seems to be working for a single testcase and fail at many, in actuality it fails a single case too but runtime error doesn't get caught.

»
5 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Mr.Whitebird (previous revision, new revision, compare).