Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///https://informatics.msk.ru/mod/statements/view.php?id=298&chapterid=366#1
- #include <iostream>
- #include <set>
- #include <vector>
- #include <deque>
- #define se second
- #define fi first
- #define mp make_pair
- #define pb push_back
- using namespace std;
- vector<int> F;
- int f(int n) {
- if (n <= 0) return 2;
- if (F[n] != 0) return F[n];
- vector<int> next;
- if (n % 3 == 0) {
- next = {n - 1, n - 2};
- } else if (n % 3 == 1) {
- next = {n - 1, n - 3};
- } else {
- next = {n - 1, n - 2, n - 3};
- }
- for (auto e : next) {
- if (f(e) == 2) {
- F[n] = 1;
- return 1;
- }
- }
- F[n] = 2;
- return 2;
- }
- int main() {
- int n;
- cin >> n;
- F.assign(n + 1, 0);
- cout << f(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement