QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1561#782788#9802. Light Up the GridhanmxhanmxFailed.2025-02-17 10:50:322025-02-17 10:50:32

Details

Extra Test:

Invalid Input

input:

1 1 1 1
1
00
00

output:


result:

FAIL Unexpected character #10, but ' ' expected (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782788#9802. Light Up the GridhanmxAC ✓146ms14148kbC++171.5kb2024-11-25 21:27:482024-11-29 22:53:28

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using i64=long long;
using u64=unsigned long long;
ll a,b,c,d;
const int N=1e5;
const ll inf=1e18;
vector<ll> dis(N,inf);
void solve(){
    int t;
    cin>>t;
    int ans=0;
    auto to=[&](char x)->int{
        return x-'0';
    };
    while(t--){
        int now=0;
        string s0,s1;
        cin>>s0>>s1;
        now=to(s0[0])*1+to(s0[1])*2+to(s1[0])*4+to(s1[1])*8;
        ans^=(1<<now);
    }
    cout<<dis[ans]<<"\n";
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    cin>>a>>b>>c>>d;
    int op[]={1,2,4,8,3,12,5,10,15};
    int cost[]={a,a,a,a,b,b,c,c,d};
    auto next=[&](int x,int k)->int{
        int v=0;
        for(int i=0;i<16;i++){
            if(x>>i&1){
                v^=1<<(i^k);
            }
        }
        return v;
    };
    auto dj=[&]()->void{
        priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<>> q;
        q.push({0,0});
        while(!q.empty()){
            auto [w,u]=q.top();
            q.pop();
            if(dis[u]!=inf) continue;
            dis[u]=w;
            for(int i=0;i<=8;i++){
                int v=next(u,op[i]);
                if(dis[v]==inf) q.push({dis[u]+cost[i],v});
                int z=v^(1<<(op[i]^15));
                if(dis[z]==inf) q.push({dis[u]+cost[i],z});
            }
        }
    };
    dj();
    while(t--) solve();
    return 0;
}