/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:102:25: warning: 'kt' may be used uninitialized in this function [-Wmaybe-uninitialized]
      else ans[j].left=kt+1;
                       ~~^~
# 状态 耗时 内存占用
#1 Accepted 3ms 360.0 KiB
#2 Accepted 3ms 356.0 KiB
#3 Accepted 3ms 356.0 KiB
#4 Accepted 6ms 380.0 KiB
#5 Accepted 31ms 344.0 KiB
#6 Accepted 32ms 384.0 KiB
#7 Accepted 260ms 476.0 KiB
#8 Accepted 400ms 512.0 KiB
#9 Accepted 425ms 476.0 KiB
#10 Accepted 565ms 500.0 KiB

代码

#include<bits/stdc++.h>
using namespace std;
int m,n,t;
struct node
{
	int left,num;
}ans[1001];
int a[1001],tt[1001];
inline const void read(int &a)
{
	a=0;
	int k=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		k=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
	a*=k;
} 
int main()
{
	//freopen("9.in.txt","r",stdin);
	//freopen("9.out.txt","w",stdout);
	cin>>n>>m>>t;
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<=1001&&ans[j].left;j++)
		{
			ans[j].left=0;
			ans[j].num=0;
		}
		int front=0,rail=0,MAX=0;
		for(int j=1;j<=n;j++)
		{
			read(a[j]);
			if(ans[j-1].num==0&&ans[j-1].left==0)
			{
				ans[j].left=j;
				ans[j].num=a[j];
				MAX=a[j];
				front=j;
				rail=j;
	//			cout<<"1"<<endl;
	//			cout<<"j="<<j<<" MAX="<<MAX<<" front="<<front<<" rail="<<rail<<endl;
			}
			else if(ans[j-1].num<0)
			{
				ans[j].left=j;
				ans[j].num=a[j];
				if(MAX<=ans[j].num)
				{
					MAX=ans[j].num;
					front=j;
					rail=j;
	//				cout<<"j="<<j<<" MAX="<<MAX<<" front="<<front<<" rail="<<rail<<endl;
				}
	//			cout<<"2"<<endl;
			}
			else if(ans[j-1].num>=0)
			{
				if(j-ans[j-1].left<=t-1)
				{
					ans[j].left=ans[j-1].left;
					ans[j].num=ans[j-1].num+a[j];
					if(ans[j].num>=MAX)
					{
						MAX=ans[j].num;
						front=ans[j].left;
						rail=j;
					//cout<<"j="<<j<<" MAX="<<MAX<<" front="<<front<<" rail="<<rail<<endl;
					}
					//cout<<"3"<<endl;
	//				cout<<"ans["<<j<<"].num="<<ans[j].num<<" ans["<<j<<"].left="<<ans[j].left<<endl<<endl;
	//				int ww=0;
	//				for(int sa=ans[j].left;sa<=j;sa++)
	//					ww+=a[sa];
	//				cout<<"ww="<<ww<<endl;
					
				}
				else if(j-ans[j-1].left>t-1)
				{
					int ks=ans[j-1].num+a[j],MAX1=-100000,kt;
					for(int ss=ans[j-1].left;ss<j;ss++)
					{
						ks-=a[ss];
						if(ks>MAX1)
						{
							MAX1=ks;
							kt=ss;
						}
					}
					ans[j].num=max(MAX1,a[j]);
					if(ans[j].num==a[j])
					ans[j].left=j;
					else ans[j].left=kt+1;
					if(ans[j].num>=MAX)
					{
						MAX=ans[j].num;
						front=ans[j].left;
						rail=j;
						//cout<<"j="<<j<<" MAX="<<MAX<<" front="<<front<<" rail="<<rail<<endl;
					} 
					//cout<<"4"<<endl;
	//				cout<<"ans["<<j<<"].num="<<ans[j].num<<" ans["<<j<<"].left="<<ans[j].left<<endl<<endl;
	//				int ww=0;
	//				for(int sa=ans[j].left;sa<=j;sa++)
	//					ww+=a[sa];
	//				cout<<"ww="<<ww<<endl;
				}
			}
		}
	//	cout<<"i="<<i<<" front="<<front<<" rail="<<rail<<endl;
		for(int j=front;j<=rail;j++)
		tt[j]++;
	}	
	for(int i=1;i<=n;i++)
	cout<<tt[i]<<' ';
	cout<<endl;
	return 0;
}

信息

递交者
类型
递交
题目
骂战(原创)
题目数据
下载
语言
C++
递交时间
2017-10-12 16:02:04
评测时间
2017-10-12 17:07:15
评测机
分数
100
总耗时
1733ms
峰值内存
512.0 KiB