Submission #1275652
Source Code Expand
#include "bits/stdc++.h" using namespace std; #define OUT(x) cout << #x << " = " << x << endl; #define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++) #define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++) #define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++) #define each(i, v) for (auto i : v) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb(x) push_back(x) #define bp(x) __builtin_popcount(x) #define mp(x, y) make_pair((x), (y)) #define fi first #define se second #define setp(x) setprecision(x) #define mset(m, v) memset(m, v, sizeof(m)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; static const int MOD = 1000000007; static const double PI = 3.14159265358979; #define int long long typedef vector<double> vd; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; } template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } int in() { int _x; cin >> _x; return _x; } signed main() { int m; cin >> m; int a[6]; rep(i, 6) cin >> a[i]; int s = in(), g = in(); s --; g --; vi p(m); rep(i, m) cin >> p[i]; queue<pair<int, vector<int>>> q; bool f = false; rep(i, 6) { if (0 <= g + a[i] && g + a[i] < m) { vi add; add.pb(i + 1); q.push(mp(g + a[i], add)); if (g + a[i] == s) { f = true; break; } } if (0 <= g - a[i] && g - a[i] < m) { vi add; add.pb(-(i + 1)); q.push(mp(g - a[i], add)); if (g - a[i] == s) { f = true; break; } } } while (!f) { pair<int, vi> qq; qq = q.front(); q.pop(); rep(i, m) { if (i + p[i] == qq.fi) { rep(j, 6) { //OUT(j); if (0 <= i + a[j] && i + a[j] < m) { //OUT(i + a[j]); vi add; add.pb(j + 1); rep(k, qq.se.size()) add.pb(qq.se[k]); q.push(mp(i + a[j], add)); if (i + a[j] == s) { f = true; break; } } if (0 <= i - a[j] && i - a[j] < m) { //OUT(i - a[j]); vi add; add.pb(-(j + 1)); rep(k, qq.se.size()) add.pb(qq.se[k]); q.push(mp(i - a[j], add)); if (i - a[j] == s) { f = true; break; } } } } } } vector<int> ans = q.back().se; reverse(all(ans)); rep(pp, ans.size()) { int dice; cin >> dice; if (ans[pp] == -dice) cout << 1 << endl; else if (ans[pp] == dice) cout << -1 << endl; else { cout << 0 << endl; pp --; } } return 0; }