LUXURY 8

A - Gargari and Bishops

Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 463C

Description

Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.

He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.

We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).

Input

The first line contains a single integer n(2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij(0 ≤ aij ≤ 109) — description of the chessboard.

Output

On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2(1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to nfrom left to right.

If there are several optimal solutions, you can print any of them.

Sample Input

Input

41 1 1 12 1 1 01 1 1 01 0 0 1

Output

122 2 3 2

 做这道题会碰到2个问题:

1.如何很方便的得到每个“X”的值?经过yy可以发现矩阵上在"/"这种形状上i+j都为定值,而在"\"上i + n - j为定值,所以预处理出“\" , "/"对应的数组,然后你就能在O(1)时间内得到每个”X"

2.如何能很快的知道两个“X",符合题设的条件?多画几次你就会发现i+j为奇数,和偶数是,那两个叉肯定不会存在公共点。

观察很重要啊

B - Bits

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 485C

Description

Let‘s denote as  the number of bits set (‘1‘ bits) in the binary representation of the non-negative integer x.

You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and  is maximum possible. If there are multiple such numbers find the smallest of them.

Input

The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).

Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).

Output

For each query print the answer in a separate line.

Sample Input

Input

31 22 41 10

Output

137

Hint

The binary representations of numbers from 1 to 10 are listed below:

110 = 12

210 = 102

310 = 112

410 = 1002

510 = 1012

610 = 1102

710 = 1112

810 = 10002

910 = 10012

1010 = 10102

一个纯粹的贪心,可以按位一步一步贪。

C - No to Palindromes!

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 465C

Description

Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and sdoesn‘t contain any palindrome contiguous substring of length 2 or more.

Paul has found a tolerable string s of length n. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.

Input

The first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).

Output

If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes).

Sample Input

Input

3 3cba

Output

NO

Input

3 4cba

Output

cbd

Input

4 4abcd

Output

abda

Hint

String s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s1 = t1, ..., si = ti,si + 1 > ti + 1.

The lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.

A palindrome is a string that reads the same forward or reversed.

一道构造题,构造题真是。。。。。

要做这道题,有个结论非常重要,那就是只有“部分对称” , 才会有可能性造成“整体堆成”,所以只要破坏所有“部分对称“,就行了。

而部分对称只有两种形式”aa” , “aba”

D - George and Job

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 467C

Description

The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn‘t have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.

Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers:

[l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 < l2 ≤ r2 < ... < lk ≤ rk ≤ nri - li + 1 = m), 

in such a way that the value of sum  is maximal possible. Help George to cope with the task.

Input

The first line contains three integers nm and k(1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn(0 ≤ pi ≤ 109).

Output

Print an integer in a single line — the maximum possible value of sum.

Sample Input

Input

5 2 11 2 3 4 5

Output

9

Input

7 1 32 10 7 18 5 33 0

Output

61

一道裸的dp,一开始需要转移的状态没有想清楚,然后学长提醒后,很快就想到了,我用dp[前i个人][j个组] = max (当前i为第j组的最后一人 ,dp[i-1][j])

转移的状态真心要想清楚啊。

时间: 2025-01-22 20:20:16

LUXURY 8的相关文章

A Diesel is a luxury watch brand that is known to all the classes

When worn with almost any type of clothes, these watches can help you attain the charm of a dictator. Consider a brand such as Diesel. A Diesel is a luxury watch brand that is known to all the classes in the society. Former Iraqi President Saddam Hus

LUXURY 7

A.Little Pony and Expected Maximum Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 454C Description Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutte

根据76大细分词性对单词进行归组(二)

词性的重要性不言而喻,尤其是对于自然语言处理来说,哪怕就是记单词,根据词性对单词进行归组也是非常有帮助的. superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 各大词性及其包括的词: 32.N-COUNT-COLL(可数集合名词) (词数:50) 1 aristocracy army array audience band 2 cast chapter command commission committee 3 co

[POI2014]HOT-Hotels

https://www.luogu.org/problem/show?pid=3565 枚举中间点 枚举中间点的子树 枚举距离 如果只有3个子树,那么对答案的贡献为a*b*c 假设现在来了第4个子树,那么答案会增加 d*(a*b+a*c+b*c) 再来第5个,答案增加e*(a*b+a*c+a*d+b*c+b*d+c*d) 括号里的数好像有点儿规律 用c2维护来维护它 d*(a*b+a*c+b*c)变到 e*(a*b+a*c+a*d+b*c+b*d+c*d) 增加了 e*(a+b+c) 所以用再用

Linux Netcat command – The swiss army knife of net

Swiss Army Knife of networking netcat is a versatile tool that is able to read and write data across TCP and UDP network . Combined with other tools and redirection it can be used in number of ways in your scripts. You will be surprised to see what y

HDU 2451 Simple Addition Expression(组合数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laughers and singing from the hall where an

linux ncat命令

netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的就是在两台电脑之间建立链接并返回两个数据流,在这之后所能做的事就看你的想像力了.你能建立一个服务器,传输文件,与朋友聊天,传输流媒体或者用它作为其它协议的独立客户端. 下面是一些使用netcat的例子. [A(172.31.100.7) B(172.31.100.23)] Linux netcat

Spring各种依赖注入对比

转自:http://www.jb51.net/article/81741.htm(谢谢楼主分享) 注解注入顾名思义就是通过注解来实现注入,Spring和注入相关的常见注解有Autowired.Resource.Qualifier.Service.Controller.Repository.Component. Autowired是自动注入,自动从spring的上下文找到合适的bean来注入 Resource用来指定名称注入 Qualifier和Autowired配合使用,指定bean的名称 Se

工厂设计模式之:简单工厂、工厂方法、抽象工厂

简单工厂模式(Simple Factory):简单工厂模式又叫静态工厂模式,顾名思义,通过一个具体的工厂类,在该工厂类中定义返回值为不同实例对象的静态方法,来获得各种具体的实例对象. 工厂方法模式(Factory Method):建立一个抽象工厂,其不同的工厂实例用来创建不同的产品实例对象(单个产品),如果要增加新的产品,只需增加新的产品工厂即可.符合开闭原则. 抽象工厂模式(Abstract Factory):建立一个抽象工厂,用来实例化工厂子类,这些工厂子类用来生产对应的产品族(即一组对象实