A. The Artful Expedien
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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, …, xn and 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 xor means 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 = yj; i ≠ j and xi = xj; i ≠ 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
3
1 2 3
4 5 6
output
Karen
input
5
2 4 6 8 10
9 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,因为如果ai ^ bj == ak, 则ak ^ bj == ai 那么永远有偶数对
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
puts("Karen");
return 0;
}
B. The Eternal Immortality
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
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.
题解:
题意就是让你求b!/a!的结果的最后一位是什么,我们不难发现,我们上下是能约分的,那么就转化成求从a+1乘到b的结果的最后一位是什么,而我们又发现如果从a+1到b中有一个数的最后一位是0,那么结果就是0,所以我们只需判断一下b-a是否大于10,如果大于10,那么一定会有一个末位为0的数,如果不大于10,就只需乘最后一位即可,
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long Int;
int main()
{
long long a, b;
cin >> a >> b;
if (b - a > 10)
puts("0");
else
{
Int ans = 1;
for (Int i = a+1; i <= b; i++)
{
Int ls = i%10;
ans *= ls;
ans %= 10;
}
cout << ans;
}
return 0;
}
C. The Intriguing Obsession
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 a, b 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 a, b 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 is 23 = 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.

题解:
我们不用管它的约束条件,只需计算每两堆能连多少条边,最后乘起来即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL mod = 998244353;
LL C[5050][5050];
int main()
{
LL a, b, c;
cin >> a >> b >> c;
C[0][0] = 1;
for (int i = 1; i <= 5000; i++)
{
C[i][0] = 1;
for (int j = 1; j <= i; j++)
{
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
C[i][j] %= mod;
}
}
if (a < b)
swap(a, b);
if (a < c)
swap(a, c);
if (b < c)
swap(b, c);
LL lsa, lsb, lsc, ls;
ls = lsa = lsb = lsc = 1;
for (LL i = a; i >= a - b + 1; i--)
{
ls *= i;
ls %= mod;
lsa += ls * C[b][a - i + 1];
lsa %= mod;
}
ls = 1;
for (LL i = a; i >= a - c + 1; i--)
{
ls *= i;
ls %= mod;
lsb += ls * C[c][a - i + 1];
lsb %= mod;
}
ls = 1;
for (LL i = b; i >= b - c + 1; i--)
{
ls *= i;
ls %= mod;
lsc += ls * C[c][b - i + 1];
lsc %= mod;
}
LL ans = (((lsa * lsb) % mod) * lsc) % mod;
cout << ans;
return 0;
}
D题:
全场只有一个A了的,不会。。。
E题:
正解用二维树状数组或者四叉树。。再次不会。。。