CENS20A-Cherry and Bits, https://www.codechef.com/problems/CENS20A

Why I’m getting wrong answer?
What is the mistake in this code?

https://www.codechef.com/viewsolution/37012722

CODE:-
#include
using namespace std;
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main() {
speed
int n,m;
cin>>n>>m;
int a[n][m];
for(int i=0;i<n;i++)
{
cin>>a[i][0];
int s=m;
while(s!=1)
{
s–;
a[i][s]=a[i][0]%10;
a[i][0]/=10;
}
}
int test;
cin>>test;
while(test–)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
for(int i=x1-1;i<x2;i++)
{
for(int j=y1-1;j<y2;j++)
{
(a[i][j])? a[i][j]=0:a[i][j]=1;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<a[i][j];
}
cout<<‘\n’;
}
return 0;
}

Take the input as a string. It is impossible to store a number of m digits(max-1000)
in int or any other data type in c++. Moreover, after taking the input as string also it will give TLE.
Do this :-
string s;
cin >> s;
for(int j=0; j<m; j++)
a[i][j] = s[j]-‘0’;

1 Like