257B - Playing Cubes - CodeForces Solution


games greedy implementation *1300

Please click on ads to support us..

Python Code:

n,m=list(map(int,input().split()))
result=[[],[]]
a=n
b=m
count=0
while count<n+m:
    if count%2==0:
        if result[0]==[]:
            result[0].append(1)
            a-=1
        else:
            if result[0][count-1]==1 and a>0:
                result[0].append(1)
                a-=1
            elif result[0][count-1]==-1 and b>0:
                result[0].append(-1)
                b-=1
            else:
                if a>0:
                    result[0].append(1)
                    a-=1
                else:
                    result[0].append(-1)
                    b-=1
    else:
        if result[0][count-1]==1 and b>0:
            result[0].append(-1)
            b-=1
        elif result[0][count-1]==-1 and a>0:
            result[0].append(1)
            a-=1
        else:
            if a>0:
                result[0].append(1)
                a-=1
            else:
                result[0].append(-1)
                b-=1
    count+=1
a=n
b=m
count=0
while count<n+m:
    if count%2==0:
        if result[1]==[]:
            result[1].append(-1)
            b-=1
        else:
            if result[1][count-1]==1 and a>0:
                result[1].append(1)
                a-=1
            elif result[1][count-1]==-1 and b>0:
                result[1].append(-1)
                b-=1
            else:
                if a>0:
                    result[1].append(1)
                    a-=1
                else:
                    result[1].append(-1)
                    b-=1
    else:
        if result[1][count-1]==1 and b>0:
            result[1].append(-1)
            b-=1
        elif result[1][count-1]==-1 and a>0:
            result[1].append(1)
            a-=1
        else:
            if a>0:
                result[1].append(1)
                a-=1
            else:
                result[1].append(-1)
                b-=1
    count+=1
score=[[],[]]
for i in range(len(result)):
    p=0
    v=0
    for j in range(len(result[i])-1):
        if result[i][j]==result[i][j+1]:
            p+=1
        else:
            v+=1
    score[i].append(p)
    score[i].append(v)
index=0
if score[1][0]>score[0][0]:
    index=1
for i in score[index]:
    print(i,end=" ")
	  	   		 			   	 		  	 	 	  		

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n,m;
    cin>>n>>m;
    cout<<n+m-1-min(n,m)<<" "<<min(n,m);
    return 0;
}


Comments

Submit
0 Comments
More Questions

1559B - Mocha and Red and Blue
1579C - Ticks
268B - Buttons
898A - Rounding
1372B - Omkar and Last Class of Math
1025D - Recovering BST
439A - Devu the Singer and Churu the Joker
1323A - Even Subset Sum Problem
1095A - Repeating Cipher
630F - Selection of Personnel
630K - Indivisibility
20B - Equation
600B - Queries about less or equal elements
1015A - Points in Segments
1593B - Make it Divisible by 25
680C - Bear and Prime 100
1300A - Non-zero
1475E - Advertising Agency
1345B - Card Constructions
1077B - Disturbed People
653A - Bear and Three Balls
794A - Bank Robbery
157A - Game Outcome
3B - Lorry
1392A - Omkar and Password
489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp