当前位置:网站首页>Codeforces Global Round 19
Codeforces Global Round 19
2022-07-07 07:46:00 【whitewall_ nine】
B.
This competition is full of violence , I didn't expect the positive solution , For such a complex situation, there must be a conclusion that can make the topic simple . Yes A Speaking of, if it has been ordered , Then it must be no otherwise It indicates that there is a point a[i] > a[j], i < j Or let a[i] < a[j] i > j For the first case, it must be YES, For the second case, we can let j - 1 It is also natural and non reducing . Explain that if there is no order , It must be YES about B Consider greed , Because we need to make the value as big as possible , Let's divide into as many paragraphs as possible , That is to say 1 One number, one segment , except 0 The unexpected number did not contribute , Only 0 Yes, there will be 1 The contribution of . Then consider including 0 All interval numbers of are (i + 1) * (n - i) * (1 + (a[i] == 0));
#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);i++)
#define per(i,l,r) for(int i=(l);i>=(r);i--)
#define ll long long
#define pii pair<int, int>
#define mset(s,t) memset(s,t,sizeof(t))
#define mcpy(s,t) memcpy(s,t,sizeof(t))
#define fir first
#define pb push_back
#define sec second
#define sortall(x) sort((x).begin(),(x).end())
inline int read () {
int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= (ch=='-'),ch= getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f?-x:x;
}
template<typename T> void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) print(x/10);
putchar(x % 10 + '0');
}
#define int long long
const int N = 2e5 + 10;
int n;
int f[N];
int a[N], b[N];
int sum;
void solve() {
cin >> n;
memset(f, 0, sizeof f);
sum = 0;
for (int i = 1; i<= n ;i ++) {
cin >> a[i];
sum += a[i];
}
for (int i = 1; i<= n ;i ++) {
cin >> b[i];
sum += b[i];
}
f[0] = 1;
for (int i = 1; i<= n; i ++) {
int ndp[N] = {0};
for (int j = 0; j <= sum; j ++) {
if (f[j]) {
ndp[j + a[i]] = ndp[j + b[i]] = 1;
}
}
memcpy(f, ndp,sizeof f);
}
int ans = sum * sum;
for (int i = 0; i <= sum; i ++) {
if (f[i])
ans = min (ans, i * i + (sum - i) * (sum - i));
}
for (int i = 1; i <= n; i ++) {
ans += (a[i] * a[i] + b[i] * b[i]) * (n - 2);
}
cout << ans << endl;
}
signed main () {
int t;
cin >> t;
while (t --) solve();
}
01 knapsack problem , Judge which volume is feasible through backpack . Then the formula can be found as shown in the figure One part is unchanged , Then let a part take the minimum . This is a classic technique . Get the global minimum through traversal
边栏推荐
- 即刻报名|飞桨黑客马拉松第三期等你挑战
- misc ez_usb
- 4、 High performance go language release optimization and landing practice youth training camp notes
- pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
- 解决could not find or load the Qt platform plugin “xcb“in ““.
- 聊聊异步编程的 7 种实现方式
- 图解GPT3的工作原理
- Bi she - college student part-time platform system based on SSM
- 1140_ SiCp learning notes_ Use Newton's method to solve the square root
- Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
猜你喜欢
随机推荐
海思芯片(hi3516dv300)uboot镜像生成过程详解
三、高质量编程与性能调优实战 青训营笔记
URP - shaders and materials - light shader lit
按键精灵采集学习-矿药采集及跑图
2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
测试周期被压缩?教你9个方法去应对
pytorch 参数初始化
About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model
[guess-ctf2019] fake compressed packets
Determining the full type of a variable
四、高性能 Go 语言发行版优化与落地实践 青训营笔记
探索Cassandra的去中心化分布式架构
UWB learning 1
07_ Handout on the essence and practical skills of text measurement and geometric transformation
Weibo publishing cases
Wx is used in wechat applet Showtoast() for interface interaction
聊聊异步编程的 7 种实现方式
微信小程序中使用wx.showToast()进行界面交互
Common method signatures and meanings of Iterable, collection and list
微博发布案例