QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780752#9802. Light Up the GridaYi_7#WA 437ms3664kbC++232.9kb2024-11-25 12:59:122024-11-25 12:59:15

Judging History

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

  • [2024-11-25 12:59:15]
  • 评测
  • 测评结果:WA
  • 用时:437ms
  • 内存:3664kb
  • [2024-11-25 12:59:12]
  • 提交

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;
    bool flag=0;
    for(int i=0;i<m;i++){
        string q,w;cin>>q>>w;
        q+=w;
        bitset<4>s(q);
        if(vs(s)==15)flag=1;
        hh.insert(vs(s));
    }
    int ans=LONG_LONG_MAX;
    for(int cur:hh){
        set<int>h=hh;
        int cost=0;
        cost+=d[cur][15];
        if(cur==15)cost=mm;
        h.erase(cur);
        function<void(int)>dfs=[&](int cur){
            if(h.empty()){
                ans=min(ans,cost);
                return ;
            }
            vector<int>v;
            int to=*h.begin(),ct=d[cur][to];
            for(int s:h)if(d[cur][s]<ct){to=s;ct=d[cur][to];}
            for(int s:h)if(d[cur][s]==ct)v.emplace_back(s);
            cost+=ct;
            for(int s:v){
                h.erase(s);
                dfs(s);
                h.insert(s);
            }
            cost-=ct;
        };
        dfs(cur);
    }
    cout<<ans<<"\n";
}
/*
 2 1000 100 10 1
 4
 10
 00
 01
 00
 00
 10
 00
 01
 1
 11
 11


 1 1000 100 10 1
7
10
01

10
00

00
11

11
10

01
00

11
00

01
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];if(d[i][vs(r)]==-1)q.push({r,cost+a0});}
            r=s;r[0]=!r[0];r[1]=!r[1];if(d[i][vs(r)]==-1)q.push({r,cost+a1});
            r=s;r[2]=!r[2];r[3]=!r[3];if(d[i][vs(r)]==-1)q.push({r,cost+a1});
            r=s;r[0]=!r[0];r[2]=!r[2];if(d[i][vs(r)]==-1)q.push({r,cost+a2});
            r=s;r[1]=!r[1];r[3]=!r[3];if(d[i][vs(r)]==-1)q.push({r,cost+a2});
            r=s;r[0]=!r[0];r[1]=!r[1];r[2]=!r[2];r[3]=!r[3];if(d[i][vs(r)]==-1)q.push({r,cost+a3});
        }
    }
    for (int i = 0; i < t; ++i) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

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: 3628kb

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: 3664kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 437ms
memory: 3640kb

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

result:

wrong answer 10th numbers differ - expected: '41', found: '42'