Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AtCoder Beginner Contest 182 Tutorial #19

Open
utterances-bot opened this issue Nov 8, 2020 · 10 comments
Open

AtCoder Beginner Contest 182 Tutorial #19

utterances-bot opened this issue Nov 8, 2020 · 10 comments

Comments

@utterances-bot
Copy link

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/

Copy link

can you explain F a bit more??

@lucifer1004
Copy link
Owner

@swapno7064 I have added an example.

Copy link

heyuhhh commented Nov 9, 2020

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

@lucifer1004
Copy link
Owner

@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.

Copy link

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.

@lucifer1004
Copy link
Owner

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

@swapno7064
Copy link

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 ??

@lucifer1004
Copy link
Owner

@swapno7064 The coefficients can be negative.

Copy link

#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?

Copy link

This is for Problem-C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants