QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797645 | #9802. Light Up the Grid | ucup-team4975# | WA | 53ms | 16328kb | C++14 | 2.5kb | 2024-12-03 15:42:29 | 2024-12-03 15:42:30 |
Judging History
answer
#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif
#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif
#ifdef LOCAL
#define debugv(x) \
cerr << setw(4) << #x << ":: "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl
#else
#define debugv(x)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
out << x.fir << " " << x.sec << endl;
return out;
}
const int mod = 998244353;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 200020;
ll dp[(1 << 16) + 10][16], ans[(1 << 16) + 10];
int vis[(1 << 16) + 10][16];
int op[9] = {1, 2, 4, 8, 3, 12, 5, 10, 15};
int val[9];
void solve()
{
int n, now = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
string s1, s2;
cin >> s1 >> s2;
int res = (s1[0] - '0') + (s1[1] - '0') * 2 + (s2[0] - '0') * 4 + (s2[1] - '0') * 8;
now = (now | (1 << res));
}
// cout << now << el;
ll as = inf;
for (int i = 1; i < (1 << 16); i++) {
if ((i & now) == now) {
bitset<16>b = i;
// cout << i << " " << b << " " << ans[i]<< el;
as = min(as, ans[i]);
}
}
cout << as << el;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
int a1, a2, a3, a4;
cin >> a1 >> a2 >> a3 >> a4;
val[0] = val[1] = val[2] = val[3] = a1;
val[4] = val[5] = a2;
val[6] = val[7] = a3;
val[8] = a4;
for (int i = 0; i < (1 << 16); i++) {
for (int j = 0; j < 16; j++) {
dp[i][j] = inf;
}
ans[i] = inf;
}
priority_queue<pair<PII, int>> q;
dp[0][15] = 0;
q.push({{0, 15}, 0});
while (!q.empty()) {
auto [x, vl] = q.top();
q.pop();
if (vis[x.fir][x.sec])
continue;
vis[x.fir][x.sec] = 1;
ans[x.fir] = min(ans[x.fir], dp[x.fir][x.sec]);
for (int i = 0; i < 9; i++) {
int state = x.sec ^ op[i];
int st = (x.fir | (1 << state));
if (vis[st][state])
continue;
int v = dp[x.fir][x.sec] + val[i];
if (v < dp[st][state]) {
dp[st][state] = v;
q.push({{st, state}, v});
}
}
}
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 53ms
memory: 16328kb
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
1211 2
result:
wrong answer 1st numbers differ - expected: '1121', found: '1211'