Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]
2 seconds
256 megabytes
standard input
standard output
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the army by destroying one detail of the i-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 most k shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?
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 contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of details of the i-th type for the respective robot.
Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-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.
5 2 4
4 0
1 2
2 1
0 2
1 3
2 2
3 2 4
1 2
1 3
2 2
1 3
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.
题解如标题,线段树+线性扫一遍即可~~~
9855946 | 2015-02-15 10:16:13 | njczy2010 | D - R2D2 and Droid Army | GNU C++ | Accepted | 186 ms | 27412 KB |
9855894 | 2015-02-15 10:10:30 | njczy2010 | D - R2D2 and Droid Army | GNU C++ | Wrong answer on test 6 | 15 ms | 27400 KB |
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 100005
#define M 1505
//#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
//#define inf 2147483647
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll n,m,k;
ll ma;
ll ans[]; typedef struct
{
ll t[];
}PP;
PP a[N];
PP tree[*N]; PP build(ll i,ll l,ll r)
{
//printf(" i=%I64d l=%I64d r=%I64d\n",i,l,r);
if(l==r){
tree[i]=a[l];
return tree[i];
}
PP le,ri;
ll mid=(l+r)/;
le=build(*i,l,mid);
ri=build(*i+,mid+,r);
ll j;
for(j=;j<=m;j++){
tree[i].t[j]=max(le.t[j],ri.t[j]);
}
return tree[i];
} PP query(ll i,ll l,ll r,ll L,ll R)
{
//printf(" i=%I64d l=%I64d r=%I64d L=%I64d R=%I64d\n",i,l,r,L,R);
if(l>=L && r<=R) return tree[i];
ll mid;
mid=(l+r)/;
PP le,ri,re;
ll j;
for(j=;j<=m;j++){
le.t[j]=ri.t[j]=;
}
if(mid>=L){
le=query(i*,l,mid,L,R);
}
if(mid<R){
ri=query(i*+,mid+,r,L,R);
}
for(j=;j<=m;j++){
re.t[j]=max(le.t[j],ri.t[j]);
}
return re;
} void ini()
{
memset(ans,,sizeof(ans));
ma=;
ll i,j;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
scanf("%I64d",&a[i].t[j]);
}
}
//printf(" bb\n");
build(,,n);
} void solve()
{
ll st,en;
st=;
en=;
ll now=;
PP re;
ll j;
for(j=;j<=m;j++){
re.t[j]=;
}
while(en<n)
{
en++;
now=;
for(j=;j<=m;j++){
re.t[j]=max(re.t[j],a[en].t[j]);
now+=re.t[j];
}
while(now>k){
st++;
if(st>en){
for(j=;j<=m;j++){
re.t[j]=;
}
break;
}
re=query(,,n,st,en);
now=;
for(j=;j<=m;j++){
now+=re.t[j];
}
//printf(" st=%I64d en=%I64d now=%I64d\n",st,en,now);
}
if(now>k) continue;
// printf(" st=%I64d en=%I64d now=%I64d ma=%I64d\n",st,en,now,ma);
if(en-st+>ma){
ma=en-st+;
for(j=;j<=m;j++){
ans[j]=re.t[j];
}
}
}
} void out()
{
printf("%I64d",ans[]);
ll i;
for(i=;i<=m;i++){
printf(" %I64d",ans[i]);
}
printf("\n");
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
//scanf("%d%d",&n,&m);
while(scanf("%I64d%I64d%I64d",&n,&m,&k)!=EOF)
{
ini();
solve();
out();
}
return ;
}
最新文章
- linux之netstat命令
- 使用RequireJs和Bootstrap模态框实现表单提交
- python下ssh的简单实现
- 将csv文件读入数据库
- 图像预处理第9步:存为.bmp文件
- Eclipse 工程迁移到 Android Studio
- centos7 systemctl命令
- 【WinRT】国内外 Windows 应用商店应用开发者博客收集
- iOS开发——图形编程OC篇&;粘性动画以及果冻效果
- cocos2d-x lua脚本开发 1
- 探讨SQL Server并发处理队列数据不阻塞解决方案
- jquery表单序列化
- Linux乱码问题解决
- Android WebKit 内核
- Android为TV端助力之解决setOnItemSelectedListener一进来就自动执行一次的问题
- 关于学习CentOS7使用firewalld打开关闭防火墙和端口
- Linux 线程实现模型
- SVN简单使用
- PHY过采样问题
- vue中输入框聚焦,自动跳转下一个输入框