답안 #696473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696473 2023-02-06T15:15:33 Z cig32 Diversity (CEOI21_diversity) C++17
38 / 100
7000 ms 5152 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
void solve(int tc) {
  int n, q;
  cin >> n >> q;
  int c = 300000;
  int freq[c+1];
  for(int i=1; i<=c; i++) freq[i] = 0;
  for(int i=1; i<=n; i++) {
    int x;cin >> x;freq[x]++;
  }
  sort(freq+1, freq+c+1);
  int a[n+1];
  int l=1,r=n,ct=0;
  deque<int> dq;
  stack<int> y; queue<int> x;
  for(int i=1;i<=c; i++) {
    if(freq[i]>0) {
      if(ct&1) {
        y.push(freq[i]);
      }
      else {
        x.push(freq[i]);
      }
      ct^=1;
    }
  }
  while(x.size()) {
    dq.push_back(x.front()); x.pop();
  }
  while(y.size()) {
    dq.push_back(y.top()); y.pop();
  }
  int m=dq.size();
  int ans=0;
  for(int i=0;i<m; i++){
    for(int j=i; j<m; j++) {
      int li = dq[i], lj = dq[j];
      if(i == j) {
        ans += li * (li + 1) / 2;
      }
      else {
        ans += li * lj * (j-i+1);
      }
    }
  }
  cout << ans << "\n";

}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}

Compilation message

diversity.cpp: In function 'void solve(long long int)':
diversity.cpp:33:7: warning: unused variable 'a' [-Wunused-variable]
   33 |   int a[n+1];
      |       ^
diversity.cpp:34:7: warning: unused variable 'l' [-Wunused-variable]
   34 |   int l=1,r=n,ct=0;
      |       ^
diversity.cpp:34:11: warning: unused variable 'r' [-Wunused-variable]
   34 |   int l=1,r=n,ct=0;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 5 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 5 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 5 ms 2644 KB Output is correct
