777A - Shell Game - CodeForces Solution


constructive algorithms implementation math *1000

Please click on ads to support us..

Python Code:

n=int(input())
p=int(input())
ls1=[0,1,2]
ls2=[1,0,2]
if(n%6==0):
    print(ls1[p])
elif(n%6==1):
    print(ls2[p])
elif(n%6==2):
    ls1=ls1[1:]+ls1[:1]
    print(ls1[p])
elif(n%6==3):
    ls2=ls2[-1:]+ls2[:-1]
    print(ls2[p])
elif(n%6==4):
    ls1=ls1[2:]+ls1[:2]
    print(ls1[p])
elif(n%6==5):
    ls2=ls2[-2:]+ls2[:-2]
    print(ls2[p])

C++ Code:

// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <istream>
#include <numeric>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
#define gogo ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define assertm(exp, msg) assert(((void)msg, exp))
#define rep(i, a, n) for (int i = a;i < n;i ++)
#define per(i, n, a) for (int i = n - 1;i>= a;i --)
#define x first
#define y second
#define vt vector
#define ar array
#define pb push_back
#define sz(x) (int)(x).size()
#define EACH(x, a) for (auto& x: a)
#define FOR(a) for(auto it : a)
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {cin >> x;}
void read(double& d) {string t;read(t);d=stod(t);}
void read(long double& d) {string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) { EACH(a, x) read(a); }
template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a);}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
template<class A> void write(A x) { cout << x; }
template<class H, class... T> void write(const H& h, const T&... t) { write(h);write(t...); }
void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { 
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}
template <typename T> void outg(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector<vector<T>> res(m, vector<T>(n));
    rep(i, 0, n) {
        rep(j, 0, m) 
            write(v[i][j], ' ');
        print();
    }
}
template <typename T> void outv(vector<T> &v) {
    if(empty(v)) return;
    for (auto i : v) write(i, ' ');
    print();
}
template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
    for (int i = start;i < end;i ++)
        cout << v[i] << (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
template <class T, class S> T POW(T x, S n, const ll &mod) {
    T res = 1;
    x %= mod;
    for(; n; n >>= 1, x = x * x % mod)
        if(n & 1) res = res * x % mod;
    return res;
}
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
template <typename T> void rot(vector<vector<T>> &v) {
    if(empty(v)) return;
    int n = v.size(), m = v[0].size();
    vector<vector<T>> res(m, vector<T>(n));
    rep(i, 0, n) rep(j, 0, m) res[m - 1 - j][i] = v[i][j];
    v.swap(res);
}
// x in [l, r)
template <class T, class S> bool inc(const T &x, const S &l, const S &r) { return l <= x and x < r; }
string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; }
string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; }
namespace DEBUG {
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& V) {
  os << "[ ";
  for (const auto& vv : V) os << vv << ", ";
  os << "]";
  return os;
}
template <typename T>
inline void _debug(const char* format, T t) {
  cerr << format << '=' << t << endl;
}
template <class First, class... Rest>
inline void _debug(const char* format, First first, Rest... rest) {
  while (*format != ',') cerr << *format++;
  cerr << '=' << first << ",";
  _debug(format + 1, rest...);
}
#define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
}  // namespace DEBUG

using namespace DEBUG;
int main() {
	gogo;

	int N, x;
	cin >> N >> x;

	int ans[6][3] = {
		{1, 0, 2},
		{1, 2, 0},
		{2, 1, 0},
		{2, 0, 1},
		{0, 2, 1},
		{0, 1, 2}
	};

	cout << ans[(N - 1) % 6][x] << '\n';

    return 0;
}






Comments

Submit
0 Comments
More Questions

118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream