當前位置:首頁 > 芯聞號 > 充電吧
[導讀]【CF簡介】提交鏈接:CF 514D題面:D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 25

【CF簡介】

提交鏈接:CF 514D


題面:


D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

An army of n droids is lined up in one row. Each droid is described bym integers a1,?a2,?...,?am, whereai is the number of details of thei-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He hasm weapons, the i-th weapon can affect all the droids in the army by destroying one detail of thei-th type (if the droid doesn't have details of this type, nothing happens to it).

A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at mostk shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?

Input

The first line contains three integers n,?m,?k (1?≤?n?≤?105, 1?≤?m?≤?5, 0?≤?k?≤?109) — the number of droids, the number of detail types and the number of available shots, respectively.

Next n lines follow describing the droids. Each line containsm integers a1,?a2,?...,?am (0?≤?ai?≤?108), where ai is the number of details of thei-th type for the respective robot.

Output

Print m space-separated integers, where thei-th number is the number of shots from the weapon of thei-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.

If there are multiple optimal solutions, print any of them.

It is not necessary to make exactly k shots, the number of shots can be less.

Examples Input

5?2?4
4?0
1?2
2?1
0?2
1?3

Output

2?2

Input

3?2?4
1?2
1?3
2?2

Output

1?3

Note

In the first test the second, third and fourth droids will be destroyed.

In the second test the first and second droids will be destroyed.



題意:

???? 有n個有序排列的機器人,每個機器人有m項屬性,每個機器人的每項屬性并不統(tǒng)一。要消滅一個機器人,需要將他的每項屬性值都減為1,現(xiàn)在有k次操作機會,每次操作可以將每個機器人的某項屬性值都減1,問在不超過k次操作的情況下,如何分配每項屬性減幾次,可以使得最終消滅最多的連續(xù)機器人序列,輸出分配攻擊方案。

???? 注意:如果不能全部消滅,則每項輸出0,因為要求消耗盡量少的操作數(shù),達到殺死盡量多連續(xù)的機器人。


解題:

???? RMQ,區(qū)間詢問問題,可以做到O(nlogn)復雜度預處理,O(log n)復雜度詢問,入門ST算法,可以看這篇博客,通過RMQ預處理好每項屬性,區(qū)間最大值。

???? 隨后詢問時,只要查詢出該區(qū)間每項屬性的最大值,隨后將這些最大值累加,即為消滅該區(qū)間全部機器人的最小操作次數(shù)。

???? 枚舉左端點,二分右區(qū)間,若區(qū)間需要操作數(shù)大于k,則左移右區(qū)間,縮小區(qū)間長度,若小于等于k則,右移右區(qū)間,增大區(qū)間長度。在二分過程中更新區(qū)間最優(yōu)值,同時還需記錄此時的分配情況,若區(qū)間長度相等的情況下,還需保證操作數(shù)盡量小。


代碼:


#include#include#include#include#include#include#include#include#define?LL?long?long
#define?maxn?100010
#define?sq(a)??1LL*(a)*(a)
#define?mod?1000000007
using?namespace?std;
int?arr[maxn][5],d[maxn][5][20],path[5],tmp[5];
int?n,m,k;
void?init()
{
??for(int?i=0;i<n;i++)
	??for(int?j=0;j<m;j++)
		??d[i][j][0]=arr[i][j];
??for(int?j=1;(1<<j)<=n;j++)
	??for(int?i=0;i+(1<<j)-1<n;i++)
		??for(int?k=0;k<m;k++)
			??d[i][k][j]=max(d[i][k][j-1],d[i+(1<<(j-1))][k][j-1]);
}
int?RMQ(int?le,int?ri)
{
	int?k=0,res=0;
	for(int?i=0;i<m;i++)
	{
		k=0;
		while((1<<(k+1))<=ri-le+1)
			k++;
		tmp[i]=max(d[le][i][k],d[ri-(1<<k)+1][i][k]);
		res+=tmp[i];
	}
	return?res;
}
void?update()
{				?
??for(int?j=0;j<m;j++)
	path[j]=tmp[j];
}
int?main()
{
	int?le,ri,temp,ans=0,ansk=0x3f3f3f3f;
	bool?flag=0;
	scanf("%d%d%d",&n,&m,&k);
????for(int?i=0;i<n;i++)
		for(int?j=0;j<m;j++)
			scanf("%d",&arr[i][j]);
	init();

	for(int?i=0;i<n;i++)
	{
??????le=i;
??????ri=n-1;
	??if(ri-le+1<ans)
		??break;
	??while(le>1;
		?temp=RMQ(i,mid);
		?if(tempans)
			?{
				?ansk=temp;
				?ans=mid-i+1;
				?update();
			?}
			?else?if(mid-i+1==ans)
			?{
				?if(ansk>temp)
				?{
					ansk=temp;
????????????????????update();
				?}
			?}
			?le=mid+1;
		?}
		?else
		?{
			?ri=mid-1;
			?if(ri-i+1<ans)
				?break;
		?}
	??}
	}
	printf("%d",path[0]);
	for(int?i=1;i<m;i++)
		printf("?%d",path[i]);
	printf("n");
	return?0;
}



本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或將催生出更大的獨角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據媒體報道,騰訊和網易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據產業(yè)博覽會開幕式在貴陽舉行,華為董事、質量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據產業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經營業(yè)績穩(wěn)中有升 落實提質增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數(shù)字經濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯(lián)合牽頭組建的NVI技術創(chuàng)新聯(lián)盟在BIRTV2024超高清全產業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術創(chuàng)新聯(lián)...

關鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