結果
| 問題 | No.2172 SEARCH in the Text Editor |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-28 19:40:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 2,365 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 87,368 KB |
| 最終ジャッジ日時 | 2025-02-11 18:53:17 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%s", it);
| ~~~~~^~~~~~~~~~
main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%s", ib);
| ~~~~~^~~~~~~~~~
main.cpp:47:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | scanf("%d %d", &a, &b); a--; b--;
| ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
bool operator()(const int& a, const int& b) {
return a<b;
}
};
#define MOD 998244353
char it[128];
int ff[128];
char ib[100004];
int cc[100004];
char ssc[100004], esc[100004];
char ss[100004][52];
char es[100004][52];
int main() {
int n, i, j, m, f, c, a, b, k;
scanf("%d", &n);
scanf("%s", it);
f=-1; for (m=0;;m++) {
ff[m]=f;
while(f!=-1&&it[f]!=it[m]) f=ff[f]; f++;
if (it[m]==0) break;
}
for (i=0; i<n; i++) {
scanf("%s", ib);
if (ib[0]=='~') {
scanf("%d %d", &a, &b); a--; b--;
c=cc[a]+cc[b];
// printf("merge %d,%d, start : %d\n", a, b, c);
f=0;
for (j=0; j<esc[a]; j++) {
while(f!=-1&&it[f]!=es[a][esc[a]-1-j]) f=ff[f]; f++;
}
for (j=0; j<ssc[b]; j++) {
while(f!=-1&&it[f]!=ss[b][j]) f=ff[f]; f++;
if (f>=m) c++;
}
c%=MOD;
cc[i]=c;
//
for (j=0; j<ssc[a]; j++) ss[i][j]=ss[a][j]; c=ssc[a];
for (j=0; j<ssc[b]&&c<m-1; j++, c++) ss[i][c]=ss[b][j];
ssc[i]=c;
for (j=0; j<esc[b]; j++) es[i][j]=es[b][j]; c=esc[b];
for (j=0; j<esc[a]&&c<m-1; j++, c++) es[i][c]=es[a][j];
esc[i]=c;
} else {
c=0; f=0;
for (j=0; ib[j]; j++) {
while(f!=-1&&it[f]!=ib[j]) f=ff[f];
f++;
if (f>=m) c++;
}
cc[i]=c%MOD;
if (j>=m) {
ssc[i]=m-1; esc[i]=m-1;
for (k=0; k<m-1; k++) {
ss[i][k]=ib[k];
es[i][k]=ib[j-1-k];
}
} else {
ssc[i]=j; esc[i]=j;
for (k=0; k<j; k++) {
ss[i][k]=ib[k];
es[i][k]=ib[j-1-k];
}
}
}
}
printf("%d\n", cc[n-1]);
return 0;
}