QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#815499#9802. Light Up the Griducup-team1769#WA 0ms3596kbC++142.4kb2024-12-15 15:01:482024-12-15 15:01:50

Judging History

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

  • [2024-12-15 15:01:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3596kb
  • [2024-12-15 15:01:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define max_len ((1 << (4)) + 10)
#define status_map(i1, i2, i3, i4) (((i1) * 0x1) | ((i2) * 0x2) | ((i3) * 0x4) | ((i4) * 0x8))

int min_cost[max_len];
int a1, a2, a3, a4;
void init_cost()
{
    memset(min_cost, 0x3f, sizeof(min_cost));
}

void bfs()
{
    // cost, status
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    que.push({0, status_map(1, 1, 1, 1)});
    while (que.size() != 0)
    {
        auto [co, st] = que.top();
        que.pop();
        if(min_cost[st] != 0x3f3f3f3f)
        {
            continue;
        }
        min_cost[st] = co;

        auto mask_status = [&] (int mask_s, int cost_use){
            int new_st = st ^ mask_s;
            que.push({co + cost_use, new_st});
        };
        mask_status(status_map(1, 1, 1, 1), a4);
        
        mask_status(status_map(1, 0, 1, 0), a3);
        mask_status(status_map(0, 1, 0, 1), a3);
        
        mask_status(status_map(1, 1, 0, 0), a2);
        mask_status(status_map(0, 0, 1, 1), a2);

        mask_status(status_map(1, 0, 0, 0), a1);
        mask_status(status_map(0, 1, 0, 0), a1);
        mask_status(status_map(0, 0, 1, 0), a1);
        mask_status(status_map(0, 0, 0, 1), a1);
    }
}

int can_stauts[max_len];
int N;

int get_ans()
{
    sort(can_stauts, can_stauts + N);
    int ans = 0x3f3f3f3f;
    do
    {
        int tans = 0;
        int all_mask = 0;
        for (int i = 0; i < N; i++)
        {
            tans += min_cost[all_mask ^ can_stauts[i]];
            all_mask ^= ((all_mask ^ can_stauts[i]) ^ status_map(1, 1, 1, 1));
        }
        ans = min(ans, tans);
        
    } while (next_permutation(can_stauts, can_stauts + N));
    return ans;
}
#define ch2int(ch) ((ch) - '0')
void sol()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string s1, s2;
        cin >> s1 >> s2;
        can_stauts[i] = status_map(ch2int(s1[0]), ch2int(s1[1]), ch2int(s2[0]), ch2int(s2[1]));

    }
    if(N == 1 && can_stauts[0] == 0x0f)
    {
        cout << 2 << "\n";
        return;
    }
    init_cost();
    bfs();
    int ans = get_ans();
    cout << ans << "\n";
}


int main()
{
    // cout << status_map(1, 1, 1, 1) << endl;
    int T;
    cin >> T >> a1 >> a2 >> a3 >> a4;
    while (T--)
    {
        sol();
    }
    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: -100
Wrong Answer
time: 0ms
memory: 3596kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2

result:

wrong answer 1st numbers differ - expected: '2000000', found: '2'