QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797988 | #7600. Minimums on the Edges | Cookie_Creamm | RE | 0ms | 0kb | C++23 | 3.0kb | 2024-12-03 22:27:28 | 2024-12-03 22:27:30 |
answer
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define pii pair<int, int>
#define sz(dq) (int)dq.size()
#define forr(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pll pair<ll, ll>
#define mpp make_pair
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ld long double
ifstream fin("store.inp");
ofstream fout("store.out");
const ll mxn = 4e5 + 5, inf = 1e9, mod = 998244353, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
//const int x[4] = {0, -1, 0, 1};
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
//const char dir[4] = {'D', 'U', 'R', 'L'};
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, s;
int cnt[(1 << 18)], dp[(1 << 18)][105];
pii trace[(1 << 18)][105];
int res[19];
bool ckmax(int &a, int b){
if(a < b){
a = b; return(1);
}
return(0);
}
void solve(){
cin >> n >> m >> s;
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v; --u; --v;
cnt[(1 << u) | (1 << v)] = 1;
}
for(int i = 0; i < 18; i++){
for(int j = 0; j < (1 << 18); j++){
if((j >> i) & 1){
cnt[j] += cnt[j ^ (1 << i)];
}
}
}
for(int i = 0; i < (1 << n); i++){
for(int j = 0; j <= s; j++){
dp[i][j] = -inf;
}
}
dp[0][0] = 0;
for(int i = 0; i < (1 << n); i++){
int c = __builtin_popcount(i);
for(int j = 0; j <= s; j++){
if(dp[i][j] == -inf)continue;
for(int k = 0; k < n; k++){
if(!((i >> k) & 1)){
if(ckmax(dp[i | (1 << k)][j], dp[i][j])){
trace[i | (1 << k)][j] = mpp(i, j);
}
}
}
if(j + c <= s){
if(ckmax(dp[i][j + c], dp[i][j] + cnt[i])){
trace[i][j + c] = mpp(i, j);
}
}
}
}
pii state;
int ans = -1;
for(int i = 0; i <= s; i++){
if(ckmax(ans, dp[(1 << n) - 1][i])){
state = mpp((1 << n) - 1, i);
}
}
while(state.fi != 0){
pii cool = trace[state.fi][state.se];
if(state.se != cool.se){
for(int i = 0; i < n; i++){
if((cool.fi >> i) & 1){
res[i]++; s--;
}
}
}
state = cool;
}
res[0] += s;
for(int i = 0; i < n; i++)cout << res[i] << " ";
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("ARRAY.inp", "r", stdin);
//freopen("ARRAY.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
4 4 6 1 2 2 3 3 1 1 4