QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#842438#9970. Looping RPSucup-team3555#WA 1ms7228kbC++202.1kb2025-01-04 12:56:392025-01-04 12:56:40

Judging History

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

  • [2025-01-04 12:56:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7228kb
  • [2025-01-04 12:56:39]
  • 提交

answer

/*

*/

# include <bits/stdc++.h>

const int N=100010,INF=0x3f3f3f3f,base=229;

inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-') f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}

int n,len[N];
std::string s[N];

std::map <int,int> mp;

typedef unsigned long long ull;
typedef long long ll;

std::vector <ull> pre[N];
std::vector <int> pi[N];

std::map <ull,int> prefix[3];
int id[200];

std::map <ull,std::vector <int> > sl;

inline void init(int x){
	pre[x].resize(len[x]+1);
	pi[x].resize(len[x]+1);

	for(int i=1;i<=len[x];++i){
		pre[x][i]=pre[x][i-1]*base+s[x][i];
		++prefix[id[s[x][i]]][pre[x][i-1]];
	}
	for(int i=2,j;i<=len[x];++i){
		j=pi[x][i-1];
		for(;;){
			if(s[i]==s[j+1]) {pi[x][i]=j+1; break;}
			else if(j) j=pi[x][j];
			else {pi[x][i]=0; break;}
		}
	}

	sl[pre[x][len[x]-pi[x][len[x]]]].push_back(len[x]);

	return;
}

int main(void){
	id['P']=0,id['K']=1,id['N']=2;

	n=read();
	for(int i=1;i<=n;++i) std::cin>>s[i],s[i]=" "+s[i],len[i]=s[i].size()-1,init(i);

	ll ans=0;

	for(auto &e:sl) std::sort(e.second.begin(),e.second.end());

	for(int i=1;i<=n;++i){

//		std::cerr<<s[i]<<std::endl;
//		printf("ans = %lld\n",ans);

		for(int j=1;j<=len[i];++j){
//			printf("%llu ",pre[i][j]);

			ull pha=pre[i][j-1];
			int w=id[s[i][j]]; ll cur=1;

//			printf("cur = %lld\n",cur);
			for(int k=0;k<=2;++k){
				if(k!=w) cur*=prefix[k][pha] ;//,printf("(%d)%llu ",k,prefix[k][pha]);
			}
//			printf("pha=%llu a = %d b = %d c = %d cur = %lld\n",pha,prefix[0][pha],prefix[1][pha],prefix[2][pha],cur);

			ans+=cur,--prefix[w][pha];

			if(j==1) continue;

			int per=j-1-pi[i][j-1],r=id[s[i][(j-1)%per+1]],p=3-(w+r);

//			printf("j = %d w = %d p = %d r = %d\n",j,w,p,r);

			if(w==r) continue;
			ull ha=pre[i][per];


//			for(auto v:sl[ha]) printf("%d ",v);
//			puts("");

			ans+=1ll*prefix[p][pha]
			*(std::lower_bound(sl[ha].begin(),sl[ha].end(),j)-sl[ha].begin());
		}
//		puts("");
	}

	printf("%lld",ans);

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7212kb

input:

6
P
PN
KK
N
PKK
PN

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7228kb

input:

10
KKKNP
KNKPPKNK
KNKPP
KNKPPKN
KKKN
NNKNNNKNNNKNNNKNNNKNNNKNNNKNNPN
NNKN
NPPN
NNKNNNKNNNKNNNKNNNKNNNKNNNK
KKKNN

output:

1

result:

wrong answer 1st numbers differ - expected: '3', found: '1'