QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412227#3166. Hopscotchlittlecat#WA 2ms7712kbC++14956b2024-05-16 10:45:532024-05-16 10:45:54

Judging History

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

  • [2024-05-16 10:45:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7712kb
  • [2024-05-16 10:45:53]
  • 提交

answer

#include <iostream>
#include <queue>
using namespace std;
const int mx=50; typedef pair<int,int> pi; typedef pair<pi,int> ppi;
int n, a[mx][mx], dp[mx][mx][mx*mx+1];
queue<ppi> q;
void set(int i, int j, int k, int x)
{
    if(i<0||i>=n||j<0||j>=n||dp[i][j][k]!=-1) return;
    if(a[i][j]==k+1) k++; dp[i][j][k]=x, q.push(ppi(pi(i,j),k));
}
int main()
{
    int K; cin>>n>>K;
    for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin>>a[i][j];
    for(int i=0; i<n; i++) for(int j=0; j<n; j++)
        for(int k=1; k<=K; k++) dp[i][j][k]=-1;
    for(int i=0; i<n; i++) for(int j=0; j<n; j++) if(a[i][j]==1)
        dp[i][j][1]=0, q.push(ppi(pi(i,j),1));
    while(!q.empty())
    {
        ppi p=q.front(); q.pop();
        int i=p.first.first, j=p.first.second, k=p.second;
        if(k==K) cout<<dp[i][j][k]<<'\n', exit(0);
        int x=dp[i][j][k]+1;
        set(i-1,j,k,x), set(i+1,j,k,x), set(i,j-1,k,x), set(i,j+1,k,x);
    }
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7712kb

input:

10 5
5 1 3 4 2 4 2 1 2 1
4 5 3 4 1 5 3 1 1 4
4 2 4 1 5 4 5 2 4 1
5 2 1 5 5 3 5 2 3 2
5 5 2 3 2 3 1 5 5 5
3 4 2 4 2 2 4 4 2 3
1 5 1 1 2 5 4 1 5 3
2 2 4 1 2 5 1 4 3 5
5 3 2 1 4 3 5 2 3 1
3 4 2 5 2 5 3 4 4 2

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7660kb

input:

10 5
5 1 5 4 1 2 2 4 5 2
4 2 1 4 1 1 1 5 2 5
2 2 4 4 4 2 4 5 5 4
2 4 4 5 5 5 2 5 5 2
2 2 4 4 4 5 4 2 4 4
5 2 5 5 4 1 2 4 4 4
4 2 1 2 4 4 1 2 4 5
1 2 1 1 2 4 4 1 4 5
2 1 2 5 5 4 5 2 1 1
1 1 2 4 5 5 5 5 5 5

output:


result:

wrong answer 1st lines differ - expected: '-1', found: ''