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 ;
}
Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]的更多相关文章
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树
C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp
D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心
B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...
- Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)
题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...
- Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP
题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...
随机推荐
- UVA - 1395 Slim Span (最小生成树Kruskal)
Kruskal+并查集. 点很少,按边权值排序,枚举枚举L和R,并查集检查连通性.一旦连通,那么更新答案. 判断连通可以O(1),之前O(n)判的,第一次写的过了,后来T.. #include< ...
- ndarray数组变换
import numpy as np 维度变换 a = np.arange(24) a array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ...
- C#中Json进行序列化时去掉值为null的节点
当我们用json文件为数据源时,并对json数据进行操作时可能会产生一些数值为null的节点生成,想要去掉null的节点需要一些操作 本文用一个简单的工具对json进行操作 工具:Newtonsoft ...
- Java数据结构和算法(五)--希尔排序和快速排序
在前面复习了三个简单排序Java数据结构和算法(三)--三大排序--冒泡.选择.插入排序,属于算法的基础,但是效率是偏低的,所以现在 学习高级排序 插入排序存在的问题: 插入排序在逻辑把数据分为两部分 ...
- Python 类变量,成员变量,静态变量,局部变量
局部 class TestClass(object): val1 = 100 def __init__(self): self.val2 = 200 def fcn(self,val = 400): ...
- Python字符编码及字符串
字符编码 字符串是一种数据类型,但是字符串比较特殊的是编码问题,计算机只能处理数字,处理文本就需要将文本转换成数字. 计算机设计时8bit作为一个字节byte,一个字节能表示的最大整数就是(2^8)- ...
- Bootstrap CSS概览
HTML5文档类型(<!DOCTYPE html>) Bootstrap前端框架使用了HTML5和CSS属性,为了让这些能正常工作,您需要使用HTML5文档类型(<!DOCTYPE ...
- graphviz 布局和子图,表格教程
有了这三个利器,就搞定架构图了. 子图间互相调用要开启 http://graphviz.org/pdf/dotguide.pdf
- __new__.py
def func(self): print('hello %s' %self.name)def __init__(self,name,age): self.name = name self.age = ...
- 在/etc/crondtab中添加定时任务注意事项
1 要添加用户名 2 要重启定时任务服务