답안 #170195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170195 2019-12-24T08:17:53 Z ics0503 Languages (IOI10_languages) C++17
100 / 100
4090 ms 205032 KB
#include <stdlib.h>
#include <stdio.h>
#include <set>
using namespace std;

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

#define SZ 100
int num[56][65536], ccnt = 0, commonChar[65536], uniqueChar[65536];
const int mod = 249943;
int num2[56][mod];
int num3[56][mod];
int num4[56][mod];
int num5[56][mod];
long long hash2(long long x, long long y) {
	return (x * 65536 + y) % mod;
}
long long hash3(long long x, long long y, long long z) {
	return (((x * 65536 + y) % mod) * 65536 + z) % mod;
}
long long hash4(long long x, long long y, long long z, long long g) {
	return (((((x * 65536 + y) % mod) * 65536 + z) % mod) * 65536 + g)%mod;
}
long long hash5(long long x, long long y, long long z, long long g, long long r) {
	return ((((((x * 65536 + y) % mod) * 65536 + z) % mod) * 65536 + g) % mod * 65536 + r) % mod;
}
long long hashX(int *E, int s, int e) {
	if (s > e)return 0;
	long long res = 0, i;
	for (i = s; i <= e; i++) {
		res = (res * 65536 + E[i]) % mod;
	}
	return res;
}
int pandan(int *E) {
	int nE[222] = { 0, }, n=0, i, j;
	int js[56] = { 0, };
	for (i = 0; i < 100; i++) {
		for (j = 0; j < 56; j++) {
			js[j] += !!num[j][E[i]];
		}
	}
	for (i = 1; i < 100; i++) {
		int g = hash2(E[i - 1], E[i]);
		for (j = 0; j < 56; j++) {
			js[j] += num2[j][g];
		}
	}
	for (i = 2; i < 100; i++) {
		int g = hash3(E[i - 2], E[i - 1], E[i]);
		for (j = 0; j < 56; j++) {
			js[j] += num3[j][g];
		}
	}
	for (i = 3; i < 100; i++) {
		int g = hash4(E[i - 3], E[i - 2], E[i - 1], E[i]);
		for (j = 0; j < 56; j++) {
			js[j] += num4[j][g];
		}
	}
	for (i = 4; i < 100; i++) {
		int g = hash5(E[i - 4], E[i - 3], E[i - 2], E[i - 1], E[i]);
		for (j = 0; j < 56; j++) {
			js[j] += num5[j][g];
		}
	}
	int mx = -1, mxw = 0;
	for (i = 0; i < 56; i++) if (mx < js[i])mx = js[i], mxw = i;
	return mxw;
}
int num2x[65536] = { 0, };
int max(int a, int b) {
	if (a < b)return b; return a;
}
void learn(int *E, int ans) {
	int i, j, k;
	for (i = 0; i < 100; i++) num2x[E[i]] = 0;
	for (i = 0; i < 100; i++) num2x[E[i]]++;
	for (i = 0; i < 100; i++) num[ans][E[i]] = max(num[ans][E[i]], num2x[E[i]]);
	for (i = 1; i < 100; i++) num2[ans][hash2(E[i - 1], E[i])] = 1;
	for (i = 2; i < 100; i++) num3[ans][hash3(E[i - 2], E[i - 1], E[i])] = 1;
	for (i = 3; i < 100; i++) num4[ans][hash4(E[i - 3], E[i - 2], E[i - 1], E[i])] = 1;
	for (i = 4; i < 100; i++) num5[ans][hash5(E[i - 4], E[i - 3], E[i - 2], E[i - 1], E[i])] = 1;
}
void excerpt(int *E) {
	int i, j;
	ccnt++;
	int ans = language(pandan(E));
	learn(E, ans);
}

Compilation message

lang.cpp: In function 'int pandan(int*)':
lang.cpp:37:6: warning: unused variable 'nE' [-Wunused-variable]
  int nE[222] = { 0, }, n=0, i, j;
      ^~
lang.cpp:37:24: warning: unused variable 'n' [-Wunused-variable]
  int nE[222] = { 0, }, n=0, i, j;
                        ^
lang.cpp: In function 'int max(int, int)':
lang.cpp:74:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if (a < b)return b; return a;
  ^~
lang.cpp:74:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (a < b)return b; return a;
                      ^~~~~~
lang.cpp: In function 'void learn(int*, int)':
lang.cpp:77:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k;
         ^
lang.cpp:77:12: warning: unused variable 'k' [-Wunused-variable]
  int i, j, k;
            ^
lang.cpp: In function 'void excerpt(int*)':
lang.cpp:87:6: warning: unused variable 'i' [-Wunused-variable]
  int i, j;
      ^
lang.cpp:87:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4090 ms 204980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3756 ms 205032 KB Output is correct - 90.97%