QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789411 | #9802. Light Up the Grid | xyggzsf# | WA | 8ms | 129368kb | C++17 | 3.3kb | 2024-11-27 20:15:52 | 2024-11-27 20:15:53 |
Judging History
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
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'