結果

問題 No.430 文字列検索
ユーザー tsuishitsuishi
提出日時 2021-05-06 14:17:50
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 4,024 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 30,728 KB
実行使用メモリ 31,976 KB
最終ジャッジ日時 2023-10-12 06:52:53
合計ジャッジ時間 1,706 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
31,680 KB
testcase_01 WA -
testcase_02 AC 13 ms
31,916 KB
testcase_03 AC 14 ms
31,788 KB
testcase_04 AC 9 ms
31,692 KB
testcase_05 AC 10 ms
31,788 KB
testcase_06 AC 10 ms
31,828 KB
testcase_07 AC 10 ms
31,724 KB
testcase_08 AC 19 ms
31,772 KB
testcase_09 AC 10 ms
31,744 KB
testcase_10 WA -
testcase_11 AC 16 ms
31,976 KB
testcase_12 AC 16 ms
31,852 KB
testcase_13 AC 15 ms
31,976 KB
testcase_14 AC 14 ms
31,772 KB
testcase_15 AC 14 ms
31,772 KB
testcase_16 AC 13 ms
31,860 KB
testcase_17 AC 13 ms
31,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
extern int getchar_unlocked(void);
extern int putchar_unlocked(int);
#define DEBUG
// ---------------------------
#define NOP do{}while(0)
#define gc(d)	(d)=getchar_unlocked()
#define pc(d)	putchar_unlocked(d)
#define mygc(c)	(c)=getchar()
#define PRINCR	pc('\n')
#ifdef DEBUG
#include <time.h>
#define TRACE(...) do{fprintf(stderr,__VA_ARGS__);}while(0)
#define TRACECR do{fprintf(stderr,"\n");}while(0)
static clock_t	startclock;
void DEBUGSTART(void){TRACE("--DEBUG MODE --\n");startclock=clock();}
void DEBUGEND(void){startclock=clock()-startclock;TRACE("--finish --\ntime is %.3fms\n",startclock/1000.);}
#else
#define TRACE(...) NOP
#define TRACECR NOP
void DEBUGSTART(void){return;}
void DEBUGEND(void){return;}
#endif
// ---------------------------
#define NOCR(strig) do{char *p;p=strchr(strig,'\n');if(p)*p='\0';}while(0)
#define SWAP(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0)
#define MAX(a,b)	((a)>(b)?(a):(b))
#define MID(a,b,c)	((a)>(b)?(b)>(c)?(b):(a)>(c)?(c):(a):(c)>(b)?(b):(c)>(a)?(c):(a))
#define MIN(a,b)	((a)<(b)?(a):(b))
#define REP(a,b)	for(int a=0;a<(int)(b);++a)
#define REP1(a,b)	for(int a=1;a<=(int)(b);++a)
#define ll	long long
#define INPUT	GETLINE
#define	ull	unsigned ll
static char *GETWORD(char* str) {char c;char *cp;cp=&str[0];gc(c);while(c!=EOF){if((c==' ')||(c=='\n'))break;*cp++=c;gc(c);}*cp='\0';return &str[0];}
#define GETLINE(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0)
#define REP(a,b) for(int a=0;a<(int)(b);++a)
static int GETLINEINT(void) {char s[34];GETLINE(s);return atoi(s);}
static int GETWORDINT(void) {char s[34];GETWORD(s);return atoi(s);}
static ll GETWORDLL(void) {char s[34];GETWORD(s);return atoll(s);}
static long GETLINELONG(void) {char s[34];GETLINE(s);return atol(s);}
static ll GETLINELL(void) {char s[34];GETLINE(s);return atoll(s);}
static int cmpint123(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
static int cmpint321(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
static ll midll(ll a,ll b,ll c){if(a>b){if(b>c){return b;}else if(a>c){return c;}
else{return a;}}else{if(c>b){return b;}else if(c>a){return c;}else{return a;}}}
static int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}    // 最大公約数
static ll gcdll(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}    // 最大公約数
#define Yes(a)    printf("%s\n",((a)?"Yes":"No"))
#define	uchar	unsigned char
#define	uint	unsigned int
#define	ulon	unsigned long
// ---------------------------
// グローバル変数
#define	CASHSIZE	(7653370L)
#define	CASHTYPE	uint
char	Str[50002];
char	Mto[50002];
int		Leng;
ull		ccc;
CASHTYPE	ht[CASHSIZE];
int		overv = 0;
// ---------------------------
void init(void)
{
	memset( ht , 0 , sizeof(CASHTYPE) * CASHSIZE );
}
void push( ull x)
{
	if(ht[x %CASHSIZE]) overv++;
	ht[ x % CASHSIZE ] = 1;
}
ulon makeidx(void)
{
	char 	*cp;
	ulon	idx=0;
	int		ii=0;

	while( ii < Leng ) {
		idx *= 26;
		idx %= CASHSIZE;
		idx += (Str[ii] - '@');
		idx %= CASHSIZE;
		ii++;
	}
	return idx;
}
int	getcash( ull x )
{
	ull ix;
	ix = x % CASHSIZE;
	return ht[ ix ];
}
int testcash(void)
{
	uint	ans = 0;
	ulon	idx;
	int		ii = 0;


	while( ii < Leng ) {
		idx = 0;
		for(int i = 0; i < 10 ;i++) {
			if( (ii + i) >= Leng ) break;
			idx *= 26;
			idx %= CASHSIZE;
			idx += (Str[ ii + i] - '@');
			idx %= CASHSIZE;
			//TRACE("%llu(%u),",idx,ht[idx]);
			ans += getcash(idx);
		}
		ii++;
	}
	return (int)ans;
}
void read(void)
{
	INPUT(Str);
	Leng = strlen(Str);
}
// *********************
int main( void )
{
	int	M;
	int	ans = 0;

	init();
	read();
	strcpy( Mto , Str );
	DEBUGSTART();

	M = GETLINEINT();
	REP(i,M) {
		ulon iii;

		read();
		push(makeidx());
	}
	if( overv ) TRACE("over %d\n",overv);
	strcpy( Str, Mto ); Leng = strlen(Str);
	ans = testcash();
	DEBUGEND();
	printf("%d\n",ans);
}
0