結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
otsnsk
|
| 提出日時 | 2015-02-17 13:10:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 2,129 bytes |
| コンパイル時間 | 769 ms |
| コンパイル使用メモリ | 73,728 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 01:53:13 |
| 合計ジャッジ時間 | 1,490 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
/*
http://yukicoder.me/problems/344
No. 150
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define FORR(i,b,e) for(int i=(b);i<(int)(e);++i)
#define FOR(i,e) FORR(i,0,e)
#define sortuniq(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(),v.end()),v.end())
#define dump(var) cerr << #var ": " << var << "\n"
#define dumpc(con) for(auto& e: con) cerr << e << " "; cerr<<"\n"
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-6;
const int d4[] = {0, -1, 0, 1, 0};
using namespace std;
const int INF = 1e9;
template<class T>
struct SegmentTree {
int size;
vector<T> v;
SegmentTree(int req_size) {
size = 1<<1;
while (size < req_size) {
size <<= 1;
}
v.resize(size << 1);
}
void update(int p, T val) {
p += size-1;
v[p] = val;
while (p) {
p >>= 1;
v[p] = min(v[p<<1], v[(p<<1)+1]);
}
}
T minVal(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) return INF;
if (a <= l && r <= b) return v[k];
return min(minVal(a, b, k<<1, l, (l+r)>>1),
minVal(a, b, (k<<1)+1, (l+r)>>1, r));
}
T minVal(int a, int b) {
return minVal(a, b, 1, 1, size+1);
}
};
inline int edit_score(const string &src, int pos, const string &t) {
int score = 0;
FOR(i, t.size()) {
score += src[pos+i] != t[i];
}
return score;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
const string sg = "good", sp = "problem";
int T;
cin >> T;
while (T--) {
string S;
cin >> S;
SegmentTree<int> st(S.size());
FORR(i, sg.size(), S.size()-sp.size()+1) {
st.update(i, edit_score(S, i, sp));
}
int min_score = INF;
FOR(i, S.size()-sg.size()-sp.size()+1) {
min_score = min(min_score,
edit_score(S, i, sg) +
st.minVal(i+sg.size(), S.size()-sp.size()+1));
}
cout << min_score << endl;
}
return 0;
}
otsnsk