답안 #235432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235432 2020-05-28T09:16:37 Z dolphingarlic Languages (IOI10_languages) C++14
0 / 100
10000 ms 178128 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

#include "grader.h"
// #include "lang.h"

const int SZ = 100, LANGS = 56;
const float LETTER_WEIGHT = 1, BIGRAM_WEIGHT = 2, TRIGRAM_WEIGHT = 3;

unordered_map<ll, float> prev_letters[LANGS], prev_bigrams[LANGS], prev_trigrams[LANGS];
int prev_cnt[LANGS];

void excerpt(int *E) {
   unordered_map<ll, float> curr_letters, curr_bigrams, curr_trigrams;
   FOR(i, 0, SZ) {
      curr_letters[E[i]]++;
      if (i) curr_bigrams[(E[i - 1] << 15) + E[i]]++;
      if (i > 1) curr_trigrams[(E[i - 2] << 31) + (E[i - 1] << 15) + E[i]]++;
   }
   
   int best_lang = 0;
   float best_diff = 1e18;
   FOR(i, 0, LANGS) if (prev_cnt[i]) {
      float curr_diff = 0;
      for (pair<ll, float> j : curr_letters) {
         curr_diff += LETTER_WEIGHT * abs(j.second - (prev_letters[i][j.first] / prev_cnt[i]));
      }
      for (pair<ll, float> j : curr_bigrams) {
         curr_diff += BIGRAM_WEIGHT * abs(j.second - (prev_bigrams[i][j.first] / prev_cnt[i]));
      }
      for (pair<ll, float> j : curr_trigrams) {
         curr_diff += TRIGRAM_WEIGHT * abs(j.second - (prev_trigrams[i][j.first] / prev_cnt[i]));
      }
      if (curr_diff < best_diff) {
         best_diff = curr_diff;
         best_lang = i;
      }
   }

   int correct = language(best_lang);
   prev_cnt[correct]++;
   for (pair<ll, float> i : curr_letters) {
      prev_letters[correct][i.first] += i.second;
   }
   for (pair<ll, float> i : curr_bigrams) {
      prev_bigrams[correct][i.first] += i.second;
   }
   for (pair<ll, float> i : curr_trigrams) {
      prev_trigrams[correct][i.first] += i.second;
   }
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10088 ms 178128 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10029 ms 177704 KB Time limit exceeded