您的位置:首页 > 其它

codeforces round 119 div2 A-D

2017-06-18 18:13 253 查看
被skipped了啊- -,少作弊为好

A. Karen and Morning

time limit per test
2 seconds

memory limit per test
512 megabytes

input
standard input

output
standard output

Karen is getting ready for a new school day!



It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and
she believes that it is good luck to wake up when the time is a palindrome.

What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?

Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards
is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards
is 05:50.

Input

The first and only line of input contains a single string in the format hh:mm (00 ≤  hh  ≤ 23, 00 ≤  mm  ≤ 59).

Output

Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.

Examples

input
05:39


output
11


input
13:31


output
0


input
23:59


output
1


Note

In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50,
when the time is a palindrome.

In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.

In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00,
when the time is a palindrome.

没什么好说的,模拟

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(int a){
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(int a){
write(a); puts("");
}
inline int	read()//不管是正负数,都可以
{
int x = 0; char ch = getchar(); bool positive = 1;
for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline bool check(int a,int b){
if(a%10==b/10&&b%10==a/10)return true; else return false;
}
int main(){
int s1,s2;
scanf("%d:%d",&s1,&s2);
int ans=0;
while(!check(s1,s2)){
ans++; s2++; if(s2==60){
s2=0; s1++;
}
if(s1==24)s1=0;
}
writeln(ans);
}


B. Karen and Coffee

time limit per test
2.5 seconds

memory limit per test
512 megabytes

input
standard input

output
standard output

To stay woke and attentive during classes, Karen needs some coffee!



Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".

She knows n coffee recipes. The i-th
recipe suggests that coffee should be brewed between li and ri degrees,
inclusive, to achieve the optimal taste.

Karen thinks that a temperature is admissible if at least k recipes
recommend it.

Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature
between a and b,
inclusive, can you tell her how many admissible integer temperatures fall within the range?

Input

The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000),
and q (1 ≤ q ≤ 200000),
the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.

The next n lines describe the recipes. Specifically, the i-th
line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000),
describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees,
inclusive.

