Submission #48510418
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define eb emplace_back
//#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll MOD=998244353;
// head
const int M=305;
int a[M][M];
int all[M];
int last[M],now[M];
signed main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
int H,W,N,h,w;cin>>H>>W>>N>>h>>w;
for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) {cin>>a[i][j];all[a[i][j]]++;}
for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) now[a[i][j]]++;
for(int i=1;i<=N;i++) last[i]=now[i];
int ans=0,last_ans;
for(int i=1;i<=N;i++) if(now[i]==all[i]) ans++;
last_ans=ans;
for(int i=h;i<=H;i++){
for(int j=w;j<=W;j++){
cout<<N-ans<<" ";
for(int k=i-h+1;k<=i;k++){
if(now[a[k][j-w+1]]==all[a[k][j-w+1]]) ans--;
now[a[k][j-w+1]]--;
}
for(int k=i-h+1;k<=i;k++){
if(now[a[k][j+1]]==all[a[k][j+1]]-1) ans++;
now[a[k][j+1]]++;
}
}
ans=last_ans;
for(int j=1;j<=N;j++) now[j]=last[j];
for(int j=1;j<=w;j++){
if(now[a[i-h+1][j]]==all[a[i-h+1][j]]) ans--;
now[a[i-h+1][j]]--;
}
for(int j=1;j<=w;j++){
if(now[a[i+1][j]]==all[a[i+1][j]]-1) ans++;
now[a[i+1][j]]++;
}
for(int j=1;j<=N;j++) last[j]=now[j];
last_ans=ans;
cout<<endl;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Grid Filling |
| User | gangbengr |
| Language | C++ 20 (gcc 12.2) |
| Score | 500 |
| Code Size | 1435 Byte |
| Status | AC |
| Exec Time | 25 ms |
| Memory | 4344 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 03_max_12.txt, 03_max_13.txt, 03_max_14.txt, 03_max_15.txt, 04_edge_16.txt, 04_edge_17.txt, 04_edge_18.txt, 04_edge_19.txt, 04_edge_20.txt, 04_edge_21.txt, 04_edge_22.txt, 04_edge_23.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 4 ms | 3500 KiB |
| 00_sample_01.txt | AC | 1 ms | 3428 KiB |
| 00_sample_02.txt | AC | 1 ms | 3576 KiB |
| 01_small_03.txt | AC | 1 ms | 3496 KiB |
| 01_small_04.txt | AC | 1 ms | 3508 KiB |
| 01_small_05.txt | AC | 1 ms | 3476 KiB |
| 02_random_06.txt | AC | 1 ms | 3780 KiB |
| 02_random_07.txt | AC | 9 ms | 4000 KiB |
| 02_random_08.txt | AC | 1 ms | 3452 KiB |
| 02_random_09.txt | AC | 1 ms | 3596 KiB |
| 02_random_10.txt | AC | 1 ms | 3628 KiB |
| 02_random_11.txt | AC | 1 ms | 4052 KiB |
| 03_max_12.txt | AC | 21 ms | 4096 KiB |
| 03_max_13.txt | AC | 10 ms | 4344 KiB |
| 03_max_14.txt | AC | 25 ms | 4144 KiB |
| 03_max_15.txt | AC | 8 ms | 4328 KiB |
| 04_edge_16.txt | AC | 8 ms | 4124 KiB |
| 04_edge_17.txt | AC | 7 ms | 4140 KiB |
| 04_edge_18.txt | AC | 9 ms | 4224 KiB |
| 04_edge_19.txt | AC | 5 ms | 4092 KiB |
| 04_edge_20.txt | AC | 8 ms | 4092 KiB |
| 04_edge_21.txt | AC | 6 ms | 4152 KiB |
| 04_edge_22.txt | AC | 7 ms | 4280 KiB |
| 04_edge_23.txt | AC | 11 ms | 4228 KiB |