結果
問題 | No.239 にゃんぱすー |
ユーザー |
![]() |
提出日時 | 2018-07-29 18:22:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 2,959 bytes |
コンパイル時間 | 862 ms |
コンパイル使用メモリ | 81,804 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-18 09:22:31 |
合計ジャッジ時間 | 1,909 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
#include <iostream>#include <map>#include <string>#include <vector>using namespace std;/**@breif にゃんぱす格納関数@param collection 格納する挨拶コンテナ@note入力を1行だけコンテナに格納する。vectorは村民1に対する相手jの挨拶が格納される。mapには村民jの村民1相手以外の挨拶が格納される。つまり、vectorが挨拶行列の列、mapが挨拶行列の行を指す。**/void InputToCollection(vector<multimap<string, int>>* collection){for (int i = 0; i < (int)collection->size(); i++){ // mapのキーのみ使用する、mapの値は使用しないので適当な数字を入れておくstring word; cin >> word;(*collection)[i].emplace(word, 0);}}/**@breif にゃんぱす検索関数@param collection 検索する村人の挨拶コンテナ@retval [1-INT_MAX] れんちょんの村民番号@retval -1 れんちょんを特定できない@noteこの関数はテストケースの穴を突いている。たとえば- nyanpass ohayoa - chicchakunaiyonyanpass nyanpass -この場合、村民1は村民2に対してnyanpassと挨拶してないので-1が正解な気がする。しかし、nyanpassより値の小さいテストケースが存在しないのかmapの最後尾だけ調べてもACが通った。より正確な検索関数はFindNyanpassII()で実装。**/int FindNyanpass(vector<multimap<string, int>>* collection){int find = -1;// れんちょんは誰に対しても"nyanpass"と挨拶するので// mapの最後尾(map::endの1つ前の要素)だけ調べて判断するfor (int nyan_index = 0; nyan_index < (int)collection->size(); nyan_index++){if ((--(*collection)[nyan_index].end())->first == "nyanpass"){if (find == -1)find = nyan_index + 1;else{find = -1;break;}}}return find;}/**@breif にゃんぱす検索関数II@param collection 検索する村人の挨拶コンテナ@retval [1-INT_MAX] れんちょんの村民番号@retval -1 れんちょんを特定できない**/int FindNyanpassII(vector<multimap<string, int>>* collection){int find = -1;// れんちょんは誰に対しても"nyanpass"と挨拶するので// "nyanpass"キーが村民-1個存在するか調べて判断するfor (int nyan_index = 0; nyan_index < (int)collection->size(); nyan_index++){if ((*collection)[nyan_index].count("nyanpass") == collection->size() - 1){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);// nya_max 繰り返して全ての入力をコンテナに格納for (int i = 0; i < nya_max; i++)InputToCollection(&nya_collection);cout << FindNyanpass(&nya_collection);// cout << FindNyanpassII(&nya_collection);return 0;}