QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794311 | #9802. Light Up the Grid | ucup-team3584# | WA | 20ms | 3668kb | C++23 | 1.9kb | 2024-11-30 13:32:32 | 2024-11-30 13:32:33 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q;
cin >> q;
vector<int> a(9);
cin >> a[0];
a[1] = a[2] = a[3] = a[0];
cin >> a[4];
a[5] = a[4];
cin >> a[6];
a[7] = a[6];
cin >> a[8];
vector<int> dp(1 << 16, 2e9);
vector<vector<int>> tr(16, vector<int>(9));
vector<int> uo = {1, 2, 4, 8, 3, 12, 5, 10, 15};
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 9; ++j) {
tr[i][j] = i ^ uo[j];
}
}
dp[0] = 0;
for (int i = 0; i < 1 << 16; ++i) {
for (int j = 0; j < 9; ++j) {
int bit = (1 << (15 ^ uo[j]));
for (int k = 0; k < 16; ++k) {
if (1 << k & i) {
bit |= 1 << (k ^ uo[j]);
}
}
dp[bit] = min(dp[bit], dp[i] + a[j]);
}
}
for (int i = dp.size() - 1; i > 0; --i) {
for (int j = 0; j < 16; ++j) {
if ((1 << j) & i) {
dp[i ^ (1 << j)] = min(dp[i ^ (1 << j)], dp[i]);
}
}
}
while (q--) {
int n;
cin >> n;
int bit = 0;
for (int i = 0; i < n; ++i) {
char c;
int num = 0;
for (int j = 0; j < 4; ++j) {
cin >> c;
if (c == '1') {
num |= 1 << j;
}
}
bit |= (1 << num);
}
cout << dp[bit] << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 13ms
memory: 3556kb
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: 13ms
memory: 3600kb
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: 13ms
memory: 3668kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 20ms
memory: 3608kb
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:
36 38 42 46 49 43 44 48 48 47 45 54 46 39 42 39 37 45 50 42 41 40 52 44 31 44 44 43 35 41 36 49 43 37 54 48 52 40 43 39 36 50 46 40 52 39 45 40 43 47 49 42 48 44 48 49 50 50 47 46 44 45 43 38 34 52 41 40 52 41 40 41 36 46 37 49 44 50 48 40 36 45 46 40 36 44 50 48 44 40 48 44 44 49 41 32 38 43 36 36 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '36'