QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#782881 | #9802. Light Up the Grid | EZGG | WA | 30ms | 13844kb | C++23 | 1.5kb | 2024-11-25 21:59:47 | 2024-11-25 21:59:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<ll>> dp(1 << 16, vector<ll>(17, 0x3f3f3f3f));
void init()
{
ll a, b, c, d;
cin >> a >> b >> c >> d;
b = min(2 * a, b);
c = min(2 * b, c);
d = min({2 * b, 2 * c, d});
vector<ll> mp(16);
mp[1] = mp[2] = mp[4] = mp[8] = a;
mp[12] = mp[3] = b;
mp[10] = mp[5] = c;
mp[15] = d;
mp[6] = mp[9] = min(b + c, 2 * a);
mp[7] = mp[11] = mp[13] = mp[14] = min({b + a, c + a, d + a});
mp[0] = min({a, b, c, d}) * 2;
dp[0][0] = 0;
for (int i = 1; i < (1 << 16); i++)
{
for (int j = 1; j <= 16; j++)
{
if (i & (1 << j - 1))
{
dp[i][j] = min(dp[i][j], dp[i ^ (1 << j - 1)][0] + mp[j - 1]);
for (int k = 0; k < 16; k++)
{
if (i & (1 << k))
{
dp[i][j] = min(dp[i][j], dp[i ^ (1 << j - 1)][k + 1] + mp[(j - 1 ^ k)]);
}
}
}
}
}
}
void solve()
{
int n;
cin >> n;
int _ = 0;
while (n--)
{
int a, b;
cin >> a >> b;
int tmp = a / 10 * 8 + a % 10 * 4 + b / 10 * 2 + b % 10;
_ ^= 1 << ((15 ^ tmp));
}
cout << *min_element(dp[_].begin(), dp[_].end()) << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
cin >> tt;
init();
while (tt--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 27ms
memory: 13828kb
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: 22ms
memory: 13836kb
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: 26ms
memory: 13844kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 30ms
memory: 13792kb
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:
28 26 30 30 34 30 36 32 34 36 30 38 28 32 32 26 26 34 34 34 32 34 38 32 26 32 32 32 28 32 26 36 28 30 36 34 40 28 32 28 26 30 34 34 38 30 34 32 32 32 36 26 36 36 30 36 38 34 36 28 36 34 32 28 28 32 32 32 36 34 28 30 26 28 26 32 30 34 32 32 30 32 32 28 28 28 36 36 32 32 34 34 32 36 32 26 30 34 30 28 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '28'