cp-wiki icon indicating copy to clipboard operation
cp-wiki copied to clipboard

AtCoder Beginner Contest 182 Tutorial

Open utterances-bot opened this issue 5 years ago • 10 comments

AtCoder Beginner Contest 182 Tutorial | CP Wiki

A number can be divided by $3$ if and only if the sum of its digits can be divided by $3$.

https://cp-wiki.vercel.app/en/tutorial/atcoder/ABC182/

utterances-bot avatar Nov 08 '20 20:11 utterances-bot

can you explain F a bit more??

swapno7064 avatar Nov 08 '20 20:11 swapno7064

@swapno7064 I have added an example.

lucifer1004 avatar Nov 08 '20 22:11 lucifer1004

why we need to ensure the current sum can be divided by a_{i+1}?

heyuhhh avatar Nov 09 '20 01:11 heyuhhh

@heyuhhh Because in the future, we can never use numbers less than $a_{i+1}$. So if the current value cannot be divided by $a_{i+1}$, it will never become 0.

lucifer1004 avatar Nov 12 '20 09:11 lucifer1004

from the above example how come 7 unique value can be generated means we have to find no of unique 'y' above 'X' . so how come 7 will be the answer?? i think only valid unique numbers are 192,216, 190 above 'X= 190'.?? can explain the transition.

swapno7064 avatar Nov 17 '20 09:11 swapno7064

@swapno7064 Note that for each number in the intermediate transitions, there is a count of different ways to reach that number.

lucifer1004 avatar Nov 17 '20 12:11 lucifer1004

but the condition says we will use minimum coins like in the given example 108+(236)+(12)=192 only 1 way to reach 192...instead of 12 we cannot use (34)coins ??

swapno7064 avatar Nov 17 '20 13:11 swapno7064

@swapno7064 The coefficients can be negative.

lucifer1004 avatar Nov 17 '20 13:11 lucifer1004

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vint> vvint;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef pair<ll, ll> iPair;
#define ff first
#define ss second

int main(){
	ll n, k = 0;
	cin >> n;
	vint cnt(3, 0);
	while(n){
		cnt[(n % 10) % 3]++;
		n /= 10;
		k++;
	}
	
	ll ans = abs(cnt[1] - cnt[2]) % 3;
	if(ans <= k - 1){
		cout << ans;
	}
	else
		cout << -1;


	return 0;
}

Can you tell me why this method won't work?

Mastan1301 avatar Mar 12 '21 05:03 Mastan1301

This is for Problem-C.

Mastan1301 avatar Mar 12 '21 05:03 Mastan1301