QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132678#6739. Teleportde_sousa#WA 33ms31980kbC++173.4kb2023-07-31 02:02:082023-07-31 02:02:09

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 02:02:09]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:31980kb
  • [2023-07-31 02:02:08]
  • 提交

answer

#pragma GCC optimize("-O3","unroll-loops")

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

#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));
    vector<vector<int>> visited(n,vector<int>(m,0));
    
    distance[0][0]=0;
    visited[0][0]=1;
    vector<int> rep(n+m);
    vector<vector<int>> next(n+m,vector<int>(n,-1));
    vector<vector<int>> prev(n+m,vector<int>(n,-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++){
	rep[id(i,0)]=i;
    }
    for(int j=0;j<m;j++){
	rep[id(0,j)]=j;
    }

    for(int i=0;i<n;i++){
	int tmp=-1;
	for(int j=0;true;j++){
	    if(i+j>=n)break;
	    if(a[i+j][j]=='*'){
		visited[i+j][j]=true;
		continue;
	    }
	    if(tmp!=-1)next[id(i,0)][tmp]=j;
	    prev[id(i,0)][j]=tmp;
	    tmp=j;
	}
    }
    for(int i=1;i<m;i++){
	int tmp=-1;
	for(int j=0;true;j++){
	    if(i+j>=n)break;
	    if(a[j][i+j]=='*'){
		visited[j][i+j]=true;
		continue;
	    }
	    if(tmp!=-1)next[id(0,i)][tmp]=j;
	    prev[id(0,i)][j]=tmp;
	    tmp=j;
	}
    }


    auto remove=[&](int x,int y)
    {	
	int tmpid=id(x,y);
	int tmp=(x+y-rep[tmpid])/2;
	if(prev[tmpid][tmp]!=-1)
	    next[tmpid][prev[tmpid][tmp]]=next[tmpid][tmp];
	if(next[tmpid][tmp]!=-1)
	    prev[tmpid][next[tmpid][tmp]]=prev[tmpid][tmp];
	visited[x][y]=1;
    };

    int Qi=0;
    while(Qi<Q.size()){
	auto[i,j]=Q[Qi];
	// cout<<i<<' '<<j<<' '<<distance[i][j]<<'\n';
	if(i==n-1&&j==m-1){
	    cout<<distance[i][j]<<'\n';
	    return;
	}
	
	if(i>0&&!visited[i-1][j]){
	    distance[i-1][j]=1+distance[i][j];
	    Q.push_back({i-1,j});
	    remove(i-1,j);
	}
	if(i<n-1&&!visited[i+1][j]){
	    distance[i+1][j]=1+distance[i][j];
	    Q.push_back({i+1,j});
	    remove(i+1,j);
	}
	if(j>0&&!visited[i][j-1]){
	    distance[i][j-1]=1+distance[i][j];
	    Q.push_back({i,j-1});
	    remove(i,j-1);
	}
	if(j<m-1&&!visited[i][j+1]){
	    distance[i][j+1]=1+distance[i][j];
	    Q.push_back({i,j+1});
	    remove(i,j+1);
	}

	{
	    int tmpid=id(i,j);
	    int iter=(i+j-rep[tmpid])/2;
	    int saveval=(i+j-rep[tmpid])/2;
	    iter=next[tmpid][iter];
	    while(iter!=-1&&iter-saveval<=k/2){
		if(visited[i+iter-saveval][j+iter-saveval]){
		    iter=next[tmpid][iter];
		    continue;
		}
		distance[i+iter-saveval][j+iter-saveval]=1+distance[i][j];
		Q.push_back({i+iter-saveval,j+iter-saveval});
		remove(i+iter-saveval,j+iter-saveval);
		iter=next[tmpid][iter];
	    }
	}
	if(j<m-1){
	    int tmpid=id(j+1,i);
	    int iter=(j+1+i-rep[tmpid])/2;
	    int saveval=(j+1+i-rep[tmpid])/2;
	    while(iter!=-1&&iter-saveval<=(k-1)/2){
		if(visited[j+1+iter-saveval][i+iter-saveval]){
		    iter=next[tmpid][iter];
		    continue;
		}
		distance[j+1+iter-saveval][i+iter-saveval]=1+distance[i][j];
		Q.push_back({j+1+iter-saveval,i+iter-saveval});
		remove(j+1+iter-saveval,i+iter-saveval);
		iter=next[tmpid][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: 3456kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 33ms
memory: 31980kb

input:

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

output:

547

result:

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