这个为什么莫名其妙TLE了?本地是可以过的
  • 板块P2814 家谱
  • 楼主Jianbing_Juan
  • 当前回复13
  • 已保存回复13
  • 发布时间2023/9/20 23:56
  • 上次更新2023/11/2 18:55:23
查看原帖
这个为什么莫名其妙TLE了?本地是可以过的
940854
Jianbing_Juan楼主2023/9/20 23:56

rt.

评测记录

本蒟蒻使用STL,不喜勿喷。

本地测,洛谷在线IDE测都是没有问题的。而且我提交是删了 freopen 的。

code:

#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;

int main()
{
	//freopen("P2814_1.in","r",stdin);
	//freopen("P2814_1_ans.out","w",stdout);
	map<string,string> mp;
	string anc,son,sch;
	char ch='\0';
	while(ch!='$')
	{
		ch=getchar();
		if(ch=='$')break;
		if(ch=='#')
		{
			cin>>anc;
			if(mp.find(anc)==mp.end())
			{
				mp[anc]="######";
			}
		}
		else if(ch=='+')
		{
			cin>>son;
			
			mp[son]=anc;
		}
		else
		{
			cin>>sch;
			while(mp[sch]!="######")
			{
				sch=mp[sch];
			}
			cout<<sch<<endl;
		}
		getchar();
	}
}
2023/9/20 23:56
加载中...