QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#797993 | #7600. Minimums on the Edges | Cookie_Creamm | WA | 5ms | 8404kb | C++23 | 2.6kb | 2024-12-03 22:29:01 | 2024-12-03 22:29:03 |
Judging History
answer
#include<bits/stdc++.h>
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
const ll mxn = 4e5 + 5, inf = 1e9, mod = 998244353, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353;
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);
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 7760kb
input:
4 4 6 1 2 2 3 3 1 1 4
output:
2 2 2 0
result:
ok answer = 6
Test #2:
score: 0
Accepted
time: 5ms
memory: 6724kb
input:
3 7 7 1 2 1 2 1 2 1 3 1 3 2 3 2 3
output:
3 2 2
result:
ok answer = 14
Test #3:
score: -100
Wrong Answer
time: 5ms
memory: 8404kb
input:
5 10 61 5 3 1 2 4 5 2 3 2 1 3 1 1 5 3 5 2 4 2 1
output:
13 12 12 12 12
result:
wrong answer jury has the better answer: jans = 122, pans = 120