QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#786935 | #9802. Light Up the Grid | hxsj | WA | 58ms | 3828kb | C++14 | 3.0kb | 2024-11-27 02:10:48 | 2024-11-29 22:56:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
//using i128 = __int128;
#define sz(a) (int)(a.size())
#define rep(x,a,b) for(int x = a; x < b; x++)
#define all(a) a.begin(), a.end()
#define uni(a) a.resize(unique(all(a)) - a.begin())
#define maxe(a) max_element(all(a))
#define mine(a) min_element(all(a))
#define lb(b,val) lower_bound(b.begin(), b.end(), val) - b.begin()
#define ub(b,val) upper_bound(b.begin(), b.end(), val) - b.begin()
#define fd(b,val) find(all(b), val) - b.begin()
#define ct(b,val) count(all(b), val)
#define bp(s) __builtin_popcountll(s)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define sp setprecision
int a, b, e, d;
int dp[20][20];
int op[18] = {1, 2, 4, 8, 3, 12, 5, 10, 15, 1, 2, 4, 8, 3, 12, 5, 10, 15};
int cost[18];
const int mod = 1e9 + 7;
int m = (1 << 16);
vector<int> ans(m, 2e9);
void solve(){
int n;
cin >> n;
string s;
string t = "";
rep(i, 1, n + 1){
cin >> s;
t += s;
cin >> s;
t += s;
if(i != n) getline(cin, s);
}
vector<int> bb;
for(int i = 0; i < t.size(); i += 4){
int st = 0;
if(t[i] == '1') st += 8;
if(t[i + 1] == '1') st += 4;
if(t[i + 2] == '1') st += 2;
if(t[i + 3] == '1') st += 1;
bb.pb(st);
}
sort(all(bb));
uni(bb);
int st = 0;
for(auto x : bb) st += (1 << x);
cout << ans[st] << endl;
}
signed main(){
int _ = 1;
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin >> _ >> a >> b >> e >> d;
cost[0] = a;
cost[1] = a;
cost[2] = a;
cost[3] = a;
cost[4] = b;
cost[5] = b;
cost[6] = e;
cost[7] = e;
cost[8] = d;
cost[9] = a;
cost[10] = a;
cost[11] = a;
cost[12] = a;
cost[13] = b;
cost[14] = b;
cost[15] = e;
cost[16] = e;
cost[17] = d;
for(int i = 0; i < 16; i++){
for(int j = 0; j < 16; j++){
dp[i][j] = 2e9;
}
}
for(int i = 1; i < (1 << 18); i++){
int st = 0;
int cnt = 0;
for(int j = 0; j < 18; j++){
if(i >> j & 1){
st ^= op[j];
cnt += cost[j];
}
}
for(int j = 0; j < 16; j++){
dp[j][j ^ st] = dp[j ^ st][j] = min(dp[j][j ^ st], cnt);
}
}
for(int j = 0; j < 16; j++) ans[1 << j] = dp[j][15];
for(int i = 0; i < m; i++){
for(int j = 0; j < 16; j++){
if(i >> j & 1){
for(int k = 0; k < 16; k++){
if(k == j) continue;
if(i >> k & 1){
ans[i] = min(ans[i], ans[i - (1 << j)] + dp[15][j ^ 15 ^ k]);
}
}
}
}
}
while(_--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 47ms
memory: 3596kb
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: 47ms
memory: 3616kb
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: 47ms
memory: 3828kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 58ms
memory: 3760kb
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 38 36 42 38 40 38 36 44 34 34 36 32 29 36 38 40 36 38 42 36 27 34 36 36 32 33 32 40 34 36 38 40 42 34 36 32 29 36 38 40 40 35 39 36 38 36 40 29 38 40 36 38 42 40 40 34 41 38 34 32 34 38 36 36 40 38 34 34 27 34 32 38 36 38 36 36 36 36 31 34 34 34 38 38 38 38 40 40 36 36 36 27 34 38 36 34 ...
result:
wrong answer 5th numbers differ - expected: '40', found: '38'