結果
問題 |
No.2761 Substitute and Search
|
ユーザー |
![]() |
提出日時 | 2024-05-22 15:48:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,553 bytes |
コンパイル時間 | 297 ms |
コンパイル使用メモリ | 41,856 KB |
最終ジャッジ日時 | 2025-02-21 16:25:37 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 MLE * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:61:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | scanf("%d%d%d", &n, &l, &qn); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:64:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 64 | scanf("%s", s); | ~~~~~^~~~~~~~~ main.cpp:73:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 73 | scanf("%d", &op); | ~~~~~^~~~~~~~~~~ main.cpp:78:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 78 | scanf("%d%s%s", &k, sc, sd); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:86:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 86 | 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 { Node *cs[26]; int s; Node(): cs(), s(0) {} }; /* global variables */ Node *root; char s[MAX_L + 4]; int ts[MAX_L][26]; /* subroutines */ void trie_add(int l, char s[]) { Node *u = root; for (int i = 0; i < l; i++) { int ci = s[i] - 'a'; if (u->cs[ci] == nullptr) u->cs[ci] = new Node(); u = u->cs[ci]; u->s++; } } int trie_count(Node *u, int i, char s[]) { if (! s[i]) return u->s; int ci = s[i] - 'a'; int sum = 0; for (int j = 0; j < 26; j++) if (ts[i][j] == ci && u->cs[j] != nullptr) sum += trie_count(u->cs[j], i + 1, s); return sum; } int trie_count(char s[]) { return trie_count(root, 0, s); } /* main */ int main() { root = new Node(); 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; }