The next q lines describe the questions. Each of these lines contains a and b,
(1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees,
inclusive.

Output

For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees,
inclusive.

Examples

input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100


output
3
3
04


input
2 1 11 1200000 20000090 100


output
0


Note

In the first test case, Karen knows 3 recipes.

The first one recommends brewing the coffee between 91 and 94 degrees,
inclusive.

The second one recommends brewing the coffee between 92 and 97 degrees,
inclusive.

The third one recommends brewing the coffee between 97 and 99 degrees,
inclusive.

A temperature is admissible if at least 2 recipes recommend it.

She asks 4 questions.

In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees,
inclusive. There are 3: 92, 93 and 94 degrees
are all admissible.

In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees,
inclusive. There are 3: 93, 94 and 97 degrees
are all admissible.

In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees,
inclusive. There are none.

In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees,
inclusive. There are 4: 92, 93, 94 and 97 degrees
are all admissible.

In the second test case, Karen knows 2 recipes.

The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.

The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing
the coffee at exactly 200000 degrees.

A temperature is admissible if at least 1 recipe recommends it.

In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.

先预处理一下每一位是否大于k,然后树状数组模板直接上

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int N=2000005;
int k,q,zs[N],sum,m,a[N],ans,t,s1,s2,ss,n,c[N],i;
using namespace std;
inline int lowbit(int x){
return x&(-x);
}
inline void change(int i,int de){
int j=i;
while (j<=n){
c[j]+=de;
j+=lowbit(j);
}
}
inline int getsum(int i){
int zs=0; int j=i;
while (j){
zs+=c[j]; //out<<j<<endl;
j-=lowbit(j);
}
return zs;
}
inline int read()//读入一个正数
{
int a=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
a=a*10+ch-'0';
ch=getchar();
while(ch>='0'&&ch<='9')
{
a=a*10+ch-'0';
ch=getchar();
}
return a;
}
inline void write(int a){
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(int a){
write(a); puts("");
}
int main(){
m=read(); k=read(); q=read(); n=200000;
while(m--){
int l=read(),r=read();
zs[l]++; zs[r+1]--;
}
for(i=1;i<=n;i++){
sum+=zs[i];
a[i]=(sum>=k);//if(i==92)cout<<a[i]<<endl;
}
for(int i=1;i<=n;i++)change(i,a[i]);
while(q--){
int l=read(),r=read();
writeln(getsum(r)-getsum(l-1));
}
}


C. Karen and Game

time limit per test
2 seconds

memory limit per test
512 megabytes

input
standard input

output
standard output

On the way to school, Karen became fixated on the puzzle game on her phone!



The game is played as follows. In each level, you have a grid with n rows and m columns.
Each cell originally contains the number 0.

One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.

To win the level, after all the moves, the number in the cell at the i-th row and j-th
column should be equal to gi, j.

Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!

Input

The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100),
the number of rows and the number of columns in the grid, respectively.

The next n lines each contain m integers.
In particular, the j-th integer in the i-th
of these rows contains gi, j (0 ≤ gi, j ≤ 500).

Output

If there is an error and it is actually not possible to beat the level, output a single integer -1.

Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level.

The next k lines should each contain one of the following, describing the moves in the order they must be done:

row x, (1 ≤ x ≤ n)
describing a move of the form "choose the x-th row".

col x, (1 ≤ x ≤ m)
describing a move of the form "choose the x-th column".

If there are multiple optimal solutions, output any one of them.

Examples

input
3 5
2 2 2 3 2
0 0 0 1 01 1 1 2 1


output
4
row 1row 1col 4
row 3


input
3 3
0 0 00 1 00 0 0


output
-1


input
3 3
1 1 11 1 11 1 1


output
3
row 1row 2
row 3


Note

In the first test case, Karen has a grid with 3 rows and 5 columns.
She can perform the following 4 moves to beat the level:



In the second test case, Karen has a grid with 3 rows and 3 columns.
It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have
one 1 in the center.

In the third test case, Karen has a grid with 3 rows and 3 columns.
She can perform the following 3 moves to beat the level:



Note that this is not the only solution; another solution, among others, is col 1, col
2, col 3.

贪心大水题啊,由于要求最小,考虑先对一次能减少的大的操作。
我们说当一行(或一列)中所有数均不为0,那么将其全部减一是最优解。
下面给出证明。
若不然,不妨假设为m>n,即之后不再对该行进行操作,那么由于最终答案要全为0所以必然每列都会进行一次操作,即全屏都减一,显然将其转变为每行都减一更优,
证毕。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#define For(i,j,k)	for(int i=j;i<=k;i++)
using namespace std;
inline void read(int &tx){   int x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  tx=x*f; }
inline void write(int x){    if (x<0) putchar('-'),x=-x; if(x>=10) write(x/10);   putchar(x%10+'0');  }
inline void writeln(int x){write(x);puts("");}
const int N=2001;
int n,m,a[N][N],ans1[10000001],ans2[10000001],tot,tot1;
inline void t_l()
{
For(i,1,n)
{
int mi=1e9;
For(j,1,m)	mi=min(mi,a[i][j]);
For(j,1,mi)	ans1[++tot]=i;
For(j,1,m)	a[i][j]-=mi;
}
}
inline void t_r()
{
For(i,1,m)
{
int mi=1e9;
For(j,1,n)	mi=min(mi,a[j][i]);
For(j,1,mi)	ans2[++tot1]=i;
For(j,1,n)	a[j][i]-=mi;
}
}
int main()
{
read(n);read(m);
For(i,1,n)
For(j,1,m)	read(a[i][j]);
if(n<m)	t_l(),t_r();
else t_r(),t_l();
For(i,1,n)For(j,1,m)if(a[i][j])	{puts("-1");return 0;}
writeln(tot1+tot);
For(i,1,tot)printf("row %d\n",ans1[i]);
For(i,1,tot1)printf("col %d\n",ans2[i]);
}


D. Karen and Test

time limit per test
2 seconds

memory limit per test
512 megabytes

input
standard input

output
standard output

Karen has just arrived at school, and she has a math test today!



The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points.

There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums
or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition.

Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa.

The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test.

Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row?

Since this number can be quite large, output only the non-negative remainder after dividing it by 109 + 7.

Input

The first line of input contains a single integer n (1 ≤ n ≤ 200000),
the number of numbers written on the first row.

The next line contains n integers. Specifically, the i-th
one among these is ai (1 ≤ ai ≤ 109),
the i-th number on the first row.

Output

Output a single integer on a line by itself, the number on the final row after performing the process above.

Since this number can be quite large, print only the non-negative remainder after dividing it by 109 + 7.

Examples

input
5
3 6 9 12 15


output
36


input
4
3 7 5 2


output
1000000006


Note

In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15.

Karen performs the operations as follows:



The non-negative remainder after dividing the final number by 109 + 7 is
still 36, so this is the correct output.

In the second test case, the numbers written on the first row are 3, 7, 5 and 2.

Karen performs the operations as follows:



The non-negative remainder after dividing the final number by 109 + 7 is 109 + 6,
so this is the correct output.

考虑每个数对答案的贡献,直接找规律即可,发现和组合数有千丝万缕的联系。

奇数可由偶数转化而来

注意特判1(因为理论上它不能由偶数转化而来)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(long long a){
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(long long a){
write(a); puts("");
}
inline long long	read()//不管是正负数,都可以
{
long long x = 0; char ch = getchar(); bool positive = 1;
for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
return positive ? x : -x;
}
const long long N=2000005;
long long n,b[N],a[N],ans,mod=1000000007,zs;
inline long long ksm(long long a,long long b){
long long t=1,y=a;
while (b){
if (b&1) t=(long long)t*y%mod;
y=(long long)y*y%mod;
b>>=1;
}
return t;
}
int main(){
n=read();
long long m=n/2; a[1]=1;
for(long long i=2;i<=m;i++)a[i*2-1]=a[i*2-3]*(m-1-i+1+1)%mod*ksm(i-1,mod-2)%mod;
for(long long i=2;i<=m*2;i+=2)a[i]=((m&1)?1:-1)*a[i-1];
//for(long long i=1;i<=n;i++)cout<<a[i]<<endl;
for(long long i=1;i<=n;i++)b[i]=read();
if(!(n&1)){
for(long long i=1;i<=n;i++)ans=(ans+(long long)a[i]*b[i]%mod+mod)%mod; writeln((ans%mod+mod)%mod);
}else{
for(long long i=1;i<=n;i++)ans=(ans+(long long)((i&1)?a[i]-a[i-1]:a[i]+a[i-1])*b[i]%mod+mod)%mod; writeln((ans%mod+mod)%mod);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: