Codeforces Global Round 1 A--E

3235 단어 CodeForces
A. Parity
/**
  :    ,     
*/
#include
#define ll long long
using namespace std;

int main (){
    int b,k,ans=0;cin>>b>>k;
    for(int i=0;i>x;
        ans=(ans*b+x)%2;
    }
    puts((ans&1)?"odd":"even");
    return 0;
}
//python
b , k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for x in a:
    ans = (ans*b+x)%2
if ans&1 == True:
    print("odd")
else :
    print("even")

B. Tape
/**
  ,      ,       ,  k-1   
*/
#include
#define ll long long
using namespace std;
const int maxn=1e6+7;
ll a[maxn],b[maxn];
int main(){
    ll n,m,k;
    scanf("%lld %lld %lld",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=2;i<=n;i++) b[i-1]=a[i]-a[i-1]-1;
    sort(b+1,b+n);
    ll ans=0;
    for(int i=1;i<=n-k;i++) ans+=b[i];
    printf("%lld
",ans+n); return 0; }

C. Meaningless Operations
/**
      ,n 2^x - 1 ans:n      ,          n    -1
*/
#include
#define ll long long
using namespace std;
int main(){
	int t;cin>>t;
	while(t--){
		cin>>n;
		int fac=1,flag=0,tmp=n;
		while(n){
			if(n%2==0) flag=1;
			n/=2,fac*=2;
		}
		if(flag) printf("%d
",fac-1); else{ int mx=1;n=tmp; for(int i=2;i*i<=n;i++) if(n%i==0) mx=max(mx,max(n/i,i)); printf("%d
",mx); } } return 0; }

 D. Jongmah
/**
  :                     
  :      ,dp[i][j][k]:  1-->i j         k       ;
  j      ,    a+1--->a+1,a+1,a+1    :dp[i][j][k]=max(dp[i][j][k],dp[i-1][k+x][x]+x+(a[i]-j-x)/3);
*/
#include
#define ll long long
using namespace std;

int k,x,b[300001],a[2000001],dp[3000001][5][3];

int main(){
	int n,m;scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		a[x]++;
	}
	memset(dp,2000,sizeof(dp));
	for(int i=0;i<=2;i++) dp[1][i][0]=(a[1]-i)/3;
	for(int i=2;i<=m;i++)
	 for(int j=0;j<=4;j++) if(a[i]>=j)
	  for(int k=0;k<=2;k++) if(a[i-1]>=k)
	   for(int x=0;x<=2;x++)
        if(a[i]-j>=x&&a[i-1]-k>=x) dp[i][j][k]=max(dp[i][j][k],dp[i-1][k+x][x]+x+(a[i]-j-x)/3);
	//
	cout<

E. Magic Stones
/**
E. Magic Stones
https://codeforces.com/contest/1110/problem/E
      ;
   [a1,a2,a3],       [a1,a1+a3-a2,a3],         [a3-a2,a2-a1]
                               ;
*******tricks****
         QWQ
*/
#include
#define ll long long
using namespace std;

ll k,n,m,b[200001],a[200001];

mapmp;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],mp[a[i]-a[i-1]]++;;//a[0]=0,a[n]=0;
	for(int i=1;i<=n;i++) cin>>b[i];//b[0]=0,b[n]=0;
	if(a[1]!=b[1]||a[n]!=b[n]) {puts("No");return 0;}
	for(int i=1;i<=n;i++){
        if(mp[b[i]-b[i-1]]==0) { puts("No");return 0;}
        else mp[b[i]-b[i-1]]--;
	}
	if(a[n]!=b[n]) puts("No");
	else puts("Yes");
	return 0;

	/**
	7 2 4 12
	7 15 10 12

	-5 2 8
	8 -5 2
	
	2 3 2
	2 1 2
	2 1 -1
	2 -1 1
	
	*/
}

좋은 웹페이지 즐겨찾기