QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#669607#8236. Snake Movefrankly6#Compile Error//C++171.9kb2024-10-23 19:09:472024-10-23 19:09:48

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 19:09:48]
  • 评测
  • [2024-10-23 19:09:47]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<map>
#include<queue>
#define int unsigned long long
using namespace std;
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
const int MX=3030;
const int NX=100010;
const int inf=0x3fffffff;

int N, M, K;
int mp[MX][MX];
ull ans[MX][MX];
bool vis[MX][MX];
int dx[5]={0,1,0,-1,0};
int dy[5]={0,0,1,0,-1};
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
queue<PII> q;
void bfs()
{
    while(!q.empty())
    {
        auto [x,y]=q.front(); q.pop();
        for(int i=1;i<=4;i++)
        {
            int nx=x+dx[i], ny=y+dy[i];
            if(mp[nx][ny]==-1) continue;
            if(nx<=0||nx>N||ny<=0||ny>M) continue;
            int upd=max(ans[x][y]+1,(mp[nx][ny]!=0)*(K-mp[nx][ny]+1));
            if(ans[nx][ny]<=upd) continue;
            ans[nx][ny]=upd;
            q.push({nx,ny});
        }
    }
}
signed main()
{
    // freopen("testdata.in","r",stdin);
    N=read(); M=read(); K=read();
    for(int i=1;i<=K;i++)
    {
        int x=read(), y=read();
        mp[x][y]=i;
        if(i==1)
        {
            q.push({x,y});
            vis[x][y]=1;
        }
    }
    for(int i=1;i<=N;i++)
    {
        string s; cin >> s; s=" "+s;
        for(int j=1;j<=M;j++)
        {
            if(s[j]=='#') mp[i][j]=-1;
            if(!vis[i][j]) ans[i][j]=inf;
        }
    }
    bfs();    
    ull sum=0;
    for(int i=1;i<=N;i++)
    {
        // cout << "i=" << i << '\n';
        for(int j=1;j<=M;j++)
        {
            // cout << ans[i][j] << " ";
            if(ans[i][j]!=inf) sum+=ans[i][j]*ans[i][j];
        }
        // cout << '\n';
    }
    cout << sum << '\n';
    return (0-0);
}

詳細信息

answer.code:19:18: error: narrowing conversion of ‘-1’ from ‘int’ to ‘long long unsigned int’ [-Wnarrowing]
   19 | int dx[5]={0,1,0,-1,0};
      |                  ^~
answer.code:20:20: error: narrowing conversion of ‘-1’ from ‘int’ to ‘long long unsigned int’ [-Wnarrowing]
   20 | int dy[5]={0,0,1,0,-1};
      |                    ^~