QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#119694#1066. ROBOTSmyee500 ✓308ms83848kbC++113.3kb2023-07-05 15:03:352023-07-05 15:03:37

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-05 15:03:37]
  • Judged
  • Verdict: 500
  • Time: 308ms
  • Memory: 83848kb
  • [2023-07-05 15:03:35]
  • Submitted

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
uint Nxt[1000005],Go[1000005];chr C[505][505];
const uint dx[]={1,0,-1u,0},dy[]={0,1,0,-1u};
std::vector<uint>To[250005];
uint Dist[9][9][250005];
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    uint n,h,w;scanf("%u%u%u",&n,&w,&h);
    for(uint i=0;i<h;i++)scanf("%s",C[i]);
    for(uint i=0;i<h;i++)for(uint j=0;j<w;j++)if(C[i][j]!='x')for(uint op=0,x,y;op<4;op++)
        Nxt[(i*w+j)<<2|op]=(x=i+dx[op])<h&&(y=j+dy[op])<w&&C[x][y]!='x'?(x*w+y)<<2
                                    |(C[x][y]=='A'?(op+1)&3:(C[x][y]=='C'?(op+3)&3:op)):-1u;
    else Nxt[(i*w+j)<<2]=Nxt[(i*w+j)<<2|1]=Nxt[(i*w+j)<<2|2]=Nxt[(i*w+j)<<2|3]=-1;
    for(uint i=0;i<h*w*4;i++)Go[i]=-1;
    for(uint i=0;i<h*w*4;i++)if(~Nxt[i])Go[Nxt[i]]=i;
    for(uint i=0,p;i<h*w*4;i++)if(!~Nxt[i]){p=i;while(~p)To[p>>2].push_back(i>>2),p=Go[p];}
    for(uint i=0;i<n;i++)for(uint j=i;j<n;j++)for(uint k=0;k<h*w;k++)Dist[i][j][k]=2e9;
    for(uint i=0;i<h;i++)for(uint j=0;j<w;j++)if(C[i][j]>='1'&&C[i][j]<='9')Dist[C[i][j]-'1'][C[i][j]-'1'][i*w+j]=0;
    for(uint len=0;len<n;len++)
    {
        if(len)for(uint l=0;l+len<n;l++)for(uint mid=l;mid<l+len;mid++)for(uint k=0;k<h*w;k++)
            _min(Dist[l][l+len][k],Dist[l][mid][k]+Dist[mid+1][l+len][k]);
        for(uint l=0;l+len<n;l++)
        {
            uint*D=Dist[l][l+len];
            static bol G[250005];
            std::vector<uint>V;std::queue<uint>Q;
            for(uint k=0;k<h*w;k++)
            {
                G[k]=false;
                if(D[k]<1e9)V.push_back(k);
            }
            std::sort(V.begin(),V.end(),[&](uint a,uint b){return D[a]>D[b];});
            while(Q.size()||V.size())
            {
                uint p;
                if(Q.size()&&(V.empty()||D[Q.front()]<D[V.back()]))p=Q.front(),Q.pop();else p=V.back(),V.pop_back();
                for(auto s:To[p])if(_min(D[s],D[p]+1))G[s]=true,Q.push(s);
                while(V.size()&&G[V.back()])V.pop_back();
            }
            // for(uint i=0;i<h*w;i++,putchar(" \n"[!(i%w)]))if(D[i]<1e9)printf("%2u",D[i]);else printf("-1");
            // puts("");
        }
    }
    uint ans=2e9;
    for(uint i=0;i<h*w;i++)_min(ans,Dist[0][n-1][i]);
    if(ans<1e9)printf("%u\n",ans);else puts("-1");
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 2ms
memory: 15300kb

input:

2 2 1
12

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 3ms
memory: 17288kb

input:

2 3 1
1x2

output:

-1

result:

ok single line: '-1'

Test #3:

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

input:

2 4 1
.12.

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 3ms
memory: 15308kb

input:

2 10 10
...x...x.2
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
1x...x...x

output:

10

result:

ok single line: '10'

Test #5:

score: 0
Accepted
time: 3ms
memory: 15300kb

input:

2 10 10
..........
.xx..xx...
xx..xx..x.
x..xx..xx.
..xx..xx..
.xx..xx..x
xx..xx..xx
x..xx..xx2
..xx..xx..
1xx......x

output:

29

result:

ok single line: '29'

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 20
Accepted
time: 2ms
memory: 15304kb

input:

2 2 2
1C
.2

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 3ms
memory: 15476kb

input:

2 3 1
1A2

output:

2

result:

ok single line: '2'

Test #8:

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

input:

2 3 3
.x.
1CA
.x2

output:

2

result:

ok single line: '2'

Test #9:

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

input:

2 6 2
C1CA2A
CCCAAA

output:

6

result:

ok single line: '6'

Test #10:

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

input:

2 10 10
C.CxC.CxC2
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
.x.x.x.x.x
1xA.AxA.Ax

output:

1

result:

ok single line: '1'

Subtask #3:

score: 30
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 30
Accepted
time: 33ms
memory: 73788kb

input:

9 296 298
2..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....

output:

47593

result:

ok single line: '47593'

Test #12:

score: 0
Accepted
time: 4ms
memory: 22660kb

input:

1 296 298
1..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 7ms
memory: 55772kb

input:

7 300 300
.x...x...x...x...x..4x...x...x...x...x...x...x...x..1x...x...x...x...x...x..5x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..6x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..7x...x...

output:

438

result:

ok single line: '438'

Test #14:

score: 0
Accepted
time: 105ms
memory: 74016kb

input:

9 296 298
1AAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxC...

output:

45376

result:

ok single line: '45376'

Test #15:

score: 0
Accepted
time: 16ms
memory: 72204kb

input:

9 296 298
4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x....

output:

-1

result:

ok single line: '-1'

Subtask #4:

score: 40
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 40
Accepted
time: 52ms
memory: 83720kb

input:

9 500 500
.....................................................................................................................................................................................................................................................................................................

output:

44

result:

ok single line: '44'

Test #17:

score: 0
Accepted
time: 308ms
memory: 82088kb

input:

9 496 500
2AAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxAAAxxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxCCCxC...

output:

138163

result:

ok single line: '138163'

Test #18:

score: 0
Accepted
time: 61ms
memory: 83504kb

input:

9 496 500
4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x....

output:

-1

result:

ok single line: '-1'

Test #19:

score: 0
Accepted
time: 50ms
memory: 83600kb

input:

9 500 500
.x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..4x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x..7x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...

output:

484

result:

ok single line: '484'

Test #20:

score: 0
Accepted
time: 172ms
memory: 83848kb

input:

9 496 500
4..x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...x...xx...x...x...x...x...x...x...x...x...x...x....

output:

126926

result:

ok single line: '126926'