結果

問題 No.2761 Substitute and Search
コンテスト
ユーザー 👑 tails
提出日時 2024-05-22 12:43:55
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,680 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 152 ms
コンパイル使用メモリ 26,752 KB
最終ジャッジ日時 2026-02-24 01:19:47
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function 'maze':
main.c:25:21: error: expected ';' before 'a'
   25 |                 rep(a,26){
      |                     ^
main.c:7:32: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c:25:21: error: 'a' undeclared (first use in this function)
   25 |                 rep(a,26){
      |                     ^
main.c:7:36: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c:25:21: note: each undeclared identifier is reported only once for each function it appears in
   25 |                 rep(a,26){
      |                     ^
main.c:7:36: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c: In function 'main':
main.c:44:13: error: expected ';' before 'i'
   44 |         rep(i,n){
      |             ^
main.c:7:32: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c:44:13: error: 'i' undeclared (first use in this function)
   44 |         rep(i,n){
      |             ^
main.c:7:36: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c:46:21: error: expected ';' before 'j'
   46 |                 rep(j,l){
      |                     ^
main.c:7:32: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c:46:21: error: 'j' undeclared (first use in this function)
   46 |                 rep(j,l){
      |                     ^
main.c:7:36: note: in definition of macro 'rep'
    7 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c:67:29: error: expected ';' before 'i'
   67 |                         rep(i,tn[k-1])

ソースコード

diff #
raw source code

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define wt(v) {unsigned _z=v,_n=0;long _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define rep(v,e) for(typeof(e) v=0;v<e;++v)

char wbuf[1<<25];

struct E {
	short cnt;
	short cid;
};

struct N {
	struct E e[26];
};

struct N tree[3001][1000];
int tn[3001];

void maze(l,k,ci,di){
	if(k<l){
		rep(a,26){
			if(tree[k][ci].e[a].cnt){
				if(tree[k][di].e[a].cnt){
					tree[k][di].e[a].cnt+=tree[k][ci].e[a].cnt;
					maze(l,k+1,tree[k][ci].e[a].cid,tree[k][di].e[a].cid);
				}else{
					tree[k][di].e[a]=tree[k][ci].e[a];
				}
			}
		}
	}
}

int main(){
	rd_init();
	int n=rd();
	int l=rd();
	int q=rd();
	tn[0]=1;
	rep(i,n){
		int nid=0;
		rep(j,l){
			int c=*rp++-'a';
			struct E*ep=&tree[j][nid].e[c];
			if(ep->cnt==0){
				ep->cid=tn[j+1]++;
			}
			ep->cnt+=1;
			nid=ep->cid;
		}
		++rp;
	}
	char*wp=wbuf;
	while(q--){
		int t=*rp;
		rp+=2;
		if(t&1){
			int k=rd();
			int c=*rp-'a';
			rp+=2;
			int d=*rp-'a';
			rp+=2;
			rep(i,tn[k-1]){
				struct N*np=&tree[k-1][i];
				if(np->e[c].cnt){
					if(np->e[d].cnt){
						np->e[d].cnt+=np->e[c].cnt;
						maze(l,k,np->e[c].cid,np->e[d].cid);
					}else{
						np->e[d]=np->e[c];
					}
					np->e[c].cnt=0;
				}
			}
		}else{
			int z=0;
			int nid=0;
			int k=0;
			for(int c;c=*rp++-'a',c>=0;){
				z=tree[k][nid].e[c].cnt;
				if(!z){
					while(*rp++-'a'>=0);
					break;
				}
				nid=tree[k][nid].e[c].cid;
				++k;
			}
			wt(z);
			*wp++='\n';
		}
	}
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0