/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Accepted 4ms 4.375 MiB
#2 Accepted 4ms 4.363 MiB
#3 Accepted 4ms 4.371 MiB
#4 Accepted 9ms 10.73 MiB
#5 Accepted 42ms 34.73 MiB
#6 Accepted 55ms 37.0 MiB
#7 Accepted 388ms 154.621 MiB
#8 Accepted 442ms 201.461 MiB
#9 Wrong Answer 522ms 203.352 MiB
#10 Accepted 844ms 239.223 MiB

代码

#include <stdio.h>
#include <iostream>
#define inf 1e9
using namespace std;
inline int read() {
	int k=0;
	char f=1;
	char c=getchar();
	for(; !isdigit(c); c=getchar() )
		if(c=='-')
			f=-1;
	for(; isdigit(c); c=getchar() )
		k=k*10+c-'0';
	return k*f;
}
int n,m,t;
int s[5005][2003],a[5005][2003],ans[2500],Max[5002][2003],Min[5002][2500],MaxID[5002][2003],MinID[5002][2003],Q[2003];

void get_min(int line) {
	int head,tail,i;
	head=1;
	tail=1;
	Q[tail]=1;
	Min[line][1]=s[line][0];
	for (i=1; i<=n; i++) {
		while ((head<=tail)&&(s[line][i]<s[line][Q[tail]]))
			tail--;
		Q[++tail]=i;
		while ((head<=tail)&&(Q[head]<i-t+1))
			head++;

		Min[line][i]=s[line][Q[head]];
		MinID[line][i] = Q[head];
	}
}
void get_max(int line) {
	int head,tail,i;
	head=1;
	tail=1;
	Q[tail]=1;
	Max[line][1]=s[line][0];
	for (i=1; i<=n; i++) {
		while ((head<=tail)&&(s[line][i]>s[line][Q[tail]]))
			tail--;
		Q[++tail]=i;
		while ((head<=tail)&&(Q[head]<i-t+1))
			head++;

		Max[line][i]=s[line][Q[head]];
		MaxID[line][i] = Q[head];
	}
}
void solve2(int line) {
	int minid = 1,maxid = 0;
	for(int k = 1; k<=t; k++) {
		for(int i = k; i<=n; i++) {
			for(int j = i-k+1; j<=i; j++) {
				if(s[line][i]-s[line][j-1]>s[line][maxid]-s[line][minid-1]) {
					maxid = i,minid = j;
				} else if(s[line][i]-s[line][j-1]==s[line][maxid]-s[line][minid-1]) {
					if(i-j>maxid-minid) {
						maxid = i,minid = j;
					}
				}
			}
		}
	}
	if(minid==1&&maxid==0)return;
	for(int i = minid; i<=maxid; i++) ans[i]++;
}
void solve(int line) {
	int minid = 0,maxid = 0;
	get_max(line);
	get_min(line);
	int maxx = 0;
	for(int i = 1; i<=n; i++) {
		if((!maxid&&!minid)||(Max[line][i]-Min[line][i]>maxx&&MaxID[line][i]-MinID[line][i]>0)) {
			maxid = MaxID[line][i];
			minid = MinID[line][i]+1;
			maxx = Max[line][i] - Min[line][i];
		} else if(Max[line][i]-Min[line][i]==maxx&&MaxID[line][i]-MinID[line][i]-1>maxid-minid) {
			maxid = MaxID[line][i];
			minid = MinID[line][i]+1;
			maxx = Max[line][i] - Min[line][i];
		}
	}
	if(minid==0&&maxid==0)return;
	for(int i = minid; i<=maxid; i++) {
		if(i-t>0)
			ans[i-t]++;
	}
}
int main() {
	n =read();
	m = read();
	t = read();
	if(n<50) {
		for(int i = 1; i<=m; i++) {
			for(int j = 1; j<=n; j++) {
				a[i][j] = read();
				s[i][j] = s[i][j-1]+a[i][j];
			}
		}
		for(int i = 1; i<=m; i++) solve2(i);
		for(int i = 1; i<=n; i++) cout<<ans[i]<<" ";
		return 0;
	}
	t++;

	for(int i = 1; i<=m; i++) {
		for(int j = 1; j<=n; j++) {
			a[i][j] = read();
			s[i][j+t] = s[i][(j-1)+t]+a[i][j];
		}
	}
	n+=t;
	if(n>50)
		for(int i = 1; i<=m; i++) solve(i);
	else {

		for(int i = 1; i<=m; i++) solve2(i);

	}
	n-=t;
	for(int i = 1; i<=n; i++) cout<<ans[i]<<" ";
	return 0;
}

信息

递交者
类型
递交
题目
骂战(原创)
题目数据
下载
语言
C++
递交时间
2017-10-12 20:55:29
评测时间
2017-10-12 20:55:39
评测机
分数
90
总耗时
2319ms
峰值内存
239.223 MiB