QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789589#9802. Light Up the GridWzy#WA 33ms22212kbC++142.9kb2024-11-27 21:01:022024-11-27 21:01:03

Judging History

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

  • [2024-11-27 21:01:03]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:22212kb
  • [2024-11-27 21:01:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef pair<LL,int> PII;
const int N=(1<<17)-1,M=1000010;
const int mod=998244353;
LL a[4];
vector<LL> k[4];
LL dp[N][17];
LL dis[N];

int count(int x){

    for(int i=0;i<17;i++){
        int t=(x>>i)&1;

        if(t) return i;
    }

    return 0;
}

void djs(){
    priority_queue<PII,vector<PII>,greater<PII> > q;
    memset(dis,0x3f,sizeof dis);

    dis[0]=(LL)k[3][0]*2;
    q.push({dis[0],0});
    for(int i=0;i<4;i++)
        for(auto t:k[i]){
            dis[t]=a[i];
            q.push({a[i],t});
        }

    vector<int> st(20);


    while(q.size()){
        auto t=q.top();
        int u=t.second;
        q.pop();
        if(st[u]) continue;
        st[u]=true;


        for(int i=0;i<4;i++){
            for(auto j:k[i]){
                int v=j^u;
                if(st[v]) continue;

                if(dis[v]<dis[u]+a[i]) continue;

                dis[v]=dis[u]+a[i];
                q.push({dis[v],v});
            }
        }
    }

    return ;
}

void init(){
    djs();
    memset(dp,0x3f,sizeof dp);

    for(int i=1;i<=N;i++){
        if((i&-i)==i){
            int cnt=count(i);
            //cout<<i<<" "<<cnt<<endl;
            dp[i][cnt]=0;
            continue;
        }
        //cout<<i<<endl;

        vector<int> tmp;
        int t=i;
        while(t) tmp.push_back(count(t&-t)),t-=t&-t;
        //cout<<i<<endl;
        for(int g=0;g<tmp.size();g++){
            t=tmp[g];
            //if(i==278) cout<<t<<" ";
            for(int j=0;j<tmp.size();j++){
                if(j==g) continue;
                //if(t==1&&i==278) cout<<dp[i^2][tmp[j]]<<" "<<dis[tmp[j]^t]<<endl;

                dp[i][t]=min(dp[i][t],dp[i^(1<<t)][tmp[j]]+dis[tmp[j]^t]);
            }
            //if(i==278) cout<<dp[i][t]<<endl;;
        }
        //cout<<endl;
    }
}
 
 
void solve(){
    int m;
    cin>>m;
    vector<int> tmp;

    int g=15;
    while(m--){
        string a,b;
        cin>>a>>b;
        int t=0;
        t+=a[0]-'0';
        t<<=1;
        t+=a[1]-'0';
        t<<=1;
        t+=b[0]-'0';
        t<<=1;
        t+=b[1]-'0';
        //cout<<t<<endl;
        t^=g;
        tmp.push_back(t);
    }


    LL res=1e18;
    int t=0;
    for(int i=0;i<tmp.size();i++){
        t+=(1<<tmp[i]);
    }

    //cout<<t<<endl;

    for(int i=0;i<tmp.size();i++){
        res=min(res,dp[t][tmp[i]]+dis[tmp[i]]);
    }

    cout<<res<<endl;
}   
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    cin>>T;

    for(int i=0;i<4;i++) cin>>a[i];
    k[0].push_back(1),k[0].push_back(2),k[0].push_back(4),k[0].push_back(8);
    k[1].push_back(3),k[0].push_back(12);
    k[2].push_back(10),k[2].push_back(5);
    k[3].push_back(15);
    init();

    //cout<<dis[3]<<endl;

    while(T--) solve();
 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 31ms
memory: 22212kb

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: 33ms
memory: 22036kb

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: -100
Wrong Answer
time: 30ms
memory: 22212kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

30

result:

wrong answer 1st numbers differ - expected: '2000000', found: '30'