QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412232#3166. Hopscotchlittlecat#WA 1ms9600kbC++14972b2024-05-16 10:47:502024-05-16 10:47:52

Judging History

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

  • [2024-05-16 10:47:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9600kb
  • [2024-05-16 10:47:50]
  • 提交

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) return;
    if(a[i][j]==k+1) k++; if(dp[i][j][k]!=-1) return;
    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);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9600kb

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: 0ms
memory: 7608kb

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: ''