QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#782633 | #9802. Light Up the Grid | susanzhishen# | WA | 24ms | 9796kb | C++20 | 4.8kb | 2024-11-25 20:47:10 | 2024-11-25 20:47:11 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> PII;
const int N=3e5+10;
const int M=1e3+10;
int mod=1e9+7;
int a[N];
int mp[N];
int mp2[N];
void solve(){
int T, a0, a1, a2, a3;
cin >> T >> a0 >> a1 >> a2 >> a3;
memset(mp, -1, sizeof(mp));
mp[0] = 0, mp[3] = 1, mp[5] = 2, mp[6] = 3, mp[9] = 4, mp[10] = 5, mp[12] = 6, mp[15] = 7;
mp2[0] = 0, mp2[1] = 3, mp2[2] = 5, mp2[3] = 6, mp2[4] = 9, mp2[5] = 10, mp2[6] = 12, mp2[7] = 15;
const int M = 8, inf = 1e18;
vector f(M, inf);
a1 = min(a1, a0 * 2);
a2 = min(a2, a0 * 2);
a3 = min({a3, a0 * 4, a1 * 2, a2 * 2});
f[0] = a3, f[1] = a1, f[2] = a2, f[3] = min(2 * a0, a1 + a2);
f[4] = min(2 * a0, a1 + a2), f[5] = a2, f[6] = a1, f[7] = 0;
vector dp(1 << M, vector<int>(M, inf));
auto dfs = [&](auto self, int mask, int las, int cost) -> void {
if(las != -1) {
if(dp[mask][las] < cost) return;
dp[mask][las] = cost;
}
for(int i = 0; i < M; i ++ ) {
if(~mask >> i & 1) {
if(las == -1) {
self(self, mask ^ (1 << i), i, f[i]);
} else {
int ch = mp2[las];
int chage = 0;
for(int j = 0; j < 4; j ++ ) {
if(~ch >> j & 1) {
chage |= (1 << j);
}
}
int now = mp2[i] ^ chage;
// assert(now >= 0 && now < M);
self(self, mask ^ (1 << i), i, cost + f[mp[now]]);
}
}
}
};
dfs(dfs, 0, -1, 0);
while(T -- ) {
int m;
cin >> m;
vector<int> x1, x2;
int cur = 0;
for(int o = 0; o < m; o ++ ) {
string s, t;
cin >> s >> t;
s += t;
int cnt = 0;
for(int j = 0; j < 4; j ++ ) {
if(s[j] == '1') {
cnt ++;
}
}
int nw = 0;
for(int j = 0; j < 4; j ++ ) {
if(s[j] == '1') {
nw |= (1 << (3 - j));
}
}
if(nw == 15) {
cur += 2 * min({a0, a1, a2, a3});
}
if(cnt & 1) {
x2.push_back(nw);
} else {
x1.push_back(mp[nw]);
}
}
int mask = 0;
for(auto x: x1) {
mask |= (1 << x);
}
int ans = inf;
if(x1.empty()) {
for(int j = 0; j < 4; j ++ ) {
vector<int> x3;
int sum = a0 + cur;
for(auto y: x2) {
int now = y ^ (1 << j);
x3.emplace_back(mp[now]);
}
int mask2 = 0;
for(auto y: x3) {
mask2 |= (1 << y);
}
for(auto y: x3) {
ans = min(ans, dp[mask2][y] + sum);
}
}
} else {
for(auto x: x1) {
int sum = dp[mask][x] + cur;
if(x2.empty()) {
ans = min(ans, sum);
}
for(int j = 0; j < 4; j ++ ) {
vector<int> x3;
sum += a0;
for(auto y: x2) {
int ch = mp2[x];
int chage = 0;
for(int k = 0; k < 4; k ++ ) {
if(~ch >> k & 1) {
chage |= (1 << k);
}
}
int now = y ^ chage ^ (1 << j);
x3.emplace_back(mp[now]);
}
int mask2 = 0;
for(auto y: x3) {
mask2 |= (1 << y);
}
for(auto y: x3) {
// cout << y << " " << sum << " " << dp[mask2][y] << "\n";
ans = min(ans, dp[mask2][y] + sum);
}
sum -= a0;
}
}
}
cout << ans << "\n";
}
}
/*
2 1000 100 10 1
4
10
00
01
00
00
10
00
01
1
11
11
*/
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int _;
_=1;
//cin>>_;
// freopen("in.txt", "r", stdin);
// freopen("std.txt", "w", stdout);
while(_--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7676kb
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: 2ms
memory: 9796kb
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: 2ms
memory: 7936kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 24ms
memory: 7732kb
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 34 38 38 44 36 46 38 40 42 38 46 34 38 38 36 29 40 40 40 38 40 44 38 29 38 38 38 34 35 32 42 38 40 42 44 46 34 38 34 29 40 40 40 48 36 40 38 38 38 42 29 42 42 36 42 44 40 42 34 44 40 38 38 34 40 38 38 42 40 38 36 29 34 32 42 38 40 38 38 36 40 35 34 36 34 42 42 38 40 40 44 38 42 38 29 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '36'