답안 #713233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713233 2023-03-21T10:56:38 Z Pacybwoah Diversity (CEOI21_diversity) C++14
0 / 100
2 ms 2644 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;

int main(){
    ll n,q;
    cin>>n>>q;
    if(q!=1) return 0;
    int a,b;
    vector<ll> vec(n);
    for(int i=0;i<n;i++) cin>>vec[i];
    cin>>a>>b;
    vector<ll> cnt(300001);
    for(int i=0;i<n;i++) cnt[vec[i]]++;
    vector<ll> p;
    for(int i=0;i<=300000;i++){
        if(cnt[i]>0) p.push_back(cnt[i]);
    }
    sort(p.begin(),p.end());
    vector<ll> f;
    for(int i=0;i<p.size();i+=2){
        f.push_back(p[i]);
    }
    for(int i=(p.size()%2==0?p.size()-1:p.size()-2);i>=0;i-=2) f.push_back(p[i]);
    ll sum=0,len=f.size();
    vector<ll> pre1(len),pre2(len);
    pre1[0]=0;
    pre2[0]=0;
    for(int i=1;i<len;i++){
        pre1[i]=pre1[i-1]+f[i]*i;
        pre2[i]=pre2[i-1]+f[i];
    }
    for(ll i=0;i<len;i++){
        sum+=f[i]*(f[i]+1)/2;
        sum+=f[i]*(pre1[n-1]-pre1[i]-(i-1)*(pre2[n-1]-pre2[i]));
    }
    cout<<sum<<"\n";
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<p.size();i+=2){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -