QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545344#9224. Express EvictionXY_ElevenWA 5ms6796kbC++236.2kb2024-09-03 10:20:532024-09-03 10:20:53

Judging History

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

  • [2024-09-03 10:20:53]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:6796kb
  • [2024-09-03 10:20:53]
  • 提交

answer

#include <bits/stdc++.h>
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<LL,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1888686661ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{

}
cint D=88,N=28888,M=88888;
int n,m;
int d1,d2;
int id[2][D][D],id2[2][D][D],id3[2][D][D];
char str[D];
cLL inf=1e9,INF=1e18;
LL w[M<<1];
vct <pii> v[N];
void bld(int x,int y,LL lw)
{
    // printf("%d %d ",x,y);
    // if(lw==INF) printf("INF\n");
    // else if(lw==inf) printf("inf\n");
    // else outll(lw);
    w[(++m)<<1]=lw;
    v[x].pb({y,m<<1});
    v[y].pb({x,m<<1|1});
}
void bld2(int x,int y,LL lw)
{
    // printf("%d %d ",x,y);
    // if(lw==INF) printf("INF\n");
    // else if(lw==inf) printf("inf\n");
    // else outll(lw);
    // printf("%d %d\n",y,x);
    m++;
    w[m<<1]=w[m<<1|1]=lw;
    v[x].pb({y,m<<1});
    v[y].pb({x,m<<1|1});
}
int now[N],dis[N];
queue <int> q;
bool bfs()
{
    memset(now,0,(n+1)<<2);
    memset(dis,0xff,(n+1)<<2);
    clean(q); q.push(0),dis[0]=0;
    while(!q.empty())
    {
        int p=frt(q);
        // printf("p=%d\n",p);
        for(auto [i,id]:v[p])
        {
            exc((~dis[i])||(!w[id]));
            dis[i]=dis[p]+1;
            q.push(i);
        }
    }
    return (~dis[n]);
}
LL dfs(int p,LL f)
{
    if(p==n) return f;
    // printf("%d,%lld\n",p,f);
    int len=sz(v[p]);
    LL s=0ll;
    for(int i_=now[p];i_<len&&f;i_++)
    {
        auto [i,id]=v[p][i_];
        now[p]=i_;
        exc(!w[id]||dis[i]!=dis[p]+1);
        LL d=dfs(i,min(f,w[id]));
        s+=d,f-=d,w[id]-=d,w[id^1]+=d;
    }
    return s;
}
LL dinic()
{
    LL ans=0ll;
    while(bfs())
    {
        LL d=dfs(0,INF);
        stop(!d);
        ans+=d;
    }
    return ans;
}
cint dx[8]={-1,0,1,-1,1,-1,0,-1},dy[8]={-1,-1,-1,0,0,1,1,1};
void main_solve()
{
    inpr(d1,d2);
    n=m=0;
    For(i,0,d1+1) For(j,0,d2+1) For(k,0,1)
        id[k][i][j]=++n,id2[k][i][j]=++n,id3[k][i][j]=++n;
    n++;
    For(i,0,d1+1) For(j,0,d2+1) bld(0,id[0][i][j],inf),bld(id[1][i][j],n,inf),bld(id[0][i][j],id[1][i][j],INF);
    For(j,0,d2+1) bld(0,id[0][0][j],INF),bld(id[1][d1+1][j],n,INF);
    For(i,1,d1) bld(0,id[0][i][d2+1],INF),bld(id[1][i][0],n,INF);
    For(i,0,d1+1) For(j,0,d2+1) bld(id[0][i][j],id3[0][i][j],INF),bld(id3[1][i][j],id[1][i][j],INF);
    For(i,0,d1+1) For(j,0,d2+1) For_(k,0,8)
    {
        int i2=i+dx[k],j2=j+dy[k];
        exc(i2<0||j2<0||i2>d1+1||j2>d2+1);
        bld(id2[0][i][j],id3[1][i2][j2],INF);
        bld(id3[0][i][j],id2[1][i2][j2],INF);
    }
    For(i,1,d1)
    {
        scanf("%s",str+1);
        For(j,1,d2)
            if(str[j]=='#')
                bld(id[0][i][j],id2[0][i][j],1ll),bld(id2[1][i][j],id[1][i][j],1ll);
    }
    // return ;
    outll(dinic()-inf*(d1+2)*(d2+2));
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

詳細信息

Test #1:

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

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 6796kb

input:

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

output:

11

result:

ok 1 number(s): "11"

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 5640kb

input:

35 35
....###########...#########........
##..#######################..#####.
....#######################..#####.
...#.....##################..#####.
.##......##################.....##.
.##..##..#############.....#....##.
.....##..#############......##..##.
....#....#############..##..##..##.
####.....

output:

14

result:

wrong answer 1st numbers differ - expected: '16', found: '14'