QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784663 | #9802. Light Up the Grid | lnkkerst | WA | 85ms | 3656kb | C++17 | 1.8kb | 2024-11-26 15:39:05 | 2024-11-29 22:55:05 |
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);
function<void(int, int, int)> dfs = [&](int state, int table, int val) {
// cout << state << ' ' << table << ' ' << val << endl;
if (ans[table] <= val) {
return;
}
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);
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();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 85ms
memory: 3584kb
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: 43ms
memory: 3560kb
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: 43ms
memory: 3584kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 66ms
memory: 3656kb
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 37 42 38 40 41 36 44 35 38 38 32 29 39 39 40 38 39 44 37 29 38 37 38 35 34 32 41 34 36 42 40 44 34 37 34 29 38 39 40 42 36 39 38 38 38 42 31 40 41 36 43 43 40 41 34 42 39 37 33 34 38 38 38 42 40 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 41 38 39 40 42 37 40 38 29 36 40 36 35 ...
result:
wrong answer 6th numbers differ - expected: '36', found: '37'