結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2016-10-24 05:10:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,585 ms / 2,000 ms |
| コード長 | 2,535 bytes |
| コンパイル時間 | 289 ms |
| コンパイル使用メモリ | 30,720 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-10 00:11:48 |
| 合計ジャッジ時間 | 9,103 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:77:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
77 | scanf("%s%d", s, &m);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:78:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
78 | inc(i, m) { scanf("%s", c[i]); }
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cmath>
#define incID(i, l, r) for(int i = (l) ; i < (r); i++)
#define incII(i, l, r) for(int i = (l) ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r) ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
typedef long long signed int LL;
typedef long long unsigned int LU;
template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
int m;
char s[50001];
char c[5000][11];
char sc[50001];
int sn[50001];
char cc[5000][11];
int cn[5000][11];
int ans;
void encode(char str[], char c_char[], int c_int[]) {
int i = 0, p = -1;
char pre = '@';
while(str[i] != '\0') {
if(str[i] != pre) {
c_char[++p] = str[i];
c_int[p] = 1;
} else {
c_int[p]++;
}
pre = str[i++];
}
c_char[++p] = '\0';
c_int[p] = 1;
return;
}
void test(char str[], char code_s[], int code_i[]) {
//printf("%s\n", str);
int i;
i = 0;
while(code_s[i] != '\0') {
printf("%c", code_s[i]);
i++;
} printf("\n");
i = 0;
while(code_s[i] != '\0') {
printf("%d", code_i[i]);
i++;
} printf("\n");
printf("\n");
return;
}
int main() {
scanf("%s%d", s, &m);
inc(i, m) { scanf("%s", c[i]); }
encode(s, sc, sn);
inc(i, m) { encode(c[i], cc[i], cn[i]); }
// test(s, sc, sn);
// inc(i, m) { test(c[i], cc[i], cn[i]); }
inc(i, m) {
int j = 0;
while(sc[j] != '\0') {
int k = 0, x, y;
bool flag = true;
while(cc[i][k] != '\0') {
// printf("j; %2d, k: %d, %c, %c\n", j, k, sc[j + k], cc[i][k]);
x = sn[j + k], y = cn[i][k];
if(sc[j + k] == cc[i][k] &&
( x == y || (x >= y && (k == 0 || cc[i][k + 1] == '\0')) )
) { k++; } else { flag = false; break; }
}
if(flag) { if(k == 1) { ans += (x - y + 1); } else { ans++; } }
j++; }
}
printf("%d\n", ans);
return 0;
}
FF256grhy