QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#532671#9224. Express Evictionucup-team1231#WA 86ms8312kbC++141.8kb2024-08-25 08:45:192024-08-25 08:45:20

Judging History

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

  • [2024-08-25 08:45:20]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:8312kb
  • [2024-08-25 08:45:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define SZ 200055
int h,w;
typedef pair<int,int> pii;
#define fi first
#define se second
char u[66][66];
void edt(set<pii>&s,pii u,int w) {
    for(int dx=0;dx<=1;++dx)
        for(int dy=0;dy<=1;++dy) {
            pii o(u.fi+dx,u.se+dy);
            if(w) s.insert(o); else s.erase(o);
        }
}
int contb(vector<pii> a) {
    set<pii> g;
    edt(g,a.back(),1);
    for(int i=0;i+1<a.size();++i)
        edt(g,a[i],0);
    int ans=0;
    for(auto t:g)
    //     cout<<t.fi<<","<<t.se<<"JAA\n",
        ans+=u[t.fi][t.se]=='#';
    return ans;
}
void dj(pii t) {
    int ans=2e9;
    map<pii,int> DD;
    map<vector<pii>,int> d;
    priority_queue<pair<int,vector<pii>>> q;
    vector<pii> S{t}; int O=contb(S)+1;
    d[S]=O; q.push({-O,S});
    while(!q.empty()) {
        auto t=q.top(); q.pop(); t.fi*=-1;
        if(d[t.se]!=t.fi) continue;
        const int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
        for(int k=0;k<4;++k) {
            pii tt(t.se.back().fi+dx[k],t.se.back().se+dy[k]);
            if(tt.fi<0||tt.fi>h||tt.se<0||tt.se>w) continue;
            auto TT=t.se; TT.push_back(tt); int EX=contb(TT);
            if(TT.size()==5) TT.erase(TT.begin());
            int&G=d[TT];
            if(G!=0&&G<=t.fi+EX) continue;
            G=t.fi+EX;
            if(!DD.count(tt)||DD[tt]>G) DD[tt]=G;
            if(tt.fi==h&&tt.se==w) ans=min(ans,G);
            q.push({-G,TT});
        }
    }
    // cout<<contb({{2,0}})<<"?\n";
    // cout<<contb({{1,0},{2,0},{3,0}})<<"?\n";
    // cout<<contb({{2,0},{3,0}})<<"?\n";
    cout<<ans-1<<"\n";
    // for(int i=0;i<=h;++i,cout<<"\n")
    //     for(int j=0;j<=w;++j)
    //         cout<<DD[pii(i,j)]-1<<" ";
}
int main() {
    cin>>h>>w;
    for(int i=1;i<=h;++i) cin>>(u[i]+1);
    dj({0,0});
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3764kb

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 86ms
memory: 8312kb

input:

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

output:

12

result:

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