QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765455#9578. 爱上字典forget-star#WA 1ms5748kbC++111.5kb2024-11-20 14:20:242024-11-20 14:20:25

Judging History

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

  • [2024-11-20 14:20:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5748kb
  • [2024-11-20 14:20:24]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long

using namespace std;

int read()
{
	int a = 0,x = 1;char ch = getchar();
	while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();}
	while(ch >='0' && ch <= '9') {a = a*10 + ch-'0';ch = getchar();}
	return a*x;
}
const int N = 5e6+7,base1 = 133,base2 = 131,mod1 = 1000429,mod2 = 20190631;
char s[N];
int head[N],go[N],nxt[N],cnt,val[N];
void add(int u,int v,int w)
{
	go[++cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
	val[cnt] = w;
}
int fid(int u,int v)
{
	for(int e = head[u];e;e = nxt[e]) {
		if(go[e] == v) return e;
	}
	return 0;
}
int main()
{
	// freopen("in.in","r",stdin);
	gets(s+1);int len = strlen(s+1);s[len+1] = ' ';len ++;
	ll hash1 = 0,hash2 = 0;
	for(int i = 1;i <= len;i ++) {
		if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 'a'-'A';
		if(s[i] > 'z' || s[i] < 'a') {
			if(hash1) {
				int e = fid(hash1,hash2);
				if(e) val[e] ++;
				else {
					add(hash1,hash2,1);
				}
				hash1 = hash2 = 0;
			}
			continue;
		}
		hash1 = (hash1 * base1 + s[i]) % mod1;
		hash2 = (hash2 * base2 + s[i]) % mod2;
	}
	int n = read();
	for(int i= 1;i <= n;i ++) {
		scanf("%s",s+1);len = strlen(s+1);
		hash1 = hash2 = 0;
		for(int j = 1;j <= len;j ++) {
			hash1 = (hash1 * base1 + s[j]) % mod1;
			hash2 = (hash2 * base2 + s[j]) % mod2;
		}
		int e = fid(hash1,hash2);
		val[e] = 0;
	}
	int ans = 0;
	for(int i = 1;i <= cnt;i ++) ans += val[i];
	printf("%d\n",ans);
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5692kb

input:

I love Liaoning. Love Dalian!
1
love

output:

3

result:

ok single line: '3'

Test #2:

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

input:

Sulfox Loves Furry! Fur fur Furred.
2
anthropomorphic furry

output:

5

result:

wrong answer 1st lines differ - expected: '4', found: '5'