QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#552336#9224. Express EvictionwyxqwqWA 1ms6820kbC++142.6kb2024-09-07 22:07:242024-09-07 22:07:25

Judging History

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

  • [2024-09-07 22:07:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6820kb
  • [2024-09-07 22:07:24]
  • 提交

answer

#include<bits/stdc++.h>
#define vectorwyx maze
namespace vectorwyx{
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define sml(x,y) (x=min(x,y))
#define big(x,y) (x=max(x,y))
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define umap unordered_map
#define db double
#define fo(i,x,y) for(int i=(x);i<=(y);++i)
#define go(i,x,y) for(int i=(x);i>=(y);--i)
#define ptc putchar
#define gtc getchar
#define emp emplace
#define re return
#define co continue
#define brk break
#define HH (ptc('\n'))
#define bctz __builtin_ctz
#define bclz __builtin_clz
#define bppc __builtin_popcount
using namespace std;
ll seed=chrono::system_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
inline int rm(int x,int y){return (int)(rnd()%(y-x+1ll)+x);}
inline int read(){signed ch=getchar();int x=0,f=1;while(!isdigit(ch)){if(ch==(int)('-'))f=-1;ch=getchar();}while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
template<typename T> void out(T *a,int l,int r){fo(i,l,r) cout<<*(a+i)<<' ';puts("");}

const int N=1e5+5,inf=1e9;
char a[100][100];
int n,m,val[N],dis[N],A,dlt[N],ans=inf;
vector<int> e[N];
#define F(i,x,y) ((i)*(n+1)*(m+1)+((x)-1)*(m+1)+(y))
void add(int x,int y){e[x].pb(y);}

void dij(int s){
    fo(i,1,A) dis[i]=inf,dlt[i]=0;
    dis[s]=val[s];
    priority_queue<pii> q;q.emp(-dis[s],s);
    while(1){
        while(!q.empty()&&dlt[q.top().se]) q.pop();
        if(q.empty()) break;
        int x=q.top().se;q.pop();dlt[x]=1;
        for(int i:e[x]) if(dis[i]>dis[x]+val[i]){
            dis[i]=dis[x]+val[i];
            q.emp(-dis[i],i);
        }
    }
    fo(i,0,3) sml(ans,dis[F(i,n+1,m+1)]);
}

signed main(){
    cin>>n>>m;
    fo(i,1,n) scanf("%s",a[i]+1);
    A=F(3,n+1,m+1);
    fo(i,1,n+1) fo(j,1,m+1){
        val[F(0,i,j)]=(a[i-1][j-1]=='#')+(a[i-1][j]=='#');
        val[F(1,i,j)]=(a[i-1][j]=='#')+(a[i][j]=='#');
        val[F(2,i,j)]=(a[i][j-1]=='#')+(a[i][j]=='#');
        val[F(3,i,j)]=(a[i-1][j-1]=='#')+(a[i][j-1]=='#');
    }
    fo(i,1,n+1) fo(j,1,m+1){
        fo(k,0,3){
            int x=F(k,i,j);
            if(i>1) add(x,F(0,i-1,j));
            if(j<=m) add(x,F(1,i,j+1));
            if(i<=n) add(x,F(2,i+1,j));
            if(j>1) add(x,F(3,i,j-1));
        }
    }
    dij(F(1,1,1));
    dij(F(2,1,1));
    cout<<ans;
    return 0;
}
}
/*
4 6
.##...
.#....
##....
....#.
-------------------------------------------------
*/










signed main(){re vectorwyx::main();}

详细

Test #1:

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

input:

4 6
.##...
.#....
##....
....#.

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 6820kb

input:

20 30
...###########################
#..###########################
...###########################
...###########################
.#############################
...###########################
...###########################
#..###########################
...###########################
..#...............

output:

12

result:

wrong answer 1st numbers differ - expected: '11', found: '12'