fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MaxR=300;
  4. const int MaxN=300;
  5. int H, W, N, h, w;
  6. int num[300][300];
  7. int cnt[301]={};
  8. int cpy[301];
  9.  
  10. int main(){
  11. cin>>H>>W>>N>>h>>w;
  12. for(int r=0; r<H; r+=1)
  13. for(int c=0; c<W; c+=1)
  14. cin>>num[r][c];
  15.  
  16. int all=0;
  17. for(int r=0; r<H; r+=1)
  18. for(int c=0; c<W; c+=1){
  19. all+= cnt[ num[r][c] ]==0;
  20. cnt[ num[r][c] ]+=1;
  21. }
  22.  
  23. for(int k=0; k<=H-h; k+=1){//row
  24. // 資料複製
  25. int nowN=all;
  26. for(int n=1; n<=N; n+=1)//column
  27. cpy[n]=cnt[n];
  28.  
  29. for(int r=0; r<h; r+=1)//column
  30. for(int c=0; c<w; c+=1){
  31. cpy[ num[r+k][c] ]-=1;
  32. nowN-=cpy[ num[r+k][c] ]==0;
  33. }
  34. cout<<nowN<<" ";
  35. for(int l=0; l<W-w; l+=1){//column
  36. // 新增 column[l]
  37. for(int r=0; r<h; r+=1){
  38. nowN+= cpy[ num[r+k][l] ]==0;
  39. cpy[ num[r+k][l] ]+=1;
  40. }
  41. // 遮住 column[l+w]
  42. for(int r=0; r<h; r+=1){
  43. cpy[ num[r+k][l+w] ]-=1;
  44. nowN-= cpy[ num[r+k][l+w] ]==0;
  45. }
  46. cout<<nowN<<" ";
  47. }
  48. cout<<"\n";
  49. }
  50. }
Success #stdin #stdout 0.01s 5280KB
stdin
3 4 5 2 2
2 2 1 1
3 2 5 3
3 4 4 3
stdout
4 4 3 
5 3 4