QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132664#6739. Teleportde_sousa#WA 264ms44392kbC++172.4kb2023-07-31 00:35:082023-07-31 00:35:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-31 00:35:11]
  • 评测
  • 测评结果:WA
  • 用时:264ms
  • 内存:44392kb
  • [2023-07-31 00:35:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) begin(x),end(x)
#define trav(a, b) for (auto a : b)
#define lld long long

using i64 = long long; 

void solve() {
    int n,m,k;
    cin>>n>>k;
    m=n;
    vector<string> a(n);
    for(auto&i:a){
	cin>>i;
    }

    vector<array<int,2>> Q;
    Q.push_back({0,0});
    vector<vector<int>> distance(n,vector<int>(m,-1));
    distance[0][0]=0;
    vector<set<array<int,2>>> sets(n+m); // id of (i,j) is i-j+m-1

    auto id=[&](int x,int y)
    {
	int val=x-y+m-1;
	assert(val>=0);
	return val;
    };
    
    for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
	    if(a[i][j]!='*'){
		sets[id(i,j)].insert({i,j});
	    }
	}
    }

    int Qi=0;
    while(Qi<Q.size()){
	auto[i,j]=Q[Qi];
	
	if(i>0&&sets[id(i-1,j)].find({i-1,j})!=sets[id(i-1,j)].end()){
	    distance[i-1][j]=1+distance[i][j];
	    Q.push_back({i-1,j});
	    sets[id(i-1,j)].erase({i-1,j});
	}
	if(i<n-1&&sets[id(i+1,j)].find({i+1,j})!=sets[id(i+1,j)].end()){
	    distance[i+1][j]=1+distance[i][j];
	    Q.push_back({i+1,j});
	    sets[id(i+1,j)].erase({i+1,j});
	}
	if(j>0&&sets[id(i,j-1)].find({i,j-1})!=sets[id(i,j-1)].end()){
	    distance[i][j-1]=1+distance[i][j];
	    Q.push_back({i,j-1});
	    sets[id(i,j-1)].erase({i,j-1});
	}
	if(j<m-1&&sets[id(i,j+1)].find({i,j+1})!=sets[id(i,j+1)].end()){
	    distance[i][j+1]=1+distance[i][j];
	    Q.push_back({i,j+1});
	    sets[id(i,j+1)].erase({i,j+1});
	}

	{
	    vector<array<int,2>> toErase;
	    for(auto iter=sets[id(i,j)].lower_bound({i,j});iter!=sets[id(i,j)].upper_bound({i+k/2,j+k/2});iter++){
		toErase.push_back(*iter);
		auto[xi,yi]=*iter;
		distance[xi][yi]=1+distance[i][j];
		Q.push_back({xi,yi});
	    }
	    for(auto iter:toErase){
		sets[id(i,j)].erase(iter);
	    }
	}
	{
	    vector<array<int,2>> toErase;
	    for(auto iter=sets[id(j+1,i)].lower_bound({j+1,i});iter!=sets[id(j+1,i)].upper_bound({j+1+(k-1)/2,i+(k-1)/2});iter++){
		toErase.push_back(*iter);
		auto[xi,yi]=*iter;
		distance[xi][yi]=1+distance[i][j];
		Q.push_back({xi,yi});
	    }
	    for(auto iter:toErase){
		sets[id(j+1,i)].erase(iter);
	    }
	}
	Qi++;
    }

    cout<<distance[n-1][m-1]<<'\n';
    
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    while (tt--) solve();
    return 0;
}

详细

Test #1:

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

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3588kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 253ms
memory: 44392kb

input:

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

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: -100
Wrong Answer
time: 264ms
memory: 39840kb

input:

975 434
.*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...

output:

6

result:

wrong answer 1st numbers differ - expected: '5', found: '6'