結果

問題 No.239 にゃんぱすー
ユーザー tkr987tkr987
提出日時 2018-07-28 22:48:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,543 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 70,688 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-09-20 17:26:03
合計ジャッジ時間 2,057 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 9 ms
4,556 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 6 ms
4,380 KB
testcase_35 AC 8 ms
4,380 KB
testcase_36 AC 9 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

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