Manthan, Codefest 16A Ebony and Lvory

Problem - A - Codeforces

Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool used[10500];

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  memset(used, 0, sizeof(used));
  used[0] = true;

  rep(i, c + 1) {
      if(used[i]) {
          used[i+a] = true;
      }
  }

  rep(i, c + 1) {
      if(used[i]) {
          used[i+b] = true;
      }
  }

  if(used[c]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}
Feb 29th, 2016