Codeforces Round #439 (Div. 2) A-C题解

来源:互联网 发布:服务器 定时关机 软件 编辑:程序博客网 时间:2024/06/06 16:30
A. The Artful Expedient
time limit per test
 1 second
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

Rock... Paper!

After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows.

A positive integer n is decided first. Both Koyomi and Karen independently choose n distinct positive integers, denoted by x1, x2, ..., xnand y1, y2, ..., yn respectively. They reveal their sequences, and repeat until all of 2n integers become distinct, which is the only final state to be kept and considered.

Then they count the number of ordered pairs (i, j) (1 ≤ i, j ≤ n) such that the value xi xor yj equals to one of the 2n integers. Here xormeans the bitwise exclusive or operation on two integers, and is denoted by operators ^ and/or xor in most programming languages.

Karen claims a win if the number of such pairs is even, and Koyomi does otherwise. And you're here to help determine the winner of their latest game.

Input

The first line of input contains a positive integer n (1 ≤ n ≤ 2 000) — the length of both sequences.

The second line contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 2·106) — the integers finally chosen by Koyomi.

The third line contains n space-separated integers y1, y2, ..., yn (1 ≤ yi ≤ 2·106) — the integers finally chosen by Karen.

Input guarantees that the given 2n integers are pairwise distinct, that is, no pair (i, j) (1 ≤ i, j ≤ n) exists such that one of the following holds: xi = yji ≠ j and xi = xji ≠ j and yi = yj.

Output

Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.

Examples
input
31 2 34 5 6
output
Karen
input
52 4 6 8 109 7 5 3 1
output
Karen
Note

In the first example, there are 6 pairs satisfying the constraint: (1, 1)(1, 2)(2, 1)(2, 3)(3, 2) and (3, 3). Thus, Karen wins since 6 is an even number.

In the second example, there are 16 such pairs, and Karen wins again.

分析:水题 上下异或,如果异或出来的数在输入的里面就加一,如果出现次数是偶数次就输出KAREN赢了,否则就是另外一个人。有大佬推理出来只有K赢,玄学。

#include<stdio.h>#include<iostream> #include <algorithm>#include<string.h>#include<vector>#include<math.h>#include<queue>#include<set>#define LL long long#define INf 0x3f3f3f3fusing namespace std;int KGCD(int a,int b){if(a==0)return b;if(b==0)return a;if(~a&1){ if(b&1) return KGCD(a>>1,b);else return KGCD(a>>1,b>>1) <<1; } if(~b & 1)  return KGCD(a, b>>1);  if(a > b) return KGCD((a-b)>>1, b);return KGCD((b-a)>>1, a);}  int LCM(int a,int b){ return a/KGCD(a,b)*b; } int dir[5][2]={0,1,0,-1,1,0,-1,0};using namespace std;int a[2000005];int b[2000005];int c[10000005];int main(){int n,x,ans=0;scanf("%d",&n);memset(c,0,sizeof(c));for(int i=0;i<n;i++){scanf("%d",&a[i]);c[a[i]]++;}for(int i=0;i<n;i++){scanf("%d",&b[i]);c[b[i]]++;}for(int i=0;i<n;i++){for(int j=0;j<n;j++){int temp=a[i]^b[j];if(c[temp])ans++;}}if(ans%2==0)printf("Karen\n");elseprintf("Koyomi\n");return 0;}


B. The Eternal Immortality
time limit per test
 1 second
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

Even if the world is full of counterfeits, I still regard it as wonderful.

Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.

The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is,a! = 1 × 2 × ... × a. Specifically, 0! = 1.

Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Examples
input
2 4
output
2
input
0 10
output
0
input
107 109
output
2
Note

In the first example, the last digit of  is 2;

In the second example, the last digit of  is 0;

In the third example, the last digit of  is 2.

分析:输出阶乘差值的最后一位,水题模拟下就OK了,但是注意几个特判。

#include<stdio.h>#include<iostream> #include <algorithm>#include<string.h>#include<vector>#include<math.h>#include<queue>#include<set>#define LL long long#define INf 0x3f3f3f3fusing namespace std;int KGCD(int a,int b){if(a==0)return b;if(b==0)return a;if(~a&1){ if(b&1) return KGCD(a>>1,b);else return KGCD(a>>1,b>>1) <<1; } if(~b & 1)  return KGCD(a, b>>1);  if(a > b) return KGCD((a-b)>>1, b);return KGCD((b-a)>>1, a);}  int LCM(int a,int b){ return a/KGCD(a,b)*b; } int dir[5][2]={0,1,0,-1,1,0,-1,0};using namespace std;int main(){long long a,b;scanf("%I64d%I64d",&a,&b);if(b==0)//都是0的阶乘{printf("1\n");}else{long long temp=b-a;if(temp>=10)//其中一定有10  直接输出0{printf("0\n");}else{temp=1;for(long long i=a+1;i<=b;i++){temp=temp*(i%10);if(temp==0)//有0肯定就是0{break;}if(temp/10)temp=temp%10;}printf("%I64d\n",temp);}} return 0;}

