답안 #235417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235417 2020-05-28T08:56:26 Z dolphingarlic Languages (IOI10_languages) C++14
89 / 100
5916 ms 91320 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 ll chr = 65535;

inline double sq(double X) { return X * X; }

unordered_map<ll, double> prev_trigrams[langs];
int prev_cnt[langs];

void excerpt(int *E) {
   unordered_map<ll, double> curr_trigrams;
   FOR(i, 2, sz) {
      curr_trigrams[(E[i - 2] << 32) + (E[i - 1] << 16) + E[i]]++;
   }
   
   int best_lang = 0;
   double best_diff = 1e18;
   FOR(i, 0, langs) if (prev_cnt[i]) {
      double curr_diff = 0;
      for (pair<ll, double> j : curr_trigrams) {
         curr_diff += 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, double> i : curr_trigrams) {
      prev_trigrams[correct][i.first] += i.second;
   }
}

Compilation message

lang.cpp: In function 'void excerpt(int*)':
lang.cpp:20:34: warning: left shift count >= width of type [-Wshift-count-overflow]
       curr_trigrams[(E[i - 2] << 32) + (E[i - 1] << 16) + E[i]]++;
                                  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5459 ms 91320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 5916 ms 91108 KB Output is partially correct - 81.61%