QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#821277#9802. Light Up the Griducup-team3548#WA 18ms11756kbC++203.4kb2024-12-19 14:54:282024-12-19 14:54:28

Judging History

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

  • [2024-12-19 14:54:28]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:11756kb
  • [2024-12-19 14:54:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const ll inf = 1e16;

vector<ll> ans;

void init() {
    vector<ll> a(4);
    for (int i = 0; i < 4; ++i) {
        cin >> a[i];
    }
    int m = 16;
    auto trans = [&](array<array<int, 2>, 2> &s) {
        int res = 0;
        res += s[0][0] + (s[0][1]) * 2 + (s[1][0]) * 4 + (s[1][1]) * 8;
        return res;
    };
    vector<ll> dis(m, inf);
    array<array<int, 2>, 2> ar;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            ar[i][j] = 0;
        }
    }
    priority_queue<pair<ll, array<array<int, 2>, 2> > > heap;
    heap.push({0, ar});
    while (heap.size()) {
        auto [d, u] = heap.top();
        heap.pop();
        d = -d;
        if (d != dis[trans(u)] && d != 0) continue;
        auto v = u;
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                v[i][j] ^= 1;
                int iv = trans(v);
                if (dis[iv] > d + a[0]) {
                    dis[iv] = d + a[0];
                    heap.push({-dis[iv], v});
                }
                v[i][j] ^= 1;
            }
            v[i][0] ^= 1, v[i][1] ^= 1;
            int iv = trans(v);
            if (dis[iv] > d + a[1]) {
                dis[iv] = d + a[1];
                heap.push({-dis[iv], v});
            }
            v[i][0] ^= 1, v[i][1] ^= 1;

            v[0][i] ^= 1, v[1][i] ^= 1;
            iv = trans(v);
            if (dis[iv] > d + a[2]) {
                dis[iv] = d + a[2];
                heap.push({-dis[iv], v});
            }
            v[0][i] ^= 1, v[1][i] ^= 1;
        }
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                v[i][j] ^= 1;
            }
        }
        int iv = trans(v);
        if (dis[iv] > d + a[3]) {
            dis[iv] = d + a[3];
            heap.push({-dis[iv], v});
        }
    }
    // for (int i = 0; i < m; ++i) {
    //     cout << i << " " << dis[i] << "\n";
    // }
    vector<vector<ll> > f(m, vector<ll> (1 << m, inf));
    f[0][0] = 0;
    for (int i = 1; i < (1 << m); ++i) {
        for (int j = 0; j < m; ++j) {
            if (!(i >> j & 1)) continue;
            int k = i ^ (1 << j);
            for (int l = 0; l < m; ++l) {
                if (l == j) continue;
                f[j][i] = min(f[j][i], f[l][k] + dis[j ^ l]);
            }
        }
    }
    ans.resize(1 << m, inf);
    for (int i = 0; i < (1 << m); ++i) {
        for (int j = 0; j < m; ++j) {
            ans[i] = min(ans[i], f[j][i]);
        }
    }
}

void Solve()
{
    int m;
    cin >> m;
    auto trans = [&](array<array<int, 2>, 2> &s) {
        int res = 0;
        res += s[0][0] + (s[0][1]) * 2 + (s[1][0]) * 4 + (s[1][1]) * 8;
        return res;
    };
    array<string, 2> s;
    int id = 0;
    for (int i = 0; i < m; ++i) {
        cin >> s[0] >> s[1];
        array<array<int, 2>, 2> ar;
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                ar[j][k] = '1' - s[j][k];
            }
        }
        id |= 1 << trans(ar);
    }
    cout << ans[id] << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    init();
    while(t--)
    {
        Solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 18ms
memory: 11756kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
10000000000000000

result:

wrong answer 2nd numbers differ - expected: '2', found: '10000000000000000'