QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784818 | #9802. Light Up the Grid | lnkkerst | TL | 0ms | 0kb | C++17 | 2.0kb | 2024-11-26 16:02:37 | 2024-11-29 22:55:11 |
Judging History
answer
#pragma GCC optimize(2)
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
void solve() {
int t;
vector<int> a(4);
cin >> t;
for (int i = 0; i < 4; ++i) {
cin >> a[i];
}
vector<int> ans((1 << 16) + 1, 1e9);
vector<int> ansa((1 << 21) + 1, 1e9);
// int cnt = 0;
function<void(int, int, int)> dfs = [&](int state, int table, int val) {
// ++cnt;
// if (cnt % 10000000 == 0) {
// cout << cnt << endl;
// }
if (ansa[(table << 4) + state] <= val) {
return;
}
ansa[(table << 4) + state] = val;
ans[table] = min(ans[table], val);
for (int i = 0; i < 4; ++i) {
int ns = state ^ (1 << i);
int nt = table | (1 << ns);
dfs(ns, nt, val + a[0]);
}
dfs(state ^ 0b1100, table | (1 << (state ^ 0b1100)), val + a[1]);
dfs(state ^ 0b0011, table | (1 << (state ^ 0b0011)), val + a[1]);
dfs(state ^ 0b1010, table | (1 << (state ^ 0b1010)), val + a[2]);
dfs(state ^ 0b0101, table | (1 << (state ^ 0b0101)), val + a[2]);
dfs(state ^ 0b1111, table | (1 << (state ^ 0b1111)), val + a[3]);
};
dfs(0b1111, 0, 0);
// cout << "OK" << endl;
for (int i = 0; i < (1 << 16); ++i) {
for (int j = i; j; j = (j - 1) & i) {
ans[j] = min(ans[j], ans[i]);
}
}
while (t--) {
int n;
cin >> n;
int table = 0;
for (int i = 1; i <= n; ++i) {
string s0, s1;
cin >> s0 >> s1;
table |= 1 << stoi(s0 + s1, 0, 2);
}
cout << ans[table] << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11