跳到正文

剪贴板

剪贴板 z1rgru0e

原文
剪贴板信息

剪贴板信息

收录
更新

测试点 3

C++
#include<bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ui = unsigned int;

mt19937 txn(chrono::system_clock::now().time_since_epoch().count());

const ull z = 1e9 + 7;

int lis[]={0,4,20,100,500,1500,5000,20000,100000,500000};
int n,m;
int p,q,k;
int f[410];
#define um unordered_map
bool flag=1;

inline ull hsh(ull a, ull b, ull c, ull d, ull e) {
	return
	   (a+1) * z * z * z * z * z
	 + (b+1) * z * z * z * z
	 + (c+1) * z * z * z
	 + (d+1) * z * z
	 + (e+1) * z;
}

#define must_be_now1 0
#define must_be_now2 340

unordered_map<ull, double> _mp1;
inline double &Mp1(int a, int b, int c, int d, int e) {
	return _mp1[hsh(a, b, c, d, e)];
}
unordered_map<ull, long long> _mp2;
inline long long &Mp2(int a, int b, int c, int d, int e) {
	return _mp2[hsh(a, b, c, d, e)];
}
unordered_map<ull, bool> _vis;
inline bool &Vis(int a, int b, int c, int d, int e) {
	return _vis[hsh(a, b, c, d, e)];
}
int mxans[10000010];

double dfs(int dep,long long a,long long b,long long c,int bm)
{
	mxans[dep]=max(mxans[dep],bm);
	if(bm<mxans[dep]-8)return 0;
	if(Vis(dep, a, b, c, bm)) return Mp1(dep, a, b, c, bm);
	Vis(dep, a, b, c, bm) = 1;
	pair<double,int> ans=make_pair(0,0);
	if(!a)
	{
		if(dep<=k)
		{
			if(f[dep]!=9&&f[dep]==b&&f[dep]==c)ans=max(ans,
				make_pair(dfs(dep+1,f[dep]+1,0,0,bm)+lis[f[dep]]+lis[f[dep]+1],3));
			else ans=max(ans,make_pair(dfs(dep+1,f[dep],b,c,bm)+lis[f[dep]],2));
		}
		if(b==c&&b!=9&&b!=0)ans=max(ans,make_pair(dfs(dep,b+1,0,0,bm)+lis[b]+lis[b+1]-must_be_now1-(unsigned int)txn()%10,1));
		if((b!=c||b==9||b==0)) ans=max(ans,make_pair(dfs(dep,1,b,c,bm)+lis[1]-must_be_now2-(unsigned int)txn()%10,-1));
	}
	if(!b)
	{
		if(dep<=k)
		{
			if(f[dep]!=9&&f[dep]==a&&f[dep]==c)ans=max(ans,
				make_pair(dfs(dep+1,0,f[dep]+1,0,bm)+lis[f[dep]]+lis[f[dep]+1],6));
			else ans=max(ans,make_pair(dfs(dep+1,a,f[dep],c,bm)+lis[f[dep]],5));
		}
		if(a==c&&a!=9&&a!=0)ans=max(ans,make_pair(dfs(dep,0,a+1,0,bm)+lis[a]+lis[a+1]-must_be_now1-(unsigned int)txn()%10,4));
		if((a!=c||a==9||a==0)) ans=max(ans,make_pair(dfs(dep,a,1,c,bm)+lis[1]-must_be_now2-(unsigned int)txn()%10,-2));
	}
	if(!c)
	{
		if(dep<=k)
		{
			if(f[dep]!=9&&f[dep]==a&&f[dep]==b)ans=max(ans,
				make_pair(dfs(dep+1,0,0,f[dep]+1,bm)+lis[f[dep]]+lis[f[dep]+1],9));
			else ans=max(ans,make_pair(dfs(dep+1,a,b,f[dep],bm)+lis[f[dep]],8));
		}
		if(a==b&&a!=9&&a!=0)ans=max(ans,make_pair(dfs(dep,0,0,a+1,bm)+lis[a]+lis[a+1]-must_be_now1-(unsigned int)txn()%10,7));
		if((a!=b||a==9||a==0)) ans=max(ans,make_pair(dfs(dep,a,b,1,bm)+lis[1]-must_be_now2-(unsigned int)txn()%10,-3));
	}
	if(a&&b&&c)
	{
		if(a&&bm)ans=max(ans,make_pair(dfs(dep,0,b,c,bm-1)-lis[a]/2,10));
		if(b&&bm)ans=max(ans,make_pair(dfs(dep,a,0,c,bm-1)-lis[b]/2,11));
		if(c&&bm)ans=max(ans,make_pair(dfs(dep,a,b,0,bm-1)-lis[c]/2,12));
	}
	Mp1(dep, a, b, c, bm) = ans.first;
	Mp2(dep, a, b, c, bm) = ans.second;
	return ans.first;
}
void fin(int dep,long long a,long long b,long long c,int bm)
{
	int k = Mp2(dep, a, b, c, bm);
	if(!k)
	{
		printf("END");
		return;
	}
	if(k==3)
	{
		printf("PUT 1 1\n");
		fin(dep+1,f[dep]+1,0,0,bm);
	}
	if(k==2)
	{
		printf("PUT 1 1\n");
		fin(dep+1,f[dep],b,c,bm);
	}
	if(k==1)
	{
		printf("STAR 1 1\n");
		fin(dep,b+1,0,0,bm);
	}
	if(k==6)
	{
		printf("PUT 1 2\n");
		fin(dep+1,0,f[dep]+1,0,bm);
	}
	if(k==5)
	{
		printf("PUT 1 2\n");
		fin(dep+1,a,f[dep],c,bm);
	}
	if(k==4)
	{
		printf("STAR 1 2\n");
		fin(dep,0,a+1,0,bm);
	}
	if(k==9)
	{
		printf("PUT 1 3\n");
		fin(dep+1,0,0,f[dep]+1,bm);
	}
	if(k==8)
	{
		printf("PUT 1 3\n");
		fin(dep+1,a,b,f[dep],bm);
	}
	if(k==7)
	{
		printf("STAR 1 3\n");
		fin(dep,0,0,a+1,bm);
	}
	if(k==10)
	{
		printf("BOMBER 1 1\n");
		fin(dep,0,b,c,bm-1);
	}
	if(k==11)
	{
		printf("BOMBER 1 2\n");
		fin(dep,a,0,c,bm-1);
	}
	if(k==12)
	{
		printf("BOMBER 1 3\n");
		fin(dep,a,b,0,bm-1);
	}
	if(k==-1)
	{
		printf("STAR 1 1\n");
		fin(dep,1,b,c,bm);
	}
	if(k==-2)
	{
		printf("STAR 1 2\n");
		fin(dep,a,1,c,bm);
	}
	if(k==-3)
	{
		printf("STAR 1 3\n");
		fin(dep,a,b,1,bm);
	}
}
string s;
int main()
{
	freopen("tritown3.in", "r", stdin);
	freopen("tritown3.out","w",stdout);
	scanf("%d%d",&n,&m);
	scanf("%d%d",&p,&q);
	cin>>s;
	scanf("%d",&k);
	for(int i=1;i<=k;++i)scanf("%d",f+i);
	dfs(1,0,0,0,q);
	fin(1,0,0,0,q);
	return 0;
}