QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#765455 | #9578. 爱上字典 | forget-star# | WA | 1ms | 5748kb | C++11 | 1.5kb | 2024-11-20 14:20:24 | 2024-11-20 14:20:25 |
Judging History
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'