Submission #235434

# Submission time Handle Problem Language Result Execution time Memory
235434 2020-05-28T09:22:16 Z dolphingarlic Languages (IOI10_languages) C++14
0 / 100
10000 ms 152236 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_letters[(E[i - 1] << 15) + E[i]]++;
      if (i > 1) curr_letters[(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;
   // }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 10092 ms 147832 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 10040 ms 152236 KB Time limit exceeded