QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780692#9802. Light Up the GridaYi_7#WA 76ms3848kbC++232.3kb2024-11-25 12:25:582024-11-25 12:26:03

Judging History

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

  • [2024-11-25 12:26:03]
  • 评测
  • 测评结果:WA
  • 用时:76ms
  • 内存:3848kb
  • [2024-11-25 12:25:58]
  • 提交

answer

#include <bits/stdc++.h>
#define b4 bitset<4>
#define int long long
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 7;
int d[16][16];
b4 bs[16];
struct node{
    b4 s;
    int cost;
};
struct cmp{
    bool operator () (node a,node b){
        return (a.cost>b.cost);
    }
};
int vs(b4 &s){return 1*s[0]+2*s[1]+4*s[2]+8*s[3];}
int mm=LONG_LONG_MAX;
void solve() {
    int m;
    cin>>m;
    set<int>hh;
    for(int i=0;i<m;i++){
        string q,w;cin>>q>>w;
        q+=w;
        bitset<4>s(q);
        hh.insert(vs(s));
    }
    int ans=LONG_LONG_MAX;
    for(int cur:hh){
        set<int>h=hh;
        int cost=0;
        cost+=d[cur][15];
        h.erase(cur);
        while(!h.empty()){
            int to=*h.begin(),ct=d[cur][to];
            for(int s:h)if(d[cur][s]<ct){to=s;ct=d[cur][to];}
            cost+=ct;
            cur=to;
            h.erase(to);
        }
        ans=min(ans,cost);
    }
    if(ans==0)ans=mm;
    cout<<ans<<"\n";
}
/*
 2 1000 100 10 1
 4
 10
 00
 01
 00
 00
 10
 00
 01
 1
 11
 11
 * */
signed main() {
    for(auto & i : d)
        for(auto & j : i)
            j=-1;
    for(int i=0;i<16;++i){
        bitset<4> s("0000");
        int id=i;
        for(int j=0;j<4;++j){
            if(id&1)s[j]=1;
            id>>=1;
        }
        bs[i]=s;
    }

    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t = 1;
    cin >> t;
    int a0,a1,a2,a3;cin>>a0>>a1>>a2>>a3;
    mm=min({a0,a1,a2,a3})*2ll;
    for(int i=0;i<16;++i){
        priority_queue<node,vector<node>,cmp>q;
        q.push({bs[i],0});
        while(!q.empty()){
            b4 s=q.top().s;
            int cost=q.top().cost;
            int id=vs(s);
            q.pop();
            if(d[i][id]!=-1)continue;
            d[i][id]=cost;
            b4 r;
            for(int j=0;j<4;++j){r=s;r[j]=!r[j];q.push({r,cost+a0});}
            r=s;r[0]=!r[0];r[1]=!r[1];q.push({r,cost+a1});
            r=s;r[2]=!r[2];r[3]=!r[3];q.push({r,cost+a1});
            r=s;r[0]=!r[0];r[2]=!r[2];q.push({r,cost+a2});
            r=s;r[1]=!r[1];r[3]=!r[3];q.push({r,cost+a2});
            r=s;r[0]=!r[0];r[1]=!r[1];r[2]=!r[2];r[3]=!r[3];q.push({r,cost+a3});
        }
    }
    for (int i = 0; i < t; ++i) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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: 0ms
memory: 3624kb

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: 0ms
memory: 3848kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 76ms
memory: 3564kb

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:

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

result:

wrong answer 1st numbers differ - expected: '34', found: '32'