Блог пользователя BanazadehAria

Автор BanazadehAria, история, 5 лет назад, По-английски

This is my code for 611C problem on code forces

And this is my code but i dont know why it is wrong?

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e3;
char graph[MAXN][MAXN];
int vertic[MAXN][MAXN],hort[MAXN][MAXN];

int main()
{
    int row,col;cin >> row >> col;
    for(int i=0;i<row;++i){
        for(int j=0;j<col;++j){
            cin >> graph[i][j];
        }
    }
    // Now we precompute all of them
    vertic[0][0]=0;
    for(int i=1;i<row;++i){
        vertic[0][i] = vertic[0][i-1];
        if(graph[0][i] == graph[0][i-1] && graph[0][i]=='.') ++vertic[0][i];
    }
    for(int i=1;i<col;++i){
        hort[i][0] = hort[i-1][0];
        if(graph[i][0] == graph[i-1][0] && graph[i][0]=='.') ++hort[i][0];
    }
    for(int i=1;i<row;++i){
        for(int j=1;j<col;++j){
            vertic[i][j] = vertic[i-1][j] + vertic[i][j-1] - vertic[i-1][j-1] + (graph[i][j-1]=='.' && graph[i][j]=='.');
            hort[i][j] = hort[i-1][j] + hort[i][j-1] - hort[i-1][j-1] + (graph[i-1][j] =='.' && graph[i][j]=='.');
        }
    }
    int q;cin >> q;
    for(int i=0;i<q;++i){
        int r1,c1,r2,c2;cin >> r1 >> c1 >> r2 >> c2;--r1;--c1;--r2;--c2;
        int vecOne = vertic[r2][c2] - vertic[r2][c1] - vertic[r1][c2] + vertic[r1][c1];
        int horOne = hort[r2][c2] - hort[r2][c1] - hort[r1][c2] + hort[r1][c1];
        cout << vecOne + horOne << endl;
    }
}
  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

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

You are asking what's wrong with your code? You should be asking what's wrong with yourself first. Fancy posting a wall of unreadable code without any explanation at all. I don't think anyone's gonna help you to debug.

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

    You can dont answer me but you can't choose for others

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      What he meant was, by posting a blog like this, it's really unlikely that anyone will go through the trouble to help you. I suggest you do the following:

      • Put a direct link to the problem you're trying to solve in the blog to ease the access(maybe to the editorial as well).

      • Explain your approach(the algorithm you used not the code) so that people will first see if the idea is wrong, else the fault will be in the implementation.

      • Then finally comment your code and use meaningful names for variables. The more you comment the better.