QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816682 | #9802. Light Up the Grid | cdd | WA | 279ms | 114616kb | C++23 | 3.4kb | 2024-12-16 16:31:06 | 2024-12-16 16:31:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef long long LL;
typedef unsigned long long uLL;
const int inf32 = 1e9;
const LL inf64 = 1e18;
const int d[10][5] = {{0, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 1, 0},
{0, 0, 0, 0, 1},
{0, 1, 1, 0, 0},
{0, 0, 0, 1, 1},
{0, 1, 0, 1, 0},
{0, 0, 1, 0, 1},
{0, 1, 1, 1, 1}};
struct node {
int cost, id, S;
};
bool operator < (node x, node y) {
return x.cost > y.cost;
}
signed main()
{
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
int T, a1, a2, a3, a4;
cin >> T >> a1 >> a2 >> a3 >> a4;
vector<vector<int>> dis(20, vector<int>(20, inf64));
for (int i = 1; i <= 17; i++) dis[i][i] = 0;
for (int i = 0; i <= 15; i++) {
vector<int> a(5, 0);
for (int j = 1; j <= 4; j++)
a[j] = i >> (j - 1) & 1;
// if (i == 17) a[1] = a[2] = a[3] = a[4] = 1;
for (int k = 1; k <= 9; k++) {
int cost = 0;
if (k <= 4) cost = a1;
else if (k <= 6) cost = a2;
else if (k <= 8) cost = a3;
else cost = a4;
int v = 0;
for (int j = 1; j <= 4; j++)
v += (a[j] ^ d[k][j]) * (1 << (j - 1));
if (v == 15) v = 16;
dis[i][v] = min(dis[i][v], cost);
// dis[i][17] = min(dis[i][17], cost);
}
}
for (int k = 0; k <= 16; k++)
for (int i = 0; i <= 16; i++)
for (int j = 0; j <= 16; j++)
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
// for (int i = 0; i <= 16; i++) {
// for (int j = 0; j <= 16; j++)
// cerr << dis[i][j] << ' ';
// cerr<<endl;
// }
vector<vector<int>> dp(20, vector<int>((1 << 18) + 5, inf64)), vis(20, vector<int>((1 << 18) + 5, 0));
priority_queue<node> q;
for (int i = 0; i <= 16; i++)
dp[i][1 << i] = 0, q.push({0, i, 1 << i});
while (!q.empty()) {
auto [cost, cur, S] = q.top();
q.pop();
if (vis[cur][S]) continue;
vis[cur][S] = 1;
for (int v = 0; v <= 16; v++) {
if (dis[cur][v] == inf64) continue;
if (dp[cur][S] + dis[cur][v] < dp[v][S | (1 << v)]) {
dp[v][S | (1 << v)] = dp[cur][S] + dis[cur][v];
q.push({dp[v][S | (1 << v)], v, S | (1 << v)});
}
}
}
for (int i = 1; i < (1 << 18); i++) {
for (int j = 0; j <= 16; j++)
if (i >> j & 1) dp[16][i ^ (1 << j)] = min(dp[16][i ^ (1 << j)], dp[16][i]);
}
while (T--) {
int n;
cin >> n;
int S = 1 << 16;
for (int i = 1; i <= n; i++) {
string str = "";
while (str == "") cin >> str;
int id = 0;
id += 1 * (str[0] ^ 48);
id += 2 * (str[1] ^ 48);
cin >> str;
id += 4 * (str[0] ^ 48);
id += 8 * (str[1] ^ 48);
S |= 1 << id;
}
cout << dp[16][S] << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 274ms
memory: 114616kb
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: 171ms
memory: 96084kb
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: 192ms
memory: 95132kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 279ms
memory: 102784kb
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:
40 38 42 42 46 36 48 38 40 46 42 50 34 37 37 38 29 44 39 40 38 44 48 42 33 42 42 38 34 39 32 46 40 42 46 46 48 34 37 34 29 42 44 44 48 35 44 42 38 42 46 29 46 46 36 46 43 44 41 38 48 39 42 40 34 44 42 42 42 40 40 40 28 34 32 44 42 39 42 37 40 44 39 38 42 34 46 40 42 44 40 46 42 46 42 33 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '40'