結果

問題 No.2761 Substitute and Search
ユーザー chro_96
提出日時 2024-05-17 22:59:10
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 2,984 ms / 4,000 ms
コード長 1,646 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-20 15:01:25
合計ジャッジ時間 9,111 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmp_str (const void *a, const void *b) {
return strcmp(*(char **)a, *(char **)b);
}
int main () {
int n = 0;
int l = 0;
int q = 0;
char s[1000][3001] = {};
int p = 0;
int k = 0;
char c = '\0';
char d = '\0';
char t[3001] = "";
int res = 0;
char *sp[1000] = {};
res = scanf("%d", &n);
res = scanf("%d", &l);
res = scanf("%d", &q);
for (int i = 0; i < n; i++) {
res = scanf("%s", s[i]);
sp[i] = s[i];
}
qsort(sp, n, sizeof(char *), cmp_str);
while (q > 0) {
res = scanf("%d", &p);
if (p == 1) {
res = scanf("%d", &k);
res = scanf("%c", &c);
res = scanf("%c", &c);
res = scanf("%c", &d);
res = scanf("%c", &d);
k--;
for (int i = 0; i < n; i++) {
if (sp[i][k] == c) {
sp[i][k] = d;
}
}
qsort(sp, n, sizeof(char *), cmp_str);
} else {
int ans[2][2] = { { -1, n }, { -1, n } };
res = scanf("%s", t);
while (ans[0][1]-ans[0][0] > 1) {
int nxt = (ans[0][0]+ans[0][1])/2;
if (strcmp(sp[nxt], t) < 0) {
ans[0][0] = nxt;
} else {
ans[0][1] = nxt;
}
}
for (int i = 0; i < l; i++) {
if (t[i] == '\0') {
t[i] = 'z';
t[i+1] = '\0';
}
}
while (ans[1][1]-ans[1][0] > 1) {
int nxt = (ans[1][0]+ans[1][1])/2;
if (strcmp(sp[nxt], t) <= 0) {
ans[1][0] = nxt;
} else {
ans[1][1] = nxt;
}
}
printf("%d\n", ans[1][1]-ans[0][1]);
}
q--;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0