QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789455 | #9802. Light Up the Grid | xyggzsf# | WA | 119ms | 69080kb | C++17 | 3.0kb | 2024-11-27 20:25:11 | 2024-11-27 20:25:11 |
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 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 });
}
}
}
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();
for (int i = (1 << 16) - 1; i >= 0; i--)
{
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: 119ms
memory: 69080kb
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'