Submission #60841

#TimeUsernameProblemLanguageResultExecution timeMemory
60841spencercomptonLanguages (IOI10_languages)C++17
89 / 100
7974 ms22180 KiB
#include <stdlib.h> #include <stdio.h> #include <bits/stdc++.h> #include "grader.h" #include "lang.h" using namespace std; #define SZ 100 typedef long long ll; int freq[56][65536]; double allsq[56]; int tot[56]; map<ll, int> par[56]; bool f = true; int totp[56]; double parsq[56]; vector<ll> all[56]; void excerpt(int *E) { // cout << "A " << endl; if(f){ for(int i = 0; i<65536; i++){ for(int j = 0; j<56; j++){ freq[j][i] = 0; tot[j] = 0; allsq[j] = 0.0; parsq[j] = 0.0; totp[j] = 0; } } f = false; } pair<double, int> best = make_pair(655360.0,0); vector<ll> li4; vector<int> li2; for(int i = 0; i<100; i++){ if(i>0){ li4.push_back(655360LL * (ll)E[i-1] + E[i]); } li2.push_back(E[i]); } sort(li2.begin(),li2.end()); sort(li4.begin(),li4.end()); vector<pair<ll, int> > li3; for(int i = 0; i<99; i++){ if(i==0 || li4[i-1]!=li4[i]){ int cnt = 0; for(int j = i; j<99 && li4[j]==li4[i]; j++){ cnt++; } li3.push_back(make_pair(li4[i],cnt)); } } vector<pair<int, double> > li; for(int i = 0; i<100; i++){ if(i==0 || li2[i]!=li2[i-1]){ int cnt = 0; for(int j = i; j<100 && li2[i]==li2[j]; j++){ cnt++; } li.push_back(make_pair(li2[i],cnt)); } } // cout << "B " << endl; bool fir = true; for(int i = 0; i<56; i++){ if(tot[i]==0){ continue; } double now = allsq[i]; for(int j = 0; j<li.size(); j++){ int ch = li[j].first; double f1 = (double)freq[i][ch]/(double)tot[i]; double f2 = (double)li[j].second / 100.0; now -= f1 * f1; now += (f1-f2) * (f1-f2); } 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 / 99.0; now2 -= f1 * f1; now2 += (f1-f2) * (f1-f2); } double w1 = 1.0; double w2 = 2.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); for(int i = 0; i<li.size() && tot[res]>0; i++){ double f1 = (double)freq[res][li[i].first] / (double)(tot[res]); allsq[res] -= f1*f1; } for(int i = 0; i<100; i++){ freq[res][E[i]]++; tot[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); } par[res][li3[i].first] += li3[i].second; totp[res] += li3[i].second; } // cout << "D" << endl; // allsq[res]=0.0; if(tot[res]-100>0){ allsq[res] *= tot[res]-100; allsq[res] *= tot[res]-100; } // allsq[res] *= tot[res]-100; allsq[res] /= tot[res]; allsq[res] /= tot[res]; for(int i = 0; i<li.size(); i++){ double f1 = (double)freq[res][li[i].first] / (double)(tot[res]); allsq[res] += f1*f1; } parsq[res] = 0.0; for(int i = 0; i<all[res].size(); i++){ double ff = (double)(par[res][all[res][i]]) / (double)totp[res]; parsq[res] += ff*ff; } // cout << "E " << endl; }

Compilation message (stderr)

lang.cpp: In function 'void excerpt(int*)':
lang.cpp:71:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j<li.size(); j++){
                  ~^~~~~~~~~~
lang.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j<li3.size(); j++){
                  ~^~~~~~~~~~~
lang.cpp:100:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<li.size() && tot[res]>0; i++){
                 ~^~~~~~~~~~
lang.cpp:108:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<li3.size(); i++){
                 ~^~~~~~~~~~~
lang.cpp:126:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<li.size(); i++){
                 ~^~~~~~~~~~
lang.cpp:131:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i<all[res].size(); i++){
                 ~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...