답안 #617175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617175 2022-08-01T09:20:42 Z Mr_Husanboy Diversity (CEOI21_diversity) C++14
4 / 100
7000 ms 1264 KB
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>


 
 
using namespace std;
using ll = long long;


 
mt19937 rng(123);
#define ld long double
#define ull unsigned long long 
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define setp(x) setprecision(x)


ll mod=1e9+7;
int inf=1e9;
const int LOGN = 20;
const int MXX=3e5;

const long double PI = 3.1415926535897932384626433832795;




int calc(deque<int> v){
	int ans = 0;
	int n = v.size();
	for(int i = 0; i < n; i ++){
		set<int> st;
		for(int j = i; j < n; j ++){
			st.insert(v[j]); ans += st.size();
		}
	}
	return ans;
}


void solve(){
	int n, q; cin >> n >> q;
	map<int,int> mp;
	for(int i = 0; i<n; i ++){
		int x; cin >> x; x --;
		mp[x] ++;
	}
	vector<pair<int,int>> v;
	for(auto u : mp){
		v.push_back({u.ss,u.ff});
	}
	sort(all(v), greater<>());
//	for(auto u : v) cout << u.ff << ' ' << u.ss << endl;cout << endl;
	deque<int> a;
	int col = 1;
	for(auto u : v){
		int tem = u.ff;
		if(col){
			while(tem --){
				a.push_back(u.ss);
			}
		}else{
			while(tem --){
				a.push_front(u.ss);
			}
		}
		col^=1;
	}
//	for(auto u : a) cout << u << ' '; cout << endl;
	cout << calc(a);
}

 
int main(){
	int testcases = 1;
//	cin >> testcases;
	while(testcases --){
		solve(); if(testcases) cout << '\n';
		cout << endl;
	}
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 220 ms 380 KB Output is correct
4 Execution timed out 7062 ms 1264 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 220 ms 380 KB Output is correct
4 Execution timed out 7062 ms 1264 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 308 KB Output is correct
3 Correct 220 ms 380 KB Output is correct
4 Execution timed out 7062 ms 1264 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 3 ms 308 KB Output is correct
13 Correct 220 ms 380 KB Output is correct
14 Execution timed out 7062 ms 1264 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 3 ms 308 KB Output is correct
13 Correct 220 ms 380 KB Output is correct
14 Execution timed out 7062 ms 1264 KB Time limit exceeded
15 Halted 0 ms 0 KB -