Codeforces Round #439 (Div. 2) A-C題解
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.
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 one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
3 1 2 3 4 5 6
Karen
5 2 4 6 8 10 9 7 5 3 1
Karen
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.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=2e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int a[40000],b[40000];
bool visit[maxn*4];
int main()
{
int n,i,j,k;
while(cin>>n)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
visit[a[i]]++;
}
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
visit[b[i]]++;
}
int ans=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
int temp=a[i]^b[j];
if(visit[temp])
ans++;
}
}
if(ans%2==0)
cout<<"Karen"<<endl;
else
cout<<"Koyomi"<<endl;
}
return 0;
}
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.
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
2 4
2
0 10
0
107 109
2
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.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=2e6+5;
const int mod=1e9+7;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int main()
{
ll a,b;
cin>>a>>b;
if(b==0||a==b)
{
cout<<"1"<<endl;
return 0;
}
ll t=b-a;
b%=10;
int ans=b--;
t--;
while(t>0&&t--)
{
ans=ans*b%10;
b--;
if(b<0)
b+=10;
if(ans==0)
break;
}
cout<<ans<<endl;
return 0;
}
— 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.
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 one line containing an integer — the number of different ways to build bridges, modulo 998 244 353.
1 1 1
8
1 2 2
63
1 3 5
3264
6 2 9
813023575
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.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<cstdio>
#define ll long long
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
const double PI=acos(-1);
const int inf=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=2e6+5;
const int mod=998244353;
int dir[4][2]={0,1,1,0,0,-1,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int dp[5005][5005];
int solve(int x,int y)
{
if(x==0||y==0)
return 1;
if (dp[x][y] == 0)
{
dp[x][y]=(y*1ll*solve(x-1,y-1)+solve(x-1,y))%mod;
}
return dp[x][y];
}
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a>b)
swap(a,b);
if(b>c)
swap(b,c);
if(a>b)
swap(a,b);
printf("%lld\n",solve(a,b)*1ll*solve(b,c)%mod*solve(a,c)%mod);
}
相關文章
- Codeforces Round #665 (Div. 2)A-C題解2020-08-22
- Codeforces Round 986 (Div. 2) A-C2024-11-26
- Codeforces Round 976 (Div. 2) 題解2024-10-03
- Codeforces Round 965 (Div. 2) 題解2024-08-11
- Codeforces Round #956 (Div. 2)題解2024-07-11
- Codeforces Round 983 (Div. 2) 題解2024-11-02
- Codeforces Round 951 (Div. 2) 題解2024-06-07
- Codeforces Round 932 (Div. 2) DE 題解2024-03-06
- Codeforces Round #681 (Div. 2)E題解2020-11-11
- Codeforces Round 990 (Div. 2) 題解 (A ~ E)2024-12-04
- Educational Codeforces Round 93 (Rated for Div. 2)題解2020-08-15
- Codeforces Round #673 (Div. 2)(A-D)題解2020-09-28
- Codeforces Round #537 (Div. 2)解題報告2019-02-04
- Codeforces Round 893 (Div. 2)題解記錄2024-10-17
- Codeforces Round 892 (Div. 2)題解記錄2024-10-18
- Educational Codeforces Round 168 (Rated for Div. 2) 題解2024-07-31
- Educational Codeforces Round 171 (Rated for Div. 2) 題解2024-11-03
- Codeforces Round 976 (Div. 2) 題解(A-E)2024-10-13
- Codeforces Round 899 (Div. 2)題解記錄2024-10-13
- Codeforces Round 992 (Div. 2) 解題報告2024-12-09
- Codeforces Round 987 (Div. 2)題解記錄(A~D)2024-11-16
- Codeforces Round 979 (Div. 2) (ABCD個人題解)2024-10-20
- Codeforces Round 986 (Div. 2)題解記錄(A~D)2024-11-11
- Codeforces Round 946 (Div. 3) 題解2024-05-28
- Codeforces Round #615 (Div. 3) (題解)2020-10-06
- Codeforces Round 984 (Div. 3) 題解2024-11-05
- Codeforces Round 962 (Div. 3) 題解2024-07-27
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】2020-06-01GAM
- Codeforces Round 975 (Div. 2)題解記錄(A,B,E)2024-09-28
- Codeforces Round #541 (Div. 2)2019-02-24
- Codeforces Round 940 (Div. 2)2024-04-22
- Codeforces Round 934 (Div. 2)2024-03-17
- Codeforces Round 932 (Div. 2)2024-03-13
- Codeforces Round 948 (Div. 2)2024-05-27
- Codeforces Round #639 (Div. 2)2020-05-07
- Codeforces Round #672 (Div. 2)2020-09-25
- Codeforces Round #682 (Div. 2)2020-11-16
- Codeforces Round #678 (Div. 2)2020-10-25
- Codeforces Round #673 (Div. 2)2020-09-29