Codeforces Round 684(Div.2) Question C1:
https://codeforces.com/contest/1440/problem/C1
What is wrong in my solution and why is the above mentioned error occuring in the below commented line for each of solution. I am doing the in the specified number of operations and my output is also coming correct but each time i go to submit my solution it throws the error mentioned in the title . What is wrong in that line or in the entire for the given question?
My solution:
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int arr[n][m];
int c=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>arr[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
c+=arr[i][j]; **//error occuring in this line**
}
}
cout<<(c*3)<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(arr[i][j]==1&&(i!=n-1&&j!=m-1)){
cout<<(i+1)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+2)<<" "<<(i+2)<<" "<<(j+2)<<endl;
cout<<(i+1)<<" "<<(j+1)<<" "<<(i+2)<<" "<<(j+1)<<" "<<(i+2)<<" "<<(j+2)<<endl;
cout<<(i+2)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+2)<<endl;
}
else if(arr[i][j]==1&&(i==n-1||j==m-1)){
if(j==m-1&&i<n-1){
cout<<(i+2)<<" "<<(j)<<" "<<(i+1)<<" "<<(j)<<" "<<(i+1)<<" "<<(j+1)<<endl;
cout<<(i+2)<<" "<<(j)<<" "<<(i+2)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+1)<<endl;
cout<<(i+1)<<" "<<(j)<<" "<<(i+1)<<" "<<(j+1)<<" "<<(i+2)<<" "<<(j+1)<<endl;
}
if(i==n-1&&j<m-1){
cout<<(i+1)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+2)<<" "<<(i)<<" "<<(j+2)<<endl;
cout<<(i+1)<<" "<<(j+1)<<" "<<(i)<<" "<<(j+1)<<" "<<(i)<<" "<<(j+2)<<endl;
cout<<(i)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+2)<<endl;
}
if(i==n-1&&j==m-1){
cout<<(i)<<" "<<(j)<<" "<<(i+1)<<" "<<(j)<<" "<<(i+1)<<" "<<(j+1)<<endl;
cout<<(i)<<" "<<(j)<<" "<<(i)<<" "<<(j+1)<<" "<<(i+1)<<" "<<(j+1)<<endl;
cout<<(i+1)<<" "<<(j)<<" "<<(i+1)<<" "<<(j+1)<<" "<<(i)<<" "<<(j+1)<<endl;
}
}
}
}
}
return 0;
}