Submission #456865

# Submission time Handle Problem Language Result Execution time Memory
456865 2021-08-07T03:01:00 Z ntabc05101 Vještica (COCI16_vjestica) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

#define taskname ""

int main() {
  if (fopen(taskname".inp", "r")) {
    freopen(taskname".inp", "r", stdin);
    freopen(taskname".out", "w", stdout);
  }

  cin.tie(0)->sync_with_stdio(0);

  int n; cin >> n;
  int c[n][26];
  memset(c, 0, sizeof(c));
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (auto& _: s) {
      c[i][_ - 'a']++;
    }
  }

  const int full_bit = 1 << n;

  int dp[full_bit];
  dp[0] = 0;
  for (int msk = 1; msk < full_bit; msk++) {
    int n_node = 0;
    vector<int> _min(26, mod);
    for (int i = 0; i < n; i++) {
      if (msk >> i & 1) {
        for (int j = 0; j < 26; j++) {
          _min[j] = min(_min[j], c[i][j]);
        }
      }
    }
    for (int i = 0; i < 26; i++) {
      n_node += _min[i];
    }

    if ((msk & -msk) == msk) {
      dp[msk] = n_node;
    }
    else {
      dp[msk] = mod;
      for (int _msk = (msk - 1) & msk; _msk; _msk = (_msk - 1) & msk) {
        dp[msk] = min(dp[msk], dp[_msk] + dp[msk ^ _msk] - n_node);
      }
    }
  }

  //cout << dp[2] << "\n";
  cout << dp[full_bit - 1] + 1 << endl;

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

const int mod = 1e9 + 7;

#define taskname ""

int main() {
  if (fopen(taskname".inp", "r")) {
    freopen(taskname".inp", "r", stdin);
    freopen(taskname".out", "w", stdout);
  }

  cin.tie(0)->sync_with_stdio(0);

  int n; cin >> n;
  int c[n][26];
  memset(c, 0, sizeof(c));
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (auto& _: s) {
      c[i][_ - 'a']++;
    }
  }

  const int full_bit = 1 << n;

  int dp[full_bit];
  dp[0] = 0;
  for (int msk = 1; msk < full_bit; msk++) {
    int n_node = 0;
    vector<int> _min(26, mod);
    for (int i = 0; i < n; i++) {
      if (msk >> i & 1) {
        for (int j = 0; j < 26; j++) {
          _min[j] = min(_min[j], c[i][j]);
        }
      }
    }
    for (int i = 0; i < 26; i++) {
      n_node += _min[i];
    }

    if ((msk & -msk) == msk) {
      dp[msk] = n_node;
    }
    else {
      dp[msk] = mod;
      for (int _msk = (msk - 1) & msk; _msk; _msk = (_msk - 1) & msk) {
        dp[msk] = min(dp[msk], dp[_msk] + dp[msk ^ _msk] - n_node);
      }
    }
  }

  //cout << dp[2] << "\n";
  cout << dp[full_bit - 1] + 1 << endl;

  return 0;
}

Compilation message

vjestica.cpp:64:11: error: redefinition of 'const int mod'
   64 | const int mod = 1e9 + 7;
      |           ^~~
vjestica.cpp:4:11: note: 'const int mod' previously defined here
    4 | const int mod = 1e9 + 7;
      |           ^~~
vjestica.cpp:68:5: error: redefinition of 'int main()'
   68 | int main() {
      |     ^~~~
vjestica.cpp:8:5: note: 'int main()' previously defined here
    8 | int main() {
      |     ^~~~
vjestica.cpp: In function 'int main()':
vjestica.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen(taskname".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vjestica.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     freopen(taskname".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vjestica.cpp: In function 'int main()':
vjestica.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen(taskname".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vjestica.cpp:71:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     freopen(taskname".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~