結果
問題 |
No.2761 Substitute and Search
|
ユーザー |
![]() |
提出日時 | 2024-05-22 15:54:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,569 bytes |
コンパイル時間 | 337 ms |
コンパイル使用メモリ | 42,108 KB |
最終ジャッジ日時 | 2025-02-21 16:25:53 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 RE * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:59:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 59 | scanf("%d%d%d", &n, &l, &qn); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:62:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | scanf("%s", s); | ~~~~~^~~~~~~~~ main.cpp:71:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 71 | scanf("%d", &op); | ~~~~~^~~~~~~~~~~ main.cpp:76:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 76 | scanf("%d%s%s", &k, sc, sd); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:84:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 84 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2761.cc: No.2761 Substitute and Search - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_L = 3000; /* typedef */ struct Node { short cs[26], s; Node(): s(0) { fill(cs, cs + 26, -1); } }; /* global variables */ Node buf[MAX_N * MAX_L]; int bpt = 1; char s[MAX_L + 4]; int ts[MAX_L][26]; /* subroutines */ void trie_add(int l, char s[]) { int u = 0; for (int i = 0; i < l; i++) { int ci = s[i] - 'a'; if (buf[u].cs[ci] < 0) buf[u].cs[ci] = bpt++; u = buf[u].cs[ci]; buf[u].s++; } } int trie_count(int u, int i, char s[]) { if (! s[i]) return buf[u].s; int ci = s[i] - 'a'; int sum = 0; for (int j = 0; j < 26; j++) if (ts[i][j] == ci && buf[u].cs[j] >= 0) sum += trie_count(buf[u].cs[j], i + 1, s); return sum; } int trie_count(char s[]) { return trie_count(0, 0, s); } /* main */ int main() { int n, l, qn; scanf("%d%d%d", &n, &l, &qn); for (int i = 0; i < n; i++) { scanf("%s", s); trie_add(l, s); } for (int i = 0; i < l; i++) for (int j = 0; j < 26; j++) ts[i][j] = j; while (qn--) { int op; scanf("%d", &op); if (op == 1) { int k; char sc[4], sd[4]; scanf("%d%s%s", &k, sc, sd); k--; int c = sc[0] - 'a', d = sd[0] - 'a'; for (int j = 0; j < 26; j++) if (ts[k][j] == c) ts[k][j] = d; } else { scanf("%s", s); int cnt = trie_count(s); printf("%d\n", cnt); } } return 0; }