比赛 20120806 评测结果 AAWATTTTTT
题目名称 符文之语 最终得分 30
用户昵称 feng 运行时间 6.103 s
代码语言 C++ 内存使用 11.76 MiB
提交时间 2012-08-06 10:48:50
显示代码纯文本
#include<cstdio>
using namespace std;
int m,i,j,n,k,maxn,t,maxm,l,ki,kx,minm,minn;
int f[1001][1001];
int q[1001][1001];
int a[1001][1001];
char s[1001];
int main()
{
	freopen("chars.in","r",stdin);
	freopen("chars.out","w",stdout);
	scanf("%s",&s);
	scanf("%d",&m);
	n=0;
	while (s[n]<='9' && s[n]>'0')
		n++;
	for (i=n;i>=1;i--)
		s[i]=s[i-1];
	for (i=1;i<=n;i++)
		for (j=i;j<=n;j++){
			a[i][j]=0;
			for (k=i;k<=j;k++)
				a[i][j]=(a[i][j]*10+s[k]-'0')%m;
		}

		for (i=1;i<=n;i++){
			f[i][0]=a[1][i];
			q[i][0]=a[1][i];
			for (j=1;j<=n;j++){
				maxn=0;
				minn=100000000;
				for (k=2;k<=i;k++){
					t=f[k-1][j-1]*a[k][i]%m;
					if (t>maxn) maxn=t;
					t=q[k-1][j-1]*a[k][i]%m;
					if (t<minn) minn=t;
				}
				f[i][j]=maxn;
				q[i][j]=minn;
			}
		}
		maxm=a[1][n];
		ki=0;
		minm=a[1][n];
		kx=0;
	for (i=0;i<n;i++){
		if (f[n][i]>maxm){
			maxm=f[n][i];
			kx=i;
		}
		if (q[n][i]<minm){
			minm=q[n][i];
			ki=i;
		}
	}
	printf("%d %d %d %d",minm,ki,maxm,kx);
	return 0;
}