8 Correct 5 ms 2644 KB Output is correct
9 Correct 4 ms 2632 KB Output is correct
10 Correct 8 ms 2632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 5 ms 2672 KB Output is correct
3 Correct 6 ms 2696 KB Output is correct
4 Correct 8 ms 2872 KB Output is correct
5 Correct 15 ms 3048 KB Output is correct
6 Correct 19 ms 3296 KB Output is correct
7 Correct 20 ms 3284 KB Output is correct
8 Correct 17 ms 3300 KB Output is correct
9 Correct 18 ms 3284 KB Output is correct
10 Correct 18 ms 3284 KB Output is correct
11 Correct 18 ms 3288 KB Output is correct
12 Correct 18 ms 3340 KB Output is correct
13 Correct 18 ms 3324 KB Output is correct
14 Correct 21 ms 3312 KB Output is correct
15 Correct 18 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 5 ms 2672 KB Output is correct
3 Correct 6 ms 2696 KB Output is correct
4 Correct 8 ms 2872 KB Output is correct
5 Correct 15 ms 3048 KB Output is correct
6 Correct 19 ms 3296 KB Output is correct
7 Correct 20 ms 3284 KB Output is correct
8 Correct 17 ms 3300 KB Output is correct
9 Correct 18 ms 3284 KB Output is correct
10 Correct 18 ms 3284 KB Output is correct
11 Correct 18 ms 3288 KB Output is correct
12 Correct 18 ms 3340 KB Output is correct
13 Correct 18 ms 3324 KB Output is correct
14 Correct 21 ms 3312 KB Output is correct
15 Correct 18 ms 3284 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 5 ms 2644 KB Output is correct
19 Correct 9 ms 2896 KB Output is correct
20 Correct 16 ms 3168 KB Output is correct
21 Correct 20 ms 3412 KB Output is correct
22 Correct 19 ms 3416 KB Output is correct
23 Correct 19 ms 3412 KB Output is correct
24 Correct 19 ms 3440 KB Output is correct
25 Correct 20 ms 3412 KB Output is correct
26 Correct 19 ms 3424 KB Output is correct
27 Correct 21 ms 3424 KB Output is correct
28 Correct 19 ms 3292 KB Output is correct
29 Correct 19 ms 3296 KB Output is correct
30 Correct 20 ms 3460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 5 ms 2672 KB Output is correct
3 Correct 6 ms 2696 KB Output is correct
4 Correct 8 ms 2872 KB Output is correct
5 Correct 15 ms 3048 KB Output is correct
6 Correct 19 ms 3296 KB Output is correct
7 Correct 20 ms 3284 KB Output is correct
8 Correct 17 ms 3300 KB Output is correct
9 Correct 18 ms 3284 KB Output is correct
10 Correct 18 ms 3284 KB Output is correct
11 Correct 18 ms 3288 KB Output is correct
12 Correct 18 ms 3340 KB Output is correct
13 Correct 18 ms 3324 KB Output is correct
14 Correct 21 ms 3312 KB Output is correct
15 Correct 18 ms 3284 KB Output is correct
16 Correct 4 ms 2644 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 5 ms 2644 KB Output is correct
19 Correct 9 ms 2896 KB Output is correct
20 Correct 16 ms 3168 KB Output is correct
21 Correct 20 ms 3412 KB Output is correct
22 Correct 19 ms 3416 KB Output is correct
23 Correct 19 ms 3412 KB Output is correct
24 Correct 19 ms 3440 KB Output is correct
25 Correct 20 ms 3412 KB Output is correct
26 Correct 19 ms 3424 KB Output is correct
27 Correct 21 ms 3424 KB Output is correct
28 Correct 19 ms 3292 KB Output is correct
29 Correct 19 ms 3296 KB Output is correct
30 Correct 20 ms 3460 KB Output is correct
31 Correct 4 ms 2632 KB Output is correct
32 Correct 5 ms 2644 KB Output is correct
33 Correct 5 ms 2648 KB Output is correct
34 Correct 5 ms 2644 KB Output is correct
35 Correct 5 ms 2644 KB Output is correct
36 Correct 9 ms 2712 KB Output is correct
37 Correct 8 ms 2772 KB Output is correct
38 Correct 8 ms 2772 KB Output is correct
39 Correct 12 ms 3028 KB Output is correct
40 Correct 17 ms 3412 KB Output is correct
41 Correct 23 ms 3800 KB Output is correct
42 Correct 24 ms 3800 KB Output is correct
43 Correct 25 ms 3796 KB Output is correct
44 Correct 23 ms 3916 KB Output is correct
45 Correct 22 ms 3808 KB Output is correct
46 Correct 28 ms 3812 KB Output is correct
47 Correct 22 ms 3792 KB Output is correct
48 Correct 22 ms 3812 KB Output is correct
49 Correct 22 ms 3804 KB Output is correct
50 Correct 22 ms 3796 KB Output is correct
51 Correct 22 ms 3796 KB Output is correct
52 Correct 22 ms 3792 KB Output is correct
53 Correct 23 ms 3820 KB Output is correct
54 Correct 22 ms 3804 KB Output is correct
55 Correct 23 ms 3796 KB Output is correct
56 Correct 23 ms 3816 KB Output is correct
57 Correct 22 ms 3808 KB Output is correct
58 Correct 22 ms 3796 KB Output is correct
59 Correct 23 ms 3924 KB Output is correct
60 Correct 29 ms 3800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 5 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 5 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 5 ms 2644 KB Output is correct
8 Correct 5 ms 2644 KB Output is correct
9 Correct 4 ms 2632 KB Output is correct
10 Correct 8 ms 2632 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 5 ms 2672 KB Output is correct
13 Correct 6 ms 2696 KB Output is correct
14 Correct 8 ms 2872 KB Output is correct
15 Correct 15 ms 3048 KB Output is correct
16 Correct 19 ms 3296 KB Output is correct
17 Correct 20 ms 3284 KB Output is correct
18 Correct 17 ms 3300 KB Output is correct
19 Correct 18 ms 3284 KB Output is correct
20 Correct 18 ms 3284 KB Output is correct
21 Correct 18 ms 3288 KB Output is correct
22 Correct 18 ms 3340 KB Output is correct
23 Correct 18 ms 3324 KB Output is correct
24 Correct 21 ms 3312 KB Output is correct
25 Correct 18 ms 3284 KB Output is correct
26 Correct 4 ms 2644 KB Output is correct
27 Correct 5 ms 2644 KB Output is correct
28 Correct 5 ms 2644 KB Output is correct
29 Correct 9 ms 2896 KB Output is correct
30 Correct 16 ms 3168 KB Output is correct
31 Correct 20 ms 3412 KB Output is correct
32 Correct 19 ms 3416 KB Output is correct
33 Correct 19 ms 3412 KB Output is correct
34 Correct 19 ms 3440 KB Output is correct
35 Correct 20 ms 3412 KB Output is correct
36 Correct 19 ms 3424 KB Output is correct
37 Correct 21 ms 3424 KB Output is correct
38 Correct 19 ms 3292 KB Output is correct
39 Correct 19 ms 3296 KB Output is correct
40 Correct 20 ms 3460 KB Output is correct
41 Correct 4 ms 2632 KB Output is correct
42 Correct 5 ms 2644 KB Output is correct
43 Correct 5 ms 2648 KB Output is correct
44 Correct 5 ms 2644 KB Output is correct
45 Correct 5 ms 2644 KB Output is correct
46 Correct 9 ms 2712 KB Output is correct
47 Correct 8 ms 2772 KB Output is correct
48 Correct 8 ms 2772 KB Output is correct
49 Correct 12 ms 3028 KB Output is correct
50 Correct 17 ms 3412 KB Output is correct
51 Correct 23 ms 3800 KB Output is correct
52 Correct 24 ms 3800 KB Output is correct
53 Correct 25 ms 3796 KB Output is correct
54 Correct 23 ms 3916 KB Output is correct
55 Correct 22 ms 3808 KB Output is correct
56 Correct 28 ms 3812 KB Output is correct
57 Correct 22 ms 3792 KB Output is correct
58 Correct 22 ms 3812 KB Output is correct
59 Correct 22 ms 3804 KB Output is correct
60 Correct 22 ms 3796 KB Output is correct
61 Correct 22 ms 3796 KB Output is correct
62 Correct 22 ms 3792 KB Output is correct
63 Correct 23 ms 3820 KB Output is correct
64 Correct 22 ms 3804 KB Output is correct
65 Correct 23 ms 3796 KB Output is correct
66 Correct 23 ms 3816 KB Output is correct
67 Correct 22 ms 3808 KB Output is correct
68 Correct 22 ms 3796 KB Output is correct
69 Correct 23 ms 3924 KB Output is correct
70 Correct 29 ms 3800 KB Output is correct
71 Correct 19 ms 2868 KB Output is correct
72 Correct 12 ms 2900 KB Output is correct
73 Correct 12 ms 2900 KB Output is correct
74 Correct 13 ms 2892 KB Output is correct
75 Correct 12 ms 2900 KB Output is correct
76 Correct 40 ms 3168 KB Output is correct
77 Correct 36 ms 3172 KB Output is correct
78 Correct 48 ms 3108 KB Output is correct
79 Correct 37 ms 3152 KB Output is correct
80 Correct 39 ms 3164 KB Output is correct
81 Correct 116 ms 3708 KB Output is correct
82 Correct 131 ms 3712 KB Output is correct
83 Correct 130 ms 3696 KB Output is correct
84 Correct 120 ms 3700 KB Output is correct
85 Correct 117 ms 3668 KB Output is correct
86 Correct 411 ms 3896 KB Output is correct
87 Correct 426 ms 3896 KB Output is correct
88 Correct 418 ms 3896 KB Output is correct
89 Correct 415 ms 3900 KB Output is correct
90 Correct 421 ms 3892 KB Output is correct
91 Execution timed out 7035 ms 5152 KB Time limit exceeded
92 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2644 KB Output is correct
2 Correct 4 ms 2644 KB Output is correct
3 Correct 5 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 5 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 5 ms 2644 KB Output is correct
8 Correct 5 ms 2644 KB Output is correct
9 Correct 4 ms 2632 KB Output is correct
10 Correct 8 ms 2632 KB Output is correct
11 Correct 4 ms 2644 KB Output is correct
12 Correct 5 ms 2672 KB Output is correct
13 Correct 6 ms 2696 KB Output is correct
14 Correct 8 ms 2872 KB Output is correct
15 Correct 15 ms 3048 KB Output is correct
16 Correct 19 ms 3296 KB Output is correct
17 Correct 20 ms 3284 KB Output is correct
18 Correct 17 ms 3300 KB Output is correct
19 Correct 18 ms 3284 KB Output is correct
20 Correct 18 ms 3284 KB Output is correct
21 Correct 18 ms 3288 KB Output is correct
22 Correct 18 ms 3340 KB Output is correct
23 Correct 18 ms 3324 KB Output is correct
24 Correct 21 ms 3312 KB Output is correct
25 Correct 18 ms 3284 KB Output is correct
26 Correct 4 ms 2644 KB Output is correct
27 Correct 5 ms 2644 KB Output is correct
28 Correct 5 ms 2644 KB Output is correct
29 Correct 9 ms 2896 KB Output is correct
30 Correct 16 ms 3168 KB Output is correct
31 Correct 20 ms 3412 KB Output is correct
32 Correct 19 ms 3416 KB Output is correct
33 Correct 19 ms 3412 KB Output is correct
34 Correct 19 ms 3440 KB Output is correct
35 Correct 20 ms 3412 KB Output is correct
36 Correct 19 ms 3424 KB Output is correct
37 Correct 21 ms 3424 KB Output is correct
38 Correct 19 ms 3292 KB Output is correct
39 Correct 19 ms 3296 KB Output is correct
40 Correct 20 ms 3460 KB Output is correct
41 Correct 4 ms 2632 KB Output is correct
42 Correct 5 ms 2644 KB Output is correct
43 Correct 5 ms 2648 KB Output is correct
44 Correct 5 ms 2644 KB Output is correct
45 Correct 5 ms 2644 KB Output is correct
46 Correct 9 ms 2712 KB Output is correct
47 Correct 8 ms 2772 KB Output is correct
48 Correct 8 ms 2772 KB Output is correct
49 Correct 12 ms 3028 KB Output is correct
50 Correct 17 ms 3412 KB Output is correct
51 Correct 23 ms 3800 KB Output is correct
52 Correct 24 ms 3800 KB Output is correct
53 Correct 25 ms 3796 KB Output is correct
54 Correct 23 ms 3916 KB Output is correct
55 Correct 22 ms 3808 KB Output is correct
56 Correct 28 ms 3812 KB Output is correct
57 Correct 22 ms 3792 KB Output is correct
58 Correct 22 ms 3812 KB Output is correct
59 Correct 22 ms 3804 KB Output is correct
60 Correct 22 ms 3796 KB Output is correct
61 Correct 22 ms 3796 KB Output is correct
62 Correct 22 ms 3792 KB Output is correct
63 Correct 23 ms 3820 KB Output is correct
64 Correct 22 ms 3804 KB Output is correct
65 Correct 23 ms 3796 KB Output is correct
66 Correct 23 ms 3816 KB Output is correct
67 Correct 22 ms 3808 KB Output is correct
68 Correct 22 ms 3796 KB Output is correct
69 Correct 23 ms 3924 KB Output is correct
70 Correct 29 ms 3800 KB Output is correct
71 Correct 19 ms 2868 KB Output is correct
72 Correct 12 ms 2900 KB Output is correct
73 Correct 12 ms 2900 KB Output is correct
74 Correct 13 ms 2892 KB Output is correct
75 Correct 12 ms 2900 KB Output is correct
76 Correct 40 ms 3168 KB Output is correct
77 Correct 36 ms 3172 KB Output is correct
78 Correct 48 ms 3108 KB Output is correct
79 Correct 37 ms 3152 KB Output is correct
80 Correct 39 ms 3164 KB Output is correct
81 Correct 116 ms 3708 KB Output is correct
82 Correct 131 ms 3712 KB Output is correct
83 Correct 130 ms 3696 KB Output is correct
84 Correct 120 ms 3700 KB Output is correct
85 Correct 117 ms 3668 KB Output is correct
86 Correct 411 ms 3896 KB Output is correct
87 Correct 426 ms 3896 KB Output is correct
88 Correct 418 ms 3896 KB Output is correct
89 Correct 415 ms 3900 KB Output is correct
90 Correct 421 ms 3892 KB Output is correct
91 Execution timed out 7035 ms 5152 KB Time limit exceeded
92 Halted 0 ms 0 KB -