QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789881#9802. Light Up the Gridxyggzsf#WA 116ms68948kbC++173.5kb2024-11-27 22:25:162024-11-27 22:25:20

Judging History

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

  • [2024-11-27 22:25:20]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:68948kb
  • [2024-11-27 22:25:16]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
#define int    long long 
typedef pair<int, int>pii;
typedef pair<char, int>pci;
typedef pair<pii, int>piii;
const int mod = 998244353;
const int N = 5e5 + 100;
int opt1(int x, int pos)
{
    x ^= 1ll << pos;
    return x;
}
int opt2(int x, int pos)
{
    if (pos == 0)
    {
        x ^= 12;
    }
    else x ^= 3;
    return x;
}
int opt3(int x, int pos)
{
    if (pos == 0)
    {
        x ^= 10;
    }
    else x ^= 5;
    return x;
}
int opt4(int x)
{
    return x ^ 15;
}
int ans[1ll << 16];
int a[10];
void solve()
{
    int m, sum = 0;
    cin >> m;
    while (m--)
    {
        int t, tot = 0;
        string s1, s2;
        cin >> s1 >> s2;
        s1 += s2;
        for (int i = 0; i < 4; i++)
        {
            tot += (s1[i] - '0') << (3 - i);
        }
        sum |= 1ll << tot;
    }
    cout << ans[sum] << endl;
}
int cal(int st, int now)
{
    return st * 16 + now;
}
int dist[N * 16];
bool st[N];
void dijkstra()
{
    for (int i = 0; i < N * 16; i++)
    {
        dist[i] = 1e17;
    }
    priority_queue<pii, vector<pii>, greater<pii> >hp;
    dist[cal(0, 15)] = 0;
    hp.push({ 0,cal(0,15) });
    while (hp.size())
    {
        int u = hp.top().second;
        hp.pop();
        if (st[u])continue;
        st[u] = 1;
        int ok = u >> 4, now = u % 16;
        ans[ok] = min(ans[ok], dist[u]);
        for (int j = 0; j < 4; j++)
        {
            int nxt = opt1(now, j);
            int v = cal(ok | (1ll << nxt), nxt);
            if (!st[v] && dist[u] + a[0] < dist[v])
            {
                dist[v] = dist[u] + a[0];
                hp.push({ dist[v],v });
            }
        }
        for (int j = 0; j < 2; j++)
        {
            int nxt = opt2(now, j);
            int v = cal(ok | (1ll << nxt), nxt);
            if (!st[v] && dist[u] + a[1] < dist[v])
            {
                dist[v] = dist[u] + a[1];
                hp.push({ dist[v],v });
            }
        }
        for (int j = 0; j < 2; j++)
        {
            int nxt = opt3(now, j);
            int v = cal(ok | (1ll << nxt), nxt);
            if (!st[v] && dist[u] + a[2] < dist[v])
            {
                dist[v] = dist[u] + a[2];
                hp.push({ dist[v],v });
            }
        }
        int nxt = opt4(now);
        int v = cal(ok | (1 << nxt), nxt);
        if (!st[v] && dist[u] + a[3] < dist[v])
        {
            dist[v] = dist[u] + a[3];
            hp.push({ dist[v],v });
        }
    }
}
bool used[1 << 16];
int dfs(int u)
{
    if (used[u])return ans[u];
    for (int i = 0; i < 16; i++)
    {
        if (u != (u | (1 << i)))ans[u] = min(ans[u], dfs(u | (1 << i)));
    }
    used[u] = 1;
    return ans[u];
}
signed main()
{
    ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int t = 1;
    cin >> t;
    for (int i = 0; i <= 3; i++)cin >> a[i];
    for (int i = (1 << 16) - 1; ~i; i--)
    {
        ans[i] = 1e17;
    }
    dijkstra();
    memset(used, 0, sizeof used);
    used[(1 << 16) - 1] = 1;
    //dfs(0);
    // 
    for (int i = (1 << (16)) - 1; i >= 0; i--)
    {
        for (int j = 0; j <= 15; j++)
        {
            if ((i >> j) & 1)
            {
                ans[i - (int)pow(2, j)] = min(ans[i - (int)pow(2, j)], ans[i]);
            }
        }
    }
    //cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 116ms
memory: 68948kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2002

result:

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