提出 #65483104


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
  // 入力を受け取る
  int N, M;
  cin >> N >> M;
  vector<ll> C(N), K(M);
  vector<vector<int>> A(M);
  for(int i = 0; i < N; i++) {
    cin >> C[i];
  }
  for(int i = 0; i < M; i++) {
    cin >> K[i];
    A[i].resize(K[i]);
    for(int j = 0; j < K[i]; j++) {
      cin >> A[i][j];
    }
  }

  // can_see[i] := (動物園 i で見ることができる動物のリスト)
  vector<vector<int>> can_see(N);
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < K[i]; j++) {
      can_see[A[i][j] - 1].push_back(i);
    }
  }

  // 0, 1, 2 からなる長さ N 以下の列を探索する
  // v := (長さがちょうど N の列を列挙したもの)
  vector<vector<int>> v;
  auto dfs = [&](auto dfs, vector<int> X) -> void {
    if(X.size() == N) {
      v.push_back(X);
    }else {
      for(int x = 0; x <= 2; x++) {
        X.push_back(x);
        dfs(dfs, X);
        X.pop_back();
      }
    }
  };
  dfs(dfs, vector<int>());

  // 答えを計算する
  // cnt_vis[i] := (動物園 i を訪れた回数)
  // cnt_see[i] := (動物 i を見た回数)
  ll ans = 2'000'000'000'0;
  for(vector<int> cnt_vis : v) {
    ll cost = 0;
    vector<int> cnt_see(M);
    for(int i = 0; i < N; i++) {
      cost += C[i] * cnt_vis[i];
      for(int animal : can_see[i]) {
        cnt_see[animal] += cnt_vis[i];
      }
    }
    bool ok = true;
    for(int i = 0; i < M; i++) {
      if(cnt_see[i] < 2) ok = false;
    }
    if(ok) ans = min(ans, cost);
  }

  cout << ans << endl;
}

提出情報

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

コンパイルエラー

Main.cpp: In instantiation of ‘main()::<lambda(auto:53, std::vector<int>)> [with auto:53 = main()::<lambda(auto:53, std::vector<int>)>]’:
Main.cpp:45:6:   required from here
Main.cpp:35:17: warning: comparison of integer expressions of different signedness: ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
   35 |     if(X.size() == N) {
      |        ~~~~~~~~~^~~~

ジャッジ結果

セット名 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 3644 KiB
hand_02.txt AC 1 ms 3552 KiB
hand_03.txt AC 1 ms 3476 KiB
random_01.txt AC 45 ms 7508 KiB
random_02.txt AC 45 ms 7412 KiB
random_03.txt AC 25 ms 7456 KiB
random_04.txt AC 29 ms 7476 KiB
random_05.txt AC 9 ms 7392 KiB
random_06.txt AC 4 ms 4648 KiB
random_07.txt AC 30 ms 7468 KiB
random_08.txt AC 1 ms 3744 KiB
random_09.txt AC 9 ms 7624 KiB
random_10.txt AC 1 ms 3652 KiB
random_11.txt AC 29 ms 7552 KiB
random_12.txt AC 1 ms 3524 KiB
random_13.txt AC 10 ms 7400 KiB
random_14.txt AC 1 ms 3608 KiB
random_15.txt AC 34 ms 7508 KiB
random_16.txt AC 1 ms 3564 KiB
random_17.txt AC 11 ms 7620 KiB
random_18.txt AC 1 ms 3508 KiB
random_19.txt AC 9 ms 7368 KiB
random_20.txt AC 12 ms 7400 KiB
random_21.txt AC 1 ms 3684 KiB
random_22.txt AC 10 ms 7452 KiB
random_23.txt AC 1 ms 3696 KiB
random_24.txt AC 4 ms 4676 KiB
random_25.txt AC 1 ms 3736 KiB
random_26.txt AC 10 ms 7440 KiB
random_27.txt AC 1 ms 3688 KiB
random_28.txt AC 2 ms 3808 KiB
random_29.txt AC 2 ms 3852 KiB
random_30.txt AC 3 ms 4560 KiB
sample_01.txt AC 1 ms 3632 KiB
sample_02.txt AC 1 ms 3744 KiB