답안 #588439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588439 2022-07-03T09:36:18 Z jasmin Diversity (CEOI21_diversity) C++14
0 / 100
1 ms 244 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    int n, q;
    cin >> n >> q;
    vector<int> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    map<int,int> cnt;
    for(int i=0; i<n; i++){
        cnt[s[i]]++;
    }
    for(int i=0; i<q; i++){
        int a, b;
        cin >> a >> b;
    }

    vector<pair<int,int> > sorted;
    for(auto e: cnt){
        sorted.push_back({e.second, e.first});
    }
    sort(sorted.begin(), sorted.end());

    vector<pair<int,int> > res(cnt.size());
    int l=0; int r=cnt.size()-1; bool left=true;
    for(auto e: sorted){
        int x=e.second; int anz=e.first;
        if(left){
            res[l]={x, anz};
            l++;
            left=false;
        }
        else{
            res[r]={x, anz};
            r--;
            left=true;
        }
    }

    vector<int> neu(n);
    int i=0;
    for(auto e: cnt){
        int x=e.first;
        int anz=e.second;
        for(int j=0; j<anz; j++, i++){
            neu[i]=x;
        }
    }

    int ans=1;
    int last=1;
    for(int i=1; i<n; i++){
        if(neu[i]==neu[i-1]){
            ans+=last+1;
            last++;
        }
        else{
            ans+=last+i+1;
            last=last+i+1;
        }
    }
    
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 244 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -