A - Ice Tea Store


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

You've come to your favorite store Infinitesco to buy some ice tea.

The store sells ice tea in bottles of different volumes at different costs. Specifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen. The store has an infinite supply of bottles of each type.

You want to buy exactly N liters of ice tea. How many yen do you have to spend?

Constraints

  • 1≤Q,H,S,D≤108
  • 1≤N≤109
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

Q H S D
N

Output

Print the smallest number of yen you have to spend to buy exactly N liters of ice tea.


Sample Input 1

20 30 70 90
3

Sample Output 1

150

Buy one 2-liter bottle and two 0.5-liter bottles. You'll get 3 liters for 90+30+30=150 yen.


Sample Input 2

10000 1000 100 10
1

Sample Output 2

100

Even though a 2-liter bottle costs just 10 yen, you need only 1 liter. Thus, you have to buy a 1-liter bottle for 100 yen.


Sample Input 3

10 100 1000 10000
1

Sample Output 3

40

Now it's better to buy four 0.25-liter bottles for 10+10+10+10=40 yen.


Sample Input 4

12345678 87654321 12345678 87654321
123456789

Sample Output 4

1524157763907942
    #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll a[],n;
int main()
{
while(scanf("%lld%lld%lld%lld",&a[],&a[],&a[],&a[])!=EOF)
{
scanf("%lld",&n);
for(int i=;i<;i++) a[i]=min(a[i],*a[i-]);
printf("%lld\n",n/*a[]+(n&)*a[]);
}
return ;
}

B - Reverse and Compare


Time limit : 2sec / Memory limit : 256MB

Score : 500 points

Problem Statement

You have a string A=A1A2An consisting of lowercase English letters.

You can choose any two indices i and j such that 1≤ijn and reverse substring AiAi+1Aj.

You can perform this operation at most once.

How many different strings can you obtain?

Constraints

  • 1≤|A|≤200,000
  • A consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

A

Output

Print the number of different strings you can obtain by reversing any substring in A at most once.


Sample Input 1

aatt

Sample Output 1

5

You can obtain aatt (don't do anything), atat (reverse A[2..3]), atta (reverse A[2..4]), ttaa (reverse A[1..4]) and taat (reverse A[1..3]).


Sample Input 2

xxxxxxxxxx

Sample Output 2

1

Whatever substring you reverse, you'll always get xxxxxxxxxx.


Sample Input 3

abracadabra

Sample Output 3

44
预处理。
    #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll a[][],ans;
char s[];
int main()
{
while(scanf("%s",s+)!=EOF)
{
memset(a,,sizeof(a));
int len=strlen(s+);
ans=;
for(int i=;i<=len;i++)
{
for(int j=;j<;j++)
a[i][j]=a[i-][j];
a[i][s[i]-'a']++;
}
for(int i=;i<=len;i++)
ans+=len-i-a[len][s[i]-'a']+a[i][s[i]-'a'];
printf("%lld\n",ans+);
}
return ;
}

Atcoder AGC 019 A,B的更多相关文章

  1. 【做题记录】AtCoder AGC做题记录

    做一下AtCoder的AGC锻炼一下思维吧 目前已做题数: 75 总共题数: 239 每一场比赛后面的字母是做完的题,括号里是写完题解的题 AGC001: ABCDEF (DEF) AGC002: A ...

  2. AtCoder AGC #2 Virtual Participation

    在知乎上听zzx大佬说AGC练智商...于是试了一下 A.Range Product 给$a$,$b$,求$\prod^{b}_{i=a}i$是正数,负数还是$0$ ...不写了 B.Box and ...

  3. 【题解】Atcoder AGC#16 E-Poor Turkeys

    %拜!颜神怒A此题,像我这样的渣渣只能看看题解度日╭(╯^╰)╮在这里把两种做法都记录一下吧~ 题解做法:可以考虑单独的一只鸡 u 能否存活.首先我们将 u 加入到集合S.然后我们按照时间倒序往回推, ...

  4. 【题解】Atcoder AGC#01 E-BBQ Hard

    计数题萌萌哒~ 这道题其实就是统计 \(\sum_{i=1}^{n}\sum_{j=i+1}^{n}C\binom{a[i] + a[j]}{a[i] + a[j] + b[i] + b[j]}\) ...

  5. 【题解】Atcoder AGC#03 E-Sequential operations on Sequence

    仙题膜拜系列...首先我们可以发现:如果在截取了一段大的区间之后再截取一段小的区间,显然是没有什么用的.所以我们可以将操作序列变成单调递增的序列. 然后怎么考虑呢?启示:不一定要考虑每一个数字出现的次 ...

  6. AtCoder AGC #4 Virtual Participation

    我好懒啊QAQ 老规矩 从C开始 C.给一个矩阵,里面有一些紫色方块,你需要涂两个矩阵,一个红色,一个蓝色,保证你涂的颜色四连通 然后把红色蓝色矩阵叠起来要求紫色的地方必须是紫色,其他地方不能是紫色 ...

  7. AtCoder AGC #3 Virtual Participation

    Havana真好听qwq AB题就不写了 SB C.BBuBBBlesort! 有一个长度为$n$的数列 你每次可以用两种操作 1.交换两个相邻元素 2.交换两个隔且仅隔了一个的元素 求把数列排成有序 ...

  8. [题解] Atcoder AGC 005 F Many Easy Problems NTT,组合数学

    题目 观察当k固定时答案是什么.先假设每个节点对答案的贡献都是\(\binom{n}{k}\),然后再减掉某个点没有贡献的选点方案数.对于一个节点i,它没有贡献的方案数显然就是所有k个节点都选在i连出 ...

  9. AtCoder Beginner Contest 122 D - We Like AGC (DP)

    D - We Like AGC Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement Yo ...

随机推荐

  1. PostgreSQL Replication之第八章 与pgbouncer一起工作(1)

    当您在使用大规模的设施工作,可能有时候,您必须处理许多并发打开的连接.没有人会使用十台服务器来为两个并发用户提供服务--在许多情况下,这根本没有意义.大量的设施通常会处理成百上千的并发连接.引入连接池 ...

  2. 关于eclipse的注释和反注释的快捷键

    使用eclipse那么久了额,对注释和反注释的快捷键一直很模糊,现在记下来,方便查看. 注释和反注释有两种方式.如对下面这段代码片段(①)进行注释: private String value; pri ...

  3. vue打包后显示空白正确处理方法

    vue打包后显示空白正确处理方法是 1.找到配置文件(js与css加载不上) 修改 这样打包处理可以打开但是页面样式会找不到 2.修改(针对css中的图片加载不上) 找到对应的位置加上publicPa ...

  4. 比起 Windows,怎样解读 Linux 的文件系统与目录结构?

    Linux 和 Windows 的文件系统有些不同,在学习使用 Linux 之前,若能够了解这些不同,会有助于后续学习. 本文先对 Windows 和 Linux 上面文件系统原理.组织概念进行区分, ...

  5. Hope is a good thing, maybe the best of things and no good thing ever dies !

  6. dist文件夹、src文件夹、dest文件夹是什么意思?

    dist文件夹是编译后或者压缩后的代码,终发布版本的代码 src文件夹是源码文件 dest文件夹为压缩包文件夹

  7. Redis报错 : (error) NOAUTH Authentication required.

    原文:Redis报错 : (error) NOAUTH Authentication required. 这个错误是因为没有用密码登陆认证 , 先输入密码试试 . 127.0.0.1:6379> ...

  8. Unity C# 设计模式(七)适配器模式

    定义: 将一个类的接口转换成客户希望的另一个接口.adapter模式使得原本由于接口不兼容而不能在一起的那些类可以一起工作. 示例代码: 1.类适配器 /* Class Adapter:类适配器,这里 ...

  9. Linux下的ioctl()函数详解

    我这里说的ioctl函数是指驱动程序里的,因为我不知道还有没有别的场合用到了它,所以就规定了我们讨论的范围.写这篇文章是因为我前一阵子被ioctl给搞混了,这几天才弄明白它,于是在这里清理一下头脑. ...

  10. 题解 P3372 【【模板】线段树1 】

    看了一下题解里的zkw线段树,感觉讲的不是很清楚啊(可能有清楚的但是我没翻到,望大佬勿怪). 决定自己写一篇...希望大家能看明白... zkw线段树是一种优秀的非递归线段树,速度比普通线段树快两道三 ...