[Original] CLRS 4-6

[Original] CLRS 4-6

暂无测试数据。

Background

改编自CLRS(算法导论) 练习4-6

Description

定义:对一个m×nm\times n的实数序列AA。若对1i<km\forall 1\leqslant i < k \leqslant m1j<ln1 \leqslant j < l \leqslant ni,j,k,li,j,k,l,都有
Ai,j+Ak,lAi,l+Ak,jA_{i,j} + A_{k,l} \leqslant A_{i,l} + A_{k,j}
则称AA时**Monge**阵列。现给出TT个Monge阵列,求出每一行的最左最小元素。

Format

Input

Two integers x and y, satisfying 0 <= x, y <= 32767.

Output

One integer, the sum of x and y.

Sample 1

Input

123 500

Output

623

Limitation

对于所有的测试点,每个测试点提供256 MB的内存和4.0s的时限
对于所有的测试点,有T3×103,n,m5×105T \leqslant 3\times 10^3, n,m \leqslant 5 \times10^5

Hint

Free Pascal Code

var a,b:longint;
begin
    readln(a,b);
    writeln(a+b);
end.

C Code

#include <stdio.h>
int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a + b);
    return 0;
}

C++ Code

#include <iostream>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}

Python Code

a, b = [int(i) for i in raw_input().split()]
print(a + b)

Java Code

import java.io.*;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a + b);
    }
}

Source

Vijos Original

Tips

对于一个朴素的算法,时间复杂度为O(Tmn)O(Tmn)
而一个优秀的算法,可达到O(Tm+Tnlogm)O(Tm+Tn\log m)
注意这道题可能会被卡常数。如果你的优秀算法无法通过,允许在程序的开头处添加以下代码:

#pragma GCC optimize("Ofast")

信息

难度
(无)
分类
(无)
标签
(无)
递交数
0
已通过
0
通过率
?
上传者