QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794349 | #9802. Light Up the Grid | ucup-team3584# | WA | 20ms | 3844kb | C++23 | 2.0kb | 2024-11-30 13:48:39 | 2024-11-30 13:48:39 |
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<ll> 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<ll> 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 = 0;
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]);
bit |= 1 << (15 ^ 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: 3620kb
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: 3844kb
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: 3720kb
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: 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:
46 38 42 48 68 43 50 68 55 60 51 59 55 53 42 39 39 52 2000000000 59 47 44 56 48 37 52 55 68 35 45 39 2000000000 45 37 2000000000 54 63 44 46 39 42 61 49 40 2000000000 48 45 50 49 52 56 48 2000000000 2000000000 48 54 63 58 47 46 57 55 56 49 34 52 56 45 62 63 47 43 40 49 46 63 50 57 56 50 36 200000000...
result:
wrong answer 1st numbers differ - expected: '34', found: '46'