fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
  5. #define time cerr<<"Time taken : " <<(float)clock()/CLOCKS_PER_SEC <<" secs"<<"\n" ;
  6. #define F first
  7. #define S second
  8. #define pb push_back
  9. typedef long long int ll ;
  10.  
  11.  
  12. const ll INF = (ll)1e18 ;
  13. const ll MOD = (ll)1e9 + 7 ;
  14.  
  15.  
  16. /*-------------------------------------------------------------------------------------------------------------*/
  17.  
  18. void solve() {
  19.  
  20. ll n;
  21. cin >> n;
  22.  
  23. string str ;
  24. cin >> str;
  25.  
  26. string arr[n+1] ;
  27.  
  28. for(ll i=1;i<=n; i++){
  29. for(ll j=1;j<=n;j++){
  30.  
  31. if(i==j){
  32. arr[i][j] = 'X' ;
  33. }
  34. else{
  35. arr[i][j] = '=' ;
  36. }
  37. }
  38. }
  39.  
  40. vector<ll>one,two ;
  41.  
  42. for(ll i=0; i<n; i++){
  43. if(str[i]=='1'){
  44. one.pb(i+1) ;
  45. }
  46. else{
  47. two.pb(i+1) ;
  48. }
  49. }
  50.  
  51. if(two.size()<=2 && !two.empty()){
  52. cout <<"NO\n" ;
  53. return ;
  54. }
  55.  
  56. sort(two.begin(),two.end()) ;
  57.  
  58.  
  59. ll p = two.size() ;
  60. if(two.size() > 0) {
  61.  
  62. for (ll i = 0; i < p-1 ; i++) {
  63. // cout << two[i] << " " << two[i + 1] << " ";
  64. arr[two[i]][two[i+1]] = '+' ;
  65. arr[two[i+1]][two[i]] = '-' ;
  66. }
  67.  
  68. arr[two[p-1]][two[0]] = '+' ;
  69. arr[two[0]][two[p-1]] = '-' ;
  70. }
  71. // cout <<"\n" ;
  72.  
  73. // arr[two[p-1]][two[0]] = '+' ;
  74.  
  75. bool check = 1 ;
  76.  
  77. for(ll i=1;i<=n;i++){
  78. for(ll j=1;j<=n; j++){
  79.  
  80. if(i==j){
  81. if(arr[i][j]!='X'){
  82. check = 0 ;
  83. break ;
  84. }
  85. }
  86.  
  87. if(!check){
  88. break ;
  89. }
  90. }
  91. if(!check){
  92. break ;
  93. }
  94. }
  95.  
  96. if(!check){
  97. cout <<"NO\n" ;
  98. return ;
  99. }
  100. else{
  101. cout <<"YES\n" ;
  102. for(ll i=1;i<=n;i++){
  103. for(ll j=1;j<=n; j++){
  104. cout << arr[i][j] ;
  105. }
  106. cout <<"\n" ;
  107. }
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114. //cout <<"\n";
  115. }
  116.  
  117.  
  118. int32_t main() {
  119.  
  120. fast ; time;
  121.  
  122.  
  123.  
  124. int t = 1;
  125. cin >> t;
  126.  
  127. while (t--) {
  128. solve() ;
  129. }
  130.  
  131.  
  132. return 0 ;
  133. }
  134.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:134:1: error: stray ‘\302’ in program
  
 ^
prog.cpp:134:2: error: stray ‘\240’ in program
  
  ^
stdout
Standard output is empty