QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295138#4828. Four Plus Fourucup-team191#0 0ms0kbC++232.8kb2023-12-30 19:22:532023-12-30 19:22:53

Judging History

你现在查看的是最新测评结果

  • [2023-12-30 19:22:53]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-12-30 19:22:53]
  • 提交

answer

#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
#define pb push_back
#define all(a) begin(a),end(a)

mt19937 rng(32984);

const int N=300010,MOD=1e9+7;
const char en='\n';
const ll LLINF=1ll<<60;

int n,m,q,usKe[N];
string ti;
vector<pair<string,string>> qu;
vector<string> va,vb;
bool uz[4000][4000],uz2[4000];
map<string,vector<string>> pass;
map<pair<string,string>,string> keys;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	freopen("inpF.txt","r",stdin);
	cin>>ti>>q;
	while (q--)
	{
		string a,b;
		if (ti=="password") cin>>a,b="?";
		else cin>>a>>b;
		qu.pb({a,b});
	}
	cin>>n;
	for (int i=0;i<n;++i)
	{
		string x;
		cin>>x;
		va.pb(x);
	}
	cin>>m;
	for (int i=0;i<m;++i)
	{
		string x;
		cin>>x;
		vb.pb(x);
	}
	vector<set<int>> canKey(n);
	vector<set<int>> canKeyInv(m);
	int ccant=0,sumsiz=0;
	for (int i=0;i<n;++i)
	{
		vi cn(256);
		for (auto x: va[i]) ++cn[x];
		for (int j=0;j<m;++j)
		{
			bool ok=1;
			for (auto x: vb[j])
			{
				--cn[x];
				if (cn[x]<0) ok=0;
			}
			for (auto x: vb[j]) ++cn[x];
			if (ok) canKey[i].insert(j),canKeyInv[j].insert(i),++sumsiz;
		}
		if (canKey[i].size()<=2) ++ccant;
	}
	set<pii> mog;
	for (int i=0;i<n;++i) if (canKey[i].size()>=3) mog.insert({canKey[i].size(),i});
	int narp=0;
	while (mog.size())
	{
		int i=mog.begin()->y;
		mog.erase(mog.begin());
		++narp;
		vi v(all(canKey[i]));
		shuffle(all(v),rng);
		//random_shuffle(all(v));
		int cv=v.size();
		/*if (narp==236)
		{
			cout<<narp<<' '<<va[i]<<en;
			for (auto x: v) cout<<x<<' ';
			cout<<en;
			for (auto x: v)
			{
				for (auto y: v) cout<<uz[x][y];
				cout<<en;
			}
			cout<<en;
			for (auto x: v) cout<<uz2[x];
			cout<<en<<en;
		}*/
		bool nap=0;
		for (int a=0;a<cv;++a) for (int b=a+1;b<cv;++b) for (int c=b+1;c<cv;++c)
		{
			if (nap) continue;
			int x=v[a],y=v[b],z=v[c];
			if (!uz[x][y] && !uz[y][z] && !uz[x][z])
			{
				uz[x][y]=uz[y][x]=uz[x][z]=uz[z][x]=uz[y][z]=uz[z][y]=1;
				pass[va[i]]={vb[x],vb[y],vb[z]};
				keys[{vb[x],vb[y]}]=va[i];
				keys[{vb[x],vb[z]}]=va[i];
				keys[{vb[y],vb[x]}]=va[i];
				keys[{vb[y],vb[z]}]=va[i];
				keys[{vb[z],vb[x]}]=va[i];
				keys[{vb[z],vb[y]}]=va[i];
				nap=1;
			}
		}
		if (!nap)
		{
			for (int a=0;a<cv;++a) if (!uz2[v[a]])
			{
				if (nap) continue;
				pass[va[i]]={vb[v[a]],vb[v[a]],vb[v[a]]};
				keys[{vb[v[a]],vb[v[a]]}]=va[i];
				uz2[v[a]]=1;
				nap=1;
			}
			if (!nap)
			{
				cout<<"X"<<narp<<' '<<v.size()<<en;
			}
		}
	}
	for (auto x: qu)
	{
		if (x.y=="?")
		{
			for (auto z: pass[x.x]) cout<<z<<' ';
			cout<<endl;
		}
		else
		{
			cout<<keys[x]<<endl;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer on the first run

input:

password
2
password
couthier
28558
aardvark aardwolf aasvogel abacuses abalones abampere abandons abapical abasedly abashing abatable abatises abattoir abbacies abbatial abbesses abdicate abdomens abdomina abducens abducent abducing abducted abductee abductor abelmosk aberrant abetment abettals abet...

output:


input:


output:


result:

wrong output format Unexpected end of file - token expected