lundi 30 septembre 2019

error C2131: expression did not evaluate to a constant

When i run the program in codeblocks it works fine. but when i submitted it in codeforces it shows the error. why? i saw some solutions for one dimensional arrays. but what about multidimensional arrays? how to take variable length for multidimensional arrays?

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
  int h,w;
  cin>>h>>w;
  int hi[h],wi[w],arr[h][w];
  memset(arr,0,sizeof(arr));
  long long int result=1;
  for(int i=0;i<h;i++)cin>>hi[i];
  for(int i=0;i<w;i++)cin>>wi[i];
  for(int i=0;i<h;i++){
    for(int j=0;j<=hi[i];j++){
      if(j!=w)arr[i][j]=1;
    }
  }
  for(int i=0;i<w;i++){
    for(int j=0;j<=wi[i];j++){
      if(j!=h)arr[j][i]=1;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      //cout<< arr[i][j]<<" ";
      if(arr[i][j]==0){
          result*=2;
      }
    }
    //cout<<endl;
  }
  if(result==1)result=0;
  printf("%lld\n",result%1000000007);
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire