problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define inf 2000000009 #define mod 1000000007 using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); bool dp[k + 1][2]; // 0 odd 1 even for (ll i = 0; i < k + 1; i++) for (ll j = 0; j < 2; j++) dp[i][j] = 0; dp[0][1] = 1; for (ll i = 1; i <= k; i++) { bool f = 0, f1 = 0, t1 = 0, t2 = 0; for (ll j = 0; a[j] <= i; j++) { if (dp[i - a[j]][0] == 0 and dp[i - a[j]][1] == 1) dp[i][0] = 1; else if (dp[i - a[j]][0] == 1 and dp[i - a[j]][1] == 0) dp[i][1] = 1; } if (dp[i][0] == 0 and dp[i][1] == 0) dp[i][0] = dp[i - 1][0], dp[i][1] = dp[i - 1][1]; } if (dp[k][0] == 1) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define inf 2000000009 #define mod 1000000007 using namespace std; int main() { fast; ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); bool dp[k + 1][2]; // 0 odd 1 even for (ll i = 0; i < k + 1; i++) for (ll j = 0; j < 2; j++) dp[i][j] = 0; dp[0][1] = 1; for (ll i = 1; i <= k; i++) { bool f = 0, f1 = 0, t1 = 0, t2 = 0; for (ll j = 0; a[j] <= i; j++) { if (dp[i - a[j]][0] == 0 and dp[i - a[j]][1] == 1) dp[i][0] = 1; else if (dp[i - a[j]][0] == 1 and dp[i - a[j]][1] == 0) dp[i][1] = 1; } if (dp[i][0] == 0 and dp[i][1] == 0) dp[i][0] = dp[i - 1][0], dp[i][1] = dp[i - 1][1]; } if (dp[k][0] == 1) cout << "First" << endl; else cout << "Second" << endl; }
delete
16
20
16
16
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vll vector<long long> #define str string #define ch char #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair int dp[100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int ar[n]; int mx = 0; for (int i = 0; i < n; i++) { cin >> ar[i]; dp[ar[i]] = 1; mx = max(mx, ar[i]); } for (int i = 1; i <= k; i++) { if (dp[i] == 1) continue; for (int j = 1; j < n; j++) { if (dp[i - ar[j]] == 0) { dp[i] = 1; } } } if (dp[k] == 1) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vll vector<long long> #define str string #define ch char #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair int dp[100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int ar[n]; int mx = 0; for (int i = 0; i < n; i++) { cin >> ar[i]; dp[ar[i]] = 1; mx = max(mx, ar[i]); } for (int i = 1; i <= k; i++) { if (dp[i] == 1) continue; for (int j = 0; j < n; j++) { if (i - ar[j] >= 1 && dp[i - ar[j]] == 0) { dp[i] = 1; } } } if (dp[k] == 1) cout << "First"; else cout << "Second"; }
replace
28
30
28
30
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define MOD 1000000007 #define ar array #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); char game(int K, vector<int> &a, vector<int> &in_set, vector<char> &state) { if (state[K] != 'X') return state[K]; if (in_set[K]) { state[K] = 'W'; return 'W'; } char curr_state = 'L'; for (int i = 0; i < a.size(); i++) { if (game(K - a[i], a, in_set, state) == 'L') { curr_state = 'W'; break; } } state[K] = curr_state; return curr_state; } int32_t main() { fast_io; // int t; cin >> t; // while (t--) { // } int n, k; cin >> n >> k; vector<int> a(n); vector<int> in_set(k + 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; in_set[a[i]]++; } vector<char> state(k + 1, 'X'); state[0] = 'L'; char ans = game(k, a, in_set, state); if (ans == 'W') { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define MOD 1000000007 #define ar array #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); char game(int K, vector<int> &a, vector<int> &in_set, vector<char> &state) { if (state[K] != 'X') return state[K]; if (in_set[K]) { state[K] = 'W'; return 'W'; } char curr_state = 'L'; for (int i = 0; i < a.size(); i++) { if (K - a[i] >= 0 && game(K - a[i], a, in_set, state) == 'L') { curr_state = 'W'; break; } } state[K] = curr_state; return curr_state; } int32_t main() { fast_io; // int t; cin >> t; // while (t--) { // } int n, k; cin >> n >> k; vector<int> a(n); vector<int> in_set(k + 1, 0); for (int i = 0; i < n; i++) { cin >> a[i]; in_set[a[i]]++; } vector<char> state(k + 1, 'X'); state[0] = 'L'; char ans = game(k, a, in_set, state); if (ans == 'W') { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
19
20
19
20
0
p03170
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/timeb.h> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define reprev(i, n) reprrev(i, 0, n) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define chmin(mi, value) mi = min(mi, value) #define chmax(ma, value) ma = max(ma, value) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mp make_pair #define mt make_tuple #define INF 1050000000 #define INFR INT_MAX #define INFL (long long)(4e18) #define INFLR LLONG_MAX #define EPS (1e-10) #define MOD 1000000007 // #define MOD 998244353 #define PI 3.141592653589793238 #define RMAX 4294967295 using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vvvvi = vector<vector<vector<vector<int>>>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vvvd = vector<vector<vector<double>>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vvs = vector<vector<string>>; using Pi = pair<int, int>; using vPi = vector<Pi>; using vvPi = vector<vector<Pi>>; using vvvPi = vector<vector<vector<Pi>>>; using vvvvPi = vector<vector<vector<vector<Pi>>>>; using Pll = pair<ll, ll>; using vPll = vector<Pll>; using Pd = pair<double, double>; using vPd = vector<Pd>; template <class T> using vec = vector<T>; template <class T> using pql = priority_queue<T, vector<T>, greater<T>>; using Comp = complex<double>; // vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv // vector input template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // deque template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } // multiset template <typename T> ostream &operator<<(ostream &os, const multiset<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif // ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^ string YN(bool y, int id = 0) { if (id) cout << id; return (y ? "YES" : "NO"); } string yn(bool y, int id = 0) { if (id) cout << id; return (y ? "Yes" : "No"); } string ON(bool y, int id = 0) { if (id) cout << id; return (y ? "OK" : "NG"); } int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}}; int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}}; char dirchar[4] = {'<', '^', '>', 'v'}; // [a,b) int irand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_int_distribution<int> dist(a, b - 1); return dist(Rand); } // [a,b) double drand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_real_distribution<double> dist(a, b); return dist(Rand); } // https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c template <typename A, typename F> inline auto transform(const A &v, F &&f) { using result_type = decltype(std::declval<F>()(std::declval<typename A::value_type>())); vector<result_type> y(v.size()); std::transform(std::cbegin(v), std::cend(v), std::begin(y), f); return y; } // generate vector which has multiple dimension template <class T> vector<T> make_v(size_t size, const T &init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <typename T> T Max(vector<T> a) { return *max_element(all(a)); } template <typename T> T Min(vector<T> a) { return *min_element(all(a)); } template <typename T> T Sum(vector<T> a) { return accumulate(all(a), (T)0); } // for counting using map template <typename T> void Add(map<T, int> &m, T item) { if (m.find(item) == m.end()) { m[item] = 1; } else { m[item]++; } } // for counting using map template <typename T> void Erase(map<T, int> &m, T item) { if (m.find(item) == m.end()) { } else { if (m[item] == 1) { m.erase(item); } else { m[item]--; } } } // get method for map with default value template <typename T, typename U> U Get(map<T, U> m, T key, U def) { if (m.find(key) == m.end()) { return def; } else { return m[key]; } } template <typename T> inline bool Contains(const set<T> &t, const T &key) { return t.find(key) != t.end(); } template <typename T, typename U> inline bool Contains(const map<T, U> &t, const T &key) { return t.find(key) != t.end(); } template <class T> struct Edge { int from, to; T cost; Edge(int f, int t, T c) : from(f), to(t), cost(c) {} }; template <class T> bool operator<(const Edge<T> e1, const Edge<T> e2) { return e1.cost < e2.cost || (e1.cost == e2.cost && e1.from < e2.from) || (e1.cost == e2.cost && e1.from == e2.from && e1.to < e2.to); } template <class T> ostream &operator<<(ostream &os, const Edge<T> &edge) { os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")"; return os; } template <class T = int> class Graph { int n; bool directed; vector<vector<Edge<T>>> edges; public: Graph(int n, bool directed) : n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {} void add_edge(int s, int t, T cost) { edges[s].emplace_back(s, t, cost); if (!directed) { edges[t].emplace_back(t, s, cost); } } Graph() {} vector<Edge<T>> &operator[](size_t i) { return edges[i]; } int size() const { return n; } }; //====================================================== int main() { int N, K; cin >> N >> K; vi a(N); cin >> a; vb win(N + 1, false); rep(i, K + 1) { rep(j, N) { if (i - a[j] >= 0 && !win[i - a[j]]) win[i] = true; } } if (win[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/timeb.h> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define reprev(i, n) reprrev(i, 0, n) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define chmin(mi, value) mi = min(mi, value) #define chmax(ma, value) ma = max(ma, value) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define mp make_pair #define mt make_tuple #define INF 1050000000 #define INFR INT_MAX #define INFL (long long)(4e18) #define INFLR LLONG_MAX #define EPS (1e-10) #define MOD 1000000007 // #define MOD 998244353 #define PI 3.141592653589793238 #define RMAX 4294967295 using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vvvvi = vector<vector<vector<vector<int>>>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vvvd = vector<vector<vector<double>>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvc = vector<vector<char>>; using vs = vector<string>; using vvs = vector<vector<string>>; using Pi = pair<int, int>; using vPi = vector<Pi>; using vvPi = vector<vector<Pi>>; using vvvPi = vector<vector<vector<Pi>>>; using vvvvPi = vector<vector<vector<vector<Pi>>>>; using Pll = pair<ll, ll>; using vPll = vector<Pll>; using Pd = pair<double, double>; using vPd = vector<Pd>; template <class T> using vec = vector<T>; template <class T> using pql = priority_queue<T, vector<T>, greater<T>>; using Comp = complex<double>; // vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv // vector input template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // deque template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } // multiset template <typename T> ostream &operator<<(ostream &os, const multiset<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif // ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^ string YN(bool y, int id = 0) { if (id) cout << id; return (y ? "YES" : "NO"); } string yn(bool y, int id = 0) { if (id) cout << id; return (y ? "Yes" : "No"); } string ON(bool y, int id = 0) { if (id) cout << id; return (y ? "OK" : "NG"); } int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}}; int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0}, {1, 0}, {-1, 1}, {0, 1}, {1, 1}}; char dirchar[4] = {'<', '^', '>', 'v'}; // [a,b) int irand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_int_distribution<int> dist(a, b - 1); return dist(Rand); } // [a,b) double drand(int a, int b) { static mt19937 Rand(static_cast<unsigned int>(time(nullptr))); uniform_real_distribution<double> dist(a, b); return dist(Rand); } // https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c template <typename A, typename F> inline auto transform(const A &v, F &&f) { using result_type = decltype(std::declval<F>()(std::declval<typename A::value_type>())); vector<result_type> y(v.size()); std::transform(std::cbegin(v), std::cend(v), std::begin(y), f); return y; } // generate vector which has multiple dimension template <class T> vector<T> make_v(size_t size, const T &init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <typename T> T Max(vector<T> a) { return *max_element(all(a)); } template <typename T> T Min(vector<T> a) { return *min_element(all(a)); } template <typename T> T Sum(vector<T> a) { return accumulate(all(a), (T)0); } // for counting using map template <typename T> void Add(map<T, int> &m, T item) { if (m.find(item) == m.end()) { m[item] = 1; } else { m[item]++; } } // for counting using map template <typename T> void Erase(map<T, int> &m, T item) { if (m.find(item) == m.end()) { } else { if (m[item] == 1) { m.erase(item); } else { m[item]--; } } } // get method for map with default value template <typename T, typename U> U Get(map<T, U> m, T key, U def) { if (m.find(key) == m.end()) { return def; } else { return m[key]; } } template <typename T> inline bool Contains(const set<T> &t, const T &key) { return t.find(key) != t.end(); } template <typename T, typename U> inline bool Contains(const map<T, U> &t, const T &key) { return t.find(key) != t.end(); } template <class T> struct Edge { int from, to; T cost; Edge(int f, int t, T c) : from(f), to(t), cost(c) {} }; template <class T> bool operator<(const Edge<T> e1, const Edge<T> e2) { return e1.cost < e2.cost || (e1.cost == e2.cost && e1.from < e2.from) || (e1.cost == e2.cost && e1.from == e2.from && e1.to < e2.to); } template <class T> ostream &operator<<(ostream &os, const Edge<T> &edge) { os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")"; return os; } template <class T = int> class Graph { int n; bool directed; vector<vector<Edge<T>>> edges; public: Graph(int n, bool directed) : n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {} void add_edge(int s, int t, T cost) { edges[s].emplace_back(s, t, cost); if (!directed) { edges[t].emplace_back(t, s, cost); } } Graph() {} vector<Edge<T>> &operator[](size_t i) { return edges[i]; } int size() const { return n; } }; //====================================================== int main() { int N, K; cin >> N >> K; vi a(N); cin >> a; vb win(K + 1, false); rep(i, K + 1) { rep(j, N) { if (i - a[j] >= 0 && !win[i - a[j]]) win[i] = true; } } if (win[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
314
315
314
315
0
p03170
C++
Runtime Error
// {{{ #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define FOR(i, a, b) \ for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++) #define FORR(i, a, b) \ for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--) #define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++) #define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> IP; typedef pair<ll, LP> LLP; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; constexpr int INF = 100000000; constexpr ll LINF = 10000000000000000ll; constexpr int MOD = static_cast<int>(1e9 + 7); constexpr double EPS = 1e-9; static inline ll mod(ll x, ll m) { ll y = x % m; return (y >= 0 ? y : y + m); } // }}} int N, K; int a[100]; bool dp[100001]; void solve() { dp[0] = false; REP(i, K + 1) { REP(j, N) { dp[i + a[j]] |= !dp[i]; } } cout << (dp[K] ? "First" : "Second") << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; REP(i, N) cin >> a[i]; solve(); return 0; } // vim:set foldmethod=marker:
// {{{ #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define FOR(i, a, b) \ for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++) #define FORR(i, a, b) \ for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--) #define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++) #define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> IP; typedef pair<ll, LP> LLP; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; constexpr int INF = 100000000; constexpr ll LINF = 10000000000000000ll; constexpr int MOD = static_cast<int>(1e9 + 7); constexpr double EPS = 1e-9; static inline ll mod(ll x, ll m) { ll y = x % m; return (y >= 0 ? y : y + m); } // }}} int N, K; int a[100]; bool dp[100001]; void solve() { dp[0] = false; REP(i, K + 1) { REP(j, N) { if (i + a[j] <= K) dp[i + a[j]] |= !dp[i]; } } cout << (dp[K] ? "First" : "Second") << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; REP(i, N) cin >> a[i]; solve(); return 0; } // vim:set foldmethod=marker:
replace
61
62
61
65
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) #define MOD 1000000007 #define INF 1e9 #define INFL 1e12 typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; template <class T> void pr(T x) { cout << x << endl; } template <class T> void prvec(vector<T> &a) { rep(i, a.size() - 1) { cout << a[i] << " "; } cout << a[a.size() - 1] << endl; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int dp[10010] = {}; // rep(i, n) printf("%d ", a[i]); cout << endl; int m = 100000; rep(i, n) chmin(m, a[i]); rep(i, m) dp[i] = -1; for (int i : a) dp[i] = 1; rep(i, k + 1) { if (dp[i] != 0) continue; for (int j : a) { if (i - j >= 0 && dp[i - j] == -1) { dp[i] = 1; break; } } if (dp[i] == 0) dp[i] = -1; } // rep(i, k+1) printf("%d ", dp[i]); cout << endl; if (dp[k] == 1) printf("First\n"); else printf("Second\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) #define MOD 1000000007 #define INF 1e9 #define INFL 1e12 typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; template <class T> void pr(T x) { cout << x << endl; } template <class T> void prvec(vector<T> &a) { rep(i, a.size() - 1) { cout << a[i] << " "; } cout << a[a.size() - 1] << endl; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; int dp[100100] = {}; // rep(i, n) printf("%d ", a[i]); cout << endl; int m = 100000; rep(i, n) chmin(m, a[i]); rep(i, m) dp[i] = -1; for (int i : a) dp[i] = 1; rep(i, k + 1) { if (dp[i] != 0) continue; for (int j : a) { if (i - j >= 0 && dp[i - j] == -1) { dp[i] = 1; break; } } if (dp[i] == 0) dp[i] = -1; } // rep(i, k+1) printf("%d ", dp[i]); cout << endl; if (dp[k] == 1) printf("First\n"); else printf("Second\n"); return 0; }
replace
38
39
38
39
0
p03170
C++
Runtime Error
// We only fail when we stop trying #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define endl '\n' #define D(x) cerr << #x << " = " << (x) << '\n' #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() const int N = 101; const int V = 100010; int n, k; int a[N]; int dp[N]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 0; for (int i = 1; i <= k; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if (i - a[j] >= 0 && !dp[i - a[j]]) { dp[i] = 1; break; } } } cout << (dp[k] ? "First" : "Second") << endl; return 0; }
// We only fail when we stop trying #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define endl '\n' #define D(x) cerr << #x << " = " << (x) << '\n' #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() const int N = 101; const int V = 100010; int n, k; int a[N]; int dp[V]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 0; for (int i = 1; i <= k; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if (i - a[j] >= 0 && !dp[i - a[j]]) { dp[i] = 1; break; } } } cout << (dp[k] ? "First" : "Second") << endl; return 0; }
replace
15
16
15
16
0
p03170
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < n; ++i) #define exout(x) printf("%.10f\n", x) const double pi = acos(-1.0); const ll MOD = 1000000007; const ll INF = 1e10; const ll MAX_N = 1010; // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { if (x == 0 || y == 0) return 0; return (x / gcd(x, y) * y); } bool dp[101010]; ll dx[4] = {0, 0, -1, 1}; ll dy[4] = {-1, 1, 0, 0}; ll a[303]; // long longしか使わない // 素数は1より大きい int main() { ll n, k; cin >> n >> k; rep(i, n) { cin >> a[i]; } for (ll i = 0; i <= k; ++i) { rep(j, n) { if (dp[i] == false) { dp[i + a[j]] = true; } } } if (dp[k]) puts("First"); else { puts("Second"); } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < n; ++i) #define exout(x) printf("%.10f\n", x) const double pi = acos(-1.0); const ll MOD = 1000000007; const ll INF = 1e10; const ll MAX_N = 1010; // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { if (x == 0 || y == 0) return 0; return (x / gcd(x, y) * y); } bool dp[1010101]; ll dx[4] = {0, 0, -1, 1}; ll dy[4] = {-1, 1, 0, 0}; ll a[303]; // long longしか使わない // 素数は1より大きい int main() { ll n, k; cin >> n >> k; rep(i, n) { cin >> a[i]; } for (ll i = 0; i <= k; ++i) { rep(j, n) { if (dp[i] == false) { dp[i + a[j]] = true; } } } if (dp[k]) puts("First"); else { puts("Second"); } return 0; }
replace
43
44
43
44
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define all(x) (x).begin(), (x).end() #define MAX(a, b) (a > b ? a : b) #define MIN(a, b) (a < b ? a : b) const int MOD = 1000000007; bool DP[100001]; int main() { IOS; int N, K; cin >> N >> K; int a[N]; for (int i = 0; i < N; i++) { cin >> a[i]; DP[a[i]] = true; } for (int i = a[0] + 1; i <= K; i++) { if (DP[i]) continue; for (int j = 0; j < N; j++) { if (!DP[i - a[j]]) { DP[i] = true; break; } } } if (DP[K]) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define all(x) (x).begin(), (x).end() #define MAX(a, b) (a > b ? a : b) #define MIN(a, b) (a < b ? a : b) const int MOD = 1000000007; bool DP[100001]; int main() { IOS; int N, K; cin >> N >> K; int a[N]; for (int i = 0; i < N; i++) { cin >> a[i]; DP[a[i]] = true; } for (int i = a[0] + 1; i <= K; i++) { if (DP[i]) continue; for (int j = 0; j < N; j++) { if (i - a[j] >= 0 && !DP[i - a[j]]) { DP[i] = true; break; } } } if (DP[K]) cout << "First"; else cout << "Second"; return 0; }
replace
28
29
28
29
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define pb push_back #define eb emplace_back using ll = long long; using P = pair<int, int>; using LP = pair<ll, int>; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) const ll MOD = 1000000007, MOD2 = 998244353; int main() { int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A.at(i); vector<bool> dp(K + 1, false); rep(i, K + 1) { if (dp[i]) continue; rep(j, N) { dp[i + A.at(j)] = true; } } if (dp[K]) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define pb push_back #define eb emplace_back using ll = long long; using P = pair<int, int>; using LP = pair<ll, int>; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) const ll MOD = 1000000007, MOD2 = 998244353; int main() { int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A.at(i); vector<bool> dp(K + 1, false); rep(i, K + 1) { if (dp[i]) continue; rep(j, N) { if (i + A.at(j) <= K) dp[i + A.at(j)] = true; } } if (dp[K]) cout << "First" << endl; else cout << "Second" << endl; }
replace
22
23
22
26
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define pb push_back #define eb emplace_back using ll = long long; using P = pair<int, int>; using LP = pair<ll, int>; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) const ll MOD = 1000000007, MOD2 = 998244353; int main() { int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A.at(i); vector<bool> dp(K + 1); rep(i, K + 1) dp[i] = false; rep(i, K + 1) { if (dp[i]) continue; rep(j, N) { dp[i + A.at(j)] = true; } } if (dp[K]) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define pb push_back #define eb emplace_back using ll = long long; using P = pair<int, int>; using LP = pair<ll, int>; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) const ll MOD = 1000000007, MOD2 = 998244353; int main() { int N, K; cin >> N >> K; vector<int> A(N); rep(i, N) cin >> A.at(i); vector<bool> dp(200005); rep(i, K + 1) dp[i] = false; rep(i, K + 1) { if (dp[i]) continue; rep(j, N) { dp[i + A.at(j)] = true; } } if (dp[K]) cout << "First" << endl; else cout << "Second" << endl; }
replace
18
19
18
19
0
p03170
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <functional> #include <iostream> #include <set> #include <utility> #include <vector> using namespace std; typedef unsigned long long ull; typedef pair<ull, ull> p; #define mp make_pair #define append push_back vector<ull> v; set<ull> s; multiset<ull> ms; ull prime[10000000]; #define f(i, a, b) for (int i = a; i < (b); i++) #define print cout << void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } vector<ull> visited(10000000, 0); vector<ull> adj[100000]; struct node { ull data; node *left; node *right; }; node *getNode(ull val) { node *newNode = new node(); newNode->data = val; newNode->left = newNode->right = NULL; return newNode; } node *findNode(node *root, ull data) { if (root->data == data) return root; if (root->left) findNode(root->left, data); if (root->right) findNode(root->right, data); } void display(node *root) { // displaying the tree queue<node *> Q; Q.push(root); while (!Q.empty()) { node *x = Q.front(); Q.pop(); if (x->left) Q.push(x->left); if (x->right) Q.push(x->right); cout << x->data << " "; } cout << endl; } node *copy(node *root) { if (!root) return root; node *temp = new node(); temp->data = root->data; temp->left = copy(root->left); temp->right = copy(root->right); return temp; } void mirror(node *root) { if (root) { mirror(root->left); mirror(root->right); node *temp = root->left; root->left = root->right; root->right = temp; } return; } int findMirror(int target, node *left, node *right) { if (left == NULL || right == NULL) return 0; if (left->data == target) return right->data; if (right->data == target) return left->data; int mirrorValue = findMirror(target, left->left, right->right); if (mirrorValue) return mirrorValue; return findMirror(target, left->right, right->left); } ull ncrmodp(ull num, ull r, ull mod) { ull C[r + 1]; ull i, j; memset(C, 0, sizeof(C)); C[0] = 1; for (i = 1; i <= num; i++) { for (j = min(i, r); j > 0; j--) { C[j] = ((C[j]) % mod + (C[j - 1]) % mod) % mod; } } return C[r]; } ull multiply(ull n, ull m) { ull prod = 1; f(i, 0, n) { prod *= v[i]; prod = prod % m; } return prod; } ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); } ull power(ull x, ull y, ull p) { ull res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } void dfs(int k) { visited[k] = 1; for (int i = 0; i < adj[k].size(); ++i) { if (visited[adj[k][i]] == 0) { dfs(adj[k][i]); } } } void sieve(ull ending) { for (int i = 2; i < ending; i++) prime[i] = 1; for (int i = 2; i * i <= ending; i++) { if (prime[i] == 1) { for (int j = 2 * i; j <= ending; j = j + i) { prime[j] = 0; } } } prime[1] = 0; } ull mex(set<ull> s) { ull me = 0; while (s.find(me) != s.end()) me++; return me; } ull k, n; ull dp[100005] = {0}; void grundy() { ull j = v[0], l, i; for (i = 0; i < j; i++) dp[i] = 0; for (i = j; i <= k; i++) { set<ull> s; for (l = 0; l < n; l++) { if (i - v[l] < 0) break; else s.insert(dp[i - v[l]]); } dp[i] = mex(s); } } int main() { boost(); ull i, j; ull t, m; cin >> n >> k; for (i = 0; i < n; i++) { ull a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); grundy(); if (!dp[k]) cout << "Second" << endl; else cout << "First" << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <functional> #include <iostream> #include <set> #include <utility> #include <vector> using namespace std; typedef long long ull; typedef pair<ull, ull> p; #define mp make_pair #define append push_back vector<ull> v; set<ull> s; multiset<ull> ms; ull prime[10000000]; #define f(i, a, b) for (int i = a; i < (b); i++) #define print cout << void boost() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } vector<ull> visited(10000000, 0); vector<ull> adj[100000]; struct node { ull data; node *left; node *right; }; node *getNode(ull val) { node *newNode = new node(); newNode->data = val; newNode->left = newNode->right = NULL; return newNode; } node *findNode(node *root, ull data) { if (root->data == data) return root; if (root->left) findNode(root->left, data); if (root->right) findNode(root->right, data); } void display(node *root) { // displaying the tree queue<node *> Q; Q.push(root); while (!Q.empty()) { node *x = Q.front(); Q.pop(); if (x->left) Q.push(x->left); if (x->right) Q.push(x->right); cout << x->data << " "; } cout << endl; } node *copy(node *root) { if (!root) return root; node *temp = new node(); temp->data = root->data; temp->left = copy(root->left); temp->right = copy(root->right); return temp; } void mirror(node *root) { if (root) { mirror(root->left); mirror(root->right); node *temp = root->left; root->left = root->right; root->right = temp; } return; } int findMirror(int target, node *left, node *right) { if (left == NULL || right == NULL) return 0; if (left->data == target) return right->data; if (right->data == target) return left->data; int mirrorValue = findMirror(target, left->left, right->right); if (mirrorValue) return mirrorValue; return findMirror(target, left->right, right->left); } ull ncrmodp(ull num, ull r, ull mod) { ull C[r + 1]; ull i, j; memset(C, 0, sizeof(C)); C[0] = 1; for (i = 1; i <= num; i++) { for (j = min(i, r); j > 0; j--) { C[j] = ((C[j]) % mod + (C[j - 1]) % mod) % mod; } } return C[r]; } ull multiply(ull n, ull m) { ull prod = 1; f(i, 0, n) { prod *= v[i]; prod = prod % m; } return prod; } ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); } ull power(ull x, ull y, ull p) { ull res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } void dfs(int k) { visited[k] = 1; for (int i = 0; i < adj[k].size(); ++i) { if (visited[adj[k][i]] == 0) { dfs(adj[k][i]); } } } void sieve(ull ending) { for (int i = 2; i < ending; i++) prime[i] = 1; for (int i = 2; i * i <= ending; i++) { if (prime[i] == 1) { for (int j = 2 * i; j <= ending; j = j + i) { prime[j] = 0; } } } prime[1] = 0; } ull mex(set<ull> s) { ull me = 0; while (s.find(me) != s.end()) me++; return me; } ull k, n; ull dp[100005] = {0}; void grundy() { ull j = v[0], l, i; for (i = 0; i < j; i++) dp[i] = 0; for (i = j; i <= k; i++) { set<ull> s; for (l = 0; l < n; l++) { if (i - v[l] < 0) break; else s.insert(dp[i - v[l]]); } dp[i] = mex(s); } } int main() { boost(); ull i, j; ull t, m; cin >> n >> k; for (i = 0; i < n; i++) { ull a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); grundy(); if (!dp[k]) cout << "Second" << endl; else cout << "First" << endl; return 0; }
replace
9
10
9
10
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03170
C++
Runtime Error
// DO NOT USE: A N (segtree) #include <bits/stdc++.h> using namespace std; // MACROS #define ll long long #define pii pair<int, int> #define f(a, b, c) for (int a = b; a < c; a++) #define read(t) \ ll t; \ cin >> t; #define readarr(arr, n) \ ll arr[n]; \ f(i, 0, n) cin >> arr[i]; #define deb(x) cout << x << " KAMEHAMEHA" << endl; // OBJECTS struct obj { ll x, y; }; // USEFUL //FUNCTIONS ll powm(ll, ll); // SEGMENT // TREE(!N) const int N = 3e0 + 5; ll tree[4 * N + 1]; ll A[N]; ll lazy[4 * N + 1] = {0}; void build(ll, ll, ll); void update(ll, ll, ll, ll, ll); ll query(ll, ll, ll, ll, ll); void updateRange(ll, ll, ll, ll, ll, ll); ll queryRange(ll, ll, ll, ll, ll); // GLOBAL //VARS ll INF = LLONG_MAX; const ll M = 1000000007; ll dp[100005] = {0}; bool solve(ll a[], ll k, ll n, bool p) { if (k == 0) return 0; if (k < 0) return 1; // deb(k) bool win = 0; f(i, 0, n) { if (dp[k - a[i]] == 2) if (!solve(a, k - a[i], n, !p)) win = 1; else { if (!dp[k - a[i]]) win = 1; } } dp[k] = win; return win; } // MAIN int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(n) read(k) readarr(a, n) f(i, 0, 100004) dp[i] = 2; bool z = solve(a, k, n, 0); if (z) cout << "First"; else cout << "Second"; } // FUNCTIONS //DECLARATIONS ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } void build(ll node, ll start, ll end) { if (start == end) { // Leaf node will have a single element tree[node] = A[start]; } else { ll mid = (start + end) / 2; // Recurse on the left child build(2 * node, start, mid); // Recurse on the right child build(2 * node + 1, mid + 1, end); // llernal node will have the sum of both of its children tree[node] = tree[2 * node] + tree[2 * node + 1]; } } void update(ll node, ll start, ll end, ll idx, ll val) { if (start == end) { // Leaf node A[idx] += val; tree[node] += val; } else { ll mid = (start + end) / 2; if (start <= idx and idx <= mid) { // If idx is in the left child, recurse on the left child update(2 * node, start, mid, idx, val); } else { // if idx is in the right child, recurse on the right child update(2 * node + 1, mid + 1, end, idx, val); } // llernal node will have the sum of both of its children tree[node] = tree[2 * node] + tree[2 * node + 1]; } } ll query(ll node, ll start, ll end, ll l, ll r) { if (r < start or end < l) { // range represented by a node is completely outside the given range return 0; } if (l <= start and end <= r) { // range represented by a node is completely inside the given range return tree[node]; } // range represented by a node is partially inside and partially outside the // given range ll mid = (start + end) / 2; ll p1 = query(2 * node, start, mid, l, r); ll p2 = query(2 * node + 1, mid + 1, end, l, r); return (p1 + p2); } void updateRange(ll node, ll start, ll end, ll l, ll r, ll val) { if (lazy[node] != 0) { // This node needs to be updated tree[node] += (end - start + 1) * lazy[node]; // Update it if (start != end) { lazy[node * 2] += lazy[node]; // Mark child as lazy lazy[node * 2 + 1] += lazy[node]; // Mark child as lazy } lazy[node] = 0; // Reset it } if (start > end or start > r or end < l) // Current segment is not within range [l, r] return; if (start >= l and end <= r) { // Segment is fully within range tree[node] += (end - start + 1) * val; if (start != end) { // Not leaf node lazy[node * 2] += val; lazy[node * 2 + 1] += val; } return; } ll mid = (start + end) / 2; updateRange(node * 2, start, mid, l, r, val); // Updating left child updateRange(node * 2 + 1, mid + 1, end, l, r, val); // Updating right child tree[node] = tree[node * 2] + tree[node * 2 + 1]; // Updating root with max value } ll queryRange(ll node, ll start, ll end, ll l, ll r) { if (start > end or start > r or end < l) return 0; // Out of range if (lazy[node] != 0) { // This node needs to be updated tree[node] += (end - start + 1) * lazy[node]; // Update it if (start != end) { lazy[node * 2] += lazy[node]; // Mark child as lazy lazy[node * 2 + 1] += lazy[node]; // Mark child as lazy } lazy[node] = 0; // Reset it } if (start >= l and end <= r) // Current segment is totally within range [l, r] return tree[node]; ll mid = (start + end) / 2; ll p1 = queryRange(node * 2, start, mid, l, r); // Query left child ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r); // Query right child return (p1 + p2); }
// DO NOT USE: A N (segtree) #include <bits/stdc++.h> using namespace std; // MACROS #define ll long long #define pii pair<int, int> #define f(a, b, c) for (int a = b; a < c; a++) #define read(t) \ ll t; \ cin >> t; #define readarr(arr, n) \ ll arr[n]; \ f(i, 0, n) cin >> arr[i]; #define deb(x) cout << x << " KAMEHAMEHA" << endl; // OBJECTS struct obj { ll x, y; }; // USEFUL //FUNCTIONS ll powm(ll, ll); // SEGMENT // TREE(!N) const int N = 3e0 + 5; ll tree[4 * N + 1]; ll A[N]; ll lazy[4 * N + 1] = {0}; void build(ll, ll, ll); void update(ll, ll, ll, ll, ll); ll query(ll, ll, ll, ll, ll); void updateRange(ll, ll, ll, ll, ll, ll); ll queryRange(ll, ll, ll, ll, ll); // GLOBAL //VARS ll INF = LLONG_MAX; const ll M = 1000000007; ll dp[100005] = {0}; bool solve(ll a[], ll k, ll n, bool p) { if (k == 0) return 0; if (k < 0) return 1; // deb(k) bool win = 0; f(i, 0, n) { if (dp[k - a[i]] == 2) if (!solve(a, k - a[i], n, !p)) win = 1; else { if (!dp[k - a[i]]) win = 1; } } dp[k] = win; return win; } // MAIN int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(n) read(k) readarr(a, n) sort(a, a + n); f(i, 0, k + 1) { if (dp[i]) continue; f(j, 0, n) { if (i + a[j] <= k) dp[i + a[j]] = 1; } } if (dp[k]) cout << "First"; else cout << "Second"; } // FUNCTIONS //DECLARATIONS ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } void build(ll node, ll start, ll end) { if (start == end) { // Leaf node will have a single element tree[node] = A[start]; } else { ll mid = (start + end) / 2; // Recurse on the left child build(2 * node, start, mid); // Recurse on the right child build(2 * node + 1, mid + 1, end); // llernal node will have the sum of both of its children tree[node] = tree[2 * node] + tree[2 * node + 1]; } } void update(ll node, ll start, ll end, ll idx, ll val) { if (start == end) { // Leaf node A[idx] += val; tree[node] += val; } else { ll mid = (start + end) / 2; if (start <= idx and idx <= mid) { // If idx is in the left child, recurse on the left child update(2 * node, start, mid, idx, val); } else { // if idx is in the right child, recurse on the right child update(2 * node + 1, mid + 1, end, idx, val); } // llernal node will have the sum of both of its children tree[node] = tree[2 * node] + tree[2 * node + 1]; } } ll query(ll node, ll start, ll end, ll l, ll r) { if (r < start or end < l) { // range represented by a node is completely outside the given range return 0; } if (l <= start and end <= r) { // range represented by a node is completely inside the given range return tree[node]; } // range represented by a node is partially inside and partially outside the // given range ll mid = (start + end) / 2; ll p1 = query(2 * node, start, mid, l, r); ll p2 = query(2 * node + 1, mid + 1, end, l, r); return (p1 + p2); } void updateRange(ll node, ll start, ll end, ll l, ll r, ll val) { if (lazy[node] != 0) { // This node needs to be updated tree[node] += (end - start + 1) * lazy[node]; // Update it if (start != end) { lazy[node * 2] += lazy[node]; // Mark child as lazy lazy[node * 2 + 1] += lazy[node]; // Mark child as lazy } lazy[node] = 0; // Reset it } if (start > end or start > r or end < l) // Current segment is not within range [l, r] return; if (start >= l and end <= r) { // Segment is fully within range tree[node] += (end - start + 1) * val; if (start != end) { // Not leaf node lazy[node * 2] += val; lazy[node * 2 + 1] += val; } return; } ll mid = (start + end) / 2; updateRange(node * 2, start, mid, l, r, val); // Updating left child updateRange(node * 2 + 1, mid + 1, end, l, r, val); // Updating right child tree[node] = tree[node * 2] + tree[node * 2 + 1]; // Updating root with max value } ll queryRange(ll node, ll start, ll end, ll l, ll r) { if (start > end or start > r or end < l) return 0; // Out of range if (lazy[node] != 0) { // This node needs to be updated tree[node] += (end - start + 1) * lazy[node]; // Update it if (start != end) { lazy[node * 2] += lazy[node]; // Mark child as lazy lazy[node * 2 + 1] += lazy[node]; // Mark child as lazy } lazy[node] = 0; // Reset it } if (start >= l and end <= r) // Current segment is totally within range [l, r] return tree[node]; ll mid = (start + end) / 2; ll p1 = queryRange(node * 2, start, mid, l, r); // Query left child ll p2 = queryRange(node * 2 + 1, mid + 1, end, l, r); // Query right child return (p1 + p2); }
replace
71
74
71
82
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // Define using ll = long long; using ull = unsigned long long; using ld = long double; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; const ll MOD = 1e9 + 7; const ll mod = 998244353; const ll inf = 1 << 30; const ll LINF = LONG_MAX; const ll INF = 1LL << 60; const ull MAX = ULONG_MAX; #define mp make_pair #define pb push_back #define elif else if #define endl '\n' #define space ' ' #define def inline auto #define func inline constexpr ll #define run(a) __attribute__((constructor)) def _##a() #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define input(a) scanf("%lld", &(a)) #define print(a) printf("%lld\n", (a)) #define fi first #define se second #define ok(a, b) (0 <= (a) && (a) < (b)) template <class T> using vvector = vector<vector<T>>; template <class T> using pvector = vector<pair<T, T>>; template <class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } // Debug #define debug(...) \ { \ cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \ for (auto &&X : {__VA_ARGS__}) \ cerr << "[" << X << "] "; \ cerr << endl; \ } #define dump(a, h, w) \ { \ cerr << __LINE__ << ": " << #a << " = [" << endl; \ rep(__i, h) { \ rep(__j, w) { cerr << a[__i][__j] << space; } \ cerr << endl; \ } \ cerr << "]" << endl; \ } #define vdump(a, n) \ { \ cerr << __LINE__ << ": " << #a << " = ["; \ rep(__i, n) if (__i) cerr << space << a[__i]; \ else cerr << a[__i]; \ cerr << "]" << endl; \ } // Loop #define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i) #define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i) #define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i) #define each(i, a) for (auto &&i : a) #define loop() for (;;) // Stream #define fout(n) cout << fixed << setprecision(n) #define fasten cin.tie(0), ios::sync_with_stdio(0) run(0) { fasten, fout(10); } // Speed #pragma GCC optimize("O3") #pragma GCC target("avx") // Math func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } func lcm(ll a, ll b) { return a / gcd(a, b) * b; } func sign(ll a) { return a ? abs(a) / a : 0; } inline constexpr ll modulo(const ll n, const ll m = MOD) { ll k = n % m; return k + m * (k < 0); } inline constexpr ll chmod(ll &n, const ll m = MOD) { n %= m; return n += m * (n < 0); } inline constexpr ll mpow(ll a, ll n, const ll m = MOD) { ll r = 1; while (n) { if (n & 1) r *= a; chmod(r, m); a *= a; chmod(a, m); n >>= 1; } return r; } inline ll inv(const ll n, const ll m = MOD) { ll a = n, b = m, x = 1, y = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return modulo(x, m); } struct Factor { inline vector<ll> factors(ll N) { vector<ll> A; ll i = 2; while (i * i <= N) { if (N % i == 0) { A.push_back(i); N /= i; } else { i++; } } if (N != 1) A.push_back(N); sort(all(A)); return A; } inline vector<ll> divisor(ll N) { vector<ll> A; inc(i, 1, sqrt(N)) { if (N % i == 0) { A.push_back(i); if (i * i != N) A.push_back(N / i); } } sort(all(A)); return A; } }; struct csum { ll N; vector<ll> A, S; csum(vector<ll> v) : A(v), S(1) { each(k, v) S.push_back(k + S.back()); } ll sum(ll l, ll r) { return S[r] - S[l]; } ll lsum(ll r) { return S[r]; } ll rsum(ll l) { return S.back() - S[l]; } }; template <ull mod = MOD> struct mi { inline constexpr ll modulo(const ll n, const ll m) const noexcept { ll k = n % m; return k + m * (k < 0); } ll num; inline constexpr mi() noexcept : num() { num = 0; } inline constexpr mi(const int n) noexcept : num() { num = modulo(n, mod); } inline constexpr mi(const ll n) noexcept : num() { num = modulo(n, mod); } inline constexpr mi<mod> inv() const noexcept { ll a = num, b = mod, x = 1, y = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return mi<mod>(x); } inline constexpr mi<mod> inv(ll n) const noexcept { ll a = n, b = mod, x = 1, y = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return mi<mod>(x); } inline constexpr mi<mod> inv(const mi<mod> m) const noexcept { return inv(m.num); } inline constexpr mi<mod> operator+() const noexcept { return mi(num); } inline constexpr mi<mod> operator+(const int n) const noexcept { return mi<mod>(num + n); } inline constexpr mi<mod> operator+(const ll n) const noexcept { return mi<mod>(num + n); } inline constexpr mi<mod> operator+(const mi<mod> m) const noexcept { return mi<mod>(num + m.num); } inline constexpr mi<mod> operator-() const noexcept { return -num; } inline constexpr mi<mod> operator-(const int n) const noexcept { return mi<mod>(num - n); } inline constexpr mi<mod> operator-(const ll n) const noexcept { return mi<mod>(num - n); } inline constexpr mi<mod> operator-(const mi<mod> m) const noexcept { return mi<mod>(num - m.num); } inline constexpr mi<mod> operator*(const int n) const noexcept { return mi<mod>(num * n); } inline constexpr mi<mod> operator*(const ll n) const noexcept { return mi<mod>(num * n); } inline constexpr mi<mod> operator*(const mi<mod> m) const noexcept { return mi<mod>(num * m); } inline constexpr mi<mod> operator/(const int n) const noexcept { return mi<mod>(num * (ll)inv(n)); } inline constexpr mi<mod> operator/(const ll n) const noexcept { return mi<mod>(num * (ll)inv(n)); } inline constexpr mi<mod> operator/(const mi<mod> m) const noexcept { return mi<mod>(num * (ll)inv(m)); } inline constexpr mi<mod> &operator=(const int n) noexcept { num = modulo(n, mod); return *this; } inline constexpr mi<mod> &operator=(const ll n) noexcept { num = modulo(n, mod); return *this; } inline constexpr mi<mod> &operator=(const mi<mod> m) noexcept { num = m.num; return *this; } inline constexpr mi<mod> &operator+=(const int n) noexcept { num = modulo(num + n, mod); return *this; } inline constexpr mi<mod> &operator+=(const ll n) noexcept { num = modulo(num + n, mod); return *this; } inline constexpr mi<mod> &operator+=(const mi<mod> m) noexcept { num = modulo(num + m.num, mod); return *this; } inline constexpr mi<mod> &operator++() noexcept { num = modulo(num + 1, mod); return *this; } inline constexpr mi<mod> operator++(int) noexcept { mi &pre = *this; num = modulo(num + 1, mod); return pre; } inline constexpr mi<mod> &operator-=(const int n) noexcept { num = modulo(num - n, mod); return *this; } inline constexpr mi<mod> &operator-=(const ll n) noexcept { num = modulo(num - n, mod); return *this; } inline constexpr mi<mod> &operator-=(const mi<mod> m) noexcept { num = modulo(num - m.num, mod); return *this; } inline constexpr mi<mod> &operator--() noexcept { num = modulo(num - 1, mod); return *this; } inline constexpr mi<mod> operator--(int) noexcept { mi &pre = *this; num = modulo(num - 1, mod); return pre; } inline constexpr mi<mod> &operator*=(const int n) noexcept { num = modulo(num * n, mod); return *this; } inline constexpr mi<mod> &operator*=(const ll n) noexcept { num = modulo(num * n, mod); return *this; } inline constexpr mi<mod> &operator*=(const mi<mod> m) noexcept { num = modulo(num * m.num, mod); return *this; } inline constexpr mi<mod> &operator/=(const int n) noexcept { num = modulo(num * (ll)inv(n), mod); return *this; } inline constexpr mi<mod> &operator/=(const ll n) noexcept { num = modulo(num * (ll)inv(n), mod); return *this; } inline constexpr mi<mod> &operator/=(const mi<mod> m) noexcept { num = modulo(num * (ll)inv(m), mod); return *this; } inline constexpr mi<mod> operator==(const int n) const noexcept { return num == modulo(n, mod); } inline constexpr mi<mod> operator==(const ll n) const noexcept { return num == modulo(n, mod); } inline constexpr mi<mod> operator==(const mi<mod> m) const noexcept { return num == m.num; } inline constexpr mi<mod> operator!=(const int n) const noexcept { return num != modulo(n, mod); } inline constexpr mi<mod> operator!=(const ll n) const noexcept { return num != modulo(n, mod); } inline constexpr mi<mod> operator!=(const mi<mod> m) const noexcept { return num != m.num; } constexpr operator int() const noexcept { return num; } constexpr operator ll() const noexcept { return num; } friend std::istream &operator>>(std::istream &, const mi<> &); friend std::ostream &operator<<(std::ostream &, const mi<> &); }; template <ull mod = MOD> inline constexpr mi<mod> operator+(const int n, const mi<mod> m) noexcept { return mi<mod>(n + m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator+(const ll n, const mi<mod> m) noexcept { return mi<mod>(n + m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator-(const int n, const mi<mod> m) noexcept { return mi<mod>(n - m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator-(const ll n, const mi<mod> m) noexcept { return mi<mod>(n - m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator*(const int n, const mi<mod> m) noexcept { return mi<mod>(n * m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator*(const ll n, const mi<mod> m) noexcept { return mi<mod>(n * m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator/(const int n, const mi<mod> m) noexcept { return mi<mod>(n * (ll)m.inv()); } template <ull mod = MOD> inline constexpr mi<mod> operator/(const ll n, const mi<mod> m) noexcept { return mi<mod>(n * (ll)m.inv()); } inline constexpr mi<MOD> operator""_m(ull n) { return mi<MOD>((ll)n); } template <ull mod = MOD> inline constexpr mi<mod> pow(mi<mod> m, ll n) noexcept { mi<mod> r = mi<mod>(1); while (n) { if (n & 1) r *= m; m *= m; n >>= 1; } return r; } template <ull mod> istream &operator>>(istream &is, mi<mod> &m) { is >> m.num; return is; } template <ull mod> ostream &operator<<(ostream &is, mi<mod> &m) { is << (ll)m; return is; } template <ull mod = MOD> struct modmath { ll max; vector<mi<mod>> fac, inv; modmath() : max(1 << 20), fac(max + 1), inv(max + 1) { fac[0] = mi<mod>(1); rep(i, max) fac[i + 1] = fac[i] * (i + 1); inv[max] = fac[max].inv(); dec(i, max - 1, 0) inv[i] = inv[i + 1] * (i + 1); } modmath(ll n) : max(n), fac(n + 1), inv(n + 1) { fac[0] = 1; rep(i, n) fac[i + 1] = fac[i] * (i + 1); inv[n] = 1 / fac[n]; dec(i, n - 1, 0) inv[i] = inv[i + 1] * (i + 1); } inline mi<mod> fact(ll n) { if (n < 0) return mi<mod>(0); return fac[n]; } inline mi<mod> perm(ll n, ll r) { if (r < 0 || n < r) return mi<mod>(0); return fac[n] * inv[n - r]; } inline mi<mod> comb(ll n, ll r) { if (r < 0 || n < r) return mi<mod>(0); return fac[n] * inv[r] * inv[n - r]; } inline mi<mod> nHr(ll n, ll r) { return comb(n + r - 1, n - 1); } }; struct UFR { vector<ll> data; UFR(ll N) : data(N) { rep(i, N) data[i] = -1; } def root(ll x) { if (data[x] < 0) return x; else return data[x] = root(data[x]); } def unite(ll x, ll y) { ll root_x = root(x), root_y = root(y); if (root_x != root_y) { if (data[root_x] > data[root_y]) swap(root_x, root_y); data[root_x] -= data[root_x] == data[root_y]; data[root_y] = root_x; return true; } return false; } def same(ll x, ll y) { return root(x) == root(y); } }; struct position { ll x, y; position() {} position(ll a, ll b) : x(a), y(b) {} position next(ll i) { return {x + dx[i], y + dy[i]}; } ll mdist() { return abs(x) + abs(y); } double dist() { return sqrt(x * x + y * y); } double norm(ll d) { if (d == inf) return max(x, y); if (d == 1) return mdist(); if (d == 2) return dist(); return 0; } ll num(ll width) { return abs(x) * width + abs(y); } bool operator==(position a) { return x == a.x && y == a.y; } bool operator!=(position a) { return x != a.x || y != a.y; } bool operator<(position a) { return x < a.x && y < a.y; } bool operator>(position a) { return x > a.x && y > a.y; } bool operator<=(position a) { return x <= a.x && y <= a.y; } bool operator>=(position a) { return x >= a.x && y >= a.y; } position operator+(position a) { return position(x + a.x, y + a.y); } position operator-(position a) { return position(x - a.x, y - a.y); } position operator*(position a) { return position(x * a.x, y * a.y); } position operator/(position a) { return position(x / a.x, y / a.y); } position operator%(position a) { return position(x % a.x, y % a.y); } position complex(position a) { return position(x * a.x - y * a.y, x * a.y + y * a.x); } /* // for sort: bool operator<(position a) { return x ^ a.x ? x < a.x : y < a.y; } bool operator>(position a) { return x ^ a.x ? x > a.x : y > a.y; } bool operator<=(position a) { return x ^ a.x ? x < a.x : y <= a.y; } bool operator>=(position a) { return x ^ a.x ? x > a.x : y >= a.y; } */ }; position Origin = position(0, 0); using pos = position; using vec = position; template <class T> struct Array { struct node { ll childl, childr; T data; node(ll l, ll r, T t) : childl(l), childr(r), data(t) {} }; ll n, depth; vector<ll> versions; vector<ll> prev_versions; vector<node> nodes; Array(ll n = 1 << 20, T val = T()) : n(n), depth(0) { while (n /= 2) depth++; init(val); } void init(T val) { versions.push_back(0); prev_versions.push_back(0); rep(i, 2 * n - 1) { if (i < n - 1) { nodes.push_back(node(2 * i + 1, 2 * i + 2, T())); } else { nodes.push_back(node(0, 0, val)); } } } void set(ll index, ll val, ll version = -1) { ll id, par = nodes.size(), left = 0, right = n; if (version == -1) { id = versions.back(); version = versions.size() - 1; } else { id = versions[version]; } versions.push_back(par); prev_versions.push_back(version); if (right == -1) right = n; rep(i, depth) { ll mid = (left + right) / 2; if (index < mid) { nodes.push_back(node(par + i + 1, nodes[id].childr, T())); id = nodes[id].childl; right = mid; } else { nodes.push_back(node(nodes[id].childl, par + i + 1, T())); id = nodes[id].childr; left = mid; } } nodes.push_back(node(0, 0, val)); } T get(ll index, ll version = -1) { ll id, left = 0, right = n; if (version == -1) { id = versions.back(); } else { id = versions[version]; } rep(i, depth) { ll mid = (left + right) / 2; if (index < mid) { id = nodes[id].childl; right = mid; } else { id = nodes[id].childr; left = mid; } } return nodes[id].data; } ll latest() { return versions.size() - 1; } }; struct BipartiteGraph { ll V; vector<vector<ll>> G; vector<ll> match; vector<bool> used; BipartiteGraph(ll N) : V(N), G(N), match(N), used(N) {} void addEdge(ll i, ll j) { G[i].push_back(j); G[j].push_back(i); } bool dfs(ll now) { used[now] = true; rep(i, G[now].size()) { ll next = G[now][i], w = match[next]; if (w == -1 || (!used[w] && dfs(w))) { match[now] = next, match[next] = now; return true; } } return false; } ll matching() { ll res = 0; fill(all(match), -1); rep(i, V) { if (match[i] == -1) { fill(all(used), false); if (dfs(i)) res++; } } return res; } }; template <typename T = ll> struct Dijkstra { ll V; using P = pair<ll, ll>; vector<vector<P>> G; vector<T> dist; vector<bool> used; Dijkstra(ll v) : V(v), G(v), dist(v), used(v) {} void setDist(ll a, ll b, ll d) { G[a].push_back(P(d, b)); } void culc(ll s = 0) { priority_queue<P, vector<P>, greater<P>> Q; Q.push(P(0, s)); fill_n(dist.begin(), V, INF); fill_n(used.begin(), V, false); while (!Q.empty()) { T d; ll t; tie(d, t) = Q.top(), Q.pop(); if (used[t]) continue; used[t] = true, dist[t] = d; for (P e : G[t]) { if (dist[e.second] <= d + e.first) continue; Q.push(P(d + e.first, e.second)); } } } }; ll N, K, A[100]; ll DP[100001]; signed main() { cin >> N >> K; rep(i, N) cin >> A[i]; rep(i, K + 1) { DP[i] = !DP[i]; rep(j, N) DP[i + A[j]] |= DP[i]; } cout << (DP[K] ? "Second" : "First") << endl; }
#include <bits/stdc++.h> using namespace std; // Define using ll = long long; using ull = unsigned long long; using ld = long double; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; const ll MOD = 1e9 + 7; const ll mod = 998244353; const ll inf = 1 << 30; const ll LINF = LONG_MAX; const ll INF = 1LL << 60; const ull MAX = ULONG_MAX; #define mp make_pair #define pb push_back #define elif else if #define endl '\n' #define space ' ' #define def inline auto #define func inline constexpr ll #define run(a) __attribute__((constructor)) def _##a() #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define input(a) scanf("%lld", &(a)) #define print(a) printf("%lld\n", (a)) #define fi first #define se second #define ok(a, b) (0 <= (a) && (a) < (b)) template <class T> using vvector = vector<vector<T>>; template <class T> using pvector = vector<pair<T, T>>; template <class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } // Debug #define debug(...) \ { \ cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \ for (auto &&X : {__VA_ARGS__}) \ cerr << "[" << X << "] "; \ cerr << endl; \ } #define dump(a, h, w) \ { \ cerr << __LINE__ << ": " << #a << " = [" << endl; \ rep(__i, h) { \ rep(__j, w) { cerr << a[__i][__j] << space; } \ cerr << endl; \ } \ cerr << "]" << endl; \ } #define vdump(a, n) \ { \ cerr << __LINE__ << ": " << #a << " = ["; \ rep(__i, n) if (__i) cerr << space << a[__i]; \ else cerr << a[__i]; \ cerr << "]" << endl; \ } // Loop #define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i) #define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i) #define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i) #define each(i, a) for (auto &&i : a) #define loop() for (;;) // Stream #define fout(n) cout << fixed << setprecision(n) #define fasten cin.tie(0), ios::sync_with_stdio(0) run(0) { fasten, fout(10); } // Speed #pragma GCC optimize("O3") #pragma GCC target("avx") // Math func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } func lcm(ll a, ll b) { return a / gcd(a, b) * b; } func sign(ll a) { return a ? abs(a) / a : 0; } inline constexpr ll modulo(const ll n, const ll m = MOD) { ll k = n % m; return k + m * (k < 0); } inline constexpr ll chmod(ll &n, const ll m = MOD) { n %= m; return n += m * (n < 0); } inline constexpr ll mpow(ll a, ll n, const ll m = MOD) { ll r = 1; while (n) { if (n & 1) r *= a; chmod(r, m); a *= a; chmod(a, m); n >>= 1; } return r; } inline ll inv(const ll n, const ll m = MOD) { ll a = n, b = m, x = 1, y = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return modulo(x, m); } struct Factor { inline vector<ll> factors(ll N) { vector<ll> A; ll i = 2; while (i * i <= N) { if (N % i == 0) { A.push_back(i); N /= i; } else { i++; } } if (N != 1) A.push_back(N); sort(all(A)); return A; } inline vector<ll> divisor(ll N) { vector<ll> A; inc(i, 1, sqrt(N)) { if (N % i == 0) { A.push_back(i); if (i * i != N) A.push_back(N / i); } } sort(all(A)); return A; } }; struct csum { ll N; vector<ll> A, S; csum(vector<ll> v) : A(v), S(1) { each(k, v) S.push_back(k + S.back()); } ll sum(ll l, ll r) { return S[r] - S[l]; } ll lsum(ll r) { return S[r]; } ll rsum(ll l) { return S.back() - S[l]; } }; template <ull mod = MOD> struct mi { inline constexpr ll modulo(const ll n, const ll m) const noexcept { ll k = n % m; return k + m * (k < 0); } ll num; inline constexpr mi() noexcept : num() { num = 0; } inline constexpr mi(const int n) noexcept : num() { num = modulo(n, mod); } inline constexpr mi(const ll n) noexcept : num() { num = modulo(n, mod); } inline constexpr mi<mod> inv() const noexcept { ll a = num, b = mod, x = 1, y = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return mi<mod>(x); } inline constexpr mi<mod> inv(ll n) const noexcept { ll a = n, b = mod, x = 1, y = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); x -= t * y; swap(x, y); } return mi<mod>(x); } inline constexpr mi<mod> inv(const mi<mod> m) const noexcept { return inv(m.num); } inline constexpr mi<mod> operator+() const noexcept { return mi(num); } inline constexpr mi<mod> operator+(const int n) const noexcept { return mi<mod>(num + n); } inline constexpr mi<mod> operator+(const ll n) const noexcept { return mi<mod>(num + n); } inline constexpr mi<mod> operator+(const mi<mod> m) const noexcept { return mi<mod>(num + m.num); } inline constexpr mi<mod> operator-() const noexcept { return -num; } inline constexpr mi<mod> operator-(const int n) const noexcept { return mi<mod>(num - n); } inline constexpr mi<mod> operator-(const ll n) const noexcept { return mi<mod>(num - n); } inline constexpr mi<mod> operator-(const mi<mod> m) const noexcept { return mi<mod>(num - m.num); } inline constexpr mi<mod> operator*(const int n) const noexcept { return mi<mod>(num * n); } inline constexpr mi<mod> operator*(const ll n) const noexcept { return mi<mod>(num * n); } inline constexpr mi<mod> operator*(const mi<mod> m) const noexcept { return mi<mod>(num * m); } inline constexpr mi<mod> operator/(const int n) const noexcept { return mi<mod>(num * (ll)inv(n)); } inline constexpr mi<mod> operator/(const ll n) const noexcept { return mi<mod>(num * (ll)inv(n)); } inline constexpr mi<mod> operator/(const mi<mod> m) const noexcept { return mi<mod>(num * (ll)inv(m)); } inline constexpr mi<mod> &operator=(const int n) noexcept { num = modulo(n, mod); return *this; } inline constexpr mi<mod> &operator=(const ll n) noexcept { num = modulo(n, mod); return *this; } inline constexpr mi<mod> &operator=(const mi<mod> m) noexcept { num = m.num; return *this; } inline constexpr mi<mod> &operator+=(const int n) noexcept { num = modulo(num + n, mod); return *this; } inline constexpr mi<mod> &operator+=(const ll n) noexcept { num = modulo(num + n, mod); return *this; } inline constexpr mi<mod> &operator+=(const mi<mod> m) noexcept { num = modulo(num + m.num, mod); return *this; } inline constexpr mi<mod> &operator++() noexcept { num = modulo(num + 1, mod); return *this; } inline constexpr mi<mod> operator++(int) noexcept { mi &pre = *this; num = modulo(num + 1, mod); return pre; } inline constexpr mi<mod> &operator-=(const int n) noexcept { num = modulo(num - n, mod); return *this; } inline constexpr mi<mod> &operator-=(const ll n) noexcept { num = modulo(num - n, mod); return *this; } inline constexpr mi<mod> &operator-=(const mi<mod> m) noexcept { num = modulo(num - m.num, mod); return *this; } inline constexpr mi<mod> &operator--() noexcept { num = modulo(num - 1, mod); return *this; } inline constexpr mi<mod> operator--(int) noexcept { mi &pre = *this; num = modulo(num - 1, mod); return pre; } inline constexpr mi<mod> &operator*=(const int n) noexcept { num = modulo(num * n, mod); return *this; } inline constexpr mi<mod> &operator*=(const ll n) noexcept { num = modulo(num * n, mod); return *this; } inline constexpr mi<mod> &operator*=(const mi<mod> m) noexcept { num = modulo(num * m.num, mod); return *this; } inline constexpr mi<mod> &operator/=(const int n) noexcept { num = modulo(num * (ll)inv(n), mod); return *this; } inline constexpr mi<mod> &operator/=(const ll n) noexcept { num = modulo(num * (ll)inv(n), mod); return *this; } inline constexpr mi<mod> &operator/=(const mi<mod> m) noexcept { num = modulo(num * (ll)inv(m), mod); return *this; } inline constexpr mi<mod> operator==(const int n) const noexcept { return num == modulo(n, mod); } inline constexpr mi<mod> operator==(const ll n) const noexcept { return num == modulo(n, mod); } inline constexpr mi<mod> operator==(const mi<mod> m) const noexcept { return num == m.num; } inline constexpr mi<mod> operator!=(const int n) const noexcept { return num != modulo(n, mod); } inline constexpr mi<mod> operator!=(const ll n) const noexcept { return num != modulo(n, mod); } inline constexpr mi<mod> operator!=(const mi<mod> m) const noexcept { return num != m.num; } constexpr operator int() const noexcept { return num; } constexpr operator ll() const noexcept { return num; } friend std::istream &operator>>(std::istream &, const mi<> &); friend std::ostream &operator<<(std::ostream &, const mi<> &); }; template <ull mod = MOD> inline constexpr mi<mod> operator+(const int n, const mi<mod> m) noexcept { return mi<mod>(n + m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator+(const ll n, const mi<mod> m) noexcept { return mi<mod>(n + m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator-(const int n, const mi<mod> m) noexcept { return mi<mod>(n - m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator-(const ll n, const mi<mod> m) noexcept { return mi<mod>(n - m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator*(const int n, const mi<mod> m) noexcept { return mi<mod>(n * m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator*(const ll n, const mi<mod> m) noexcept { return mi<mod>(n * m.num); } template <ull mod = MOD> inline constexpr mi<mod> operator/(const int n, const mi<mod> m) noexcept { return mi<mod>(n * (ll)m.inv()); } template <ull mod = MOD> inline constexpr mi<mod> operator/(const ll n, const mi<mod> m) noexcept { return mi<mod>(n * (ll)m.inv()); } inline constexpr mi<MOD> operator""_m(ull n) { return mi<MOD>((ll)n); } template <ull mod = MOD> inline constexpr mi<mod> pow(mi<mod> m, ll n) noexcept { mi<mod> r = mi<mod>(1); while (n) { if (n & 1) r *= m; m *= m; n >>= 1; } return r; } template <ull mod> istream &operator>>(istream &is, mi<mod> &m) { is >> m.num; return is; } template <ull mod> ostream &operator<<(ostream &is, mi<mod> &m) { is << (ll)m; return is; } template <ull mod = MOD> struct modmath { ll max; vector<mi<mod>> fac, inv; modmath() : max(1 << 20), fac(max + 1), inv(max + 1) { fac[0] = mi<mod>(1); rep(i, max) fac[i + 1] = fac[i] * (i + 1); inv[max] = fac[max].inv(); dec(i, max - 1, 0) inv[i] = inv[i + 1] * (i + 1); } modmath(ll n) : max(n), fac(n + 1), inv(n + 1) { fac[0] = 1; rep(i, n) fac[i + 1] = fac[i] * (i + 1); inv[n] = 1 / fac[n]; dec(i, n - 1, 0) inv[i] = inv[i + 1] * (i + 1); } inline mi<mod> fact(ll n) { if (n < 0) return mi<mod>(0); return fac[n]; } inline mi<mod> perm(ll n, ll r) { if (r < 0 || n < r) return mi<mod>(0); return fac[n] * inv[n - r]; } inline mi<mod> comb(ll n, ll r) { if (r < 0 || n < r) return mi<mod>(0); return fac[n] * inv[r] * inv[n - r]; } inline mi<mod> nHr(ll n, ll r) { return comb(n + r - 1, n - 1); } }; struct UFR { vector<ll> data; UFR(ll N) : data(N) { rep(i, N) data[i] = -1; } def root(ll x) { if (data[x] < 0) return x; else return data[x] = root(data[x]); } def unite(ll x, ll y) { ll root_x = root(x), root_y = root(y); if (root_x != root_y) { if (data[root_x] > data[root_y]) swap(root_x, root_y); data[root_x] -= data[root_x] == data[root_y]; data[root_y] = root_x; return true; } return false; } def same(ll x, ll y) { return root(x) == root(y); } }; struct position { ll x, y; position() {} position(ll a, ll b) : x(a), y(b) {} position next(ll i) { return {x + dx[i], y + dy[i]}; } ll mdist() { return abs(x) + abs(y); } double dist() { return sqrt(x * x + y * y); } double norm(ll d) { if (d == inf) return max(x, y); if (d == 1) return mdist(); if (d == 2) return dist(); return 0; } ll num(ll width) { return abs(x) * width + abs(y); } bool operator==(position a) { return x == a.x && y == a.y; } bool operator!=(position a) { return x != a.x || y != a.y; } bool operator<(position a) { return x < a.x && y < a.y; } bool operator>(position a) { return x > a.x && y > a.y; } bool operator<=(position a) { return x <= a.x && y <= a.y; } bool operator>=(position a) { return x >= a.x && y >= a.y; } position operator+(position a) { return position(x + a.x, y + a.y); } position operator-(position a) { return position(x - a.x, y - a.y); } position operator*(position a) { return position(x * a.x, y * a.y); } position operator/(position a) { return position(x / a.x, y / a.y); } position operator%(position a) { return position(x % a.x, y % a.y); } position complex(position a) { return position(x * a.x - y * a.y, x * a.y + y * a.x); } /* // for sort: bool operator<(position a) { return x ^ a.x ? x < a.x : y < a.y; } bool operator>(position a) { return x ^ a.x ? x > a.x : y > a.y; } bool operator<=(position a) { return x ^ a.x ? x < a.x : y <= a.y; } bool operator>=(position a) { return x ^ a.x ? x > a.x : y >= a.y; } */ }; position Origin = position(0, 0); using pos = position; using vec = position; template <class T> struct Array { struct node { ll childl, childr; T data; node(ll l, ll r, T t) : childl(l), childr(r), data(t) {} }; ll n, depth; vector<ll> versions; vector<ll> prev_versions; vector<node> nodes; Array(ll n = 1 << 20, T val = T()) : n(n), depth(0) { while (n /= 2) depth++; init(val); } void init(T val) { versions.push_back(0); prev_versions.push_back(0); rep(i, 2 * n - 1) { if (i < n - 1) { nodes.push_back(node(2 * i + 1, 2 * i + 2, T())); } else { nodes.push_back(node(0, 0, val)); } } } void set(ll index, ll val, ll version = -1) { ll id, par = nodes.size(), left = 0, right = n; if (version == -1) { id = versions.back(); version = versions.size() - 1; } else { id = versions[version]; } versions.push_back(par); prev_versions.push_back(version); if (right == -1) right = n; rep(i, depth) { ll mid = (left + right) / 2; if (index < mid) { nodes.push_back(node(par + i + 1, nodes[id].childr, T())); id = nodes[id].childl; right = mid; } else { nodes.push_back(node(nodes[id].childl, par + i + 1, T())); id = nodes[id].childr; left = mid; } } nodes.push_back(node(0, 0, val)); } T get(ll index, ll version = -1) { ll id, left = 0, right = n; if (version == -1) { id = versions.back(); } else { id = versions[version]; } rep(i, depth) { ll mid = (left + right) / 2; if (index < mid) { id = nodes[id].childl; right = mid; } else { id = nodes[id].childr; left = mid; } } return nodes[id].data; } ll latest() { return versions.size() - 1; } }; struct BipartiteGraph { ll V; vector<vector<ll>> G; vector<ll> match; vector<bool> used; BipartiteGraph(ll N) : V(N), G(N), match(N), used(N) {} void addEdge(ll i, ll j) { G[i].push_back(j); G[j].push_back(i); } bool dfs(ll now) { used[now] = true; rep(i, G[now].size()) { ll next = G[now][i], w = match[next]; if (w == -1 || (!used[w] && dfs(w))) { match[now] = next, match[next] = now; return true; } } return false; } ll matching() { ll res = 0; fill(all(match), -1); rep(i, V) { if (match[i] == -1) { fill(all(used), false); if (dfs(i)) res++; } } return res; } }; template <typename T = ll> struct Dijkstra { ll V; using P = pair<ll, ll>; vector<vector<P>> G; vector<T> dist; vector<bool> used; Dijkstra(ll v) : V(v), G(v), dist(v), used(v) {} void setDist(ll a, ll b, ll d) { G[a].push_back(P(d, b)); } void culc(ll s = 0) { priority_queue<P, vector<P>, greater<P>> Q; Q.push(P(0, s)); fill_n(dist.begin(), V, INF); fill_n(used.begin(), V, false); while (!Q.empty()) { T d; ll t; tie(d, t) = Q.top(), Q.pop(); if (used[t]) continue; used[t] = true, dist[t] = d; for (P e : G[t]) { if (dist[e.second] <= d + e.first) continue; Q.push(P(d + e.first, e.second)); } } } }; ll N, K, A[100]; ll DP[100001]; signed main() { cin >> N >> K; rep(i, N) cin >> A[i]; rep(i, K + 1) { DP[i] = !DP[i]; rep(j, N) if (i + A[j] <= K) DP[i + A[j]] |= DP[i]; } cout << (DP[K] ? "Second" : "First") << endl; }
replace
650
651
650
651
0
p03170
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; long long int INF = 1e18; long long int mod = 1000000007; double Pi = 3.1415926535897932384626; vector<ll> G[500005]; vector<P> tree[500010]; // big priority queue priority_queue<ll> pql; priority_queue<P> pqp; // small priority queue priority_queue<ll, vector<ll>, greater<ll>> pqls; priority_queue<P, vector<P>, greater<P>> pqps; // top pop int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; char dir[] = "RULD"; // ↓,→,↑,← #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << x << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << x; #define re(i, n) \ for (i = 0; i < n; i++) \ ; #define pb push_back #define lb lower_bound #define ub upper_bound #define deba(x) cout << #x << " = " << x << endl ll rui(ll number1, ll number2) { if (number2 == 0) { return 1; } else { ll number3 = rui(number1, number2 / 2); number3 *= number3; number3 %= mod; if (number2 % 2 == 1) { number3 *= number1; number3 %= mod; } return number3; } } ll gcd(ll number1, ll number2) { if (number1 > number2) { swap(number1, number2); } if (number1 == 0 || number1 == number2) { return number2; } else { return gcd(number2 % number1, number1); } } ll i, j, k, ii, jj, n, m; ll a, b, c, d, e, g, h, r, l, w, num, ans; ll x[500005], y[500005], z[500005]; ll dp[300005]; bool flag, dame, ng; int main() { cin >> n >> k; for (i = 0; i < n; i++) { cin >> x[i]; } dp[0] = 2; for (i = 1; i <= k; i++) { flag = false; for (j = 0; j < n; j++) { if (k - x[j] < 0) continue; if (dp[i - x[j]] == 2) { flag = true; } } if (flag) { dp[i] = 1; } else { dp[i] = 2; } // pe(dp[i]); } // el; if (dp[k] == 2) { p("Second"); } else { p("First"); } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; long long int INF = 1e18; long long int mod = 1000000007; double Pi = 3.1415926535897932384626; vector<ll> G[500005]; vector<P> tree[500010]; // big priority queue priority_queue<ll> pql; priority_queue<P> pqp; // small priority queue priority_queue<ll, vector<ll>, greater<ll>> pqls; priority_queue<P, vector<P>, greater<P>> pqps; // top pop int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; char dir[] = "RULD"; // ↓,→,↑,← #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << x << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << x; #define re(i, n) \ for (i = 0; i < n; i++) \ ; #define pb push_back #define lb lower_bound #define ub upper_bound #define deba(x) cout << #x << " = " << x << endl ll rui(ll number1, ll number2) { if (number2 == 0) { return 1; } else { ll number3 = rui(number1, number2 / 2); number3 *= number3; number3 %= mod; if (number2 % 2 == 1) { number3 *= number1; number3 %= mod; } return number3; } } ll gcd(ll number1, ll number2) { if (number1 > number2) { swap(number1, number2); } if (number1 == 0 || number1 == number2) { return number2; } else { return gcd(number2 % number1, number1); } } ll i, j, k, ii, jj, n, m; ll a, b, c, d, e, g, h, r, l, w, num, ans; ll x[500005], y[500005], z[500005]; ll dp[300005]; bool flag, dame, ng; int main() { cin >> n >> k; for (i = 0; i < n; i++) { cin >> x[i]; } dp[0] = 2; for (i = 1; i <= k; i++) { flag = false; for (j = 0; j < n; j++) { if (i - x[j] < 0) continue; if (dp[i - x[j]] == 2) { flag = true; } } if (flag) { dp[i] = 1; } else { dp[i] = 2; } // pe(dp[i]); } // el; if (dp[k] == 2) { p("Second"); } else { p("First"); } return 0; }
replace
98
99
98
99
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int n, k; vector<int> v; int dp[100005]; void solve() { for (int i = 1; i <= k; ++i) { if (dp[i] >= 0) continue; int res; for (int j = 0; j < n; ++j) { res = dp[i - v[j]]; if (res == 1) { dp[i] = 2; } else if (res == 2) { dp[i] = 1; break; } } } } int main() { cin >> n >> k; memset(dp, -1, sizeof(dp)); int num1, menor = 1000002; for (int i = 0; i < n; ++i) { cin >> num1; v.push_back(num1); dp[num1] = 1; menor = min(menor, num1); } for (int i = 0; i < menor; ++i) { dp[i] = 2; } solve(); if (dp[k] == 1 || dp[k] == 3) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int n, k; vector<int> v; int dp[100005]; void solve() { for (int i = 1; i <= k; ++i) { if (dp[i] >= 0) continue; int res; for (int j = 0; j < n; ++j) { int tam = (i - v[j]); if (tam < 0) continue; res = dp[tam]; if (res == 1) { dp[i] = 2; } else if (res == 2) { dp[i] = 1; break; } } } } int main() { cin >> n >> k; memset(dp, -1, sizeof(dp)); int num1, menor = 1000002; for (int i = 0; i < n; ++i) { cin >> num1; v.push_back(num1); dp[num1] = 1; menor = min(menor, num1); } for (int i = 0; i < menor; ++i) { dp[i] = 2; } solve(); if (dp[k] == 1 || dp[k] == 3) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
16
17
16
20
0
p03170
C++
Runtime Error
#include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <vector> #define Max (int)1e5 + 10 #define MAX_INT (int)1e9 + 2 #define MOD ((int)1e9 + 7) using namespace std; int dp[Max]; void init() { int i; for (i = 0; i < Max; i++) dp[i] = -1; } int canWin(int k, int min, int n, int a[]) { if (k == 0) return 0; if (dp[k] != -1) return dp[k]; int status = 0, i; for (i = 0; i < n; i++) { if (canWin(k - a[i], min, n, a) == 0 && k - a[i] >= 0) status = 1; } dp[k] = status; return dp[k]; } int main() { int n, k, a[Max], min = MAX_INT, i; init(); scanf("%d%d", &n, &k); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (min > a[i]) min = a[i]; } if (canWin(k, min, n, a)) printf("First\n"); else printf("Second\n"); } /* Atcoder Dp G-Longest Path iterative solution vector<int>vec[Max]; queue<int>q; int dp[Max]; int vis[Max]; void init(){ int i; for(i=0;i<Max;i++){ dp[i] = 0; vis[i] = 0; } } int getMax(int a,int b){ return (a<b)?b:a; } void solve(int x){ int i,u; q.push(x); while(!q.empty()){ u = q.front(); q.pop(); if(vis[u]) continue; vis[u] = 1; for(i=0;i<vec[u].size();i++){ dp[vec[u][i]] = getMax(dp[vec[u][i]],dp[u]+1); q.push(vec[u][i]); } } } int main(){ int n,m,incoming[Max],x,y,i; for(i=0;i<Max;i++) incoming[i] = 0; init(); scanf("%d%d",&n,&m); for(i=0;i<m;i++){ scanf("%d%d",&x,&y); vec[y].push_back(x); incoming[x]++; } for(i=1;i<=n;i++) solve(i); int max = 0; for(i=0;i<Max;i++) max = getMax(max,dp[i]); printf("%d\n",max); return 0; } */
#include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <vector> #define Max (int)1e5 + 10 #define MAX_INT (int)1e9 + 2 #define MOD ((int)1e9 + 7) using namespace std; int dp[Max]; void init() { int i; for (i = 0; i < Max; i++) dp[i] = -1; } int canWin(int k, int min, int n, int a[]) { if (k == 0) return 0; if (dp[k] != -1) return dp[k]; int status = 0, i; for (i = 0; i < n; i++) { if (k - a[i] >= 0) { if (canWin(k - a[i], min, n, a) == 0) status = 1; } } dp[k] = status; return dp[k]; } int main() { int n, k, a[Max], min = MAX_INT, i; init(); scanf("%d%d", &n, &k); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (min > a[i]) min = a[i]; } if (canWin(k, min, n, a)) printf("First\n"); else printf("Second\n"); } /* Atcoder Dp G-Longest Path iterative solution vector<int>vec[Max]; queue<int>q; int dp[Max]; int vis[Max]; void init(){ int i; for(i=0;i<Max;i++){ dp[i] = 0; vis[i] = 0; } } int getMax(int a,int b){ return (a<b)?b:a; } void solve(int x){ int i,u; q.push(x); while(!q.empty()){ u = q.front(); q.pop(); if(vis[u]) continue; vis[u] = 1; for(i=0;i<vec[u].size();i++){ dp[vec[u][i]] = getMax(dp[vec[u][i]],dp[u]+1); q.push(vec[u][i]); } } } int main(){ int n,m,incoming[Max],x,y,i; for(i=0;i<Max;i++) incoming[i] = 0; init(); scanf("%d%d",&n,&m); for(i=0;i<m;i++){ scanf("%d%d",&x,&y); vec[y].push_back(x); incoming[x]++; } for(i=1;i<=n;i++) solve(i); int max = 0; for(i=0;i<Max;i++) max = getMax(max,dp[i]); printf("%d\n",max); return 0; } */
replace
27
29
27
31
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 105, K = 100005; int a[N], dp[K]; vector<int> q; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for (int i = 0; i < a[1]; i++) dp[i] = 0; for (int i = a[1]; i <= k; i++) { for (int j = 1; j <= n; j++) if (!dp[i - a[j]]) dp[i] = 1; } puts(dp[k] ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 105, K = 100005; int a[N], dp[K]; vector<int> q; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for (int i = 0; i < a[1]; i++) dp[i] = 0; for (int i = a[1]; i <= k; i++) { for (int j = 1; j <= n; j++) if (i >= a[j] && !dp[i - a[j]]) dp[i] = 1; } puts(dp[k] ? "First" : "Second"); return 0; }
replace
15
16
15
16
0
p03170
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, K; cin >> n >> K; int niz[n]; for (int i = 0; i < n; i++) cin >> niz[i]; int df[K + 1]; df[0] = 2; for (int i = 1; i < K + 1; i++) { bool t = false; for (int j = 0; j < n; j++) { if (df[i - niz[j]] == 2) { t = true; break; } } if (t == true) df[i] = 1; else df[i] = 2; } // for(int i=0; i<K+1; i++) cout<<df[i]<<" "; if (df[K] == 1) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <iostream> using namespace std; int main() { int n, K; cin >> n >> K; int niz[n]; for (int i = 0; i < n; i++) cin >> niz[i]; int df[K + 1]; df[0] = 2; for (int i = 1; i < K + 1; i++) { bool t = false; for (int j = 0; j < n; j++) { if (i >= niz[j] && df[i - niz[j]] == 2) { t = true; break; } } if (t == true) df[i] = 1; else df[i] = 2; } // for(int i=0; i<K+1; i++) cout<<df[i]<<" "; if (df[K] == 1) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
16
17
16
17
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define F first #define S second // cout<<fixed<<setprecision(11); const string nl = "\n"; const ll MOD = 1e9 + 7; const ll ARR_MAX = 1e5 + 1; const ll INF = 1e14; bool dp[ARR_MAX]; // dp[i]=1 if player playing now will win. =0 if he will lose. void solve() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = a[0]; i <= k; i++) { bool f = 0; for (int j = 0; j < n; j++) { if (a[j] >= i) { f = f || !(dp[i - a[j]]); } } dp[i] = f; } // for(int i=0;i<=k;i++){ // cout<<dp[i]<<" "; // } // cout<<nl; if (dp[k] == 0) { cout << "Second" << nl; } else { cout << "First" << nl; } } int main() { int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define F first #define S second // cout<<fixed<<setprecision(11); const string nl = "\n"; const ll MOD = 1e9 + 7; const ll ARR_MAX = 1e5 + 1; const ll INF = 1e14; bool dp[ARR_MAX]; // dp[i]=1 if player playing now will win. =0 if he will lose. void solve() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = a[0]; i <= k; i++) { bool f = 0; for (int j = 0; j < n; j++) { if (a[j] <= i) { f = f || !(dp[i - a[j]]); } } dp[i] = f; } // for(int i=0;i<=k;i++){ // cout<<dp[i]<<" "; // } // cout<<nl; if (dp[k] == 0) { cout << "Second" << nl; } else { cout << "First" << nl; } } int main() { int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
31
32
31
32
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; using PII = pair<ll, ll>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << '\n' #define p2(s, t) cout << (s) << " " << (t) << '\n' #define br() p("") #define pn(s) cout << (#s) << " " << (s) << '\n' #define p_yes() p("YES") #define p_no() p("NO") #define SZ(x) ((int)(x).size()) #define SORT(A) sort(ALL(A)) #define RSORT(A) sort(ALL(A), greater<ll>()) #define MP make_pair void no() { p_no(); exit(0); } void yes() { p_yes(); exit(0); } const ll mod = 1e9 + 7; const ll inf = 1e18; const double PI = acos(-1); ll N, K; VI A; int main() { cin.tie(0); ios::sync_with_stdio(false); // input cin >> N >> K; A.resize(N); rep(i, N) { cin >> A[i]; } VI dp(100500, 0); dp[0] = 0; // lose rep(i, 100500) { if (dp[i] == 0) { for (ll a : A) { dp[i + a] = 1; } } } ll ans = dp[K]; if (ans == 1) { p("First"); } else { p("Second"); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; using PII = pair<ll, ll>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << '\n' #define p2(s, t) cout << (s) << " " << (t) << '\n' #define br() p("") #define pn(s) cout << (#s) << " " << (s) << '\n' #define p_yes() p("YES") #define p_no() p("NO") #define SZ(x) ((int)(x).size()) #define SORT(A) sort(ALL(A)) #define RSORT(A) sort(ALL(A), greater<ll>()) #define MP make_pair void no() { p_no(); exit(0); } void yes() { p_yes(); exit(0); } const ll mod = 1e9 + 7; const ll inf = 1e18; const double PI = acos(-1); ll N, K; VI A; int main() { cin.tie(0); ios::sync_with_stdio(false); // input cin >> N >> K; A.resize(N); rep(i, N) { cin >> A[i]; } VI dp(100500, 0); dp[0] = 0; // lose rep(i, 100500) { if (dp[i] == 0) { for (ll a : A) { if (i + a < 100500) dp[i + a] = 1; } } } ll ans = dp[K]; if (ans == 1) { p("First"); } else { p("Second"); } return 0; }
replace
149
150
149
151
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define f(i, l, n) for (int i = l; i < n; i++) #define E "\n" #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define MAX 1e5 #define MIN -1e5 const int N = 1e5 + 2; int n, k; vector<int> a; int dp[N][2]; int solve(int x, int k) { if (k < a[0]) return 1 - x; if (dp[k][x] != -1) return dp[k][x]; int ans = 1 - x; for (int i = 0; i < n; i++) { if (a[i] <= k) { if (solve(1 - x, k - a[i]) == x) { ans = x; break; } } else break; } return dp[k][x] = ans; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> k; a.resize(n); f(i, 0, N) f(j, 0, 2) dp[i][j] = -1; for (int i = 0; i < n; ++i) { cin >> a[i]; } if (solve(0, k) == 0) cout << "First\n"; else cout << "Second"; }
#include <bits/stdc++.h> using namespace std; #define int long long #define f(i, l, n) for (int i = l; i < n; i++) #define E "\n" #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define MAX 1e5 #define MIN -1e5 const int N = 1e5 + 2; int n, k; vector<int> a; int dp[N][2]; int solve(int x, int k) { if (k < a[0]) return 1 - x; if (dp[k][x] != -1) return dp[k][x]; int ans = 1 - x; for (int i = 0; i < n; i++) { if (a[i] <= k) { if (solve(1 - x, k - a[i]) == x) { ans = x; break; } } else break; } return dp[k][x] = ans; } int32_t main() { cin >> n >> k; a.resize(n); f(i, 0, N) f(j, 0, 2) dp[i][j] = -1; for (int i = 0; i < n; ++i) { cin >> a[i]; } if (solve(0, k) == 0) cout << "First\n"; else cout << "Second"; }
delete
43
48
43
43
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vec(k) vector<k> #define vecvec(k) vector<vector<k>> #define pai(k) pair<k, k> #define mod 1000000007 #define mpai make_pair #define p1 first #define p2 second #define umap(x, y) unordered_map<x, y> int solve(int *arr, int n, int k) { int dp[n + 1][k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { dp[i][j] = dp[i - 1][j]; if (j >= arr[i - 1]) dp[i][j] = dp[i][j] | (!dp[i][j - arr[i - 1]]); } } return dp[n][k]; } int solveagain(int *arr, int n, int k) { int dp[k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { dp[i] = dp[i] | (i >= arr[j]) ? (!dp[i - arr[j]]) : 0; } } return dp[k]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, x, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int ans = solveagain(arr, n, k); if (ans) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vec(k) vector<k> #define vecvec(k) vector<vector<k>> #define pai(k) pair<k, k> #define mod 1000000007 #define mpai make_pair #define p1 first #define p2 second #define umap(x, y) unordered_map<x, y> int solve(int *arr, int n, int k) { int dp[n + 1][k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { dp[i][j] = dp[i - 1][j]; if (j >= arr[i - 1]) dp[i][j] = dp[i][j] | (!dp[i][j - arr[i - 1]]); } } return dp[n][k]; } int solveagain(int *arr, int n, int k) { int dp[k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (i < arr[j]) continue; if (dp[i - arr[j]] == 0) dp[i] = 1; } } return dp[k]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, x, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int ans = solveagain(arr, n, k); if (ans) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
29
30
29
33
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; int main(void) { int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; vector<bool> stones(K + 3, false); // 1,2, ... Kまでの値で // それぞれ先手必勝or後手必勝7日を調べる // 答えはstones[K]により判定される // stones[K] == trueならば 先手必勝である // stones[K] == falseならば 後手必勝である for (int i = 1; i <= K; i++) { for (int j = 0; j < N; j++) { if (stones[i - a[j]] == false && i - a[j] >= 0) stones[i] = true; } } if (stones[K]) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main(void) { int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; vector<bool> stones(K + 3, false); // 1,2, ... Kまでの値で // それぞれ先手必勝or後手必勝7日を調べる // 答えはstones[K]により判定される // stones[K] == trueならば 先手必勝である // stones[K] == falseならば 後手必勝である for (int i = 1; i <= K; i++) { for (int j = 0; j < N; j++) { if (i - a[j] >= 0 && stones[i - a[j]] == false) stones[i] = true; } } if (stones[K]) cout << "First" << endl; else cout << "Second" << endl; }
replace
25
26
25
26
0
p03170
C++
Runtime Error
#include <iostream> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) int dp[100010]; int a[110]; int main() { int n, k; cin >> n >> k; REP(i, n) { cin >> a[i]; } REP(i, k + 1) { dp[i] = 0; } REP(i, k) { if (i < a[0]) { dp[i] = -1; } REP(j, n) { if (dp[i + a[j]] != 1) { dp[i + a[j]] = -dp[i]; } } } if (dp[k] == 1) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <iostream> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) int dp[100010]; int a[110]; int main() { int n, k; cin >> n >> k; REP(i, n) { cin >> a[i]; } REP(i, k + 1) { dp[i] = 0; } REP(i, k) { if (i < a[0]) { dp[i] = -1; } REP(j, n) { if (i + a[j] > k) continue; if (dp[i + a[j]] != 1) { dp[i + a[j]] = -dp[i]; } } } if (dp[k] == 1) { cout << "First" << endl; } else { cout << "Second" << endl; } }
insert
23
23
23
25
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define AB_BHI_NI_DEGI \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define pb push_back #define N 100009 #define inf 1e18 const double PI = 3.141592653589793238462643383279; int mod = 1e9 + 7; // int mod = 998244353; #define P pair<int, int> #define F first #define S second #define ll long long #define all(v) v.begin(), v.end() #define vi vector<int> #define ld long double #define ordered_set \ tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update> void end(int n = -1) { cout << n << "\n"; exit(0); } int n, k; int a[103]; int dp[N]; int fun(int rem) { if (dp[N]) return dp[N]; for (int i = 1; i <= n; i++) { if (rem >= a[i]) { if (fun(rem - a[i]) == 2) { dp[rem] = 1; return dp[rem]; } } } return dp[rem] = 2; } int32_t main() { AB_BHI_NI_DEGI cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0] = 2; int x = fun(k); if (x == 1) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define AB_BHI_NI_DEGI \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define pb push_back #define N 100009 #define inf 1e18 const double PI = 3.141592653589793238462643383279; int mod = 1e9 + 7; // int mod = 998244353; #define P pair<int, int> #define F first #define S second #define ll long long #define all(v) v.begin(), v.end() #define vi vector<int> #define ld long double #define ordered_set \ tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update> void end(int n = -1) { cout << n << "\n"; exit(0); } int n, k; int a[103]; int dp[N]; int fun(int rem) { if (dp[rem]) return dp[rem]; for (int i = 1; i <= n; i++) { if (rem >= a[i]) { if (fun(rem - a[i]) == 2) { dp[rem] = 1; return dp[rem]; } } } return dp[rem] = 2; } int32_t main() { AB_BHI_NI_DEGI cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0] = 2; int x = fun(k); if (x == 1) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
36
38
36
38
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; vector<bool> dp(k + 1, false); for (int i = a[0]; i < dp.size(); i++) { rep(j, a.size()) { if (dp[i - a[j]] == false) { dp[i] = true; break; } } } printf("%s", dp[k] == true ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; vector<bool> dp(k + 1, false); for (int i = a[0]; i < dp.size(); i++) { rep(j, a.size()) { if (i - a[j] >= 0 && dp[i - a[j]] == false) { dp[i] = true; break; } } } printf("%s", dp[k] == true ? "First" : "Second"); return 0; }
replace
16
17
16
17
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define X first #define Y second #define pb push_back void solve(); int main() { // freopen("schools.in", "r", stdin); // freopen("schools.out", "w", stdout); ios_base::sync_with_stdio(0), cin.tie(0); // cout << fixed << setprecision(10); int t; // cin >> t; t = 1; while (t--) solve(); return 0; } int dp[105]; int n, k, a[100005]; bool dfs(int balance) { if (dp[balance] != -1) return dp[balance]; int ans = 0; for (int i = 1; i <= n; ++i) if (a[i] <= balance) ans |= !dfs(balance - a[i]); return dp[balance] = ans; } void solve() { cin >> n >> k; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= n; ++i) cin >> a[i]; cout << (dfs(k) ? "First\n" : "Second\n"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define X first #define Y second #define pb push_back void solve(); int main() { // freopen("schools.in", "r", stdin); // freopen("schools.out", "w", stdout); ios_base::sync_with_stdio(0), cin.tie(0); // cout << fixed << setprecision(10); int t; // cin >> t; t = 1; while (t--) solve(); return 0; } int dp[100005]; int n, k, a[100005]; bool dfs(int balance) { if (dp[balance] != -1) return dp[balance]; int ans = 0; for (int i = 1; i <= n; ++i) if (a[i] <= balance) ans |= !dfs(balance - a[i]); return dp[balance] = ans; } void solve() { cin >> n >> k; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= n; ++i) cin >> a[i]; cout << (dfs(k) ? "First\n" : "Second\n"); }
replace
23
24
23
24
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int // #include "../../Template.cpp" vector<vector<int>> dp; int n, k; vector<int> arr; int solve(int left = k, int chance = 0) { if (dp[chance][left] != -1) { return dp[chance][left]; } int ans = chance; for (int i = 0; i < n; i++) { int temp = left - arr[i]; if (temp >= 0 && temp < arr[0]) { dp[chance][left] = chance; return chance; } } for (int i = 0; i < n; i++) { if (solve(left - arr[i], !chance) == chance) { dp[chance][left] = chance; } } if (dp[chance][left] == -1) { dp[chance][left] = !chance; } return dp[chance][left]; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; dp.assign(2, vector<int>(k + 1, -1)); arr.assign(n + 1, 0); for (int i = 0; i < n; i++) cin >> arr[i]; int ans = solve(); // cout << dp << endl; cout << (ans ? "Second" : "First") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int // #include "../../Template.cpp" vector<vector<int>> dp; int n, k; vector<int> arr; int solve(int left = k, int chance = 0) { if (dp[chance][left] != -1) { return dp[chance][left]; } int ans = chance; for (int i = 0; i < n; i++) { int temp = left - arr[i]; if (temp >= 0 && temp < arr[0]) { dp[chance][left] = chance; return chance; } } for (int i = 0; i < n; i++) { if (left >= arr[i] && (solve(left - arr[i], !chance) == chance)) { dp[chance][left] = chance; } } if (dp[chance][left] == -1) { dp[chance][left] = !chance; } return dp[chance][left]; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; dp.assign(2, vector<int>(k + 1, -1)); arr.assign(n + 1, 0); for (int i = 0; i < n; i++) cin >> arr[i]; int ans = solve(); // cout << dp << endl; cout << (ans ? "Second" : "First") << endl; return 0; }
replace
23
24
23
24
0
p03170
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<bool> dp(n + 1, 0); for (int i = 0; i <= k; i++) { for (int a : v) { if (i - a >= 0 && !dp[i - a]) dp[i] = 1; } } if (dp[k]) cout << "First"; else cout << "Second"; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<bool> dp(k + 1, 0); for (int i = 0; i <= k; i++) { for (int a : v) { if (i - a >= 0 && !dp[i - a]) dp[i] = 1; } } if (dp[k]) cout << "First"; else cout << "Second"; }
replace
16
17
16
17
0
p03170
C++
Runtime Error
/* _________________________________________________________________________________________________ | | | Author : Aditya Ahuja | | Date : Sun, 4th Aug 2019 | |_________________________________________________________________________________________________| */ #include <bits/stdc++.h> using namespace std; // #define int long long #define pb push_back #define F first #define S second #define endl "\n" #define rep(i, a, b) for (int i = a; i < (int)b; i++) #define req(i, a, b) for (int i = (int)b - 1; i >= a; i--) #define all(a) (a).begin(), (a).end() #define ret(x) \ { \ cout << x << endl; \ return; \ } #define sz(x) (int)x.size() #define type(x) typeid(x).name() typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<vector<int>> vii; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } #ifdef LOCAL #define wa(x) cerr << (#x) << " --- " << (x) << endl #define pvi(v) \ { \ for (auto it : v) \ cerr << it << " "; \ cerr << endl; \ } #define line1 cerr << "---------------------------" << endl; #else #define wa // #define line1 // #define pvi // #define printf // #endif void solve(); signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(10); int t = 1; // cin>>t; while (t--) solve(); return 0; } //___________________________________________________________________________________________________ void solve() { int n, k; cin >> n >> k; vi a(n); rep(i, 0, n) cin >> a[i]; sort(all(a)); vi dp(k + 1, 0); // dp[i] : would player 1 win if there were i stones in the pile? rep(i, 0, a[0]) dp[i] = 0; rep(i, a[0], k + 1) { rep(j, 0, n) { if (dp[i - a[j]] == 0) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
/* _________________________________________________________________________________________________ | | | Author : Aditya Ahuja | | Date : Sun, 4th Aug 2019 | |_________________________________________________________________________________________________| */ #include <bits/stdc++.h> using namespace std; // #define int long long #define pb push_back #define F first #define S second #define endl "\n" #define rep(i, a, b) for (int i = a; i < (int)b; i++) #define req(i, a, b) for (int i = (int)b - 1; i >= a; i--) #define all(a) (a).begin(), (a).end() #define ret(x) \ { \ cout << x << endl; \ return; \ } #define sz(x) (int)x.size() #define type(x) typeid(x).name() typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<vector<int>> vii; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } #ifdef LOCAL #define wa(x) cerr << (#x) << " --- " << (x) << endl #define pvi(v) \ { \ for (auto it : v) \ cerr << it << " "; \ cerr << endl; \ } #define line1 cerr << "---------------------------" << endl; #else #define wa // #define line1 // #define pvi // #define printf // #endif void solve(); signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(10); int t = 1; // cin>>t; while (t--) solve(); return 0; } //___________________________________________________________________________________________________ void solve() { int n, k; cin >> n >> k; vi a(n); rep(i, 0, n) cin >> a[i]; sort(all(a)); vi dp(k + 1, 0); // dp[i] : would player 1 win if there were i stones in the pile? rep(i, 0, a[0]) dp[i] = 0; rep(i, a[0], k + 1) { rep(j, 0, n) { if (i - a[j] >= 0 && dp[i - a[j]] == 0) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
replace
80
81
80
81
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long string solve(int arr[], int k, int n) { vector<bool> dp(k + 1, 0); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (i >= j) { if (dp[i - arr[j]] == 0) dp[i] = 1; } } } return dp[k] ? "First" : "Second"; } int main() { // code int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } cout << solve(arr, k, n) << endl; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long string solve(int arr[], int k, int n) { vector<bool> dp(k + 1, 0); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (i >= arr[j]) { if (dp[i - arr[j]] == 0) dp[i] = 1; } } } return dp[k] ? "First" : "Second"; } int main() { // code int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } cout << solve(arr, k, n) << endl; }
replace
10
11
10
11
0
p03170
C++
Runtime Error
// #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second #define pb push_back #define REP(i, a, b) for (long long int i = a; i < b; i++) #define mp make_pair #define mt make_tuple #define INF 1000000000000000000 #define mod 1000000007 #define pi pair<ll, ll> #define pd pair<ld, ld> #define tp tuple<ll, ll, ll> #define td tuple<ld, ld, ld> #define vi vector<ll> #define vd vector<ld> #define vvi vector<vi> #define vvvi vector<vvi> #define vvd vector<vd> #define vpi vector<pi> #define vpd vector<pd> #define vs vector<string> #define vvs vector<vs> #define us unordered_set<ll> #define um unordered_map<ll, ll> #define MXPQ priority_queue<ll> #define MNPQ priority_queue<ll, vi, greater<ll>> #define sortA(a) sort(a.begin(), a.end()) #define sortD(a) sort(a.begin(), a.end(), greater<ll>()) #define all(a) a.begin(), a.end() #define bll __builtin_popcountll #define N 100005 const ld PI = acos(-1); #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define in insert #define fbo find_by_order #define ook order_of_key template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(char s) { string x = ""; x += s; return x; } string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t sze> string to_string(bitset<sze> v) { string res = ""; for (size_t i = 0; i < sze; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); } #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) ll powmod(ll a, ll b, ll p) { ll res = 1; while (b > 0) { if (b & 1) { res = (res * a) % p; } a = (a * a) % p; b >>= 1; } return res; } void print1D(vi a) { for (ll i = 0; i < (ll)a.size(); ++i) { cout << a[i] << " "; } cout << endl; } void print2D(vector<vi> a) { for (ll i = 0; i < (ll)a.size(); ++i) { for (ll j = 0; j < (ll)a[i].size(); ++j) { cout << a[i][j] << " "; } cout << endl; } } void solve() { ll n, k; cin >> n >> k; vi a(n); for (ll i = 0; i < n; ++i) { cin >> a[i]; } vi dp(k + 1); for (ll i = 1; i <= k; ++i) { for (ll j = 0; j < n; ++j) { if ((i - a[j]) >= 0 && dp[i - a[j]] == 0) { dp[i] = 1; break; } } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1; // cin >> t; while (t--) { solve(); } }
// #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second #define pb push_back #define REP(i, a, b) for (long long int i = a; i < b; i++) #define mp make_pair #define mt make_tuple #define INF 1000000000000000000 #define mod 1000000007 #define pi pair<ll, ll> #define pd pair<ld, ld> #define tp tuple<ll, ll, ll> #define td tuple<ld, ld, ld> #define vi vector<ll> #define vd vector<ld> #define vvi vector<vi> #define vvvi vector<vvi> #define vvd vector<vd> #define vpi vector<pi> #define vpd vector<pd> #define vs vector<string> #define vvs vector<vs> #define us unordered_set<ll> #define um unordered_map<ll, ll> #define MXPQ priority_queue<ll> #define MNPQ priority_queue<ll, vi, greater<ll>> #define sortA(a) sort(a.begin(), a.end()) #define sortD(a) sort(a.begin(), a.end(), greater<ll>()) #define all(a) a.begin(), a.end() #define bll __builtin_popcountll #define N 100005 const ld PI = acos(-1); #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define in insert #define fbo find_by_order #define ook order_of_key template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(char s) { string x = ""; x += s; return x; } string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t sze> string to_string(bitset<sze> v) { string res = ""; for (size_t i = 0; i < sze; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); } #define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) ll powmod(ll a, ll b, ll p) { ll res = 1; while (b > 0) { if (b & 1) { res = (res * a) % p; } a = (a * a) % p; b >>= 1; } return res; } void print1D(vi a) { for (ll i = 0; i < (ll)a.size(); ++i) { cout << a[i] << " "; } cout << endl; } void print2D(vector<vi> a) { for (ll i = 0; i < (ll)a.size(); ++i) { for (ll j = 0; j < (ll)a[i].size(); ++j) { cout << a[i][j] << " "; } cout << endl; } } void solve() { ll n, k; cin >> n >> k; vi a(n); for (ll i = 0; i < n; ++i) { cin >> a[i]; } vi dp(k + 1); for (ll i = 1; i <= k; ++i) { for (ll j = 0; j < n; ++j) { if ((i - a[j]) >= 0 && dp[i - a[j]] == 0) { dp[i] = 1; break; } } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ll t = 1; // cin >> t; while (t--) { solve(); } }
replace
178
182
178
182
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); const int INF = 1e9; int main() { fast int n, K; cin >> n >> K; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<bool> dp(100001, false); for (int k = 0; k < n; k++) { for (int x = 0; x <= K; x++) { if (!dp[x]) dp[x + a[k]] = true; } } if (dp[K]) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); const int INF = 1e9; int main() { fast int n, K; cin >> n >> K; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<bool> dp(K + 1, false); for (int x = 0; x <= K; x++) { for (int k = 0; k < n; k++) { if (x + a[k] <= K) { if (!dp[x]) dp[x + a[k]] = true; } } } if (dp[K]) cout << "First"; else cout << "Second"; return 0; }
replace
15
20
15
22
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define mp make_pair #define pb push_back #define em emplace #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) template <class T> inline int chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline int chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 58; constexpr int mod = 1000000007; bool dp[100010]; int main() { int n, k; cin >> n >> k; vector<int> A(n); for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < k; i++) { if (dp[i]) continue; for (int j = 0; j < n; j++) { dp[i + A[j]] = 1; } } cout << (dp[k] ? "First" : "Second") << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define mp make_pair #define pb push_back #define em emplace #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) template <class T> inline int chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline int chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 58; constexpr int mod = 1000000007; bool dp[200010]; int main() { int n, k; cin >> n >> k; vector<int> A(n); for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < k; i++) { if (dp[i]) continue; for (int j = 0; j < n; j++) { dp[i + A[j]] = 1; } } cout << (dp[k] ? "First" : "Second") << endl; }
replace
31
32
31
32
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 107; int a[MAX]; int g[MAX * MAX * MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 1; i <= k; ++i) g[i] = -1; for (int i = 1; i <= k; ++i) { for (int j = 0; a[j] <= i; ++j) if (g[i - a[j]] == 0) g[i] = 1; if (g[i] == -1) g[i] = 0; } if (g[k] == 1) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 107; int a[MAX]; int g[MAX * MAX * MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 1; i <= k; ++i) g[i] = -1; for (int i = 1; i <= k; ++i) { for (int j = 0; j < n && a[j] <= i; ++j) if (g[i - a[j]] == 0) g[i] = 1; if (g[i] == -1) g[i] = 0; } if (g[k] == 1) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
21
22
21
22
-11
p03170
C++
Runtime Error
// author:-*mdragneell* #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pi pair<int, int> #define pl pair<ll, ll> int const N = 3001; ll min(ll x, ll y) { if (x < y) return x; else return y; } ll max(ll x, ll y) { if (x > y) return x; else return y; } ll cache[N]; ll n, k, a[N]; ll sol(ll k) { if (k == 0) return 0; if (cache[k] != -1) return cache[k]; cache[k] = 0; for (int i = 0; i < n; i++) { if (k < a[i]) break; cache[k] |= (sol(k - a[i]) == 0); } return cache[k]; } int main() { ll i, j; cin >> n >> k; memset(cache, -1, sizeof(cache)); for (i = 0; i < n; i++) cin >> a[i]; if (sol(k)) cout << "First" << endl; else cout << "Second" << endl; }
// author:-*mdragneell* #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pi pair<int, int> #define pl pair<ll, ll> int const N = 100005; ll min(ll x, ll y) { if (x < y) return x; else return y; } ll max(ll x, ll y) { if (x > y) return x; else return y; } ll cache[N]; ll n, k, a[N]; ll sol(ll k) { if (k == 0) return 0; if (cache[k] != -1) return cache[k]; cache[k] = 0; for (int i = 0; i < n; i++) { if (k < a[i]) break; cache[k] |= (sol(k - a[i]) == 0); } return cache[k]; } int main() { ll i, j; cin >> n >> k; memset(cache, -1, sizeof(cache)); for (i = 0; i < n; i++) cin >> a[i]; if (sol(k)) cout << "First" << endl; else cout << "Second" << endl; }
replace
11
12
11
12
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int dp[k + 1]; dp[0] = 0; int i = 1; while (i < a[0]) { dp[i] = 0; i++; } for (int i = a[0]; i <= k; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if (!dp[i - a[j]]) dp[i] |= 1; } } cout << (dp[k] ? "First" : "Second") << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int dp[k + 1]; dp[0] = 0; int i = 1; while (i < a[0]) { dp[i] = 0; i++; } for (int i = a[0]; i <= k; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if ((i - a[j] >= 0) && !dp[i - a[j]]) dp[i] |= 1; } } cout << (dp[k] ? "First" : "Second") << endl; }
replace
21
22
21
22
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define loop(i, a, b) for (lli i = a; i <= b; ++i) #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define lli long long int using namespace std; signed main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif fast; int n, k; cin >> n >> k; int x[n]; loop(i, 0, n - 1) cin >> x[i]; bool a[k + 1]; loop(i, 0, k) { bool ans = false; loop(j, 0, n - 1) { if (i - x[j] >= 0) { ans = ans || (a[i - x[j]] == 0); } } a[i] = ans; } cout << (a[k] ? "First" : "Second") << endl; return 0; }
#include <bits/stdc++.h> #define loop(i, a, b) for (lli i = a; i <= b; ++i) #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define lli long long int using namespace std; signed main() { fast; int n, k; cin >> n >> k; int x[n]; loop(i, 0, n - 1) cin >> x[i]; bool a[k + 1]; loop(i, 0, k) { bool ans = false; loop(j, 0, n - 1) { if (i - x[j] >= 0) { ans = ans || (a[i - x[j]] == 0); } } a[i] = ans; } cout << (a[k] ? "First" : "Second") << endl; return 0; }
delete
10
16
10
10
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll INFL = 1000000000000000010; // 10^18 = 2^60 int INF = 2000000000; // 10^9 ll MOD = 1000000007; vector<bool> W(100010); int main() { int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } for (int i = 0; i <= K; i++) { if (W.at(i) == 0) { for (int j = 0; j < N; j++) { W.at(i + a.at(j)) = 1; } } } if (W.at(K)) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll INFL = 1000000000000000010; // 10^18 = 2^60 int INF = 2000000000; // 10^9 ll MOD = 1000000007; vector<bool> W(100010); int main() { int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } for (int i = 0; i <= K; i++) { if (W.at(i) == 0) { for (int j = 0; j < N; j++) { if (i + a.at(j) < 100010) { W.at(i + a.at(j)) = 1; } } } } if (W.at(K)) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
19
20
19
22
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; bool dp[k + 1]; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = false; for (int i = 1; i < k + 1; i++) { dp[i] = false; for (int j = 0; j < n; j++) { if (a[j] <= k) { if (!dp[i - a[j]]) dp[i] = !dp[i - a[j]]; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; bool dp[k + 1]; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = false; for (int i = 1; i < k + 1; i++) { dp[i] = false; for (int j = 0; j < n; j++) { if (a[j] <= i) { if (!dp[i - a[j]]) dp[i] = !dp[i - a[j]]; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
replace
14
15
14
15
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <chrono> #include <cstdio> #include <random> using namespace std; #define DRACARYS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cin.exceptions(cin.failbit); \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second #define mp make_pair #define pb push_back #define PI 3.14159265 const long long int MAXN = 1e5 + 10; const long long int MINN = 1e5 + 10; const long long int inf = 1e18 + 7; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef stack<int> st; int n, k, a[105], dp[MAXN]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); DRACARYS cin >> n >> k; repA(i, 1, n) cin >> a[i]; repA(i, 0, k) repA(j, 1, n) if (!dp[i]) dp[i + a[j]] = 1; if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> #include <chrono> #include <cstdio> #include <random> using namespace std; #define DRACARYS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cin.exceptions(cin.failbit); \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second #define mp make_pair #define pb push_back #define PI 3.14159265 const long long int MAXN = 2e5 + 10; const long long int MINN = 1e5 + 10; const long long int inf = 1e18 + 7; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef stack<int> st; int n, k, a[105], dp[MAXN]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); DRACARYS cin >> n >> k; repA(i, 1, n) cin >> a[i]; repA(i, 0, k) repA(j, 1, n) if (!dp[i]) dp[i + a[j]] = 1; if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
23
24
23
24
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <stdio.h> #define ll long long #define M 300002 #define N 1000000000000000003 #define endl "\n" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, v; cin >> n >> v; ll arr[200004] = {0}; ll var[200003] = {0}; for (ll i = 1; i <= n; i++) { cin >> arr[i]; var[arr[i]] = 1; } sort(arr, arr + n); for (ll i = arr[1]; i <= v; i++) { if (var[i] == 1) { continue; } for (ll j = 1; j <= n; j++) { if ((var[i - arr[j]] == 0) && (i - arr[j] >= 0)) { var[i] = 1; break; } } } if (var[v] == 1) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> #include <stdio.h> #define ll long long #define M 300002 #define N 1000000000000000003 #define endl "\n" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, v; cin >> n >> v; ll arr[200004] = {0}; ll var[200003] = {0}; for (ll i = 1; i <= n; i++) { cin >> arr[i]; var[arr[i]] = 1; } sort(arr, arr + n); for (ll i = arr[1]; i <= v; i++) { if (var[i] == 1) { continue; } for (ll j = 1; j <= n; j++) { if (i - arr[j] >= 0) { if (var[i - arr[j]] == 0) { var[i] = 1; break; } } } } if (var[v] == 1) cout << "First"; else cout << "Second"; return 0; }
replace
28
31
28
33
0
p03170
C++
Runtime Error
/* Code by : Suraj (@suraj1611) */ #include <bits/stdc++.h> #include <string> using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define mx INT_MAX #define mn INT_MIN #define md 1000000007 #define pb push_back #define mp make_pair #define maxsize 1100005 #define lb cout << endl; #define endl "\n" #define F first #define S second #define label cout << "hello!" << endl #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll power(ll x, ll y) { ll m = md; ll ans = 1; while (y > 0) { if (y & 1) ans = (ans * x) % m; x = (x * x) % m; y >>= 1; } return ans; } int main() { IOS ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; bool dp[n + 1]; fill(dp, dp + 1, 0); rep(i, k + 1) { for (auto j : a) { if ((i - j) >= 0 and !dp[i - j]) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
/* Code by : Suraj (@suraj1611) */ #include <bits/stdc++.h> #include <string> using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define mx INT_MAX #define mn INT_MIN #define md 1000000007 #define pb push_back #define mp make_pair #define maxsize 1100005 #define lb cout << endl; #define endl "\n" #define F first #define S second #define label cout << "hello!" << endl #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll power(ll x, ll y) { ll m = md; ll ans = 1; while (y > 0) { if (y & 1) ans = (ans * x) % m; x = (x * x) % m; y >>= 1; } return ans; } int main() { IOS ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; bool dp[k + 1]; fill(dp, dp + k + 1, 0); rep(i, k + 1) { for (auto j : a) { if ((i - j) >= 0 and !dp[i - j]) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
47
49
47
49
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, k; int a[1000005], f[1000005]; int solve(int x) { if (f[x] != -1) return f[x]; if (x == 0) return f[x] = 0; int ret = 0; for (int i = 1; i <= n; i++) { if (x >= a[i]) ret |= (solve(x - a[i]) ^ 1); } return ret; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(f, -1, sizeof(f)); puts(solve(k) ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[1000005], f[1000005]; int solve(int x) { if (f[x] != -1) return f[x]; if (x == 0) return f[x] = 0; int ret = 0; for (int i = 1; i <= n; i++) { if (x >= a[i]) ret |= (solve(x - a[i]) ^ 1); } return f[x] = ret; } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(f, -1, sizeof(f)); puts(solve(k) ? "First" : "Second"); return 0; }
replace
14
15
14
15
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h>#De #define DIM 107 #define INF 1000000007 using namespace std; long long n, k, a[DIM], used[DIM]; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= k; ++i) for (int j = 1; j <= n; ++j) if (i >= a[j] && used[i - a[j]] == 0) used[i] = 1; if (used[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h>#De #define DIM 107 #define INF 1000000007 using namespace std; long long n, k, a[DIM], used[100007]; int main() { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= k; ++i) for (int j = 1; j <= n; ++j) if (i >= a[j] && used[i - a[j]] == 0) used[i] = 1; if (used[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
5
6
5
6
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) #define REPi(i, a, b) for (int i = int(a); i < int(b); i++) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const ll MOD = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, N) { ll a; cin >> a; A[i] = a; } vector<int> DP(K + 1000); REP(i, K + 1) { REP(j, N) { ll a = A[j]; if (DP[i] == 0) DP[i + a] = 1; } } ll ans = DP[K]; if (ans == 0) cout << "Second" << endl; else cout << "First" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) #define REPi(i, a, b) for (int i = int(a); i < int(b); i++) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const ll MOD = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, N) { ll a; cin >> a; A[i] = a; } vector<int> DP(K + 1000); REP(i, K + 1) { REP(j, N) { ll a = A[j]; if (i + a > K) continue; if (DP[i] == 0) DP[i + a] = 1; } } ll ans = DP[K]; if (ans == 0) cout << "Second" << endl; else cout << "First" << endl; return 0; }
insert
38
38
38
40
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; vector<int> grundy(100005, -1); int getMax(set<int> s) { int max = 0; while (s.find(max) != s.end()) max++; return max; } int getGrundy(int pos, int *a, int n) { if (grundy[pos] != -1) return grundy[pos]; set<int> s; for (int i = 0; i < n; i++) { if (a[i] > pos) break; int res = getGrundy(pos - a[i], a, n); s.insert(res); } return getMax(s); } int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); grundy[0] = 0; grundy[k] = getGrundy(k, a, n); if (grundy[k]) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> grundy(100005, -1); int getMax(set<int> s) { int max = 0; while (s.find(max) != s.end()) max++; return max; } int getGrundy(int pos, int *a, int n) { if (grundy[pos] != -1) return grundy[pos]; set<int> s; for (int i = 0; i < n; i++) { if (a[i] > pos) break; int res = getGrundy(pos - a[i], a, n); s.insert(res); } return grundy[pos] = getMax(s); } int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); grundy[0] = 0; grundy[k] = getGrundy(k, a, n); if (grundy[k]) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
22
23
22
23
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> posnum(n); for (int i = 0; i < n; i++) cin >> posnum[i]; vector<bool> dp(k + 1, false); for (int stone = 1; stone <= k; stone++) { for (int num = 0; num < n; num++) { if (dp[stone - posnum[num]] == false) { dp[stone] = true; break; } } } if (dp[k] == true) cout << "First"; else cout << "Second"; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> posnum(n); for (int i = 0; i < n; i++) cin >> posnum[i]; vector<bool> dp(k + 1, false); for (int stone = 1; stone <= k; stone++) { for (int num = 0; num < n; num++) { if (stone >= posnum[num] && dp[stone - posnum[num]] == false) { dp[stone] = true; break; } } } if (dp[k] == true) cout << "First"; else cout << "Second"; cout << endl; return 0; }
replace
12
13
12
13
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /* #ifndef ONLINE_JUDGE #define cin f #define cout g ifstream cin("a.in"); ofstream cout("a.out"); #endif */ int n, k, v[103]; bool viz[1 << 17]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> v[i]; for (int i = 0; i <= k; ++i) if (!viz[i]) for (int j = 1; j <= n; ++j) viz[i + v[j]] = 1; if (viz[k]) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> using namespace std; /* #ifndef ONLINE_JUDGE #define cin f #define cout g ifstream cin("a.in"); ofstream cout("a.out"); #endif */ int n, k, v[103]; bool viz[1 << 17]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> v[i]; for (int i = 0; i <= k; ++i) if (!viz[i]) for (int j = 1; j <= n; ++j) viz[min(i + v[j], k + 1)] = 1; if (viz[k]) cout << "First"; else cout << "Second"; return 0; }
replace
22
23
22
23
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; //************** StrAnge.R ********************* #define ll long long int #define ull unsigned long long #define ld long double #define lll __int128 #define vi vector<int> #define vl vector<ll> #define vvi vector<vector<int>> #define pii pair<int, int> #define piii pair<int, pair<int, int>> #define pll pair<ll, ll> #define vii vector<pii> #define min_pq priority_queue<int, vector<int>, greater<int>> #define sz(v) ((int)(v).size()) #define all(s) s.begin(), s.end() #define allr(s) s.rbegin(), s.rend() #define unq(c) (sort(all(c)), c.resize(distance(c.begin(), unique(all(c))))) #define get_pos(c, x) (lower_bound(all(c), x) - c.begin()) #define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a)) #define MS0(v) memset((v), 0, sizeof((v))) #define MS1(v) memset((v), -1, sizeof((v))) #define LEN(v) strlen(v) #define MP make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define sc scanf #define pf printf #define endl "\n" #define LL \ ({ \ ll __LL; \ scanf("%lld", &__LL); \ __LL; \ }) #define II \ ({ \ int __II; \ scanf("%d", &__II); \ __II; \ }) #define CC \ ({ \ char __CC; \ scanf("%c", &__CC); \ __CC; \ }) #define DD \ ({ \ double __DD; \ scanf("%lf", &__DD); \ __DD; \ }) #define intmx INT_MAX #define llmx 1llu << 61 #define PI 3.14159265358979323846264338327950L #define MOD 1000000007 #define MAX 100010 #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a) * ((b) / gcd(a, b))) #define shuffle(v) (random_shuffle(all(v))) #define min_ele(v) (*min_element(all(v))) #define max_ele(v) (*max_element(all(v))) #define is_equal(x, y) (abs(x - y) < eps) #define cnt_ele(v, x) (count(all(v), x)) #define sum_ele(v) (accumulate(all(v), 0)) #define pro_ele(v) (accumulate(all(v), 1, multiplies<int>())) #define init_range(v, x) (iota(all(v), x)) #define TEST_CASE \ int ___T; \ scanf("%d", &___T); \ for (int cs = 1; cs <= ___T; cs++) #define PRINT_CASE printf("Case %d: ", cs) #define PRINT_CASEN printf("Case %d:\n", cs) #define vpf(v, len) \ for (int ix = 0; ix < len; ix++) { \ pf("%d", v[ix]); \ if (ix != len - 1) \ pf(" "); \ else \ pf("\n"); \ } #define vsc(v, len) \ for (int ix = 0; ix < len; ix++) \ scanf("%d", &v[ix]); #define FOR(i, a, b, stp) for (int i = (a); i <= (b); i += stp) #define ROF(i, a, b, stp) for (int i = (a); i >= (b); i -= stp) template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } inline ll exp(ll a, ll p) { if (p == 0) return 1; ll x = exp(a, p / 2) % MOD; x = (x * x) % MOD; if (p & 1) x = (x * (a % MOD)) % MOD; return x; } inline int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } inline int sub(int a, int b) { a -= b; if (a < MOD) a += MOD; return a; } inline int multi(ll a, ll b) { a *= b; if (a >= MOD) a %= MOD; return a; } inline int on_bit(int N, int pos) { return N = N | (1 << pos); } inline int off_bit(int N, int pos) { return N = N & ~(1 << pos); } inline bool check_bit(ll N, int pos) { return (bool)(N & (1 << pos)); } #define on_bit_cnt(x) (__builtin_popcount(x)) #define start_clock clock_t tStart = clock() #define end_clock \ printf("\n>>Runtime: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fileio \ freopen("in.txt", "r", stdin); \ freopen("out.txt", "w", stdout) //******************* my code starts here ********************************** int n, k; int ar[105]; int dp[100005][5]; int solve(int stones, int player) { if (player) { int ret = 0; for (int i = 0; i < n; ++i) { if (ar[i] <= stones) { if (solve(stones - ar[i], player ^ 1) == 0) { ret = 1; } } } return dp[stones][player] = ret; } else { int ret = 0; for (int i = 0; i < n; ++i) { if (ar[i] <= stones) { if (solve(stones - ar[i], player ^ 1) == 0) { ret = 1; } } } return dp[stones][player] = ret; } } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> ar[i]; MS1(dp); if (solve(k, 1)) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> using namespace std; //************** StrAnge.R ********************* #define ll long long int #define ull unsigned long long #define ld long double #define lll __int128 #define vi vector<int> #define vl vector<ll> #define vvi vector<vector<int>> #define pii pair<int, int> #define piii pair<int, pair<int, int>> #define pll pair<ll, ll> #define vii vector<pii> #define min_pq priority_queue<int, vector<int>, greater<int>> #define sz(v) ((int)(v).size()) #define all(s) s.begin(), s.end() #define allr(s) s.rbegin(), s.rend() #define unq(c) (sort(all(c)), c.resize(distance(c.begin(), unique(all(c))))) #define get_pos(c, x) (lower_bound(all(c), x) - c.begin()) #define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a)) #define MS0(v) memset((v), 0, sizeof((v))) #define MS1(v) memset((v), -1, sizeof((v))) #define LEN(v) strlen(v) #define MP make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define sc scanf #define pf printf #define endl "\n" #define LL \ ({ \ ll __LL; \ scanf("%lld", &__LL); \ __LL; \ }) #define II \ ({ \ int __II; \ scanf("%d", &__II); \ __II; \ }) #define CC \ ({ \ char __CC; \ scanf("%c", &__CC); \ __CC; \ }) #define DD \ ({ \ double __DD; \ scanf("%lf", &__DD); \ __DD; \ }) #define intmx INT_MAX #define llmx 1llu << 61 #define PI 3.14159265358979323846264338327950L #define MOD 1000000007 #define MAX 100010 #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a) * ((b) / gcd(a, b))) #define shuffle(v) (random_shuffle(all(v))) #define min_ele(v) (*min_element(all(v))) #define max_ele(v) (*max_element(all(v))) #define is_equal(x, y) (abs(x - y) < eps) #define cnt_ele(v, x) (count(all(v), x)) #define sum_ele(v) (accumulate(all(v), 0)) #define pro_ele(v) (accumulate(all(v), 1, multiplies<int>())) #define init_range(v, x) (iota(all(v), x)) #define TEST_CASE \ int ___T; \ scanf("%d", &___T); \ for (int cs = 1; cs <= ___T; cs++) #define PRINT_CASE printf("Case %d: ", cs) #define PRINT_CASEN printf("Case %d:\n", cs) #define vpf(v, len) \ for (int ix = 0; ix < len; ix++) { \ pf("%d", v[ix]); \ if (ix != len - 1) \ pf(" "); \ else \ pf("\n"); \ } #define vsc(v, len) \ for (int ix = 0; ix < len; ix++) \ scanf("%d", &v[ix]); #define FOR(i, a, b, stp) for (int i = (a); i <= (b); i += stp) #define ROF(i, a, b, stp) for (int i = (a); i >= (b); i -= stp) template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } inline ll exp(ll a, ll p) { if (p == 0) return 1; ll x = exp(a, p / 2) % MOD; x = (x * x) % MOD; if (p & 1) x = (x * (a % MOD)) % MOD; return x; } inline int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } inline int sub(int a, int b) { a -= b; if (a < MOD) a += MOD; return a; } inline int multi(ll a, ll b) { a *= b; if (a >= MOD) a %= MOD; return a; } inline int on_bit(int N, int pos) { return N = N | (1 << pos); } inline int off_bit(int N, int pos) { return N = N & ~(1 << pos); } inline bool check_bit(ll N, int pos) { return (bool)(N & (1 << pos)); } #define on_bit_cnt(x) (__builtin_popcount(x)) #define start_clock clock_t tStart = clock() #define end_clock \ printf("\n>>Runtime: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fileio \ freopen("in.txt", "r", stdin); \ freopen("out.txt", "w", stdout) //******************* my code starts here ********************************** int n, k; int ar[105]; int dp[100005][5]; int solve(int stones, int player) { if (dp[stones][player] != -1) return dp[stones][player]; if (player) { int ret = 0; for (int i = 0; i < n; ++i) { if (ar[i] <= stones) { if (solve(stones - ar[i], player ^ 1) == 0) { ret = 1; } } } return dp[stones][player] = ret; } else { int ret = 0; for (int i = 0; i < n; ++i) { if (ar[i] <= stones) { if (solve(stones - ar[i], player ^ 1) == 0) { ret = 1; } } } return dp[stones][player] = ret; } } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> ar[i]; MS1(dp); if (solve(k, 1)) cout << "First\n"; else cout << "Second\n"; return 0; }
insert
169
169
169
172
TLE
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define NMAX 100005 using namespace std; int n, k, d[NMAX], maxim, a[NMAX]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 0; j <= k; j) { if (d[j] == 0) { for (int i = 1; i <= n; i++) { if (j + a[i] <= k) d[j + a[i]] = 1; } } } if (d[k]) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> #define NMAX 100005 using namespace std; int n, k, d[NMAX], maxim, a[NMAX]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 0; j <= k; j++) { if (d[j] == 0) { for (int i = 1; i <= n; i++) { if (j + a[i] <= k) d[j + a[i]] = 1; } } } if (d[k]) cout << "First"; else cout << "Second"; return 0; }
replace
8
9
8
9
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef vector<ll> vint; typedef vector<vector<ll>> vvint; typedef vector<vector<vector<ll>>> vvvint; typedef vector<string> vstring; typedef vector<vector<string>> vvstring; typedef vector<char> vchar; typedef vector<vector<char>> vvchar; typedef vector<long double> vdouble; typedef vector<vector<long double>> vvdouble; typedef vector<vector<vector<long double>>> vvvdouble; typedef pair<ll, ll> pint; typedef vector<pint> vpint; typedef vector<bool> vbool; #define rep(i, n) for (ll i = 0; i < n; i++) #define repf(i, f, n) for (ll i = f; i < n; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define mp make_pair #define mt make_tuple #define pb push_back #define pf push_front #define fi first #define se second #define ALL(obj) (obj).begin(), (obj).end() #define vmax(vec) *max_element(vec.begin(), vec.end()) #define vmin(vec) *min_element(vec.begin(), vec.end()) #define vsort(vec) sort(vec.begin(), vec.end()) #define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>()) #define MOD 1000000007 const double PI = 3.14159265358979323846; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } ll n, k; ll a[120]; ll dp[(int)1e5 + 10]; int main() { cout << fixed << setprecision(10); cin >> n >> k; rep(i, n) cin >> a[i]; memset(dp, -1, sizeof(dp)); // dp[0] = 0; rep(i, k) { if (dp[i] < 0) dp[i] = 0; rep(j, n) { ll nxt = i + a[j]; chmax(dp[nxt], dp[i] ^ 1); } } if (dp[k]) puts("First"); else puts("Second"); } //
#include <bits/stdc++.h> using namespace std; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef vector<ll> vint; typedef vector<vector<ll>> vvint; typedef vector<vector<vector<ll>>> vvvint; typedef vector<string> vstring; typedef vector<vector<string>> vvstring; typedef vector<char> vchar; typedef vector<vector<char>> vvchar; typedef vector<long double> vdouble; typedef vector<vector<long double>> vvdouble; typedef vector<vector<vector<long double>>> vvvdouble; typedef pair<ll, ll> pint; typedef vector<pint> vpint; typedef vector<bool> vbool; #define rep(i, n) for (ll i = 0; i < n; i++) #define repf(i, f, n) for (ll i = f; i < n; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define mp make_pair #define mt make_tuple #define pb push_back #define pf push_front #define fi first #define se second #define ALL(obj) (obj).begin(), (obj).end() #define vmax(vec) *max_element(vec.begin(), vec.end()) #define vmin(vec) *min_element(vec.begin(), vec.end()) #define vsort(vec) sort(vec.begin(), vec.end()) #define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>()) #define MOD 1000000007 const double PI = 3.14159265358979323846; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } ll n, k; ll a[120]; ll dp[(int)1e5 + 10]; int main() { cout << fixed << setprecision(10); cin >> n >> k; rep(i, n) cin >> a[i]; memset(dp, -1, sizeof(dp)); // dp[0] = 0; rep(i, k) { if (dp[i] < 0) dp[i] = 0; rep(j, n) { ll nxt = i + a[j]; if (nxt > k) continue; chmax(dp[nxt], dp[i] ^ 1); } } if (dp[k]) puts("First"); else puts("Second"); } //
insert
70
70
70
72
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define mp make_pair #define pb push_back #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long LL; typedef pair<LL, LL> P; const LL mod = 1e9 + 7; const LL LINF = 1LL << 62; const int INF = 1000000000; vector<int> a; int memo[100001][2]; int N; int dfs(int k, int c) { if (memo[k][c] == 0) return memo[k][c]; for (int i = 0; i < N; i++) { if (k - a[i] < 0) break; if (c) { if (dfs(k - a[i], c ^ 1)) return memo[k][c] = c; } else { if (!dfs(k - a[i], c ^ 1)) return memo[k][c] = c; } } return memo[k][c] = c ^ 1; } int main() { int K; cin >> N >> K; for (int i = 0; i < N; i++) { int x; cin >> x; a.pb(x); } memset(memo, -1, sizeof(memo)); if (dfs(K, 1)) puts("First"); else puts("Second"); return 0; }
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define mp make_pair #define pb push_back #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long LL; typedef pair<LL, LL> P; const LL mod = 1e9 + 7; const LL LINF = 1LL << 62; const int INF = 1000000000; vector<int> a; int memo[100001][2]; int N; int dfs(int k, int c) { if (~memo[k][c]) return memo[k][c]; for (int i = 0; i < N; i++) { if (k - a[i] < 0) break; if (c) { if (dfs(k - a[i], c ^ 1)) return memo[k][c] = c; } else { if (!dfs(k - a[i], c ^ 1)) return memo[k][c] = c; } } return memo[k][c] = c ^ 1; } int main() { int K; cin >> N >> K; for (int i = 0; i < N; i++) { int x; cin >> x; a.pb(x); } memset(memo, -1, sizeof(memo)); if (dfs(K, 1)) puts("First"); else puts("Second"); return 0; }
replace
20
21
20
21
TLE
p03170
C++
Runtime Error
//__professor_ #include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define lld long double #define pb push_back #define ff first #define ss second #define mk make_pair #define ub upper_bound #define lb lower_bound #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define test \ ll t; \ cin >> t; \ while (t--) #define mod 1000000007 #define inf 1000000000000000001 const double pi = 3.141592653589793238463; using namespace std; int main() { FAST; ll n, k; cin >> n >> k; ll arr[n]; ll min = INT_MAX; for (ll i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] < min) min = arr[i]; } ll ans[k + 1]; for (ll i = 0; i <= k; i++) { ans[i] = -1; } for (ll i = 0; i < n; i++) { ans[arr[i]] = 0; } for (ll i = 0; i < min; i++) { ans[i] = 1; } for (ll i = min + 1; i <= k; i++) { ll f = 0; if (ans[i] == -1) { for (ll j = 0; j < n; j++) { if (ans[i - arr[j]] == 1) { f = 1; break; } } if (f == 1) { ans[i] = 0; } else { ans[i] = 1; } } } if (ans[k] == 0) { cout << "First" << endl; } else { cout << "Second" << endl; } // for(ll i=0;i<=k;i++) // cout<<ans[i]<<" "; return 0; }
//__professor_ #include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define lld long double #define pb push_back #define ff first #define ss second #define mk make_pair #define ub upper_bound #define lb lower_bound #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define test \ ll t; \ cin >> t; \ while (t--) #define mod 1000000007 #define inf 1000000000000000001 const double pi = 3.141592653589793238463; using namespace std; int main() { FAST; ll n, k; cin >> n >> k; ll arr[n]; ll min = INT_MAX; for (ll i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] < min) min = arr[i]; } ll ans[k + 1]; for (ll i = 0; i <= k; i++) { ans[i] = -1; } for (ll i = 0; i < n; i++) { ans[arr[i]] = 0; } for (ll i = 0; i < min; i++) { ans[i] = 1; } for (ll i = min + 1; i <= k; i++) { ll f = 0; if (ans[i] == -1) { for (ll j = 0; j < n; j++) { if ((i - arr[j]) >= 0) { if (ans[i - arr[j]] == 1) { f = 1; break; } } } if (f == 1) { ans[i] = 0; } else { ans[i] = 1; } } } if (ans[k] == 0) { cout << "First" << endl; } else { cout << "Second" << endl; } // for(ll i=0;i<=k;i++) // cout<<ans[i]<<" "; return 0; }
replace
50
53
50
55
0
p03170
C++
Runtime Error
// ######################################## LET'S DO THIS // #########################################################// /* Name: Prathamesh S Motto: To Never Give Up Linkedin: https://www.linkedin.com/in/prathamesh-shendarkar-1a3411172/ */ // ####################################### Start of Macros // ########################################################// #include <bits/stdc++.h> // ######################################### Containers // ###########################################################// #define all(v) v.begin(), v.end() #define mem(n, m) memset(n, m, sizeof(n)) #define pii pair<int, int> #define pll pair<long long, long long> #define sii set<int> #define sll set<long long> #define vii vector<int> #define vll vector<long long> #define mll map<long long, long long> #define ff first #define ss second #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define len(s) s.length() // ########################################### Loops // ##############################################################// #define loopa(i, a, b) for (i = a; i <= b; i++) #define loop(i, n) for (i = 0; i < n; i++) #define pool(i, n) for (i = n - 1; i >= 0; i--) #define poop(i, a, b) for (i = a; i >= b; i--) // ########################################## Debugging // ###########################################################// #define on cout << endl #define o2(a, b) cout << a << " " << b #define debug(a) cout << a << "\n"; #define os cout << " " // ########################################## Ends/Bounds // #########################################################// #define lob lower_bound #define upb upper_bound #define ret return 0 // ########################################## Containers // ##########################################################// #define present(s, x) (s.find(x) != s.end()) #define cpresent(s, x) (find(all(s), x) != s.end()) #define ford(container, it) \ for (__typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define fors(container, it, a, b) \ for (__typeof(container.begin()) it = a; it != b; it++) // ############################################# Size // #############################################################// #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mod 1000000007 #define EPSILON 1e-9 #define PI 3.14159265358979323846 #define inf 999999999999999999 #define siz 100001 #define SIZ 1000001 #define SIZE 200001 // ############################################ typedefs // #########################################################// typedef long long ll; typedef long double ldo; typedef double db; // ########################################## End of Macros // ######################################################// using namespace std; // ######################################### Start of Program // ####################################################// int main() { fastio ll n, k; cin >> n >> k; vector<ll> v(n); vector<ll> dp(k + 1, 0); for (ll i = 0; i < n; i++) { cin >> v[i]; dp[v[i]]++; } // Here I need to biased and make taro win ll mini = *min_element(v.begin(), v.end()); for (ll i = mini + 1; i <= k; i++) { if (dp[i] == 0) { // Here i need to check if my k is making any odd number or not with denom ll flag = 0; for (ll j = 0; j < n; j++) { if (dp[(i - v[j])] % 2 == 0) { dp[i] = dp[(i - v[j])] + 1; // This means first is the winner flag = 1; break; } } if (flag != 1) { dp[i] = dp[i - v[0]] + 1; // That means second is the winner } } } if (dp[k] % 2 == 0) { cout << "Second" << "\n"; } else { cout << "First" << "\n"; } } /* */ // ######################################### End of Program // ######################################################//
// ######################################## LET'S DO THIS // #########################################################// /* Name: Prathamesh S Motto: To Never Give Up Linkedin: https://www.linkedin.com/in/prathamesh-shendarkar-1a3411172/ */ // ####################################### Start of Macros // ########################################################// #include <bits/stdc++.h> // ######################################### Containers // ###########################################################// #define all(v) v.begin(), v.end() #define mem(n, m) memset(n, m, sizeof(n)) #define pii pair<int, int> #define pll pair<long long, long long> #define sii set<int> #define sll set<long long> #define vii vector<int> #define vll vector<long long> #define mll map<long long, long long> #define ff first #define ss second #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define len(s) s.length() // ########################################### Loops // ##############################################################// #define loopa(i, a, b) for (i = a; i <= b; i++) #define loop(i, n) for (i = 0; i < n; i++) #define pool(i, n) for (i = n - 1; i >= 0; i--) #define poop(i, a, b) for (i = a; i >= b; i--) // ########################################## Debugging // ###########################################################// #define on cout << endl #define o2(a, b) cout << a << " " << b #define debug(a) cout << a << "\n"; #define os cout << " " // ########################################## Ends/Bounds // #########################################################// #define lob lower_bound #define upb upper_bound #define ret return 0 // ########################################## Containers // ##########################################################// #define present(s, x) (s.find(x) != s.end()) #define cpresent(s, x) (find(all(s), x) != s.end()) #define ford(container, it) \ for (__typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define fors(container, it, a, b) \ for (__typeof(container.begin()) it = a; it != b; it++) // ############################################# Size // #############################################################// #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mod 1000000007 #define EPSILON 1e-9 #define PI 3.14159265358979323846 #define inf 999999999999999999 #define siz 100001 #define SIZ 1000001 #define SIZE 200001 // ############################################ typedefs // #########################################################// typedef long long ll; typedef long double ldo; typedef double db; // ########################################## End of Macros // ######################################################// using namespace std; // ######################################### Start of Program // ####################################################// int main() { fastio ll n, k; cin >> n >> k; vector<ll> v(n); vector<ll> dp(k + 1, 0); for (ll i = 0; i < n; i++) { cin >> v[i]; dp[v[i]]++; } // Here I need to biased and make taro win ll mini = *min_element(v.begin(), v.end()); for (ll i = mini + 1; i <= k; i++) { if (dp[i] == 0) { // Here i need to check if my k is making any odd number or not with denom ll flag = 0; for (ll j = 0; j < n; j++) { if (i - v[j] > 0 && dp[(i - v[j])] % 2 == 0) { dp[i] = dp[(i - v[j])] + 1; // This means first is the winner flag = 1; break; } } if (flag != 1) { dp[i] = dp[i - v[0]] + 1; // That means second is the winner } } } if (dp[k] % 2 == 0) { cout << "Second" << "\n"; } else { cout << "First" << "\n"; } } /* */ // ######################################### End of Program // ######################################################//
replace
101
102
101
102
0
p03170
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <algorithm> #include <cmath> #include <fstream> #include <map> #include <set> #include <string> #include <vector> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define forl(i, a, n) for (int i = a; i < n; i++) #define rfor(i, n, a) for (int i = n; i >= a; i--) #define ll long long #define ld long double #define pb push_back #define ld long double #define vi vector<int> #define vll vector<long long> #define pi pair<int, int> #define pll pair<long long, long long> #define mp make_pair #define B begin() #define E end() #define S size() #define m9 1000000007 using namespace std; /* string fs(string str1, string str2) { if (str1.length() > str2.length()) swap(str1, str2); string str = ""; int n1 = str1.length(), n2 = str2.length(); int diff = n2 - n1; int carry = 0; for (int i=n1-1; i>=0; i--) { int sum = ((str1[i]-'0') + (str2[i+diff]-'0') + carry); str.push_back(sum%10 + '0'); carry = sum/10; } for (int i=n2-n1-1; i>=0; i--) { int sum = ((str2[i]-'0')+carry); str.push_back(sum%10 + '0'); carry = sum/10; } if (carry) str.push_back(carry+'0'); reverse(str.begin(), str.end()); return str; }*/ ll gcd(ll x, ll y) { if (x == 0) return y; return gcd(y % x, x); } /* ll gcdextended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; int gcd = gcdextended(b%a, a, &x1, &y1); *x = y1 - (b/a) * x1; *y = x1; return gcd; } ///RELATIVE COPRIME ll modinverse(ll a, ll m) { ll x, y; ll g = gcdextended(a, m, &x, &y); if (g != 1) return -1; else { ll res = (x%m + m) % m; return res; } } */ ll powmod(ll x, ll y, ll m) { if (y == 0) return 1; ll p = powmod(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } /// M IS PRIME ll modif(ll x, ll m) { return (powmod(x, m - 2, m)); } bool fa(vll &x, vll &y) { return x[0] < y[0]; } bool fa1(vll &x, vll &y) { return x[1] < y[1]; } bool f1(pll &x, pll &y) { return x.second < y.second; } bool f2(pll &x, pll &y) { return x.first > y.first; } bool f3(ll &x, ll &y) { return x > y; } #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define pin(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define fck(a) \ cout << a; \ exit(0) #define vvll vector<vector<ll>> #define A(b) b.begin(), b.end() ll dp[3001][3001]; // include<bits/stdc++.h> int main() { fastio; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll n, k; cin >> n >> k; ll b[n]; forl(i, 0, n) cin >> b[i]; ll dp[k + 2]; forl(i, 0, k + 2) dp[i] = 0; dp[0] = -1; forl(i, 1, k + 2) { ll ch = 0; for (auto x : b) { ll y = i - x; if (x < 0) continue; if (dp[y] == -1) { ch++; break; } } if (ch == 0) { dp[i] = -1; } else { dp[i] = 1; } // p2(i,ch); } // pin(dp); if (dp[k] == 1) { cout << "First"; } else cout << "Second"; return 0; } /* ll n; ll s=0;cin>>n; ll b[n];vll t1(3,0); forl(i,0,n){ cin>>b[i];s+=b[i]; t1[b[i]-1]++; } vector<map<vll,ll> > dp; map<vll,ll>temp; temp[t1]++; dp.pb(temp); //pin(t1); ld ans=0;ld p2=temp.S,pt=0; forl(i,0,s){ temp.clear(); for(auto x:dp[i]){ for(auto y:x.first)cout<<y<<" ";cout<<"\t"; forl(t,0,3){ vll r=x.first; if(x.first[t]==0)continue; r[t]--; if(t>0)r[t-1]++; temp[r]++;pt++; } ld z=x.first[0]+x.first[1]+x.first[2]; ld p1=x.second; cout<<p1<<" "<<p2<<"\t"; ld p=p1/p2; ld f=(ld)n/z;f*=p; cout<<n<<" "<<z<<"\t"; p1(f); ans+=f;} dp.pb(temp); cout<<endl; p2=pt;pt=0; } cout<<ans; return 0; } */
#include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <algorithm> #include <cmath> #include <fstream> #include <map> #include <set> #include <string> #include <vector> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define forl(i, a, n) for (int i = a; i < n; i++) #define rfor(i, n, a) for (int i = n; i >= a; i--) #define ll long long #define ld long double #define pb push_back #define ld long double #define vi vector<int> #define vll vector<long long> #define pi pair<int, int> #define pll pair<long long, long long> #define mp make_pair #define B begin() #define E end() #define S size() #define m9 1000000007 using namespace std; /* string fs(string str1, string str2) { if (str1.length() > str2.length()) swap(str1, str2); string str = ""; int n1 = str1.length(), n2 = str2.length(); int diff = n2 - n1; int carry = 0; for (int i=n1-1; i>=0; i--) { int sum = ((str1[i]-'0') + (str2[i+diff]-'0') + carry); str.push_back(sum%10 + '0'); carry = sum/10; } for (int i=n2-n1-1; i>=0; i--) { int sum = ((str2[i]-'0')+carry); str.push_back(sum%10 + '0'); carry = sum/10; } if (carry) str.push_back(carry+'0'); reverse(str.begin(), str.end()); return str; }*/ ll gcd(ll x, ll y) { if (x == 0) return y; return gcd(y % x, x); } /* ll gcdextended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; int gcd = gcdextended(b%a, a, &x1, &y1); *x = y1 - (b/a) * x1; *y = x1; return gcd; } ///RELATIVE COPRIME ll modinverse(ll a, ll m) { ll x, y; ll g = gcdextended(a, m, &x, &y); if (g != 1) return -1; else { ll res = (x%m + m) % m; return res; } } */ ll powmod(ll x, ll y, ll m) { if (y == 0) return 1; ll p = powmod(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } /// M IS PRIME ll modif(ll x, ll m) { return (powmod(x, m - 2, m)); } bool fa(vll &x, vll &y) { return x[0] < y[0]; } bool fa1(vll &x, vll &y) { return x[1] < y[1]; } bool f1(pll &x, pll &y) { return x.second < y.second; } bool f2(pll &x, pll &y) { return x.first > y.first; } bool f3(ll &x, ll &y) { return x > y; } #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define pin(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define fck(a) \ cout << a; \ exit(0) #define vvll vector<vector<ll>> #define A(b) b.begin(), b.end() ll dp[3001][3001]; // include<bits/stdc++.h> int main() { fastio; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll n, k; cin >> n >> k; ll b[n]; forl(i, 0, n) cin >> b[i]; ll dp[k + 2]; forl(i, 0, k + 2) dp[i] = 0; dp[0] = -1; forl(i, 1, k + 2) { ll ch = 0; for (auto x : b) { ll y = i - x; if (y < 0) continue; if (dp[y] == -1) { ch++; break; } } if (ch == 0) { dp[i] = -1; } else { dp[i] = 1; } // p2(i,ch); } // pin(dp); if (dp[k] == 1) { cout << "First"; } else cout << "Second"; return 0; } /* ll n; ll s=0;cin>>n; ll b[n];vll t1(3,0); forl(i,0,n){ cin>>b[i];s+=b[i]; t1[b[i]-1]++; } vector<map<vll,ll> > dp; map<vll,ll>temp; temp[t1]++; dp.pb(temp); //pin(t1); ld ans=0;ld p2=temp.S,pt=0; forl(i,0,s){ temp.clear(); for(auto x:dp[i]){ for(auto y:x.first)cout<<y<<" ";cout<<"\t"; forl(t,0,3){ vll r=x.first; if(x.first[t]==0)continue; r[t]--; if(t>0)r[t-1]++; temp[r]++;pt++; } ld z=x.first[0]+x.first[1]+x.first[2]; ld p1=x.second; cout<<p1<<" "<<p2<<"\t"; ld p=p1/p2; ld f=(ld)n/z;f*=p; cout<<n<<" "<<z<<"\t"; p1(f); ans+=f;} dp.pb(temp); cout<<endl; p2=pt;pt=0; } cout<<ans; return 0; } */
replace
153
154
153
154
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define se second #define fr first #define int long long int #define pb push_back #define inf 1e18 #define all(v) v.begin(), v.end() #define CHAL_BAAP_KO_MT_SIKHA \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 /* Damn Fast:TheFuckinMastermind while(How to solve the Question?){ Read the Question Again!! } do Practise #Motivation::::0/0 */ const int N = 2e2; int dp[N + 1], a[N + 1]; signed main() { CHAL_BAAP_KO_MT_SIKHA int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (i >= a[j]) dp[i] |= (!dp[i - a[j]]); } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; #define se second #define fr first #define int long long int #define pb push_back #define inf 1e18 #define all(v) v.begin(), v.end() #define CHAL_BAAP_KO_MT_SIKHA \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 /* Damn Fast:TheFuckinMastermind while(How to solve the Question?){ Read the Question Again!! } do Practise #Motivation::::0/0 */ const int N = 2e5; int dp[N], a[101]; signed main() { CHAL_BAAP_KO_MT_SIKHA int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (i >= a[j]) dp[i] |= (!dp[i - a[j]]); } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
22
24
22
24
0
p03170
C++
Runtime Error
// #include<bits/stdc++.h> // using namespace std; // const int N = 100000, MAXI = 3, D = 1000; // int main() { // freopen("output.txt", "r", stdin); // freopen("input.txt", "w", stdout); // srand(time(nullptr)); // int tc = 10000, flag = 1; // cout << tc << "\n"; // int n = 1; // while (tc--) // { // n = rand()%N + 1; // cout << n << "\n~\n"; // } // return 0; // } //---------------------------------------------// /* #define int long long #define mod (int)(1e9+9) #define endl '\n' #define MAXI (int)(3e17+10) #define N 200005 */ // /* while(!cin.eof()) */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod (int)(1e9 + 7) #define MAXI (int)(3e17 + 10) #define N 105 #define M 100005 int dp[M]; int n, k, a[N]; // Driver code to test above functions int32_t main() { #ifndef ONLINE_JUDGE // for getting input from inpu.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 0; for (int i = 1; i <= k; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if (i - a[j] >= 0) { if (!dp[i - a[j]]) { dp[i] = 1; break; } } } } if (dp[k]) cout << "First"; else cout << "Second"; return 0; }
// #include<bits/stdc++.h> // using namespace std; // const int N = 100000, MAXI = 3, D = 1000; // int main() { // freopen("output.txt", "r", stdin); // freopen("input.txt", "w", stdout); // srand(time(nullptr)); // int tc = 10000, flag = 1; // cout << tc << "\n"; // int n = 1; // while (tc--) // { // n = rand()%N + 1; // cout << n << "\n~\n"; // } // return 0; // } //---------------------------------------------// /* #define int long long #define mod (int)(1e9+9) #define endl '\n' #define MAXI (int)(3e17+10) #define N 200005 */ // /* while(!cin.eof()) */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod (int)(1e9 + 7) #define MAXI (int)(3e17 + 10) #define N 105 #define M 100005 int dp[M]; int n, k, a[N]; // Driver code to test above functions int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 0; for (int i = 1; i <= k; i++) { dp[i] = 0; for (int j = 0; j < n; j++) { if (i - a[j] >= 0) { if (!dp[i - a[j]]) { dp[i] = 1; break; } } } } if (dp[k]) cout << "First"; else cout << "Second"; return 0; }
delete
49
55
49
49
0
p03170
C++
Time Limit Exceeded
// By Tushar Gautam #pragma GCC optimize("-O2") #include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define memreset(a) memset(a, 0, sizeof(a)) #define testcase(t) \ int t; \ cin >> t; \ while (t--) #define forstl(i, v) for (auto &i : v) #define forn(i, e) for (int i = 0; i < e; i++) #define forsn(i, s, e) for (int i = s; i < e; i++) #define rforn(i, s) for (int i = s; i >= 0; i--) #define rforsn(i, s, e) for (int i = s; i >= e; i--) #define leadzero(a) __builtin_clz(a) // count leading zeroes #define trailzero(a) __builtin_ctz(a) // count trailing zeroes #define bitcount(a) __builtin_popcount(a) // count set bits (add ll) #define ln "\n" #define dbgarr(v, s, e) \ cerr << #v << " = "; \ forsn(i, s, e) cerr << v[i] << ", "; \ cerr << endl #define inputfile freopen("input.txt", "r", stdin) #define outputfile freopen("output.txt", "w", stdout) #define dbg(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) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, args...); } template <typename T1, typename T2> ostream &operator<<(ostream &c, pair<T1, T2> &v) { c << "(" << v.fi << "," << v.se << ")"; return c; } template <template <class...> class TT, class... T> ostream &operator<<(ostream &out, TT<T...> &c) { out << "{ "; forstl(x, c) out << x << " "; out << "}"; return out; } typedef long long int ll; typedef long double ld; typedef pair<ll, ll> p64; typedef pair<int, int> p32; typedef pair<int, p32> p96; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<v32> vv32; typedef vector<v64> vv64; typedef vector<p32> vp32; typedef vector<vp32> vvp32; typedef map<int, int> m32; const int LIM = 1e5 + 5, MOD = 1e9 + 7; int t, n, m, k, x, y; v32 a; v32 dp; int solve(int x) { if (x == 0) return 0; bool poss = 1; forstl(it, a) { if (x >= it) poss &= solve(x - it); } return dp[x] = !poss; } int main() { fastio; cin >> n >> k; a.resize(n); dp.assign(k + 1, -1); forn(i, n) { cin >> a[i]; } auto b = solve(k); if (b) { cout << "First\n"; } else cout << "Second\n"; return 0; }
// By Tushar Gautam #pragma GCC optimize("-O2") #include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define memreset(a) memset(a, 0, sizeof(a)) #define testcase(t) \ int t; \ cin >> t; \ while (t--) #define forstl(i, v) for (auto &i : v) #define forn(i, e) for (int i = 0; i < e; i++) #define forsn(i, s, e) for (int i = s; i < e; i++) #define rforn(i, s) for (int i = s; i >= 0; i--) #define rforsn(i, s, e) for (int i = s; i >= e; i--) #define leadzero(a) __builtin_clz(a) // count leading zeroes #define trailzero(a) __builtin_ctz(a) // count trailing zeroes #define bitcount(a) __builtin_popcount(a) // count set bits (add ll) #define ln "\n" #define dbgarr(v, s, e) \ cerr << #v << " = "; \ forsn(i, s, e) cerr << v[i] << ", "; \ cerr << endl #define inputfile freopen("input.txt", "r", stdin) #define outputfile freopen("output.txt", "w", stdout) #define dbg(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) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << "\t"; err(++it, args...); } template <typename T1, typename T2> ostream &operator<<(ostream &c, pair<T1, T2> &v) { c << "(" << v.fi << "," << v.se << ")"; return c; } template <template <class...> class TT, class... T> ostream &operator<<(ostream &out, TT<T...> &c) { out << "{ "; forstl(x, c) out << x << " "; out << "}"; return out; } typedef long long int ll; typedef long double ld; typedef pair<ll, ll> p64; typedef pair<int, int> p32; typedef pair<int, p32> p96; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<v32> vv32; typedef vector<v64> vv64; typedef vector<p32> vp32; typedef vector<vp32> vvp32; typedef map<int, int> m32; const int LIM = 1e5 + 5, MOD = 1e9 + 7; int t, n, m, k, x, y; v32 a; v32 dp; int solve(int x) { if (x == 0) return 0; if (dp[x] != -1) return dp[x]; bool poss = 1; forstl(it, a) { if (x >= it) poss &= solve(x - it); } return dp[x] = !poss; } int main() { fastio; cin >> n >> k; a.resize(n); dp.assign(k + 1, -1); forn(i, n) { cin >> a[i]; } auto b = solve(k); if (b) { cout << "First\n"; } else cout << "Second\n"; return 0; }
insert
78
78
78
80
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << " "; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define M(X, Y) (((X) + (Y)) >> 1) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LLINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1); template <typename T> T max_self(T &a, T b) { if (a < b) a = b; return a; } template <typename T> T min_self(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; } template <typename T> T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD; } template <typename T> T sub(T x, T y) { return add(x, -y + MOD); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> vector<T> read(vector<T> &v, int n) { v.resize(n); for (auto &x : v) cin >> x; } template <typename T> void trav(vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { cout << v[i]; if (i != (int)v.size() - 1) cout << ' '; } } int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; } int lg2(int x) { return 32 - __builtin_clzll(x) - 1; } int n, k, a[MAXN]; bool dp[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; } dp[0] = false; for (int i = 0; i <= k; ++i) { if (dp[i] == false) { for (int j = 0; j < n; ++j) { dp[i + a[j]] = true; } } } string ans = "First"; if (!dp[k]) ans = "Second"; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define debug(x) cout << #x << ":" << x << " "; #define debugg(x) cout << #x << ":" << x << ' ' << "\n"; #define endl "\n" #define L(X) ((X) << 1) #define R(X) (((X) << 1) | 1) #define M(X, Y) (((X) + (Y)) >> 1) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int MAXN = 1e5 + 5; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long int LLINF = 0x3f3f3f3f3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1); template <typename T> T max_self(T &a, T b) { if (a < b) a = b; return a; } template <typename T> T min_self(T &a, T b) { if (a > b) a = b; return a; } template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; } template <typename T> T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD; } template <typename T> T sub(T x, T y) { return add(x, -y + MOD); } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> vector<T> read(vector<T> &v, int n) { v.resize(n); for (auto &x : v) cin >> x; } template <typename T> void trav(vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { cout << v[i]; if (i != (int)v.size() - 1) cout << ' '; } } int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; } int lg2(int x) { return 32 - __builtin_clzll(x) - 1; } int n, k, a[MAXN]; bool dp[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a[i]; } dp[0] = false; for (int i = 0; i <= k; ++i) { if (dp[i] == false) { for (int j = 0; j < n; ++j) { if (i + a[j] <= k) dp[i + a[j]] = true; } } } string ans = "First"; if (!dp[k]) ans = "Second"; cout << ans << endl; return 0; }
replace
78
79
78
80
0
p03170
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; int const MAXN = 110, MAXK = 110000; int n, k, v[MAXN]; bool dp[MAXN]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 1; i <= k; i++) { bool possible = false; for (int j = 0; j < n && i - v[j] >= 0 && !dp[i]; j++) if (!dp[i - v[j]]) dp[i] = true; } cout << (dp[k] ? "First" : "Second"); }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; int const MAXN = 110, MAXK = 110000; int n, k, v[MAXN]; bool dp[MAXK]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 1; i <= k; i++) { bool possible = false; for (int j = 0; j < n && i - v[j] >= 0 && !dp[i]; j++) if (!dp[i - v[j]]) dp[i] = true; } cout << (dp[k] ? "First" : "Second"); }
replace
5
6
5
6
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using namespace std; #define a_macro(args...) sum(args) #define mp make_pair #define eb emplace_back #define mt make_tuple #define fi first #define se second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef long long ll; const ll mod = 1e9 + 7; typedef tuple<int, int, int> State; // operator< defined typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef double ld; int main(int argc, const char **argv) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int n, k, i; cin >> n >> k; int a[n]; for (i = 0; i < n; ++i) cin >> a[i]; int dp[k + 1], j; memset(dp, 0, sizeof(dp)); for (i = 1; i <= k; ++i) { for (j = 0; j < n; ++j) { if (a[j] > i) continue; if (dp[i - a[j]] == 0) dp[i] = 1; } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; #ifndef LOCAL_DEFINE cerr << "Time elapsed: " << 1e1 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif // LOCAL_DEFINE return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using namespace std; #define a_macro(args...) sum(args) #define mp make_pair #define eb emplace_back #define mt make_tuple #define fi first #define se second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef long long ll; const ll mod = 1e9 + 7; typedef tuple<int, int, int> State; // operator< defined typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef double ld; int main(int argc, const char **argv) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; int n, k, i; cin >> n >> k; int a[n]; for (i = 0; i < n; ++i) cin >> a[i]; int dp[k + 1], j; memset(dp, 0, sizeof(dp)); for (i = 1; i <= k; ++i) { for (j = 0; j < n; ++j) { if (a[j] > i) continue; if (dp[i - a[j]] == 0) dp[i] = 1; } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; #ifndef LOCAL_DEFINE cerr << "Time elapsed: " << 1e1 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif // LOCAL_DEFINE return 0; }
delete
36
42
36
36
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, K; vector<int> a; vector<bool> dp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> K; a.resize(N); dp.resize(K + 1, false); for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i <= K; i++) { for (int j = 0; j < N; j++) { if (dp[i]) { continue; } if (i < a[j]) { continue; } if (!dp[j - a[i]]) { dp[i] = true; } } } (dp[K]) ? cout << "First" : cout << "Second"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, K; vector<int> a; vector<bool> dp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> K; a.resize(N); dp.resize(K + 1, false); for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i <= K; i++) { for (int j = 0; j < N; j++) { if (dp[i]) { continue; } if (i < a[j]) { continue; } if (!dp[i - a[j]]) { dp[i] = true; } } } (dp[K]) ? cout << "First" : cout << "Second"; return 0; }
replace
26
27
26
27
0
p03170
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const int N = 105; int n, k, a[N], dp[N]; int dfs(int x) { if (~dp[x]) return dp[x]; bool win = 0; for (int i = 1; i <= n; ++i) { if (x - a[i] < 0) continue; win |= (dfs(x - a[i]) == 0); } return dp[x] = win; } int main() { memset(dp, -1, sizeof dp); dp[0] = 0; // 0先手败 大于0先手胜 scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); puts(dfs(k) ? "First" : "Second"); // for(int i=1;i<=5;++i) // printf("%d:%d\n",i,dp[i]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const int N = 105, K = 1e5 + 10; int n, k, a[N], dp[K]; int dfs(int x) { if (~dp[x]) return dp[x]; bool win = 0; for (int i = 1; i <= n; ++i) { if (x - a[i] < 0) continue; win |= (dfs(x - a[i]) == 0); } return dp[x] = win; } int main() { memset(dp, -1, sizeof dp); dp[0] = 0; // 0先手败 大于0先手胜 scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); puts(dfs(k) ? "First" : "Second"); // for(int i=1;i<=5;++i) // printf("%d:%d\n",i,dp[i]); return 0; }
replace
6
8
6
8
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int dp[100001][2], a[101], n; // p = {0, 1} : {first, second} int recur(int k, bool p) { if (k < a[0]) return not p; int &ret = dp[k][p]; for (int i = 0; i < n and k - a[i] >= 0; ++i) if (recur(k - a[i], not p) == p) return ret = p; return ret = not p; } int main() { int k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); memset(dp, -1, sizeof dp); cout << (recur(k, 0) == 0 ? "First" : "Second") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100001][2], a[101], n; // p = {0, 1} : {first, second} int recur(int k, bool p) { if (k < a[0]) return not p; int &ret = dp[k][p]; if (ret != -1) return ret; for (int i = 0; i < n and k - a[i] >= 0; ++i) if (recur(k - a[i], not p) == p) return ret = p; return ret = not p; } int main() { int k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); memset(dp, -1, sizeof dp); cout << (recur(k, 0) == 0 ? "First" : "Second") << endl; return 0; }
insert
12
12
12
15
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[100009]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int arr[n + 1]; for (int i = 0; i < n; i++) { cin >> arr[i]; dp[arr[i]] = 1; } for (int i = 0; i < arr[0]; i++) dp[i] = 0; int flag = 0; for (int i = arr[0] + 1; i < k + 1; i++) { flag = 0; for (int j = 0; j < n; j++) { if (dp[i - arr[j]] == 0) { dp[i] = 1; flag = 1; break; } } if (flag == 0) dp[i] = 0; } string ans = (dp[k] == 1 ? "First\n" : "Second\n"); cout << ans; }
#include <bits/stdc++.h> using namespace std; int dp[100009]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int arr[n + 1]; for (int i = 0; i < n; i++) { cin >> arr[i]; dp[arr[i]] = 1; } for (int i = 0; i < arr[0]; i++) dp[i] = 0; int flag = 0; for (int i = arr[0] + 1; i < k + 1; i++) { flag = 0; for (int j = 0; j < n; j++) { if (i - arr[j] >= 0 and dp[i - arr[j]] == 0) { dp[i] = 1; flag = 1; break; } } if (flag == 0) dp[i] = 0; } string ans = (dp[k] == 1 ? "First\n" : "Second\n"); cout << ans; }
replace
20
21
20
21
0
p03170
C++
Runtime Error
// 参考:https://blog.csdn.net/HQG_AC/article/details/85984085 // 记忆化优点:https://blog.csdn.net/u011639256/article/details/29389951 #include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, k; int a[maxn], dp[maxn][2]; // dp[容量][人]记录是否能赢 // 记忆化搜索初始化必须可以实现判断是否记忆 // 记忆化好处:从上往下递归,但是不用吧中途的所有情况都记下来,只需要用到递归到的状态的值 bool dfs(int x, int y) { if (dp[x][y] >= 0) return dp[x][y]; int ans = 0; for (int i = 1; i <= n; i++) { if (x >= a[i]) ans |= !dfs( x - a[i], !y); // 只要后面状态有一个是另一方必输则当前状态此人必赢,公式很妙 } return dp[x][y] = ans; } signed main() { memset(dp, -1, sizeof dp); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; if (dfs(k, 0)) cout << "First" << endl; else cout << "Second" << endl; return 0; }
// 参考:https://blog.csdn.net/HQG_AC/article/details/85984085 // 记忆化优点:https://blog.csdn.net/u011639256/article/details/29389951 #include <bits/stdc++.h> using namespace std; const int maxn = 110; int n, k; int a[maxn], dp[100005][2]; // dp[容量][人]记录是否能赢 // 记忆化搜索初始化必须可以实现判断是否记忆 // 记忆化好处:从上往下递归,但是不用吧中途的所有情况都记下来,只需要用到递归到的状态的值 bool dfs(int x, int y) { if (dp[x][y] >= 0) return dp[x][y]; int ans = 0; for (int i = 1; i <= n; i++) { if (x >= a[i]) ans |= !dfs( x - a[i], !y); // 只要后面状态有一个是另一方必输则当前状态此人必赢,公式很妙 } return dp[x][y] = ans; } signed main() { memset(dp, -1, sizeof dp); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; if (dfs(k, 0)) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
7
8
7
8
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[100000 + 5]; int A[100 + 5]; int main(int argc, char const *argv[]) { int N, K; while (cin >> N >> K) { memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = A[0]; i <= K; i++) { for (int j = 0; j < N; j++) { if (i >= j && dp[i - A[j]] == 0) { dp[i] = 1; break; } else { dp[i] = 0; } } } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100000 + 5]; int A[100 + 5]; int main(int argc, char const *argv[]) { int N, K; while (cin >> N >> K) { memset(dp, 0, sizeof(dp)); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = A[0]; i <= K; i++) { for (int j = 0; j < N; j++) { if (i >= A[j] && dp[i - A[j]] == 0) { dp[i] = 1; break; } else { dp[i] = 0; } } } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } } return 0; }
replace
14
15
14
15
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 107, MAXK = 1e1 + 7; int n, k; int lst[MAXN], dp[MAXK]{-1}; int winner(int rem) { if (dp[rem]) return dp[rem]; bool canwin = false; for (int i = 0; i != n; ++i) if (lst[i] <= rem && winner(rem - lst[i]) == -1) { canwin = true; break; } return dp[rem] = (canwin ? 1 : -1); } int main() { #ifdef LOCAL freopen("data.txt", "r", stdin); #endif scanf("%d%d", &n, &k); for (int i = 0; i != n; ++i) scanf("%d", &lst[i]); puts(winner(k) == 1 ? "First" : "Second"); }
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 107, MAXK = 1e5 + 7; int n, k; int lst[MAXN], dp[MAXK]{-1}; int winner(int rem) { if (dp[rem]) return dp[rem]; bool canwin = false; for (int i = 0; i != n; ++i) if (lst[i] <= rem && winner(rem - lst[i]) == -1) { canwin = true; break; } return dp[rem] = (canwin ? 1 : -1); } int main() { #ifdef LOCAL freopen("data.txt", "r", stdin); #endif scanf("%d%d", &n, &k); for (int i = 0; i != n; ++i) scanf("%d", &lst[i]); puts(winner(k) == 1 ? "First" : "Second"); }
replace
2
3
2
3
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int func(vector<int> arr, int n, int k, int minv) { vector<int> dp(k + 1, 1); for (int i = 0; i < minv; i++) dp[i] = 0; for (int i = minv; i <= k; i++) { for (int p = 0; p < n; p++) { int rem = i - arr[p]; dp[i] = dp[i] & dp[rem]; // if(dp[rem]==0) dp[i]=1; } dp[i] = !dp[i]; } return dp[k]; } int main() { int n, k; cin >> n >> k; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; int minv = *min_element(arr.begin(), arr.end()); int ans = func(arr, n, k, minv); if (ans == 1) cout << " First " << endl; else cout << " Second " << endl; }
#include <bits/stdc++.h> using namespace std; int func(vector<int> arr, int n, int k, int minv) { vector<int> dp(k + 1, 1); for (int i = 0; i < minv; i++) dp[i] = 0; for (int i = minv; i <= k; i++) { for (int p = 0; p < n; p++) { if (arr[p] <= i) { int rem = i - arr[p]; dp[i] = dp[i] & dp[rem]; // if(dp[rem]==0) dp[i]=1; } } dp[i] = !dp[i]; } return dp[k]; } int main() { int n, k; cin >> n >> k; vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; int minv = *min_element(arr.begin(), arr.end()); int ans = func(arr, n, k, minv); if (ans == 1) cout << " First " << endl; else cout << " Second " << endl; }
replace
11
14
11
16
0
p03170
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<bool> dp(n + 1); for (int stone = 0; stone <= k; ++stone) { for (int x : a) { if (stone >= x and dp[stone - x] == false) { dp[stone] = true; } } } cout << (dp[k] == true ? "First" : "Second"); }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<bool> dp(k + 1); for (int stone = 0; stone <= k; ++stone) { for (int x : a) { if (stone >= x and dp[stone - x] == false) { dp[stone] = true; } } } cout << (dp[k] == true ? "First" : "Second"); }
replace
35
36
35
36
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define faster \ cin.tie(0); \ ios_base::sync_with_stdio(0) #define ll long long // # setprecision doubt int n, k; int main() { int temp; cin >> n >> k; vector<int> arr; for (int i = 0; i < n; i++) { cin >> temp; arr.push_back(temp); } sort(arr.begin(), arr.end()); vector<bool> dp(k + 1, 0); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (i < arr[j] < 0) break; if (dp[i - arr[j]] == false) { // found a way to defeat a opponent // so i win dp[i] = true; break; } } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; #define faster \ cin.tie(0); \ ios_base::sync_with_stdio(0) #define ll long long // # setprecision doubt int n, k; int main() { int temp; cin >> n >> k; vector<int> arr; for (int i = 0; i < n; i++) { cin >> temp; arr.push_back(temp); } sort(arr.begin(), arr.end()); vector<bool> dp(k + 1, 0); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (i - arr[j] < 0) break; if (dp[i - arr[j]] == false) { // found a way to defeat a opponent // so i win dp[i] = true; break; } } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
22
23
22
23
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define IOS \ ; \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define MX 110 #define FF \ freopen("input.in", "r", stdin); \ freopen("output.txt", "w", stdout); int dp[MX][2]; int n; int a[MX]; int f(int k, bool turn) { if (k == 0) return 0; if (dp[k][turn] != -1) return dp[k][turn]; int ans = 0; for (int i = 0; i < n; i++) { if (k - a[i] < 0) break; else dp[k][turn] = ans |= !f(k - a[i], !turn); } return ans; } int main() { // FF; IOS; int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; memset(dp, -1, sizeof dp); if (f(k, 0)) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define IOS \ ; \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define MX 100001 #define FF \ freopen("input.in", "r", stdin); \ freopen("output.txt", "w", stdout); int dp[MX][2]; int n; int a[MX]; int f(int k, bool turn) { if (k == 0) return 0; if (dp[k][turn] != -1) return dp[k][turn]; int ans = 0; for (int i = 0; i < n; i++) { if (k - a[i] < 0) break; else dp[k][turn] = ans |= !f(k - a[i], !turn); } return ans; } int main() { // FF; IOS; int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; memset(dp, -1, sizeof dp); if (f(k, 0)) cout << "First"; else cout << "Second"; }
replace
8
9
8
9
0
p03170
C++
Runtime Error
#include <iomanip> #include <iostream> #include <vector> using namespace std; int n, k; vector<int> a; int dp[10010]; // 石がx個残っている場合の勝ち負けを判断、0の場合負け int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; // dp[0] = 0; //残りの石が0個の場合負け for (int i = 0; i <= k; ++i) { for (int j = 0; j < n; ++j) { if (i - a[j] >= 0 && dp[i - a[j]] == 0) { dp[i] = 1; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <iomanip> #include <iostream> #include <vector> using namespace std; int n, k; vector<int> a; int dp[100010]; // 石がx個残っている場合の勝ち負けを判断、0の場合負け int main() { cin >> n >> k; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; // dp[0] = 0; //残りの石が0個の場合負け for (int i = 0; i <= k; ++i) { for (int j = 0; j < n; ++j) { if (i - a[j] >= 0 && dp[i - a[j]] == 0) { dp[i] = 1; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
6
7
6
7
0
p03170
C++
Runtime Error
// #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define mod 998244353 #define fi first #define se second #define pii pair<int, int> #define int long long #define endl '\n' #define pll pair<long long, long long> #define LONGLONG_MAX 100000000000000 using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; long long power(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) { ans = (ans * a) % mod; } a = (a * a) % mod; b >>= 1; } return ans; } int dp[100005]; int fun(int i, int a[], int n) { if (i < 0) return 1; if (i == 0) return 0; if (dp[i] != -1) return dp[i]; int ans = 0; for (int j = 0; j < n; j++) { if (fun(i - j, a, n) == 0) { ans = 1; break; } } return dp[i] = ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } memset(dp, -1, sizeof(dp)); if (fun(k, a, n)) cout << "First"; else cout << "Second"; return 0; }
// #pragma GCC optimize("Ofast") // #pragma GCC optimize ("unroll-loops") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define mod 998244353 #define fi first #define se second #define pii pair<int, int> #define int long long #define endl '\n' #define pll pair<long long, long long> #define LONGLONG_MAX 100000000000000 using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; long long power(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) { ans = (ans * a) % mod; } a = (a * a) % mod; b >>= 1; } return ans; } int dp[100005]; int fun(int i, int a[], int n) { if (i < 0) return 1; if (i == 0) return 0; if (dp[i] != -1) return dp[i]; int ans = 0; for (int j = 0; j < n; j++) { if (fun(i - a[j], a, n) == 0) { ans = 1; break; } } return dp[i] = ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } memset(dp, -1, sizeof(dp)); if (fun(k, a, n)) cout << "First"; else cout << "Second"; return 0; }
replace
40
41
40
41
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const int NM = 1e5; int v[105]; bool dp[NM]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> v[i]; /// dp[i]=1, daca sunt i pietre si primul jucator castiga for (int j = 0; j <= k; j++) for (int i = 1; i <= n; i++) if (!dp[j]) dp[j + v[i]] = 1; cout << (dp[k] ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int NM = 1e5; int v[105]; bool dp[NM]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> v[i]; /// dp[i]=1, daca sunt i pietre si primul jucator castiga for (int j = 0; j <= k; j++) for (int i = 1; i <= n; i++) if (!dp[j] && j + v[i] <= k) dp[j + v[i]] = 1; cout << (dp[k] ? "First" : "Second"); return 0; }
replace
17
18
17
18
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int, int> #define all(x) (x).begin(), (x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // fKreopen("q.cik","w",stdout); int n, k; cin >> n >> k; vector<bool> K(k + 1, false); vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i <= k; i++) { if (K[i] == false) { for (int j = 0; j < n; j++) K[i + arr[j]] = true; } } if (K[k]) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define ii pair<int, int> #define all(x) (x).begin(), (x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // fKreopen("q.cik","w",stdout); int n, k; cin >> n >> k; vector<bool> K(5000000, false); vector<int> arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i <= k; i++) { if (K[i] == false) { for (int j = 0; j < n; j++) K[i + arr[j]] = true; } } if (K[k]) cout << "First"; else cout << "Second"; }
replace
18
19
18
19
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k, dp[105][2]; int a[105]; bool dfs(int k, int t) { if (dp[k][t] >= 0) return dp[k][t]; int ans = 0; for (int i = 1; i <= n; i++) if (k >= a[i]) ans |= !dfs(k - a[i], !t); return dp[k][t] = ans; } int main() { memset(dp, -1, sizeof(dp)); scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); if (dfs(k, 0)) puts("First"); else puts("Second"); }
#include <bits/stdc++.h> using namespace std; int n, k, dp[1000005][2]; int a[10000005]; bool dfs(int k, int t) { if (dp[k][t] >= 0) return dp[k][t]; int ans = 0; for (int i = 1; i <= n; i++) if (k >= a[i]) ans |= !dfs(k - a[i], !t); return dp[k][t] = ans; } int main() { memset(dp, -1, sizeof(dp)); scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); if (dfs(k, 0)) puts("First"); else puts("Second"); }
replace
2
4
2
4
0
p03170
C++
Runtime Error
/* _oo0oo_ o8888888o 88" . "88 (| -_- |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vikash Kumar @ Codechef/codeforces ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include <bits/stdc++.h> #define ll long long int #define ll_MAX LLONG_MAX #define ll_MIN LLONG_MIN #define pi 3.14159265358979323846 #define count_1(n) __builtin_popcountll(n) #define MOD 1000000007 #define MAX 1e9 #define MIN -1e9 #define itoc(c) ((char)(((int)'0') + c)) #define mid(s, e) (s + (e - s) / 2) const int MX = 10010896; const int lmt = 3164; const int N = 10000001; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } else { int g = extgcd(b, a % b, y, x); y -= a / b * x; return g; } } ll modpow(ll a, ll b) { ll res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } bool dp[100005]; inline void solve() { /*<logic>*/ int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; memset(dp, false, sizeof(dp)); for (int stone = 0; stone <= k; stone++) { for (int a : arr) { if (stone >= a && !dp[stone - a]) { dp[stone] = true; break; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; /*</logic>*/ } int main() { cout << fixed << setprecision(12); // freopen("input.txt", "r", stdin); fastio; ll t = 1, tc = 1; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif // cin>>t; while (t--) { solve(); } return 0; }
/* _oo0oo_ o8888888o 88" . "88 (| -_- |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Vikash Kumar @ Codechef/codeforces ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include <bits/stdc++.h> #define ll long long int #define ll_MAX LLONG_MAX #define ll_MIN LLONG_MIN #define pi 3.14159265358979323846 #define count_1(n) __builtin_popcountll(n) #define MOD 1000000007 #define MAX 1e9 #define MIN -1e9 #define itoc(c) ((char)(((int)'0') + c)) #define mid(s, e) (s + (e - s) / 2) const int MX = 10010896; const int lmt = 3164; const int N = 10000001; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } else { int g = extgcd(b, a % b, y, x); y -= a / b * x; return g; } } ll modpow(ll a, ll b) { ll res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } bool dp[100005]; inline void solve() { /*<logic>*/ int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; memset(dp, false, sizeof(dp)); for (int stone = 0; stone <= k; stone++) { for (int a : arr) { if (stone >= a && !dp[stone - a]) { dp[stone] = true; break; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; /*</logic>*/ } int main() { cout << fixed << setprecision(12); // freopen("input.txt", "r", stdin); fastio; ll t = 1, tc = 1; // cin>>t; while (t--) { solve(); } return 0; }
delete
95
98
95
95
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define pll pair<ll, ll> #define F first #define S second #define pb push_back #define ld long double #define vll vector<ll> #define vpll vector<pll> #define ppll pair<pll, ll> ll M = 1000000007; ll MAX = LONG_LONG_MAX; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; ll power(ll a, ll m, ll mod) { ll ans = 1; while (m) { if (m % 2) { ans *= a; ans %= (mod); } a = (a * a) % (mod); m >>= 1; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin>>t; while (t--) { ll n, i, j, k, x = INT_MAX, m, a; cin >> n >> k; vector<ll> v(n); vector<bool> dp(k + 1, 0); for (i = 0; i < n; i++) { cin >> a; v[i] = a; x = min(x, a); dp[a] = 1; } for (i = x + 1; i <= k; i++) { if (dp[i]) continue; for (j = 0; j < n; j++) { if (dp[i - v[j]] == 0) { dp[i] = 1; break; } } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define pll pair<ll, ll> #define F first #define S second #define pb push_back #define ld long double #define vll vector<ll> #define vpll vector<pll> #define ppll pair<pll, ll> ll M = 1000000007; ll MAX = LONG_LONG_MAX; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; ll power(ll a, ll m, ll mod) { ll ans = 1; while (m) { if (m % 2) { ans *= a; ans %= (mod); } a = (a * a) % (mod); m >>= 1; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin>>t; while (t--) { ll n, i, j, k, x = INT_MAX, m, a; cin >> n >> k; vector<ll> v(n); vector<bool> dp(k + 1, 0); for (i = 0; i < n; i++) { cin >> a; v[i] = a; x = min(x, a); dp[a] = 1; } for (i = x + 1; i <= k; i++) { if (dp[i]) continue; for (j = 0; j < n; j++) { if (i - v[j] < 0) break; if (dp[i - v[j]] == 0) { dp[i] = 1; break; } } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; } }
insert
55
55
55
57
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define inf (long long)1e18 using namespace std; int n, k, a[101]; bool dp[100001]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < k; i++) if (!dp[i]) { // losing position for (int j = 0; j < n; j++) dp[i + a[j]] = true; // winning // removing a[j] stones will result in losing position (of opponent) // so you win (first player) } printf(dp[k] ? "First\n" : "Second\n"); return 0; }
#include <bits/stdc++.h> #define inf (long long)1e18 using namespace std; int n, k, a[101]; bool dp[100001]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < k; i++) if (!dp[i]) { // losing position for (int j = 0; j < n; j++) if (i + a[j] <= k) dp[i + a[j]] = true; // winning // removing a[j] stones will result in losing position (of opponent) // so you win (first player) } printf(dp[k] ? "First\n" : "Second\n"); return 0; }
replace
12
13
12
14
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(rng(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(rng(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vs = vector<string>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; typedef vector<pii> vp; typedef vector<tiii> vt; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1 << 30) - 1; const ll INFLL = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } bool dp[11000]; int main() { int n, k; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; for (int i = 1; i <= k; ++i) { for (int j = 0; j < n; ++j) { if (i - a[j] >= 0) dp[i] |= !dp[i - a[j]]; } } if (dp[k]) puts("First"); else puts("Second"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(rng(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(rng(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vs = vector<string>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; typedef vector<pii> vp; typedef vector<tiii> vt; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1 << 30) - 1; const ll INFLL = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } bool dp[110000]; int main() { int n, k; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; for (int i = 1; i <= k; ++i) { for (int j = 0; j < n; ++j) { if (i - a[j] >= 0) dp[i] |= !dp[i - a[j]]; } } if (dp[k]) puts("First"); else puts("Second"); return 0; }
replace
89
90
89
90
0
p03170
C++
Runtime Error
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ signed main() { int N, K; cin >> N >> K; int A[N]; for (int i = 0; i < N; i++) cin >> A[i]; sort(A, A + N); int dp[K + 1]; fill(dp, dp + K + 1, 0); for (int i = 0; i < A[0]; i++) { dp[i] = -1; } for (int i = A[0]; i <= K; i++) { bool lose = true; for (int j = 0; j < N; j++) { if (i - A[j] >= 0 && dp[i - A[j]] == -1) { dp[i] = 1; lose = false; break; } } if (lose) A[i] = -1; } cout << (dp[K] == 1 ? "First" : "Second") << endl; return 0; }
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ signed main() { int N, K; cin >> N >> K; int A[N]; for (int i = 0; i < N; i++) cin >> A[i]; sort(A, A + N); int dp[K + 1]; fill(dp, dp + K + 1, 0); for (int i = 0; i < A[0]; i++) { dp[i] = -1; } for (int i = A[0]; i <= K; i++) { bool lose = true; for (int j = 0; j < N; j++) { if (i - A[j] >= 0 && dp[i - A[j]] == -1) { dp[i] = 1; lose = false; break; } } if (lose) dp[i] = -1; } cout << (dp[K] == 1 ? "First" : "Second") << endl; return 0; }
replace
63
64
63
64
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define rep(i, n) for (ll i = 0; i < n; i++) #define rep1(i, n) for (ll i = 1; i <= n; i++) #define mp make_pair #define F first #define S second #define pf pop_front #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0) typedef long long ll; const ll mod = 1e9 + 7; const ll maxn = 305; const ll inf = 1e9 + 7; ll dp[maxn]; ll n, k; ll a[maxn]; int main() { cin >> n >> k; memset(dp, 0, sizeof(dp)); rep(i, n) cin >> a[i]; for (int i = 0; i <= k; i++) { if (!dp[i]) rep(j, n) { if (i + a[j] <= k) dp[i + a[j]] = 1; } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define rep(i, n) for (ll i = 0; i < n; i++) #define rep1(i, n) for (ll i = 1; i <= n; i++) #define mp make_pair #define F first #define S second #define pf pop_front #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0) typedef long long ll; const ll mod = 1e9 + 7; const ll maxn = 100005; const ll inf = 1e9 + 7; ll dp[maxn]; ll n, k; ll a[maxn]; int main() { cin >> n >> k; memset(dp, 0, sizeof(dp)); rep(i, n) cin >> a[i]; for (int i = 0; i <= k; i++) { if (!dp[i]) rep(j, n) { if (i + a[j] <= k) dp[i + a[j]] = 1; } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; }
replace
14
15
14
15
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int dp[k + 1]; vector<int> v; for (int i = 0; i <= k; i++) dp[i] = 0; for (int i = 1; i <= n; i++) { int last_element; cin >> last_element; v.push_back(last_element); } for (int suppose_sum = 0; suppose_sum <= k; suppose_sum++) { for (int first_chosen : v) // lets us suppose that sum is suppose_sum then if { // first turn is given to firtst palyer(taro) if (!dp[suppose_sum - first_chosen]) // dp[i]=1 if taro wins and 0 if 2nd player wins dp[suppose_sum] = 1; // * first_chosen is the first value chosen by TARO } // we look at all possibilites of first_chosen } // and if for any first value we come to know that taro (dp[k]) ? (cout << "First") : (cout << "Second"); // wins then we update it as 0 bcoz taro is // playing optimally return 0; }
#include <bits/stdc++.h> #define ll long long int const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int dp[k + 1]; vector<int> v; for (int i = 0; i <= k; i++) dp[i] = 0; for (int i = 1; i <= n; i++) { int last_element; cin >> last_element; v.push_back(last_element); } for (int suppose_sum = 0; suppose_sum <= k; suppose_sum++) { for (int first_chosen : v) // lets us suppose that sum is suppose_sum then if { // first turn is given to firtst palyer(taro) if (suppose_sum >= first_chosen && !dp[suppose_sum - first_chosen]) // dp[i]=1 if taro wins and 0 if 2nd player wins dp[suppose_sum] = 1; // * first_chosen is the first value chosen by TARO } // we look at all possibilites of first_chosen } // and if for any first value we come to know that taro (dp[k]) ? (cout << "First") : (cout << "Second"); // wins then we update it as 0 bcoz taro is // playing optimally return 0; }
replace
22
23
22
24
0
p03170
C++
Runtime Error
#include <iostream> using namespace std; const int N(109); int n, m, k, ans; int a[N]; int f[N][2]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i <= k; i++) { for (int j = 0; j < 2; j++) { for (int l = 1; l <= n; l++) { if (i >= a[l] && !f[i - a[l]][!j]) { f[i][j] = 1; } } } } if (f[k][0]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <iostream> using namespace std; const int N(109); int n, m, k, ans; int a[N]; int f[100005][2]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i <= k; i++) { for (int j = 0; j < 2; j++) { for (int l = 1; l <= n; l++) { if (i >= a[l] && !f[i - a[l]][!j]) { f[i][j] = 1; } } } } if (f[k][0]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
8
9
8
9
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sf(n) scanf("%lld", &n) #define sff(n, m) scanf("%lld %lld", &n, &m) #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PLL pair<ll, ll> #define mod 1000000007 #define mx 1000002 #define FILE freopen("input.txt", "r", stdin) ll n; ll a[102]; ll dp[102]; ll F(ll x) { if (dp[x] != -1) return dp[x]; ll ret = 0; for (ll i = 1; i <= n; i++) { if (a[i] <= x) ret = ret | F(x - a[i]); } return dp[x] = !ret; } int main() { ll k; sff(n, k); for (ll i = 1; i <= n; i++) { sf(a[i]); } memset(dp, -1, sizeof dp); if (!F(k)) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sf(n) scanf("%lld", &n) #define sff(n, m) scanf("%lld %lld", &n, &m) #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PLL pair<ll, ll> #define mod 1000000007 #define mx 1000002 #define FILE freopen("input.txt", "r", stdin) ll n; ll a[102]; ll dp[mx]; ll F(ll x) { if (dp[x] != -1) return dp[x]; ll ret = 0; for (ll i = 1; i <= n; i++) { if (a[i] <= x) ret = ret | F(x - a[i]); } return dp[x] = !ret; } int main() { ll k; sff(n, k); for (ll i = 1; i <= n; i++) { sf(a[i]); } memset(dp, -1, sizeof dp); if (!F(k)) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
16
17
16
17
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; int a[100]; int dp[100001][2]; // dp[number of remain stone][player id] = winner // {player id : {First: 0, Second: 1}} // {winner : {0: First, 1: Second, -1: unknown}} int dfs(int stones, int player) { if (dp[stones][player] != -1) return dp[stones][player]; bool win = false; for (int i = 0; i < n && (!win); i++) { if (dfs(stones - a[i], (player + 1) % 2) == player) win = true; } if (win) dp[stones][player] = player; else dp[stones][player] = (player + 1) % 2; return dp[stones][player]; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= k; i++) { dp[i][0] = -1; dp[i][1] = -1; } for (int i = 0; i < a[0]; i++) { dp[i][0] = 1; dp[i][1] = 0; } cout << (dfs(k, 0) == 0 ? "First" : "Second") << endl; }
#include <bits/stdc++.h> using namespace std; int n, k; int a[100]; int dp[100001][2]; // dp[number of remain stone][player id] = winner // {player id : {First: 0, Second: 1}} // {winner : {0: First, 1: Second, -1: unknown}} int dfs(int stones, int player) { if (dp[stones][player] != -1) return dp[stones][player]; bool win = false; for (int i = 0; i < n && (!win); i++) { if (stones - a[i] >= 0) { if (dfs(stones - a[i], (player + 1) % 2) == player) win = true; } } if (win) dp[stones][player] = player; else dp[stones][player] = (player + 1) % 2; return dp[stones][player]; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= k; i++) { dp[i][0] = -1; dp[i][1] = -1; } for (int i = 0; i < a[0]; i++) { dp[i][0] = 1; dp[i][1] = 0; } cout << (dfs(k, 0) == 0 ? "First" : "Second") << endl; }
replace
14
16
14
18
0
p03170
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int n, k; int a[110]; bool f[10010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= k; ++i) for (int j = 1; j <= n && a[j] <= i; ++j) if (!f[i - a[j]]) { f[i] = 1; break; } printf(f[k] ? "First" : "Second"); return 0; }
#include <cstdio> #include <iostream> using namespace std; int n, k; int a[110]; bool f[100010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= k; ++i) for (int j = 1; j <= n && a[j] <= i; ++j) if (!f[i - a[j]]) { f[i] = 1; break; } printf(f[k] ? "First" : "Second"); return 0; }
replace
7
8
7
8
0
p03170
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <iostream> #include <map> #include <math.h> #include <stack> #include <string.h> #include <unordered_map> #include <vector> using namespace std; const int INF = 1e9; #define ll long long #define int ll #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define testcase \ int t; \ cin >> t; \ while (t--) #define pb push_back #define endl "\n" #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(x, y, z, w) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #w << ": " << w << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(a) int((a).size()) #define pii pair<int, int> #define fi first #define se second #define ld long double #define vii vector<int> #define all(v) v.begin(), v.end() #define prec(n) fixed << setprecision(n) const int MOD = (int)1e9 + 7; const int MOD2 = 1007681537; const ll LINF = (ll)1e18; const ld PI = acos((ld)-1); const ld EPS = 1e-12; inline ll gcd(ll a, ll b) { ll r; while (b) { r = a % b; a = b; b = r; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll fpow(ll n, ll k, int p = MOD) { ll r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; } template <class T> inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; } inline void addmod(int &a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int &a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; } inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } template <class T> inline void get_arr(T arr[], int n) { for (int i = 0; i < n; i++) cin >> arr[i]; } template <class T> inline void print_arr(T arr[], int n) { for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } int32_t main() { int n, k; cin >> n >> k; int arr[n]; get_arr(arr, n); vector<bool> dp(n + 1); for (int i = 0; i <= k; i++) { for (int j = 0; j < n; j++) { if (i - arr[j] >= 0 && !dp[i - arr[j]]) { dp[i] = true; } } } cout << (dp[k] ? "First" : "Second"); }
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <iostream> #include <map> #include <math.h> #include <stack> #include <string.h> #include <unordered_map> #include <vector> using namespace std; const int INF = 1e9; #define ll long long #define int ll #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define testcase \ int t; \ cin >> t; \ while (t--) #define pb push_back #define endl "\n" #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(x, y, z, w) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #w << ": " << w << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(a) int((a).size()) #define pii pair<int, int> #define fi first #define se second #define ld long double #define vii vector<int> #define all(v) v.begin(), v.end() #define prec(n) fixed << setprecision(n) const int MOD = (int)1e9 + 7; const int MOD2 = 1007681537; const ll LINF = (ll)1e18; const ld PI = acos((ld)-1); const ld EPS = 1e-12; inline ll gcd(ll a, ll b) { ll r; while (b) { r = a % b; a = b; b = r; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll fpow(ll n, ll k, int p = MOD) { ll r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; } template <class T> inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; } inline void addmod(int &a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int &a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; } inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } template <class T> inline void get_arr(T arr[], int n) { for (int i = 0; i < n; i++) cin >> arr[i]; } template <class T> inline void print_arr(T arr[], int n) { for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } int32_t main() { int n, k; cin >> n >> k; int arr[n]; get_arr(arr, n); vector<bool> dp(k + 1); for (int i = 0; i <= k; i++) { for (int j = 0; j < n; j++) { if (i - arr[j] >= 0 && !dp[i - arr[j]]) { dp[i] = true; } } } cout << (dp[k] ? "First" : "Second"); }
replace
100
101
100
101
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define db1(x) cout << #x << "=" << x << '\n' #define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n' #define db3(x, y, z) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << '\n' #define db4(x, y, z, w) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << "," << #w << "=" << w << '\n' #define sz(a) int((a).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin, (x).rend() #define PR(a, n) \ { \ cout << #a << "="; \ for (int __ = 0; __ < n; __++) \ cout << a[__] << ' '; \ cout << "\n"; \ } using namespace std; using ll = unsigned long long; #define int ll signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> v(n); for (int &i : v) cin >> i; vector<bool> dp(k + 1); sort(v.begin(), v.end()); int m = v.front(); if (k < m) cout << "Second"; else { for (int i = 0; i < m; ++i) dp[i] = false; dp[m] = true; for (int i = m + 1; i <= k; ++i) { for (int x : v) { if (i - x < 0) { break; } if (!dp[i - x]) { dp[i] = true; break; } } } if (dp[k]) { cout << "First"; } else { cout << "Second"; } } return 0; }
#include <bits/stdc++.h> #define db1(x) cout << #x << "=" << x << '\n' #define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n' #define db3(x, y, z) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << '\n' #define db4(x, y, z, w) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << "," << #w << "=" << w << '\n' #define sz(a) int((a).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin, (x).rend() #define PR(a, n) \ { \ cout << #a << "="; \ for (int __ = 0; __ < n; __++) \ cout << a[__] << ' '; \ cout << "\n"; \ } using namespace std; using ll = long long; #define int ll signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> v(n); for (int &i : v) cin >> i; vector<bool> dp(k + 1); sort(v.begin(), v.end()); int m = v.front(); if (k < m) cout << "Second"; else { for (int i = 0; i < m; ++i) dp[i] = false; dp[m] = true; for (int i = m + 1; i <= k; ++i) { for (int x : v) { if (i - x < 0) { break; } if (!dp[i - x]) { dp[i] = true; break; } } } if (dp[k]) { cout << "First"; } else { cout << "Second"; } } return 0; }
replace
21
22
21
22
0
p03170
C++
Runtime Error
#include "bits/stdc++.h" #include <random> using namespace std; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } const lint MOD = 1e9 + 7, INF = 1e18; lint dp[100001]; lint N, K, arr[100]; lint mex(lint curr) { set<lint> st; REP(i, N) { if (curr - arr[i] < 0) continue; if (dp[curr - arr[i]] == INF) continue; st.insert(dp[curr - arr[i]]); } REP(i, N) { if (st.find(i) == st.end()) { return i; } } } int main() { cin >> N >> K; REP(i, N) { cin >> arr[i]; } REP(i, K + 1) dp[i] = INF; REP(i, K + 1) { if (i < arr[0]) dp[i] = 0; else dp[i] = mex(i); } if (dp[K] == 0) cout << "Second" << endl; else cout << "First" << endl; }
#include "bits/stdc++.h" #include <random> using namespace std; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } const lint MOD = 1e9 + 7, INF = 1e18; lint dp[100001]; lint N, K, arr[100]; lint mex(lint curr) { set<lint> st; REP(i, N) { if (curr - arr[i] < 0) continue; if (dp[curr - arr[i]] == INF) continue; st.insert(dp[curr - arr[i]]); } REP(i, N + 1) { if (st.find(i) == st.end()) { return i; } } } int main() { cin >> N >> K; REP(i, N) { cin >> arr[i]; } REP(i, K + 1) dp[i] = INF; REP(i, K + 1) { if (i < arr[0]) dp[i] = 0; else dp[i] = mex(i); } if (dp[K] == 0) cout << "Second" << endl; else cout << "First" << endl; }
replace
51
52
51
52
0
p03170
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define PIGRECO 3.141592653589793 #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " /////////////////////////////////////////////////////////////////////////// //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// /////////////////////////////////////////////////////////////////////////// #define int long long int32_t main() { ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, k; cin >> n >> k; vector<int> a(n); vector<int> dp(k + 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= k; i++) { for (auto x : a) { if (i >= x) { if (dp[i - x] == 0) { dp[i] = 1; } } } } cout << ((dp[k]) ? "First" : "Second") << endl; }
#include "bits/stdc++.h" using namespace std; #define PIGRECO 3.141592653589793 #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " /////////////////////////////////////////////////////////////////////////// //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// /////////////////////////////////////////////////////////////////////////// #define int long long int32_t main() { ios::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, k; cin >> n >> k; vector<int> a(n); vector<int> dp(k + 1); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= k; i++) { for (auto x : a) { if (i >= x) { if (dp[i - x] == 0) { dp[i] = 1; } } } } cout << ((dp[k]) ? "First" : "Second") << endl; }
replace
54
55
54
55
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long unsigned int ll; // definition {{{ 1 // scaning {{{ 2 #define Scd(x) scanf("%d", &x) #define Scd2(x, y) scanf("%d%d", &x, &y) #define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define Scll(x) scanf("%llu", &x) #define Scll2(x, y) scanf("%llu%llu", &x, &y) #define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z) #define Scc(c) scanf("%c", &c); #define Scs(s) scanf("%s", s); #define Scstr(s) scanf("%s", &s); // }}} 2 // constants {{{ 2 #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) // }}} 2 // systems {{{ 2 #define Rep(x, y) for (int x = 0; x < y; x++) #define Repe(x, y, z) for (int x = z; x < y; x++) // }}} 2 // output {{{ 2 #define YesNo(a) (a) ? printf("Yes\n") : printf("No\n"); // }}} 2 // }}} 1 int main() { int N, K, a[102]; Scd2(N, K); Rep(i, N) Scd(a[i]); int dp[100002] = {}; Rep(i, K + 1) { if (dp[i] == 0) { Rep(j, N) { dp[i + a[j]] = 1; } } } printf(dp[K] ? "First" : "Second"); printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long unsigned int ll; // definition {{{ 1 // scaning {{{ 2 #define Scd(x) scanf("%d", &x) #define Scd2(x, y) scanf("%d%d", &x, &y) #define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define Scll(x) scanf("%llu", &x) #define Scll2(x, y) scanf("%llu%llu", &x, &y) #define Scll3(x, y, z) scanf("%llu%llu%llu", &x, &y, &z) #define Scc(c) scanf("%c", &c); #define Scs(s) scanf("%s", s); #define Scstr(s) scanf("%s", &s); // }}} 2 // constants {{{ 2 #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) // }}} 2 // systems {{{ 2 #define Rep(x, y) for (int x = 0; x < y; x++) #define Repe(x, y, z) for (int x = z; x < y; x++) // }}} 2 // output {{{ 2 #define YesNo(a) (a) ? printf("Yes\n") : printf("No\n"); // }}} 2 // }}} 1 int main() { int N, K, a[102]; Scd2(N, K); Rep(i, N) Scd(a[i]); int dp[200002] = {}; Rep(i, K + 1) { if (dp[i] == 0) { Rep(j, N) { dp[i + a[j]] = 1; } } } printf(dp[K] ? "First" : "Second"); printf("\n"); return 0; }
replace
43
44
43
44
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long int dp[k + 1]; dp[0] = 0; for (int i = 1; i <= k; i++) { if (i < a[0]) dp[i] = 0; for (int j = 0; j <= n; j++) { if (j == n) { dp[i] = 0; break; } if (!dp[i - a[j]]) { dp[i] = 1; break; } } } if (dp[k] == 1) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long int dp[k + 1]; dp[0] = 0; for (int i = 1; i <= k; i++) { if (i < a[0]) dp[i] = 0; else { for (int j = 0; j <= n; j++) { if (j == n) { dp[i] = 0; break; } if (i >= a[j]) { if (!dp[i - a[j]]) { dp[i] = 1; break; } } else break; } } } if (dp[k] == 1) cout << "First"; else cout << "Second"; }
replace
15
23
15
28
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define FOR(v, a, b) for (int v = (a); v < (b); ++v) #define FORE(v, a, b) for (int v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for (int v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define ITR(it, c) for (auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for (auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c, x) ((c).find(x) != (c).end()) #define LLI long long int #define fst first #define snd second #ifdef DEBUG #include <boost/core/demangle.hpp> #define dump(x) \ cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" \ << boost::core::demangle(typeid(x).name()) << "\e[37m" \ << " " << (#x) << " = " << (x) << "\e[m" << endl; #else #define dump(x) #endif using namespace std; template <typename T> using V = vector<T>; template <typename T, typename U> using P = pair<T, U>; template <typename I> void join(ostream &ost, I s, I t, string d = " ") { for (auto i = s; i != t; ++i) { if (i != s) ost << d; ost << *i; } ost << endl; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &a : v) is >> a; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; ITR(i, v) { if (i != v.begin()) os << ","; os << *i; } os << "}"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } bool dp[2][101000]; bool visit[2][101000]; bool rec(bool p, int k, vector<int> &a) { if (k < 0) return p; if (visit[p][k]) return dp[p][k]; for (auto x : a) { if (rec(!p, k - x, a) == p) { return dp[p][k] = p; } } return dp[p][k] = !p; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> a(N); cin >> a; if (rec(true, K, a)) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> #define FOR(v, a, b) for (int v = (a); v < (b); ++v) #define FORE(v, a, b) for (int v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for (int v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define ITR(it, c) for (auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for (auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c, x) ((c).find(x) != (c).end()) #define LLI long long int #define fst first #define snd second #ifdef DEBUG #include <boost/core/demangle.hpp> #define dump(x) \ cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" \ << boost::core::demangle(typeid(x).name()) << "\e[37m" \ << " " << (#x) << " = " << (x) << "\e[m" << endl; #else #define dump(x) #endif using namespace std; template <typename T> using V = vector<T>; template <typename T, typename U> using P = pair<T, U>; template <typename I> void join(ostream &ost, I s, I t, string d = " ") { for (auto i = s; i != t; ++i) { if (i != s) ost << d; ost << *i; } ost << endl; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &a : v) is >> a; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << "{"; ITR(i, v) { if (i != v.begin()) os << ","; os << *i; } os << "}"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } bool dp[2][101000]; bool visit[2][101000]; bool rec(bool p, int k, vector<int> &a) { if (k < 0) return p; if (visit[p][k]) return dp[p][k]; visit[p][k] = true; for (auto x : a) { if (rec(!p, k - x, a) == p) { return dp[p][k] = p; } } return dp[p][k] = !p; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> a(N); cin >> a; if (rec(true, K, a)) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
insert
71
71
71
72
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define taskname "" #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define for0(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef vector<cd> vcd; typedef vector<int> vi; template <class T> using v2d = vector<vector<T>>; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int maxN = 1e2 + 10; const int maxK = 1e5 + 10; int n, k; int a[maxN]; bool dp[maxK]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for1(i, n) { cin >> a[i]; } for0(i, k) { for1(j, n) { dp[i + a[j]] |= !dp[i]; } } if (dp[k]) { cout << "First"; } else { cout << "Second"; } return 0; }
#include <bits/stdc++.h> #define taskname "" #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define for0(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef vector<cd> vcd; typedef vector<int> vi; template <class T> using v2d = vector<vector<T>>; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int maxN = 1e2 + 10; const int maxK = 1e5 + 10; int n, k; int a[maxN]; bool dp[maxK]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for1(i, n) { cin >> a[i]; } for0(i, k) { for1(j, n) { if (i + a[j] <= k) { dp[i + a[j]] |= !dp[i]; } } } if (dp[k]) { cout << "First"; } else { cout << "Second"; } return 0; }
replace
42
43
42
47
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, imin = 0; int minn = INT_MAX; int maxx = INT_MIN; cin >> n >> k; int dp[k + 1]; int arr[n]; for (i = 0; i <= k; i++) { dp[i] = 1; } for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] < minn) { imin = i; minn = arr[i]; } dp[arr[i]] = 0; } for (i = imin + 1; i <= k; i++) { if (dp[i] != 0) { for (j = 0; j < n; j++) { if (arr[j] >= i && dp[i - arr[j]] == 1) { dp[i] = 0; break; } } } } if (dp[k] == 0) { cout << "First"; } else { cout << "Second"; } }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n, imin = 0; int minn = INT_MAX; int maxx = INT_MIN; cin >> n >> k; int dp[k + 1]; int arr[n]; for (i = 0; i <= k; i++) { dp[i] = 1; } for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] < minn) { imin = i; minn = arr[i]; } dp[arr[i]] = 0; } for (i = imin + 1; i <= k; i++) { if (dp[i] != 0) { for (j = 0; j < n; j++) { if (i >= arr[j] && dp[i - arr[j]] == 1) { dp[i] = 0; break; } } } } if (dp[k] == 0) { cout << "First"; } else { cout << "Second"; } }
replace
23
24
23
24
0
p03170
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { int n, k; cin >> n >> k; vector<bool> dp(k + 1, false); vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; dp[a[i]] = true; } for (int i = 0; i <= k; i++) { bool ok = false; for (int j = 0; j < n; i++) { if (i < a[j]) break; if (!dp[i - a[j]]) { ok = true; break; } } dp[i] = ok; } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { int n, k; cin >> n >> k; vector<bool> dp(k + 1, false); vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; dp[a[i]] = true; } for (int i = 0; i <= k; i++) { bool ok = false; for (int j = 0; j < n; j++) { if (i < a[j]) break; if (!dp[i - a[j]]) { ok = true; break; } } dp[i] = ok; } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
26
27
26
27
0