QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784872 | #9802. Light Up the Grid | lnkkerst | TL | 877ms | 14620kb | C++17 | 1.9kb | 2024-11-26 16:12:28 | 2024-11-29 22:55:23 |
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);
vector<vector<int>> ansa((1 << 16) + 1, vector<int>((1 << 4) + 1, 1e9));
function<void(int, int, int)> dfs = [&](int state, int table, int val) {
if (ansa[table][state] <= val) {
return;
}
ansa[table][state] = val;
ans[table] = min(ans[table], val);
dfs(state ^ 0b1111, table | (1 << (state ^ 0b1111)), val + a[3]);
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]);
for (int i = 0; i < 4; ++i) {
int ns = state ^ (1 << i);
int nt = table | (1 << ns);
dfs(ns, nt, val + a[0]);
}
};
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: 877ms
memory: 14452kb
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: 378ms
memory: 14432kb
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: 375ms
memory: 14620kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: 0
Accepted
time: 826ms
memory: 14600kb
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 36 42 38 40 41 36 44 34 37 37 32 29 39 39 40 38 39 44 37 29 37 37 38 34 34 32 41 34 36 41 40 44 34 37 34 29 36 39 40 42 35 39 37 38 38 41 29 40 41 36 41 43 40 41 34 42 39 37 33 34 38 38 37 42 40 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 40 38 38 40 40 37 40 38 29 36 40 36 34 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 764ms
memory: 14500kb
input:
10000 73 78 73 17 11 01 10 01 11 10 00 11 11 00 00 11 01 10 11 11 10 00 11 10 01 01 00 6 00 00 10 11 11 10 01 01 11 01 11 00 7 01 11 01 00 10 00 10 11 10 10 00 00 01 01 10 10 01 10 10 00 10 10 11 10 00 01 01 01 10 11 11 11 00 00 01 10 11 11 01 11 10 10 01 01 00 01 ...
output:
523 382 287 579 523 596 343 275 343 472 382 343 455 326 433 360 579 545 506 523 326 528 467 382 438 421 377 460 416 579 489 596 309 326 326 596 438 387 506 562 523 377 416 309 523 348 365 343 416 392 343 399 348 506 421 596 450 426 579 370 506 185 489 377 489 387 416 472 314 489 506 450 421 433 416 ...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 862ms
memory: 14552kb
input:
10000 701 328 455 703 7 10 11 00 01 00 11 00 10 01 00 11 11 11 00 7 00 01 01 00 00 11 11 11 00 00 11 10 11 01 6 01 10 01 01 00 01 00 11 10 01 11 00 8 00 11 10 11 00 10 00 01 11 10 01 01 10 10 11 00 5 00 11 10 11 11 00 01 10 01 00 7 00 01 10 10 11 01 00 10 10 00 11 11...
output:
3124 3124 2595 4153 2595 3177 3907 2796 4235 3833 3296 2595 4809 3579 3579 3050 3169 3907 3907 3251 3169 2714 2595 3050 3251 3542 2796 3251 4563 3251 3452 3907 3251 3251 4034 4034 1730 2140 3087 4153 3907 3907 4727 4809 2923 3497 3579 3431 3251 4235 2267 4354 2595 4153 3169 4727 3087 4235 3579 2595 ...
result:
ok 10000 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
10000 6459 225 8979 7226 16 00 11 11 01 10 01 10 10 00 01 01 11 11 00 11 11 00 10 11 10 01 01 01 00 01 10 10 00 00 00 10 11 16 10 00 11 10 01 10 11 11 00 01 00 00 01 00 01 11 01 01 10 01 00 10 10 10 00 11 11 01 10 11 11 00 16 10 11 01 11 10 00 10 10 01 00 11 11 01...