QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788402#9802. Light Up the GridxbzxznWA 47ms25944kbC++202.2kb2024-11-27 16:48:582024-11-29 22:56:54

Judging History

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

  • [2024-11-29 22:56:54]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:47ms
  • 内存:25944kb
  • [2024-11-27 16:48:59]
  • 评测
  • 测评结果:0
  • 用时:45ms
  • 内存:25868kb
  • [2024-11-27 16:48:58]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define Pa pair<int,int>
using namespace std;
const int inf=1e18;
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
    vector<int>a(5);
    for(int i=0;i<4;i++)cin>>a[i];
    vector<array<int,2>>e;
    e.push_back({a[0],1});
    e.push_back({a[0],2});
    e.push_back({a[0],4});
    e.push_back({a[0],8});
    e.push_back({a[1],3});
    e.push_back({a[1],12});
    e.push_back({a[2],10});
    e.push_back({a[2],5});
    e.push_back({a[3],15});
    int mx=16;
    vector<int>dis(mx+1,inf),vis(1<<(mx+1),0);
    dis[15]=0;
    priority_queue<array<int,2>,vector<array<int,2>>,greater<array<int,2>>>q;
    q.push({dis[15],15});
    while(!q.empty()){
        auto [_,u]=q.top();q.pop();
        if(vis[u])continue;
        vis[u]=1;
        for(auto[val,nxt]:e){
            int v=u^nxt;
            if(dis[v]>dis[u]+val){
                dis[v]=dis[u]+val;
                q.push({dis[v],v});
            }
        }
    }
    dis[15]=inf;
    for(int i=0;i<=15;i++){
        dis[15]=min(dis[15],dis[i]*2ll);
    }
    for(int i=0;i<(1ll<<(mx+1));i++)vis[i]=0;
    vector<vector<int>>dp(1<<(mx+1),vector<int>(16,inf));
    for(int i=0;i<=15;i++){
        dp[1<<i][i]=dis[i];
    }
    for(int i=1;i<(1ll<<mx);i++){
        for(int j=0;j<=15;j++){
            if((i>>j)&1){
                int cur=i^(1<<j);
                for(int k=0;k<=15;k++){
                    if((cur>>k)&1){
                        dp[i][j]=min(dp[i][j],dp[cur][k]+dis[k^15^j]);
                    }
                }
            }
        }
    }
    while(T--){
        int n;cin>>n;
        vector<int>b(n);
        int res=0;
        for(int i=0;i<n;i++){
            string s;cin>>s;
            b[i]=(s[0]-'0')*8;
            b[i]+=(s[1]-'0')*4;
            cin>>s;
            b[i]+=(s[0]-'0')*2;
            b[i]+=(s[1]-'0');
            res|=(1ll<<b[i]);
//            cout<<b[i]<<' ';
        }
        cout<<'\n';
//        cout<<res<<'\n';

        int ans=inf;
        for(int i=1;i<=15;i++){
            ans=min(ans,dp[res][i]);
        }
        cout<<ans<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 34ms
memory: 25688kb

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: 34ms
memory: 25828kb

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: 38ms
memory: 25876kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:


2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: 0
Accepted
time: 39ms
memory: 25944kb

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

41

36

44

34

37

37

32

29

39

39

40

38

39

44

37

29

37

37

38

34

34

32

41

34

36

41

40

44

34

37

34

29

36

39

40

42

35

39

37

38

38

41

29

40

41

36

41

43

40

41

34

42

39

37

33

34

38

38

37

42

40

34

36

28

34

32
...

result:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 39ms
memory: 25776kb

input:

10000 73 78 73 17
11
01
10

01
11

10
00

11
11

00
00

11
01

10
11

11
10

00
11

10
01

01
00
6
00
00

10
11

11
10

01
01

11
01

11
00
7
01
11

01
00

10
00

10
11

10
10

00
00

01
01
10
10
01

10
10

00
10

10
11

10
00

01
01

01
10

11
11

11
00

00
01
10
11
11

01
11

10
10

01
01

00
01

...

output:


523

382

287

579

523

596

343

275

343

472

382

343

455

326

433

360

579

545

506

523

326

528

467

382

438

421

377

460

416

579

489

596

309

326

326

596

438

387

506

562

523

377

416

309

523

348

365

343

416

392

343

399

348

506

421

596

450

426

579

370
...

result:

ok 10000 numbers

Test #6:

score: 0
Accepted
time: 47ms
memory: 25732kb

input:

10000 701 328 455 703
7
10
11

00
01

00
11

00
10

01
00

11
11

11
00
7
00
01

01
00

00
11

11
11

00
00

11
10

11
01
6
01
10

01
01

00
01

00
11

10
01

11
00
8
00
11

10
11

00
10

00
01

11
10

01
01

10
10

11
00
5
00
11

10
11

11
00

01
10

01
00
7
00
01

10
10

11
01

00
10

10
00

11
11...

output:


3124

3124

2595

4153

2595

3177

3907

2796

4235

3833

3296

2595

4809

3579

3579

3050

3169

3907

3907

3251

3169

2714

2595

3050

3251

3542

2796

3251

4563

3251

3452

3907

3251

3251

4034

4034

1730

2140

3087

4153

3907

3907

4727

4809

2923

3497

3579

3431

3251

4235
...

result:

ok 10000 numbers

Test #7:

score: 0
Accepted
time: 38ms
memory: 25752kb

input:

10000 6459 225 8979 7226
16
00
11

11
01

10
01

10
10

00
01

01
11

11
00

11
11

00
10

11
10

01
01

01
00

01
10

10
00

00
00

10
11
16
10
00

11
10

01
10

11
11

00
01

00
00

01
00

01
11

01
01

10
01

00
10

10
10

00
11

11
01

10
11

11
00
16
10
11

01
11

10
00

10
10

01
00

11
11

01...

output:


22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302

22302...

result:

ok 10000 numbers

Test #8:

score: -100
Wrong Answer
time: 43ms
memory: 25688kb

input:

10000 47809 35506 569 26740
5
00
01

10
10

11
01

11
11

00
11
8
11
01

10
10

11
00

01
00

10
01

01
10

10
00

00
10
6
01
10

11
00

00
11

11
11

10
01

01
01
8
00
10

10
01

01
10

10
11

00
00

00
11

01
01

11
10
6
01
11

10
01

00
10

00
00

10
00

01
10
8
00
01

01
10

01
11

00
00

10
10
...

output:


119959

122235

38351

122235

87298

122235

122804

122804

122804

85591

123373

123942

121097

86160

122235

123942

122235

85591

86729

124511

122804

122235

88436

123373

122804

122235

124511

85591

121666

49516

122235

122235

122235

121666

86160

121097

125649

123373

87867...

result:

wrong answer 1052nd numbers differ - expected: '1138', found: '1707'