fork(6) download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iomanip>
  5. #include<cmath>
  6. #include<cstdlib>
  7. #include<algorithm>
  8. using namespace std;
  9. short int mat[2001][2001];
  10. int main(){
  11. // cout<<"hi";
  12. int n;
  13. scanf("%d",&n);
  14. int i;
  15. int arr[1001],top;
  16. int ans=0;
  17. for(i=1;i<=n;i++){
  18. top=0;
  19. char ch;
  20. int j;
  21. getchar();
  22. for(j=1;j<=n;j++){
  23. ch=getchar();
  24. if(ch=='0')
  25. continue;
  26. else{
  27.  
  28. top++;
  29. arr[top]=j;
  30. //printf("top%darr%d ",top,arr[top]);
  31. if(mat[i][j]==1)
  32. {
  33. mat[i][j]=-1;
  34. mat[j][i]=-1;
  35. ans-=2;
  36. }
  37. if(mat[i][j]==0){
  38. mat[i][j]=-1;
  39. mat[j][i]=-1;
  40. }
  41. }
  42.  
  43.  
  44. }int u,y;
  45. //for(u=1;u<=top;u++)
  46. //printf("%d ",arr[u]);
  47. for(u=1;u<top;u++)
  48. for(y=u+1;y<=top;y++){
  49. if(mat[arr[u]][arr[y]]==0){
  50. mat[arr[u]][arr[y]]=1;
  51. mat[arr[y]][arr[u]]=1;
  52. ans+=2;
  53. }
  54. }
  55. //printf("ansis %d",ans);
  56.  
  57. }printf("%d\n",ans);
  58. cin.get();
  59. cin.get();
  60. }/*
  61. 9
  62. 011100000
  63. 101100000
  64. 110100000
  65. 111000001
  66. 000000000
  67. 000000100
  68. 000001000
  69. 000000001
  70. 000100010*/
  71.  
Success #stdin #stdout 0s 11120KB
stdin
Standard input is empty
stdout
0