QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788898 | #9807. Make Them Believe | ucup-team5071# | WA | 141ms | 7940kb | C++20 | 3.0kb | 2024-11-27 18:39:42 | 2024-11-27 18:39:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int a0, a1, a2, a3;
int dis[16][1 << 16];
int ans[1 << 16];
void gmin(int &x, int y)
{
if (y == -1)
return;
if (x == -1)
x = y;
else if (y < x)
x = y;
}
typedef array<array<int, 2>, 2> info;
int getid(info a)
{
int x = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
x = x * 2 + a[i][j];
}
return x;
}
int solve()
{
int m;
cin >> m;
cout << "m=" << m << endl;
int x = 0;
while (m--)
{
info now;
string s[2];
for (int i = 0; i < 2; i++)
{
cin >> s[i];
for (int j = 0; j < 2; j++)
now[i][j] = s[i][j] - '0';
}
x |= (1 << getid(now));
}
return ans[x];
}
const int inf = 2e9;
struct kkk
{
info a;
int x, len;
bool operator<(kkk k1) const
{
return len > k1.len;
}
};
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
memset(dis, -1, sizeof(dis));
memset(ans, -1, sizeof(ans));
int T;
cin >> T;
cin >> a0 >> a1 >> a2 >> a3;
priority_queue<kkk, vector<kkk>> qu;
auto try_push = [&](info a, int x, int d)
{
int id = getid(a);
// cout << "try_push id=" << id << " x=" << x << " d=" << d << endl;
x |= (1 << id);
if (dis[id][x] != -1)
return false;
qu.push(kkk{a, x, d});
return true;
};
auto push = [&](info a, int x, int d)
{
// cout << "id=" << getid(a) << " x=" << x << " d=" << d << endl;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
auto b = a;
b[i][j] ^= 1;
try_push(b, x, d + a0);
}
}
for (int i = 0; i < 2; i++)
{
auto b = a;
b[i][0] ^= 1;
b[i][1] ^= 1;
try_push(b, x, d + a1);
}
for (int j = 0; j < 2; j++)
{
auto b = a;
b[0][j] ^= 1;
b[1][j] ^= 1;
try_push(b, x, d + a2);
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
a[i][j] ^= 1;
}
try_push(a, x, d + a3);
};
push(info{array<int, 2>{1, 1}, array<int, 2>{1, 1}}, 0, 0);
while (!qu.empty())
{
// cout << "???" << endl;
kkk k1 = qu.top();
qu.pop();
int id = getid(k1.a);
if (dis[id][k1.x] != -1)
continue;
dis[id][k1.x] = k1.len;
push(k1.a, k1.x, k1.len);
}
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < (1 << 16); j++)
gmin(ans[j], dis[i][j]);
}
for (int j = 0; j < 32; j++)
cout << "ans_" << j << " =" << ans[j] << endl;
// return 0;
while (T--)
{
cout << solve() << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 141ms
memory: 7940kb
input:
LNG 55 WBG 65 HLE 70 BLG 75 TES 48 T1 80 GEN 60 FLY 50
output:
ans_0 =-1 ans_1 =0 ans_2 =-1 ans_3 =0 ans_4 =-1 ans_5 =0 ans_6 =-1 ans_7 =0 ans_8 =0 ans_9 =0 ans_10 =0 ans_11 =0 ans_12 =0 ans_13 =0 ans_14 =0 ans_15 =0 ans_16 =-1 ans_17 =0 ans_18 =-1 ans_19 =0 ans_20 =-1 ans_21 =0 ans_22 =-1 ans_23 =0 ans_24 =-1 ans_25 =0 ans_26 =0 ans_27 =0 ans_28 =-1 ans_29 =0 ...
result:
wrong answer 1st words differ - expected: 'T1', found: 'ans_0'