lucifer1004 / cp-wiki

lucifer1004 的 CP 笔记
https://cp-wiki.vercel.app
130 stars 15 forks source link

AtCoder Beginner Contest 182 Tutorial #19

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

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/

swapno7064 commented 3 years ago

can you explain F a bit more??

lucifer1004 commented 3 years ago

@swapno7064 I have added an example.

heyuhhh commented 3 years ago

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

lucifer1004 commented 3 years ago

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

swapno7064 commented 3 years ago

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 commented 3 years ago

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

swapno7064 commented 3 years ago

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 commented 3 years ago

@swapno7064 The coefficients can be negative.

Mastan1301 commented 3 years ago
#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 commented 3 years ago

This is for Problem-C.