QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293807 | #7600. Minimums on the Edges | ship2077 | RE | 11ms | 108016kb | C++14 | 1.2kb | 2023-12-29 19:35:05 | 2023-12-29 19:35:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=18,M=1<<18;
int n,m,k,lim,low,ans[N],f[N][M],g[M],dp[M][101],tmp1[M];
pair<int,int>pre[N][101],tmp2[M];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
int main(){
n=read();m=read();k=read();lim=1<<n;
for (int i=1;i<=m;i++){int x,y;
x=read()-1;y=read()-1;
f[x][1<<y]++;f[y][1<<x]++;
}
for (int i=0;i<n;i++)
for (int s=1;s<lim;s++)
f[i][s]=f[i][s^(s&-s)]+f[i][s&-s];
for (int s=0;s<lim;s++)
low=s&-s,g[s]=g[s^low]+f[__lg(low)][s];
memset(dp,-0x3f,sizeof(dp));dp[0][0]=0;
for (int s=0;s<lim;s++){
int siz=__builtin_popcount(s);
for (int i=siz;i<=k;i++)
if (dp[s][i-siz]+g[s]>dp[s][i])
dp[s][i]=dp[s][i-siz]+g[s],pre[s][i]={s,i-siz};
for (int i=0;i<n;i++)
if (~s>>i&1)
for (int j=0;j<=k;j++)
if (dp[s][j]>dp[s^1<<i][j])
dp[s^1<<i][j]=dp[s][j],pre[s^1<<i][j]={s,j};
} pair<int,int>nxt;
for (int i=1,t=lim-1,j=k;j;i++,t=nxt.first,j=nxt.second){
nxt=pre[t][j];
if (nxt.second!=j)
for (int i=0;i<n;i++)
if (t>>i&1) ans[i]++;
}
for (int i=0;i<n;i++) printf("%d ",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 107084kb
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: 4ms
memory: 107172kb
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: 0
Accepted
time: 0ms
memory: 107080kb
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:
15 15 15 1 15
result:
ok answer = 122
Test #4:
score: 0
Accepted
time: 3ms
memory: 107100kb
input:
5 10 6 1 4 3 4 4 3 1 4 5 1 4 3 3 2 1 3 5 2 2 3
output:
2 0 2 2 0
result:
ok answer = 12
Test #5:
score: 0
Accepted
time: 3ms
memory: 107084kb
input:
5 10 85 3 1 4 5 4 1 4 5 1 5 2 3 4 5 1 4 3 2 2 3
output:
27 2 2 27 27
result:
ok answer = 170
Test #6:
score: 0
Accepted
time: 11ms
memory: 107168kb
input:
5 10 30 2 5 2 4 4 5 4 3 5 1 4 3 2 3 1 5 1 4 2 1
output:
6 6 6 6 6
result:
ok answer = 60
Test #7:
score: 0
Accepted
time: 8ms
memory: 107104kb
input:
5 10 77 1 3 4 1 4 3 5 2 5 2 2 5 2 3 3 4 5 3 5 2
output:
0 38 1 0 38
result:
ok answer = 154
Test #8:
score: 0
Accepted
time: 3ms
memory: 107928kb
input:
10 10000 4 5 3 6 1 7 8 2 10 3 6 7 5 6 8 1 5 6 5 10 8 1 9 4 5 2 10 8 10 8 6 6 4 3 4 7 9 1 3 10 7 1 10 4 10 1 10 7 6 3 7 10 5 3 7 1 6 1 9 4 5 8 9 5 9 9 5 6 2 8 10 4 3 3 5 6 8 6 10 5 2 9 6 7 8 8 5 4 10 6 2 1 4 4 2 3 2 1 4 8 1 5 2 1 7 1 5 1 2 6 2 5 6 6 9 1 6 10 5 4 1 4 10 7 2 3 5 3 10 5 2 4 8 2 4 10 1 5...
output:
0 0 0 0 1 1 1 1 0 0
result:
ok answer = 1415
Test #9:
score: 0
Accepted
time: 0ms
memory: 107940kb
input:
10 10000 83 7 9 6 4 3 6 7 5 2 5 10 7 10 7 7 10 6 5 3 9 2 6 9 10 8 2 6 2 10 1 3 9 4 2 9 5 2 10 6 3 10 5 5 9 6 2 1 4 8 9 7 6 2 5 7 8 10 4 2 1 2 9 7 10 2 7 2 5 9 10 10 8 4 1 10 8 2 5 3 10 6 7 6 3 5 8 10 2 6 10 6 3 9 5 6 2 8 5 8 2 8 10 2 8 5 10 5 2 10 3 8 6 3 1 3 2 8 7 3 7 8 2 9 7 5 9 5 3 7 5 2 6 6 9 8 ...
output:
8 8 8 8 8 8 9 8 9 9
result:
ok answer = 80726
Test #10:
score: 0
Accepted
time: 0ms
memory: 107936kb
input:
10 10000 28 8 3 7 5 10 9 6 2 1 9 4 7 4 7 7 1 10 6 10 5 5 3 8 3 3 1 3 1 8 1 4 7 5 6 4 10 3 2 4 8 2 4 9 7 8 7 10 9 9 10 2 1 6 1 7 1 2 8 5 10 1 4 5 8 1 3 8 3 4 3 9 2 5 1 4 6 10 1 10 2 5 4 9 3 10 2 5 9 2 1 7 4 1 8 4 8 3 9 9 6 3 6 5 1 2 7 4 3 2 8 8 10 1 7 4 1 3 9 1 2 1 9 8 4 9 5 1 5 6 4 1 6 6 7 2 7 10 4 ...
output:
3 3 3 2 3 2 3 3 3 3
result:
ok answer = 26312
Test #11:
score: 0
Accepted
time: 7ms
memory: 108016kb
input:
10 10000 6 9 7 10 4 7 4 6 8 9 4 10 9 9 3 5 7 7 9 9 1 7 3 5 2 3 4 1 9 9 2 1 3 5 3 3 6 10 9 10 5 10 2 3 9 6 4 6 8 1 5 7 10 4 8 7 8 7 1 8 6 5 1 8 7 3 6 6 2 10 5 5 2 10 4 8 6 7 8 8 7 9 2 7 8 4 9 9 6 8 2 1 3 7 4 8 6 1 7 4 3 1 6 8 2 6 9 4 10 2 5 3 5 8 1 8 7 8 6 8 10 9 8 4 10 1 10 2 10 7 8 1 6 6 8 8 10 1 1...
output:
1 0 1 1 0 0 1 0 1 1
result:
ok answer = 3460
Test #12:
score: 0
Accepted
time: 0ms
memory: 107936kb
input:
10 10000 19 1 3 6 7 4 5 9 8 5 8 1 9 10 7 10 6 2 9 2 5 2 4 2 3 3 2 9 3 3 9 7 10 7 8 7 1 8 6 8 9 1 5 2 5 4 6 2 10 8 9 8 2 6 7 9 10 1 2 3 10 5 6 8 5 5 9 3 4 4 10 5 3 8 9 6 1 4 2 2 5 2 9 2 10 1 9 9 4 10 2 8 4 9 1 7 8 1 2 6 10 8 2 8 10 5 4 10 9 7 2 3 2 6 8 5 4 8 9 8 10 6 8 10 4 7 3 3 5 9 8 6 7 5 3 5 8 2 ...
output:
2 2 2 2 2 2 2 2 1 2
result:
ok answer = 18048
Test #13:
score: -100
Runtime Error
input:
18 15 22 8 17 13 14 5 15 2 17 18 1 17 10 1 5 6 18 1 6 11 2 15 17 2 13 4 3 1 10 16 14