QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140981#6739. TeleportUFRJ#WA 50ms7776kbC++201.5kb2023-08-17 03:08:292023-08-17 03:08:32

Judging History

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

  • [2023-08-17 03:08:32]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:7776kb
  • [2023-08-17 03:08:29]
  • 提交

answer

#include<bits/stdc++.h>

using lint = int64_t;
using namespace std;

int main(void) {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, k;
  cin>>n>>k;
  vector<string>s(n);
  for(int i=0;i<n;i++) cin>>s[i];
  vector<pair<int, int>>cur;
  vector<vector<int>>dist(n, vector<int>(n, -1));
  dist[0][0] = 0;
  cur.push_back({0, 0});
  vector<int>dx = {0, 1, 0, -1};
  vector<int>dy = {1, 0, -1, 0};
  
  while(!cur.empty()){
    vector<pair<int, int>>nxt;
    sort(cur.begin(), cur.end(), [&](pair<int, int>a, pair<int, int>b){
      return a.first + a.second < b.first + b.second;
    });
    for(auto [a, b] : cur){
      for(int i=2;i<=k;i+=2){
        int na = a + i/2, nb = b + i/2;
        if(na < 0 || na >= n || nb < 0 || nb >= n || s[na][nb] == '*') continue;
        if(dist[na][nb] != -1) break;
        dist[na][nb] = dist[a][b] + 1;
        nxt.push_back({na, nb});
      }
      for(int i=1;i<=k;i+=2){
        int na = b + 1 + i/2, nb = a + i / 2;
        if(na < 0 || na >= n || nb < 0 || nb >= n || s[na][nb] == '*') continue;
        if(dist[na][nb] != -1) break;
        dist[na][nb] = dist[a][b] + 1;
        nxt.push_back({na, nb});
      }
    }
    for(auto [a, b] : cur){
      for(int k=0;k<4;k++){
        int na = a + dx[k], nb = b + dy[k];
        if(na < 0 || na >= n || nb < 0 || nb >= n || s[na][nb] == '*' || dist[na][nb] != -1) continue;
        dist[na][nb] = dist[a][b] + 1;
        nxt.push_back({na, nb});
      }
    }
    swap(nxt, cur);
  }
  cout<<dist[n-1][n-1]<<"\n";

  return 0;
}

詳細信息

Test #1:

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

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 50ms
memory: 7776kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

545

result:

wrong answer 1st numbers differ - expected: '540', found: '545'