結果

問題 No.150 "良問"(良問とは言っていない
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-07-21 04:49:57
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 851 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 65,876 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-19 09:32:39
合計ジャッジ時間 3,219 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int f()’:
main.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
main.cpp:42:21: warning: ‘e1.E::ch’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |                 int ch2=ch1+e1.ch;
      |                     ^~~

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <queue>
#include <string>

struct E{
	int p,ch;
	bool operator<(const E& e1)const{
		if(ch!=e1.ch)return ch>e1.ch;
		return p>e1.p;
	}
};

int ch(std::string str,std::string word){
	int res=0;
	for(int i=0;i<word.size();i++){
		if(str[i]!=word[i])res++;
	}
	return res;
}
int f(){
	std::string str;
	std::cin>>str;
	std::priority_queue<E> pq;
	int ans=-1;
	for(int i=0;i+6<str.size();i++){
		E e1;
		e1.p=i;
		e1.ch=ch(str.substr(i,7),"problem");
		pq.push(e1);
	}
	for(int i=0;i+10<str.size();i++){
		int ch1=ch(str.substr(i,4),"good");
		E e1;
		while(pq.empty()==false){
			e1=pq.top();
			if(e1.p>i+3){
				break;
			}
			pq.pop();
		}
		int ch2=ch1+e1.ch;
		if((ans==-1)||(ans>ch2)){
			ans=ch2;
		}
	}
	printf("%d\n",ans);
}

int main() {
	int n;
	std::cin>>n;
	for(int i=0;i<n;i++){
		f();
	}
	
}
0