QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#786914 | #9802. Light Up the Grid | hxsj | WA | 40ms | 3860kb | C++14 | 3.5kb | 2024-11-27 01:36:27 | 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];
const int mod = 1e9 + 7;
int m = (1 << 16);
vector<int> ans(m, 2e9);
//const int mod = 998244353;
vector<int> cal(int x){
vector<int> res(16, 2e9);
queue<int> q;
q.push(x);
while(!q.empty()){
int u = q.front();
q.pop();
if(res[u] == 2e9) res[u] = 0;
for(int i = 0; i < 4; i++){
int v = u;
v ^= (1 << i);
if(res[v] > res[u] + a){
res[v] = res[u] + a;
q.push(v);
}
}
int v = u;
v ^= 3;
if(res[v] > res[u] + b){
res[v] = res[u] + b;
q.push(v);
}
v = u;
v ^= 12;
if(res[v] > res[u] + b){
res[v] = res[u] + b;
q.push(v);
}
v = u;
v ^= 5;
if(res[v] > res[u] + e){
res[v] = res[u] + e;
q.push(v);
}
v = u;
v ^= 10;
if(res[v] > res[u] + e){
res[v] = res[u] + e;
q.push(v);
}
v = u;
v ^= 15;
if(res[v] > res[u] + d){
res[v] = res[u] + d;
q.push(v);
}
if(res[u] == 0) res[u] = 2e9;
}
return res;
}
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;
for(int i = 0; i < 16; i++){
vector<int> st = cal(i);
for(int j = 0; j < 16; j++){
dp[i][j] = dp[j][i] = st[j];
//cout << dp[i][j] << " ";
}
//cout << endl;
}
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: 29ms
memory: 3564kb
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: 29ms
memory: 3824kb
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: 25ms
memory: 3860kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 40ms
memory: 3800kb
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'