QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784606#9802. Light Up the GridCorycle#WA 110ms20812kbC++201.8kb2024-11-26 15:29:242024-11-26 15:29:24

Judging History

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

  • [2024-11-26 15:29:24]
  • 评测
  • 测评结果:WA
  • 用时:110ms
  • 内存:20812kb
  • [2024-11-26 15:29:24]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=16;
const int M=1<<16;
int read(){
    int s=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
    return s*f;
}
char s[4][4];
ll dis[N][M];
bool vis[N][M];
int n,m,Sta,a[9],sta[M];
int b[9]={1,2,4,8,5,10,3,12,15};
struct Node{
    int x,t;
    ll dis;
    friend bool operator<(Node A,Node B){
        return A.dis>B.dis;
    }
};
void BFS(){
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            dis[i][j]=1e18;
            vis[i][j]=0;
        }
    }
    priority_queue<Node>q;
    q.push((Node){15,0,0});
    dis[15][0]=0;
    while(q.size()){
        Node x=q.top();q.pop();
        if(vis[x.x][x.t])continue;
        vis[x.x][x.t]=1;
        // cout<<"Solve: "<<x.x<<" "<<x.t<<" "<<x.dis<<endl;
        for(int i=0;i<9;i++){
            Node y=(Node){x.x^b[i],x.t|(1<<(x.x^b[i])),x.dis+a[i]};
            // cout<<": "<<y.x<<" "<<y.t<<" "<<y.dis<<endl;
            if(dis[y.x][y.t]>y.dis){
                dis[y.x][y.t]=y.dis;
                q.push(y);
            }
        }
    }
}
int main(){
    int T=read();
    a[0]=a[1]=a[2]=a[3]=read();
    a[4]=a[5]=read();
    a[6]=a[7]=read();
    a[8]=read();
    BFS();
    for(int x=0;x<16;x++)
    for(int i=M-1;i>=0;i--){
        for(int j=0;j<16;j++){
            dis[x][i]=min(dis[x][i],dis[x][i|(1<<j)]);
        }
    }
    while(T--){
        n=read();
        Sta=0;
        for(int i=0;i<n;i++){
            scanf("%s%s",s[0],s[1]);
            int x=(s[0][0]-'0')+(s[0][1]-'0')*2+(s[1][0]-'0')*4+(s[1][1]-'0')*8;
            Sta|=(1<<x);
        }
        ll ans=1e18;
        for(int i=0;i<16;i++)ans=min(ans,dis[i][Sta]);
        printf("%lld\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 110ms
memory: 20812kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 64ms
memory: 17228kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

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

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 97ms
memory: 16924kb

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

34
32
31
34
40
38
42
37
40
41
31
44
34
38
38
32
38
38
38
40
36
42
42
37
32
40
36
40
34
44
36
41
34
36
41
31
44
27
38
34
34
36
39
39
42
35
39
37
36
34
40
36
40
42
34
41
43
29
41
33
42
37
37
34
29
40
36
40
42
38
34
29
33
34
32
36
38
39
38
39
35
38
43
33
36
32
42
40
28
40
38
42
38
41
36
36
35
38
34
36
...

result:

wrong answer 3rd numbers differ - expected: '36', found: '31'