Lose it!
You are given an array aa consisting of nn integers. Each aiai is one of the six following numbers: 4,8,15,16,23,424,8,15,16,23,42.
Your task is to remove the minimum number of elements to make this array good.
An array of length kk is called good if kk is divisible by 66 and it is possible to split it into k6k6 subsequences 4,8,15,16,23,424,8,15,16,23,42.
Examples of good arrays:
- [4,8,15,16,23,42][4,8,15,16,23,42] (the whole array is a required sequence);
- [4,8,4,15,16,8,23,15,16,42,23,42][4,8,4,15,16,8,23,15,16,42,23,42] (the first sequence is formed from first, second, fourth, fifth, seventh and tenth elements and the second one is formed from remaining elements);
- [][] (the empty array is good).
Examples of bad arrays:
- [4,8,15,16,42,23][4,8,15,16,42,23] (the order of elements should be exactly 4,8,15,16,23,424,8,15,16,23,42);
- [4,8,15,16,23,42,4][4,8,15,16,23,42,4] (the length of the array is not divisible by 66);
- [4,8,15,16,23,42,4,8,15,16,23,23][4,8,15,16,23,42,4,8,15,16,23,23] (the first sequence can be formed from first six elements but the remaining array cannot form the required sequence).
The first line of the input contains one integer nn (1≤n≤5⋅1051≤n≤5⋅105) — the number of elements in aa.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (each aiai is one of the following numbers: 4,8,15,16,23,424,8,15,16,23,42), where aiai is the ii-th element of aa.
Print one integer — the minimum number of elements you have to remove to obtain a good array.
5
4 8 15 16 23
5
12
4 8 4 15 16 8 23 15 16 42 23 42
0
15
4 8 4 8 15 16 8 16 23 15 16 4 42 23 42
3
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <xfunctional>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = 1e5 + ;
const long long inf = 0x7f7f7f7f7f7f7f7f; int main()
{
vector<int> p({ , , , , , }); int n;
cin >> n;
vector<int> a(n);
for (int i = ; i < n; ++i)
{
cin >> a[i];
a[i] = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
} vector<int> seq();
for (int i = ; i < n; ++i)
{
if (a[i] == )
{
++seq[];
}
else
{
if (seq[a[i] - ] > )
{
--seq[a[i] - ];
++seq[a[i]];
}
}
} cout << n - seq[] * << endl;
return ;
}
Lose it!的更多相关文章
- etymon word write alb pain high alt increase large agency ag lose weight fat assist out~3
1● alb 2● write =====>rait 1● alg 2● pain 痛,疼痛 1● alt 2● high 高 1 ...
- Spoken English Practice(not always estimating your status in other's hearts. you will lose yourself when you live in other's look. do your best and walk on you own way.)
绿色:连读: 红色:略读: 蓝色:浊化: 橙色:弱读 下划线_为浊化 口语蜕变(2017/7/8) 英 ...
- POJ 2521:How much did the businessman lose
How much did the businessman lose Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9965 ...
- g/test/s/lose/won/g
包含字符串test的任意行商,用lose代替won
- Baidu set to lose leading role in digital advertising _china daily
advertising: n,广告 Online search giant Baidu Inc is set to loset its top spot in the nation's booming ...
- google chrome 32 升级变更找回user agent(google chrome lose user agent)
chrome32中user agent 找不着了?没关系,看我画的图吧.为什么是英文的,国际化嘛...
- Mac环境下mysql初始化密码问题--If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
个人在Mac上操作数据库,遇到的启动数据库问题的简单记录 1.苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) 2.进 ...
- .Net Core Package lose or not match
错误.警告的说明: 示例一: 严重性:警告 代码:MSB3106 说明 :程序集强名称“C:\Users\$(computerName)\.nuget\packages\$(packageName)\ ...
- unity, editorWindow lose data when enter play mode
我写了个editorWindow,其中有个成员变量m_x,在创建editorWindow的时候为m_x赋的值,而在editorWindow的OnGUI里把m_x显示出来. 当我开着这个editorWi ...
- SD 一轮集训 day1 lose
神TM有是结论题,我讨厌结论题mmp. 杨氏矩阵了解一下(建议去维基百科). 反正就是推柿子,使劲推,最后写起来有一点小麻烦,但是在草稿纸(然鹅我木有啊)上思路清晰的话还是没问题的. #include ...
随机推荐
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- svn提交更新代码提示Please execute the 'Cleanup' command 的解决办法
那可能是提交或更新代码的过程意外终止,第二次提交或更新会报这个错误 更新或上传的时候动作没有完成,导致本地存在锁定状态没有释放 或者有文件正在更新或上传,该文件夹被锁定. 解决办法: 将对应文件夹里的 ...
- Java知识点题集
一.红黑树的特性 (1)每个节点或者是黑色,或者是红色. (2)根节点是黑色. (3)每个叶子节点(NIL)是黑色. [注意:这里叶子节点,是指为空(NIL或NULL)的叶子节点!] (4)如果一个节 ...
- 性能优化-css,js的加载与执行
前端性能优化 css,js的加载与执行 javascript是单线程的 一个网站在浏览器是如何进行渲染的呢? html页面加载渲染的过程 html渲染过程的一些特点 顺序执行,并发加载 词法分析 并发 ...
- Longest Ordered Subsequence POJ - 2533 dp 最长上升/不下降 子序列
#include<iostream> using namespace std ; ; int f[N]; int a[N]; int n; int main() { cin>> ...
- 前端:将网站打造成单页面应用SPA
前端:将网站打造成单页面应用SPA 前言 不知你有没有发现,像Github.百度.微博等这些大站,已经不再使用普通的a标签做跳转了.他们大多使用Ajax请求替代了a标签的默认跳转,然后使用HTML ...
- ActiveMQ使用JDBC持久化
步骤一:创建一个数据库 步骤二:配置activemq.xml配置文件 1.在persistenceAdapter加入如下配置 <!--crea ...
- linux - mysql 异常:Ignoring query to other database
问题描述 Ignoring query to other database(忽略其他数据库查询) 问题原因 登录方式错误,登录命令用的是 “mysql -root -p”,应该用命令 “mysql - ...
- (转)linux 之 grep命令
转自:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html 简介 grep (global search regular e ...
- 介绍axios和promise
今天小编为大家带来 axios 和promise的详细讲解,包含 axios的使用方法 多种写法,封装 以及 promise的详细讲解,项目中如何运用等,会一一的为大家讲解清楚. 一.axios的介绍 ...