답안 #1054032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054032 2024-08-12T05:08:49 Z sleepntsheep Diversity (CEOI21_diversity) C++17
0 / 100
0 ms 2396 KB
#include <cstdio>
#include <algorithm>
#define N 300001
#define A 300001

int o, n, q, a[N], fr[N], fr2[N];
long long z, y;

long long c2(int x) { return (x - 1ll) * x / 2; }

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i), ++fr[a[i]];

  for (int i = 1; i <= 300000; ++i)
    ++fr2[fr[i]];

  int sum = 0;
  for (int i = 1; i <= n; ++i)
    for (; fr2[i]--; )
      a[++o] = i, sum += i;

  for (int i = 1; i <= o; ++i) {
    int psum = 0;
    for (int j = 1; j + 1 <= o; psum += a[j++]) {
      int x = psum;
      int y = sum - psum - a[j] - a[j + 1];
      int a_ = a[j];
      int b_ = a[j + 1];
      if (-c2(b_ + y + 1) -c2(a_ + x + 1) > -c2(b_ + x + 1) - c2(a_ + y + 1))
        std::swap(a[j], a[j + 1]);
    }
  }

  int psum = 0;
  for (int i = 1; i <= o; psum += a[i++]) {
    z += c2(n + 1) - c2(psum + 1) - c2(sum - psum - a[i] + 1);
  }


  printf("%lld", z);

}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d%d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~
diversity.cpp:13:37: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   for (int i = 1; i <= n; ++i) scanf("%d", a + i), ++fr[a[i]];
      |                                ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 0 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -