fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int arr1[103][103];
  5. string arr[103];
  6.  
  7. int checkthewinner (int x,int y)
  8. {
  9. int pp=arr[x-1][y-1]-48;
  10. if (pp==1)
  11. return x;
  12. return y;
  13. }
  14.  
  15. int next (int i,int j,int n)
  16. {
  17. if (i+j==n)
  18. return i+j;
  19.  
  20. int varr=(i+j)%n;
  21.  
  22. return varr;
  23. }
  24.  
  25. int main()
  26. {
  27. int n;
  28. scanf ("%d",&n);
  29.  
  30. for (int i=0; i<n ; i++)
  31. cin >> arr[i];
  32.  
  33. for (int i=1; i<=n ; i++)
  34. arr1[i][next(i,1,n)]=1;
  35.  
  36. for (int length =2; length<n; ++length)
  37. {
  38. for (int beg=1; beg<=n; beg++)
  39. {
  40. int endd=next(beg,length,n);
  41.  
  42. for (int k=next(beg,1,n); k!=endd ;k=next(k,1,n))
  43. if (arr1[beg][k]==1 && arr1[k][endd]==1 && (arr[beg-1][k-1]-48==1 || arr[endd-1][k-1]-48==1 ) )
  44. arr1[beg][endd]=1;
  45.  
  46. }
  47. }
  48.  
  49. int winners=0;
  50.  
  51. for (int i=1; i<=n ; i++)
  52. for (int j=1; j<=n; j++)
  53. if (arr1[i][j]==1 && arr1[j][i]==1)
  54. {
  55. int xxx=checkthewinner(i,j);
  56. if (arr1[xxx][xxx]==0)
  57. {
  58. arr1[xxx][xxx]=1;
  59. winners++;
  60. }
  61.  
  62. }
  63.  
  64. printf ("%d\n", winners);
  65.  
  66. for (int i=1; i<=n;++i)
  67. if(arr1[i][i]==1)
  68. printf ("%d\n", i);
  69.  
  70. return 0;
  71. }
Runtime error #stdin #stdout 1.79s 3508KB
stdin
Standard input is empty
stdout
Standard output is empty