fork download
  1. #include <bits/stdc++.h>
  2. #define x1 fjsdifj1
  3. #define y1 adjasodjao
  4. #define x2 fjsdifj
  5. #define y2 adjasodja
  6. using namespace std;
  7. int a[2005], b[2005], c[2005][2005], n,m,s;
  8. const int INF = 1e9;
  9. int dt(int x1, int y1, int x2, int y2){
  10. cout<<c[x2][y2]<< " "<<c[x1-1][y2]<<" "<<c[x2][y1-1]<<" "<<c[x1-1][y1-1];
  11. return c[x2][y2]-c[x1-1][y2]-c[x2][y1-1]+c[x1-1][y1-1];
  12. }
  13. int check(int x1, int y1, int x2, int y2){
  14. if (c[x2][y2]-c[x1-1][y2]-c[x2][y1-1]+c[x1-1][y1-1]>s) return 0; else return 1;
  15. }
  16. int isOk(int d, int r){
  17. for (int i=1;i<=n-r+1;i++){
  18. for (int j=1;j<=m-d+1;j++) if (check(i,j,i+r-1,j+d-1)==1) return 1;
  19. }
  20. return 0;
  21. }
  22. int kiemtra(int area){
  23. for (int i=1;i<=sqrt(area);i++){
  24. if (isOk((int)area/i,i)==1) return 1;
  25. }
  26. for (int i=1;i<=sqrt(area);i++){
  27. if (isOk(i,(int)area/i)==1) return 1;
  28. }
  29. return 0;
  30. }
  31. int main(){
  32. cin>>n>>m;
  33. for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) c[i][j]=0;
  34. for (int i=1;i<=n;i++) cin>>a[i];
  35. for (int i=1;i<=m;i++) cin>>b[i];
  36. for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) c[i][j]=a[i]*b[j];
  37. for (int i=1;i<=n;i++){
  38. for (int j=1;j<=m;j++) c[i][j]=c[i][j-1]+c[i-1][j]-c[i-1][j-1]+c[i][j];
  39. }
  40. cin>>s;
  41. int l=0, r=INF, mid, res;
  42. while (l<=r){
  43. mid = (l+r)>>1;
  44. if (kiemtra(mid)==1){
  45. res=mid;
  46. l=mid+1;
  47. } else r=mid-1;
  48. }
  49. for (int i=1;i<=n;i++){
  50. for (int j=1;j<=m;j++) cout<<c[i][j]<<" ";
  51. cout<<endl;
  52. }
  53. //cout<<res;
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 30952KB
stdin
Standard input is empty
stdout
Standard output is empty