A9563 | Tricky Function
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task.
You're given an (1-based) array $a$ with $n$ elements. Let's define function $f(i,j)$ $(1<=i,j<=n)$ as $(i-j)^{2}+g(i,j)^{2}$ . Function g is calculated by the following pseudo-code:
```
int g(int i, int j) {
int sum = 0;
for (int k = min(i, j) + 1; k <= max(i, j); k = k + 1)
sum = sum + a[k];
return sum;
}
```
Find a value $min_{i≠j} f(i,j)$ .
Probably by now Iahub already figured out the solution to this problem. Can you?
You're given an (1-based) array $a$ with $n$ elements. Let's define function $f(i,j)$ $(1<=i,j<=n)$ as $(i-j)^{2}+g(i,j)^{2}$ . Function g is calculated by the following pseudo-code:
```
int g(int i, int j) {
int sum = 0;
for (int k = min(i, j) + 1; k <= max(i, j); k = k + 1)
sum = sum + a[k];
return sum;
}
```
Find a value $min_{i≠j} f(i,j)$ .
Probably by now Iahub already figured out the solution to this problem. Can you?
输入格式
The first line of input contains a single integer $n$ ( $2<=n<=100000$ ). Next line contains $n$ integers $a[1]$ , $a[2]$ , ..., $a[n]$ ( $-10^{4}<=a[i]<=10^{4}$ ).
输出格式
Output a single integer — the value of $min_{i≠j} f(i,j)$ .
输入输出样例
输入 #1
4 1 0 0 -1
输出 #1
1
输入 #2
2 1 -1
输出 #2
2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted