fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <bits/stdc++.h>
  6. #define ll long long
  7. using namespace std;
  8. void fastIO(void) {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. cout.tie(NULL);
  12. }
  13. ll rectangle[1000+1][1000+1]={(0,0)};
  14. ll PowerRect[11][1000+1][1000+1]={(0,0,0)};
  15. int main() {
  16. ll n,m; cin>>n>>m;
  17. for (ll i = 1; i<n+1; i++) {
  18. for (ll j = 1; j<m+1; j++) {
  19. cin>>rectangle[i][j];
  20. }
  21. }
  22. for (ll p = 1; p<=10; p++) {
  23. for (ll i = 1; i<n+1; i++) {
  24. for (ll j = 1; j<m+1; j++) {
  25. PowerRect[p][i][j]=p>rectangle[i][j];
  26. }
  27. }
  28. }
  29. for (ll p = 1; p<=10; p++) {
  30. for (ll i = 1; i<n+1; i++) {
  31. for (ll j = 1; j<m+1; j++) {
  32. PowerRect[p][i][j]=p>rectangle[i][j];
  33. }
  34. }
  35. }
  36. for (ll p = 1; p<=10; p++) {
  37. for (ll i = 1; i<n+1; i++) {
  38. for (ll j = 1; j<m+1; j++) {
  39. PowerRect[p][i][j]+=PowerRect[p][i][j-1];
  40. }
  41. }
  42. for (ll i = 1; i<n+1; i++) {
  43. for (ll j = 1; j<m+1; j++) {
  44. PowerRect[p][i][j]+=PowerRect[p][i-1][j];
  45. }
  46. }
  47. }
  48. ll q; cin>>q;
  49. while (q--) {
  50. ll L1,U1,R1,D1,P1; cin>>L1>>U1>>R1>>D1>>P1;
  51. ll L2,U2,R2,D2,P2; cin>>L2>>U2>>R2>>D2>>P2;
  52. ll Mo7a = PowerRect[P1][D1][R1]-PowerRect[P1][D1][L1-1]-PowerRect[P1][U1-1][R1]+PowerRect[P1][U1-1][L1-1];
  53. ll Samo7a = PowerRect[P2][D2][R2]-PowerRect[P2][D2][L2-1]-PowerRect[P2][U2-1][R2]+PowerRect[P2][U2-1][L2-1];
  54. if (Mo7a == 0 && Samo7a == 0) {
  55. cout<<"Sameh"<<'\n';
  56. }
  57. else if (Mo7a>Samo7a) {
  58. cout<<"Mo7a"<<' '<<Mo7a<<'\n';
  59. }
  60. else if (Mo7a<Samo7a) {
  61. cout<<"Samo7a"<<' '<<Samo7a<<'\n';
  62. }
  63. else if (Mo7a==Samo7a) {
  64. cout<<"Draw"<<' '<<Samo7a<<'\n';
  65. }
  66.  
  67. }
  68. }
  69.  
Success #stdin #stdout 0.01s 26204KB
stdin
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3
1 1 2 2 8
1 1 3 3 8
1 2 3 4 5
2 3 4 4 1
1 4 2 4 8
3 1 4 4 10
stdout
Samo7a 6
Sameh
Samo7a 4