QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#669421 | #8236. Snake Move | frankly6# | WA | 1ms | 5968kb | C++17 | 3.1kb | 2024-10-23 18:34:12 | 2024-10-23 18:34:17 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
#include<bitset>
using namespace std;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const int MX=3030;
const int NX=100010;
const int inf=0x3fffffff;
int N, M, K;
int opx[NX], opy[NX];
int mp[MX][MX];
int ans[MX][MX], len[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;
}
struct node
{
int now;
deque<PII> l;
map<PII,bool> mp;
// bool ix[NX], iy[NX];
}beg, one;
deque<node> q;
void bfs()
{
while(!q.empty())
{
node p=q.front(); q.pop_front();
auto [x,y]=p.l.front();
auto [ex,ey]=p.l.back();
// cout << "ans=" << ans[x][y] << '\n';
ans[x][y]=min(ans[x][y],p.now);
// if(1) cout << "p: x=" << x << ", y=" << y << ", ans=" << ans[x][y] << '\n';
// if(1) {for(auto [ppx,ppy]:p.l) cout << ppx << "&" << ppy << " "; cout << '\n';}
for(int i=1;i<=4;i++)
{
int nx=x+dx[i], ny=y+dy[i];
// cout << "1/x=" << x << ", y=" << y << ", nx=" << nx << ", ny=" << ny << '\n';
if(ans[nx][ny]<p.now+1||mp[nx][ny]==1) continue;
// cout << "2/x=" << x << ", y=" << y << ", nx=" << nx << ", ny=" << ny << '\n';
if(nx<=0||nx>N||ny<=0||ny>M) continue;
// cout << "3/x=" << x << ", y=" << y << ", nx=" << nx << ", ny=" << ny << '\n';
if(p.mp[{nx,ny}]==1&&(nx!=ex||ny!=ey)) continue;
// cout << "4/x=" << x << ", y=" << y << ", nx=" << nx << ", ny=" << ny << '\n';
// if(x==4&&y==3&&p.l.size()==5) cout << x << "&" << y << " " << nx << "&" << ny << ", len=" << p.l.size() << ", ans=" << p.now << '\n';
node np=p;
np.now=p.now+1;
// cout << "ex=" << ex << ", ey=" << ey << '\n';
np.mp[{ex,ey}]=0;
// cout << "nx=" << nx << ", ny=" << ny << '\n';
np.mp[{nx,ny}]=1;
np.l.pop_back(); np.l.push_front({nx,ny});
q.push_back(np);
}
}
}
int main()
{
// freopen("testdata.in","r",stdin);
N=read(); M=read(); K=read();
for(int i=1;i<=K;i++)
{
int x=read(), y=read();
opx[i]=x, opy[i]=y;
beg.now=K-i;
beg.l.push_back({x,y});
beg.mp[{x,y}]=1;
if(abs(x-opx[1])+abs(y-opy[1]<=1)) q.push_front(beg);
}
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;
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);
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5968kb
input:
4 5 5 3 5 3 4 3 3 3 2 4 2 ..... ..... ..... .....
output:
6 5 4 3 2 5 4 3 2 1 6 5 4 4 0 5 4 3 2 1 293
result:
wrong answer 1st lines differ - expected: '293', found: '6 5 4 3 2 '