QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796383#9802. Light Up the GridBoBoowenWA 0ms12336kbC++203.0kb2024-12-01 17:55:462024-12-01 17:55:47

Judging History

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

  • [2024-12-01 17:55:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12336kb
  • [2024-12-01 17:55:46]
  • 提交

answer

#include <map>
#include <set>
#include <fstream>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <iomanip>
#define endl '\n'
#define int long long
#define Max(a, b) (((a) > (b)) ? (a) : (b))
#define Min(a, b) (((a) < (b)) ? (a) : (b))
#define BoBoowen ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

int a0, a1, a2, a3;
int dis[16][16];
int dp[1 << 16][16];
int ans[1 << 16];
const int inf = 1e9 + 7;

void ckmin(int x, int y)
{
    x = min(x, y);
}

void add(int x, int y, int w)
{
    ckmin(dis[x][y], w);
    ckmin(dis[y][x], w);
}

void init()
{
    cin >> a0 >> a1 >> a2 >> a3;

    memset(dis, inf, sizeof(dis));

    for (int i = 0; i < 16; i++)
    {
        // 0
        for (int j = 0; j < 4; j++)
        {
            add(i, (i ^ (1 << j)), a0);
        }
        // 1
        // 1100,0011
        add(i, (i ^ 12), a1);
        add(i, (i ^ 3), a1);

        // 2
        // 1010,0101
        add(i, (i ^ 10), a2);
        add(i, (i ^ 5), a2);

        // 3
        // 1111
        add(i, (i ^ 15), a3);
    }

    for (int i = 0; i < 16; i++)
    {
        dis[i][i] = 0;
    }

    dis[15][15] = 2 * min({a0, a1, a2, a3});

    for (int k = 0; k < 16; k++)
    {
        for (int i = 0; i < 16; i++)
        {
            for (int j = 0; j < 16; j++)
            {
                ckmin(dis[i][j], dis[i][k] + dis[k][j]);
            }
        }
    }

    memset(dp, inf, sizeof(dp));
    memset(ans, inf, sizeof(ans));
    for (int i = 0; i < 16; i++)
    {
        dp[1 << i][i] = dis[i][15];
    }

    for (int ms = 1; ms < 1 << 16; ms++)
    {
        for (int j = 0; j < 16; j++)
        {
            if ((ms >> j & 1) == 0)
                continue;
            for (int k = 0; k < 16; k++)
            {
                if (ms >> k & 1)
                    continue;
                ckmin(dp[ms | (1 << k)][k], dp[ms][j] + dis[(j ^ 15) ^ k][15]);
            }
        }
    }

    for (int ms = 1; ms < 1 << 16; ms++)
    {
        for (int j = 0; j < 16; j++)
        {
            ckmin(ans[ms], dp[ms][j]);
        }
    }
}

void solve()
{
    int n;
    cin >> n;
    int ms = 0;
    for (int i = 0; i < n; i++)
    {
        string p, q;
        cin >> p >> q;

        int x = 0;
        if (p[0] == '1')
        {
            x += 8;
        }
        if (p[1] == '1')
        {
            x += 4;
        }
        if (q[0] == '1')
        {
            x += 2;
        }
        if (q[1] == '1')
        {
            x += 1;
        }
        ms |= (1 << x);
    }
    cout << ans[ms] << endl;
}

signed main()
{
    BoBoowen;
    int T;
    cin >> T;

    init();

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 12336kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

506381209866536711
506381209866536711

result:

wrong answer 1st numbers differ - expected: '1121', found: '506381209866536711'