提出 #65457162
ソースコード 拡げる
#include<bits/stdc++.h>
#define fi first
#define se second
#define mkp(x,y) make_pair(x,y)
#define lsb(x) (x&(-x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD=1e9;
ll n,m,ans,c[20],k[109],a[20][109],cnt[20],sum[209];
void dfs(ll id){
if(id==n+1){
ll res=0;
for(ll i=1;i<=m;i++) sum[i]=0;
for(ll i=1;i<=n;i++){
res+=c[i]*cnt[i];
if(cnt[i])
for(ll j=1;j<=m;j++)if(a[i][j]) sum[j]+=cnt[i];
}
bool flag=1;
for(ll i=1;i<=m;i++) if(sum[i]<2){
flag=0;
break;
}
if(flag) ans=min(ans,res);
return;
}
cnt[id]=0;
dfs(id+1);
cnt[id]=1;
dfs(id+1);
cnt[id]=2;
dfs(id+1);
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
scanf("%lld%lld",&n,&m);
for(ll i=1;i<=n;i++)
scanf("%lld",&c[i]);
for(ll i=1;i<=m;i++){
scanf("%lld",&k[i]);
for(ll j=1;j<=k[i];j++){
ll v;
scanf("%lld",&v);
a[v][i]=1;
}
}
ans=1e15;
dfs(1);
if(ans==1e15) printf("-1");
else printf("%lld",ans);
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
D - Goin' to the Zoo |
| ユーザ |
wangaz |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
400 |
| コード長 |
1052 Byte |
| 結果 |
AC |
| 実行時間 |
33 ms |
| メモリ |
3920 KiB |
コンパイルエラー
Main.cpp: In function ‘int main()’:
Main.cpp:38:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%lld%lld",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
40 | scanf("%lld",&c[i]);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%lld",&k[i]);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:45:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%lld",&v);
| ~~~~~^~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
400 / 400 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt |
| All |
hand_01.txt, hand_02.txt, hand_03.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| hand_01.txt |
AC |
1 ms |
3616 KiB |
| hand_02.txt |
AC |
1 ms |
3844 KiB |
| hand_03.txt |
AC |
1 ms |
3664 KiB |
| random_01.txt |
AC |
28 ms |
3860 KiB |
| random_02.txt |
AC |
28 ms |
3784 KiB |
| random_03.txt |
AC |
32 ms |
3920 KiB |
| random_04.txt |
AC |
33 ms |
3692 KiB |
| random_05.txt |
AC |
4 ms |
3908 KiB |
| random_06.txt |
AC |
2 ms |
3652 KiB |
| random_07.txt |
AC |
31 ms |
3908 KiB |
| random_08.txt |
AC |
1 ms |
3760 KiB |
| random_09.txt |
AC |
3 ms |
3776 KiB |
| random_10.txt |
AC |
1 ms |
3776 KiB |
| random_11.txt |
AC |
31 ms |
3708 KiB |
| random_12.txt |
AC |
1 ms |
3780 KiB |
| random_13.txt |
AC |
5 ms |
3580 KiB |
| random_14.txt |
AC |
1 ms |
3852 KiB |
| random_15.txt |
AC |
33 ms |
3572 KiB |
| random_16.txt |
AC |
1 ms |
3704 KiB |
| random_17.txt |
AC |
5 ms |
3672 KiB |
| random_18.txt |
AC |
1 ms |
3708 KiB |
| random_19.txt |
AC |
5 ms |
3664 KiB |
| random_20.txt |
AC |
4 ms |
3784 KiB |
| random_21.txt |
AC |
1 ms |
3616 KiB |
| random_22.txt |
AC |
4 ms |
3764 KiB |
| random_23.txt |
AC |
1 ms |
3916 KiB |
| random_24.txt |
AC |
2 ms |
3904 KiB |
| random_25.txt |
AC |
1 ms |
3848 KiB |
| random_26.txt |
AC |
5 ms |
3852 KiB |
| random_27.txt |
AC |
1 ms |
3784 KiB |
| random_28.txt |
AC |
1 ms |
3792 KiB |
| random_29.txt |
AC |
1 ms |
3656 KiB |
| random_30.txt |
AC |
2 ms |
3688 KiB |
| sample_01.txt |
AC |
1 ms |
3668 KiB |
| sample_02.txt |
AC |
1 ms |
3920 KiB |