C. The Intriguing Obsession
time limit per test
 1 second
memory limit per test
 256 megabytes
input
 standard input
output
 standard output

— This is not playing but duty as allies of justice, Nii-chan!

— Not allies but justice itself, Onii-chan!

With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!

There are three clusters of islands, conveniently coloured red, blue and purple. The clusters consist of ab and c distinct islands respectively.

Bridges have been built between some (possibly all or none) of the islands. A bridge bidirectionally connects two different islands and has length 1. For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3, apparently in order to prevent oddities from spreading quickly inside a cluster.

The Fire Sisters are ready for the unknown, but they'd also like to test your courage. And you're here to figure out the number of different ways to build all bridges under the constraints, and give the answer modulo 998 244 353. Two ways are considered different if a pair of islands exist, such that there's a bridge between them in one of them, but not in the other.

Input

The first and only line of input contains three space-separated integers ab and c (1 ≤ a, b, c ≤ 5 000) — the number of islands in the red, blue and purple clusters, respectively.

Output

Output one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.

Examples
input
1 1 1
output
8
input
1 2 2
output
63
input
1 3 5
output
3264
input
6 2 9
output
813023575
Note

In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is23 = 8.

In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the blue and purple clusters, respectively.


分析:给你三种桥,每种桥都有一种颜色,让你连接桥,问问有多少种方式,但是保证同样的颜色不能直接连接,就是同一类的桥不能直接相连。将题目分成12  23  13三种情况来考虑,最后相乘就行了,化整为分。

1 2两种桥,假设各有a,b个。(a>b)


两个桥连一条边,显然有C(b,1)*a种。//从一个选择可以到对面的a种的一个


连二条边,有C(b,2)*a*(a-1)种。//从b选择2个 a种可以有a*(a-1)选择

.......


连第b条边,有C(b,b)*a*(a-1)*...*(a-b+1)种。//B这边桥数目少,全部练到A这边


最后加起来就是总数。


#include<stdio.h>#include<iostream> #include <algorithm>#include<string.h>#include<vector>#include<math.h>#include<queue>#include<set>#define LL long long#define INf 0x3f3f3f3f#define mod 998244353using namespace std;int KGCD(int a,int b){if(a==0)return b;if(b==0)return a;if(~a&1){ if(b&1) return KGCD(a>>1,b);else return KGCD(a>>1,b>>1) <<1; } if(~b & 1)  return KGCD(a, b>>1);  if(a > b) return KGCD((a-b)>>1, b);return KGCD((b-a)>>1, a);}  int LCM(int a,int b){ return a/KGCD(a,b)*b; } int dir[5][2]={0,1,0,-1,1,0,-1,0};using namespace std;int dp[5005][5005];int main(){int a,b,c;scanf("%d%d%d",&a,&b,&c);dp[0][0]=1;for(int j=1;j<=5000;j++)//组合数打表{dp[j][0]=1;for(int k=1;k<=j;k++)dp[j][k]=(dp[j-1][k]+dp[j-1][k-1])%mod;}if(a<b)//将三个值从大到小拍好swap(a,b);if(a<c)swap(a,c);if(b<c)swap(b,c);long long temp=1;long long t=1;for(long long i=a;i>=a-b+1;i--){t=t*i;t=t%mod;temp=(temp+(t*dp[b][a-i+1])%mod)%mod;//每种情况 累加}t=1;long long temp1=1;for(long long i=b;i>=b-c+1;i--){t=t*i;t=t%mod;temp1=(temp1+(t*dp[c][b-i+1])%mod)%mod;}t=1;long long temp2=1;for(long long i=a;i>=a-c+1;i--){t=t*i;t=t%mod;temp2=(temp2+(t*dp[c][a-i+1])%mod)%mod;}temp=((temp*temp1)%mod*temp2)%mod;printf("%I64d\n",temp); }
有人写的不一样:点击打开链接(记忆化搜索)




原创粉丝点击