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. Java SpringMvc Jar包下载及部署方式_转载

    本次来记录一下关于 springmvc jar包的下载以及部署 首先登陆   http://repo.spring.io/release/org/springframework/spring/到里面我 ...

  2. 通俗易懂的Git使用入门教程

    原文链接:点我 首先新司机接触 Git 和 Github 可能会搞不清楚两者之间的关系,这里稍微解释一下: 1.Git是一款免费.开源的分布式版本控制系统 2.Github是用Git做版本控制的代码托 ...

  3. 欢迎访问微先锋vXianFeng官方博客

    欢迎访问微先锋vXianFeng官方博客,专注微商城.P2P理财.山寨矿机平台研究与开发!

  4. 去掉vs2010字符串下红色波浪线

    由于在vs集成了qt库,无法提升代码. 所以下载了visual assist,然后新的问题出现了,凡是在vs中输入的字符串,下面都有红色的波浪线,而且没有错误,只是看着不舒服. 解决方法: 在VAss ...

  5. 一 梳理 从 HDFS 到 MR。

      MapReduce 不仅仅是一个工具,更是一个框架.我们必须拿问题解决方案去适配框架的 map 和 reduce 过程   很多情况下,需要关注 MapReduce 作业所需要的系统资源,尤其是集 ...

  6. hdu 5380 Travel with candy(双端队列)

    pid=5380">题目链接:hdu 5380 Travel with candy 保持油箱一直处于满的状态,维护一个队列,记录当前C的油量中分别能够以多少价格退货,以及能够推货的量. ...

  7. PL/SQL Developer怎么连接远程数据库

    首先打开电脑,到PL/SQL安装的指定目录 [D:\app\DZL\product\10.2.0\dbhome_1\NETWORK\ADMIN]或者[D:\oracle\product\10.2.0\ ...

  8. android事件学习

    一.android处理事件有两种形式. 1.基于监听的事件处理,就是通过setXxxListenter()进行处理的. 2.基于回调的事件处理,就是View类内部的onTouchEvent(),一般是 ...

  9. && 的用法

    document.body.style.display === "" && (document.body.style.display = "none&qu ...

  10. UVA Watering Grass

    贪心算法. #include <iostream> #include <cstdio> #include <cstring> #include <queue& ...