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. int main() {
  14. fastIO();
  15. ll n,m; cin>>n>>m;
  16. ll rectangle[n+1][m+1]={(0,0)};
  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. ll PowerRect[11][n+1][m+1]={(0,0,0)};
  23. for (ll p = 1; p<=10; p++) {
  24. for (ll i = 1; i<n+1; i++) {
  25. for (ll j = 1; j<m+1; j++) {
  26. PowerRect[p][i][j]=(p>rectangle[i][j]);
  27. }
  28. }
  29. }
  30. for (ll p = 1; p<=10; p++) {
  31. for (ll i = 1; i<n+1; i++) {
  32. for (ll j = 1; j<m+1; j++) {
  33. PowerRect[p][i][j]+=PowerRect[p][i-1][j];
  34. }
  35. }
  36. for (ll i = 1; i<n+1; i++) {
  37. for (ll j = 1; j<m+1; j++) {
  38. PowerRect[p][i][j]+=PowerRect[p][i][j-1];
  39. }
  40. }
  41. }
  42. ll q; cin>>q;
  43. while (q--) {
  44. ll L1,U1,R1,D1,P1; cin>>L1>>U1>>R1>>D1>>P1;
  45. ll L2,U2,R2,D2,P2; cin>>L2>>U2>>R2>>D2>>P2;
  46. ll Mo7a = PowerRect[P1][D1][R1]-PowerRect[P1][D1][L1-1]-PowerRect[P1][U1-1][R1]+PowerRect[P1][U1-1][L1-1];
  47. ll Samo7a = PowerRect[P2][D2][R2]-PowerRect[P2][D2][L2-1]-PowerRect[P2][U2-1][R2]+PowerRect[P2][U2-1][L2-1];
  48. if (Mo7a == 0 && Samo7a == 0) {
  49. cout<<"Sameh"<<'\n';
  50. }
  51. else if (Mo7a>Samo7a) {
  52. cout<<"Mo7a"<<' '<<Mo7a<<'\n';
  53. }
  54. else if (Mo7a<Samo7a) {
  55. cout<<"Samo7a"<<' '<<Samo7a<<'\n';
  56. }
  57. else if (Mo7a==Samo7a) {
  58. cout<<"Draw"<<' '<<Samo7a<<'\n';
  59. }
  60.  
  61. }
  62. }
  63.  
Success #stdin #stdout 0s 5320KB
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 4294967299