QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132667#6739. Teleportde_sousa#WA 272ms43476kbC++172.4kb2023-07-31 00:38:182023-07-31 00:38:20

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:38:20]
  • 评测
  • 测评结果:WA
  • 用时:272ms
  • 内存:43476kb
  • [2023-07-31 00:38:18]
  • 提交

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);
	    }
	}
	if(j<m-1){
	    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: 3584kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 243ms
memory: 43476kb

input:

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

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: -100
Wrong Answer
time: 272ms
memory: 41472kb

input:

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

output:

6

result:

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