QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785589#9802. Light Up the Gridxbzxzn#WA 63ms7284kbC++202.6kb2024-11-26 18:24:582024-11-26 18:24:58

Judging History

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

  • [2024-11-26 18:24:58]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:7284kb
  • [2024-11-26 18:24:58]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define Pa pair<int,int>
using namespace std;
const int inf=1e18;
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
    vector<int>a(5);
    for(int i=0;i<4;i++)cin>>a[i];
    vector<array<int,2>>e;
    e.push_back({a[0],1});
    e.push_back({a[0],2});
    e.push_back({a[0],4});
    e.push_back({a[0],8});
    e.push_back({a[1],3});
    e.push_back({a[1],12});
    e.push_back({a[2],10});
    e.push_back({a[2],5});
    e.push_back({a[3],15});
    int mx=16;
    vector<int>dis(mx+1,inf),vis(1<<(mx+1),0);
    dis[15]=0;
    priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>>>q;
    q.push({dis[15],15});
    while(!q.empty()){
        auto [_,u]=q.top();q.pop();
        if(vis[u])continue;
        vis[u]=1;
        for(auto[val,nxt]:e){
            int v=u^nxt;
            if(dis[v]>dis[u]+val){
                dis[v]=dis[u]+val;
                q.push({dis[v],v});
            }
        }
    }
    dis[15]=inf;
    for(int i=0;i<=15;i++){
        dis[15]=min(dis[15],dis[i]*2ll);
    }
    int mn=inf;
    for(int i=0;i<4;i++)mn=min(mn,2*a[i]);
//    cout<<dis[15]<<' '<<mn<<endl;
    for(int i=0;i<(1ll<<(mx+1));i++)vis[i]=0;
    vector<int>dp(1<<(mx+1),inf),pre(1<<(mx+1),0);
    dp[0]=0;
    q.push({0,0});
    int maxn=0;int id=0;
    while(!q.empty()){
        auto [_,u]=q.top();q.pop();
        if(vis[u])continue;
        vis[u]=1;
        if(dp[u]>maxn){
            maxn=dp[u];
            id=u;
        }
        for(int i=0;i<mx;i++){
            if((u>>i)&1)continue;
            int v=u|(1ll<<i);
            int cur=pre[u]^i;
            if(cur==15&&u!=0){
                if(dp[v]>dp[u]){
                    dp[v]=dp[u];
                    pre[v]=pre[u];
                    q.push({dp[v],v});
                }
            }
            else if(dp[v]>dp[u]+dis[cur]){
                dp[v]=dp[u]+dis[cur];
                pre[v]=pre[u]^(15^cur);
                q.push({dp[v],v});
            }
        }
    }
//    cout<<maxn<<endl;
//    cout<<(1<<mx)-1<<endl;
    for(int i=(1<<mx)-1;i>=0;i--){
        for(int j=i;j;j=(j-1)&i){
            dp[j]=min(dp[j],dp[i]);
        }
    }
    while(T--){
        int n;cin>>n;
        vector<int>b(n);
        int res=0;
        for(int i=0;i<n;i++){
            string s;cin>>s;
            b[i]=(s[0]-'0')*8;
            b[i]+=(s[1]-'0')*4;
            cin>>s;
            b[i]+=(s[0]-'0')*2;
            b[i]+=(s[1]-'0');
            res|=(1ll<<b[i]);
//            cout<<b[i]<<'\n';
        }
        cout<<dp[res]<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 58ms
memory: 7284kb

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: 49ms
memory: 6828kb

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: 49ms
memory: 6900kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 63ms
memory: 7284kb

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
36
37
42
36
42
38
40
42
36
44
34
37
38
32
29
39
40
40
38
40
46
38
31
38
37
38
34
35
32
41
34
36
41
40
45
34
38
34
29
36
40
40
43
35
39
38
38
38
42
29
41
41
36
42
44
40
41
35
42
40
38
33
34
39
38
37
42
40
34
36
29
34
34
38
36
39
38
37
36
38
35
34
36
34
42
40
38
40
40
40
38
42
38
29
36
40
36
36
...

result:

wrong answer 4th numbers differ - expected: '36', found: '37'