QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#416489#2409. 猜词pwx2009100 ✓4696ms4104kbC++203.7kb2024-05-21 21:38:462024-05-21 21:38:47

Judging History

你现在查看的是最新测评结果

  • [2024-05-21 21:38:47]
  • 评测
  • 测评结果:100
  • 用时:4696ms
  • 内存:4104kb
  • [2024-05-21 21:38:46]
  • 提交

answer

#include"word.h"
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
const int N=9000;
char Ans[N][5];
const char fir[30][7]={
    "slier","lares","lares","tores","tarns","arles", "lares", "lares", "snare",
    "ousel","ranis","nares","tares","aides","tries", "lares", "raise", "aides",
    "plate","nares","snare","riles","nares","cones", "kanes", "aeons"
};
void init(int num_scramble, const char *scramble) {
	for(int i=0;i<num_scramble;i++){
		for(int j=0,k=i*5;j<5;j++,k++)
			Ans[i][j]=scramble[k];
	}
}
int ans[8];
bool ok[30][7];
bool mn[30];
int d[N],cnt;
int should[30],tot;
char A[7];
int sum[30];
void check(int x){
	for(int i=0;i<5;i++)
		if(!ok[Ans[x][i]-'a'][i])
			return;
	bool flag=true;
	for(int i=0;i<5&&flag;i++)
		sum[Ans[x][i]-'a']++;
	for(int i=1;i<=tot&&flag;i++)
		if(!sum[should[i]]&&mn[should[i]])
			flag=0;
	for(int i=0;i<5;i++)
		sum[Ans[x][i]-'a']=0;
	if(flag)
		d[++cnt]=x;
}
int work(int x,int y){
	int u=0;
	int w[8];
	w[0]=1;
	for(int i=1;i<6;i++)w[i]=w[i-1]*3;
	for(int i=0;i<5;i++){
		if(Ans[x][i]==Ans[y][i]);
		else sum[Ans[y][i]-'a']++;
	}
	for(int i=0;i<5;i++){
		if(Ans[x][i]==Ans[y][i]){
			u+=2*w[i];
			continue;
		}
		if(sum[Ans[x][i]-'a']){
			sum[Ans[x][i]-'a']--;
			u+=w[i];
		}
	}
	for(int i=0;i<5;i++)
		sum[Ans[y][i]-'a']=0;
	return u;
}
int sure[10];
bool must[30][10];
const char *guess(int num_testcase, int remaining_guesses, char initial_letter, bool *gold, bool *silver) {
	// your code here
	bool have[30];
	int num;
	memset(have,0,sizeof have);
	if(remaining_guesses==5){
		memset(ans,0,sizeof ans);
		memset(must,0,sizeof must);
		memset(mn,0,sizeof mn);
		memset(ok,1,sizeof ok);
		for(int i=0;i<26;i++)ok[i][0]=0;
		num=initial_letter-'a';
		ok[num][0]=1;
		must[num][0]=1;
		mn[num]=1;
		ans[5]=8869;
		for(int i=0;i<5;i++)
			Ans[8869][i]=A[i]=fir[num][i];
		return A;
	}
	for(int i=0;i<5;i++){
		num=Ans[ans[remaining_guesses+1]][i]-'a';
		if(gold[i]){
			for(int j=0;j<26;j++)
				if(num!=j)ok[j][i]=0;
			mn[num]=1;
			must[num][i]=1;
			continue;
		}
		if(silver[i]){
			mn[num]=1;
			ok[num][i]=0;
			continue;
		}
	}
	for(int i=0;i<5;i++){
		num=Ans[ans[remaining_guesses+1]][i]-'a';
		if(gold[i])continue;
		if(silver[i])continue;
		for(int j=0;j<5;j++)
			if(!must[num][j])
				ok[num][j]=0;
	}
	tot=cnt=0;
	for(int i=0;i<26;i++){
		if(mn[i])
			should[++tot]=i;
		// printf("%c  %d ",i+'a',mn[i]);
		// for(int j=0;j<5;j++)printf("%d",ok[i][j]);
		// putchar(10);
	}
	for(int i=0;i<8869;i++)check(i);
	if(cnt==1){
		for(int i=0;i<5;i++)
			A[i]=Ans[d[1]][i];
		return A;
	}
	if(cnt==0){
		ans[remaining_guesses]=0;
		for(int i=0;i<5;i++)
			A[i]=Ans[ans[remaining_guesses]][i];
		return A;
	}
	ans[remaining_guesses]=d[1];
    if(cnt>2){
        long double now=0,Mn=0,pi;
        bool flag=0;
		int S[250];
        for(int i=0;i<8869;i++){
            now=0.0;
			pi=1.0;
			pi=pi/cnt;
            memset(S,0,sizeof S);
            for(int j=1;j<=cnt;j++){
                int k=work(i,d[j]);
                S[k]++;
				if(k==242)now+=1.0/cnt*5.5;
            }
            flag=0;
            for(int j=0;j<243;j++){
                pi=S[j]*1.0/cnt;
                if(S[j]==0);
                else now-=1.0*pi*log2f(pi),flag=1;
            }
			for(int j=0;j<6&&flag;j++)
				if(j!=remaining_guesses&&i==ans[j])
					flag=0;
            if(now>Mn&&flag){
                Mn=now;
                ans[remaining_guesses]=i;
            }
        }
    }
	// printf("%.7Lf ",Mn);
	for(int i=0;i<5;i++)
		A[i]=Ans[ans[remaining_guesses]][i];
	return A;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4696ms
memory: 4104kb

input:

1000 258971
aahedaaliiaarghabacaabaciabackabaftabakaabampabaseabashabateabayaabbasabbesabbeyabbotabeamabeleabetsabhorabideabledablerablesabmhoabodeabohmaboilabomaaboonabortaboutaboveabrisabuseabutsabuzzabyesabysmabyssacariacerbacetaachedachesachooacidsacidyacingaciniackeeacmesacmicacnedacnesacockaco...

output:

100.000

result:

points 1.0 finished