답안 #971057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971057 2024-04-27T21:35:32 Z imann Amusement Park (CEOI19_amusementpark) C++17
0 / 100
3000 ms 348 KB
#include <iostream>
#include <array>
#include <algorithm>

using ll = long long;

const int MAX_N = 18 + 1;
const int MOD = 998244353;

std::array<std::array<bool, MAX_N>, MAX_N> graph;
std::array<ll, (1 << MAX_N)> dp, sSize;
std::array<bool, (1 << MAX_N)> sInd;

ll solve(int n) {
  sInd.fill(true);
  for (int s = 0; s < (1 << n); ++s) {
    int c = 0;
    for (int i = 0; i < n; ++i) {
      if (s & (1 << i)) {
        for (int j = 0; j < n; ++j) {
          if (s & (1 << j)) {
            if (graph[i][j]) {
              sInd[s] = false;
            }
          }
        }
        c++;
      }
    }
    sSize[s] = c;
  }

  dp[0] = 1;
  for (int s = 1; s < (1 << n); ++s) {
    std::vector<int> ones;
    for (int i = 0; i < n; ++i) {
      if ((1 << i) & s) {
        ones.push_back(i);
      }
    }
    for (int ss = 1; ss < (1 << ones.size()); ++ss) {
      int ssI = 0;
      for (int j = 0; j < ones.size(); ++j) {
        if (ss & (1 << j)) {
          ssI += (1 << ones[j]);
        }
      }
      if (sInd[ssI]) {
        if ((sSize[ssI] % 2) == 1) {
          dp[s] = (dp[s] + dp[s - ssI] + MOD) % MOD;
        } else {
          dp[s] = (dp[s] - dp[s - ssI] + MOD) % MOD;
        }
      }
    }
  }

  return dp[(1 << n) - 1];
}

int main() {
  int c = 0;
  for (int i = 0; i < 1e10; ++i)
    c++;
  if (c < 10)
    std::cout << "salam" << std::endl;
  int n, m; std::cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b; std::cin >> a >> b; a--; b--;
    graph[a][b] = true;
    graph[b][a] = true;
  }
  std::cout << (m * solve(n) / 2) % MOD << std::endl;
}

Compilation message

amusementpark.cpp: In function 'll solve(int)':
amusementpark.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |       for (int j = 0; j < ones.size(); ++j) {
      |                       ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3060 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3060 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3060 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3060 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3060 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -