結果
| 問題 |
No.252 "良問"(良問とは言っていない (2)
|
| コンテスト | |
| ユーザー |
nanasili
|
| 提出日時 | 2015-07-31 13:50:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,881 bytes |
| コンパイル時間 | 662 ms |
| コンパイル使用メモリ | 85,800 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-07-17 22:54:47 |
| 合計ジャッジ時間 | 1,565 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%s", s);
| ~~~~~^~~~~~~~~
ソースコード
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>
using namespace std;
typedef long long ll;
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
char s[1000001];
scanf("%s", s);
int l = strlen(s);
char g[5] = "good", p[8] = "problem";
int a[l-4-7+1], b[l-7+1];
int gcnt = 0, pcnt = 0;
for (int j = 0; j < l-4-7+1; j++) {
int cnt = 0;
for (int k = 0; k < 4; k++) {
cnt += s[j+k] != g[k];
}
a[j] = cnt+gcnt;
if (cnt == 0) gcnt++;
}
for (int j = 0; j < l-7+1; j++) {
int cnt = 0;
for (int k = 0; k < 7; k++) {
cnt += s[j+k] != p[k];
}
b[j] = cnt+pcnt;
if (cnt == 0) pcnt++;
}
for (int j = 0; j < l-7+1; j++) {
int cnt = 0;
for (int k = -6; k <= 6; k++) {
if (j+k < 0 || j+k >= l-7+1 || k == 0) continue;
cnt += b[j+k] == 0;
}
b[j] -= cnt;
}
int ans = 11;
for (int j = 1; j < l-4-7+1; j++) {
int cnt = 0;
for (int k = -6; k <= 3; k++) {
if (j+k < 0 || j+k >= l-7+1 || k == 0) continue;
cnt += b[j+k] == 0;
}
for (int k = -3; k <= 3; k++) {
if (j+k < 0 || j+k >= l-4-7+1 || k == 0) continue;
cnt += a[j+k] == 0;
}
a[j] = min(a[j]-cnt, a[j-1]);
}
for (int j = 4; j < l-7+1; j++) {
ans = min(ans, a[j-4]+b[j]);
}
// for (int j = 0; j < l-4-7+1; j++) {
// printf("%d ", a[j]);
// }
// puts("");
// for (int j = 0; j < l-7+1; j++) {
// printf("%d ", b[j]);
// }
// puts("");
printf("%d\n", ans);
}
}
nanasili