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> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) const char sp = ' '; const char cmm = ','; const int MOD = 1000000007; using ll = long long; ll mod(ll a, ll b) { return (a % b + b) % b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void Judge(bool b) { b ? Yes() : No(); } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void JUDGE(bool b) { b ? YES() : NO(); } ll powMod(ll b, ll e, ll m) { ll r = 1; while (e > 0) { if (e & 1) r = (r % m) * (b % m) % m; b = (b % m) * (b % m) % m; e >>= 1; } return r; } double distance(ll x1, ll y1, ll x2, ll y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <typename T> void ppp(T n) { cout << n << endl; } bool dp[100001] = {false}; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> 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[i] < 0) break; dp[i] |= !dp[i - a[j]]; } } ppp(dp[k] ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) const char sp = ' '; const char cmm = ','; const int MOD = 1000000007; using ll = long long; ll mod(ll a, ll b) { return (a % b + b) % b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void Judge(bool b) { b ? Yes() : No(); } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void JUDGE(bool b) { b ? YES() : NO(); } ll powMod(ll b, ll e, ll m) { ll r = 1; while (e > 0) { if (e & 1) r = (r % m) * (b % m) % m; b = (b % m) * (b % m) % m; e >>= 1; } return r; } double distance(ll x1, ll y1, ll x2, ll y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <typename T> void ppp(T n) { cout << n << endl; } bool dp[100001] = {false}; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> 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) break; dp[i] |= !dp[i - a[j]]; } } ppp(dp[k] ? "First" : "Second"); return 0; }
replace
52
53
52
53
0
p03170
C++
Runtime Error
#include <cstdint> #include <cstdio> #include <vector> int main() { size_t N, K; scanf("%zu %zu", &N, &K); std::vector<size_t> a(N); for (auto &ai : a) scanf("%zu", &ai); std::vector<size_t> dp(K + 1, 0); for (size_t i = 0; i < K; ++i) for (size_t j = 0; j < N; ++j) { if (dp[i + a[j]] > K) break; if (dp[i] % 2 == 0 || dp[i + a[j]] % 2 == 0) dp[i + a[j]] = dp[i] + 1; } // for (size_t i = 0; i <= K; ++i) // fprintf(stderr, "%zu%c", dp[i], i<K? ' ':'\n'); puts((dp[K] % 2 > 0) ? "First" : "Second"); }
#include <cstdint> #include <cstdio> #include <vector> int main() { size_t N, K; scanf("%zu %zu", &N, &K); std::vector<size_t> a(N); for (auto &ai : a) scanf("%zu", &ai); std::vector<size_t> dp(K + 1, 0); for (size_t i = 0; i < K; ++i) for (size_t j = 0; j < N; ++j) { if (i + a[j] > K) break; if (dp[i] % 2 == 0 || dp[i + a[j]] % 2 == 0) dp[i + a[j]] = dp[i] + 1; } // for (size_t i = 0; i <= K; ++i) // fprintf(stderr, "%zu%c", dp[i], i<K? ' ':'\n'); puts((dp[K] % 2 > 0) ? "First" : "Second"); }
replace
15
16
15
16
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; const ll inf = 1e16; const ll md = 1000000007; bool stone[105]; int main() { int n, k; vi aa; cin >> n >> k; rep(i, n) { int a; cin >> a; aa.push_back(a); } for (int i = 1; i <= k; i++) { for (int a : aa) { if (i - a < 0) continue; if (stone[i - a] == false) { stone[i] = true; break; } } } if (stone[k]) puts("First"); else puts("Second"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; const ll inf = 1e16; const ll md = 1000000007; bool stone[100005]; int main() { int n, k; vi aa; cin >> n >> k; rep(i, n) { int a; cin >> a; aa.push_back(a); } for (int i = 1; i <= k; i++) { for (int a : aa) { if (i - a < 0) continue; if (stone[i - a] == false) { stone[i] = true; break; } } } if (stone[k]) puts("First"); else puts("Second"); return 0; }
replace
11
12
11
12
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; void Fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { Fast(); int n, i, k; cin >> n >> k; int *v = new int[n]; bool **dp = new bool *[k]; for (i = 0; i <= k; i++) dp[i] = new bool[2]; for (i = 0; i < n; i++) cin >> v[i]; for (i = 0; i <= k; i++) { dp[i][0] = 1, dp[i][1] = 0; for (int j = 0; j < n; j++) { if (i - v[j] >= 0) dp[i][1] |= dp[i - v[j]][0]; if (i - v[j] >= 0) dp[i][0] &= dp[i - v[j]][1]; } } cout << (dp[k][1] ? "First" : "Second"); delete[] v; for (i = 0; i <= k; i++) delete[] dp[i]; delete[] dp; }
#include <bits/stdc++.h> using namespace std; void Fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { Fast(); int n, i, k; cin >> n >> k; int *v = new int[n]; bool **dp = new bool *[k + 1]; for (i = 0; i <= k; i++) dp[i] = new bool[2]; for (i = 0; i < n; i++) cin >> v[i]; for (i = 0; i <= k; i++) { dp[i][0] = 1, dp[i][1] = 0; for (int j = 0; j < n; j++) { if (i - v[j] >= 0) dp[i][1] |= dp[i - v[j]][0]; if (i - v[j] >= 0) dp[i][0] &= dp[i - v[j]][1]; } } cout << (dp[k][1] ? "First" : "Second"); delete[] v; for (i = 0; i <= k; i++) delete[] dp[i]; delete[] dp; }
replace
12
13
12
13
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define pii pair<int, int> #define in freopen("input.txt", "r", stdin) #define out freopen("output.txt", "w", stdout) #define rep(i, n) for (long long int(i) = 0; (i) < (n); ++(i)) #define ref(i, a, b) for (long long int(i) = (a); (i) <= (b); ++(i)) #define INF 0xFFFFFF #define endl '\n' const unsigned int mod = 1e9 + 7; const int maxInt = 2147483647; const int mx = 100005; int dp[mx], a[mx]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; ref(i, 1, n) cin >> a[i]; ref(i, 0, k) { if (dp[i] == 0) { ref(j, 1, n) { dp[i + a[j]] = 1; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define pii pair<int, int> #define in freopen("input.txt", "r", stdin) #define out freopen("output.txt", "w", stdout) #define rep(i, n) for (long long int(i) = 0; (i) < (n); ++(i)) #define ref(i, a, b) for (long long int(i) = (a); (i) <= (b); ++(i)) #define INF 0xFFFFFF #define endl '\n' const unsigned int mod = 1e9 + 7; const int maxInt = 2147483647; const int mx = 100005; int dp[2 * mx], a[mx]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; ref(i, 1, n) cin >> a[i]; ref(i, 0, k) { if (dp[i] == 0) { ref(j, 1, n) { dp[i + a[j]] = 1; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
15
16
15
16
0
p03170
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) #define ALL(x) x.begin(), x.end() #define ll long long using lint = long long; typedef pair<int, int> P; const int inf = 1000000007; const int MOD = 1000000007; signed main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<bool> dp(n + 1, false); for (int j = a[0]; j <= k; ++j) { bool flag = false; rep(i, n) { if (j < a[i]) break; if (!dp[j - a[i]]) flag = true; } dp[j] = flag; } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) #define ALL(x) x.begin(), x.end() #define ll long long using lint = long long; typedef pair<int, int> P; const int inf = 1000000007; const int MOD = 1000000007; signed main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vector<bool> dp(k + 1, false); for (int j = a[0]; j <= k; ++j) { bool flag = false; rep(i, n) { if (j < a[i]) break; if (!dp[j - a[i]]) flag = true; } dp[j] = flag; } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
26
27
26
27
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[100001]; int main() { freopen("final_input.txt", "r", stdin); int n; cin >> n; int k; cin >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; dp[arr[i]] = 1; } dp[0] = 0; for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if ((i - arr[j]) < 0) { dp[i] = 0; } else { dp[i] = !dp[i - arr[j]]; if (dp[i] == 1) { break; } } } } if (dp[k] == 1) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; int dp[100001]; int main() { // freopen("final_input.txt", "r", stdin); int n; cin >> n; int k; cin >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; dp[arr[i]] = 1; } dp[0] = 0; for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if ((i - arr[j]) < 0) { dp[i] = 0; } else { dp[i] = !dp[i - arr[j]]; if (dp[i] == 1) { break; } } } } if (dp[k] == 1) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
4
5
4
5
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; void solve(); int main() { // freopen("SNOOKER.inp","r",stdin); // freopen("SNOOKER.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); } using ll = long long; #define endl "\n" #define eb emplace_back #define all(x) x.begin(), x.end() #define what_is(x) cerr << #x << " is :" << (x) << endl #define what_are(x, y) \ cerr << #x << " is : " << (x) << " ; " << #y << " is: " << y << endl #define pii pair<int, int> #define fi first #define se second const int MOD = 1e9 + 7; const int inf = INT_MAX; const int MAX_N = 1e5 + 7; int n, k; bool dp[MAX_N]; int a[107]; void solve() { fill(dp, dp + MAX_N, false); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= k; i++) { if (!dp[i]) for (int j = 1; j <= n; j++) { dp[i + a[j]] = true; } } if (dp[k]) cout << "First"; else cout << "Second"; } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/
#include <bits/stdc++.h> using namespace std; void solve(); int main() { // freopen("SNOOKER.inp","r",stdin); // freopen("SNOOKER.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); } using ll = long long; #define endl "\n" #define eb emplace_back #define all(x) x.begin(), x.end() #define what_is(x) cerr << #x << " is :" << (x) << endl #define what_are(x, y) \ cerr << #x << " is : " << (x) << " ; " << #y << " is: " << y << endl #define pii pair<int, int> #define fi first #define se second const int MOD = 1e9 + 7; const int inf = INT_MAX; const int MAX_N = 1e5 + 7; int n, k; bool dp[MAX_N]; int a[107]; void solve() { fill(dp, dp + MAX_N, false); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= k; i++) { if (!dp[i]) for (int j = 1; j <= n; j++) { dp[min(i + a[j], k + 7)] = true; } } if (dp[k]) cout << "First"; else cout << "Second"; } /*---------------------------------------------------------------------- -----------------------------------------------------------------------*/
replace
40
41
40
41
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FLASH \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false); #define pb push_back #define int long long #define fr(i, a, b) for (int i = a; i < b; i++) #define mod 1000000007 #define FILEIO \ freopen("C:\\Users\\sourav\\Documents\\cp files\\input.txt", "r", stdin); \ freopen("C:\\Users\\sourav\\Documents\\cp files\\output.txt", "w", stdout); #define maxn 1000000 using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; signed main() { #ifndef ONLINE_JUDGE FILEIO #endif FLASH int n, k; cin >> n >> k; int arr[n]; bool verdict[k + 2]; for (int i = 1; i <= k; i++) verdict[i] = false; for (int i = 0; i < n; ++i) { /* code */ cin >> arr[i]; verdict[arr[i]] = true; } // sort(arr , arr + n); int j = 1; while (!verdict[j]) { j++; } for (int i = j + 1; i <= k; i++) { if (!verdict[i]) { int flag = 0; for (int a = 0; a < n; a++) { if (i - arr[a] >= 1) { if (!verdict[i - arr[a]]) { flag = 1; } } } if (flag == 1) verdict[i] = true; } } if (verdict[k] == true) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FLASH \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false); #define pb push_back #define int long long #define fr(i, a, b) for (int i = a; i < b; i++) #define mod 1000000007 #define FILEIO \ freopen("C:\\Users\\sourav\\Documents\\cp files\\input.txt", "r", stdin); \ freopen("C:\\Users\\sourav\\Documents\\cp files\\output.txt", "w", stdout); #define maxn 1000000 using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; signed main() { FLASH int n, k; cin >> n >> k; int arr[n]; bool verdict[k + 2]; for (int i = 1; i <= k; i++) verdict[i] = false; for (int i = 0; i < n; ++i) { /* code */ cin >> arr[i]; verdict[arr[i]] = true; } // sort(arr , arr + n); int j = 1; while (!verdict[j]) { j++; } for (int i = j + 1; i <= k; i++) { if (!verdict[i]) { int flag = 0; for (int a = 0; a < n; a++) { if (i - arr[a] >= 1) { if (!verdict[i - arr[a]]) { flag = 1; } } } if (flag == 1) verdict[i] = true; } } if (verdict[k] == true) cout << "First"; else cout << "Second"; }
replace
25
28
25
26
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <stdio.h> using namespace std; using namespace __gnu_pbds; #define ll long long typedef pair<int, int> pii; #define MOD 1000000007 #define MOD1 998244353 #define ff first #define ss second #define bn cout << "\n" #define o2(a, b) cout << a << " " << b #define sz(a) (a).size() #define o(a) cout << a #define MAX6 1000006 #define int ll #define all(x) x.begin(), x.end() #define ppii pair<int, pii> #define vi vector<int> #define vii vector<pii> #define viii vector<ppii> #define vs vector<string> #define pb push_back #define eb emplace_back #define endl '\n' #define MAX5 300005 #define MAX7 10000007 #define rep(i, a, b) for (__typeof((b)) i = (a); i <= (b); i++) #define nrep(i, b, a) for (__typeof((b)) i = (b); i >= (a); i--) #define mem(a) memset(a, 0, sizeof(a)) #define memneg(a) memset(a, -1, sizeof(a)) // #define se second #define LN 14 #define LIM 22 #define MAX_ALPHA 26 const long long INF64 = 1e18; const ll INF = 1e9; const double PI = acos(-1); #define ld long double typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; inline void max_self(ll &a, ll b) { a = max(a, b); } inline void min_self(ll &a, ll b) { a = min(a, b); } inline void add_self(ll &a, ll b) { a += b; if (a >= MOD) a -= MOD; } inline void sub_self(ll &a, ll b) { a -= b; if (a < 0) a += MOD; } inline int mul(int a, int b) { return (int)((long long)a * b % MOD); } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } int countDigits(int x) { int cnt = 0; while (x) { x /= 10; cnt++; } return cnt; } ll binExpo(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res % MOD; } int sum(int a) { int result = 0; while (a > 0) { result += a % 10; a /= 10; } return result; } // dp[i] --> TRUE if we have i coins remaining and first player wins void solve() { int n, k; cin >> n >> k; vector<int> a(n + 1); rep(i, 0, k - 1) cin >> a[i]; vector<bool> dp(k + 1); dp[0] = false; rep(i, 0, k) { rep(j, 0, n - 1) { if (i - a[j] >= 0 and !dp[i - a[j]]) dp[i] = true; } } cout << (dp[k] == true ? "First" : "Second") << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <stdio.h> using namespace std; using namespace __gnu_pbds; #define ll long long typedef pair<int, int> pii; #define MOD 1000000007 #define MOD1 998244353 #define ff first #define ss second #define bn cout << "\n" #define o2(a, b) cout << a << " " << b #define sz(a) (a).size() #define o(a) cout << a #define MAX6 1000006 #define int ll #define all(x) x.begin(), x.end() #define ppii pair<int, pii> #define vi vector<int> #define vii vector<pii> #define viii vector<ppii> #define vs vector<string> #define pb push_back #define eb emplace_back #define endl '\n' #define MAX5 300005 #define MAX7 10000007 #define rep(i, a, b) for (__typeof((b)) i = (a); i <= (b); i++) #define nrep(i, b, a) for (__typeof((b)) i = (b); i >= (a); i--) #define mem(a) memset(a, 0, sizeof(a)) #define memneg(a) memset(a, -1, sizeof(a)) // #define se second #define LN 14 #define LIM 22 #define MAX_ALPHA 26 const long long INF64 = 1e18; const ll INF = 1e9; const double PI = acos(-1); #define ld long double typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; inline void max_self(ll &a, ll b) { a = max(a, b); } inline void min_self(ll &a, ll b) { a = min(a, b); } inline void add_self(ll &a, ll b) { a += b; if (a >= MOD) a -= MOD; } inline void sub_self(ll &a, ll b) { a -= b; if (a < 0) a += MOD; } inline int mul(int a, int b) { return (int)((long long)a * b % MOD); } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } int countDigits(int x) { int cnt = 0; while (x) { x /= 10; cnt++; } return cnt; } ll binExpo(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res % MOD; } int sum(int a) { int result = 0; while (a > 0) { result += a % 10; a /= 10; } return result; } // dp[i] --> TRUE if we have i coins remaining and first player wins void solve() { int n, k; cin >> n >> k; vector<int> a(n + 1); rep(i, 0, k - 1) cin >> a[i]; vector<bool> dp(k + 1); dp[0] = false; rep(i, 0, k) { rep(j, 0, n - 1) { if (i - a[j] >= 0 and !dp[i - a[j]]) dp[i] = true; } } cout << (dp[k] == true ? "First" : "Second") << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
delete
120
125
120
120
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second int n, k, a[107]; bool dp[100007], vis[100007]; bool solve(int rem) { if (vis[rem]) return dp[rem]; bool ret = false; for (int i = 1; i <= n; i++) { if (a[i] > rem) continue; ret = max((int)ret, solve(rem - a[i]) ^ 1); } dp[rem] = ret; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } cout << (solve(k) ? "First" : "Second"); }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second int n, k, a[107]; bool dp[100007], vis[100007]; bool solve(int rem) { if (vis[rem]) return dp[rem]; vis[rem] = true; bool ret = false; for (int i = 1; i <= n; i++) { if (a[i] > rem) continue; ret = max((int)ret, solve(rem - a[i]) ^ 1); } dp[rem] = ret; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } cout << (solve(k) ? "First" : "Second"); }
insert
13
13
13
14
TLE
p03170
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #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 { #ifdef LOCAL ~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 << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vii = vector<ii>; const int oo = 1e8 + 7; int main() { int n, k; scanf("%d%d", &n, &k); vector<bool> winIfIs(k + 1, false); vi s(n); int minStone = oo; for (int i = 0; i < n; ++i) { scanf("%d", &s[i]); minStone = min(minStone, s[i]); } for (int i = minStone; i <= k; ++i) { for (int j = 0; j < n; ++j) { if (winIfIs[i - s[j]] == false) { winIfIs[i] = true; break; } } } if (winIfIs[k] == true) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; #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 { #ifdef LOCAL ~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 << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vii = vector<ii>; const int oo = 1e8 + 7; int main() { int n, k; scanf("%d%d", &n, &k); vector<bool> winIfIs(k + 1, false); vi s(n); int minStone = oo; for (int i = 0; i < n; ++i) { scanf("%d", &s[i]); minStone = min(minStone, s[i]); } for (int i = minStone; i <= k; ++i) { for (int j = 0; j < n; ++j) { if (i - s[j] >= 0 && winIfIs[i - s[j]] == false) { winIfIs[i] = true; break; } } } if (winIfIs[k] == true) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
60
61
60
61
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) #define pb push_back #define all(a) a.begin(), a.end() #define rall(c) (c).rbegin(), (c).rend() #define mp make_pair #define double long double typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll inf = 1e9 + 7; const ll mod = 1e9 + 7; ll n, k; vector<vector<ll>> dp(100010, vector<ll>(2, inf)); vector<ll> a(110); ll solve(ll x, ll y) { if (dp[x][y] != inf) return dp[x][y]; if (x < a[0]) return 1 - y; ll res; if (y == 1) res = 0; else res = 1; rep(i, n) { if (x < a[i]) continue; if (y == 1) if (solve(x - a[i], 0) == 1) res = 1; if (y == 0) if (solve(x - a[i], 1 - y) == 0) res = 0; } return res; } int main() { cin >> n >> k; rep(i, n) cin >> a[i]; if (solve(k, 0)) cout << "Second" << endl; else cout << "First" << endl; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) #define pb push_back #define all(a) a.begin(), a.end() #define rall(c) (c).rbegin(), (c).rend() #define mp make_pair #define double long double typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll inf = 1e9 + 7; const ll mod = 1e9 + 7; ll n, k; vector<vector<ll>> dp(100010, vector<ll>(2, inf)); vector<ll> a(110); ll solve(ll x, ll y) { if (dp[x][y] != inf) return dp[x][y]; if (x < a[0]) return 1 - y; ll res; if (y == 1) res = 0; else res = 1; rep(i, n) { if (x < a[i]) continue; if (y == 1) if (solve(x - a[i], 0) == 1) res = 1; if (y == 0) if (solve(x - a[i], 1 - y) == 0) res = 0; } dp[x][y] = res; return res; } int main() { cin >> n >> k; rep(i, n) cin >> a[i]; if (solve(k, 0)) cout << "Second" << endl; else cout << "First" << endl; }
insert
39
39
39
40
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 1e9 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n; cin >> n; int k; cin >> k; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<bool> dp(n + 1); for (int i = 0; i <= k; i++) { for (int j = 1; j <= n; j++) { if (i >= a[j] && !dp[i - a[j]]) dp[i] = true; } } dp[k] ? (cout << "First") : (cout << "Second"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 1e9 + 5; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n; cin >> n; int k; cin >> k; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<bool> dp(k + 1); for (int i = 0; i <= k; i++) { for (int j = 1; j <= n; j++) { if (i >= a[j] && !dp[i - a[j]]) dp[i] = true; } } dp[k] ? (cout << "First") : (cout << "Second"); return 0; }
replace
17
18
17
18
0
p03170
C++
Runtime Error
/******************************** * AUTHOR: ARNAB SEN * * NICK : arnab1729 * * INSTITUTION: IIEST, SHIBPUR * ********************************/ #include <bits/stdc++.h> using namespace std; typedef string STR; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef vector<int> VI; typedef priority_queue<int> PQI; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<STR> VS; typedef vector<char> VC; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<STR, int> PSI; typedef pair<int, STR> PIS; typedef vector<PII> VII; typedef map<int, int> MII; typedef map<LL, LL> MLL; typedef map<STR, int> MSI; typedef map<char, int> MCI; typedef map<int, STR> MIS; typedef set<STR> SS; typedef set<int> SI; typedef set<LL> SLL; #define FF first #define SS second #define PB push_back #define PF push_front #define MP make_pair #define all(a) (a).begin(), (a).end() #define dec(n) cout << fixed << setprecision(n); #define f(i, n) for (LL i = 0; i < n; i++) #define fr(i, n) for (LL i = n - 1; i >= 0; i--) #define fsort(a) sort(a.begin(), a.end()) #define rsort(a) sort(a.rbegin(), a.rend()) #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)) template <class T> T maxT(T a, T b) { return (a > b ? a : b); } template <class T> T minT(T a, T b) { return (a < b ? a : b); } template <class T> void setmin(T &a, T b) { a = (a > b ? a : b); } template <class T> void setmax(T &a, T b) { a = (a < b ? a : b); } void fileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); } void ofileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void clock_out() { cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define fio() fileio() #define ofio ofileio() #define clock() clock_out() #else #define debug(...) 1 #define fio() 1 #define ofio() ofileio() #define clock() 1 #endif const LL MOD = 1000000007; const LL SIZE = 100000; const int INF = 0x3f3f3f3f; const LL LL_INF = 0x3f3f3f3f3f3f3f3f; const LD PI = acos(-1); const LL MAXN = numeric_limits<LL>::max(); int n, tot; vector<int> a(110); int memo[(int)(1e5 + 10)][2]; int dp(int k, int mv) { int &ans = memo[k][mv]; if (ans != -1) { return ans; } int nxt = (mv + 1) % 2; for (int i = 0; i < n; i++) { if (k >= a[i] && (dp(k - a[i], nxt) == mv)) { ans = mv; return mv; } } ans = nxt; return nxt; } void solve() { cin >> n >> tot; f(i, n) { cin >> a[i]; } memset(memo, -1, sizeof(memo)); memo[0][1] = 0; memo[0][0] = 1; if (dp(tot, 0)) { cout << "Second\n"; } else { cout << "First\n"; } } int main() { fast; fio(); LL t = 1; // cin>>t; while (t--) { solve(); } clock(); return 0; }
/******************************** * AUTHOR: ARNAB SEN * * NICK : arnab1729 * * INSTITUTION: IIEST, SHIBPUR * ********************************/ #include <bits/stdc++.h> using namespace std; typedef string STR; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef vector<int> VI; typedef priority_queue<int> PQI; typedef vector<LL> VLL; typedef vector<ULL> VULL; typedef vector<STR> VS; typedef vector<char> VC; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<STR, int> PSI; typedef pair<int, STR> PIS; typedef vector<PII> VII; typedef map<int, int> MII; typedef map<LL, LL> MLL; typedef map<STR, int> MSI; typedef map<char, int> MCI; typedef map<int, STR> MIS; typedef set<STR> SS; typedef set<int> SI; typedef set<LL> SLL; #define FF first #define SS second #define PB push_back #define PF push_front #define MP make_pair #define all(a) (a).begin(), (a).end() #define dec(n) cout << fixed << setprecision(n); #define f(i, n) for (LL i = 0; i < n; i++) #define fr(i, n) for (LL i = n - 1; i >= 0; i--) #define fsort(a) sort(a.begin(), a.end()) #define rsort(a) sort(a.rbegin(), a.rend()) #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)) template <class T> T maxT(T a, T b) { return (a > b ? a : b); } template <class T> T minT(T a, T b) { return (a < b ? a : b); } template <class T> void setmin(T &a, T b) { a = (a > b ? a : b); } template <class T> void setmax(T &a, T b) { a = (a < b ? a : b); } void fileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); } void ofileio() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void clock_out() { cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #ifndef ONLINE_JUDGE #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define fio() fileio() #define ofio ofileio() #define clock() clock_out() #else #define debug(...) 1 #define fio() 1 #define ofio() ofileio() #define clock() 1 #endif const LL MOD = 1000000007; const LL SIZE = 100000; const int INF = 0x3f3f3f3f; const LL LL_INF = 0x3f3f3f3f3f3f3f3f; const LD PI = acos(-1); const LL MAXN = numeric_limits<LL>::max(); int n, tot; vector<int> a(110); int memo[(int)(1e5 + 10)][2]; int dp(int k, int mv) { int &ans = memo[k][mv]; if (ans != -1) { return ans; } int nxt = (mv + 1) % 2; for (int i = 0; i < n; i++) { if (k >= a[i] && (dp(k - a[i], nxt) == mv)) { ans = mv; return mv; } } ans = nxt; return nxt; } void solve() { cin >> n >> tot; f(i, n) { cin >> a[i]; } memset(memo, -1, sizeof(memo)); memo[0][1] = 0; memo[0][0] = 1; if (dp(tot, 0)) { cout << "Second\n"; } else { cout << "First\n"; } } int main() { fast; // fio(); LL t = 1; // cin>>t; while (t--) { solve(); } clock(); return 0; }
replace
132
133
132
133
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, a, b) for (ll i = a; i < b; ++i) const ll MOD = 1000003; const ll INF = 1e9; const ll IINF = 1e18; const double EPS = 1e-8; const double pi = acos(-1); template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int N, K; cin >> N >> K; vector<int> a(N); rep(i, N) cin >> a[i]; vector<bool> decide(K + 1, false); rep(i, K + 1) { if (!decide[i]) { rep(j, N) decide[i + a[j]] = true; } } if (decide[K]) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, a, b) for (ll i = a; i < b; ++i) const ll MOD = 1000003; const ll INF = 1e9; const ll IINF = 1e18; const double EPS = 1e-8; const double pi = acos(-1); template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int N, K; cin >> N >> K; vector<int> a(N); rep(i, N) cin >> a[i]; vector<bool> decide(K + 1, false); rep(i, K + 1) { if (!decide[i]) { rep(j, N) { if (i + a[j] > K) continue; decide[i + a[j]] = true; } } } if (decide[K]) cout << "First" << endl; else cout << "Second" << endl; }
replace
36
37
36
41
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 1000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; // cin.tie(0); // ios::sync_with_stdio(false); int dp[100010] = {}; // 0==lose signed main() { int n; cin >> n; ll k; cin >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; rep(i, k + 1) { rep(j, n) { dp[i + a[j]] = max(1 - dp[i], dp[i + a[j]]); } } if (dp[k] == 1) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 1000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; // cin.tie(0); // ios::sync_with_stdio(false); int dp[500010] = {}; // 0==lose signed main() { int n; cin >> n; ll k; cin >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; rep(i, k + 1) { rep(j, n) { dp[i + a[j]] = max(1 - dp[i], dp[i + a[j]]); } } if (dp[k] == 1) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
20
21
20
21
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } const int mod = 10; ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } inline int add(int a, int b) { a += b; if (a >= mod) return a - mod; return a; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { int n, m; cin >> n >> m; vector<int> a(n); rep(i, n) cin >> a[i]; sort(all(a)); vector<int> dp(n + 1); // 0, ่ฒ ใ‘ rep3(i, 1, m + 1) { rep(j, n) { if (i - a[j] < 0) break; if (dp[i - a[j]] == 0) { dp[i] = 1; break; } } } cout << (dp[m] ? "First" : "Second") << endl; // rep(i, m + 1) cout << dp[i] << " "; cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } const int mod = 10; ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } inline int add(int a, int b) { a += b; if (a >= mod) return a - mod; return a; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { int n, m; cin >> n >> m; vector<int> a(n); rep(i, n) cin >> a[i]; sort(all(a)); vector<int> dp(m + 1); // 0, ่ฒ ใ‘ rep3(i, 1, m + 1) { rep(j, n) { if (i - a[j] < 0) break; if (dp[i - a[j]] == 0) { dp[i] = 1; break; } } } cout << (dp[m] ? "First" : "Second") << endl; // rep(i, m + 1) cout << dp[i] << " "; cout << endl; }
replace
86
87
86
87
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define db double #define ld long double #define rep(i, n) for (ll i = 0; i < n; i++) #define rev(i, n) for (ll i = n; i >= 0; i--) #define rep_a(i, a, n) for (ll i = a; i < n; i++) #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define debug(x) \ do { \ std::cerr << #x << ": " << x << std::endl; \ } while (0); #define debugg(x, y) \ do { \ std::cerr << #x << ": " << x << " " << #y << ": " << y << std::endl; \ } while (0); #define debugggg(i, j, k, ans) \ std::cerr << #i << ": " << i << " " << #j << ": " << j << #k << ": " << k \ << #ans << ": " << ans << std::endl; const long long mod = 998244353; const long long MOD = 1000000007; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<char> vchar; typedef vector<pair<ll, ll>> vpll; typedef set<ll> sll; typedef set<string> sstr; typedef set<pair<ll, ll>> spll; typedef map<ll, ll> mllll; typedef map<string, ll> mstrll; typedef queue<ll> qll; map<ll, ll> mp; int solve() { int n, k; cin >> n >> k; vll a(n + 1); rep(i, n) cin >> a[i + 1]; sort(all(a)); vll dp(n + 1, 0); // if ist wins 1 else 0; rep_a(i, 1, k + 1) { rep_a(j, 1, n + 1) { bool win = false; if (i >= a[j]) win = 1 - dp[i - a[j]]; if (win) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; } int main() { fast; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif */ solve(); /* #ifndef ONLINE_JUDGE cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC <<" Sec\n"; #endif */ return 0; }
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define db double #define ld long double #define rep(i, n) for (ll i = 0; i < n; i++) #define rev(i, n) for (ll i = n; i >= 0; i--) #define rep_a(i, a, n) for (ll i = a; i < n; i++) #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define debug(x) \ do { \ std::cerr << #x << ": " << x << std::endl; \ } while (0); #define debugg(x, y) \ do { \ std::cerr << #x << ": " << x << " " << #y << ": " << y << std::endl; \ } while (0); #define debugggg(i, j, k, ans) \ std::cerr << #i << ": " << i << " " << #j << ": " << j << #k << ": " << k \ << #ans << ": " << ans << std::endl; const long long mod = 998244353; const long long MOD = 1000000007; typedef vector<ll> vll; typedef vector<string> vstr; typedef vector<char> vchar; typedef vector<pair<ll, ll>> vpll; typedef set<ll> sll; typedef set<string> sstr; typedef set<pair<ll, ll>> spll; typedef map<ll, ll> mllll; typedef map<string, ll> mstrll; typedef queue<ll> qll; map<ll, ll> mp; int solve() { int n, k; cin >> n >> k; vll a(n + 1); rep(i, n) cin >> a[i + 1]; sort(all(a)); vll dp(k + 1, 0); // if ist wins 1 else 0; rep_a(i, 1, k + 1) { rep_a(j, 1, n + 1) { bool win = false; if (i >= a[j]) win = 1 - dp[i - a[j]]; if (win) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; } int main() { fast; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif */ solve(); /* #ifndef ONLINE_JUDGE cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC <<" Sec\n"; #endif */ return 0; }
replace
45
46
45
46
0
p03170
C++
Runtime Error
/* confirm 0LL and 1LL confirm cornercases such as 0 confirm times of cin < 10^6 */ #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using VecVec = vector<Vec>; using Graph = vector<VecP>; template <typename T> using Vec1 = vector<T>; template <typename T> using Vec2 = vector<Vec1<T>>; template <typename T> using Vec3 = vector<Vec2<T>>; #define REP(i, m, n) for (ll(i) = (m); (i) < (n); ++(i)) #define REPN(i, m, n) for (ll(i) = (m); (i) <= (n); ++(i)) #define REPR(i, m, n) for (ll(i) = (m)-1; (i) >= (n); --(i)) #define REPNR(i, m, n) for (ll(i) = (m); (i) >= (n); --(i)) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repe(i, n) REPN(i, 0, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define reper(i, n) REPNR(i, n, 0) #define all(s) (s).begin(), (s).end() #define pb push_back #define mp make_pair #define fs first #define sc second template <typename T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } template <typename T> ll pow2(const T n) { return (1LL << n); } template <typename T> void cosp(const T n) { cout << n << ' '; } template <typename T> void co(const T n) { cout << n << '\n'; } template <typename T1, typename T2> void co(pair<T1, T2> p) { cout << p.fs << ' ' << p.sc << '\n'; } template <typename T> void co(const Vec1<T> &v) { for (T i : v) cosp(i); cout << '\n'; } template <typename T> void co(initializer_list<T> v) { for (T i : v) cosp(i); cout << '\n'; } template <typename T> void ce(const T n) { cerr << n << endl; } void sonic() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void setp(const ll n) { cout << fixed << setprecision(n); } const ll INF = 1e9 + 1; const ll LINF = 1e18 + 1; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ld PI = acos(-1); const ld EPS = 1e-11; int main(void) { ll n, k; cin >> n >> k; Vec a(n); rep(i, n) cin >> a[i]; Vec dp(k + 1); repe(i, k) { if (i < a[0]) dp[i] = 1; else { ll f = 1; rep(j, n) if (dp[i - a[j]]) { f = 0; break; } dp[i] = f; } } if (!dp[k]) co("First"); else co("Second"); return 0; }
/* confirm 0LL and 1LL confirm cornercases such as 0 confirm times of cin < 10^6 */ #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; using VecVec = vector<Vec>; using Graph = vector<VecP>; template <typename T> using Vec1 = vector<T>; template <typename T> using Vec2 = vector<Vec1<T>>; template <typename T> using Vec3 = vector<Vec2<T>>; #define REP(i, m, n) for (ll(i) = (m); (i) < (n); ++(i)) #define REPN(i, m, n) for (ll(i) = (m); (i) <= (n); ++(i)) #define REPR(i, m, n) for (ll(i) = (m)-1; (i) >= (n); --(i)) #define REPNR(i, m, n) for (ll(i) = (m); (i) >= (n); --(i)) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repe(i, n) REPN(i, 0, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define reper(i, n) REPNR(i, n, 0) #define all(s) (s).begin(), (s).end() #define pb push_back #define mp make_pair #define fs first #define sc second template <typename T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } template <typename T> ll pow2(const T n) { return (1LL << n); } template <typename T> void cosp(const T n) { cout << n << ' '; } template <typename T> void co(const T n) { cout << n << '\n'; } template <typename T1, typename T2> void co(pair<T1, T2> p) { cout << p.fs << ' ' << p.sc << '\n'; } template <typename T> void co(const Vec1<T> &v) { for (T i : v) cosp(i); cout << '\n'; } template <typename T> void co(initializer_list<T> v) { for (T i : v) cosp(i); cout << '\n'; } template <typename T> void ce(const T n) { cerr << n << endl; } void sonic() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void setp(const ll n) { cout << fixed << setprecision(n); } const ll INF = 1e9 + 1; const ll LINF = 1e18 + 1; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ld PI = acos(-1); const ld EPS = 1e-11; int main(void) { ll n, k; cin >> n >> k; Vec a(n); rep(i, n) cin >> a[i]; Vec dp(k + 1); repe(i, k) { if (i < a[0]) dp[i] = 1; else { ll f = 1; rep(j, n) { if (a[j] > i) break; if (dp[i - a[j]]) { f = 0; break; } } dp[i] = f; } } if (!dp[k]) co("First"); else co("Second"); return 0; }
replace
94
97
94
101
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int dp[MAX]; int main() { int N, K, i, j; cin >> N >> K; int a[N]; int flag; for (i = 0; i < N; i++) cin >> a[i]; for (i = 0; i < a[0]; i++) dp[i] = -1; for (i = a[0]; i < K + 1; i++) { flag = 0; for (j = 0; j < N; j++) { if (dp[i - a[j]] == -1) { flag++; break; } } if (flag > 0) dp[i] = 1; else { dp[i] = -1; } } if (dp[K] == 1) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int dp[MAX]; int main() { int N, K, i, j; cin >> N >> K; int a[N]; int flag; for (i = 0; i < N; i++) cin >> a[i]; for (i = 0; i < a[0]; i++) dp[i] = -1; for (i = a[0]; i < K + 1; i++) { flag = 0; for (j = 0; j < N; j++) { if (i < a[j]) break; else if (dp[i - a[j]] == -1) { flag++; break; } } if (flag > 0) dp[i] = 1; else { dp[i] = -1; } } if (dp[K] == 1) cout << "First" << endl; else cout << "Second" << endl; }
replace
17
18
17
20
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; // #include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> #define REVERSE(v) reverse(ALL(v)) #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl #define debug cerr << "bhau" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // #define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int solve() { int n, k; cin >> n >> k; vi a(n); inputarr(a, n); vector<bool> dp(k + 1, 0); for (int stones = 0; stones <= k; stones++) { for (auto x : a) { if (stones >= x && !dp[stones - x]) { dp[stones] = 1; break; } } } string ans = (dp[k]) ? "First" : "Second"; cout << ans; r0 } signed main() { asdf #ifndef ONLINE_JUDGE inputoutput #endif int t = 1; // cin>>t; while (t--) { solve(); } }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; // #include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> #define REVERSE(v) reverse(ALL(v)) #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl #define debug cerr << "bhau" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // #define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } int solve() { int n, k; cin >> n >> k; vi a(n); inputarr(a, n); vector<bool> dp(k + 1, 0); for (int stones = 0; stones <= k; stones++) { for (auto x : a) { if (stones >= x && !dp[stones - x]) { dp[stones] = 1; break; } } } string ans = (dp[k]) ? "First" : "Second"; cout << ans; r0 } signed main() { asdf int t = 1; // cin>>t; while (t--) { solve(); } }
replace
99
102
99
100
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03170
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define pb push_back #define ins insert #define pob pop_back #define er erase #define emp empty #define f first #define s second #define ff f.f #define fs f.s #define sf s.f #define ss s.s #define var auto using namespace std; template <typename T> using s = set<T>; template <typename T> using v = vector<T>; template <typename T1, typename T2> using p = pair<T1, T2>; typedef long long ll; typedef p<int, int> pii; typedef v<int> vi; typedef v<pii> vpii; typedef s<int> si; typedef s<pii> spii; const int Max = 4e3 + 100; const int MOD = 1e9 + 7; const ll INF = 1e18; int n, k; bool dp[Max]; ll A[Max]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; // He Cant Do Any Move So Lose dp[0] = false; for (int i = 1; i <= k; i++) { bool foundLoose = false; for (var s : A) { if (s == 0) break; if (i >= s) { foundLoose = !dp[i - s]; } if (foundLoose) break; } dp[i] = foundLoose; } if (dp[k]) cout << "First"; else cout << "Second"; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define pb push_back #define ins insert #define pob pop_back #define er erase #define emp empty #define f first #define s second #define ff f.f #define fs f.s #define sf s.f #define ss s.s #define var auto using namespace std; template <typename T> using s = set<T>; template <typename T> using v = vector<T>; template <typename T1, typename T2> using p = pair<T1, T2>; typedef long long ll; typedef p<int, int> pii; typedef v<int> vi; typedef v<pii> vpii; typedef s<int> si; typedef s<pii> spii; const int Max = 1e5 + 100; const int MOD = 1e9 + 7; const ll INF = 1e18; int n, k; bool dp[Max]; ll A[Max]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; // He Cant Do Any Move So Lose dp[0] = false; for (int i = 1; i <= k; i++) { bool foundLoose = false; for (var s : A) { if (s == 0) break; if (i >= s) { foundLoose = !dp[i - s]; } if (foundLoose) break; } dp[i] = foundLoose; } if (dp[k]) cout << "First"; else cout << "Second"; }
replace
34
35
34
35
0
p03170
C++
Time Limit Exceeded
/** *COYG, 14 FA Cups we are back baby */ #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long #define mp make_pair #define pb push_back #define forn(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i < n; i++) #define ford(i, n) for (int i = n - 1; i >= 0; i--) #define vi vector<int> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define vpi vector<pair<int, int>> #define vpl vector<pair<ll, ll>> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define ull unsigned long long #define IOS ios_base::sync_with_stdio(false); #define PI 3.1415926535897932384626 #define ff first #define ss second #define char2Int(c) (c - '0') #define FOREACH(i, t) for (auto i = t.begin(); i != t.end(); i++) #define clr(a, x) memset(a, x, sizeof(a)) // set elements of array to some value #define all(x) (x).begin(), (x).end() // cout<<"Case #"<<zzz<<": "; #define plll pair<ll, pll> int n; int dp[100001]; int a[100001]; int getans(int curr) { if (dp[curr] != -1) return dp[curr]; int flag = 0; forn(i, n) { if (a[i] <= curr) { if (getans(curr - a[i]) == 0) flag = 1; } } return flag; } void solve() { cin >> n; int k; cin >> k; forn(i, n) cin >> a[i]; forn(i, k + 1) dp[i] = -1; dp[0] = 0; if (getans(k)) cout << "First"; else cout << "Second"; cout << endl; } int main() { IOS; cin.tie(NULL); int zz; zz = 1; // cin>>zz; for (int zzz = 1; zzz <= zz; zzz++) { solve(); } return 0; }
/** *COYG, 14 FA Cups we are back baby */ #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long #define mp make_pair #define pb push_back #define forn(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i < n; i++) #define ford(i, n) for (int i = n - 1; i >= 0; i--) #define vi vector<int> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define vpi vector<pair<int, int>> #define vpl vector<pair<ll, ll>> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define ull unsigned long long #define IOS ios_base::sync_with_stdio(false); #define PI 3.1415926535897932384626 #define ff first #define ss second #define char2Int(c) (c - '0') #define FOREACH(i, t) for (auto i = t.begin(); i != t.end(); i++) #define clr(a, x) memset(a, x, sizeof(a)) // set elements of array to some value #define all(x) (x).begin(), (x).end() // cout<<"Case #"<<zzz<<": "; #define plll pair<ll, pll> int n; int dp[100001]; int a[100001]; int getans(int curr) { if (dp[curr] != -1) return dp[curr]; int flag = 0; forn(i, n) { if (a[i] <= curr) { if (getans(curr - a[i]) == 0) flag = 1; } } dp[curr] = flag; return flag; } void solve() { cin >> n; int k; cin >> k; forn(i, n) cin >> a[i]; forn(i, k + 1) dp[i] = -1; dp[0] = 0; if (getans(k)) cout << "First"; else cout << "Second"; cout << endl; } int main() { IOS; cin.tie(NULL); int zz; zz = 1; // cin>>zz; for (int zzz = 1; zzz <= zz; zzz++) { solve(); } return 0; }
insert
43
43
43
44
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)n; i++) bool dp[100010]; int main() { int N, K; cin >> N >> K; vector<int> a(N); rep(i, N) cin >> a[i]; memset(dp, 0, sizeof(dp)); for (int i = 0; i <= K; i++) { if (dp[i]) continue; rep(j, N) { int x = a[j]; dp[i + x] = true; } } if (dp[K]) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)n; i++) bool dp[100010]; int main() { int N, K; cin >> N >> K; vector<int> a(N); rep(i, N) cin >> a[i]; memset(dp, 0, sizeof(dp)); for (int i = 0; i <= K; i++) { if (dp[i]) continue; rep(j, N) { int x = a[j]; if (i + x > K) continue; dp[i + x] = true; } } if (dp[K]) cout << "First" << endl; else cout << "Second" << endl; }
insert
19
19
19
21
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; bool dp[k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int val : a) { if (val > i) continue; if (dp[i - val] == 0) dp[i] = 1; } } 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; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; bool dp[k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int val : a) { if (val > i) continue; if (dp[i - val] == 0) dp[i] = 1; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
replace
6
7
6
7
-11
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ln '\n' #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> VP; typedef vector<PL> VPL; typedef vector<string> VS; VI memo; int dfs(int k, VI &av) { if (memo[k] != 0) return memo[k]; int first_res = -1; for (auto a1 : av) { if (k - a1 >= 0) { int second_res = 1; for (auto a2 : av) { if (k - a1 - a2 >= 0) second_res = min(second_res, dfs(k - a1 - a2, av)); } first_res = max(first_res, second_res); } } return memo[k] = first_res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; VI a(n); REP(i, n) cin >> a[i]; memo.resize(k + 1); cout << (dfs(k, a) == 1 ? "First" : "Second") << ln; return 0; }
#include <bits/stdc++.h> using namespace std; #define ln '\n' #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> VP; typedef vector<PL> VPL; typedef vector<string> VS; VI memo; int dfs(int k, VI &av) { if (memo[k] != 0) return memo[k]; int first_res = -1; for (auto a1 : av) { if (k - a1 >= 0) { int second_res = 1; if (memo[k - a1] != 0) { second_res = memo[k - a1] * -1; } else { for (auto a2 : av) if (k - a1 - a2 >= 0) second_res = min(second_res, dfs(k - a1 - a2, av)); memo[k - a1] = second_res * -1; } first_res = max(first_res, second_res); } } return memo[k] = first_res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; VI a(n); REP(i, n) cin >> a[i]; memo.resize(k + 1); cout << (dfs(k, a) == 1 ? "First" : "Second") << ln; return 0; }
replace
28
31
28
35
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::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 + 5); for (int stone = 0; stone <= k; stone++) { for (int x : a) // Foreach stones in array a { if (x <= stone && !dp[stone - x]) { dp[stone] = true; } } } cout << (dp[k] ? "First" : "Second") << "\n"; return 0; } /* dp[i]: True if player 1 win with i stones remaining The relation is: if (current x <= i remaining stones AND dp[remaining stones] = false) dp[i] = true Why dp[stone-x] needs to be false: because after stone - x the turn will change to the player 2 and if dp[stone-x] = false is mean that player 2 loose => player 1 win */
#include <bits/stdc++.h> using namespace std; int main() { ios::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 + 5); for (int stone = 0; stone <= k; stone++) { for (int x : a) // Foreach stones in array a { if (x <= stone && !dp[stone - x]) { dp[stone] = true; } } } cout << (dp[k] ? "First" : "Second") << "\n"; return 0; } /* dp[i]: True if player 1 win with i stones remaining The relation is: if (current x <= i remaining stones AND dp[remaining stones] = false) dp[i] = true Why dp[stone-x] needs to be false: because after stone - x the turn will change to the player 2 and if dp[stone-x] = false is mean that player 2 loose => player 1 win */
replace
12
13
12
13
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define piii pair<ll, pii> #define MOD 1000000007 #define M 105 #define N 100005 #define inf 1000000001 using namespace std; ll n, k; ll arr[M], dp[M]; // k void solve() { // 0 means 2nd player and 1 means 1st player // if there is no element in the pile , 1st player will have nothing to take // and 2nd player will always win for (ll i = 0; i < k; i++) { // height of pile for (ll j = 1; j <= n; j++) { // no of element if (i + arr[j] <= k && !dp[i]) { dp[i + arr[j]] = 1; } } // cout<< endl; } if (dp[k]) cout << "First\n"; else cout << "Second\n"; // cout<< setprecision(10)<< ans<< endl; } int main() { // ll t; cin>> t; while(t--){ cin >> n >> k; for (ll i = 1; i <= n; i++) { // no of item cin >> arr[i]; } solve(); }
#include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define piii pair<ll, pii> #define MOD 1000000007 #define M 105 #define N 100005 #define inf 1000000001 using namespace std; ll n, k; ll arr[M], dp[N]; // k void solve() { // 0 means 2nd player and 1 means 1st player // if there is no element in the pile , 1st player will have nothing to take // and 2nd player will always win for (ll i = 0; i < k; i++) { // height of pile for (ll j = 1; j <= n; j++) { // no of element if (i + arr[j] <= k && !dp[i]) { dp[i + arr[j]] = 1; } } // cout<< endl; } if (dp[k]) cout << "First\n"; else cout << "Second\n"; // cout<< setprecision(10)<< ans<< endl; } int main() { // ll t; cin>> t; while(t--){ cin >> n >> k; for (ll i = 1; i <= n; i++) { // no of item cin >> arr[i]; } solve(); }
replace
10
11
10
11
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const int maxN = 1e2 + 5; const int maxK = 1e5 + 5; const int mod = 1e9 + 7; int arr[maxN]; bool dp[maxN]; int n, k; void solve() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 1; i < k + 1; i++) { for (int j = 0; j < n; j++) { if (i - arr[j] >= 0) { if (dp[i - arr[j]] == false) { dp[i] = true; break; } } else { break; } } } if (dp[k] == true) cout << "First" << endl; else cout << "Second" << endl; } int main() { FASTIO int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const int maxN = 1e5 + 5; const int mod = 1e9 + 7; int arr[maxN]; bool dp[maxN]; int n, k; void solve() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 1; i < k + 1; i++) { for (int j = 0; j < n; j++) { if (i - arr[j] >= 0) { if (dp[i - arr[j]] == false) { dp[i] = true; break; } } else { break; } } } if (dp[k] == true) cout << "First" << endl; else cout << "Second" << endl; } int main() { FASTIO int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
11
13
11
12
0
p03170
C++
Runtime Error
/* Educational DP Contest - K - Stones https://atcoder.jp/contests/dp/tasks/dp_k */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; const ll MOD = 1000000007; #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define OUT(x) cout << x << endl #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) \ for (auto &(z) : x) \ cin >> z; #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) void solve() {} int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); int n, k; cin >> n >> k; vi a(n); READ(a); vi dp(k + 1, 0); // 0: first player wins; 1: second player wins FORN(i, 1, k) { EACH(x, a) { if (k >= x && !dp[i - x]) { dp[i] = 1; } } } OUT((dp[k] ? "First" : "Second")); return 0; }
/* Educational DP Contest - K - Stones https://atcoder.jp/contests/dp/tasks/dp_k */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; const ll MOD = 1000000007; #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define OUT(x) cout << x << endl #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) \ for (auto &(z) : x) \ cin >> z; #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) void solve() {} int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); int n, k; cin >> n >> k; vi a(n); READ(a); vi dp(k + 1, 0); // 0: first player wins; 1: second player wins FORN(i, 1, k) { EACH(x, a) { if (i >= x && !dp[i - x]) { dp[i] = 1; } } } OUT((dp[k] ? "First" : "Second")); return 0; }
replace
81
82
81
82
0
p03170
C++
Time Limit Exceeded
/* Educational DP Contest - K - Stones https://atcoder.jp/contests/dp/tasks/dp_k */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; const ll MOD = 1000000007; #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define OUT(x) cout << x << endl #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) \ for (auto &(z) : x) \ cin >> z; #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) void solve() {} int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); int n, k; cin >> n >> k; vi a(n); READ(a); // dp[i]=0: first player wins; // dp[i]=1: second player wins vi dp(k + 1, 0); FORN(i, 1, k) { for (int j = 1; a[i - 1] <= i; j++) { dp[i] |= !dp[i - a[i - 1]]; } } OUT((dp[k] ? "First" : "Second")); return 0; }
/* Educational DP Contest - K - Stones https://atcoder.jp/contests/dp/tasks/dp_k */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<vl> vvl; double EPS = 1e-9; int INF = 1000000005; long long INFF = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; const ll MOD = 1000000007; #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define OUT(x) cout << x << endl #define OUTH(x) cout << x << " " #define debug(...) fprintf(stderr, __VA_ARGS__) #define READ(x) \ for (auto &(z) : x) \ cin >> z; #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define EACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((ll)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) #define FAST_INP \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) void solve() {} int main() { FAST_INP; // #ifndef ONLINE_JUDGE // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // #endif // int tc; cin >> tc; // TC(tc) solve(); int n, k; cin >> n >> k; vi a(n); READ(a); // dp[i]=0: first player wins; // dp[i]=1: second player wins vi dp(k + 1, 0); FORN(i, 1, k) { EACH(x, a) { if (i >= x && !dp[i - x]) { dp[i] = 1; } } } OUT((dp[k] ? "First" : "Second")); return 0; }
replace
82
84
82
86
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ll_s long #define mod 1000000007 #define forn(i, start, lim) for (ll i = start; i < lim; i++) #define forn_d(i, start, lim) for (ll i = start; i >= lim; i--) #define f first #define s second #define pb push_back #define pf push_front #define mp make_pair #define debug1(a) \ cout << "------\n" << #a << " = " << a << endl << "------" << endl #define debug2(a, b) \ cout << "--------------\n" \ << #a << " = " << a << " ; " << #b << " = " << b << endl \ << "--------------" << endl #define debug3(a, b, c) \ cout << "----------------------\n" \ << #a << " = " << a << " ; " << #b << " = " << b << " ; " << #c \ << " = " << c << endl \ << "----------------------" << endl #define sz(a) (ll)(a.size()) #define debug4(a) cout << "chu " << a << endl #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t; // cin>>t; t = 1; while (t--) { ll n, k; cin >> n >> k; vector<ll> a(n), dp(k + 1, 0); forn(i, 0, n) cin >> a[i]; forn(i, 0, k) { if (dp[i] == 0) { forn(j, 0, n) { dp[i + a[j]] = 1; } } } ll ans = dp[k]; if (ans == 1) cout << "First\n"; else cout << "Second\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ll_s long #define mod 1000000007 #define forn(i, start, lim) for (ll i = start; i < lim; i++) #define forn_d(i, start, lim) for (ll i = start; i >= lim; i--) #define f first #define s second #define pb push_back #define pf push_front #define mp make_pair #define debug1(a) \ cout << "------\n" << #a << " = " << a << endl << "------" << endl #define debug2(a, b) \ cout << "--------------\n" \ << #a << " = " << a << " ; " << #b << " = " << b << endl \ << "--------------" << endl #define debug3(a, b, c) \ cout << "----------------------\n" \ << #a << " = " << a << " ; " << #b << " = " << b << " ; " << #c \ << " = " << c << endl \ << "----------------------" << endl #define sz(a) (ll)(a.size()) #define debug4(a) cout << "chu " << a << endl #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t; // cin>>t; t = 1; while (t--) { ll n, k; cin >> n >> k; vector<ll> a(n), dp(k + 1, 0); forn(i, 0, n) cin >> a[i]; forn(i, 0, k) { if (dp[i] == 0) { forn(j, 0, n) { if (i + a[j] <= k) dp[i + a[j]] = 1; } } } ll ans = dp[k]; if (ans == 1) cout << "First\n"; else cout << "Second\n"; } return 0; }
replace
41
42
41
45
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<int> arr; int n, k, temp; int dp[10002]; void solve() { memset(dp, -1, sizeof dp); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> temp; arr.push_back(temp); } dp[0] = 0; for (int i = 1; i <= k; i++) { dp[i] = 0; for (auto moves : arr) { if ((i - moves) >= 0) { if (dp[i - moves] == 0) dp[i] = 1; } } } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; } int main(void) { solve(); }
#include <bits/stdc++.h> using namespace std; vector<int> arr; int n, k, temp; int dp[100002]; void solve() { memset(dp, -1, sizeof dp); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> temp; arr.push_back(temp); } dp[0] = 0; for (int i = 1; i <= k; i++) { dp[i] = 0; for (auto moves : arr) { if ((i - moves) >= 0) { if (dp[i - moves] == 0) dp[i] = 1; } } } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; } int main(void) { solve(); }
replace
4
5
4
5
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define rep(a, n) for (ll a = 0; a < (n); ++a) using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<vector<ll>> Graph; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<bool> dp(n, false); for (int i = 1; i <= k; i++) { rep(j, n) { if (i - a[j] < 0) continue; if (!dp[i - a[j]]) { dp[i] = true; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> #define rep(a, n) for (ll a = 0; a < (n); ++a) using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef vector<vector<ll>> Graph; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<bool> dp(k + 1, false); for (int i = 1; i <= k; i++) { rep(j, n) { if (i - a[j] < 0) continue; if (!dp[i - a[j]]) { dp[i] = true; } } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
27
28
27
28
0
p03170
C++
Time Limit Exceeded
#include <iostream> using namespace std; int n, k; int a[110]; bool vis[100100][2]; bool dp[100100][2]; bool check(int x, int p) { if (x < 0) return true; if (vis[x][p]) return dp[x][p]; for (int i = 0; i < n; i++) { if (!check(x - a[i], !p)) dp[x][p] = true; } return dp[x][p]; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } if (check(k, 0)) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <iostream> using namespace std; int n, k; int a[110]; bool vis[100100][2]; bool dp[100100][2]; bool check(int x, int p) { if (x < 0) return true; if (vis[x][p]) return dp[x][p]; vis[x][p] = true; for (int i = 0; i < n; i++) { if (!check(x - a[i], !p)) dp[x][p] = true; } return dp[x][p]; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } if (check(k, 0)) { cout << "First" << endl; } else { cout << "Second" << endl; } }
insert
11
11
11
12
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // dp[i] - 1 if first player can win with i stones, 0 otherwise int N, K, a[105]; bool dp[10005]; 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++) { bool find = false; for (int j = 0; j < N; j++) { if (i - a[j] < 0) continue; if (dp[i - a[j]] == 0) { find = true; } } if (find) { dp[i] = 1; } else { dp[i] = 0; } } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; // dp[i] - 1 if first player can win with i stones, 0 otherwise int N, K, a[105]; bool dp[100005]; 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++) { bool find = false; for (int j = 0; j < N; j++) { if (i - a[j] < 0) continue; if (dp[i - a[j]] == 0) { find = true; } } if (find) { dp[i] = 1; } else { dp[i] = 0; } } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
5
6
5
6
0
p03170
C++
Runtime Error
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" using namespace std; typedef long int li; typedef long double ld; typedef long long ll; typedef pair<int, int> pt; #define fi first #define se second #define dump(x) cout << #x << " = " << x << endl #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); li n, k, a[107], dp[100007]; int main() { fastIO; cin >> n >> k; for (li i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (li i = 0; i <= a[0]; i++) dp[i] = 1; for (li i = 0; i <= k; i++) { if (!dp[i]) dp[i] = 1; if (dp[i] == 1) for (li j = 0; j < n; j++) { dp[i + a[j]] = 2; } } if (dp[k] == 2) cout << "First"; else cout << "Second"; }
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" using namespace std; typedef long int li; typedef long double ld; typedef long long ll; typedef pair<int, int> pt; #define fi first #define se second #define dump(x) cout << #x << " = " << x << endl #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); li n, k, a[107], dp[100007]; int main() { fastIO; cin >> n >> k; for (li i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (li i = 0; i <= a[0]; i++) dp[i] = 1; for (li i = 0; i <= k; i++) { if (!dp[i]) dp[i] = 1; if (dp[i] == 1) for (li j = 0; j < n; j++) { if (i + a[j] > k) continue; dp[i + a[j]] = 2; } } if (dp[k] == 2) cout << "First"; else cout << "Second"; }
insert
34
34
34
36
0
p03170
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define ALL(x) (x).begin(), (x).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; } int N, K; int DP[100010] = {}; int main() { cin >> N >> K; int a[N]; REP(i, N) { cin >> a[i]; } REP(i, K) { REP(j, N) { if (DP[i] == 0) { chmax(DP[i + a[j]], 1); } } } string res; if (DP[K] == 0) { res = "Second"; } else { res = "First"; } cout << res; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define ALL(x) (x).begin(), (x).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; } int N, K; int DP[100010] = {}; int main() { cin >> N >> K; int a[N]; REP(i, N) { cin >> a[i]; } REP(i, K) { REP(j, N) { if (DP[i] == 0) { if (i + a[j] <= K) chmax(DP[i + a[j]], 1); } } } string res; if (DP[K] == 0) { res = "Second"; } else { res = "First"; } cout << res; }
replace
49
50
49
51
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> dp(k + 1, 0), arr(n); for (int i = 0; i < n; i += 1) { cin >> arr[i]; } for (int i = 0; i <= k; i += 1) { if (dp[i] == 0) { for (int j = 0; j < n; j += 1) { dp[i + arr[j]] = 1; } } } if (dp[k]) { cout << "First"; } else { cout << "Second"; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> dp(k + 1, 0), arr(n); for (int i = 0; i < n; i += 1) { cin >> arr[i]; } for (int i = 0; i <= k; i += 1) { if (dp[i] == 0) { for (int j = 0; j < n; j += 1) { if (i + arr[j] <= k) { dp[i + arr[j]] = 1; } } } } if (dp[k]) { cout << "First"; } else { cout << "Second"; } }
replace
25
26
25
29
0
p03170
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> typedef long long ll; const ll mod = 1e9 + 7; #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define rc(x) return cout << x << "\n", 0 #define sz(s) (int)s.size() #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; ll n, x, k; bool dp[10005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; ll a[k + 2]; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int stones = 0; stones <= k; stones++) { for (int x = 1; x <= n; x++) { if (stones >= a[x] && dp[stones - a[x]] == 0) { dp[stones] = true; break; } } } if (dp[k] == true) { cout << "First"; } else cout << "Second"; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> typedef long long ll; const ll mod = 1e9 + 7; #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define rc(x) return cout << x << "\n", 0 #define sz(s) (int)s.size() #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; ll n, x, k; bool dp[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; ll a[k + 2]; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int stones = 0; stones <= k; stones++) { for (int x = 1; x <= n; x++) { if (stones >= a[x] && dp[stones - a[x]] == 0) { dp[stones] = true; break; } } } if (dp[k] == true) { cout << "First"; } else cout << "Second"; }
replace
19
20
19
20
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second typedef long long ll; typedef double ld; typedef pair<int, int> p2; typedef pair<p2, int> p3; typedef vector<ll> vi; const ll Mod = 7 + 1e9; const ll INF32 = 5 + 2e9; const ll INF64 = 1 + 1e18; const ll MAX = 5 + 100; int N, K, a[MAX], dp[MAX]; 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; i - a[j] >= 0 && j <= N; j++) if (dp[i - a[j]] == 0) { dp[i] = 1; break; } } cout << (dp[K] ? "First" : "Second") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second typedef long long ll; typedef double ld; typedef pair<int, int> p2; typedef pair<p2, int> p3; typedef vector<ll> vi; const ll Mod = 7 + 1e9; const ll INF32 = 5 + 2e9; const ll INF64 = 1 + 1e18; const ll MAX = 5 + 100; int N, K, a[MAX], dp[100005]; 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; i - a[j] >= 0 && j <= N; j++) if (dp[i - a[j]] == 0) { dp[i] = 1; break; } } cout << (dp[K] ? "First" : "Second") << endl; return 0; }
replace
14
15
14
15
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll dp[100005] = {}; int main() { std::ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> v; for (int i = 0; i < n; i++) { ll num; cin >> num; v.push_back(num); } for (int i = 1; i <= k; i++) { for (int j = 0; j < v.size(); j++) { if (dp[i - v[j]] == 0 && i - v[j] >= 0) dp[i] = 1; } } // cout<<dp[k]<<endl; if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll dp[100005] = {}; int main() { std::ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vector<ll> v; for (int i = 0; i < n; i++) { ll num; cin >> num; v.push_back(num); } for (int i = 1; i <= k; i++) { for (int j = 0; j < v.size(); j++) { if (i - v[j] >= 0) { if (dp[i - v[j]] == 0) dp[i] = 1; } } } // cout<<dp[k]<<endl; if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; }
replace
16
18
16
20
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; // how many stones are left bool dp[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; vector<int> a(n); 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 - a[j]] == false && i - a[j] >= 0) { dp[i] = true; } } } puts(dp[k] ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> using namespace std; int n, k; // how many stones are left bool dp[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; vector<int> a(n); 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 (i - a[j] >= 0 && dp[i - a[j]] == false) { dp[i] = true; } } } puts(dp[k] ? "First" : "Second"); return 0; }
replace
16
17
16
17
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define boost_io \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define debug(x) cout << #x << ":" << x << " " #define all(a) (a).begin(), (a).end() #define cast static_cast #define vi vector<int> #define v vector #define p pair #define pb push_back #define mk make_pair typedef long long int ll; typedef long double ld; typedef double d; using namespace std; ll modF = 1e9 + 7; ll INF = 1e11; void solve() { int n, k; cin >> n >> k; vi a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vi dp(k + 1); for (int i = 0; i <= k; i++) { if (i == 0) { dp[i] = 2; } else { int pos = 0; for (int j = 0; j < n && a[j] <= k; j++) { if (dp[i - a[j]] == 2) { pos = 1; break; } } if (pos) { dp[i] = 1; } else { dp[i] = 2; } } } if (dp[k] == 1) { cout << "First\n"; } else { cout << "Second\n"; } } int main() { boost_io; cout << setprecision(10); solve(); return 0; }
#include <bits/stdc++.h> #define boost_io \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define debug(x) cout << #x << ":" << x << " " #define all(a) (a).begin(), (a).end() #define cast static_cast #define vi vector<int> #define v vector #define p pair #define pb push_back #define mk make_pair typedef long long int ll; typedef long double ld; typedef double d; using namespace std; ll modF = 1e9 + 7; ll INF = 1e11; void solve() { int n, k; cin >> n >> k; vi a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vi dp(k + 1); for (int i = 0; i <= k; i++) { if (i == 0) { dp[i] = 2; } else { int pos = 0; for (int j = 0; j < n && a[j] <= i; j++) { if (dp[i - a[j]] == 2) { pos = 1; break; } } if (pos) { dp[i] = 1; } else { dp[i] = 2; } } } if (dp[k] == 1) { cout << "First\n"; } else { cout << "Second\n"; } } int main() { boost_io; cout << setprecision(10); solve(); return 0; }
replace
33
34
33
34
0
p03170
C++
Runtime Error
/*==============================================*\ ID: shahidul_brur Name: Md. Shahidul Islam Study: CSE, BRUR Address: Rangpur, Bangladesh mail: [email protected] FB : fb.com/shahidul.brur Blog: shahidul-brur.blogspot.com(in Bengali), shahidul-brur-en.blogspot.com(in English) \*===============================================*/ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<int, ll> il; typedef vector<ii> vii; typedef vector<il> vil; typedef vector<li> vli; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define all(a) a.begin(), a.end() #define mem(a, b) memset(a, b, sizeof(a)) #define f0(i, b) for (int i = 0; i < (b); i++) #define f1(i, b) for (int i = 1; i <= (b); i++) #define f2(i, a, b) for (int i = (a); i <= (b); i++) #define fr(i, b, a) for (int i = (b); i >= (a); i--) #define rep(i, a, b, c) for (int i = (a); i != (b); i += (c)) int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; const double PI = acos(-1.0); const double EPS = 1e-6; const int MOD = (int)1e9 + 7; const int maxn = 105; const int LOGN = 20; int n, k, a[102]; int win_dp[maxn]; // 1 means win, 0 means lose int cal(int stone) { if (stone < a[1]) return 0; int &win = win_dp[stone]; if (win != -1) return win; win = 0; f1(i, n) if (a[i] <= stone) win |= !cal(stone - a[i]); return win; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> n >> k; f1(i, n) cin >> a[i], win_dp[a[i]] = 1; mem(win_dp, -1); int win = cal(k); if (win) cout << "First\n"; else cout << "Second\n"; return 0; }
/*==============================================*\ ID: shahidul_brur Name: Md. Shahidul Islam Study: CSE, BRUR Address: Rangpur, Bangladesh mail: [email protected] FB : fb.com/shahidul.brur Blog: shahidul-brur.blogspot.com(in Bengali), shahidul-brur-en.blogspot.com(in English) \*===============================================*/ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ll, int> li; typedef pair<int, ll> il; typedef vector<ii> vii; typedef vector<il> vil; typedef vector<li> vli; #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define all(a) a.begin(), a.end() #define mem(a, b) memset(a, b, sizeof(a)) #define f0(i, b) for (int i = 0; i < (b); i++) #define f1(i, b) for (int i = 1; i <= (b); i++) #define f2(i, a, b) for (int i = (a); i <= (b); i++) #define fr(i, b, a) for (int i = (b); i >= (a); i--) #define rep(i, a, b, c) for (int i = (a); i != (b); i += (c)) int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; const double PI = acos(-1.0); const double EPS = 1e-6; const int MOD = (int)1e9 + 7; const int maxn = 100005; const int LOGN = 20; int n, k, a[102]; int win_dp[maxn]; // 1 means win, 0 means lose int cal(int stone) { if (stone < a[1]) return 0; int &win = win_dp[stone]; if (win != -1) return win; win = 0; f1(i, n) if (a[i] <= stone) win |= !cal(stone - a[i]); return win; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> n >> k; f1(i, n) cin >> a[i], win_dp[a[i]] = 1; mem(win_dp, -1); int win = cal(k); if (win) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
50
51
50
51
0
p03170
C++
Runtime Error
//-----by LY02------------------------------------ #include <bits/stdc++.h> using namespace std; #define endl '\n' #define M 1000000007 //------------------------------------------------ int st[110]; int dp[100010]; //------------------------------------------------ int main() { //------------------------------------------------ // freopen("In.txt","r",stdin); // freopen("Out.txt","w",stdout); //------------------------------------------------ ios::sync_with_stdio(0); cin.tie(0); //------------------------------------------------ int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> st[i]; for (int i = 0; i <= k; i++) { for (int j = 0; j < n; j++) { if (j + st[j] > k) continue; if (dp[i] == 0) dp[i + st[j]] = 1; } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; //------------------------------------------------ return 0; } //-----by LY02------------------------------------
//-----by LY02------------------------------------ #include <bits/stdc++.h> using namespace std; #define endl '\n' #define M 1000000007 //------------------------------------------------ int st[110]; int dp[100010]; //------------------------------------------------ int main() { //------------------------------------------------ // freopen("In.txt","r",stdin); // freopen("Out.txt","w",stdout); //------------------------------------------------ ios::sync_with_stdio(0); cin.tie(0); //------------------------------------------------ int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> st[i]; for (int i = 0; i <= k; i++) { for (int j = 0; j < n; j++) { if (i + st[j] > k) continue; if (dp[i] == 0) dp[i + st[j]] = 1; } } if (dp[k]) cout << "First\n"; else cout << "Second\n"; //------------------------------------------------ return 0; } //-----by LY02------------------------------------
replace
27
28
27
28
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pt; typedef pair<ll, ll> pll; #define Max 1000001 #define intinf 2147483647 #define longlonginf 9223372036854775807 #define MOD 998244353 #define MOD2 1000000007 #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define vint vector<int> #define vll vector<long long> #define endl '\n' #define fi first #define se second #define pb push_back #define F(i, n) for (int i = 0; i < n; i++) #define Fr(i, l, r) for (int i = l; i <= r; i++) #define rF(i, n) for (int i = n - 1; i >= 0; i--) #define all(arr) arr.begin(), arr.end() ll Lpow(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2) ans = (ans * a); a = (a * a); b = b / 2; } return ans; } ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(b, a % b); } signed main() { fastio; // cout.flush(); int n, k; cin >> n >> k; vector<int> arr(n); int mi = intinf; F(i, n) { cin >> arr[i]; mi = min(mi, arr[i]); } sort(all(arr)); vector<int> brr(100005, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < mi; j++) { brr[arr[i] + j] = 1; } } for (int i = 1; i <= 100000; i++) { for (int j = 0; j < n; j++) { if (arr[j] < i && brr[i - arr[j]] == 0) brr[i] = 1; } } if (brr[k] == 1) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pt; typedef pair<ll, ll> pll; #define Max 1000001 #define intinf 2147483647 #define longlonginf 9223372036854775807 #define MOD 998244353 #define MOD2 1000000007 #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define vint vector<int> #define vll vector<long long> #define endl '\n' #define fi first #define se second #define pb push_back #define F(i, n) for (int i = 0; i < n; i++) #define Fr(i, l, r) for (int i = l; i <= r; i++) #define rF(i, n) for (int i = n - 1; i >= 0; i--) #define all(arr) arr.begin(), arr.end() ll Lpow(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2) ans = (ans * a); a = (a * a); b = b / 2; } return ans; } ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(b, a % b); } signed main() { fastio; // cout.flush(); int n, k; cin >> n >> k; vector<int> arr(n); int mi = intinf; F(i, n) { cin >> arr[i]; mi = min(mi, arr[i]); } sort(all(arr)); vector<int> brr(100005, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < mi; j++) { if (arr[i] + j <= 100000) brr[arr[i] + j] = 1; } } for (int i = 1; i <= 100000; i++) { for (int j = 0; j < n; j++) { if (arr[j] < i && brr[i - arr[j]] == 0) brr[i] = 1; } } if (brr[k] == 1) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
66
67
66
68
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> // [PRIMES] 1777 ~2^10.80 using namespace std; // 10333 ~2^13.33 using ll = long long; // seq 1 128 | factor 100333 ~2^16.61 using vl = vector<ll>; // | grep -v ' .* ' 1300111 ~2^20.31 using vvl = vector<vl>; // 10300777 ~2^23.30 using vb = vector<bool>; // 100400999 ~2^26.58 using vs = vector<string>; // 1300400999 ~2^30.28 using pll = pair<ll, ll>; // 10200500333 ~2^33.25 const ll oo = 0x3f3f3f3f3f3f3f3fLL; // 100200400777 ~2^36.54 const double eps = 1e-9; // 1200300700111 ~2^40.13 #define sz(c) ll((c).size()) // 10200300500777 ~2^43.21 #define all(c) begin(c), end(c) // 100200300400777 ~2^46.51 #define mp make_pair // 1200300400600999 ~2^50.09 #define mt make_tuple // 10200300400600111 ~2^53.18 #define pb push_back // 100200300400600333 ~2^56.48 #define eb emplace_back // 1200300400500800999 ~2^60.06 #define xx first #define yy second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--) #define TR(X) \ ({ \ if (1) \ cerr << "TR: " << (#X) << " = " << (X) << endl; \ }) using namespace std; ll n, k; vl values; int dp[2][500001]; bool canWin(bool taro, ll missing) { if (dp[taro][missing] != -1) return dp[taro][missing]; bool output; if (missing < values[0]) { output = false; } else { output = false; for (ll value : values) { if (!canWin(!taro, missing - value)) { output = true; break; } } } dp[taro][missing] = output; return output; } int main() { cin.sync_with_stdio(0); cin >> n >> k; FOR(i, 0, 2) { FOR(j, 0, 500001) { dp[i][j] = -1; } } values = vl(n); FOR(i, 0, k) { cin >> values[i]; } if (canWin(true, k)) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> // [PRIMES] 1777 ~2^10.80 using namespace std; // 10333 ~2^13.33 using ll = long long; // seq 1 128 | factor 100333 ~2^16.61 using vl = vector<ll>; // | grep -v ' .* ' 1300111 ~2^20.31 using vvl = vector<vl>; // 10300777 ~2^23.30 using vb = vector<bool>; // 100400999 ~2^26.58 using vs = vector<string>; // 1300400999 ~2^30.28 using pll = pair<ll, ll>; // 10200500333 ~2^33.25 const ll oo = 0x3f3f3f3f3f3f3f3fLL; // 100200400777 ~2^36.54 const double eps = 1e-9; // 1200300700111 ~2^40.13 #define sz(c) ll((c).size()) // 10200300500777 ~2^43.21 #define all(c) begin(c), end(c) // 100200300400777 ~2^46.51 #define mp make_pair // 1200300400600999 ~2^50.09 #define mt make_tuple // 10200300400600111 ~2^53.18 #define pb push_back // 100200300400600333 ~2^56.48 #define eb emplace_back // 1200300400500800999 ~2^60.06 #define xx first #define yy second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--) #define TR(X) \ ({ \ if (1) \ cerr << "TR: " << (#X) << " = " << (X) << endl; \ }) using namespace std; ll n, k; vl values; int dp[2][500001]; bool canWin(bool taro, ll missing) { if (dp[taro][missing] != -1) return dp[taro][missing]; bool output; if (missing < values[0]) { output = false; } else { output = false; for (ll value : values) { if (missing - value < 0) continue; if (!canWin(!taro, missing - value)) { output = true; break; } } } dp[taro][missing] = output; return output; } int main() { cin.sync_with_stdio(0); cin >> n >> k; FOR(i, 0, 2) { FOR(j, 0, 500001) { dp[i][j] = -1; } } values = vl(n); FOR(i, 0, k) { cin >> values[i]; } if (canWin(true, k)) cout << "First" << endl; else cout << "Second" << endl; return 0; }
insert
44
44
44
46
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ops cout << "ops" << endl; #define freopens \ freopen("cowpatibility.in", "r", stdin); \ freopen("cowpatibility.out", "w", stdout); #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DIM 100007 #define DIMM 107 #define INF 1000000000007.0 #define X 31 #define eps 0.0000001 #define PI 3.14159265358979323846 #define MAX 25 #define MODULO (long long)1000000007 const long double gr = (1 + sqrt(5)) / 2; typedef int I; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<I, I> pII; typedef pair<ll, ll> pllll; typedef pair<ld, ld> pldld; typedef vector<I> vI; typedef vector<ll> vll; typedef vector<pllll> vpllll; typedef char cr; typedef string str; ll n, k; ll ma; ll a[DIMM], dp[DIM]; int main() { // ops; // freopens; fast; // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4; 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 (dp[i - a[j]] == 0) { dp[i] = 1; break; } } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ops cout << "ops" << endl; #define freopens \ freopen("cowpatibility.in", "r", stdin); \ freopen("cowpatibility.out", "w", stdout); #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DIM 100007 #define DIMM 107 #define INF 1000000000007.0 #define X 31 #define eps 0.0000001 #define PI 3.14159265358979323846 #define MAX 25 #define MODULO (long long)1000000007 const long double gr = (1 + sqrt(5)) / 2; typedef int I; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<I, I> pII; typedef pair<ll, ll> pllll; typedef pair<ld, ld> pldld; typedef vector<I> vI; typedef vector<ll> vll; typedef vector<pllll> vpllll; typedef char cr; typedef string str; ll n, k; ll ma; ll a[DIMM], dp[DIM]; int main() { // ops; // freopens; fast; // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4; 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 - a[j]] == 0) { dp[i] = 1; break; } } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
56
57
56
57
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; #define debug(x) cerr << #x << " = " << (x) << endl; template <typename T> ostream &operator<<(ostream &o, vector<T> &v) { for (auto &x : v) o << x << ' '; return o; } int n, k; int arr[110]; int memo[100100]; int dp(int k) { int &res = memo[k]; if (res != -1) return res; if (k == 0) return res = 0; for (int i = 0; i < n; i++) { if (arr[i] <= k) { if (dp(k) == 0) return res = 1; } } return res = 0; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; memset(memo, -1, sizeof memo); if (dp(k)) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; #define debug(x) cerr << #x << " = " << (x) << endl; template <typename T> ostream &operator<<(ostream &o, vector<T> &v) { for (auto &x : v) o << x << ' '; return o; } int n, k; int arr[110]; int memo[100100]; int dp(int k) { int &res = memo[k]; if (res != -1) return res; if (k == 0) return res = 0; for (int i = 0; i < n; i++) { if (arr[i] <= k) { if (dp(k - arr[i]) == 0) return res = 1; } } return res = 0; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; memset(memo, -1, sizeof memo); if (dp(k)) cout << "First" << endl; else cout << "Second" << endl; }
replace
28
29
28
29
-11
p03170
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, k; int v[102]; int dp[100002]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> v[i]; // 2 = losing state, 1 = winning state for (int i = 0; i < k; ++i) { if (dp[i] == 0) dp[i] = 2; for (int j = 1; j <= n; ++j) { if (dp[i + v[j]] == 1 || i + v[j] > k) continue; dp[i + v[j]] = 3 - dp[i]; } } if (dp[k] == 1) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, k; int v[102]; int dp[100002]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> v[i]; // 2 = losing state, 1 = winning state for (int i = 0; i < k; ++i) { if (dp[i] == 0) dp[i] = 2; for (int j = 1; j <= n; ++j) { if (i + v[j] > k || dp[i + v[j]] == 1) continue; dp[i + v[j]] = 3 - dp[i]; } } if (dp[k] == 1) cout << "First"; else cout << "Second"; return 0; }
replace
17
18
17
18
0
p03170
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const int inf = 1 << 30; bool dp[110]; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(i, k + 1) { rep(j, n) { if (i - a[j] >= 0) dp[i] |= (!dp[i - a[j]]); } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const int inf = 1 << 30; bool dp[100010]; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; rep(i, k + 1) { rep(j, n) { if (i - a[j] >= 0) dp[i] |= (!dp[i - a[j]]); } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; }
replace
25
26
25
26
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v(n), dp(k + 1); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i <= k; i++) { if (!dp[i]) for (auto x : v) dp[i + x] = 1; } cout << (dp[k] ? "First" : "Second"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v(n), dp(k + 1); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i <= k; i++) { if (!dp[i]) for (auto x : v) if (i + x <= k) dp[i + x] = 1; } cout << (dp[k] ? "First" : "Second"); return 0; }
replace
12
13
12
14
0
p03170
C++
Runtime Error
// _____ _______ _____ _____ // /\ \ /::\ \ /\ \ /\ \ // /::\ \ /::::\ \ /::\____\ /::\ \ // /::::\ \ /::::::\ \ /:::/ / /::::\ \ // /::::::\ \ /::::::::\ \ /:::/ / // /::::::\ \ // /:::/\:::\ \ /:::/~~\:::\ \ /:::/ / // /:::/\:::\ \ // /:::/__\:::\ \ /:::/ \:::\ \ /:::/ / /:::/__\:::\ \ // /::::\ \:::\ \ /:::/ / \:::\ \ /:::/ / /::::\ \:::\ // \ // /::::::\ \:::\ \ /:::/____/ \:::\____\ /:::/ / _____ // /::::::\ \:::\ \ // /:::/\:::\ \:::\ \|:::| | |:::| |/:::/____/ // /\ \ /:::/\:::\ \:::\ \ // /:::/ \:::\ \:::\____|:::|____| |:::|____|:::| / /::\____/:::/ // \:::\ \:::\____\ // \::/ \:::\ /:::/ /\:::\ _\___/:::/ /|:::|____\ /:::/ \::/ // \:::\ /:::/ / // \/____/ \:::\/:::/ / \:::\ |::| /:::/ / \:::\ \ /:::/ / // \/____/ \:::\/:::/ / // \::::::/ / \:::\|::|/:::/ / \:::\ \ /:::/ / // \::::::/ / // \::::/ / \::::::::::/ / \:::\ /:::/ / \::::/ // / // /:::/ / \::::::::/ / \:::\__/:::/ / /:::/ / // /:::/ / \::::::/ / \::::::::/ / /:::/ / // /:::/ / \::::/____/ \::::::/ / /:::/ / // /:::/ / |::| | \::::/ / /:::/ / // \::/ / |::|____| \::/____/ \::/ / // \/____/ ~~ ~~ \/____/ // I am aqua #include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define mp make_pair #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define fo \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define l first #define r second #define input \ .txt ifstream fin("input.txt"); \ ofstream fout("output.txt"); using namespace std; //--------------------------------------------------------------------------------------------------------------------- const int maxn = 10 + 1e2; const int maxk = 10 + 1e5; //--------------------------------------------------------------------------------------------------------------------- int n, m, a[maxn], dp[maxn]; //--------------------------------------------------------------------------------------------------------------------- int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 2; for (int i = 1; i <= m; i++) { bool b = false, k = false; for (int j = 0; j < n; j++) { if (i - a[j] >= 0 and (dp[i - a[j]] == 2 or dp[i - a[j]] == 0)) { b = true; break; } if (i - a[j] >= 0) k = true; } if (b == true) { dp[i] = 1; } else if (k == true) dp[i] = 2; } if (dp[m] == 0 or dp[m] == 2) cout << "Second"; else cout << "First"; } // I know that ; // I know where I am // Do not think I don't
// _____ _______ _____ _____ // /\ \ /::\ \ /\ \ /\ \ // /::\ \ /::::\ \ /::\____\ /::\ \ // /::::\ \ /::::::\ \ /:::/ / /::::\ \ // /::::::\ \ /::::::::\ \ /:::/ / // /::::::\ \ // /:::/\:::\ \ /:::/~~\:::\ \ /:::/ / // /:::/\:::\ \ // /:::/__\:::\ \ /:::/ \:::\ \ /:::/ / /:::/__\:::\ \ // /::::\ \:::\ \ /:::/ / \:::\ \ /:::/ / /::::\ \:::\ // \ // /::::::\ \:::\ \ /:::/____/ \:::\____\ /:::/ / _____ // /::::::\ \:::\ \ // /:::/\:::\ \:::\ \|:::| | |:::| |/:::/____/ // /\ \ /:::/\:::\ \:::\ \ // /:::/ \:::\ \:::\____|:::|____| |:::|____|:::| / /::\____/:::/ // \:::\ \:::\____\ // \::/ \:::\ /:::/ /\:::\ _\___/:::/ /|:::|____\ /:::/ \::/ // \:::\ /:::/ / // \/____/ \:::\/:::/ / \:::\ |::| /:::/ / \:::\ \ /:::/ / // \/____/ \:::\/:::/ / // \::::::/ / \:::\|::|/:::/ / \:::\ \ /:::/ / // \::::::/ / // \::::/ / \::::::::::/ / \:::\ /:::/ / \::::/ // / // /:::/ / \::::::::/ / \:::\__/:::/ / /:::/ / // /:::/ / \::::::/ / \::::::::/ / /:::/ / // /:::/ / \::::/____/ \::::::/ / /:::/ / // /:::/ / |::| | \::::/ / /:::/ / // \::/ / |::|____| \::/____/ \::/ / // \/____/ ~~ ~~ \/____/ // I am aqua #include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define mp make_pair #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define fo \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define l first #define r second #define input \ .txt ifstream fin("input.txt"); \ ofstream fout("output.txt"); using namespace std; //--------------------------------------------------------------------------------------------------------------------- const int maxn = 10 + 1e2; const int maxk = 10 + 1e5; //--------------------------------------------------------------------------------------------------------------------- int n, m, a[maxn], dp[maxk]; //--------------------------------------------------------------------------------------------------------------------- int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; dp[0] = 2; for (int i = 1; i <= m; i++) { bool b = false, k = false; for (int j = 0; j < n; j++) { if (i - a[j] >= 0 and (dp[i - a[j]] == 2 or dp[i - a[j]] == 0)) { b = true; break; } if (i - a[j] >= 0) k = true; } if (b == true) { dp[i] = 1; } else if (k == true) dp[i] = 2; } if (dp[m] == 0 or dp[m] == 2) cout << "Second"; else cout << "First"; } // I know that ; // I know where I am // Do not think I don't
replace
57
58
57
58
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define INF 2e9 #define INF_LL 1LL << 60 #define ll long long #define MOD 1e9 + 7 #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } #define print_line(vec, n) \ { \ for (int i = 0; i < (n - 1); i++) \ cout << (vec)[i] << " "; \ cout << (vec)[(n)-1] << endl; \ } template <class T> void print(const T &x) { cout << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; /* ๆฎ‹ใ‚Šiๆžšใงๅ›žใฃใฆใใŸใจใใใฎไบบใŒๅ‹ใฆใ‚‹ใ‹ใฉใ†ใ‹ */ bool dp[10001]; int main() { int N, K; cin >> N >> K; vector<int> a(N); REP(i, N) cin >> a[i]; REPN(i, 1, K + 1) REP(j, N) { dp[i] |= (a[j] <= i) && (!dp[i - a[j]]); } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define INF 2e9 #define INF_LL 1LL << 60 #define ll long long #define MOD 1e9 + 7 #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } #define print_line(vec, n) \ { \ for (int i = 0; i < (n - 1); i++) \ cout << (vec)[i] << " "; \ cout << (vec)[(n)-1] << endl; \ } template <class T> void print(const T &x) { cout << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; /* ๆฎ‹ใ‚Šiๆžšใงๅ›žใฃใฆใใŸใจใใใฎไบบใŒๅ‹ใฆใ‚‹ใ‹ใฉใ†ใ‹ */ bool dp[100001]; int main() { int N, K; cin >> N >> K; vector<int> a(N); REP(i, N) cin >> a[i]; REPN(i, 1, K + 1) REP(j, N) { dp[i] |= (a[j] <= i) && (!dp[i - a[j]]); } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
38
39
38
39
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int dp[100006]; int arr[106]; int n; int fun(int k) { if (k == 0) return 0; if (dp[k] != -1) return dp[k]; int ans = 0; for (int i = 0; i < n; i++) { if (arr[i] <= k) ans |= (!fun(k - arr[i])); } // cout<<k<<" "<<ans<<endl; return dp[n] = ans; } int main() { int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < k; i++) dp[i + 1] = -1; if (fun(k) == 0) cout << "Second" << endl; else cout << "First" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100006]; int arr[106]; int n; int fun(int k) { if (k == 0) return 0; if (dp[k] != -1) return dp[k]; int ans = 0; for (int i = 0; i < n; i++) { if (arr[i] <= k) ans |= (!fun(k - arr[i])); } // cout<<k<<" "<<ans<<endl; return dp[k] = ans; } int main() { int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < k; i++) dp[i + 1] = -1; if (fun(k) == 0) cout << "Second" << endl; else cout << "First" << endl; return 0; }
replace
21
22
21
22
TLE
p03170
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i <= n - 1; i++) cin >> a[i]; vector<bool> dp(k + 1, false); dp[a[0]] = true; for (int i = a[0] + 1; i <= k; i++) { for (auto j : a) { if (dp[i - j] == false) { dp[i] = true; break; } } } cout << (dp[k] ? "First" : "Second"); return 0; }
#include <iostream> #include <vector> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i <= n - 1; i++) cin >> a[i]; vector<bool> dp(k + 1, false); dp[a[0]] = true; for (int i = a[0] + 1; i <= k; i++) { for (auto j : a) { if (i >= j and dp[i - j] == false) { dp[i] = true; break; } } } cout << (dp[k] ? "First" : "Second"); return 0; }
replace
25
26
25
26
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define mod 1000000007 using namespace std; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin>>t; while (t--) { int n, k; cin >> n >> k; ll arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); ll dp[k + 1]; dp[0] = 1; for (int i = 1; i < arr[0]; i++) { dp[i] = 1; } dp[arr[0]] = 0; for (int i = arr[0] + 1; i <= k; i++) { vector<int> res; for (int j = 0; j < n; j++) { if (arr[j] > i) { break; } else { res.push_back(dp[i - arr[j]]); } } if (find(res.begin(), res.end(), 1) != res.end()) { dp[i] = 0; } else dp[i] = 1; } if (dp[k] == 0) { cout << "First" << endl; } else cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define mod 1000000007 using namespace std; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin>>t; while (t--) { int n, k; cin >> n >> k; ll arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); ll dp[k + 1]; dp[0] = 1; for (int i = 1; i < arr[0]; i++) { dp[i] = 1; } dp[arr[0]] = 0; for (int i = arr[0] + 1; i <= k; i++) { vector<int> res; for (int j = 0; j < n; j++) { if (arr[j] > i) { break; } else { res.push_back(dp[i - arr[j]]); } } if (find(res.begin(), res.end(), 1) != res.end()) { dp[i] = 0; } else dp[i] = 1; } if (dp[k] == 0) { cout << "First" << endl; } else cout << "Second" << endl; } return 0; }
replace
7
11
7
8
-11
p03170
C++
Runtime Error
#include <iomanip> #include <iostream> #include <map> #include <vector> using namespace std; #define MOD 1000000007 int N, K; int a[100]; int dp[100001]; int dfs(int x) { if (dp[x] != -1) return dp[x]; for (int i = 0; i < N; i++) { dp[x - a[i]] = dfs(x - a[i]); if (dp[x - a[i]] == 0) { dp[x] = 1; return 1; } } dp[x] = 0; return 0; } int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> a[i]; fill_n(dp, K + 1, -1); for (int i = 0; i < a[0]; i++) dp[i] = 0; cout << (dfs(K) ? "First" : "Second") << endl; return 0; }
#include <iomanip> #include <iostream> #include <map> #include <vector> using namespace std; #define MOD 1000000007 int N, K; int a[100]; int dp[100001]; int dfs(int x) { if (dp[x] != -1) return dp[x]; for (int i = 0; i < N; i++) { if (x - a[i] < 0) continue; dp[x - a[i]] = dfs(x - a[i]); if (dp[x - a[i]] == 0) { dp[x] = 1; return 1; } } dp[x] = 0; return 0; } int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> a[i]; fill_n(dp, K + 1, -1); for (int i = 0; i < a[0]; i++) dp[i] = 0; cout << (dfs(K) ? "First" : "Second") << endl; return 0; }
insert
16
16
16
18
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef pair<bool, int> pbi; int arr[105]; map<pbi, bool> mp; bool play(bool turn, int n, int k) { if (k == 0) return turn; pbi temp = pbi(turn, k); auto it = mp.begin(); if ((it = mp.find(temp)) != mp.end()) return it->second; bool flag = turn; for (int i = 0; i < n; ++i) { if (k >= arr[i]) { if (!turn) flag |= play(!turn, n, k - arr[i]); else flag &= play(!turn, n, k - arr[i]); } if ((!turn && flag) || (turn && !flag)) break; } return mp[temp] = flag; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> arr[i]; } if (play(0, n, k)) cout << "First\n"; else cout << "Second\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<bool, int> pbi; int arr[105]; struct hasher { size_t operator()(const pbi &temp) const { return hash<bool>()(temp.first) ^ hash<int>()(temp.second); } }; unordered_map<pbi, bool, hasher> mp; bool play(bool turn, int n, int k) { if (k == 0) return turn; pbi temp = pbi(turn, k); auto it = mp.begin(); if ((it = mp.find(temp)) != mp.end()) return it->second; bool flag = turn; for (int i = 0; i < n; ++i) { if (k >= arr[i]) { if (!turn) flag |= play(!turn, n, k - arr[i]); else flag &= play(!turn, n, k - arr[i]); } if ((!turn && flag) || (turn && !flag)) break; } return mp[temp] = flag; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> arr[i]; } if (play(0, n, k)) cout << "First\n"; else cout << "Second\n"; return 0; }
replace
4
5
4
10
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define ll long long using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } int dp[101]; memset(dp, 0, sizeof(dp)); dp[0] = -1; for (int i = 1; i <= k; i++) { bool f = true; rep(j, n) { if (i >= a[j]) { if (dp[i - a[j]] == -1) { dp[i] = a[j]; f = false; break; } } } if (f) dp[i] = -1; // rep(i, k+1)cout<<dp[i]<<' ';cout<<endl; } if (dp[k] != -1) cout << "First" << endl; else cout << "Second" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define ll long long using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } int dp[100001]; memset(dp, 0, sizeof(dp)); dp[0] = -1; for (int i = 1; i <= k; i++) { bool f = true; rep(j, n) { if (i >= a[j]) { if (dp[i - a[j]] == -1) { dp[i] = a[j]; f = false; break; } } } if (f) dp[i] = -1; // rep(i, k+1)cout<<dp[i]<<' ';cout<<endl; } if (dp[k] != -1) cout << "First" << endl; else cout << "Second" << endl; return 0; }
replace
13
14
13
14
0
p03170
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:512000000") #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <ccomplex> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #ifdef ONLINE_JUDGE #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") #pragma GCC optimize("unroll-loops") #endif // 4Head #define all(x) x.begin(), x.end() #define mp make_pair #define X first #define Y second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937_64 gen(time(nullptr)); ll const mod = 1e9 + 7; namespace { ll mul(ll a, ll b) { ll val = a * b - (ll)((ld)a * b / mod) * mod; if (val < 0) val += mod; if (val >= mod) val -= mod; return val; } ll poww(ll a, ll b) { ll val = 1; a %= mod; while (b > 0) { if (b % 2) val = mul(a, val); a = mul(a, a); b >>= 1; } return val % mod; } ll inv(ll a) { return poww(a, mod - 2); } } // namespace int const maxn = 3e5 + 5; int dp[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 < a[0]; i++) { dp[i] = 0; } for (int i = a[0]; i < maxn; i++) { bool can = false; for (int x : a) { if (dp[i - x] == 0) can = true; } dp[i] = can; } cout << (dp[k] == 1 ? "First" : "Second") << endl; return 0; } /* 5 2 6 15 5 10 4 2 6 15 5 */
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:512000000") #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <ccomplex> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #ifdef ONLINE_JUDGE #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") #pragma GCC optimize("unroll-loops") #endif // 4Head #define all(x) x.begin(), x.end() #define mp make_pair #define X first #define Y second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937_64 gen(time(nullptr)); ll const mod = 1e9 + 7; namespace { ll mul(ll a, ll b) { ll val = a * b - (ll)((ld)a * b / mod) * mod; if (val < 0) val += mod; if (val >= mod) val -= mod; return val; } ll poww(ll a, ll b) { ll val = 1; a %= mod; while (b > 0) { if (b % 2) val = mul(a, val); a = mul(a, a); b >>= 1; } return val % mod; } ll inv(ll a) { return poww(a, mod - 2); } } // namespace int const maxn = 3e5 + 5; int dp[maxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 < a[0]; i++) { dp[i] = 0; } for (int i = a[0]; i < maxn; i++) { bool can = false; for (int x : a) { if (x > i) break; if (dp[i - x] == 0) can = true; } dp[i] = can; } cout << (dp[k] == 1 ? "First" : "Second") << endl; return 0; } /* 5 2 6 15 5 10 4 2 6 15 5 */
insert
93
93
93
95
0
p03170
C++
Runtime Error
#include "bits/stdc++.h" #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) #define f(i, a, b) for (i = a; i < b; i++) using namespace std; int n, k, ar[105], dp[100005][2], mn; int fun(int rem, int x) { int i; if (rem < mn) return dp[rem][x] = x ^ 1; if (dp[rem][x] != -1) return dp[rem][x]; dp[rem][x] = x ^ 1; f(i, 0, n) { if (x) dp[rem][x] = max(dp[rem][x], fun(rem - ar[i], x ^ 1)); else dp[rem][x] = min(dp[rem][x], fun(rem - ar[i], x ^ 1)); } return dp[rem][x]; } int main() { fast; int i; cin >> n >> k; f(i, 0, n) cin >> ar[i]; mn = *min_element(ar, ar + n); memset(dp, -1, sizeof(dp)); (fun(k, 1)) ? cout << "First" : cout << "Second"; }
#include "bits/stdc++.h" #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) #define f(i, a, b) for (i = a; i < b; i++) using namespace std; int n, k, ar[105], dp[100005][2], mn; int fun(int rem, int x) { int i; if (rem < mn) return dp[rem][x] = x ^ 1; if (dp[rem][x] != -1) return dp[rem][x]; dp[rem][x] = x ^ 1; f(i, 0, n) { if (ar[i] <= rem) { if (x) dp[rem][x] |= fun(rem - ar[i], x ^ 1); else dp[rem][x] &= fun(rem - ar[i], x ^ 1); } } return dp[rem][x]; } int main() { fast; int i; cin >> n >> k; f(i, 0, n) cin >> ar[i]; mn = *min_element(ar, ar + n); memset(dp, -1, sizeof(dp)); (fun(k, 1)) ? cout << "First" : cout << "Second"; }
replace
21
25
21
27
0
p03170
C++
Runtime Error
#include <cstdio> #include <cstring> #define N 110 using namespace std; int n, k; int dp[N][2]; int a[N]; 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; } signed 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) == true) puts("First"); else puts("Second"); }
#include <cstdio> #include <cstring> #define N 100010 using namespace std; int n, k; int dp[N][2]; int a[N]; 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; } signed 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) == true) puts("First"); else puts("Second"); }
replace
2
3
2
3
0
p03170
C++
Runtime Error
/** e==m*pow(c,2) **/ #include <bits/stdc++.h> using namespace std; #define DEBUG 0 #define LL long long #define int long long // #define OFFLINE 2585 #define pii pair<int, int> #define SQR(n) (n * n) #define pb push_back // #define endl '\n' #define yes cout << "YES" << endl #define no cout << "NO" << endl #define INF 100000000000 #define PI (acos(0.0) * 2.0) #define time_start clock_t tStart = clock() #define time_end (double)(clock() - tStart) / CLOCKS_PER_SEC #define maxn 100009 // #pragma GCC diagnostic warning "-std=c++11" #define check(n, i) (int)(bool(!((n) & (1 << (i))))) #define set(n, i) (((n) | (1 << (i)))) #define mod 100000007 #define dbg(a) cout << #a << " = " << a << endl; void faster(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int lcm(int a, int b) { return (a * b) / __gcd(a, b); } int32_t main() { #ifdef ONPC freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif faster(); bool dp[100009]; memset(dp, 0, sizeof(dp)); int n, k, i, j, ara[105]; cin >> n >> k; for (i = 0; i < n; i++) cin >> ara[i]; for (i = 0; i <= k; i++) { for (j = 0; j < n; j++) { // cout<<i<<' '<<dp[i]<<' '<<j<<' '<<ara[j]<<endl; // if(dp[i+ara[j]]==1) continue; // else if(dp[i]==0) dp[i+ara[j]]=1; dp[i + ara[j]] = max((int)dp[i] ^ 1, (int)dp[i + ara[j]]); } } if (DEBUG) for (i = 0; i <= k; i++) cout << i << ' ' << dp[i] << endl; cout << (dp[k] ? "First" : "Second") << endl; return 0; }
/** e==m*pow(c,2) **/ #include <bits/stdc++.h> using namespace std; #define DEBUG 0 #define LL long long #define int long long // #define OFFLINE 2585 #define pii pair<int, int> #define SQR(n) (n * n) #define pb push_back // #define endl '\n' #define yes cout << "YES" << endl #define no cout << "NO" << endl #define INF 100000000000 #define PI (acos(0.0) * 2.0) #define time_start clock_t tStart = clock() #define time_end (double)(clock() - tStart) / CLOCKS_PER_SEC #define maxn 100009 // #pragma GCC diagnostic warning "-std=c++11" #define check(n, i) (int)(bool(!((n) & (1 << (i))))) #define set(n, i) (((n) | (1 << (i)))) #define mod 100000007 #define dbg(a) cout << #a << " = " << a << endl; void faster(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int lcm(int a, int b) { return (a * b) / __gcd(a, b); } int32_t main() { #ifdef ONPC freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif faster(); bool dp[100009]; memset(dp, 0, sizeof(dp)); int n, k, i, j, ara[105]; cin >> n >> k; for (i = 0; i < n; i++) cin >> ara[i]; for (i = 0; i <= k; i++) { for (j = 0; j < n; j++) { // cout<<i<<' '<<dp[i]<<' '<<j<<' '<<ara[j]<<endl; // if(dp[i+ara[j]]==1) continue; // else if(dp[i]==0) dp[i+ara[j]]=1; if (i + ara[j] <= k) dp[i + ara[j]] = max((int)dp[i] ^ 1, (int)dp[i + ara[j]]); } } if (DEBUG) for (i = 0; i <= k; i++) cout << i << ' ' << dp[i] << endl; cout << (dp[k] ? "First" : "Second") << endl; return 0; }
replace
50
51
50
52
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MAX 100005 int who[MAX]; int main() { int n, k, lm = MAX; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] < lm) lm = a[i]; } for (int i = 0; i < lm; i++) who[i] = 2; for (int i = lm; i <= k; i++) { for (int j = 0; j < n; j++) { if (who[i - a[j]] == 2) { who[i] = 1; break; } } if (who[i] == 0) who[i] = 2; } if (who[k] == 1) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> using namespace std; #define MAX 100005 int who[MAX]; int main() { int n, k, lm = MAX; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] < lm) lm = a[i]; } for (int i = 0; i < lm; i++) who[i] = 2; for (int i = lm; i <= k; i++) { for (int j = 0; j < n; j++) { if (i - a[j] < 0) continue; if (who[i - a[j]] == 2) { who[i] = 1; break; } } if (who[i] == 0) who[i] = 2; } if (who[k] == 1) cout << "First"; else cout << "Second"; }
insert
26
26
26
28
0
p03170
C++
Runtime Error
// ~/SolverToBe/Developers/Corvus // ~/sudo apt-get verdict Accpeted #include <algorithm> #include <assert.h> #include <bitset> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 105, M = 1000005; const ll MOD = 1e9 + 7; const double eps = 1e-9; int n, k, a[N], dp[2][100005]; int calc(int i, int rem) { if (rem == 0) return i ^ 1; int &r = dp[i][rem]; if (r != -1) return r; r = i ^ 1; for (int j = 0; j < n; j++) if (rem >= a[i] && calc(i ^ 1, rem - a[j]) == i) { r = i; break; } return r; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); memset(dp, -1, sizeof dp); printf("%s\n", calc(0, k) == 0 ? "First" : "Second"); return 0; }
// ~/SolverToBe/Developers/Corvus // ~/sudo apt-get verdict Accpeted #include <algorithm> #include <assert.h> #include <bitset> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 105, M = 1000005; const ll MOD = 1e9 + 7; const double eps = 1e-9; int n, k, a[N], dp[2][100005]; int calc(int i, int rem) { if (rem == 0) return i ^ 1; int &r = dp[i][rem]; if (r != -1) return r; r = i ^ 1; for (int j = 0; j < n; j++) if (rem >= a[j] && calc(i ^ 1, rem - a[j]) == i) { r = i; break; } return r; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); memset(dp, -1, sizeof dp); printf("%s\n", calc(0, k) == 0 ? "First" : "Second"); return 0; }
replace
44
45
44
45
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define FASTIO #define endl \ "\n" // Since endl forces a buffer flush which slows down large I/O // operations. #define ff first #define ss second #define pb push_back #define input(c, n) \ for (int i = 0; i < (n); i++) \ cin >> (c)[i]; #define exit_message(s) return 0 * printf(s) #define show(c) \ for (auto i : (c)) \ cout << i << " "; \ cout << "\n"; #define display(c, n) \ for (int i = 0; i < (n); i++) \ cout << (c)[i] << " "; \ cout << "\n"; #define forl(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n"; /* TIPS FOR DEBUGGING * Check if values are not overflowing (use long long where required) * Check if ranges are inclusive or not. * Check properly if greedy will work or not before using it. * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being * 2 minutes faster will bite you in the ass if you don't make sure * it works on edge cases. * Keep adding to this list. */ using namespace std; typedef long long ll; typedef pair<int, int> pr; typedef pair<ll, ll> prll; typedef vector<int> vi; typedef vector<ll> vill; typedef vector<pr> vpr; ifstream in("input.txt"); const ll mod = 1e9 + 7; ll mod_pow(ll a, ll b) { if (b == 0) return 1LL; ll res = mod_pow(a, b >> 1); res = (res * res) % mod; if (b & 1LL) res = (res * a) % mod; return res; } const int N = 100 + 5; const int SZ = 1e5 + 5; int n, k; int a[N]; int dp[SZ][2]; int solve(int k, int plaiya) { if (k < 0) return 1; int win = 0; for (int i = 0; i < n; i++) { win |= !(solve(k - a[i], plaiya ^ 1)); } return win; } int32_t main() { #ifdef FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #endif // freopen("in.txt", "r", stdin); // freopen("output.txt", "w", stdout); memset(dp, -1, sizeof dp); cin >> n >> k; forl(i, 0, n) { cin >> a[i]; } int ans = solve(k, 0); cout << (ans ? "First" : "Second") << "\n"; return 0; }
#include <bits/stdc++.h> #define FASTIO #define endl \ "\n" // Since endl forces a buffer flush which slows down large I/O // operations. #define ff first #define ss second #define pb push_back #define input(c, n) \ for (int i = 0; i < (n); i++) \ cin >> (c)[i]; #define exit_message(s) return 0 * printf(s) #define show(c) \ for (auto i : (c)) \ cout << i << " "; \ cout << "\n"; #define display(c, n) \ for (int i = 0; i < (n); i++) \ cout << (c)[i] << " "; \ cout << "\n"; #define forl(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n"; /* TIPS FOR DEBUGGING * Check if values are not overflowing (use long long where required) * Check if ranges are inclusive or not. * Check properly if greedy will work or not before using it. * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being * 2 minutes faster will bite you in the ass if you don't make sure * it works on edge cases. * Keep adding to this list. */ using namespace std; typedef long long ll; typedef pair<int, int> pr; typedef pair<ll, ll> prll; typedef vector<int> vi; typedef vector<ll> vill; typedef vector<pr> vpr; ifstream in("input.txt"); const ll mod = 1e9 + 7; ll mod_pow(ll a, ll b) { if (b == 0) return 1LL; ll res = mod_pow(a, b >> 1); res = (res * res) % mod; if (b & 1LL) res = (res * a) % mod; return res; } const int N = 100 + 5; const int SZ = 1e5 + 5; int n, k; int a[N]; int dp[SZ][2]; int solve(int k, int plaiya) { if (k < 0) return 1; int &win = dp[k][plaiya]; if (win != -1) return win; win = 0; for (int i = 0; i < n; i++) { win |= !(solve(k - a[i], plaiya ^ 1)); } return win; } int32_t main() { #ifdef FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #endif // freopen("in.txt", "r", stdin); // freopen("output.txt", "w", stdout); memset(dp, -1, sizeof dp); cin >> n >> k; forl(i, 0, n) { cin >> a[i]; } int ans = solve(k, 0); cout << (ans ? "First" : "Second") << "\n"; return 0; }
replace
65
66
65
71
TLE
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() using namespace std; const int INF = 1145141919, MOD = 1e9 + 7; const long long LINF = 8931145141919364364, LMOD = 998244353; inline long long mod(long long n, long long m) { return (n % m + m) % m; } // const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int n, k; int a[110]; // dp[i][j]:=iๆฎ‹ใ—ใฆjใซๅ›žใ—ใŸใจใใฎๅ‹ๆ•— int dp[100010][2]; int dfs(int num, int who) { // cout<<num<<endl; if (dp[num][who] != -1) return dp[num][who]; int ret = (who + 1) % 2; bool flg = 1; rep(i, n) { if (num - a[i] >= 0) { int tmp = dfs(num - a[i], (who + 1) % 2); if (tmp == who) ret = tmp; flg = 0; } } if (flg) { dp[num][who] = (who + 1) % 2; return dp[num][who]; } return ret; } int main() { cin >> n >> k; rep(i, n) cin >> a[i]; if (n == 1) { cout << (k / a[0] % 2 ? "First" : "Second") << endl; return 0; } rep(i, 100010) rep(j, 2) dp[i][j] = -1; cout << (dfs(k, 0) ? "Second" : "First") << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() using namespace std; const int INF = 1145141919, MOD = 1e9 + 7; const long long LINF = 8931145141919364364, LMOD = 998244353; inline long long mod(long long n, long long m) { return (n % m + m) % m; } // const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1}; int n, k; int a[110]; // dp[i][j]:=iๆฎ‹ใ—ใฆjใซๅ›žใ—ใŸใจใใฎๅ‹ๆ•— int dp[100010][2]; int dfs(int num, int who) { // cout<<num<<endl; if (dp[num][who] != -1) return dp[num][who]; int ret = (who + 1) % 2; bool flg = 1; rep(i, n) { if (num - a[i] >= 0) { int tmp = dfs(num - a[i], (who + 1) % 2); if (tmp == who) ret = tmp; flg = 0; } } dp[num][who] = ret; return dp[num][who]; } int main() { cin >> n >> k; rep(i, n) cin >> a[i]; if (n == 1) { cout << (k / a[0] % 2 ? "First" : "Second") << endl; return 0; } rep(i, 100010) rep(j, 2) dp[i][j] = -1; cout << (dfs(k, 0) ? "Second" : "First") << endl; return 0; }
replace
27
32
27
29
TLE
p03170
C++
Runtime Error
/* ___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat. ___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat. ___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb. ___az dast o zabane ke barayad ? ___kaz ohdeye shokrash be dar ayad ! ___man be to dami gharar natvanam kard ___va ehsane to ra shomar natvanam kard #################### ___gar bar tane man zaban shavad har moyee ___yek shokre to az hezar natvanam kard */ #include <bits/stdc++.h> #define pb push_back #define SALI main #define left(x) ((x)*2) #define right(x) (((x)*2) + 1) #define fuck(x) cout << #x << " : " << x << " "; #define findLowVec(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define findUpVec(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define findLowArr(a, n, x) (lower_bound(a, a + n, x) - a) #define findUpArr(a, n, x) (upper_bound(a, a + n, x) - a) #define int long long using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &p) { return out << "(" << p.first << ", " << p.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &v) { out << "["; for (int i = 0; i < v.size(); i++) { if (i) out << ", "; out << v[i]; } return out << "]"; } template <class A, class B> ostream &operator<<(ostream &out, const set<A, B> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } template <class A> ostream &operator<<(ostream &out, const set<A> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } const int N = 1e5 + 10; int a[110]; int dp[N]; int n; int solve(int k) { if (dp[k] != 0) { return dp[k]; } if (k < a[0]) { dp[k] = -1; return -1; } bool win = false; for (int i = 0; i < n; i++) { if (solve(k - a[i]) == -1) { win = true; } } dp[k] = (win ? 1 : -1); return dp[k]; } int32_t SALI() { int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; cout << (solve(k) == 1 ? "First" : "Second"); } /**< WRITEN BY ALI ADELKHAH */
/* ___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat. ___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat. ___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb. ___az dast o zabane ke barayad ? ___kaz ohdeye shokrash be dar ayad ! ___man be to dami gharar natvanam kard ___va ehsane to ra shomar natvanam kard #################### ___gar bar tane man zaban shavad har moyee ___yek shokre to az hezar natvanam kard */ #include <bits/stdc++.h> #define pb push_back #define SALI main #define left(x) ((x)*2) #define right(x) (((x)*2) + 1) #define fuck(x) cout << #x << " : " << x << " "; #define findLowVec(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define findUpVec(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define findLowArr(a, n, x) (lower_bound(a, a + n, x) - a) #define findUpArr(a, n, x) (upper_bound(a, a + n, x) - a) #define int long long using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &p) { return out << "(" << p.first << ", " << p.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &v) { out << "["; for (int i = 0; i < v.size(); i++) { if (i) out << ", "; out << v[i]; } return out << "]"; } template <class A, class B> ostream &operator<<(ostream &out, const set<A, B> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } template <class A> ostream &operator<<(ostream &out, const set<A> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } const int N = 1e5 + 10; int a[110]; int dp[N]; int n; int solve(int k) { if (dp[k] != 0) { return dp[k]; } if (k < a[0]) { dp[k] = -1; return -1; } bool win = false; for (int i = 0; i < n; i++) { if (k < a[i]) continue; if (solve(k - a[i]) == -1) { win = true; } } dp[k] = (win ? 1 : -1); return dp[k]; } int32_t SALI() { int k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; cout << (solve(k) == 1 ? "First" : "Second"); } /**< WRITEN BY ALI ADELKHAH */
insert
87
87
87
89
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 #define inf 1e18 #define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc) #define cin(t) \ int t; \ cin >> t #define w(t) while (t--) #define nl cout << endl; #define pb push_back #define ft(i) (i & (-1 * i)) #define arrIn(arr, size) \ for (int i = 0; i < size; i++) { \ cin >> arr[i]; \ } #define arrOut(arr, size, seperater) \ for (int i = 0; i < size; i++) { \ cout << arr[i] << seperater; \ } using namespace std; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } void fastIO() { 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 } int n, k; int arr[100005]; int dp[100005]; int solve(int rem) { if (rem == 0) return 0; if (dp[rem] != -1) return dp[rem]; int ans = 0; fo(i, 0, n, 1) { if ((rem - arr[i]) >= 0) { if (solve(rem - arr[i]) == 0) { ans = 1; break; } } } dp[rem] = ans; return ans; } int32_t main() { fastIO(); memset(dp, -1, sizeof(dp)); cin >> n >> k; fo(i, 0, n, 1) cin >> arr[i]; if (solve(k)) cout << "First"; else cout << "Second"; nl; return 0; } // cout << "Case #" << i << ": " << answer << endl;
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 #define inf 1e18 #define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc) #define cin(t) \ int t; \ cin >> t #define w(t) while (t--) #define nl cout << endl; #define pb push_back #define ft(i) (i & (-1 * i)) #define arrIn(arr, size) \ for (int i = 0; i < size; i++) { \ cin >> arr[i]; \ } #define arrOut(arr, size, seperater) \ for (int i = 0; i < size; i++) { \ cout << arr[i] << seperater; \ } using namespace std; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } void fastIO() { 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 } int n, k; int arr[100005]; int dp[100005]; int solve(int rem) { if (rem == 0) return 0; if (dp[rem] != -1) return dp[rem]; int ans = 0; fo(i, 0, n, 1) { if ((rem - arr[i]) >= 0) { if (solve(rem - arr[i]) == 0) { ans = 1; break; } } } dp[rem] = ans; return ans; } int32_t main() { memset(dp, -1, sizeof(dp)); cin >> n >> k; fo(i, 0, n, 1) cin >> arr[i]; if (solve(k)) cout << "First"; else cout << "Second"; nl; return 0; } // cout << "Case #" << i << ": " << answer << endl;
delete
77
78
77
77
0
p03170
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int f[101], a[101]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (a[j] <= i && !f[i - a[j]]) { f[i] = 1; break; } else if (a[j] <= i && f[i - a[j]]) f[i] = 0; } // printf("**%d %d\n",i,f[i]); } if (f[m] == 1) printf("First"); else printf("Second"); }
#include "bits/stdc++.h" using namespace std; int f[100001], a[101]; int n, m; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (a[j] <= i && !f[i - a[j]]) { f[i] = 1; break; } else if (a[j] <= i && f[i - a[j]]) f[i] = 0; } // printf("**%d %d\n",i,f[i]); } if (f[m] == 1) printf("First"); else printf("Second"); }
replace
2
3
2
3
0
p03170
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <unordered_map> #include <utility> #include <vector> #define _USE_MATH_DEFINES #include <complex> #include <iostream> #include <math.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, double> pld; typedef pair<double, double> pdd; typedef pair<double, ll> pdl; typedef pair<int, char> pic; typedef vector<ll> vl; typedef vector<int> vi; typedef complex<double> Point; typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq; typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq; typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> plpllgreaterq; typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq; typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq; #define bit(x, v) ((ll)x << v) #define rep(x, v) for (int x = 0; x < v; x++) #define rep2(x, f, v) for (int x = f; x < v; x++) // ่จฑๅฎนใ™ใ‚‹่ชคๅทฎฮต #define EPS (1e-10) // 2ใคใฎใ‚นใ‚ซใƒฉใƒผใŒ็ญ‰ใ—ใ„ใ‹ใฉใ†ใ‹ #define EQ(a, b) (abs((a) - (b)) < EPS) // 2ใคใฎใƒ™ใ‚ฏใƒˆใƒซใŒ็ญ‰ใ—ใ„ใ‹ใฉใ†ใ‹ #define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag())) const ll INF = 1000000007; const int MAX = 2000010; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // ไบŒ้ …ไฟ‚ๆ•ฐ่จˆ็ฎ— long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int pr[200010]; int lank[200010]; void uini(int n) { for (size_t i = 0; i <= n; i++) { pr[i] = i; } } int parent(int x) { if (x == pr[x]) return x; return pr[x] = parent(pr[x]); } int same(int x, int y) { return parent(x) == parent(y); } bool unit(int x, int y) { int px = parent(x); int py = parent(y); if (px == py) return false; if (lank[px] < lank[py]) { pr[py] = px; lank[px] += lank[py] + 1; } else { pr[px] = py; lank[py] += lank[px] + 1; } return true; } ll bit[200010]; int max_n = 200000; int pm = 0; void add(int x) { while (max_n >= x) { bit[x]++; x += x & -x; } } void sub(int x) { while (max_n >= x) { bit[x]--; x += x & -x; } } ll merge(ll *a, int left, int mid, int right) { ll n1 = mid - left; ll n2 = right - mid; vector<int> L(n1 + 1); vector<int> R(n2 + 1); for (size_t i = 0; i < n1; i++) { L[i] = a[left + i]; } for (size_t i = 0; i < n2; i++) { R[i] = a[mid + i]; } L[n1] = INF; R[n2] = INF; ll i = 0; ll j = 0; ll r = 0; for (size_t k = left; k < right; k++) { if (L[i] <= R[j]) { a[k] = L[i]; i++; } else { a[k] = R[j]; r += n1 - i; j++; } } return r; } ll merge2(pair<int, char> *a, int left, int mid, int right) { ll n1 = mid - left; ll n2 = right - mid; vector<pair<int, char>> L(n1 + 1); vector<pair<int, char>> R(n2 + 1); for (size_t i = 0; i < n1; i++) { L[i] = a[left + i]; } for (size_t i = 0; i < n2; i++) { R[i] = a[mid + i]; } L[n1] = make_pair(INF, ' '); R[n2] = make_pair(INF, ' '); ll i = 0; ll j = 0; ll r = 0; for (size_t k = left; k < right; k++) { if (L[i].first <= R[j].first) { a[k] = L[i]; i++; } else { a[k] = R[j]; r += n1 - i; j++; } } return r; } ll mergeSort2(pair<int, char> *a, int left, int right) { ll res = 0; if (left + 1 < right) { int mid = (left + right) / 2; res = mergeSort2(a, left, mid); res += mergeSort2(a, mid, right); res += merge2(a, left, mid, right); } return res; } ll mergeSort(ll *a, int left, int right) { ll res = 0; if (left + 1 < right) { int mid = (left + right) / 2; res = mergeSort(a, left, mid); res += mergeSort(a, mid, right); res += merge(a, left, mid, right); } return res; } int partition(pair<int, char> *a, int p, int r) { pair<int, char> x = a[r]; int i = p - 1; for (size_t j = p; j < r; j++) { if (a[j].first <= x.first) { i++; swap(a[i], a[j]); } } swap(a[i + 1], a[r]); return i + 1; } void quick(pair<int, char> *a, int p, int r) { if (p < r) { int q = partition(a, p, r); quick(a, p, q - 1); quick(a, q + 1, r); } } ll n; int ci = 0; ll P[1000010]; struct Node { int key; int priority; Node *parent, *left, *right; Node(int key, int priority); Node() {} }; Node NIL; Node::Node(int key, int priority) : key(key), priority(priority) { left = &NIL; right = &NIL; } Node *root = new Node(); void cenrec(Node *k) { if (k->key == NIL.key) return; cenrec(k->left); cout << " " << k->key; cenrec(k->right); } void fastrec(Node *k) { if (k->key == NIL.key) return; cout << " " << k->key; fastrec(k->left); fastrec(k->right); } void insert(Node *v) { Node *y = &NIL; Node *x = root; while (x->key != NIL.key) { y = x; if (v->key < x->key) { x = x->left; } else { x = x->right; } } v->parent = y; if (y->key == NIL.key) { root = v; } else if (v->key < y->key) { y->left = v; } else { y->right = v; } } Node *find(Node *k, ll v) { if (k->key == NIL.key) return &NIL; if (k->key == v) return k; if (v < k->key) return find(k->left, v); return find(k->right, v); } void delp12(Node *x) { if (x->key == NIL.key) return; Node *l = x->left; Node *r = x->right; Node *pr = x->parent; if (l->key == NIL.key && r->key == NIL.key) { if (pr->left == x) { pr->left = &NIL; } else pr->right = &NIL; } else if (l->key != NIL.key) { if (pr->left == x) { pr->left = l; } else pr->right = l; l->parent = pr; } else if (r->key != NIL.key) { if (pr->left == x) { pr->left = r; } else pr->right = r; r->parent = pr; } } Node *get_next(Node *k) { if (k->key == NIL.key) return &NIL; Node *res = get_next(k->left); if (res->key != NIL.key) return res; return k; } void del(Node *x) { if (x->key == NIL.key) return; Node *l = x->left; Node *r = x->right; Node *pr = x->parent; if (l->key != NIL.key && r->key != NIL.key) { Node *nex = get_next(r); x->key = nex->key; delp12(nex); } else { delp12(x); } } Node *rightRotate(Node *t) { Node *s = t->left; t->left = s->right; s->right = t; return s; } Node *leftRotate(Node *t) { Node *s = t->right; t->right = s->left; s->left = t; return s; } Node *_insert(Node *t, int key, int priority) { if (t->key == NIL.key) { return new Node(key, priority); } if (key == t->key) { return t; } if (key < t->key) { t->left = _insert(t->left, key, priority); if (t->priority < t->left->priority) { t = rightRotate(t); } } else { t->right = _insert(t->right, key, priority); if (t->priority < t->right->priority) { t = leftRotate(t); } } return t; } Node *delete1(Node *t, int key); Node *_delete(Node *t, int key) { if (t->left->key == NIL.key && t->right->key == NIL.key) { return &NIL; } else if (t->left->key == NIL.key) { t = leftRotate(t); } else if (t->right->key == NIL.key) { t = rightRotate(t); } else { if (t->left->priority > t->right->priority) { t = rightRotate(t); } else t = leftRotate(t); } return delete1(t, key); } Node *delete1(Node *t, int key) { if (t->key == NIL.key) { return &NIL; } if (key < t->key) { t->left = delete1(t->left, key); } else if (key > t->key) { t->right = delete1(t->right, key); } else return _delete(t, key); return t; } int H; int left(int i) { return i * 2 + 1; } int right(int i) { return i * 2 + 2; } // ๅ†…็ฉ (dot product) : aใƒปb = |a||b|cosฮ˜ double dot(Point a, Point b) { return (a.real() * b.real() + a.imag() * b.imag()); } // ๅค–็ฉ (cross product) : aร—b = |a||b|sinฮ˜ double cross(Point a, Point b) { return (a.real() * b.imag() - a.imag() * b.real()); } // 2็›ด็ทšใฎ็›ดไบคๅˆคๅฎš : aโŠฅb <=> dot(a, b) = 0 int is_orthogonal(Point a1, Point a2, Point b1, Point b2) { return EQ(dot(a1 - a2, b1 - b2), 0.0); } // 2็›ด็ทšใฎๅนณ่กŒๅˆคๅฎš : a//b <=> cross(a, b) = 0 int is_parallel(Point a1, Point a2, Point b1, Point b2) { return EQ(cross(a1 - a2, b1 - b2), 0.0); } // ็‚นcใŒ็›ด็ทša,bไธŠใซใ‚ใ‚‹ใ‹ใชใ„ใ‹ int is_point_on_line(Point a, Point b, Point c) { return EQ(cross(b - a, c - a), 0.0); } // ็‚นcใŒ็ทšๅˆ†a,bไธŠใซใ‚ใ‚‹ใ‹ใชใ„ใ‹(1) int is_point_on_line1(Point a, Point b, Point c) { return EQ(cross(b - a, c - a), 0.0) && (dot(b - a, c - a) > -EPS) && (dot(a - b, c - b) > -EPS); } // ็‚นcใŒ็ทšๅˆ†a,bไธŠใซใ‚ใ‚‹ใ‹ใชใ„ใ‹(2) int is_point_on_line2(Point a, Point b, Point c) { // |a-c| + |c-b| <= |a-b| ใชใ‚‰็ทšๅˆ†ไธŠ return (abs(a - c) + abs(c - b) < abs(a - b) + EPS); } // ็‚นa,bใ‚’้€šใ‚‹็›ด็ทšใจ็‚นcใจใฎ่ท้›ข double distance_l_p(Point a, Point b, Point c) { return abs(cross(b - a, c - a)) / abs(b - a); } // ็‚นa,bใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใจ็‚นcใจใฎ่ท้›ข double distance_ls_p(Point a, Point b, Point c) { if (dot(b - a, c - a) < EPS) return abs(c - a); if (dot(a - b, c - b) < EPS) return abs(c - b); return abs(cross(b - a, c - a)) / abs(b - a); } // a1,a2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใจb1,b2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใฎไบคๅทฎๅˆคๅฎš int is_intersected_ls(Point a1, Point a2, Point b1, Point b2) { return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) && (cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS); } // a1,a2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใจb1,b2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใฎไบค็‚น่จˆ็ฎ— Point intersection_ls(Point a1, Point a2, Point b1, Point b2) { Point b = b2 - b1; double d1 = abs(cross(b, a1 - b1)); double d2 = abs(cross(b, a2 - b1)); double t = d1 / (d1 + d2); return a1 + (a2 - a1) * t; } // a1,a2ใ‚’้€šใ‚‹็›ด็ทšใจb1,b2ใ‚’้€šใ‚‹็›ด็ทšใฎไบคๅทฎๅˆคๅฎš int is_intersected_l(Point a1, Point a2, Point b1, Point b2) { return !EQ(cross(a1 - a2, b1 - b2), 0.0); } // a1,a2ใ‚’้€šใ‚‹็›ด็ทšใจb1,b2ใ‚’้€šใ‚‹็›ด็ทšใฎไบค็‚น่จˆ็ฎ— Point intersection_l(Point a1, Point a2, Point b1, Point b2) { Point a = a2 - a1; Point b = b2 - b1; return a1 + a * cross(b, b1 - a1) / cross(b, a); } // ๅ††ใฎไบค็‚น pair<Point, Point> intersection_circle(Point p1, Point p2, double r1, double r2) { double d = abs(p2 - p1); double th = acos((d * d + r1 * r1 - r2 * r2) / (2 * d * r1)); return make_pair(p1 + polar(r1, arg(p2 - p1) + th), polar(r1, arg(p2 - p1) - th)); } ll heap[2000010]; void maxHeapify(int i) { int l = left(i); int r = right(i); int largest = 0; if (l < H && heap[l] > heap[i]) largest = l; else largest = i; if (r < H && heap[r] > heap[largest]) largest = r; if (largest != i) { swap(heap[i], heap[largest]); maxHeapify(largest); } } int pare(int i) { return (i - 1) / 2; } void raise(int i) { int l = pare(i); if (l < 0) return; if (heap[l] < heap[i]) { swap(heap[i], heap[l]); raise(l); } } void minHeapify(int i) { int l = left(i); int r = right(i); int minimam = 0; if (l < H && heap[l] < heap[i]) minimam = l; else minimam = i; if (r < H && heap[r] < heap[minimam]) minimam = r; if (minimam != i) { swap(heap[i], heap[minimam]); minHeapify(minimam); } } void buildMaxHeap() { for (int i = H / 2; i >= 0; i--) { maxHeapify(i); } } int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; std::vector<int> find_all(const std::string str, const std::string subStr) { std::vector<int> result; int subStrSize = subStr.size(); int pos = str.find(subStr); while (pos != std::string::npos) { result.push_back(pos); pos = str.find(subStr, pos + 1); } return result; } // ll memo[100010]; // ll next[100010]; // ll dm[100010]; // int f[100010]; // ll rec(int x) { // // if (~memo[x]) return memo[x]; // if (x == n) { // dm[n] = 1; // return 1; // } // ll *res = &memo[x]; // *res = 0; // set<int> st; // st.insert(f[x]); // for (int i = x + 1; i <= n; i++) // { // if (~memo[i]) { // *res += memo[i] + 1; // *res %= INF; // break; // } // // *res += rec(i); // *res %= INF; // if (st.find(f[i]) != st.end()) {break; } // st.insert(f[i]); // } // // return *res; // } #define bit(x, v) ((ll)x << v) class BIT { static const int MAX_N = 1000010; public: BIT() { memset(bit, 0, sizeof(bit)); } int bit[MAX_N + 1], n; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } void clear() { memset(bit, 0, sizeof(bit)); } int a[MAX_N]; void bable_swap_count() { ll ans = 0; for (size_t j = 0; j < n; j++) { ans += j - sum(a[j]); add(a[j], 1); } printf("%lld\n", ans); } int search(int s, int x) { ll half = (s + x) / 2; ll sh = sum(x); ll sl = sum(half); ll st = sum(s); if (sh - sl == 0) { return x; } if (sh - sl < x - half) { return search(half, x); } if (sl - st == 0) { return half; } if (sl - st < half - s) { return search(s, half); } return -1; } int lankSearch(int lank) { return lankSearch(lank, 0, MAX_N); } int lankSearch(int lank, int s, int t) { ll half = (s + t) / 2; ll v = sum(half); ll v1 = sum(t); ll v2 = sum(s); if (lank == 1) { if (s + 1 >= t) return t; else if (v - v2 > 0) { return lankSearch(lank, s, half); } else return lankSearch(lank, half, t); } if ((v - v2) < lank) { return lankSearch(lank - (v - v2), half, t); } if ((v - v2) >= lank) { return lankSearch(lank, s, half); } return -1; } }; vector<ll> getp(ll n) { vector<ll> res; ll a = 2; if (n % 2 == 0) { res.push_back(2); while (n % 2 == 0) n /= 2; } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { res.push_back(i); while (n % i == 0) n /= i; } } if (n != 1) res.push_back(n); return res; } vector<ll> getp2(ll n) { vector<ll> res; ll a = 2; if (n % 2 == 0) { while (n % 2 == 0) { n /= 2; res.push_back(2); } } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { while (n % i == 0) { n /= i; res.push_back(i); } } } if (n != 1) res.push_back(n); return res; } vector<pll> getp3(ll n) { vector<pll> res; ll a = 2; int cnt = 0; if (n % 2 == 0) { res.push_back(make_pair(2, 0)); while (n % 2 == 0) { n /= 2; res[cnt].second++; } cnt++; } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { res.push_back(make_pair(n, 0)); while (n % i == 0) { n /= i; res[cnt].second++; } cnt++; } } if (n != 1) res.push_back(make_pair(n, 1)); return res; } vector<ll> getDivisors(ll n) { vector<ll> res; ll a = 2; res.push_back(1); for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (n / i != i) res.push_back(n / i); } } return res; } struct ve { public: vector<ve> child; int _t = INF; ve(int t) : _t(t) {} ve(ve _left, ve _right) { _t = _left._t + _right._t; child.push_back(_left); child.push_back(_right); } bool operator<(const ve &t) const { return _t > t._t; } }; vector<bool> elas(ll n) { vector<bool> r(n); for (ll i = 3; i < n; i += 2) { r[i] = 1; } r[0] = 0; r[1] = 0; r[2] = 1; for (ll i = 3; i * i < n; i += 2) { if (!r[i]) continue; ll ti = i * 2; while (ti < n) { r[ti] = false; ti += i; } } return r; } bool isprime(ll v) { for (ll i = 2; i * i <= v; i++) { if (v % i == 0) return false; } return true; } ll lcm(vector<ll> v) { if (v.size() == 0) return 0; ll t = v[0]; for (size_t i = 1; i < v.size(); i++) { t = v[i] * t / gcd(v[i], t); } return t; } ll eulerphi(ll n) { auto p = getp(n); double u = n; for (auto v : p) { u *= (double)(v - 1) / (double)v; } return u; } double revs(double x) { ll dig = 0; stringstream st; st << std::fixed << setprecision(0) << x; string v = st.str(); reverse(v.begin(), v.end()); return stod(v); } bool chkparindrome(double x) { stringstream st; st << std::fixed << setprecision(0) << x; string p = st.str(); for (size_t i = 0; i < p.size() / 2; i++) { if (p[i] != p[p.size() - i - 1]) { return false; } } return true; } ll digitC(double x) { stringstream st; st << fixed << setprecision(0) << x; return st.str().size(); } ll digitSum(double x) { stringstream st; st << std::fixed << x; string p = st.str(); ll rs = 0; for (size_t i = 0; i < p.size(); i++) { if (p[i] == '.') break; rs += p[i] - '0'; } return rs; } pdd recs(int x) { if (x == 0) return make_pair(1, 2); pdd d = recs(x - 1); auto nu = d.second * 2.0 + d.first; auto de = d.second; return make_pair(de, nu); } ll caldig(ll a) { ll r = 0; while (a > 0) { a /= 10; r++; } return r; } int chav(char v) { if (v <= 'Z') return v - 'A'; return v - 'a' + 26; } char itoch(int i) { if (i < 26) return i + 'A'; return (i - 26) + 'a'; } int crmp[1000][1000]; int countR(ll base, ll x, ll y, int deep) { if (~crmp[x][y]) { return deep - crmp[x][y]; } crmp[x][y] = deep; double nu = sqrt(base) + x; double de = (base - (x * x)) / y; ll u = nu / de; ll nx = x - (u * de); return countR(base, -nx, de, deep + 1); } bool isPermutation(ll x, ll y) { int c1[10]; int c2[10]; memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); while (x > 0) { c1[x % 10]++; x /= 10; } while (y > 0) { c2[y % 10]++; y /= 10; } for (size_t i = 0; i < 10; i++) { if (c1[i] != c2[i]) return false; } return true; } bool fnd[1000]; double cl4(double a, int t, double b) { switch (t) { case 0: return a + b; case 1: return a - b; case 2: return a * b; case 3: if (b == 0) { return INF; } else return a / b; default: break; } } void clc5(double a, int t1, double b) { double ab = cl4(a, t1, b); if (ab != INF && ab > 0 && ab < 1000 && (int)ab == ab) { fnd[(int)ab] = 1; } } void clc4(double a, int t1, double b, int t2, double c) { double ab = cl4(a, t1, b); double bc = cl4(b, t2, c); if (ab != INF) { clc5(ab, t2, c); } if (bc != INF) { clc5(a, t1, bc); } } void clc3(double a, int t1, double b, int t2, double c, int t3, double d) { double ab = cl4(a, t1, b); double bc = cl4(b, t2, c); double cd = cl4(c, t3, d); if (ab != INF) { clc4(ab, t2, c, t3, d); } if (bc != INF) { clc4(a, t1, bc, t3, d); } if (cd != INF) { clc4(a, t1, b, t2, cd); } } void clc2(ll a, ll b, ll c, ll d) { for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { for (size_t k = 0; k < 4; k++) { clc3(a, i, b, j, c, k, d); } } } } void clc(ll a, ll b, ll c, ll d) { ll t[] = {a, b, c, d}; do { clc2(t[0], t[1], t[2], t[3]); } while (next_permutation(t, t + 4)); } double heron(ll a, ll b, ll c) { double s = (double)(a + b + c) / 2.0; return sqrt(s * (s - a) * (s - b) * (s - c)); } double calcThreePS(double x1, double y1, double x2, double y2, double x3, double y3) { return abs((x1 * y2 + x2 * y3 + x3 * y1 - y1 * x2 - y2 * x3 - y3 * x1) / 2.0); } double memo[310][310][310]; void solv() { ll k; cin >> n >> k; ll a[110]; for (size_t i = 0; i < n; i++) { cin >> a[i]; } bool dp[100010]; memset(dp, 0, sizeof(dp)); for (size_t i = 0; i < n; i++) { for (size_t j = 0; j <= k; j++) { if (j - a[i] < 0) continue; else dp[j] |= !dp[j - a[i]]; } } if (dp[k]) { cout << "First" << endl; } else cout << "Second" << endl; } int main() { // COMinit(); solv(); return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <unordered_map> #include <utility> #include <vector> #define _USE_MATH_DEFINES #include <complex> #include <iostream> #include <math.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, double> pld; typedef pair<double, double> pdd; typedef pair<double, ll> pdl; typedef pair<int, char> pic; typedef vector<ll> vl; typedef vector<int> vi; typedef complex<double> Point; typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq; typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq; typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>> plpllgreaterq; typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq; typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq; #define bit(x, v) ((ll)x << v) #define rep(x, v) for (int x = 0; x < v; x++) #define rep2(x, f, v) for (int x = f; x < v; x++) // ่จฑๅฎนใ™ใ‚‹่ชคๅทฎฮต #define EPS (1e-10) // 2ใคใฎใ‚นใ‚ซใƒฉใƒผใŒ็ญ‰ใ—ใ„ใ‹ใฉใ†ใ‹ #define EQ(a, b) (abs((a) - (b)) < EPS) // 2ใคใฎใƒ™ใ‚ฏใƒˆใƒซใŒ็ญ‰ใ—ใ„ใ‹ใฉใ†ใ‹ #define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag())) const ll INF = 1000000007; const int MAX = 2000010; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // ไบŒ้ …ไฟ‚ๆ•ฐ่จˆ็ฎ— long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int pr[200010]; int lank[200010]; void uini(int n) { for (size_t i = 0; i <= n; i++) { pr[i] = i; } } int parent(int x) { if (x == pr[x]) return x; return pr[x] = parent(pr[x]); } int same(int x, int y) { return parent(x) == parent(y); } bool unit(int x, int y) { int px = parent(x); int py = parent(y); if (px == py) return false; if (lank[px] < lank[py]) { pr[py] = px; lank[px] += lank[py] + 1; } else { pr[px] = py; lank[py] += lank[px] + 1; } return true; } ll bit[200010]; int max_n = 200000; int pm = 0; void add(int x) { while (max_n >= x) { bit[x]++; x += x & -x; } } void sub(int x) { while (max_n >= x) { bit[x]--; x += x & -x; } } ll merge(ll *a, int left, int mid, int right) { ll n1 = mid - left; ll n2 = right - mid; vector<int> L(n1 + 1); vector<int> R(n2 + 1); for (size_t i = 0; i < n1; i++) { L[i] = a[left + i]; } for (size_t i = 0; i < n2; i++) { R[i] = a[mid + i]; } L[n1] = INF; R[n2] = INF; ll i = 0; ll j = 0; ll r = 0; for (size_t k = left; k < right; k++) { if (L[i] <= R[j]) { a[k] = L[i]; i++; } else { a[k] = R[j]; r += n1 - i; j++; } } return r; } ll merge2(pair<int, char> *a, int left, int mid, int right) { ll n1 = mid - left; ll n2 = right - mid; vector<pair<int, char>> L(n1 + 1); vector<pair<int, char>> R(n2 + 1); for (size_t i = 0; i < n1; i++) { L[i] = a[left + i]; } for (size_t i = 0; i < n2; i++) { R[i] = a[mid + i]; } L[n1] = make_pair(INF, ' '); R[n2] = make_pair(INF, ' '); ll i = 0; ll j = 0; ll r = 0; for (size_t k = left; k < right; k++) { if (L[i].first <= R[j].first) { a[k] = L[i]; i++; } else { a[k] = R[j]; r += n1 - i; j++; } } return r; } ll mergeSort2(pair<int, char> *a, int left, int right) { ll res = 0; if (left + 1 < right) { int mid = (left + right) / 2; res = mergeSort2(a, left, mid); res += mergeSort2(a, mid, right); res += merge2(a, left, mid, right); } return res; } ll mergeSort(ll *a, int left, int right) { ll res = 0; if (left + 1 < right) { int mid = (left + right) / 2; res = mergeSort(a, left, mid); res += mergeSort(a, mid, right); res += merge(a, left, mid, right); } return res; } int partition(pair<int, char> *a, int p, int r) { pair<int, char> x = a[r]; int i = p - 1; for (size_t j = p; j < r; j++) { if (a[j].first <= x.first) { i++; swap(a[i], a[j]); } } swap(a[i + 1], a[r]); return i + 1; } void quick(pair<int, char> *a, int p, int r) { if (p < r) { int q = partition(a, p, r); quick(a, p, q - 1); quick(a, q + 1, r); } } ll n; int ci = 0; ll P[1000010]; struct Node { int key; int priority; Node *parent, *left, *right; Node(int key, int priority); Node() {} }; Node NIL; Node::Node(int key, int priority) : key(key), priority(priority) { left = &NIL; right = &NIL; } Node *root = new Node(); void cenrec(Node *k) { if (k->key == NIL.key) return; cenrec(k->left); cout << " " << k->key; cenrec(k->right); } void fastrec(Node *k) { if (k->key == NIL.key) return; cout << " " << k->key; fastrec(k->left); fastrec(k->right); } void insert(Node *v) { Node *y = &NIL; Node *x = root; while (x->key != NIL.key) { y = x; if (v->key < x->key) { x = x->left; } else { x = x->right; } } v->parent = y; if (y->key == NIL.key) { root = v; } else if (v->key < y->key) { y->left = v; } else { y->right = v; } } Node *find(Node *k, ll v) { if (k->key == NIL.key) return &NIL; if (k->key == v) return k; if (v < k->key) return find(k->left, v); return find(k->right, v); } void delp12(Node *x) { if (x->key == NIL.key) return; Node *l = x->left; Node *r = x->right; Node *pr = x->parent; if (l->key == NIL.key && r->key == NIL.key) { if (pr->left == x) { pr->left = &NIL; } else pr->right = &NIL; } else if (l->key != NIL.key) { if (pr->left == x) { pr->left = l; } else pr->right = l; l->parent = pr; } else if (r->key != NIL.key) { if (pr->left == x) { pr->left = r; } else pr->right = r; r->parent = pr; } } Node *get_next(Node *k) { if (k->key == NIL.key) return &NIL; Node *res = get_next(k->left); if (res->key != NIL.key) return res; return k; } void del(Node *x) { if (x->key == NIL.key) return; Node *l = x->left; Node *r = x->right; Node *pr = x->parent; if (l->key != NIL.key && r->key != NIL.key) { Node *nex = get_next(r); x->key = nex->key; delp12(nex); } else { delp12(x); } } Node *rightRotate(Node *t) { Node *s = t->left; t->left = s->right; s->right = t; return s; } Node *leftRotate(Node *t) { Node *s = t->right; t->right = s->left; s->left = t; return s; } Node *_insert(Node *t, int key, int priority) { if (t->key == NIL.key) { return new Node(key, priority); } if (key == t->key) { return t; } if (key < t->key) { t->left = _insert(t->left, key, priority); if (t->priority < t->left->priority) { t = rightRotate(t); } } else { t->right = _insert(t->right, key, priority); if (t->priority < t->right->priority) { t = leftRotate(t); } } return t; } Node *delete1(Node *t, int key); Node *_delete(Node *t, int key) { if (t->left->key == NIL.key && t->right->key == NIL.key) { return &NIL; } else if (t->left->key == NIL.key) { t = leftRotate(t); } else if (t->right->key == NIL.key) { t = rightRotate(t); } else { if (t->left->priority > t->right->priority) { t = rightRotate(t); } else t = leftRotate(t); } return delete1(t, key); } Node *delete1(Node *t, int key) { if (t->key == NIL.key) { return &NIL; } if (key < t->key) { t->left = delete1(t->left, key); } else if (key > t->key) { t->right = delete1(t->right, key); } else return _delete(t, key); return t; } int H; int left(int i) { return i * 2 + 1; } int right(int i) { return i * 2 + 2; } // ๅ†…็ฉ (dot product) : aใƒปb = |a||b|cosฮ˜ double dot(Point a, Point b) { return (a.real() * b.real() + a.imag() * b.imag()); } // ๅค–็ฉ (cross product) : aร—b = |a||b|sinฮ˜ double cross(Point a, Point b) { return (a.real() * b.imag() - a.imag() * b.real()); } // 2็›ด็ทšใฎ็›ดไบคๅˆคๅฎš : aโŠฅb <=> dot(a, b) = 0 int is_orthogonal(Point a1, Point a2, Point b1, Point b2) { return EQ(dot(a1 - a2, b1 - b2), 0.0); } // 2็›ด็ทšใฎๅนณ่กŒๅˆคๅฎš : a//b <=> cross(a, b) = 0 int is_parallel(Point a1, Point a2, Point b1, Point b2) { return EQ(cross(a1 - a2, b1 - b2), 0.0); } // ็‚นcใŒ็›ด็ทša,bไธŠใซใ‚ใ‚‹ใ‹ใชใ„ใ‹ int is_point_on_line(Point a, Point b, Point c) { return EQ(cross(b - a, c - a), 0.0); } // ็‚นcใŒ็ทšๅˆ†a,bไธŠใซใ‚ใ‚‹ใ‹ใชใ„ใ‹(1) int is_point_on_line1(Point a, Point b, Point c) { return EQ(cross(b - a, c - a), 0.0) && (dot(b - a, c - a) > -EPS) && (dot(a - b, c - b) > -EPS); } // ็‚นcใŒ็ทšๅˆ†a,bไธŠใซใ‚ใ‚‹ใ‹ใชใ„ใ‹(2) int is_point_on_line2(Point a, Point b, Point c) { // |a-c| + |c-b| <= |a-b| ใชใ‚‰็ทšๅˆ†ไธŠ return (abs(a - c) + abs(c - b) < abs(a - b) + EPS); } // ็‚นa,bใ‚’้€šใ‚‹็›ด็ทšใจ็‚นcใจใฎ่ท้›ข double distance_l_p(Point a, Point b, Point c) { return abs(cross(b - a, c - a)) / abs(b - a); } // ็‚นa,bใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใจ็‚นcใจใฎ่ท้›ข double distance_ls_p(Point a, Point b, Point c) { if (dot(b - a, c - a) < EPS) return abs(c - a); if (dot(a - b, c - b) < EPS) return abs(c - b); return abs(cross(b - a, c - a)) / abs(b - a); } // a1,a2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใจb1,b2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใฎไบคๅทฎๅˆคๅฎš int is_intersected_ls(Point a1, Point a2, Point b1, Point b2) { return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) && (cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS); } // a1,a2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใจb1,b2ใ‚’็ซฏ็‚นใจใ™ใ‚‹็ทšๅˆ†ใฎไบค็‚น่จˆ็ฎ— Point intersection_ls(Point a1, Point a2, Point b1, Point b2) { Point b = b2 - b1; double d1 = abs(cross(b, a1 - b1)); double d2 = abs(cross(b, a2 - b1)); double t = d1 / (d1 + d2); return a1 + (a2 - a1) * t; } // a1,a2ใ‚’้€šใ‚‹็›ด็ทšใจb1,b2ใ‚’้€šใ‚‹็›ด็ทšใฎไบคๅทฎๅˆคๅฎš int is_intersected_l(Point a1, Point a2, Point b1, Point b2) { return !EQ(cross(a1 - a2, b1 - b2), 0.0); } // a1,a2ใ‚’้€šใ‚‹็›ด็ทšใจb1,b2ใ‚’้€šใ‚‹็›ด็ทšใฎไบค็‚น่จˆ็ฎ— Point intersection_l(Point a1, Point a2, Point b1, Point b2) { Point a = a2 - a1; Point b = b2 - b1; return a1 + a * cross(b, b1 - a1) / cross(b, a); } // ๅ††ใฎไบค็‚น pair<Point, Point> intersection_circle(Point p1, Point p2, double r1, double r2) { double d = abs(p2 - p1); double th = acos((d * d + r1 * r1 - r2 * r2) / (2 * d * r1)); return make_pair(p1 + polar(r1, arg(p2 - p1) + th), polar(r1, arg(p2 - p1) - th)); } ll heap[2000010]; void maxHeapify(int i) { int l = left(i); int r = right(i); int largest = 0; if (l < H && heap[l] > heap[i]) largest = l; else largest = i; if (r < H && heap[r] > heap[largest]) largest = r; if (largest != i) { swap(heap[i], heap[largest]); maxHeapify(largest); } } int pare(int i) { return (i - 1) / 2; } void raise(int i) { int l = pare(i); if (l < 0) return; if (heap[l] < heap[i]) { swap(heap[i], heap[l]); raise(l); } } void minHeapify(int i) { int l = left(i); int r = right(i); int minimam = 0; if (l < H && heap[l] < heap[i]) minimam = l; else minimam = i; if (r < H && heap[r] < heap[minimam]) minimam = r; if (minimam != i) { swap(heap[i], heap[minimam]); minHeapify(minimam); } } void buildMaxHeap() { for (int i = H / 2; i >= 0; i--) { maxHeapify(i); } } int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; std::vector<int> find_all(const std::string str, const std::string subStr) { std::vector<int> result; int subStrSize = subStr.size(); int pos = str.find(subStr); while (pos != std::string::npos) { result.push_back(pos); pos = str.find(subStr, pos + 1); } return result; } // ll memo[100010]; // ll next[100010]; // ll dm[100010]; // int f[100010]; // ll rec(int x) { // // if (~memo[x]) return memo[x]; // if (x == n) { // dm[n] = 1; // return 1; // } // ll *res = &memo[x]; // *res = 0; // set<int> st; // st.insert(f[x]); // for (int i = x + 1; i <= n; i++) // { // if (~memo[i]) { // *res += memo[i] + 1; // *res %= INF; // break; // } // // *res += rec(i); // *res %= INF; // if (st.find(f[i]) != st.end()) {break; } // st.insert(f[i]); // } // // return *res; // } #define bit(x, v) ((ll)x << v) class BIT { static const int MAX_N = 1000010; public: BIT() { memset(bit, 0, sizeof(bit)); } int bit[MAX_N + 1], n; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } void clear() { memset(bit, 0, sizeof(bit)); } int a[MAX_N]; void bable_swap_count() { ll ans = 0; for (size_t j = 0; j < n; j++) { ans += j - sum(a[j]); add(a[j], 1); } printf("%lld\n", ans); } int search(int s, int x) { ll half = (s + x) / 2; ll sh = sum(x); ll sl = sum(half); ll st = sum(s); if (sh - sl == 0) { return x; } if (sh - sl < x - half) { return search(half, x); } if (sl - st == 0) { return half; } if (sl - st < half - s) { return search(s, half); } return -1; } int lankSearch(int lank) { return lankSearch(lank, 0, MAX_N); } int lankSearch(int lank, int s, int t) { ll half = (s + t) / 2; ll v = sum(half); ll v1 = sum(t); ll v2 = sum(s); if (lank == 1) { if (s + 1 >= t) return t; else if (v - v2 > 0) { return lankSearch(lank, s, half); } else return lankSearch(lank, half, t); } if ((v - v2) < lank) { return lankSearch(lank - (v - v2), half, t); } if ((v - v2) >= lank) { return lankSearch(lank, s, half); } return -1; } }; vector<ll> getp(ll n) { vector<ll> res; ll a = 2; if (n % 2 == 0) { res.push_back(2); while (n % 2 == 0) n /= 2; } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { res.push_back(i); while (n % i == 0) n /= i; } } if (n != 1) res.push_back(n); return res; } vector<ll> getp2(ll n) { vector<ll> res; ll a = 2; if (n % 2 == 0) { while (n % 2 == 0) { n /= 2; res.push_back(2); } } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { while (n % i == 0) { n /= i; res.push_back(i); } } } if (n != 1) res.push_back(n); return res; } vector<pll> getp3(ll n) { vector<pll> res; ll a = 2; int cnt = 0; if (n % 2 == 0) { res.push_back(make_pair(2, 0)); while (n % 2 == 0) { n /= 2; res[cnt].second++; } cnt++; } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { res.push_back(make_pair(n, 0)); while (n % i == 0) { n /= i; res[cnt].second++; } cnt++; } } if (n != 1) res.push_back(make_pair(n, 1)); return res; } vector<ll> getDivisors(ll n) { vector<ll> res; ll a = 2; res.push_back(1); for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (n / i != i) res.push_back(n / i); } } return res; } struct ve { public: vector<ve> child; int _t = INF; ve(int t) : _t(t) {} ve(ve _left, ve _right) { _t = _left._t + _right._t; child.push_back(_left); child.push_back(_right); } bool operator<(const ve &t) const { return _t > t._t; } }; vector<bool> elas(ll n) { vector<bool> r(n); for (ll i = 3; i < n; i += 2) { r[i] = 1; } r[0] = 0; r[1] = 0; r[2] = 1; for (ll i = 3; i * i < n; i += 2) { if (!r[i]) continue; ll ti = i * 2; while (ti < n) { r[ti] = false; ti += i; } } return r; } bool isprime(ll v) { for (ll i = 2; i * i <= v; i++) { if (v % i == 0) return false; } return true; } ll lcm(vector<ll> v) { if (v.size() == 0) return 0; ll t = v[0]; for (size_t i = 1; i < v.size(); i++) { t = v[i] * t / gcd(v[i], t); } return t; } ll eulerphi(ll n) { auto p = getp(n); double u = n; for (auto v : p) { u *= (double)(v - 1) / (double)v; } return u; } double revs(double x) { ll dig = 0; stringstream st; st << std::fixed << setprecision(0) << x; string v = st.str(); reverse(v.begin(), v.end()); return stod(v); } bool chkparindrome(double x) { stringstream st; st << std::fixed << setprecision(0) << x; string p = st.str(); for (size_t i = 0; i < p.size() / 2; i++) { if (p[i] != p[p.size() - i - 1]) { return false; } } return true; } ll digitC(double x) { stringstream st; st << fixed << setprecision(0) << x; return st.str().size(); } ll digitSum(double x) { stringstream st; st << std::fixed << x; string p = st.str(); ll rs = 0; for (size_t i = 0; i < p.size(); i++) { if (p[i] == '.') break; rs += p[i] - '0'; } return rs; } pdd recs(int x) { if (x == 0) return make_pair(1, 2); pdd d = recs(x - 1); auto nu = d.second * 2.0 + d.first; auto de = d.second; return make_pair(de, nu); } ll caldig(ll a) { ll r = 0; while (a > 0) { a /= 10; r++; } return r; } int chav(char v) { if (v <= 'Z') return v - 'A'; return v - 'a' + 26; } char itoch(int i) { if (i < 26) return i + 'A'; return (i - 26) + 'a'; } int crmp[1000][1000]; int countR(ll base, ll x, ll y, int deep) { if (~crmp[x][y]) { return deep - crmp[x][y]; } crmp[x][y] = deep; double nu = sqrt(base) + x; double de = (base - (x * x)) / y; ll u = nu / de; ll nx = x - (u * de); return countR(base, -nx, de, deep + 1); } bool isPermutation(ll x, ll y) { int c1[10]; int c2[10]; memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); while (x > 0) { c1[x % 10]++; x /= 10; } while (y > 0) { c2[y % 10]++; y /= 10; } for (size_t i = 0; i < 10; i++) { if (c1[i] != c2[i]) return false; } return true; } bool fnd[1000]; double cl4(double a, int t, double b) { switch (t) { case 0: return a + b; case 1: return a - b; case 2: return a * b; case 3: if (b == 0) { return INF; } else return a / b; default: break; } } void clc5(double a, int t1, double b) { double ab = cl4(a, t1, b); if (ab != INF && ab > 0 && ab < 1000 && (int)ab == ab) { fnd[(int)ab] = 1; } } void clc4(double a, int t1, double b, int t2, double c) { double ab = cl4(a, t1, b); double bc = cl4(b, t2, c); if (ab != INF) { clc5(ab, t2, c); } if (bc != INF) { clc5(a, t1, bc); } } void clc3(double a, int t1, double b, int t2, double c, int t3, double d) { double ab = cl4(a, t1, b); double bc = cl4(b, t2, c); double cd = cl4(c, t3, d); if (ab != INF) { clc4(ab, t2, c, t3, d); } if (bc != INF) { clc4(a, t1, bc, t3, d); } if (cd != INF) { clc4(a, t1, b, t2, cd); } } void clc2(ll a, ll b, ll c, ll d) { for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { for (size_t k = 0; k < 4; k++) { clc3(a, i, b, j, c, k, d); } } } } void clc(ll a, ll b, ll c, ll d) { ll t[] = {a, b, c, d}; do { clc2(t[0], t[1], t[2], t[3]); } while (next_permutation(t, t + 4)); } double heron(ll a, ll b, ll c) { double s = (double)(a + b + c) / 2.0; return sqrt(s * (s - a) * (s - b) * (s - c)); } double calcThreePS(double x1, double y1, double x2, double y2, double x3, double y3) { return abs((x1 * y2 + x2 * y3 + x3 * y1 - y1 * x2 - y2 * x3 - y3 * x1) / 2.0); } double memo[310][310][310]; void solv() { ll k; cin >> n >> k; ll a[110]; for (size_t i = 0; i < n; i++) { cin >> a[i]; } bool dp[100010]; memset(dp, 0, sizeof(dp)); for (int j = 0; j <= k; j++) { for (int i = 0; i < n; i++) { if (j - a[i] < 0) continue; else dp[j] |= !dp[j - a[i]]; } } if (dp[k]) { cout << "First" << endl; } else cout << "Second" << endl; } int main() { // COMinit(); solv(); return 0; }
replace
1,013
1,016
1,013
1,016
-11
p03170
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define gcd __gcd #define F first #define B begin() #define E end() #define ln length() #define sz size() #define S second #define em empty() #define mp make_pair #define pb push_back #define pq priority_queue #define um unordered_map #define us unordered_set #define lb lower_bound #define ub upper_bound #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define sbits(a) __builtin_popcount(a) #define lcm(a, b) ((a * b) / gcd(a, b)) #define nani(x) cerr << #x << " is " << x << endl; #define adde(g, u, v) g[u].pb(v), g[v].pb(u); #define addew(g, u, v, w) g[u].pb({v, w}), g[v].pb({u, w}); #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define inf 10000000000 #define mod 1000000007 typedef long long ll; const int N = 1e5 + 5; int A[105]; bool dp[N]; int main() { fast; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i <= k; i++) { int z = !dp[i]; for (int x = 0; x < n; x++) { if (i + A[x] <= k && !dp[i + A[x]]) dp[i + A[i]] |= z; } } if (dp[k]) cout << "First"; else cout << "Second"; return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define gcd __gcd #define F first #define B begin() #define E end() #define ln length() #define sz size() #define S second #define em empty() #define mp make_pair #define pb push_back #define pq priority_queue #define um unordered_map #define us unordered_set #define lb lower_bound #define ub upper_bound #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define sbits(a) __builtin_popcount(a) #define lcm(a, b) ((a * b) / gcd(a, b)) #define nani(x) cerr << #x << " is " << x << endl; #define adde(g, u, v) g[u].pb(v), g[v].pb(u); #define addew(g, u, v, w) g[u].pb({v, w}), g[v].pb({u, w}); #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define inf 10000000000 #define mod 1000000007 typedef long long ll; const int N = 1e5 + 5; int A[105]; bool dp[N]; int main() { fast; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i <= k; i++) { int z = !dp[i]; for (int x = 0; x < n; x++) { if (i + A[x] <= k && !dp[i + A[x]]) dp[i + A[x]] |= z; } } if (dp[k]) cout << "First"; else cout << "Second"; return 0; }
replace
68
69
68
69
0
p03170
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int stones(vector<int> &v, int k) { int dp[k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int x : v) { if (i < x) continue; if (dp[i - x] == 0) dp[i] = 1; // if taro starts with k ans removing some value // dp[i-ai] = 1 then other person will win from that k. } } return dp[k]; } void solve() { int n, k; cin >> n >> k; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } if (stones(v, k) == 1) cout << "First"; else cout << "Second"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int stones(vector<int> &v, int k) { int dp[k + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int x : v) { if (i < x) continue; if (dp[i - x] == 0) dp[i] = 1; // if taro starts with k ans removing some value // dp[i-ai] = 1 then other person will win from that k. } } return dp[k]; } void solve() { int n, k; cin >> n >> k; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } if (stones(v, k) == 1) cout << "First"; else cout << "Second"; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif solve(); return 0; }
replace
36
40
36
40
TLE
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 9; const int K = 1e5 + 9; int n, k; int a[N]; bool dp[K]; // ็Ÿณใฎๅ€‹ๆ•ฐใŒ k ๅ€‹ใชใ‚‰ first ใฏๅฟ…ใš่ฒ ใ‘ใ‚‹ int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; fill(&dp[0], &dp[K], true); for (int s = 0; s <= k; s++) { for (int i = 1; i <= n; i++) { if (dp[s]) dp[s + a[i]] = false; } } cout << (dp[k] ? "Second" : "First") << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 9; const int K = 1e6; int n, k; int a[N]; bool dp[K]; // ็Ÿณใฎๅ€‹ๆ•ฐใŒ k ๅ€‹ใชใ‚‰ first ใฏๅฟ…ใš่ฒ ใ‘ใ‚‹ int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; fill(&dp[0], &dp[K], true); for (int s = 0; s <= k; s++) { for (int i = 1; i <= n; i++) { if (dp[s]) dp[s + a[i]] = false; } } cout << (dp[k] ? "Second" : "First") << endl; }
replace
3
4
3
4
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil = pair<int, long>; using pll = pair<long, long>; #define fix20 cout << fixed << setprecision(20) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, t) for (int i = s; i < t; i++) #define RNG(i, s, t, u) for (int i = s; i < t; i += u) #define MOD 1000000007 #define all(vec) vec.begin(), vec.end() vi dp(100010, -1); int dfs(vi &a, int i) { if (dp[i] != -1) return dp[i]; if (i < a[0]) return dp[i] = 0; int ret = 0; for (int v : a) { ret |= (1 - dfs(a, i - v)); } return dp[i] = ret; } int main() { int n, k; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; sort(all(a)); if (dfs(a, k) == 1) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil = pair<int, long>; using pll = pair<long, long>; #define fix20 cout << fixed << setprecision(20) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, t) for (int i = s; i < t; i++) #define RNG(i, s, t, u) for (int i = s; i < t; i += u) #define MOD 1000000007 #define all(vec) vec.begin(), vec.end() vi dp(100010, -1); int dfs(vi &a, int i) { if (dp[i] != -1) return dp[i]; if (i < a[0]) return dp[i] = 0; int ret = 0; for (int v : a) { if (i - v < 0) continue; ret |= (1 - dfs(a, i - v)); } return dp[i] = ret; } int main() { int n, k; cin >> n >> k; vi a(n); rep(i, n) cin >> a[i]; sort(all(a)); if (dfs(a, k) == 1) cout << "First" << endl; else cout << "Second" << endl; }
insert
31
31
31
33
0
p03170
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstring> #include <iostream> #include <math.h> #include <numeric> #include <regex> #include <string> #include <vector> using namespace std; using ll = long long; using dbl = double; using pii = pair<int, int>; using pl4 = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vpii = vector<pii>; using vvpii = vector<vpii>; using vpl4 = vector<pl4>; using vvpl4 = vector<vpl4>; using vd = vector<dbl>; using vvd = vector<vd>; #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rFOR(i, a, b) for (int i = (b); i >= (a); i--) #define REP(i, a) FOR((i), 0, (a)-1) #define REP0(i, a) FOR((i), 0, (a)) #define REP1(i, a) FOR((i), 1, (a)) #define rREP(i, a) rFOR((i), 0, (a)-1) #define rREP0(i, a) rFOR((i), 0, (a)) #define rREP1(i, a) rFOR((i), 1, (a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << endl; #define Yn(a) cout << ((a) ? "Yes" : "No") << endl; #define YN(a) cout << ((a) ? "YES" : "NO") << endl; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl; #define say(a) cout << (a); #define sal(a) cout << (a) << endl; #define sak cout << endl; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cout << (#a) << ": " << (a) << endl; #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) (1 << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) #define llin(a) \ ll(a); \ cin >> (a); #define stin(a) \ string(a); \ cin >> (a); #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define min(a, b) ((a < b) ? (a) : (b)) #define max(a, b) ((a > b) ? (a) : (b)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define int ll const ll MOD = 1e9 + 7; const ll N = 1e5 + 20; // const ll MOD = 998244353; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; class BIT { public: vll d; vll v; ll size; BIT(ll sizeget) { size = sizeget; d.asn(size + 1, 0); v.asn(size, 0); } BIT(vll cpyvec) { copy(cpyvec); } void add(ll index, ll num) { // if (index < 0) return false; // if (index >= size) return false; v[index] += num; index++; while (index <= size) { d[index] += num; index += LSB(index); } // return true; return; } ll sum(ll index = INF) { index++; index = min(index, size); ll ans = 0; while (index) { ans += d[index]; index -= LSB(index); } return ans; } void copy(vll cpyvec) { size = cpyvec.sz; d.asn(size + 1, 0); v.asn(size, 0); REP(i, size) add(i, cpyvec[i]); } }; class UFT { public: ll size; ll mode; vll root; vll rank; UFT(ll sizeget, ll modeget = 0) { size = sizeget; mode = modeget; root.res(size, 0); if (!mode) rank.res(size, 0); IOTA(root, 0); } ll find(ll x) { return root[x] == x ? x : root[x] = find(root[x]); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (mode) root[y] = x; else { if (rank[x] < rank[y]) { root[x] = y; } else { root[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll inverse[N]; void init_inverse() { inverse[1] = 1; for (int i = 2; i < N; i++) inverse[i] = (MOD - MOD / i) * inverse[MOD % i] % MOD; } pl4 Bezout(ll a, ll b) { if (b != 0) { pl4 xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } if (b == 0) { return mp(1, 0); } } pl4 Bez(ll a, ll b, ll c) { pl4 xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } void salv(vll v) { say("{"); FOR(i, 0, v.sz - 1) { say(v[i]); if (i != v.sz - 1) say(","); } sal("}") } ll DigS10(ll n) { ll m = 0; FOR(i, 0, DigN10(n) - 1) { m += (ll)((llabs(n) % (ll)(pow(10.0, (double)(i + 1)))) / (ll)(pow(10.0, (double)i))); } return m; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n)) { if (n % i == 0) return 0; } return 1; } vll FactM(1, 1); vll FactMI(1, 1); ll PowM(ll a, ll b) { ll ans = 1, x = (a % MOD); FOR(i, 0, DigN2(b) - 1) { if (Dig2(b, i) == 1) ans = (ans * x) % MOD; if (i != (DigN2(b) - 1)) x = (x * x) % MOD; } return ans; } ll Mod(ll a) { a %= MOD; a = (a + MOD) % MOD; return a; } ll InvM(ll a) { a = Mod(a); a = PowM(a, MOD - 2); return a; } void CFactM(ll n) { if (FactM.sz <= n) { FOR(i, FactM.sz, n) { FactM.pb((FactM[i - 1] * (i % MOD)) % MOD); } } return; } void CFactMI(ll n) { CFactM(n); if (FactMI.sz < (n + 1)) FactMI.res(n + 1, -1); if (FactMI[n] == -1) FactMI[n] = PowM(FactM[n], MOD - 2); rFOR(i, 1, n - 1) { if (FactMI[i] != -1) break; FactMI[i] = ((FactMI[i + 1] * ((i + 1) % MOD)) % MOD); } return; } ll CombM(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (n < k) return 0; if (n + 1 > FactMI.sz) CFactMI(n); return ((((FactMI[k] * FactMI[n - k]) % MOD) * FactM[n]) % MOD); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } void cmprs(vll &v) { if (v.sz == 0) return; vll vv(v); IOTA(vv, 0); sort(vv.bgn, vv.en, [&](ll v1, ll v2) { return v[v1] < v[v2]; }); IOTA(v, 0); sort(v.bgn, v.en, [&](ll v1, ll v2) { return vv[v1] < vv[v2]; }); return; } ll BblCnt(vll v) { cmprs(v); BIT b(v.sz); ll ans = 0; REP(i, v.sz) { ans += (i - b.sum(v[i])); b.add(v[i], 1); } return ans; } signed main() { ll n, k, m = 100010; cin >> n >> k; vll a(n + 1), dp(k + 1, 0); REP(i, n) { cin >> a[i]; m = min(m, a[i]); } REP(i, m) { dp[i] = 2; } FOR(i, m, k) { REP(j, n) { if (dp[i - a[j]] == 2) { dp[i] = 1; } } if (dp[i] == 0) dp[i] = 2; } cout << ((dp[k] == 1) ? "First" : "Second"); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstring> #include <iostream> #include <math.h> #include <numeric> #include <regex> #include <string> #include <vector> using namespace std; using ll = long long; using dbl = double; using pii = pair<int, int>; using pl4 = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vpii = vector<pii>; using vvpii = vector<vpii>; using vpl4 = vector<pl4>; using vvpl4 = vector<vpl4>; using vd = vector<dbl>; using vvd = vector<vd>; #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rFOR(i, a, b) for (int i = (b); i >= (a); i--) #define REP(i, a) FOR((i), 0, (a)-1) #define REP0(i, a) FOR((i), 0, (a)) #define REP1(i, a) FOR((i), 1, (a)) #define rREP(i, a) rFOR((i), 0, (a)-1) #define rREP0(i, a) rFOR((i), 0, (a)) #define rREP1(i, a) rFOR((i), 1, (a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << endl; #define Yn(a) cout << ((a) ? "Yes" : "No") << endl; #define YN(a) cout << ((a) ? "YES" : "NO") << endl; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl; #define say(a) cout << (a); #define sal(a) cout << (a) << endl; #define sak cout << endl; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cout << (#a) << ": " << (a) << endl; #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) (1 << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) #define llin(a) \ ll(a); \ cin >> (a); #define stin(a) \ string(a); \ cin >> (a); #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define min(a, b) ((a < b) ? (a) : (b)) #define max(a, b) ((a > b) ? (a) : (b)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define int ll const ll MOD = 1e9 + 7; const ll N = 1e5 + 20; // const ll MOD = 998244353; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; class BIT { public: vll d; vll v; ll size; BIT(ll sizeget) { size = sizeget; d.asn(size + 1, 0); v.asn(size, 0); } BIT(vll cpyvec) { copy(cpyvec); } void add(ll index, ll num) { // if (index < 0) return false; // if (index >= size) return false; v[index] += num; index++; while (index <= size) { d[index] += num; index += LSB(index); } // return true; return; } ll sum(ll index = INF) { index++; index = min(index, size); ll ans = 0; while (index) { ans += d[index]; index -= LSB(index); } return ans; } void copy(vll cpyvec) { size = cpyvec.sz; d.asn(size + 1, 0); v.asn(size, 0); REP(i, size) add(i, cpyvec[i]); } }; class UFT { public: ll size; ll mode; vll root; vll rank; UFT(ll sizeget, ll modeget = 0) { size = sizeget; mode = modeget; root.res(size, 0); if (!mode) rank.res(size, 0); IOTA(root, 0); } ll find(ll x) { return root[x] == x ? x : root[x] = find(root[x]); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (mode) root[y] = x; else { if (rank[x] < rank[y]) { root[x] = y; } else { root[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll inverse[N]; void init_inverse() { inverse[1] = 1; for (int i = 2; i < N; i++) inverse[i] = (MOD - MOD / i) * inverse[MOD % i] % MOD; } pl4 Bezout(ll a, ll b) { if (b != 0) { pl4 xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } if (b == 0) { return mp(1, 0); } } pl4 Bez(ll a, ll b, ll c) { pl4 xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } void salv(vll v) { say("{"); FOR(i, 0, v.sz - 1) { say(v[i]); if (i != v.sz - 1) say(","); } sal("}") } ll DigS10(ll n) { ll m = 0; FOR(i, 0, DigN10(n) - 1) { m += (ll)((llabs(n) % (ll)(pow(10.0, (double)(i + 1)))) / (ll)(pow(10.0, (double)i))); } return m; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n)) { if (n % i == 0) return 0; } return 1; } vll FactM(1, 1); vll FactMI(1, 1); ll PowM(ll a, ll b) { ll ans = 1, x = (a % MOD); FOR(i, 0, DigN2(b) - 1) { if (Dig2(b, i) == 1) ans = (ans * x) % MOD; if (i != (DigN2(b) - 1)) x = (x * x) % MOD; } return ans; } ll Mod(ll a) { a %= MOD; a = (a + MOD) % MOD; return a; } ll InvM(ll a) { a = Mod(a); a = PowM(a, MOD - 2); return a; } void CFactM(ll n) { if (FactM.sz <= n) { FOR(i, FactM.sz, n) { FactM.pb((FactM[i - 1] * (i % MOD)) % MOD); } } return; } void CFactMI(ll n) { CFactM(n); if (FactMI.sz < (n + 1)) FactMI.res(n + 1, -1); if (FactMI[n] == -1) FactMI[n] = PowM(FactM[n], MOD - 2); rFOR(i, 1, n - 1) { if (FactMI[i] != -1) break; FactMI[i] = ((FactMI[i + 1] * ((i + 1) % MOD)) % MOD); } return; } ll CombM(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (n < k) return 0; if (n + 1 > FactMI.sz) CFactMI(n); return ((((FactMI[k] * FactMI[n - k]) % MOD) * FactM[n]) % MOD); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } void cmprs(vll &v) { if (v.sz == 0) return; vll vv(v); IOTA(vv, 0); sort(vv.bgn, vv.en, [&](ll v1, ll v2) { return v[v1] < v[v2]; }); IOTA(v, 0); sort(v.bgn, v.en, [&](ll v1, ll v2) { return vv[v1] < vv[v2]; }); return; } ll BblCnt(vll v) { cmprs(v); BIT b(v.sz); ll ans = 0; REP(i, v.sz) { ans += (i - b.sum(v[i])); b.add(v[i], 1); } return ans; } signed main() { ll n, k, m = 100010; cin >> n >> k; vll a(n + 1), dp(k + 1, 0); REP(i, n) { cin >> a[i]; m = min(m, a[i]); } REP(i, m) { dp[i] = 2; } FOR(i, m, k) { REP(j, n) { if (i - a[j] >= 0) { if (dp[i - a[j]] == 2) { dp[i] = 1; } } } if (dp[i] == 0) dp[i] = 2; } cout << ((dp[k] == 1) ? "First" : "Second"); return 0; }
replace
391
393
391
395
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define endl '\n' using namespace std; int const MX = 100009; int N, K, a[MX], dp[MX][2]; // dp[k][p] = can player p win with k stones if so 1 else 2 int const lose = 2, win = 1; void read_input() { cin >> N >> K; for (int i = 1; i <= N; ++i) { cin >> a[i]; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); read_input(); for (int i = 0; i < a[0]; ++i) { dp[i][0] = dp[i][1] = 0; } for (int k = 0; k <= K; ++k) { for (int p = 0; p <= 1; ++p) { for (int i = 1; i <= N; ++i) { int n = a[i]; if (n > k) dp[k][p] = lose; // lose if (dp[k - n][1 - p] == lose) { dp[k][p] = win; break; } } if (dp[k][p] == 0) dp[k][p] = lose; } } if (dp[K][0] == win) cout << "First" << endl; else cout << "Second" << endl; }
#include <bits/stdc++.h> #define endl '\n' using namespace std; int const MX = 100009; int N, K, a[MX], dp[MX][2]; // dp[k][p] = can player p win with k stones if so 1 else 2 int const lose = 2, win = 1; void read_input() { cin >> N >> K; for (int i = 1; i <= N; ++i) { cin >> a[i]; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); read_input(); for (int i = 0; i < a[0]; ++i) { dp[i][0] = dp[i][1] = 0; } for (int k = 0; k <= K; ++k) { for (int p = 0; p <= 1; ++p) { for (int i = 1; i <= N; ++i) { int n = a[i]; if (n > k) { continue; } if (dp[k - n][1 - p] == lose) { dp[k][p] = win; break; } } if (dp[k][p] == 0) dp[k][p] = lose; } } if (dp[K][0] == win) cout << "First" << endl; else cout << "Second" << endl; }
replace
29
31
29
32
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define all(x) x.begin(), x.end() #define ff first #define ss second #define mod 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n), dp(k + 1, 0); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i <= k; ++i) { for (auto j : a) { if (j >= i && !dp[i - j]) dp[i] = 1; } } if (dp[k]) cout << "First"; else cout << "Second"; // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " // ms\n" ; return 0; }
#include <bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define all(x) x.begin(), x.end() #define ff first #define ss second #define mod 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n), dp(k + 1, 0); for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i <= k; ++i) { for (auto j : a) { if (i >= j && !dp[i - j]) dp[i] = 1; } } if (dp[k]) cout << "First"; else cout << "Second"; // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " // ms\n" ; return 0; }
replace
23
24
23
24
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cin.exceptions(cin.failbit); #define int long long int // Comment when Unnecessary #define ll long long #define sz(a) (int)((a).size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define pii pair<int, int> #define vi vector<int> #define F first #define S second #define endl "\n" // Remove on Interactive const int N = 300009; const int mod = 1000000007; int32_t main() { IOS; int n, k; cin >> n >> k; vi a(n); rep(i, 0, n) { cin >> a[i]; } vector<bool> dp(n, false); rep(i, 1, k + 1) { trav(it, a) { if ((i - it) >= 0) { if (dp[i - it] == false) dp[i] = true; } } } if (dp[k]) { cout << "First\n"; } else { cout << "Second\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cin.exceptions(cin.failbit); #define int long long int // Comment when Unnecessary #define ll long long #define sz(a) (int)((a).size()) #define all(a) a.begin(), a.end() #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto &a : x) #define pii pair<int, int> #define vi vector<int> #define F first #define S second #define endl "\n" // Remove on Interactive const int N = 300009; const int mod = 1000000007; int32_t main() { IOS; int n, k; cin >> n >> k; vi a(n); rep(i, 0, n) { cin >> a[i]; } vector<bool> dp(k + 1, false); rep(i, 1, k + 1) { trav(it, a) { if ((i - it) >= 0) { if (dp[i - it] == false) dp[i] = true; } } } if (dp[k]) { cout << "First\n"; } else { cout << "Second\n"; } return 0; }
replace
29
30
29
30
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; typedef pair<int, int> P; const int INF = 1001001001; const long double PI = (acos(-1)); const int mod = 1e9 + 7; const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } vector<bool> dp(150, false); rep(i, k + 1) { rep(j, n) { if (i - a[j] >= 0 && dp[i - a[j]] == false) dp[i] = true; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; cout << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; typedef pair<int, int> P; const int INF = 1001001001; const long double PI = (acos(-1)); const int mod = 1e9 + 7; const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) { cin >> a[i]; } vector<bool> dp(k + 1, false); rep(i, k + 1) { rep(j, n) { if (i - a[j] >= 0 && dp[i - a[j]] == false) dp[i] = true; } } if (dp[k]) cout << "First" << endl; else cout << "Second" << endl; cout << endl; return 0; }
replace
22
23
22
23
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> v(n); vector<bool> vu(k + 1); for (int i = 0; i < n; ++i) cin >> v[i]; for (int i = 0; i <= k; ++i) { if (!vu[i]) { for (int k : v) vu[i + k] = true; } } if (vu[k]) cout << "First"; else cout << "Second"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> v(n); vector<bool> vu(2 * k + 1); for (int i = 0; i < n; ++i) cin >> v[i]; for (int i = 0; i <= k; ++i) { if (!vu[i]) { for (int k : v) vu[i + k] = true; } } if (vu[k]) cout << "First"; else cout << "Second"; return 0; }
replace
9
10
9
10
0
p03170
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; bool recursive(int N, int K, vector<int> &a, bool turn, vector<vector<int>> &table) { if (table[K][turn] != -1) return table[K][turn]; if (K < a[0]) { table[K][turn] = !turn; return !turn; } else { for (int i = 0; i < N; ++i) { bool result = recursive(N, K - a[i], a, !turn, table); if (result == turn) { table[K][turn] = turn; return turn; } } table[K][turn] = !turn; return !turn; } } int main() { int N, K; cin >> N >> K; vector<int> a(N, 0); for (int i = 0; i < N; ++i) cin >> a[i]; vector<vector<int>> table(K + 1, vector<int>(2, -1)); bool result = recursive(N, K, a, false, table); if (result) cout << "Second"; else cout << "First"; }
#include <iostream> #include <vector> using namespace std; bool recursive(int N, int K, vector<int> &a, bool turn, vector<vector<int>> &table) { if (table[K][turn] != -1) return table[K][turn]; if (K < a[0]) { table[K][turn] = !turn; return !turn; } else { for (int i = 0; i < N; ++i) { if (K - a[i] < 0) break; bool result = recursive(N, K - a[i], a, !turn, table); if (result == turn) { table[K][turn] = turn; return turn; } } table[K][turn] = !turn; return !turn; } } int main() { int N, K; cin >> N >> K; vector<int> a(N, 0); for (int i = 0; i < N; ++i) cin >> a[i]; vector<vector<int>> table(K + 1, vector<int>(2, -1)); bool result = recursive(N, K, a, false, table); if (result) cout << "Second"; else cout << "First"; }
insert
13
13
13
15
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool dp[100011]; 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) { for (int j = 0; j < n; ++j) { if (!dp[i]) dp[i + a[j]] = true; } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool dp[200011]; 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) { for (int j = 0; j < n; ++j) { if (!dp[i]) dp[i + a[j]] = true; } } if (dp[k]) { cout << "First" << endl; } else { cout << "Second" << endl; } return 0; }
replace
3
4
3
4
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)n; i++) #define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++) #define all(x) x.begin(), x.end() #define MOD 1000000007 // 1e9+7 using namespace std; typedef long long ll; typedef vector<bool> vecbool; typedef vector<int> vecint; typedef vector<ll> vecll; typedef vector<string> vecstr; typedef vector<vecint> vec2int; typedef vector<vecbool> vec2bool; int dx[4]{-1, +1, 0, 0}; int dy[4]{0, 0, -1, +1}; void init() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); } vecint a; vec2int dp; int n, k; bool rec(int p, int q) { // if (p <= 0) return false; if (dp[p][q] != -1) return dp[p][q] == 1 ? true : false; int r = 0; if (q == 0) r = 1; REP(i, n) { if (p <= a[i]) { if (!rec(p - a[i], r)) { dp[p][q] = 1; return true; } } } dp[p][q] = 0; return false; } int main() { init(); cin >> n >> k; a.resize(n); for (auto &e : a) cin >> e; dp = vector<vector<int>>(k + 1, vecint(2, -1)); // REP(i, a[0]) dp[i][0] = dp[i][1] = 0; // for (const auto& e : a) dp[e][0] = dp[e][1] = 1; // // REP(i, k + 1) { cout << i << " " << dp[i][0] << " " << dp[i][1] << endl; // } cout << (rec(k, 0) ? "First" : "Second") << endl; // REP(i, k + 1) { cout << "i: " << dp[i][0] << " " << dp[i][1] << endl; } }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)n; i++) #define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++) #define all(x) x.begin(), x.end() #define MOD 1000000007 // 1e9+7 using namespace std; typedef long long ll; typedef vector<bool> vecbool; typedef vector<int> vecint; typedef vector<ll> vecll; typedef vector<string> vecstr; typedef vector<vecint> vec2int; typedef vector<vecbool> vec2bool; int dx[4]{-1, +1, 0, 0}; int dy[4]{0, 0, -1, +1}; void init() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); } vecint a; vec2int dp; int n, k; bool rec(int p, int q) { // if (p <= 0) return false; if (dp[p][q] != -1) return dp[p][q] == 1 ? true : false; int r = 0; if (q == 0) r = 1; REP(i, n) { if (p >= a[i]) { if (!rec(p - a[i], r)) { dp[p][q] = 1; return true; } } } dp[p][q] = 0; return false; } int main() { init(); cin >> n >> k; a.resize(n); for (auto &e : a) cin >> e; dp = vector<vector<int>>(k + 1, vecint(2, -1)); // REP(i, a[0]) dp[i][0] = dp[i][1] = 0; // for (const auto& e : a) dp[e][0] = dp[e][1] = 1; // // REP(i, k + 1) { cout << i << " " << dp[i][0] << " " << dp[i][1] << endl; // } cout << (rec(k, 0) ? "First" : "Second") << endl; // REP(i, k + 1) { cout << "i: " << dp[i][0] << " " << dp[i][1] << endl; } }
replace
31
32
31
32
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ff first #define ss second #define eb emplace_back #define MP make_pair #define pb push_back #define pf push_front #define ins insert #define all(v) (v).begin(), (v).end() #define mset(m, v) memset(m, v, sizeof(m)) #define tr(c, it) for (auto it = c.begin(); it != c.end(); it++) #define fr(i, n) for (lli i = 0; i < (n); i++) #define inc(i, a, b) for (lli i = a; i <= b; i++) #define dec(i, a, b) for (lli i = a; i >= b; i--) #define fr2(i, n) for (int i = 0; i < (n); i++) #define inc2(i, a, b) for (int i = a; i <= b; i++) #define dec2(i, a, b) for (int i = a; i >= b; i--) #define ymin(a, b) (a = min((a), (b))) #define ymax(a, b) (a = max((a), (b))) #define sz(x) (lli)(x).size() typedef long long int lli; typedef long double ld; typedef pair<int, int> pii; typedef pair<lli, lli> plli; typedef vector<lli> vlli; typedef vector<int> vi; // typedef vector<vector<lli> >ncr(1001,vector<lli>(1001,0)) typedef vector<plli> vplli; long long MOD = 1000000009; double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } lli pwr(lli x, lli n) { lli res = 1; for (; n != 0; n >>= 1) { if (n & 1) res = (res * x) % MOD; x = (x * x) % MOD; } return res; } lli inver(lli num) { return pwr(num, MOD - 2); } lli findncr(lli n, lli r) { r = min(r, n - r); if (n == 0 || n == 1 || r == 0) return 1; lli numer = 1; for (lli i = n; i >= n - r + 1; i--) numer = (numer * i) % MOD; lli den = 1; for (lli i = 2; i <= r; i++) den = (den * i) % MOD; den = inver(den); lli res = (numer * den) % MOD; return res; } lli gcd(lli a, lli b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS int n, k; cin >> n >> k; vector<int> vec(n + 1, 0); fr2(i, n) cin >> vec[i]; vector<int> win(k + 1, 2); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (vec[j] - i > 0) continue; else { if (win[i - vec[j]] == 2) win[i] = 1; } } } auto p = win[k] == 1 ? "First" : "Second"; cout << p << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ff first #define ss second #define eb emplace_back #define MP make_pair #define pb push_back #define pf push_front #define ins insert #define all(v) (v).begin(), (v).end() #define mset(m, v) memset(m, v, sizeof(m)) #define tr(c, it) for (auto it = c.begin(); it != c.end(); it++) #define fr(i, n) for (lli i = 0; i < (n); i++) #define inc(i, a, b) for (lli i = a; i <= b; i++) #define dec(i, a, b) for (lli i = a; i >= b; i--) #define fr2(i, n) for (int i = 0; i < (n); i++) #define inc2(i, a, b) for (int i = a; i <= b; i++) #define dec2(i, a, b) for (int i = a; i >= b; i--) #define ymin(a, b) (a = min((a), (b))) #define ymax(a, b) (a = max((a), (b))) #define sz(x) (lli)(x).size() typedef long long int lli; typedef long double ld; typedef pair<int, int> pii; typedef pair<lli, lli> plli; typedef vector<lli> vlli; typedef vector<int> vi; // typedef vector<vector<lli> >ncr(1001,vector<lli>(1001,0)) typedef vector<plli> vplli; long long MOD = 1000000009; double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } lli pwr(lli x, lli n) { lli res = 1; for (; n != 0; n >>= 1) { if (n & 1) res = (res * x) % MOD; x = (x * x) % MOD; } return res; } lli inver(lli num) { return pwr(num, MOD - 2); } lli findncr(lli n, lli r) { r = min(r, n - r); if (n == 0 || n == 1 || r == 0) return 1; lli numer = 1; for (lli i = n; i >= n - r + 1; i--) numer = (numer * i) % MOD; lli den = 1; for (lli i = 2; i <= r; i++) den = (den * i) % MOD; den = inver(den); lli res = (numer * den) % MOD; return res; } lli gcd(lli a, lli b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif IOS int n, k; cin >> n >> k; vector<int> vec(n + 1, 0); fr2(i, n) cin >> vec[i]; vector<int> win(k + 1, 2); for (int i = 1; i <= k; i++) { for (int j = 0; j < n; j++) { if (vec[j] - i > 0) continue; else { if (win[i - vec[j]] == 2) win[i] = 1; } } } auto p = win[k] == 1 ? "First" : "Second"; cout << p << endl; }
replace
69
73
69
73
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> // #include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set using namespace std; const ll MOD = 1000000007; const ll INF = (1LL << 62); ll dp[110000]; int main() { // std::cout << std::fixed << std::setprecision(10); ll N, K; scanf("%lld %lld", &N, &K); vector<ll> list(N); for (ll i = 0; i < N; i++) { ll v; scanf("%lld", &v); list[i] = v; } for (ll i = 0; i <= K; i++) { if (!dp[i]) { for (ll j = 0; j < N; j++) { dp[i + list[j]] = 1; } } } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> #include <iostream> // #include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set using namespace std; const ll MOD = 1000000007; const ll INF = (1LL << 62); ll dp[110000]; int main() { // std::cout << std::fixed << std::setprecision(10); ll N, K; scanf("%lld %lld", &N, &K); vector<ll> list(N); for (ll i = 0; i < N; i++) { ll v; scanf("%lld", &v); list[i] = v; } for (ll i = 0; i <= K; i++) { if (!dp[i]) { for (ll j = 0; j < N; j++) { if (i + list[j] <= K) { dp[i + list[j]] = 1; } } } } if (dp[K]) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
31
32
31
34
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, arr[101], k; bool dp[100001]; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (!dp[i - arr[j]]) { dp[i] = true; break; } } } if (dp[k]) { cout << "First" << '\n'; } else { cout << "Second" << '\n'; } }
#include <bits/stdc++.h> using namespace std; int n, arr[101], k; bool dp[100001]; int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (arr[j] > i) { break; } if (!dp[i - arr[j]]) { dp[i] = true; break; } } } if (dp[k]) { cout << "First" << '\n'; } else { cout << "Second" << '\n'; } }
insert
15
15
15
18
0
p03170
C++
Runtime Error
/* * author: chw0501 * created: 15.04.2020 07:37:31(UTC) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int n, k; vector<int> v; // dp[i]: i๊ฐœ์˜ ๋Œ์ด ๋‚จ์•˜์„ ๋•Œ ํ”Œ๋ ˆ์ด ํ•  ๋•Œ ์ด๋ฒˆ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ด๊ธฐ๋ฉด 1, ์ง€๋ฉด 0์„ // ์ €์žฅ int dp[100001]; int solve(int i) { int &ret = dp[i]; if (ret != -1) return ret; if (i < v[0]) return ret = 0; ret = 0; for (int j = 0; j < n; j++) { if (solve(i - v[j]) == 0) ret = 1; } return ret; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); v.push_back(x); } memset(dp, -1, sizeof(dp)); if (solve(k) == 1) cout << "First"; else cout << "Second"; return 0; }
/* * author: chw0501 * created: 15.04.2020 07:37:31(UTC) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; int n, k; vector<int> v; // dp[i]: i๊ฐœ์˜ ๋Œ์ด ๋‚จ์•˜์„ ๋•Œ ํ”Œ๋ ˆ์ด ํ•  ๋•Œ ์ด๋ฒˆ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ์ด๊ธฐ๋ฉด 1, ์ง€๋ฉด 0์„ // ์ €์žฅ int dp[100001]; int solve(int i) { int &ret = dp[i]; if (ret != -1) return ret; if (i < v[0]) return ret = 0; ret = 0; for (int j = 0; j < n; j++) { if (v[j] > i) break; if (solve(i - v[j]) == 0) ret = 1; } return ret; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); v.push_back(x); } memset(dp, -1, sizeof(dp)); if (solve(k) == 1) cout << "First"; else cout << "Second"; return 0; }
insert
24
24
24
26
0
p03170
C++
Runtime Error
/** Which of the favors of your Lord will you deny ? **/ #include <bits/stdc++.h> using namespace std; #define LL long long #define PII pair<int, int> #define PLL pair<LL, LL> #define MP make_pair #define F first #define S second #define ALL(x) (x).begin(), (x).end() #define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl #define READ freopen("alu.txt", "r", stdin) #define WRITE freopen("vorta.txt", "w", stdout) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <class TIn> using indexed_set = tree<TIn, null_type, less<TIn>, rb_tree_tag, tree_order_statistics_node_update>; /** PBDS ------------------------------------------------- 1) insert(value) 2) erase(value) 3) order_of_key(value) // 0 based indexing 4) *find_by_order(position) // 0 based indexing **/ template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &v); template <class T> ostream &operator<<(ostream &os, set<T> &v); inline void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const int nmax = 2e5 + 7; const LL LINF = 1e17; template <class T> string to_str(T x) { stringstream ss; ss << x; return ss.str(); } // bool cmp(const PII &A,const PII &B) //{ // // } int main() { optimizeIO(); // WRITE; int n, k; cin >> n >> k; vector<int> dp(k + 1, -1); vector<int> v(n); int mn = INT_MAX; for (int i = 0; i < n; i++) cin >> v[i], mn = min(mn, v[i]); for (int i = 0; i < mn; i++) dp[i] = 0; /** lose **/ for (int i = mn; i <= k; i++) { for (int x : v) { if (x > i) break; if (dp[x - i] == 0) /** losing move available **/ dp[x] = 1; } if (dp[i] == -1) /** If no win available for first **/ dp[i] = 0; } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; return 0; } /** 1 4 3 2 4 2 3 2 5 2 3 2 7 2 3 **/ template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "} "; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { os << "[ "; for (int i = 0; i < v.size(); i++) { os << v[i] << " "; } os << " ]"; return os; } template <class T> ostream &operator<<(ostream &os, set<T> &v) { os << "[ "; for (T i : v) { os << i << " "; } os << " ]"; return os; }
/** Which of the favors of your Lord will you deny ? **/ #include <bits/stdc++.h> using namespace std; #define LL long long #define PII pair<int, int> #define PLL pair<LL, LL> #define MP make_pair #define F first #define S second #define ALL(x) (x).begin(), (x).end() #define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl #define READ freopen("alu.txt", "r", stdin) #define WRITE freopen("vorta.txt", "w", stdout) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <class TIn> using indexed_set = tree<TIn, null_type, less<TIn>, rb_tree_tag, tree_order_statistics_node_update>; /** PBDS ------------------------------------------------- 1) insert(value) 2) erase(value) 3) order_of_key(value) // 0 based indexing 4) *find_by_order(position) // 0 based indexing **/ template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p); template <class T> ostream &operator<<(ostream &os, vector<T> &v); template <class T> ostream &operator<<(ostream &os, set<T> &v); inline void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const int nmax = 2e5 + 7; const LL LINF = 1e17; template <class T> string to_str(T x) { stringstream ss; ss << x; return ss.str(); } // bool cmp(const PII &A,const PII &B) //{ // // } int main() { optimizeIO(); // WRITE; int n, k; cin >> n >> k; vector<int> dp(k + 1, -1); vector<int> v(n); int mn = INT_MAX; for (int i = 0; i < n; i++) cin >> v[i], mn = min(mn, v[i]); for (int i = 0; i < mn; i++) dp[i] = 0; /** lose **/ for (int i = mn; i <= k; i++) { for (int x : v) { if (x > i) break; if (dp[i - x] == 0) /** losing move available **/ dp[i] = 1; } if (dp[i] == -1) /** If no win available for first **/ dp[i] = 0; } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; return 0; } /** 1 4 3 2 4 2 3 2 5 2 3 2 7 2 3 **/ template <class T1, class T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << "{" << p.first << ", " << p.second << "} "; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { os << "[ "; for (int i = 0; i < v.size(); i++) { os << v[i] << " "; } os << " ]"; return os; } template <class T> ostream &operator<<(ostream &os, set<T> &v) { os << "[ "; for (T i : v) { os << i << " "; } os << " ]"; return os; }
replace
82
84
82
84
0
p03170
C++
Runtime Error
#pragma GCC optimize("03") #include <bits/stdc++.h> using namespace std; int n, k, a[105], dp[100005]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i <= k; ++i) { if (dp[i] == 0) for (int j = 1; j <= n; ++j) dp[i + a[j]] = 1; } cout << (dp[k] ? "First\n" : "Second\n"); return 0; }
#pragma GCC optimize("03") #include <bits/stdc++.h> using namespace std; int n, k, a[100005], dp[200005]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i <= k; ++i) { if (dp[i] == 0) for (int j = 1; j <= n; ++j) dp[i + a[j]] = 1; } cout << (dp[k] ? "First\n" : "Second\n"); return 0; }
replace
5
6
5
6
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int &x : a) { cin >> x; } vector<bool> dp(k + 1); dp[0] = false; for (int i = 0; i <= k; i++) { for (int j = 0; j < n; j++) { if (dp[i] == false) { dp[i + a[j]] = true; } } } if (dp[k] == true) { cout << "First" << endl; } else { cout << "Second" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int &x : a) { cin >> x; } vector<bool> dp(k + 1); dp[0] = false; for (int i = 0; i <= k; i++) { for (int j = 0; j < n; j++) { if (dp[i] == false && i + a[j] <= k) { dp[i + a[j]] = true; } } } if (dp[k] == true) { cout << "First" << endl; } else { cout << "Second" << endl; } }
replace
15
16
15
16
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k, a[101]; bool dp[100001]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0] = false; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (dp[i - a[j]] == false && i >= a[j]) { dp[i] = true; break; } } } if (dp[k] == true) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> using namespace std; int n, k, a[101]; bool dp[100001]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0] = false; for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { if (i >= a[j] && dp[i - a[j]] == false) { dp[i] = true; break; } } } if (dp[k] == true) cout << "First"; else cout << "Second"; }
replace
11
12
11
12
0
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; bool dp[100100]; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; rep(i, k) rep(j, n) if (!dp[i]) dp[i + a[j]] = true; cout << (dp[k] ? "First" : "Second") << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; bool dp[200100]; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; rep(i, k) rep(j, n) if (!dp[i]) dp[i + a[j]] = true; cout << (dp[k] ? "First" : "Second") << endl; return 0; }
replace
6
7
6
7
0
p03170
C++
Runtime Error
#include <iostream> #define MAXK 100100 using namespace std; int dp[MAXK]; int A[110]; int main() { int n, k; cin >> n >> k; for (int i = 0; i <= k; i++) dp[i] = -1; for (int i = 0; i < n; i++) cin >> A[i]; dp[0] = 1; for (int i = 0; i < n; i++) { dp[A[i]] = 0; } for (int i = 1; i <= k; i++) { if (dp[i] == -1) { dp[i] = 1; for (int j = 0; j < n; j++) { dp[i + A[j]] = 0; } } } if (dp[k] == 1) { cout << "Second\n"; } else cout << "First\n"; }
#include <iostream> #define MAXK 100100 using namespace std; int dp[MAXK]; int A[110]; int main() { int n, k; cin >> n >> k; for (int i = 0; i <= k; i++) dp[i] = -1; for (int i = 0; i < n; i++) cin >> A[i]; dp[0] = 1; for (int i = 0; i < n; i++) { dp[A[i]] = 0; } for (int i = 1; i <= k; i++) { if (dp[i] == -1) { dp[i] = 1; for (int j = 0; j < n; j++) { if (i + A[j] <= k) { dp[i + A[j]] = 0; } } } } if (dp[k] == 1) { cout << "Second\n"; } else cout << "First\n"; }
replace
26
27
26
29
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 std; typedef long long ll; using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> #define ordered_mset \ tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, \ tree_order_statistics_node_update> #define fr(i, a, b) for (int i = (a); i < (b); ++i) #define frr(i, a, b) for (ll i = (a - 1); i >= (b); --i) #define vi vector<int> #define vl vector<ll> #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define F first #define S second #define pii pair<int, int> #define rev(a) reverse(a.begin(), a.end()) #define srt(a) sort(a.begin(), a.end()) #define rsrt(a) sort(a.begin(), a.end(), greater<int>()) #define sz(a) (int)a.size() #define endl '\n' #define po(a, b) (ll)(pow(a, b) + 0.5) #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl; #define Fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const ll M = 1e9 + 7; const int MX = 1e5 + 5; int n, k; int dp[MX]; int val[MX]; int a[101]; int mn; int solve(int num) { if (val[num]) return 1; if (num < a[0]) return 0; if (dp[k] != -1) return dp[k]; int c = 0; fr(i, 0, n) { if (a[i] < num) { if (dp[num - a[i]] != -1 && c == 0) c = 1 - dp[num - a[i]]; else if (solve(num - a[i]) == 0) c = 1; } else break; } return dp[num] = c; } int main() { Fast cin >> n >> k; memset(dp, -1, sizeof dp); memset(val, 0, sizeof val); fr(i, 0, n) { cin >> a[i]; val[a[i]] = 1; } if (solve(k)) cout << "First"; else cout << "Second"; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> #define ordered_mset \ tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, \ tree_order_statistics_node_update> #define fr(i, a, b) for (int i = (a); i < (b); ++i) #define frr(i, a, b) for (ll i = (a - 1); i >= (b); --i) #define vi vector<int> #define vl vector<ll> #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define F first #define S second #define pii pair<int, int> #define rev(a) reverse(a.begin(), a.end()) #define srt(a) sort(a.begin(), a.end()) #define rsrt(a) sort(a.begin(), a.end(), greater<int>()) #define sz(a) (int)a.size() #define endl '\n' #define po(a, b) (ll)(pow(a, b) + 0.5) #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl; #define Fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const ll M = 1e9 + 7; const int MX = 1e5 + 5; int n, k; int dp[MX]; int val[MX]; int a[101]; int mn; int solve(int num) { if (val[num]) return 1; if (num < a[0]) return 0; if (dp[k] != -1) return dp[k]; int c = 0; fr(i, 0, n) { if (a[i] < num) { if (dp[num - a[i]] != -1) { if (c == 0) c = 1 - dp[num - a[i]]; } else if (solve(num - a[i]) == 0) c = 1; } else break; } return dp[num] = c; } int main() { Fast cin >> n >> k; memset(dp, -1, sizeof dp); memset(val, 0, sizeof val); fr(i, 0, n) { cin >> a[i]; val[a[i]] = 1; } if (solve(k)) cout << "First"; else cout << "Second"; }
replace
54
57
54
58
TLE
p03170
C++
Runtime Error
#pragma gcc optimize("Ofast") #include <bits/stdc++.h> using namespace std; int n, k; int dp[100005]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = a[0]; i <= k; i++) { for (int j = 0; a[j] <= i; j++) { if (dp[i - a[j]] == 0) dp[i] = 1; } } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; }
#pragma gcc optimize("Ofast") #include <bits/stdc++.h> using namespace std; int n, k; int dp[100005]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = a[0]; i <= k; i++) { for (int j = 0; a[j] <= i && j < n; j++) { if (dp[i - a[j]] == 0) dp[i] = 1; } } if (dp[k] == 1) cout << "First" << endl; else cout << "Second" << endl; }
replace
14
15
14
15
0
p03170
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; typename set<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define debug(x) cout << #x << " = " << x << endl; #define trace1(x) cout << #x << ": " << x << endl #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl typedef long long int ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<long long int, long long int> pll; typedef map<int, int> mii; typedef vector<pair<int, int>> vpii; #define endl "\n"; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(cont, it) \ for (decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define F first #define S second const ll mod = 1000000007; const ll inf = (ll)1e15; ll power(ll a, ll b, ll m = mod) { if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m; return x; } ll max(ll a, ll b) { return (a > b ? a : b); } ll min(ll a, ll b) { return (a < b ? a : b); } const int N = 105, M = 1e5 + 5; int a[N], k; int n; bool dp1[N], memo1[N], dp2[N], memo2[N]; bool func1(int); bool func2(int rem) { // cout << "inf"; if (rem == 0) return false; if (memo2[rem]) return dp2[rem]; memo2[rem] = true; bool ret = false; for (int i = 1; i <= n; i++) { if (rem - a[i] >= 0) ret |= (!func1(rem - a[i])); } return dp2[rem] = ret; } bool func1(int rem) { // cout << "inf1"; if (rem == 0) return false; if (memo1[rem]) return dp1[rem]; memo1[rem] = true; bool ret = false; for (int i = 1; i <= n; i++) { if (rem - a[i] >= 0) ret |= (!func2(rem - a[i])); } return dp1[rem] = ret; } void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool ans = func1(k); if (ans) { cout << "First" << endl; } else cout << "Second" << endl; } int main() { IOS; int t = 1, num = 1; ///// change this t for number of testcase globally while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename vector<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; typename set<T>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; typename map<F, S>::const_iterator it; for (it = v.begin(); it != v.end(); it++) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define debug(x) cout << #x << " = " << x << endl; #define trace1(x) cout << #x << ": " << x << endl #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl typedef long long int ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<long long int, long long int> pll; typedef map<int, int> mii; typedef vector<pair<int, int>> vpii; #define endl "\n"; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(cont, it) \ for (decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define F first #define S second const ll mod = 1000000007; const ll inf = (ll)1e15; ll power(ll a, ll b, ll m = mod) { if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m; return x; } ll max(ll a, ll b) { return (a > b ? a : b); } ll min(ll a, ll b) { return (a < b ? a : b); } const int N = 105, M = 1e5 + 5; int a[N], k; int n; bool dp1[M], memo1[M], dp2[M], memo2[M]; bool func1(int); bool func2(int rem) { // cout << "inf"; if (rem == 0) return false; if (memo2[rem]) return dp2[rem]; memo2[rem] = true; bool ret = false; for (int i = 1; i <= n; i++) { if (rem - a[i] >= 0) ret |= (!func1(rem - a[i])); } return dp2[rem] = ret; } bool func1(int rem) { // cout << "inf1"; if (rem == 0) return false; if (memo1[rem]) return dp1[rem]; memo1[rem] = true; bool ret = false; for (int i = 1; i <= n; i++) { if (rem - a[i] >= 0) ret |= (!func2(rem - a[i])); } return dp1[rem] = ret; } void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } bool ans = func1(k); if (ans) { cout << "First" << endl; } else cout << "Second" << endl; } int main() { IOS; int t = 1, num = 1; ///// change this t for number of testcase globally while (t--) { solve(); } return 0; }
replace
102
103
102
103
0