提出 #65437645


ソースコード 拡げる

#include <bits/stdc++.h>
#define ll long long
#define rep(i, x, y) for (int i = (x); i <= (y); ++i)
#define drep(i, x, y) for (int i = (x); i >= (y); --i)
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define mem(a, b) memset((a), b, sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
template <typename T> inline void cmin(T &x, T y) { if(x > y) x = y; }
template <typename T> inline void cmax(T &x, T y) { if(x < y) x = y; }
void Fin(string s) { freopen((s + ".in").c_str(), "r", stdin); }
void Fout(string s) { freopen((s + ".out").c_str(), "w", stdout); }


int main() {
	int n, m; fastio;
	cin >> n >> m;
	vector<int> c(n);
	for(int &x : c) cin >> x;
	vector<vector<int> > f(n);
	rep(i, 1, m) {
		int k; cin >> k;
		rep(j, 1, k) {
			int x; cin >> x;
			f[x - 1].pb(i - 1);
		}
	}
	vector<int> cn(m);
	ll ans = 1e11;
	function<void(int, ll)> dfs = [&](int k, ll w) {
		if(k == n) {
			for(int x : cn) {
				if(x < 2) return;
			}
			cmin(ans, w);
			return;
		}
		dfs(k + 1, w);
		for(int x : f[k]) ++cn[x];
		dfs(k + 1, w + c[k]);
		for(int x : f[k]) ++cn[x];
		dfs(k + 1, w + (c[k] << 1));
		for(int x : f[k]) cn[x] -= 2;
	};
	dfs(0, 0);
	cout << ans << '\n';
	return 0;
}

提出情報

提出日時
問題 D - Goin' to the Zoo
ユーザ AyaseSaki
言語 C++ 20 (gcc 12.2)
得点 400
コード長 1350 Byte
結果 AC
実行時間 9 ms
メモリ 3636 KiB

コンパイルエラー

Main.cpp: In function ‘void Fin(std::string)’:
Main.cpp:15:29: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void Fin(string s) { freopen((s + ".in").c_str(), "r", stdin); }
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function ‘void Fout(std::string)’:
Main.cpp:16:30: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 | void Fout(string s) { freopen((s + ".out").c_str(), "w", stdout); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 35
セット名 テストケース
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 3576 KiB
hand_02.txt AC 1 ms 3432 KiB
hand_03.txt AC 1 ms 3432 KiB
random_01.txt AC 9 ms 3444 KiB
random_02.txt AC 9 ms 3380 KiB
random_03.txt AC 4 ms 3508 KiB
random_04.txt AC 7 ms 3436 KiB
random_05.txt AC 2 ms 3500 KiB
random_06.txt AC 1 ms 3448 KiB
random_07.txt AC 7 ms 3516 KiB
random_08.txt AC 1 ms 3492 KiB
random_09.txt AC 2 ms 3408 KiB
random_10.txt AC 1 ms 3572 KiB
random_11.txt AC 7 ms 3412 KiB
random_12.txt AC 1 ms 3372 KiB
random_13.txt AC 2 ms 3504 KiB
random_14.txt AC 1 ms 3364 KiB
random_15.txt AC 5 ms 3364 KiB
random_16.txt AC 1 ms 3636 KiB
random_17.txt AC 2 ms 3568 KiB
random_18.txt AC 1 ms 3560 KiB
random_19.txt AC 1 ms 3432 KiB
random_20.txt AC 2 ms 3432 KiB
random_21.txt AC 1 ms 3504 KiB
random_22.txt AC 2 ms 3428 KiB
random_23.txt AC 1 ms 3480 KiB
random_24.txt AC 1 ms 3496 KiB
random_25.txt AC 1 ms 3400 KiB
random_26.txt AC 2 ms 3508 KiB
random_27.txt AC 1 ms 3436 KiB
random_28.txt AC 1 ms 3488 KiB
random_29.txt AC 1 ms 3408 KiB
random_30.txt AC 1 ms 3500 KiB
sample_01.txt AC 1 ms 3604 KiB
sample_02.txt AC 1 ms 3404 KiB