QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780674#9802. Light Up the GridZhanghaoyiWA 14ms3792kbC++232.1kb2024-11-25 12:18:182024-11-29 22:51:43

Judging History

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

  • [2024-11-29 22:51:43]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:14ms
  • 内存:3792kb
  • [2024-11-25 12:18:19]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:3832kb
  • [2024-11-25 12:18:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

int a[9];
int dis[17];
int fix(int x, int op){
    if(op < 4)
        return x ^ (1 << op);
    else if(op < 6){
        if(op == 4)
            return x ^ 3;
        else
            return x ^ 12;
    }
    else if(op < 8){
        if(op == 6)
            return x ^ 5;
        else
            return x ^ 10;
    }
    else return x ^ 15;
}

void per(){
    cin >> a[0] >> a[4] >> a[6] >> a[8];
    a[1] = a[2] = a[3] = a[0];
    a[5] = a[4];
    a[7] = a[6];
    for(int i = 0 ; i < 17 ;i ++ )
        dis[i] = 1e9;
    dis[15] = 0;
    priority_queue<pair<int,int>> q;
    q.push({0,15});
    while(!q.empty()){
        pair<int,int> tmp = q.top();
        q.pop();
        if(tmp.first > dis[tmp.second]) continue;
        for(int i = 0 ; i < 9 ; i ++ ){
            int pos = fix(tmp.second,i);
            if(dis[pos] > a[i] + dis[tmp.second]){
                dis[pos] = a[i] + dis[tmp.second];
                q.push({dis[pos],pos});
            }
        }
    }
    dis[15] = 2 * min({a[0],a[4],a[6],a[8]});
}
int ge[17];
void solve()
{
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i ++ ){
        int x = 0;
        if(i != 0) getchar();
        string s;
        for(int j = 0 ; j < 2 ; j++ ){
            cin >> s;
            for(int k = 0 ; k < 2; k ++ )
                if(s[k] == '1')
                    x += (1 << k + 2 * j);
        }
        ge[i] = x;
    }
    int ans = 0;
    while(1){
        int pos = 17 ,d = 1e9;
        for(int i = 0 ;i < n ; i++ ){
            if(ge[i] != -1 && dis[ge[i]] < d){
                pos = i;
                d = dis[ge[i]];
            }
        }
        if(d == 1e9) break;
        ans += d;
        for(int i = 0 ; i <n ; i ++ )
            if(ge[i] != -1 && i != pos)
                ge[i] ^= (15 ^ ge[pos]);
        ge[pos] = -1;
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    cin>>t;
    per();
    while(t--){
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3792kb

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

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

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 14ms
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
38
42
38
40
42
36
44
34
37
39
34
29
39
40
40
38
41
46
38
31
40
37
38
34
35
32
42
34
38
42
40
46
34
39
36
29
38
40
40
45
39
39
38
38
40
42
29
43
42
36
42
46
40
41
34
42
40
37
33
34
40
38
37
42
40
36
38
29
34
34
38
36
39
38
38
36
38
35
36
36
34
42
42
38
38
40
40
40
42
38
29
36
40
38
36
...

result:

wrong answer 6th numbers differ - expected: '36', found: '38'