Submission #977292

# Submission time Handle Problem Language Result Execution time Memory
977292 2024-05-07T16:58:45 Z mannshah1211 Diversity (CEOI21_diversity) C++17
0 / 100
442 ms 592 KB
/**
 *  author: hashman
 *  created:
**/

#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() {
  cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

using Int = long long;

Int calc(vector<int>& a) {
  Int ans = 0;
  for (int j = 0; j < a.size(); j++) {
    set<int> st;
    for (int i = j; i < a.size(); i++) {
      st.insert(a[i]);
      ans += st.size();
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    --a[i];
  } 
  vector<int> f(11);
  for (int i = 0; i < n; i++) {
    ++f[a[i]];
  }
  Int mn = 1e18;
  do {
    vector<int> now;
    for (int j = 0; j < 11; j++) {
      for (int i = 0; i < f[j]; i++) {
        now.push_back(j);
      }
    }
    mn = min(mn, calc(now));
  } while (next_permutation(f.begin(), f.end()));
  cout << mn << '\n';
}

Compilation message

diversity.cpp: In function 'Int calc(std::vector<int>&)':
diversity.cpp:58:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for (int j = 0; j < a.size(); j++) {
      |                   ~~^~~~~~~~~~
diversity.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = j; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 420 KB Output is correct
6 Incorrect 8 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 420 KB Output is correct
6 Incorrect 8 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 420 KB Output is correct
6 Incorrect 8 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -