fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ll n,q;cin>>n>>q;
  8. ll b[n][n];
  9. for(ll i=0;i<n;i++)
  10. {
  11. for(ll j=0;j<n;j++)
  12. {
  13. cin>>b[i][j];
  14. }
  15. }
  16. ll ans[n];
  17. memset(ans,0,sizeof(ans));
  18. ll h;
  19. for(ll i=1;i<(n-1);)
  20. {
  21. ll x=b[0][i];
  22. ll y=b[0][i+1];
  23. ll z=b[i][i+1];
  24. h=i+1;
  25. if(x+y==z&&x!=0)
  26. {
  27. ans[i]=x-2*x;
  28. ans[i+1]=y;
  29. i++;
  30. }
  31. else if(x==0)
  32. {
  33. ans[i]=0;
  34. }
  35. else
  36. {
  37. ans[i]=x-2*x;
  38. ans[i+1]=y-2*y;
  39. i++;
  40. }
  41. i++;
  42. }
  43. if(h==n-1)
  44. {
  45. ll i=n-2
  46. ll x=b[0][i];
  47. ll y=b[0][i+1];
  48. ll z=b[i][i+1];
  49. if(x+y==z&&x! =0)
  50. {
  51. if(x<0)
  52. ans[i+1]=y;
  53. else ans[i+1]=y-2*y;
  54.  
  55. }
  56. else if(x==0)
  57. {
  58. ll c=-1;
  59. for(ll j=1;j<i;j++)
  60. {
  61. if(ans[i]! =0) {c=j;break;}
  62. }
  63. if(c==-1) {ans[i+1]=y-2*y;}
  64. else{
  65. ll x=b[0][c];
  66. ll y=b[0][i+1];
  67. ll z=b[c][i+1];
  68. if(x+y==z) {
  69. if(x<0)
  70. ans[i+1]=y;
  71. else ans[i+1]=y-2*y;
  72. }
  73. else{
  74. if(x<0)
  75. ans[i+1]=y-2*y;
  76. else ans[i+1]=y;
  77. }
  78. }
  79. }
  80. else
  81. {
  82. if(x<0)
  83. ans[i+1]=y-2*y;
  84. else ans[i+1]=y;
  85.  
  86. }
  87. }
  88. for(ll i=0;i<n;i++)
  89. {
  90. cout<<ans[i]<<" ";
  91. }
  92. cout<<endl;
  93. while(q--)
  94. {
  95. ll p;cin>>p;
  96. p--;
  97. ll a[n];
  98. for(ll i=0;i<n;i++)
  99. {
  100. cin>>a[i];
  101.  
  102. }
  103. for(ll i=0;i<n;i++)
  104. {
  105. b[i][p]=a[i];
  106. b[p][i]=a[i];
  107. }
  108. h=0;
  109. for(ll i=1;i<(n-1);)
  110. {
  111. h=i+1;
  112. ll x=b[0][i];
  113. ll y=b[0][i+1];
  114. ll z=b[i][i+1];
  115. if((x+y)==z&&x!=0)
  116. {
  117. ans[i]=x-2*x;
  118. ans[i+1]=y;
  119. i++;
  120. }
  121. else if(x==0)
  122. {
  123. ans[i]=0;
  124.  
  125. }
  126. else
  127. {
  128. ans[i]=x-2*x;
  129. ans[i+1]=y-2*y;
  130. i++;
  131. }
  132. i++;
  133. }
  134. if(h==n-1&&b[0][n-2]==0)
  135. {
  136. ll i=n-2
  137. ll x=b[0][i];
  138. ll y=b[0][i+1];
  139. ll z=b[i][i+1];
  140. if(x+y==z&&x! =0)
  141. {
  142. if(x<0)
  143. ans[i+1]=y;
  144. else ans[i+1]=y-2*y;
  145.  
  146. }
  147. else if(x==0)
  148. {
  149. ll c=-1;
  150. for(ll j=1;j<i;j++)
  151. {
  152. if(ans[i]! =0) {c=j;break;}
  153. }
  154. if(c==-1) {ans[i+1]=y-2*y;}
  155. else{
  156. ll x=b[0][c];
  157. ll y=b[0][i+1];
  158. ll z=b[c][i+1];
  159. if(x+y==z) {
  160. if(x<0)
  161. ans[i+1]=y;
  162. else ans[i+1]=y-2*y;
  163. }
  164. else{
  165. if(x<0)
  166. ans[i+1]=y-2*y;
  167. else ans[i+1]=y;
  168. }
  169. }
  170. }
  171. else
  172. {
  173. if(x<0)
  174. ans[i+1]=y-2*y;
  175. else ans[i+1]=y;
  176.  
  177. }
  178. }
  179. for(ll i=0;i<n;i++)
  180. {
  181. cout<<ans[i]<<" ";
  182. }
  183. cout<<endl;
  184. }
  185. return 0;
  186. }
  187.  
  188.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:2:12: error: expected ‘,’ or ‘;’ before ‘long’
 #define ll long long
            ^
prog.cpp:46:11: note: in expansion of macro ‘ll’
           ll x=b[0][i];
           ^~
prog.cpp:49:6: error: ‘x’ was not declared in this scope
   if(x+y==z&&x! =0)
      ^
prog.cpp:49:15: error: expected ‘)’ before ‘!’ token
   if(x+y==z&&x! =0)
               ^
prog.cpp:61:15: error: expected ‘)’ before ‘!’ token
      if(ans[i]! =0) {c=j;break;}
               ^
prog.cpp:2:12: error: expected ‘,’ or ‘;’ before ‘long’
 #define ll long long
            ^
prog.cpp:137:11: note: in expansion of macro ‘ll’
           ll x=b[0][i];
           ^~
prog.cpp:140:6: error: ‘x’ was not declared in this scope
   if(x+y==z&&x! =0)
      ^
prog.cpp:140:15: error: expected ‘)’ before ‘!’ token
   if(x+y==z&&x! =0)
               ^
prog.cpp:152:15: error: expected ‘)’ before ‘!’ token
      if(ans[i]! =0) {c=j;break;}
               ^
stdout
Standard output is empty