当前位置:网站首页>【Incubator DAY18】Interesting exchange【Simulation】【Math】
【Incubator DAY18】Interesting exchange【Simulation】【Math】
2022-07-30 00:13:00 【VL - MOESR】

思路:
我们发现只有当n和n+1To turn over,We don't know what to do.
那么我们考虑,If the first half turned a1过去,During the second half turned a0过去,Then reverse the number can be calculated.
Then we will direct enumeration first half turned a few1过去,Then calculate the answer again and again.
c o d e code code
#include<iostream>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
const ll MAXN = 1e5 + 10;
ll n, x1[MAXN], y_1[MAXN], x0[MAXN], y_0[MAXN];
ll l1, l0, r1, r0, ans;
int main() {
freopen("balance.in", "r", stdin);
freopen("balance.out", "w", stdout);
scanf("%lld", &n);
for(ll i = 1; i <= n; i ++) {
ll x;
scanf("%lld", &x);
if(x == 1) x1[++ l1] = i;
else x0[++ l0] = i;
}
for(ll i = 1; i <= n; i ++) {
ll x;
scanf("%lld", &x);
if(x == 1) y_1[++ r1] = i;
else y_0[++ r0] = i;
}
ll suml = (n - l1) * l1 + (l1 + 1) * l1 / 2, sumr = (n - r1) * r1 + (r1 + 1) * r1 / 2;
for(ll i = 1; i <= l1; i ++) suml -= x1[i];
for(ll i = 1; i <= r1; i ++) sumr -= y_1[i];
if(suml == sumr) {
printf("0");
return 0;
}
ans = abs(suml - sumr);
ll sl = suml, sr = sumr;
ll tmp = 0;
for(ll i = l1, j = 1; i >= 1 && j <= r0; i --, j ++) {
sl += x1[i] - n + i - 1;
sr += r0 - j - y_0[j] + 1;
tmp += n - x1[i] + y_0[j];
if(tmp >= ans) break;
ans = min(ans, tmp + (sl - sr < 0 ? sr - sl : sl - sr));
}
sl = suml, sr = sumr;
tmp = 0;
for(ll i = l0, j = 1; i >= 1 && j <= r1; i --, j ++) {
sr += y_1[j] - n + r1 - j;
sl += i - x0[i];
tmp += n - x0[i] + y_1[j];
if(tmp >= ans) break;
ans = min(ans, tmp + (sl - sr < 0 ? sr - sl : sl - sr));
}
printf("%lld", ans);
return 0;
}
边栏推荐
猜你喜欢

He used to cells harvested trypsin & release procedure

Worthington弹性蛋白酶&透明质酸酶简介

软件测试拿8k以上有多简单,掌握这些随随便便拿8k以上...

2022年企业直播行业发展洞察

Worthington优化技术:细胞定量

vim相关介绍(三)

头条号自媒体运营:如何在今日头条涨500+粉丝?

Worthington Enzymatic Cell Harvest & Cell Adhesion and Harvest

外包干了五年,废了...

At the age of 29, I was fired from a functional test. Can't find a job after 2 months of interviews?
随机推荐
自媒体人如何打造出爆文?这3种类型的文章最容易爆
Getting Started with Sentinel
Worthington Optimized Technology: Cell Quantification
Worthington解离酶:胶原酶及四个基本概况
The difference and usage of call, apply and bind
Worthington Papain & Chymotrypsin & DNase I
C陷阱与缺陷 第3章 语义“陷阱” 3.10 为函数main提供返回值
EA&UML日拱一卒-多任务编程超入门-(8)多任务安全的数据类
软件测试拿8k以上有多简单,掌握这些随随便便拿8k以上...
绘制几何图形
He cell separation technology 丨 basic primary cell separation methods and materials
机器人的运动范围
管理区解耦架构见过吗?能帮客户解决大难题的
vim相关介绍(二)
【集训DAY18】Welcome J and Z 【动态规划】
Expansion of Parallel I/O Port in Single Chip Microcomputer Development
ApplicationContext的三大实现
Genesis与Axis Ventures互动密切
shell编写规范和变量
Reading notes. This is the psychology: see through the essence of the pseudo psychology (version 10)"