QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789615#9802. Light Up the GridWZY111WA 48ms21984kbC++143.1kb2024-11-27 21:10:382024-11-27 21:10:39

Judging History

你现在查看的是测评时间为 2024-11-27 21:10:39 的历史记录

  • [2024-11-29 22:57:30]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:33ms
  • 内存:22276kb
  • [2024-11-27 21:10:39]
  • 评测
  • 测评结果:0
  • 用时:48ms
  • 内存:21984kb
  • [2024-11-27 21:10:38]
  • 提交

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)a[3]*2;
    //cout<<dis[0]<<endl;
    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);
    }

    tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
    LL res=1e18;
    int t=0;
    //cout<<tmp[0]<<endl;
    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();

    //for(int i=0;i<17;i++) cout<<dis[i]<<" ";
    //cout<<endl;

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

详细

Test #1:

score: 100
Accepted
time: 26ms
memory: 21984kb

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: 31ms
memory: 21960kb

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: 29ms
memory: 21968kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 48ms
memory: 21912kb

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:

51
38
44
50
54
52
57
57
58
55
49
64
54
51
52
46
45
52
57
53
50
49
61
46
39
47
50
51
43
50
43
55
50
46
61
56
63
47
52
43
39
59
59
54
61
50
48
47
51
49
54
44
54
56
54
55
62
56
55
50
56
56
45
44
43
58
46
47
61
52
50
45
38
55
48
59
51
58
58
52
40
47
50
39
45
48
60
59
49
55
57
55
47
54
46
39
50
52
49
49
...

result:

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