QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789411#9802. Light Up the Gridxyggzsf#WA 8ms129368kbC++173.3kb2024-11-27 20:15:522024-11-27 20:15:53

Judging History

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

  • [2024-11-27 20:15:53]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:129368kb
  • [2024-11-27 20:15:52]
  • 提交

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 dp[N][16],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;
    }
    int tem = 1e17;
    if (sum & (1 << 15))
    {
        for (int i = 0; i <= 3; i++)
        {
            tem = min(tem, a[i] * 2);
        }
    }
    else tem = 0;
    cout << ans[sum]+tem << 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] = 1e16;
        dp[i >> 4][i % 16] = 1e17;
    }
    priority_queue<pii, vector<pii>, greater<pii> >hp;
    dist[cal(1 << 15, 15)] = 0;
    dist[0] = 0;
    hp.push({ 0,cal(1ll << 15,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;
        dp[ok][now] = 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 });
        }
    }
}
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];
    dijkstra();
    for (int i = (1 << 16) - 1; ~i; i--)
    {
        ans[i] = 1e17;
    }
    for (int i = (1 << 16) - 1; i >= 0; i--)
    {
        for(int j=0;j<=15;j++)ans[i] = min(ans[i], dp[i][j]);
        for (int j = 0; j <= 15; j++)ans[i] = min(ans[i], ans[i | (1 << j)]);
    }
    //cin >> t;
    while (t--) {
        solve();
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 129368kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

100000000000000000
2

result:

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