比赛 2026郑轻校赛 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 覆盖面积 最终得分 100
用户昵称 梦那边的美好ME 运行时间 5.215 s
代码语言 C++ 内存使用 3.73 MiB
提交时间 2026-04-07 19:56:40
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll n,m;
ll Q;
ll a[55][55];
ll ans[55][55];
ll dx[]={0,0,1,-1},dy[]={1,-1,0,0};

ll solve(ll xx,ll yy){
    vector <vector <bool> > vis(n+1,vector <bool>(m+1,0));
    queue <pair <ll,ll> > q;
    q.push({xx,yy});
    vis[xx][yy]=1;
    ll cnt=0;
    while (!q.empty()){
        pair <ll,ll> o=q.front();
        q.pop();
        cnt++;
        for (int i=0;i<4;++i){
            ll nx=o.first+dx[i];
            ll ny=o.second+dy[i];
            if (nx>=1&&nx<=n&&ny>=1&&ny<=m&&!vis[nx][ny]){
                if (a[nx][ny]<=a[o.first][o.second]){
                    vis[nx][ny]=1;
                    q.push({nx,ny});
                }
            }
        }
    }
    return cnt;
}

int main(){
    freopen("area.in","r",stdin);
    freopen("area.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            cin>>a[i][j];
        }
    }
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            ans[i][j]=solve(i,j);
        }
    }
    cin>>Q;
    while (Q--){
        ll x,y;
        cin>>x>>y;
        cout<<ans[x][y]<<"\n";
    }
    return 0;
}