Where is the segfault taking place in this code? It ran perfectly even in gdb but codechef throws a segfault.
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
|
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int t=0, n=0;
cin>>t;
float res[t];
for(int i=0;i<t;i++){
cin>>n;
int b[n][n], g[n][n],c=0;
for(int j=0;j<n;j++){
cin>>b[0][j];
for(int k=1;k<n;k++){
b[k][j] = b[0][j];
}
}
for(int j=0;j<n;j++){
cin>>g[0][j];
for(int k=1;k<n;k++){
g[k][j] = g[0][j];
}
}
for(int x=0;x<n;x++){
for(int k=x;k<n;k++){
for(int l=0;l<n;l++){
if(b[x][k] && g[k][l] && (pow(b[x][k],g[k][l]) > pow(g[k][l],b[x][k]))){
c++;
b[x][k] = 0;
g[k][l] = 0;
}
}
}
}
res[i] = c/n;
}
for(int i=0;i<t;i++){
cout<<res[i];
if(i < t-1)
cout<<endl;
}
return 0;
}
|
Last edited on
Last edited on
These are the constraints:
1 ≤ T ≤ 5
1 ≤ N ≤ 10^5
1 ≤ Bi ≤ 10^9
1 ≤ Gi ≤ 10^9
Would using vectors solve the problem?
Last edited on