# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587487 | NekoRolly | I want to be the very best too! (NOI17_pokemonmaster) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e4+4;
int n,m,q;
vector<vector<int>> level,poke,vis;
bool use[N];
bool valid(int a,int b,int x){
return 0 < a && a <= n && 0 < b && b <= m && !vis[a][b] && level[a][b] <= x;
}
void dfs(int a,int b,int x){ use[poke[a][b]] = vis[a][b] = 1;
if (valid(a-1, b)) dfs(a-1, b, x);
if (valid(a+1, b)) dfs(a+1, b, x);
if (valid(a, b-1)) dfs(a, b-1, x);
if (valid(a, b+1)) dfs(a, b+1, x);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
level.resize(n+1, vector<int> (m+1));
poke.resize(n+1, vector<int> (m+1));
vis.resize(n+1, vector<int> (m+1));
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin >> level[i][j];
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin >> poke[i][j];
if (q <= 10){
for (int t,a,b,x,ans; q; q--){ cin >> t >> b >> a >> x;
if (t == 1) poke[a][b] = x;
if (t == 2){ ans = 0;
for (int i=1; i<N; i++) use[i] = 0;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) vis[i][j] = 0;
if (level[a][b] <= x) dfs(a, b, x);
for (int i=1; i<N; i++) ans += use[i], use[i] = 0;
cout << ans << "\n";
}
}
}
else if (n == 1){
}
return 0;
}