답안 #60877

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60877 2018-07-24T22:19:47 Z spencercompton Languages (IOI10_languages) C++14
94 / 100
9803 ms 19368 KB
#include <stdlib.h>
#include <stdio.h>
#include <bits/stdc++.h>
#include "grader.h"
#include "lang.h"
using namespace std;
#define SZ 100
typedef int ll;
ll mod = 1000000007LL;
int tot[56];
unordered_map<ll, int> par[56];
bool f = true;
int totp[56];
double parsq[56];
vector<ll> all[56];
int big[56][1000000];
void excerpt(int *E) {
	// cout << "A " << endl;
	if(f){
			for(int j = 0; j<56; j++){
				tot[j] = 0;
				parsq[j] = 0.0;
				totp[j] = 0;
			}
		f = false;
	}
	pair<double, int> best = make_pair(655360.0,0);
	vector<ll> li4;
	for(int i = 0; i<100; i++){
		if(i>0){
 
			li4.push_back((655360LL * ((ll)E[i-1]+1)+ E[i])%mod);
		}
		if(i>1){
			long long hsh =  E[i] + 1;
			hsh *= 655360LL;
			hsh %= mod;
			hsh += E[i-1] + 1;
			hsh *= 655360LL;
			hsh %= mod;
			hsh += E[i-2] + 1;
			hsh %= mod;
			li4.push_back(hsh);
		}
	}
	sort(li4.begin(),li4.end());
	vector<pair<ll, int> > li3;
	for(int i = 0; i<197; i++){
		if(i==0 || li4[i-1]!=li4[i]){
			int cnt = 0;
			for(int j = i; j<197 && li4[j]==li4[i]; j++){
				cnt++;
			}
			li3.push_back(make_pair(li4[i],cnt));
		}
	}
	// cout << "B " << endl;
	bool fir = true;
	for(int i = 0; i<56; i++){
		if(tot[i]==0){
			continue;
		}
		double now = 0.0;
		double now2 = parsq[i];
		for(int j = 0; j<li3.size(); j++){
			ll pp = li3[j].first;
			double f1 = 0.0;
			if(par[i].find(pp)!=par[i].end()){
				f1 = par[i][pp];
			}
			f1 /= (double)totp[i];
			double f2 = (double)li3[j].second / 197.0;
			now2 -= f1 * f1;
			now2 += (f1-f2) * (f1-f2);
		}
		double w1 = 0.5;
		double w2 = 10.0;
		if(fir){
			best = make_pair(now*w1 + now2*w2,i);
			fir = false;
		}
		best = min(best,make_pair(now*w1 + now2*w2,i));
	}
	// cout << "C " << endl;
	int res = language(best.second);
	int og = totp[res];
	for(int i = 0; i<li3.size(); i++){
		if(par[res].find(li3[i].first)==par[res].end()){
			par[res][li3[i].first] = 0;
			all[res].push_back(li3[i].first);
		}
		else if(og>0){
			double ff = (double)(par[res][li3[i].first]) / (double)og;
			parsq[res] -= ff*ff;
		}
		par[res][li3[i].first] += li3[i].second;
		totp[res] += li3[i].second;
	}
	// cout << "D"  << endl;
	parsq[res] *= og;
	parsq[res] *= og;
	parsq[res] /= totp[res];
	parsq[res] /= totp[res];
	for(int i = 0; i<li3.size(); i++){
		double ff = (double)(par[res][li3[i].first]) / (double)totp[res];
		parsq[res] += ff*ff;
	}
	tot[res] += 100;
	// cout << "E " << endl;
}

Compilation message

lang.cpp: In function 'void excerpt(int*)':
lang.cpp:65:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j<li3.size(); j++){
                  ~^~~~~~~~~~~
lang.cpp:87:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<li3.size(); i++){
                 ~^~~~~~~~~~~
lang.cpp:104:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<li3.size(); i++){
                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9364 ms 19352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 9803 ms 19368 KB Output is partially correct - 86.31%