結果

問題 No.239 にゃんぱすー
ユーザー tkr987
提出日時 2018-07-28 22:48:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,543 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 72,440 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 12:24:41
合計ジャッジ時間 1,718 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

/**
@breif にゃんぱす格納関数
@param collection 格納する挨拶コンテナ
@note
 vectorは村民1に対する相手jの挨拶が格納される。
 mapには村民jの村民1相手以外の挨拶が格納される。
 つまり、vectorが挨拶行列の列、mapが挨拶行列の行を指す。
**/
void InputToCollection(vector<multimap<string, int>>* collection, int max_size)
{
	for (int i = 0; i < max_size; i++)
	{
		string word; cin >> word;
		(*collection)[i].emplace(word, 0);
	}
}

/**
@breif にゃんぱす検索関数
@param collection 検索する村人の挨拶コンテナ
@retval -1以外 れんちょんの村民番号
@retval -1 れんちょんを特定できない
**/
int FindNyanpass(vector<multimap<string, int>>* collection)
{
	int find = -1;
	// れんちょんは誰に対しても"nyanpass"と挨拶するので
	// mapの最後尾(map::endの1つ前の要素)だけ調べればよい
	for (int nyan_index = 0; nyan_index < collection->size(); nyan_index++)
	{	
		if ((--(*collection)[nyan_index].end())->first == "nyanpass")
		{
			if (find == -1)
				find = nyan_index + 1;
			else
			{
				find = -1;
				break;
			}
		}
	}

	return find;
}


int main()
{
	vector<multimap<string, int>> nya_collection;
	int nya_max; cin >> nya_max;
	nya_collection.resize(nya_max);

	for (int i = 0; i < nya_max; i++)
		InputToCollection(&nya_collection, nya_max);

	cout << FindNyanpass(&nya_collection);

	return 0;
}
0