ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1573. Alchemy

Can somebody give me the whole explanation to this problem. Thanks beforehand!
Posted by Sanatbek_Matlatipov 13 Oct 2015 13:27
Can somebody give me the whole explanation to this problem. Thanks beforehand!
Re: Can somebody give me the whole explanation to this problem. Thanks beforehand!
Posted by Egor 24 Nov 2016 16:01
If you have two different sets A = {a1, a2, a3} and B = {b1, b2, b3, b4} then we have |A| * |B| = 3 * 4 = 12 ways to choose a pair (a[i], b[j]).

i\j   b[1]  b[2]  b[3]  b[4]
a[1] [1,1] [1,2] [1,3] [1,4]
a[2] [2,1] [2,2] [2,3] [2,4]
a[3] [3,1] [3,2] [3,3] [3,4]

Modern language solution looks like that:
map<string, int> cnt;
for (auto color : {"Blue", "Red", "Yellow"})
  cin >> cnt[color];

int colors;
cin >> colors;

int ways = 1;
for (int i = 0; i < colors; i++)
{
  string color;
  cin >> color;

  ways *= cnt[color];
}

cout << ways;

Edited by author 24.11.2016 16:04

Edited by author 24.11.2016 16:07