QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794317 | #9802. Light Up the Grid | ucup-team133# | WA | 179ms | 17272kb | C++23 | 3.2kb | 2024-11-30 13:35:30 | 2024-11-30 13:35:30 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
using namespace std;
using ll = long long;
const int MAX_STATE = 16, INF = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int T;
cin >> T;
vector<int> a(4);
cin >> a;
vector dp(1 << MAX_STATE, vector<int>(MAX_STATE, INF));
priority_queue<tuple<int, int, int>> pq;
dp[0][0] = 0;
pq.emplace(-dp[0][0], 0, 0);
auto update = [&](int S, int cur, int val) {
if (chmin(dp[S][cur], val)) pq.emplace(-val, S, cur);
};
while (not pq.empty()) {
auto [val, S, cur] = pq.top();
pq.pop();
val *= -1;
if (dp[S][cur] != val) continue;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
int nxt = cur ^ (1 << (2 * i + j)), nS = S | 1 << nxt, nval = val + a[0];
update(nS, nxt, nval);
}
}
for (int i = 0; i < 2; i++) {
{
int nxt = cur ^ (1 << (2 * i)) ^ (1 << (2 * i + 1)), nS = S | 1 << nxt, nval = val + a[1];
update(nS, nxt, nval);
}
{
int nxt = cur ^ (1 << i) ^ (1 << (2 + i)), nS = S | 1 << nxt, nval = val + a[2];
update(nS, nxt, nval);
}
}
{
int nxt = cur ^ 15, nS = S | 1 << nxt, nval = val + a[3];
update(nS, nxt, nval);
}
}
vector<int> DP(1 << MAX_STATE, INF);
for (int S = 0; S < 1 << MAX_STATE; S++) {
for (int i = 0; i < MAX_STATE; i++) {
chmin(DP[S], dp[S][i]);
}
}
for (int S = 0; S < 1 << MAX_STATE; S++) {
for (int i = 0; i < MAX_STATE; i++) {
if (~S >> i & 1) {
chmin(DP[S], DP[S | 1 << i]);
}
}
}
for (; T--;) {
int m;
cin >> m;
int rest = 0;
for (; m--;) {
int S = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
char c;
cin >> c;
if (c == '0') S |= 1 << (2 * i + j);
}
}
rest |= 1 << S;
}
cout << DP[rest] << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 179ms
memory: 17272kb
input:
2 1000 100 10 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
1121 2
result:
ok 2 number(s): "1121 2"
Test #2:
score: 0
Accepted
time: 83ms
memory: 11480kb
input:
2 1 1 1 1 4 10 00 01 00 00 10 00 01 1 11 11
output:
5 2
result:
ok 2 number(s): "5 2"
Test #3:
score: 0
Accepted
time: 91ms
memory: 11480kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 170ms
memory: 12920kb
input:
10000 8 2 7 8 8 00 01 00 11 00 10 11 11 10 10 01 10 01 00 10 11 8 11 01 11 00 01 10 11 11 00 01 01 01 01 00 11 10 9 00 00 01 01 10 11 00 01 11 10 11 00 11 11 00 11 01 10 9 11 11 10 00 11 00 11 01 00 10 01 11 00 01 01 01 10 01 11 00 01 01 01 10 10 00 11 11 11 11 10 ...
output:
34 32 36 36 40 36 42 38 44 41 36 44 34 37 37 32 29 39 43 44 38 39 44 37 29 37 41 38 34 34 32 41 34 36 41 43 44 34 37 34 29 36 39 40 42 35 43 37 38 38 45 29 40 41 36 41 43 48 41 34 42 42 37 33 34 38 41 37 42 43 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 40 41 38 43 40 37 40 41 29 36 43 36 34 ...
result:
wrong answer 9th numbers differ - expected: '40', found: '44'