QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#800951 | #9802. Light Up the Grid | ucup-team135# | WA | 24ms | 11856kb | C++20 | 2.7kb | 2024-12-06 17:15:55 | 2024-12-06 17:15:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}}
int inv(int x) {return po(x,p-2);}
mt19937 rnd;
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#define debugv(v) do {cout<< #v <<" : {"; for(int izxc=0;izxc<v.size();++izxc) {cout << v[izxc];if(izxc+1!=v.size()) cout << ","; }cout <<"}"<< endl;} while(0)
#else
#define debug(...)
#define debugv(v)
#endif
#define lob(a,x) lower_bound(all(a),x)
#define upb(a,x) upper_bound(all(a),x)
template<typename T>
using pqg = priority_queue<T,vector<T>, greater<>>;
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;cin>>t;
int a, b, c, d;
cin >> a >> b >> c >> d;
vector<int> xo(16, 1e18);
xo[0] = 0;
vector<pair<int, int>> e{{a, 1}, {a, 2}, {a, 4}, {a, 8}, {b, 1 + 2}, {b, 4 + 8}, {c, 1 + 4}, {c, 2 + 8}, {d, 15}};
pqg<pair<int, int>> dijkstra;
dijkstra.push({0, 0});
while (!dijkstra.empty()) {
auto [d, mask] = dijkstra.top();
dijkstra.pop();
if (d != xo[mask]) continue;
for (auto [w, msk] : e) {
if (xo[mask ^ msk] > xo[mask] + w) {
xo[mask ^ msk] = xo[mask] + w;
dijkstra.push({xo[mask ^ msk], mask ^ msk});
}
}
}
debugv(xo);
vector<vector<int>> dp(16, vector<int>(1 << 16, 2e18));
for (int i = 0; i < 16; ++i) {
dp[i][1 << i] = xo[i];
if (xo[i] == 0) dp[i][1 << i] = 2;
}
for (int mask = 0; mask < (1 << 16); ++mask) {
if (__builtin_popcount(mask) < 1) continue;
for (int bit = 0; bit < 16; ++bit) {
if (mask & (1 << bit)) continue;
for (int last = 0; last < 16; ++last) {
if (mask & (1 << last))
dp[bit][mask ^ (1 << bit)] = min(dp[bit][mask ^ (1 << bit)], dp[last][mask] + xo[last ^ bit]);
}
}
}
for (int j = 0; j < t; ++j) {
int m;
cin >> m;
int init = 0;
for (int t = 0; t < m; ++t) {
int ma = 0;
for (int i = 0; i < 4; ++i) {
char c;
cin >> c;
ma = (ma * 2 + (c - '0'));
}
ma ^= 15;
init |= (1 << ma);
}
debug(init);
int ans = 2e18;
for (int i = 0; i < 16; ++i) ans = min(ans, dp[i][init]);
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 21ms
memory: 11856kb
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: 21ms
memory: 11792kb
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: -100
Wrong Answer
time: 24ms
memory: 11764kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2
result:
wrong answer 1st numbers differ - expected: '2000000', found: '2'