RE(OTHER)

closed account (STD8C542)
I'm getting RE(OTHER) on this code on codehchef

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while(t--){
        long int n, m, k, r, c;
        cin >> n >> m >> k;
        int a[n][m];
        memset(a,0,sizeof(a[0][0]) * n * m);
        long long int ans = k*4;
        while(k--){
            cin >> r >> c;
            a[r-1][c-1] = 1; 
        }
        int count = 0, flag = 0;
        for(int i = 0; i < n; i++){
            flag = 0;
            for(int j = 0; j < m; j++){
                if(a[i][j] == 0){
                    flag = 0;
                    continue;
                }
                if(a[i][j] == 1){
                    if(flag == 1){
                        count+=2;
                    }
                    flag = 1;
                }
            }
        }
        flag = 0;
         for(int i = 0; i < m; i++){
             flag = 0;
            for(int j = 0; j <n; j++){
                if(a[j][i] == 0){
                    flag = 0;
                    continue;
                }
                if(a[j][i] == 1){
                    if(flag == 1){
                        count+=2;
                    }
                    flag = 1;
                }
            }
        }
        cout << ans-count << endl;
    }
}
You're going to have to do better than just dumping your code.

Like for example
- a link to the actual problem.
- the input you provide to the program.

> int a[n][m];
1. C++ doesn't allow variable length arrays.
2. If m,n are large, you could be blowing up the stack.
If m * n * sizeof(int) is much larger than say 1MB, you could be stuck.

> for(int i = 0; i < n; i++){
> for(int j = 0; j < m; j++){
From past observation, most CF problems require you to sit down and think of a smart way to solve the problem.
And not go for the obvious brute-force "try everything" approach.
Topic archived. No new replies allowed.