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
p02900
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i) #define repds(i, n) for (int i = (int)(n); i > 0; --i) #define loop(i, x, n) for (int i = (int)(x); i < (n); ++i) #define loops(i, x, n) for (int i = (int)(x); i <= (n); ++i) #define loopd(i, x, n) for (int i = (int)(x); i > (n); --i) #define loopds(i, x, n) for (int i = (int)(x); i >= (n); --i) #define itrep(i, s) for (auto i = begin(s); i != end(s); ++i) #define itrepd(i, s) for (auto i = --end(s); i != begin(s); --i) #define all(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ }(x) #define rall(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \ }(x) using ll = long long; using ld = long double; constexpr ll inf = static_cast<ll>(1e17); constexpr int iinf = static_cast<int>(1e9); constexpr double dinf = 1e10; constexpr ld ldinf = 1e17; constexpr ll mod = static_cast<ll>(1e9 + 7); std::ostream &endn(std::ostream &os) { return os.put(os.widen('\n')); } template <class T> constexpr int sz(const T &a) { return (int)a.size(); } template <class T, class... Args> constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); } template <class T, class... Args> constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); } template <class T> constexpr T gcd(T a, T b) { if (a < b) gcd(b, a); T r = 0; while ((r = a % b)) { a = b; b = r; } return b; } template <class T> constexpr T lcm(T a, T b) { T g = gcd<T>(a, b); return a / g * b; } ll a, b; void solve() { cin >> a >> b; auto l = gcd(a, b); ll ans = 0; int e = (int)ceil(sqrt(l)); vector<int> vec; reps(i, e) { if (l == 0) break; if (l % i == 0) { if (l / i != 1) vec.push_back(l / i); if (i != 1) { while (l % i == 0) l /= i; } ++ans; } } all(sort, vec); rep(i, vec.size()) { if (l == 0) break; if (l % vec[i] == 0) { if (i != 1) { while (l % vec[i] == 0) l /= vec[i]; } ++ans; } } cout << ans << endn; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); cout << flush; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i) #define repds(i, n) for (int i = (int)(n); i > 0; --i) #define loop(i, x, n) for (int i = (int)(x); i < (n); ++i) #define loops(i, x, n) for (int i = (int)(x); i <= (n); ++i) #define loopd(i, x, n) for (int i = (int)(x); i > (n); --i) #define loopds(i, x, n) for (int i = (int)(x); i >= (n); --i) #define itrep(i, s) for (auto i = begin(s); i != end(s); ++i) #define itrepd(i, s) for (auto i = --end(s); i != begin(s); --i) #define all(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ }(x) #define rall(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \ }(x) using ll = long long; using ld = long double; constexpr ll inf = static_cast<ll>(1e17); constexpr int iinf = static_cast<int>(1e9); constexpr double dinf = 1e10; constexpr ld ldinf = 1e17; constexpr ll mod = static_cast<ll>(1e9 + 7); std::ostream &endn(std::ostream &os) { return os.put(os.widen('\n')); } template <class T> constexpr int sz(const T &a) { return (int)a.size(); } template <class T, class... Args> constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); } template <class T, class... Args> constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); } template <class T> constexpr T gcd(T a, T b) { if (a < b) gcd(b, a); T r = 0; while ((r = a % b)) { a = b; b = r; } return b; } template <class T> constexpr T lcm(T a, T b) { T g = gcd<T>(a, b); return a / g * b; } ll a, b; void solve() { cin >> a >> b; auto l = gcd(a, b); ll ans = 0; int e = (int)ceil(sqrt(l)); vector<ll> vec; reps(i, e) { if (l == 0) break; if (l % i == 0) { if (l / i != 1) vec.push_back(l / i); if (i != 1) { while (l % i == 0) l /= i; } ++ans; } } all(sort, vec); rep(i, vec.size()) { if (l == 0) break; if (l % vec[i] == 0) { if (i != 1) { while (l % vec[i] == 0) l /= vec[i]; } ++ans; } } cout << ans << endn; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); cout << flush; return 0; }
replace
59
60
59
60
0
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e5; const long long INF = 1e9; int main() { long long a, b; cin >> a >> b; long long g = __gcd(a, b); int ans = 1; for (int i = 2; i * i <= g; i++) { if (g % i == 0) { ans++; while (!(g % i)) g /= i; } } if (g > 1) ans++; cout << ans; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1e5; const long long INF = 1e9; int main() { long long a, b; cin >> a >> b; long long g = __gcd(a, b); int ans = 1; for (int i = 2; 1ll * i * i <= g; i++) { if (g % i == 0) { ans++; while (!(g % i)) g /= i; } } if (g > 1) ans++; cout << ans; }
replace
13
14
13
14
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> #include <math.h> #include <numeric> using namespace std; #define ll long long ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } int main() { long long a, b; cin >> a >> b; long long ans = 1; ll g = gcd(a, b); for (int i = 2; i <= g; i++) { if (g % i == 0) { ans++; while (g % i == 0) { g /= i; } } } if (g > 1) { ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <math.h> #include <numeric> using namespace std; #define ll long long ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } int main() { long long a, b; cin >> a >> b; long long ans = 1; ll g = gcd(a, b); for (int i = 2; i <= sqrt(g); i++) { if (g % i == 0) { ans++; while (g % i == 0) { g /= i; } } } if (g > 1) { ans++; } cout << ans << endl; return 0; }
replace
21
22
21
22
TLE
p02900
C++
Time Limit Exceeded
#include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; using namespace std; ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b != 0) return gcd(b, a % b); else return b; } int main() { ll a, b; cin >> a >> b; ll G = gcd(a, b); ll ans = 0; ll g = gcd(a, b); for (int i = 2; i * i <= G; i++) { if (g % i == 0) { while (g % i == 0) g /= i; ans++; } } if (g != 1) ans++; cout << ans + 1 << endl; }
#include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; using namespace std; ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b != 0) return gcd(b, a % b); else return b; } int main() { ll a, b; cin >> a >> b; ll G = gcd(a, b); ll ans = 0; ll g = gcd(a, b); for (ll i = 2; i * i <= G; i++) { if (g % i == 0) { while (g % i == 0) g /= i; ans++; } } if (g != 1) ans++; cout << ans + 1 << endl; }
replace
21
22
21
22
TLE
p02900
C++
Time Limit Exceeded
// BROWNIE TK #include <bits/stdc++.h> typedef long long int lli; typedef unsigned long long int ulli; typedef long double ldb; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front() #define si size() #define be begin() #define en end() #define all(v) v.be, v.en #define le length() #define mp make_pair #define mt make_tuple #define F first #define S second #define forz(i, n) for (int i = 0; i < n; i++) #define forzm(i, m, n) for (int i = m; i < n; i++) #define rforz(i, n) for (int i = n - 1; i >= 0; i--) #define rforzm(i, m, n) for (int i = n - 1; i >= m; i--) #define deci(n) fixed << setprecision(n) #define high(n) __builtin_popcount(n) #define parity(n) __builtin_parity(n) #define ctz(n) __builtin_ctz(n) #define lb lower_bound #define ub upper_bound #define er equal_range #define maxe *max_element #define mine *min_element #define mod 1000000007 #define mod2 998244353 #define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define osetlli \ tree<lli, null_type, less<lli>, rb_tree_tag, \ tree_order_statistics_node_update> // member functions : // 1. order_of_key(k) : number of elements strictly lesser than k // 2. find_by_order(k) : k-th element in the set #define ofk order_of_key #define fbo find_by_order using namespace std; /*STD fucntions*/ lli power(lli x, lli y, lli p) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; // y must be even now y = y >> 1; // y=y/2 x = (x * x) % p; } return res; } lli gcd(lli a, lli b) { if (b == 0) return a; return gcd(b, a % b); } lli lcm(lli a, lli b) { return a * b / gcd(a, b); } lli modi(lli a, lli m) { // fermat little thm where m is prime return power(a, m - 2, m); } /*CODE BEGINS*/ int main() { kira; lli a, b; cin >> a >> b; lli g = __gcd(a, b); lli c = 1; if (g % 2 == 0) c++; while (g % 2 == 0) { g = g / 2; } for (int i = 3; i * i <= g; i += 2) { if (g % i == 0) c++; while (g % i == 0) { g = g / i; } } if (g > 2) { c++; } p1(c); return 0; }
// BROWNIE TK #include <bits/stdc++.h> typedef long long int lli; typedef unsigned long long int ulli; typedef long double ldb; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front() #define si size() #define be begin() #define en end() #define all(v) v.be, v.en #define le length() #define mp make_pair #define mt make_tuple #define F first #define S second #define forz(i, n) for (int i = 0; i < n; i++) #define forzm(i, m, n) for (int i = m; i < n; i++) #define rforz(i, n) for (int i = n - 1; i >= 0; i--) #define rforzm(i, m, n) for (int i = n - 1; i >= m; i--) #define deci(n) fixed << setprecision(n) #define high(n) __builtin_popcount(n) #define parity(n) __builtin_parity(n) #define ctz(n) __builtin_ctz(n) #define lb lower_bound #define ub upper_bound #define er equal_range #define maxe *max_element #define mine *min_element #define mod 1000000007 #define mod2 998244353 #define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define osetlli \ tree<lli, null_type, less<lli>, rb_tree_tag, \ tree_order_statistics_node_update> // member functions : // 1. order_of_key(k) : number of elements strictly lesser than k // 2. find_by_order(k) : k-th element in the set #define ofk order_of_key #define fbo find_by_order using namespace std; /*STD fucntions*/ lli power(lli x, lli y, lli p) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; // y must be even now y = y >> 1; // y=y/2 x = (x * x) % p; } return res; } lli gcd(lli a, lli b) { if (b == 0) return a; return gcd(b, a % b); } lli lcm(lli a, lli b) { return a * b / gcd(a, b); } lli modi(lli a, lli m) { // fermat little thm where m is prime return power(a, m - 2, m); } /*CODE BEGINS*/ int main() { kira; lli a, b; cin >> a >> b; lli g = __gcd(a, b); lli c = 1; if (g % 2 == 0) c++; while (g % 2 == 0) { g = g / 2; } for (int i = 3; i <= sqrt(g); i += 2) { if (g % i == 0) c++; while (g % i == 0) { g = g / i; } } if (g > 2) { c++; } p1(c); return 0; }
replace
98
99
98
99
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; if (a < b) swap(a, b); long long amari; long long waru = b; long long warareru = a; while (amari != 0) { amari = warareru % waru; if (amari == 0) break; warareru = waru; waru = amari; } long long gcd = waru; int ans = 0; for (int i = 2; i * i <= gcd; i++) { if (gcd % i == 0) { ans++; while (gcd % i == 0) gcd /= i; } } if (gcd != 1) ans++; ans++; cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; if (a < b) swap(a, b); long long amari; long long waru = b; long long warareru = a; while (amari != 0) { amari = warareru % waru; if (amari == 0) break; warareru = waru; waru = amari; } long long gcd = waru; int ans = 0; for (long long i = 2; i * i <= gcd; i++) { if (gcd % i == 0) { ans++; while (gcd % i == 0) gcd /= i; } } if (gcd != 1) ans++; ans++; cout << ans; }
replace
21
22
21
22
TLE
p02900
C++
Runtime Error
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <limits> #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector #define ll long long #define ALL(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define int_INF 2147483647 #define pint_INF 2000000000 #define ll_INF 9223372036854775807 #define MOD 100000007 #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define pii pair<int, int> #define vpii vector<pair<int, int>> using namespace std; bool is_prime[100000000 + 1]; // Up to 1e8 + 1 template <typename T> vector<T> Eratosthenes(const T N) { // return primes up to N vector<T> P; for (int i = 0; i <= N; i++) { is_prime[i] = true; } for (int i = 2; i <= N; i++) { if (is_prime[i]) { for (int j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); // if (P.size() >= N) break; } } return P; } template <typename T> T gcd(T a, T b) { if (a > b) { T c = a; a = b; b = c; } if (a == 0) { return b; } return gcd(b % a, a); } int main() { ll A, B; cin >> A >> B; vector<ll> Erast = Eratosthenes(static_cast<ll>(1000004)); // cout << *(Erast.end()-1) << endl; ll cnt = 1; for (int i = 0; Erast[i] <= min({A, B, static_cast<ll>(1000004)}); i++) { if (A % Erast[i] == 0 or B % Erast[i] == 0) { if (A % Erast[i] == 0 and B % Erast[i] == 0) cnt++; while (A % Erast[i] == 0) { A /= Erast[i]; } while (B % Erast[i] == 0) { B /= Erast[i]; } } } if (A == B and A > 1) { cnt++; } cout << cnt << endl; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cmath> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iostream> // cout, endl, cin #include <limits> #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector #define ll long long #define ALL(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define int_INF 2147483647 #define pint_INF 2000000000 #define ll_INF 9223372036854775807 #define MOD 100000007 #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define pii pair<int, int> #define vpii vector<pair<int, int>> using namespace std; bool is_prime[100000000 + 1]; // Up to 1e8 + 1 template <typename T> vector<T> Eratosthenes(const T N) { // return primes up to N vector<T> P; for (int i = 0; i <= N; i++) { is_prime[i] = true; } for (int i = 2; i <= N; i++) { if (is_prime[i]) { for (int j = 2 * i; j <= N; j += i) { is_prime[j] = false; } P.emplace_back(i); // if (P.size() >= N) break; } } return P; } template <typename T> T gcd(T a, T b) { if (a > b) { T c = a; a = b; b = c; } if (a == 0) { return b; } return gcd(b % a, a); } int main() { ll A, B; cin >> A >> B; vector<ll> Erast = Eratosthenes(static_cast<ll>(1000004)); // cout << *(Erast.end()-1) << endl; ll cnt = 1; for (int i = 0; i < Erast.size(); i++) { if (A % Erast[i] == 0 or B % Erast[i] == 0) { if (A % Erast[i] == 0 and B % Erast[i] == 0) cnt++; while (A % Erast[i] == 0) { A /= Erast[i]; } while (B % Erast[i] == 0) { B /= Erast[i]; } } } if (A == B and A > 1) { cnt++; } cout << cnt << endl; }
replace
73
74
73
74
127
/tmp/b86a0178-e588-453d-9ef9-6ad17b8a9660.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object
p02900
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long MOD = 1e9 + 7; const int INF = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll A, B; cin >> A >> B; ll g = gcd(A, B); vector<bool> prime(1e6 + 1, true); prime[0] = prime[1] = false; for (ll i = 2; i * i <= g; ++i) { for (ll j = i * i; j <= 1e6; j += i) { prime[j] = false; } } ll ans = 0; ll x = g; int i = 2; while (x > 1) { while (i * i <= g && !prime[i]) { ++i; } if (i * i > g) { ++ans; break; } if (x % i == 0) { ++ans; while (x % i == 0) x /= i; } ++i; } ++ans; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long MOD = 1e9 + 7; const int INF = 1e9 + 7; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll A, B; cin >> A >> B; ll g = gcd(A, B); vector<bool> prime(1e6 + 1, true); prime[0] = prime[1] = false; for (ll i = 2; i * i <= g; ++i) { for (ll j = i * i; j <= 1e6; j += i) { prime[j] = false; } } ll ans = 0; ll x = g; ll i = 2; while (x > 1) { while (i * i <= g && !prime[i]) { ++i; } if (i * i > g) { ++ans; break; } if (x % i == 0) { ++ans; while (x % i == 0) x /= i; } ++i; } ++ans; cout << ans << endl; }
replace
30
31
30
31
0
p02900
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; /* ----------------------------------------------------------------------------- 型とクラス定義 ----------------------------------------------------------------------------- */ typedef long long ll; /* ----------------------------------------------------------------------------- 大域データ ----------------------------------------------------------------------------- */ ll A, B, R, C; int main() { int cnt = 1; // 22つの正整数の読込み scanf("%d %d", &A, &B); while ((R = A % B) > 0) { A = B; B = R; } C = B; // 初期状態の満足度 for (int i = 2; i <= C && i <= 1000000; i++) { if (C % i == 0) { cnt++; while (C % i == 0) C /= i; } } cnt += (C > 1); printf("%d\n", cnt); return 0; }
#include <algorithm> #include <cstdio> using namespace std; /* ----------------------------------------------------------------------------- 型とクラス定義 ----------------------------------------------------------------------------- */ typedef long long ll; /* ----------------------------------------------------------------------------- 大域データ ----------------------------------------------------------------------------- */ ll A, B, R, C; int main() { int cnt = 1; // 22つの正整数の読込み scanf("%lld %lld", &A, &B); while ((R = A % B) > 0) { A = B; B = R; } C = B; // 初期状態の満足度 for (int i = 2; i <= C && i <= 1000000; i++) { if (C % i == 0) { cnt++; while (C % i == 0) C /= i; } } cnt += (C > 1); printf("%d\n", cnt); return 0; }
replace
20
21
20
21
0
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; int main(void) { ll a, b; cin >> a >> b; ll g = __gcd(a, b); ll ans = 1; for (int i = 2; i * i <= g; i++) { if (g % i == 0) { ans++; while (g % i == 0) g /= i; } } if (g != 1) ans++; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main(void) { ll a, b; cin >> a >> b; ll g = __gcd(a, b); ll ans = 1; for (ll i = 2; i * i <= g; i++) { if (g % i == 0) { ans++; while (g % i == 0) g /= i; } } if (g != 1) ans++; cout << ans << "\n"; return 0; }
replace
11
12
11
12
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++) #define setp(n) fixed << setprecision(n) #define lf double #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define pi pair<int, int> #define all(a) (a.begin()), (a.end()) #define rall(a) (a.rbegin()), (a.rend()) #define fi first #define se second #define pb push_back #define mp make_pair #define ins insert using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; ll g = __gcd(a, b); int ans = 0; for (int i = 2; i * i <= g; i++) { if (g % i == 0) { while (g % i == 0) g /= i; ans++; } } if (g != 1) ans++; cout << ans + 1 << "\n"; return 0; } // g = __gcd(a, b)としてgを素因数分解 // 素因数の種類数+1
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++) #define setp(n) fixed << setprecision(n) #define lf double #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define pi pair<int, int> #define all(a) (a.begin()), (a.end()) #define rall(a) (a.rbegin()), (a.rend()) #define fi first #define se second #define pb push_back #define mp make_pair #define ins insert using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll a, b; cin >> a >> b; ll g = __gcd(a, b); int ans = 0; for (ll i = 2; i * i <= g; i++) { if (g % i == 0) { while (g % i == 0) g /= i; ans++; } } if (g != 1) ans++; cout << ans + 1 << "\n"; return 0; } // g = __gcd(a, b)としてgを素因数分解 // 素因数の種類数+1
replace
32
33
32
33
TLE
p02900
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define lli long long int #define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower); using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 57; const int M = 1e6 + 500; const lli ths = 1LL << 40; void solve() { lli a, b; cin >> a >> b; lli x = __gcd(a, b); lli ans = 0; bool ok = 0; for (int i = 2; i * i <= x; i++) { ok = 0; while (x % i == 0) { x /= i; ok = 1; } ans += ok; } ans++; ans += (x > 1); cout << ans; return; } /* 7 6 7 4 1 2 11 6 5 1 2 10 4 5 */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); lli t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define lli long long int #define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower); using namespace std; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 57; const int M = 1e6 + 500; const lli ths = 1LL << 40; void solve() { lli a, b; cin >> a >> b; lli x = __gcd(a, b); lli ans = 0; bool ok = 0; for (lli i = 2; i * i <= x; i++) { ok = 0; while (x % i == 0) { x /= i; ok = 1; } ans += ok; } ans++; ans += (x > 1); cout << ans; return; } /* 7 6 7 4 1 2 11 6 5 1 2 10 4 5 */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); lli t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
38
39
38
39
TLE
p02900
C++
Runtime Error
// This code writed by chtholly_micromaker(MicroMaker) #include <bits/stdc++.h> #define reg register #define int long long using namespace std; template <class t> inline void rd(t &s) { s = 0; reg char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); return; } bool vis[1000000000]; inline bool isprime(int x) { if (x == 1) return false; reg int maxi = sqrt(x); for (int i = 2; i <= maxi; ++i) if (!(x % i)) return false; return true; } signed main(void) { int n, m; cin >> n >> m; int g = __gcd(n, m); reg int maxi = sqrt(g); reg int ans = 0; // cout<<g<<endl; for (int i = 1; i <= maxi; ++i) if (!(g % i)) { if (isprime(i)) ++ans; else vis[i] = true; if (i * i != g) { if (isprime(g / i)) ++ans; // else // vis[g/i]=true; } } for (int i = 2; i <= maxi; ++i) { if (vis[i] && i * i != g) ++ans; //,cout<<"passed "<<i<<endl; for (int j = 1; i * j <= g; ++j) vis[i * j] = false; } cout << ans + 1 << endl; return 0; }
// This code writed by chtholly_micromaker(MicroMaker) #include <bits/stdc++.h> #define reg register #define int long long using namespace std; template <class t> inline void rd(t &s) { s = 0; reg char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); return; } bool vis[1000000000]; inline bool isprime(int x) { if (x == 1) return false; reg int maxi = sqrt(x); for (int i = 2; i <= maxi; ++i) if (!(x % i)) return false; return true; } signed main(void) { int n, m; cin >> n >> m; int g = __gcd(n, m); reg int maxi = sqrt(g); reg int ans = 0; // cout<<g<<endl; for (int i = 1; i <= maxi; ++i) if (!(g % i)) { if (isprime(i)) ++ans; else vis[i] = true; if (i * i != g) { if (isprime(g / i)) ++ans; // else // vis[g/i]=true; } } for (int i = 2; i <= maxi; ++i) { if (vis[i] && i * i != g) ++ans; //,cout<<"passed "<<i<<endl; for (int j = 1; i * j <= maxi; ++j) vis[i * j] = false; } cout << ans + 1 << endl; return 0; }
replace
47
48
47
48
-11
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define LL long long LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } int main() { LL a, b, c; int ans = 1; scanf("%lld%lld", &a, &b); c = gcd(a, b); for (int i = 2; i * i <= c; i++) { if (c % i == 0) ans++; while (c % i == 0) c /= i; } printf("%d", ans + (c > 1)); return 0; }
#include <bits/stdc++.h> using namespace std; #define LL long long LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } int main() { LL a, b, c; int ans = 1; scanf("%lld%lld", &a, &b); c = gcd(a, b); for (LL i = 2; i * i <= c; i++) { if (c % i == 0) ans++; while (c % i == 0) c /= i; } printf("%d", ans + (c > 1)); return 0; }
replace
9
10
9
10
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = 1e9; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); ll ans = 1; for (int i = 2; i * i <= g; i++) { if (g % i == 0) { ans++; while (g % i == 0) { g /= i; } } } if (g != 1) ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = 1e9; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); ll ans = 1; for (ll i = 2; i * i <= g; i++) { if (g % i == 0) { ans++; while (g % i == 0) { g /= i; } } } if (g != 1) ans++; cout << ans << endl; }
replace
17
18
17
18
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(), x.end() #define pb(x) push_back(x) #define INF 1000000000000000000 #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define x first #define y second const int maxx = 1000006; const int maxlog = 20; const ll mod = 1000000007; int arr[maxx]; int main() { IOS ll a, b; cin >> a >> b; ll g = __gcd(a, b); vector<ll> v; for (int i = 2; i * i <= g; i++) { if (g % i == 0) { while (g % i == 0) g /= i; v.pb(i); } } if (g > 1) v.pb(g); ll count = 0; count = v.size(); cout << count + 1; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(), x.end() #define pb(x) push_back(x) #define INF 1000000000000000000 #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define x first #define y second const int maxx = 1000006; const int maxlog = 20; const ll mod = 1000000007; int arr[maxx]; int main() { IOS ll a, b; cin >> a >> b; ll g = __gcd(a, b); vector<ll> v; for (ll i = 2; i * i <= g; i++) { if (g % i == 0) { while (g % i == 0) g /= i; v.pb(i); } } if (g > 1) v.pb(g); ll count = 0; count = v.size(); cout << count + 1; }
replace
23
24
23
24
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll countPrimes(ll n) { map<ll, int> m; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { m[i]++; n /= i; } } if (n != 1) m[n]++; return (m.size()); } int main() { ll a, b; cin >> a >> b; ll g = __gcd(a, b); cout << countPrimes(g) + 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll countPrimes(ll n) { map<ll, int> m; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { m[i]++; n /= i; } } if (n != 1) m[n]++; return (m.size()); } int main() { ll a, b; cin >> a >> b; ll g = __gcd(a, b); cout << countPrimes(g) + 1 << endl; }
replace
6
7
6
7
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rg register #define rep(i, a, b) for (rg int i = a; i <= b; i++) #define per(i, a, b) for (rg int i = b; i >= a; i--) #define pb push_back #define lowbit(x) (x & (-x)) #define mk make_pair #define VI vector<int> #define pii pair<int, int> #define pLL pair<long long, long long> #define fi first #define se second #define il inline #define ll long long #define db double #define ld long double #define inf 0x3f3f3f3f #define getc() \ (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 15, stdin), p1 == p2) \ ? EOF \ : *p1++) char buf[1 << 15], *p1 = buf, *p2 = buf; inline ll read() { #define num ch - '0' char ch; bool flag = 0; ll res; while (!isdigit(ch = getc())) (ch == '-') && (flag = true); for (res = num; isdigit(ch = getc()); res = res * 10ll + num) ; (flag) && (res = -res); #undef num return res; } inline void write(ll x) { if (x < 0) x = ~x + 1ll, putchar('-'); if (x > 9) write(x / 10ll); putchar(x % 10ll + '0'); } #define mid ((l + r) >> 1) #define ls (x << 1) #define rs ((x << 1) | 1) #undef mid #undef ls #undef rs ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } void solve() { ll a = read(), b = read(); ll c = gcd(a, b); int tot = 1; for (int i = 2; i * i <= c; i++) { if (c % i == 0) { while (c % i == 0) c /= i; tot++; } } if (c > 1) tot++; cout << tot << endl; } int main() { #ifndef ONLINE_JUDGE freopen("data.txt", "r", stdin); #endif // int T = read(); // while(T--) solve(); }
#include <bits/stdc++.h> using namespace std; #define rg register #define rep(i, a, b) for (rg int i = a; i <= b; i++) #define per(i, a, b) for (rg int i = b; i >= a; i--) #define pb push_back #define lowbit(x) (x & (-x)) #define mk make_pair #define VI vector<int> #define pii pair<int, int> #define pLL pair<long long, long long> #define fi first #define se second #define il inline #define ll long long #define db double #define ld long double #define inf 0x3f3f3f3f #define getc() \ (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 15, stdin), p1 == p2) \ ? EOF \ : *p1++) char buf[1 << 15], *p1 = buf, *p2 = buf; inline ll read() { #define num ch - '0' char ch; bool flag = 0; ll res; while (!isdigit(ch = getc())) (ch == '-') && (flag = true); for (res = num; isdigit(ch = getc()); res = res * 10ll + num) ; (flag) && (res = -res); #undef num return res; } inline void write(ll x) { if (x < 0) x = ~x + 1ll, putchar('-'); if (x > 9) write(x / 10ll); putchar(x % 10ll + '0'); } #define mid ((l + r) >> 1) #define ls (x << 1) #define rs ((x << 1) | 1) #undef mid #undef ls #undef rs ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } void solve() { ll a = read(), b = read(); ll c = gcd(a, b); int tot = 1; for (ll i = 2; i * i <= c; i++) { if (c % i == 0) { while (c % i == 0) c /= i; tot++; } } if (c > 1) tot++; cout << tot << endl; } int main() { #ifndef ONLINE_JUDGE freopen("data.txt", "r", stdin); #endif // int T = read(); // while(T--) solve(); }
replace
54
55
54
55
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() 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; } typedef long long ll; const long long INF = 1LL << 60; typedef pair<int, int> P; map<ll, ll> prime_factor(ll N) { map<ll, ll> prime; for (int i = 2; i * i <= N; i++) { while (N % i == 0) { prime[i]++; N /= i; } } if (N != 1) prime[N] = 1; return prime; } int main() { ll A, B; cin >> A >> B; map<ll, ll> mpA = prime_factor(A); map<ll, ll> mpB = prime_factor(B); int ans = 1; for (auto itr : mpA) { if (mpB.count(itr.first)) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() 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; } typedef long long ll; const long long INF = 1LL << 60; typedef pair<int, int> P; map<ll, ll> prime_factor(ll N) { map<ll, ll> prime; for (ll i = 2; i * i <= N; i++) { while (N % i == 0) { prime[i]++; N /= i; } } if (N != 1) prime[N] = 1; return prime; } int main() { ll A, B; cin >> A >> B; map<ll, ll> mpA = prime_factor(A); map<ll, ll> mpB = prime_factor(B); int ans = 1; for (auto itr : mpA) { if (mpB.count(itr.first)) ans++; } cout << ans << endl; return 0; }
replace
25
26
25
26
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define hell 1000000007 #define endl "\n" #define io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define MAX_SIZE 1000000 int32_t main() { io int a, b; cin >> a >> b; int gcd = __gcd(a, b); int gcd1 = gcd; int count = 1; for (int i = 2; i <= gcd1; i++) { if (gcd % i == 0) { while (gcd % i == 0) gcd /= i; count++; } } (gcd > 1) ? cout << count + 1 : cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define hell 1000000007 #define endl "\n" #define io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define MAX_SIZE 1000000 int32_t main() { io int a, b; cin >> a >> b; int gcd = __gcd(a, b); int gcd1 = gcd; int count = 1; for (int i = 2; i <= MAX_SIZE; i++) { if (gcd % i == 0) { while (gcd % i == 0) gcd /= i; count++; } } (gcd > 1) ? cout << count + 1 : cout << count; return 0; }
replace
21
22
21
22
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; else return gcd(b, a % b); } int main() { long long a, b, g, buf; set<long long> cd; cin >> a >> b; g = gcd(a, b); buf = g; for (int i = 2; i * i <= g; i++) { if (buf % i == 0) { cd.insert(i); while (buf % i == 0) buf /= i; } } if (buf != 1) cd.insert(buf); cd.insert(1); cout << cd.size() << endl; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; else return gcd(b, a % b); } int main() { long long a, b, g, buf; set<long long> cd; cin >> a >> b; g = gcd(a, b); buf = g; for (long long i = 2; i * i <= g; i++) { if (buf % i == 0) { cd.insert(i); while (buf % i == 0) buf /= i; } } if (buf != 1) cd.insert(buf); cd.insert(1); cout << cd.size() << endl; }
replace
19
20
19
20
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long gcd(long x, long y) { long r; if (x < y) swap(x, y); while (y > 0) { r = x % y; x = y; y = r; } return x; } long CntPrime(long x) { long cnt = 0; if (x < 2) { // cout << "CntPrimt(1)" << x << endl; return 0; } else if (x == 2) return 1; else if (x % 2 == 0) { long y = 0; while (y == 0 && x != 1) { y = x % 2; x = x / 2; } if (y != 0) x = 2 * x + y; // cout << "CntPrimt(2)" << x << endl; cnt++; cnt += CntPrime(x); return cnt; } else { for (long i = 3; i <= x; i += 2) { if (x % i == 0) { long y = 0; while (y == 0 && x != 1) { y = x % i; x = x / i; } if (y != 0) x = x * i + y; // cout << "CntPrimt(" << i << ")" << x << endl; cnt++; cnt += CntPrime(x); return cnt; } } } // return cnt; } int main() { long A, B; cin >> A >> B; long num = gcd(A, B); // cout << num << endl; long cnt = CntPrime(num); cout << cnt + 1; return 0; }
#include <bits/stdc++.h> using namespace std; long gcd(long x, long y) { long r; if (x < y) swap(x, y); while (y > 0) { r = x % y; x = y; y = r; } return x; } long CntPrime(long x) { long cnt = 0; if (x < 2) { // cout << "CntPrimt(1)" << x << endl; return 0; } else if (x == 2) return 1; else if (x % 2 == 0) { long y = 0; while (y == 0 && x != 1) { y = x % 2; x = x / 2; } if (y != 0) x = 2 * x + y; // cout << "CntPrimt(2)" << x << endl; cnt++; cnt += CntPrime(x); return cnt; } else { for (long i = 3; i <= x; i += 2) { if (x % i == 0) { long y = 0; while (y == 0 && x != 1) { y = x % i; x = x / i; } if (y != 0) x = x * i + y; // cout << "CntPrimt(" << i << ")" << x << endl; cnt++; cnt += CntPrime(x); return cnt; } else if (i * i > x) { return 1; } } } // return cnt; } int main() { long A, B; cin >> A >> B; long num = gcd(A, B); // cout << num << endl; long cnt = CntPrime(num); cout << cnt + 1; return 0; }
insert
49
49
49
51
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long f(long long a, long long b) { return !b ? a : f(b, a % b); } bool isPrime(long long i) { for (long long ii = 2; ii * ii <= i; ii++) { if (i % ii == 0) return 0; } return 1; } int main() { long long a, b, cnt = 0; scanf("%lld%lld", &a, &b); long long c = a > b ? f(a, b) : f(b, a); if (c == 1) { printf("1"); return 0; } for (long long i = 1; i * i <= c; i++) { if (isPrime(i) && c % i == 0) ++cnt; if (isPrime(c / i) && c % i == 0 && c / i != i) ++cnt; } printf("%lld", cnt); return 0; }
#include <bits/stdc++.h> using namespace std; long long f(long long a, long long b) { return !b ? a : f(b, a % b); } bool isPrime(long long i) { for (long long ii = 2; ii * ii <= i; ii++) { if (i % ii == 0) return 0; } return 1; } int main() { long long a, b, cnt = 0; scanf("%lld%lld", &a, &b); long long c = a > b ? f(a, b) : f(b, a); if (c == 1) { printf("1"); return 0; } for (long long i = 1; i * i <= c; i++) { if (c % i == 0) { if (isPrime(i)) cnt++; if (isPrime(c / i) && i != c / i) cnt++; } } printf("%lld", cnt); return 0; }
replace
23
27
23
29
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll a, b; cin >> a >> b; ll cnt = 0, g = __gcd(a, b); for (int i = 2; i * i <= g; i++) { if (g % i != 0) continue; cnt++; while (g % i == 0) g /= i; } if (g != 1) cnt++; cout << cnt + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll a, b; cin >> a >> b; ll cnt = 0, g = __gcd(a, b); for (ll i = 2; i * i <= g; i++) { if (g % i != 0) continue; cnt++; while (g % i == 0) g /= i; } if (g != 1) cnt++; cout << cnt + 1 << endl; return 0; }
replace
7
8
7
8
TLE
p02900
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; #define MOD (long long int)(1e9 + 7) #define ll long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = n - 1; i >= 0; i--) #define REPS(i, n) for (int i = n; i > 0; i--) #define FOR(i, a, b) for (int i = a; i < (int)(b); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort(ALL(x)) #define CLR(a) memset((a), 0, sizeof(a)) #define PB push_back #define MP make_pair #define SP << " " << const int INF = 1001001001; const ll LINF = 100100100100100100; const double EPS = 1e-10; const double PI = acos(-1.0); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } __attribute__((constructor)) void initial() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } bool IsPrime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (ll i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } signed main() { ll a, b; cin >> a >> b; ll ans = 1; priority_queue<ll> x, y; reps(i, pow(a, 0.5)) { if (a % i != 0) continue; if (IsPrime(i)) x.push(i); if (i == a / i) continue; if (IsPrime(a / i)) x.push(a / i); } reps(i, pow(b, 0.5)) { if (b % i != 0) continue; if (IsPrime(i)) y.push(i); if (i == b / i) continue; if (IsPrime(b / i)) y.push(b / i); } while ((!x.empty()) || (!y.empty())) { ll s = x.top(), t = y.top(); if (s == t) { x.pop(); y.pop(); ans++; // cerr << s << endl; } else if (s > t) { x.pop(); } else { y.pop(); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; #define MOD (long long int)(1e9 + 7) #define ll long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = n - 1; i >= 0; i--) #define REPS(i, n) for (int i = n; i > 0; i--) #define FOR(i, a, b) for (int i = a; i < (int)(b); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort(ALL(x)) #define CLR(a) memset((a), 0, sizeof(a)) #define PB push_back #define MP make_pair #define SP << " " << const int INF = 1001001001; const ll LINF = 100100100100100100; const double EPS = 1e-10; const double PI = acos(-1.0); typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } __attribute__((constructor)) void initial() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } bool IsPrime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (ll i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } signed main() { ll a, b; cin >> a >> b; ll ans = 1; priority_queue<ll> x, y; reps(i, pow(a, 0.5)) { if (a % i != 0) continue; if (IsPrime(i)) x.push(i); if (i == a / i) continue; if (IsPrime(a / i)) x.push(a / i); } reps(i, pow(b, 0.5)) { if (b % i != 0) continue; if (IsPrime(i)) y.push(i); if (i == b / i) continue; if (IsPrime(b / i)) y.push(b / i); } while ((!x.empty()) && (!y.empty())) { ll s = x.top(), t = y.top(); if (s == t) { x.pop(); y.pop(); ans++; // cerr << s << endl; } else if (s > t) { x.pop(); } else { y.pop(); } } cout << ans << endl; return 0; }
replace
95
96
95
96
0
p02900
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define eps 1e-9 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<ll, ll> LLP; const int MAXN = 2e5 + 10; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; const int LOGN = 20; int arr[MAXN]; int ans[MAXN]; bool isprime(ll tmp) { for (ll i = 2; i * i <= tmp; ++i) { if (tmp % i == 0) return false; } return tmp != 1; } signed main() { ll a, b; scanf("%lld%lld", &a, &b); ll gcd = __gcd(a, b); int cnt = 0; if (isprime(gcd)) { puts("2"); return 0; } for (ll i = 2; gcd != 1; ++i) { if (gcd % i == 0) { cnt++; while (gcd % i == 0) gcd /= i; } } printf("%d\n", cnt + 1); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define eps 1e-9 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<ll, ll> LLP; const int MAXN = 2e5 + 10; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; const int LOGN = 20; int arr[MAXN]; int ans[MAXN]; bool isprime(ll tmp) { for (ll i = 2; i * i <= tmp; ++i) { if (tmp % i == 0) return false; } return tmp != 1; } signed main() { ll a, b; scanf("%lld%lld", &a, &b); ll gcd = __gcd(a, b); int cnt = 0; if (isprime(gcd)) { puts("2"); return 0; } for (ll i = 2; gcd != 1; ++i) { if (gcd % i == 0) { cnt++; while (gcd % i == 0) gcd /= i; if (isprime(gcd)) { cnt++; break; } } } printf("%d\n", cnt + 1); return 0; }
insert
46
46
46
50
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif // LOCAL using ll = long long; ll a, b, x; int main() { scanf("%lld %lld", &a, &b); x = __gcd(a, b); int ans = 1; for (int i = 2; i * i <= x; i++) { if (x % i == 0) { ans++; while (x % i == 0) x /= i; } if (x == 1) break; } if (x > 1) ++ans; printf("%d\n", ans); } /* Good Luck -Lucina */
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif // LOCAL using ll = long long; ll a, b, x; int main() { scanf("%lld %lld", &a, &b); x = __gcd(a, b); int ans = 1; for (ll i = 2; i * i <= x; i++) { if (x % i == 0) { ans++; while (x % i == 0) x /= i; } if (x == 1) break; } if (x > 1) ++ans; printf("%d\n", ans); } /* Good Luck -Lucina */
replace
15
16
15
16
TLE
p02900
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> #define ll long long #define itn int #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FFOR(i, 1, n) #define SORT(V) sort((V).begin(), (V).end()) #define REVERSE(V) reverse((V).begin(), (V).end()) #define INF ((1LL << 62) - (1LL << 31)) #define MOD 1000000007 using namespace std; ll N, M, K, A, B, C, ans = 0, cnt = 0; string S, T; vector<int> P, Q; vector<pair<int, int>> PP; bool CAN = false, CAN2 = true; ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int main() { cin >> A >> B; N = gcd(A, B); if (N == 1) { cout << 1 << endl; return 0; } for (ll i = 2; i <= N; ++i) { while (N % i == 0) { N /= i; CAN = true; } if (CAN) { ans++; CAN = false; CAN2 = false; } if ((i * i >= N && CAN2 == true) || N == 1) break; } if (CAN2) { cout << 2 << endl; // Nが素数 return 0; } cout << ans + 1 << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> #define ll long long #define itn int #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FFOR(i, 1, n) #define SORT(V) sort((V).begin(), (V).end()) #define REVERSE(V) reverse((V).begin(), (V).end()) #define INF ((1LL << 62) - (1LL << 31)) #define MOD 1000000007 using namespace std; ll N, M, K, A, B, C, ans = 0, cnt = 0; string S, T; vector<int> P, Q; vector<pair<int, int>> PP; bool CAN = false, CAN2 = true; ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int main() { cin >> A >> B; N = gcd(A, B); if (N == 1) { cout << 1 << endl; return 0; } for (ll i = 2; i <= N; ++i) { while (N % i == 0) { N /= i; CAN = true; } if (CAN) { ans++; CAN = false; CAN2 = false; } if (i * i > N) { if (N != 1) ans++; break; } if (N == 1) break; } if (CAN2) { cout << 2 << endl; // Nが素数 return 0; } cout << ans + 1 << endl; }
replace
53
54
53
59
TLE
p02900
C++
Time Limit Exceeded
// // Disjoint Set of Common Divisors.cpp // National Olympiad in Informatics in Provinces // // Created by 黄子齐 on 2019/9/28. // Copyright © 2019 黄子齐. All rights reserved. // #include <stdio.h> #define ll long long ll a, b; ll gcd(ll x, ll y) { if (!y) return x; return gcd(y, x % y); } int main() { // freopen("mytestdata.in", "r", stdin); scanf("%lld%lld", &a, &b); // printf("%lld\n", gcd(a, b)); ll x = gcd(a, b); ll sum = 0; for (int i = 2; i * i <= x; i++) { if (!(x % i)) { sum++; while (!(x % i)) { x /= i; } } } if (x > 1) { sum++; } printf("%lld\n", sum + 1); return 0; }
// // Disjoint Set of Common Divisors.cpp // National Olympiad in Informatics in Provinces // // Created by 黄子齐 on 2019/9/28. // Copyright © 2019 黄子齐. All rights reserved. // #include <stdio.h> #define ll long long ll a, b; ll gcd(ll x, ll y) { if (!y) return x; return gcd(y, x % y); } int main() { // freopen("mytestdata.in", "r", stdin); scanf("%lld%lld", &a, &b); // printf("%lld\n", gcd(a, b)); ll x = gcd(a, b); ll sum = 0; for (ll i = 2; i * i <= x; i++) { if (!(x % i)) { sum++; while (!(x % i)) { x /= i; } } } if (x > 1) { sum++; } printf("%lld\n", sum + 1); return 0; }
replace
22
23
22
23
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } map<ll, ll> prime_factor(ll N) { map<ll, ll> res; // res[2] = 4は、素因数2が4個あることを表す for (int i = 2; i * i <= N; i++) { // 小さい素因数から順に割っていく while (N % i == 0) { // i = 2が素因数だとすると、割り切れる限り2で割る res[i]++; // 割り切れる回数をres[i]に格納 N /= i; } } if (N != 1) res[N] = 1; // ループ処理の結果、nが素数の場合、res[n] = 1とする。 return res; } /* */ int main() { ll A, B; cin >> A >> B; ll g = gcd(A, B); map<ll, ll> ma = prime_factor(g); // gの素因数とその個数を収納 ll count = 0; // Keyの値が小さい順にループ /*for (auto p : ma) { auto key = p.first; auto value = p.second; // key, valueを使う if(value >= 1) count++;//素因数の個数が1以上のものをカウント }*/ cout << ma.size() + 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } map<ll, ll> prime_factor(ll N) { map<ll, ll> res; // res[2] = 4は、素因数2が4個あることを表す for (ll i = 2; i * i <= N; i++) { // 小さい素因数から順に割っていく while (N % i == 0) { // i = 2が素因数だとすると、割り切れる限り2で割る res[i]++; // 割り切れる回数をres[i]に格納 N /= i; } } if (N != 1) res[N] = 1; // ループ処理の結果、nが素数の場合、res[n] = 1とする。 return res; } /* */ int main() { ll A, B; cin >> A >> B; ll g = gcd(A, B); map<ll, ll> ma = prime_factor(g); // gの素因数とその個数を収納 ll count = 0; // Keyの値が小さい順にループ /*for (auto p : ma) { auto key = p.first; auto value = p.second; // key, valueを使う if(value >= 1) count++;//素因数の個数が1以上のものをカウント }*/ cout << ma.size() + 1 << endl; }
replace
13
14
13
14
TLE
p02900
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // MACROS #define ll long long #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vld vector<ld> #define u_s unordered_set #define pii pair<int, int> #define pll pair<ll, ll> #define FOR(i, n) for (ll(i) = 0; i < n; i++) #define FORN(i, a, b) for (ll(i) = a; i < b; i++) #define FORE(i, l) for (auto(i) : l) #define pb push_back #define pob pop_back #define emp emplace #define fi first #define se second #define all(n) (n).begin(), (n).end() #define in(n) cin >> (n); #define debug(n) cout << #n << ": " << n << '\n'; // FUNCTIONS template <typename T> inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; } template <typename T> inline T ext_gcd(T a, T b, T &x, T &y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout << setprecision(15); ll a, b; cin >> a >> b; ll c = gcd(a, b); vll sieve(c + 1); set<ll> list; while (c > 0) { ll prev_c = c; for (ll i = 2; i * i <= c; i++) { if (c % i == 0) { list.emp(i); c /= i; break; } } if (c == prev_c) break; } if (c > 0) list.emp(c); list.emp(1); cout << list.size() << '\n'; }
#include <bits/stdc++.h> using namespace std; // MACROS #define ll long long #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vld vector<ld> #define u_s unordered_set #define pii pair<int, int> #define pll pair<ll, ll> #define FOR(i, n) for (ll(i) = 0; i < n; i++) #define FORN(i, a, b) for (ll(i) = a; i < b; i++) #define FORE(i, l) for (auto(i) : l) #define pb push_back #define pob pop_back #define emp emplace #define fi first #define se second #define all(n) (n).begin(), (n).end() #define in(n) cin >> (n); #define debug(n) cout << #n << ": " << n << '\n'; // FUNCTIONS template <typename T> inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; } template <typename T> inline T ext_gcd(T a, T b, T &x, T &y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout << setprecision(15); ll a, b; cin >> a >> b; ll c = gcd(a, b); set<ll> list; while (c > 0) { ll prev_c = c; for (ll i = 2; i * i <= c; i++) { if (c % i == 0) { list.emp(i); c /= i; break; } } if (c == prev_c) break; } if (c > 0) list.emp(c); list.emp(1); cout << list.size() << '\n'; }
delete
60
61
60
60
0
p02900
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; map<long long, int> factorize(long long n) { map<long long, int> m; for (long long x = 2; x <= n; ++x) { while (n % x == 0) { ++m[x]; n /= x; } } if (n != 1) { ++m[n]; } return m; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long A, B; cin >> A >> B; auto d = gcd(A, B); auto ans = factorize(d).size() + 1; cout << ans << endl; }
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; map<long long, int> factorize(long long n) { map<long long, int> m; for (long long x = 2; x * x <= n; ++x) { while (n % x == 0) { ++m[x]; n /= x; } } if (n != 1) { ++m[n]; } return m; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long A, B; cin >> A >> B; auto d = gcd(A, B); auto ans = factorize(d).size() + 1; cout << ans << endl; }
replace
9
10
9
10
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, g; cin >> a >> b; g = __gcd(a, b); set<int> s; if (g % 2 == 0) { s.insert(2); while (g % 2 == 0) g /= 2; } for (int i = 3; i * i <= g; i += 2) if (g % i == 0) { s.insert(i); while (g % i == 0) g /= i; } if (g > 2) s.insert(g); cout << s.size() + 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, g; cin >> a >> b; g = __gcd(a, b); set<int> s; if (g % 2 == 0) { s.insert(2); while (g % 2 == 0) g /= 2; } for (long long i = 3; i * i <= g; i += 2) if (g % i == 0) { s.insert(i); while (g % i == 0) g /= i; } if (g > 2) s.insert(g); cout << s.size() + 1 << endl; }
replace
12
13
12
13
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll a, b; cin >> a >> b; ll ab = gcd(a, b); int ans = 1; for (int i = 2; i * i <= ab; ++i) { if (ab % i == 0) { ++ans; while (ab % i == 0) { ab /= i; } } } if (ab > 1) ++ans; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll a, b; cin >> a >> b; ll ab = gcd(a, b); int ans = 1; for (ll i = 2; i * i <= ab; ++i) { if (ab % i == 0) { ++ans; while (ab % i == 0) { ab /= i; } } } if (ab > 1) ++ans; cout << ans << endl; }
replace
11
12
11
12
TLE
p02900
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <stdlib.h> #include <string> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> P; int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int main() { ll a, b; cin >> a >> b; ll c = gcd(a, b); ll cnt = 1; for (ll i = 2; i * i < c + 1; i++) { if (c % i == 0) { cnt++; while (c % i == 0) { c = c / i; } } } if (c != 1) { cnt++; } cout << cnt << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <stdlib.h> #include <string> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> P; ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int main() { ll a, b; cin >> a >> b; ll c = gcd(a, b); ll cnt = 1; for (ll i = 2; i * i < c + 1; i++) { if (c % i == 0) { cnt++; while (c % i == 0) { c = c / i; } } } if (c != 1) { cnt++; } cout << cnt << endl; }
replace
15
16
15
16
0
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) typedef long long ll; int main() { ll a, b; cin >> a >> b; ll g = __gcd(a, b); ll ans = 1; for (int i = 2; i * i <= g; ++i) { if (g % i == 0) { while (g % i == 0) { g /= i; } ans++; } } if (g != 1) ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) typedef long long ll; int main() { ll a, b; cin >> a >> b; ll g = __gcd(a, b); ll ans = 1; for (ll i = 2; i * i <= g; ++i) { if (g % i == 0) { while (g % i == 0) { g /= i; } ans++; } } if (g != 1) ans++; cout << ans << endl; return 0; }
replace
11
12
11
12
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #define fi first #define sc second #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int main() { ll a, b, ans = 1; scanf("%lld %lld", &a, &b); ll fpb = __gcd(a, b); ll temp = fpb; for (int i = 2; i * i <= fpb and temp > 1; i++) { if (temp % i == 0) ans++; while (temp % i == 0) temp /= i; } if (temp > 1) ans++; printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #define fi first #define sc second #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int main() { ll a, b, ans = 1; scanf("%lld %lld", &a, &b); ll fpb = __gcd(a, b); ll temp = fpb; for (ll i = 2; i * i <= fpb and temp > 1; i++) { if (temp % i == 0) ans++; while (temp % i == 0) temp /= i; } if (temp > 1) ans++; printf("%lld\n", ans); }
replace
26
27
26
27
TLE
p02900
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int divisorList[1000001] = {0}; // WA おそらく1000000を超える素数が答えにあるが出力していない int main(void) { unsigned long long A, B; cin >> A >> B; vector<int> divisor; vector<unsigned long long> AHighDiv, BHighDiv; for (int i = 1; i <= 1000000; i++) { if ((A % i == 0) && (B % i == 0)) divisor.push_back(i); if (A % i == 0) { if ((A / i) > 1000000) AHighDiv.push_back(A / i); } if (B % i == 0) { if ((B / i) > 1000000) BHighDiv.push_back(B / i); } } // 素数リストを作る for (int i = 2; i <= 1000000; i++) { if (divisorList[i] == 0) { for (int j = i * 2; j <= 1000000; j += i) { divisorList[j]++; } } } int ans = 0; for (unsigned int i = 0; i < divisor.size(); i++) { if (divisorList[divisor[i]] == 0) ans++; } if ((AHighDiv.size() > 0) && (BHighDiv.size() > 0)) { sort(AHighDiv.begin(), AHighDiv.end()); sort(BHighDiv.begin(), BHighDiv.end()); int Apos = 0, Bpos = 0; while (Apos < AHighDiv.size() && Bpos < BHighDiv.size()) { if (AHighDiv[Apos] == BHighDiv[Bpos]) { // 素数か確認する bool primeNumber = true; for (unsigned int i = 2; i < 1000000; i++) { if (divisorList[i] == 0) { if ((AHighDiv[Apos] % divisorList[i]) == 0) { primeNumber = false; break; } } } if (primeNumber) ans++; Apos++, Bpos++; } else if (AHighDiv[Apos] > BHighDiv[Bpos]) { Bpos++; } else if (AHighDiv[Apos] < BHighDiv[Bpos]) { Apos++; } } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int divisorList[1000001] = {0}; // WA おそらく1000000を超える素数が答えにあるが出力していない int main(void) { unsigned long long A, B; cin >> A >> B; vector<int> divisor; vector<unsigned long long> AHighDiv, BHighDiv; for (int i = 1; i <= 1000000; i++) { if ((A % i == 0) && (B % i == 0)) divisor.push_back(i); if (A % i == 0) { if ((A / i) > 1000000) AHighDiv.push_back(A / i); } if (B % i == 0) { if ((B / i) > 1000000) BHighDiv.push_back(B / i); } } // 素数リストを作る for (int i = 2; i <= 1000000; i++) { if (divisorList[i] == 0) { for (int j = i * 2; j <= 1000000; j += i) { divisorList[j]++; } } } int ans = 0; for (unsigned int i = 0; i < divisor.size(); i++) { if (divisorList[divisor[i]] == 0) ans++; } if ((AHighDiv.size() > 0) && (BHighDiv.size() > 0)) { sort(AHighDiv.begin(), AHighDiv.end()); sort(BHighDiv.begin(), BHighDiv.end()); int Apos = 0, Bpos = 0; while (Apos < AHighDiv.size() && Bpos < BHighDiv.size()) { if (AHighDiv[Apos] == BHighDiv[Bpos]) { // 素数か確認する bool primeNumber = true; for (unsigned int i = 2; i < 1000000; i++) { if (divisorList[i] == 0) { if ((AHighDiv[Apos] % i) == 0) { primeNumber = false; break; } } } if (primeNumber) ans++; Apos++, Bpos++; } else if (AHighDiv[Apos] > BHighDiv[Bpos]) { Bpos++; } else if (AHighDiv[Apos] < BHighDiv[Bpos]) { Apos++; } } } cout << ans << endl; return 0; }
replace
50
51
50
51
0
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; #define REP(i, n) for (ll i = 0; i < n; i++) // #define DEBUG(fmt, ...) #define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) bool is_prime(ll n) { if (n == 1) { return false; } ll i = 2; // This will loop from 2 to int(sqrt(x)) while (i * i <= n) { // Check if i divides x without leaving a remainder if (n % i == 0) { // This means that n has a factor in between 2 and sqrt(n) // So it is not a prime number return false; } i += 1; } // If we did not find any factor in the above loop, // then n is a prime number return true; } int main() { std::cout << std::fixed << std::setprecision(10); ll A, B; cin >> A >> B; ll m = min(A, B); ll count = 0; set<ll> primes; for (int i = 1; i * i <= m; i++) { if (m % i == 0) { if (i == 1 || is_prime(i)) { primes.insert(i); } if (is_prime(m / i)) { primes.insert(m / i); } } } ll x = max(A, B); for (auto p : primes) { if (x % p == 0) { count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; #define REP(i, n) for (ll i = 0; i < n; i++) // #define DEBUG(fmt, ...) #define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) bool is_prime(ll n) { if (n == 1) { return false; } ll i = 2; // This will loop from 2 to int(sqrt(x)) while (i * i <= n) { // Check if i divides x without leaving a remainder if (n % i == 0) { // This means that n has a factor in between 2 and sqrt(n) // So it is not a prime number return false; } i += 1; } // If we did not find any factor in the above loop, // then n is a prime number return true; } int main() { std::cout << std::fixed << std::setprecision(10); ll A, B; cin >> A >> B; ll m = min(A, B); ll count = 0; set<ll> primes; for (ll i = 1; i * i <= m; i++) { if (m % i == 0) { if (i == 1 || is_prime(i)) { primes.insert(i); } if (is_prime(m / i)) { primes.insert(m / i); } } } ll x = max(A, B); for (auto p : primes) { if (x % p == 0) { count++; } } cout << count << endl; }
replace
44
45
44
45
TLE
p02900
C++
Time Limit Exceeded
#include <iostream> #include <set> template <typename T> T gcd(T a, T b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main() { int64_t a, b; std::cin >> a >> b; int64_t g = gcd(a, b); std::set<int64_t> primes; primes.insert(1); for (int i = 2; i * i <= g; i++) { while (g % i == 0) { primes.insert(i); g /= i; } } if (g > 1) { primes.insert(g); } std::cout << primes.size() << std::endl; return 0; }
#include <iostream> #include <set> template <typename T> T gcd(T a, T b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main() { int64_t a, b; std::cin >> a >> b; int64_t g = gcd(a, b); std::set<int64_t> primes; primes.insert(1); for (int64_t i = 2; i * i <= g; i++) { while (g % i == 0) { primes.insert(i); g /= i; } } if (g > 1) { primes.insert(g); } std::cout << primes.size() << std::endl; return 0; }
replace
19
20
19
20
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; int ans = 1; for (long long i = 2; i <= a; i++) if (a % i == 0) { if (b % i == 0) { ans++; } while (a % i == 0) { a /= i; } } ans += (a > 1 && b % a == 0); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; int ans = 1; for (long long i = 2; i * i <= a; i++) if (a % i == 0) { if (b % i == 0) { ans++; } while (a % i == 0) { a /= i; } } ans += (a > 1 && b % a == 0); cout << ans << endl; }
replace
9
10
9
10
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; using ll = long long; typedef pair<int, int> Pair; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } vector<pair<ll, ll>> f(ll n) { vector<pair<ll, ll>> res; for (int i = 2; i * i <= n; ++i) { if (n % i != 0) continue; ll cnt = 0; while (n % i == 0) cnt++, n /= i; res.emplace_back(i, cnt); } if (n > 1) res.emplace_back(n, 1); return res; } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); auto s = f(g); cout << s.size() + 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; using ll = long long; typedef pair<int, int> Pair; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } vector<pair<ll, ll>> f(ll n) { vector<pair<ll, ll>> res; for (ll i = 2; i * i <= n; ++i) { if (n % i != 0) continue; ll cnt = 0; while (n % i == 0) cnt++, n /= i; res.emplace_back(i, cnt); } if (n > 1) res.emplace_back(n, 1); return res; } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); auto s = f(g); cout << s.size() + 1 << endl; return 0; }
replace
14
15
14
15
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); } vector<pair<ll, int>> factorize(ll n) { vector<pair<ll, int>> v; for (int i = 2; i * i <= n; i++) { if (n % i) continue; v.emplace_back(i, 0); while (n % i == 0) { v.back().second++; n /= i; } } if (n != 1) { v.emplace_back(n, 1); } return v; } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); auto f = factorize(g); cout << f.size() + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); } vector<pair<ll, int>> factorize(ll n) { vector<pair<ll, int>> v; for (ll i = 2; i * i <= n; i++) { if (n % i) continue; v.emplace_back(i, 0); while (n % i == 0) { v.back().second++; n /= i; } } if (n != 1) { v.emplace_back(n, 1); } return v; } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); auto f = factorize(g); cout << f.size() + 1 << endl; return 0; }
replace
9
10
9
10
TLE
p02900
C++
Memory Limit Exceeded
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; // 最小公倍数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } // for(int i = ; i < ; i++){} ll lmax(ll s, ll t) { if (s > t) { return s; } else { return t; } } ll lmin(ll s, ll t) { if (s < t) { return s; } else { return t; } } // ここから開始 int main() { ll a, b; cin >> a >> b; if (a > b) { ll tmp = a; a = b; b = tmp; } // 素因数分解 vector<ll> v; vector<bool> prime_count(10000000000, false); v.push_back(1); ll n = a; for (ll i = 2; i < sqrt(n) + 2; i++) { if (a % i != 0) { continue; } else { while (a % i == 0) { if (!prime_count[i]) { prime_count[i] = true; v.push_back(i); a /= i; } else { a /= i; } } } if (a == 1) break; } if (a > 1) v.push_back(a); // for(int i = 0; i<v.size(); i++) cout<<v[i]<<endl; ll cnt = 0; for (int i = 0; i < v.size(); i++) { if (b % v[i] == 0) { cnt++; } } // debug cout << cnt << endl; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; // 最小公倍数 ll gcd(ll x, ll y) { ll tmp = 0; if (x < y) { tmp = x; x = y; y = tmp; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } // 最大公倍数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } // 階乗 ll kaijo(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; sum %= 1000000000 + 7; } return sum; } // for(int i = ; i < ; i++){} ll lmax(ll s, ll t) { if (s > t) { return s; } else { return t; } } ll lmin(ll s, ll t) { if (s < t) { return s; } else { return t; } } // ここから開始 int main() { ll a, b; cin >> a >> b; if (a > b) { ll tmp = a; a = b; b = tmp; } // 素因数分解 vector<ll> v; vector<bool> prime_count(100000000, false); v.push_back(1); ll n = a; for (ll i = 2; i < sqrt(n) + 2; i++) { if (a % i != 0) { continue; } else { while (a % i == 0) { if (!prime_count[i]) { prime_count[i] = true; v.push_back(i); a /= i; } else { a /= i; } } } if (a == 1) break; } if (a > 1) v.push_back(a); // for(int i = 0; i<v.size(); i++) cout<<v[i]<<endl; ll cnt = 0; for (int i = 0; i < v.size(); i++) { if (b % v[i] == 0) { cnt++; } } // debug cout << cnt << endl; return 0; }
replace
81
82
81
82
MLE
p02900
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define MOD 1000000007 #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ll long long #define ull unsigned long long #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; const long long INF = 1LL << 60; typedef vector<ll> Array; typedef vector<Array> Matrix; 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; } // グラフ関連 struct Edge { // グラフ ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { // 最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1)); // 最大フロー・最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } ll max_flow(Graph &G, ll s, ll t) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } // 最短経路(負閉路検出) void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } // 最短経路(負の辺が含まれているとだめ) void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } // 最短経路問題(01bfs:0,1の辺のみ,O(|E|)) void bfs01(Graph &G, ll s, Array &d) { d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; deque<ll> deq; deq.push_front(s); while (deq.size() > 0) { ll v = deq.front(); // cout << v << endl; deq.pop_front(); for (auto e : G[v]) { if (d[v] + e.cap < d[e.to]) { d[e.to] = d[v] + e.cap; if (e.cap == 0) { deq.push_front(e.to); } else { deq.push_back(e.to); } } } } } // 最短経路(負の辺を含んでいてもOK) void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = INF; } } REP(i, G.size()) { REP(j, G[i].size()) { d[i][G[i][j].to] = G[i][j].cap; } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, vector<int> &order) { // トポロジカルソートO(E+V) // 閉路検出にも使える int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; lca() {} lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; class UnionFind { vector<int> data; int num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; num--; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } int numSet() { return num; } }; template <class Abel> struct PotentialUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; PotentialUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; class SumSegTree { private: int _sum(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { int s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 int s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return s1 + s2; } } public: int n, height; vector<int> dat; // 初期化(_nは最大要素数) SumSegTree(int _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<int>(2 * n - 1, 0); } // 場所i(0-indexed)にxを足す void add(int i, int x) { i += n - 1; // i番目の葉ノードへ dat[i] += x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] += x; } } // 区間[a,b)の総和。ノードk=[l,r)に着目している。 int sum(int a, int b) { return _sum(a, b, 0, 0, n); } }; class RmqTree { private: ll _find(ll a, ll b, ll k, ll l, ll r) { // 区間[l,r)の最小値を持つk番目のノードを探索 if (r <= a || b <= l) return INF; // 交差しない if (a <= l && r <= b) return dat[k]; // 完全に含む else { ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return min(s1, s2); } } public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) RmqTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, INF); } // i番目の値(0-indexed)をxに変更 void update(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] = x; while (i > 0) { // 登りながら更新 i = (i - 1) / 2; // 親ノードのインデックス dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); // 子ノードの小さい方の値を代入 } } // 区間[a,b)の最小値の取得 ll find(ll a, ll b) { return _find(a, b, 0, 0, n); } }; // nCr,nPr,modの逆元 class Combination { public: Array fact; // n! Array inv; // n!の逆元 ll mod; Combination(ll n, ll _mod) { mod = _mod; fact.resize(n + 1); fact[0] = 1; REP(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n + 1); REP(i, n + 1) { inv[i] = mod_inv(fact[i]); } } // modの逆元 ll mod_inv(ll x) { ll n = mod - 2; ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { // 重複組み合わせ:n種類のものからr個取り出す組み合わせ return nCr(r + n - 1, r); } }; // 約数 void divisor(ll n, vector<ll> &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); } // 素因数分解 void factoring(ll i, map<ll, ll> &mp) { ll x = i; // cout << x << endl; for (int j = 2; j <= i; j++) { while (x % j == 0 && x > 1) { mp[j]++; x /= j; // cout << x << " " << j << endl; } if (x == 1) break; } } // 最大公約数 ll gcd(ll m, ll n) { if (n == 0) return m; return gcd(n, m % n); } // gcd // 最小公倍数 ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } // 繰り返し自乗法 ll pow2(ll x, ll n, ll mod) { // x^n 計算量O(logn) ll ans = 1ll; while (n > 0) { if ((n & 1) == 1) { ans = ans * x % mod; } x = x * x % mod; // 一周する度にx, x^2, x^4, x^8となる n >>= 1; // 桁をずらす n = n >> 1 } return ans; } vector<ll> lis_fast(const vector<ll> &a) { // 最長部分増加列 const ll n = a.size(); vector<ll> A(n, INT_MAX); vector<ll> id(n); for (int i = 0; i < n; ++i) { // id[i] = distance(A.begin(), upper_bound(A.begin(), A.end(), // a[i]));//非減少 id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i])); A[id[i]] = a[i]; } ll m = *max_element(id.begin(), id.end()); vector<ll> b(m + 1); for (int i = n - 1; i >= 0; --i) if (id[i] == m) b[m--] = a[i]; return b; } // memo // output : fixed << setprecision(n) <<小数点以下n桁出力 // setfill('0') << setw(12) <<num 0埋めで12文字出力 // func // lower_bound(all(a),x):vector aでx以上の要素のイテレータを返す // upper_bound(all(a,x)):vector aでxより大きい要素のイテレータを返す // setやmapの場合は専用関数あり // 調和関数はlogn! n/1+n/2+n/3+... int main() { ios::sync_with_stdio(false); cin.tie(0); ll a, b; cin >> a >> b; map<ll, ll> mp; ll c = gcd(a, b); factoring(c, mp); cout << mp.size() + 1 << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define MOD 1000000007 #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ll long long #define ull unsigned long long #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; const long long INF = 1LL << 60; typedef vector<ll> Array; typedef vector<Array> Matrix; 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; } // グラフ関連 struct Edge { // グラフ ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { // 最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1)); // 最大フロー・最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } ll max_flow(Graph &G, ll s, ll t) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } // 最短経路(負閉路検出) void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } // 最短経路(負の辺が含まれているとだめ) void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } // 最短経路問題(01bfs:0,1の辺のみ,O(|E|)) void bfs01(Graph &G, ll s, Array &d) { d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; deque<ll> deq; deq.push_front(s); while (deq.size() > 0) { ll v = deq.front(); // cout << v << endl; deq.pop_front(); for (auto e : G[v]) { if (d[v] + e.cap < d[e.to]) { d[e.to] = d[v] + e.cap; if (e.cap == 0) { deq.push_front(e.to); } else { deq.push_back(e.to); } } } } } // 最短経路(負の辺を含んでいてもOK) void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = INF; } } REP(i, G.size()) { REP(j, G[i].size()) { d[i][G[i][j].to] = G[i][j].cap; } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, vector<int> &order) { // トポロジカルソートO(E+V) // 閉路検出にも使える int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; lca() {} lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; class UnionFind { vector<int> data; int num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; num--; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } int numSet() { return num; } }; template <class Abel> struct PotentialUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; PotentialUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; class SumSegTree { private: int _sum(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; // 交差しない if (a <= l && r <= b) return dat[k]; // a,l,r,bの順で完全に含まれる else { int s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 int s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return s1 + s2; } } public: int n, height; vector<int> dat; // 初期化(_nは最大要素数) SumSegTree(int _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<int>(2 * n - 1, 0); } // 場所i(0-indexed)にxを足す void add(int i, int x) { i += n - 1; // i番目の葉ノードへ dat[i] += x; while (i > 0) { // 下から上がっていく i = (i - 1) / 2; dat[i] += x; } } // 区間[a,b)の総和。ノードk=[l,r)に着目している。 int sum(int a, int b) { return _sum(a, b, 0, 0, n); } }; class RmqTree { private: ll _find(ll a, ll b, ll k, ll l, ll r) { // 区間[l,r)の最小値を持つk番目のノードを探索 if (r <= a || b <= l) return INF; // 交差しない if (a <= l && r <= b) return dat[k]; // 完全に含む else { ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return min(s1, s2); } } public: ll n, height; vector<ll> dat; // 初期化(_nは最大要素数) RmqTree(ll _n) { n = 1; height = 1; while (n < _n) { n *= 2; height++; } dat = vector<ll>(2 * n - 1, INF); } // i番目の値(0-indexed)をxに変更 void update(ll i, ll x) { i += n - 1; // i番目の葉ノードへ dat[i] = x; while (i > 0) { // 登りながら更新 i = (i - 1) / 2; // 親ノードのインデックス dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]); // 子ノードの小さい方の値を代入 } } // 区間[a,b)の最小値の取得 ll find(ll a, ll b) { return _find(a, b, 0, 0, n); } }; // nCr,nPr,modの逆元 class Combination { public: Array fact; // n! Array inv; // n!の逆元 ll mod; Combination(ll n, ll _mod) { mod = _mod; fact.resize(n + 1); fact[0] = 1; REP(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } inv.resize(n + 1); REP(i, n + 1) { inv[i] = mod_inv(fact[i]); } } // modの逆元 ll mod_inv(ll x) { ll n = mod - 2; ll res = 1LL; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; } ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; } ll nHr(ll n, ll r) { // 重複組み合わせ:n種類のものからr個取り出す組み合わせ return nCr(r + n - 1, r); } }; // 約数 void divisor(ll n, vector<ll> &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); } // 素因数分解 void factoring(ll n, map<ll, ll> &mp) { for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { mp[i]++; n /= i; } } if (n != 1) mp[n]++; } // 最大公約数 ll gcd(ll m, ll n) { if (n == 0) return m; return gcd(n, m % n); } // gcd // 最小公倍数 ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } // 繰り返し自乗法 ll pow2(ll x, ll n, ll mod) { // x^n 計算量O(logn) ll ans = 1ll; while (n > 0) { if ((n & 1) == 1) { ans = ans * x % mod; } x = x * x % mod; // 一周する度にx, x^2, x^4, x^8となる n >>= 1; // 桁をずらす n = n >> 1 } return ans; } vector<ll> lis_fast(const vector<ll> &a) { // 最長部分増加列 const ll n = a.size(); vector<ll> A(n, INT_MAX); vector<ll> id(n); for (int i = 0; i < n; ++i) { // id[i] = distance(A.begin(), upper_bound(A.begin(), A.end(), // a[i]));//非減少 id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i])); A[id[i]] = a[i]; } ll m = *max_element(id.begin(), id.end()); vector<ll> b(m + 1); for (int i = n - 1; i >= 0; --i) if (id[i] == m) b[m--] = a[i]; return b; } // memo // output : fixed << setprecision(n) <<小数点以下n桁出力 // setfill('0') << setw(12) <<num 0埋めで12文字出力 // func // lower_bound(all(a),x):vector aでx以上の要素のイテレータを返す // upper_bound(all(a,x)):vector aでxより大きい要素のイテレータを返す // setやmapの場合は専用関数あり // 調和関数はlogn! n/1+n/2+n/3+... int main() { ios::sync_with_stdio(false); cin.tie(0); ll a, b; cin >> a >> b; map<ll, ll> mp; ll c = gcd(a, b); factoring(c, mp); cout << mp.size() + 1 << endl; return 0; }
replace
473
485
473
482
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define dbg(x) cout << #x << ":" << x << endl typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> PP; ll gcd(ll a, ll b) { while (b != 0) { a %= b; swap(a, b); } return a; } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); int cnt = 1; for (int i = 2; i * i <= g; i++) { if (g % i) continue; while (g % i == 0) g /= i; cnt++; } if (g != 1) cnt++; cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define dbg(x) cout << #x << ":" << x << endl typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> PP; ll gcd(ll a, ll b) { while (b != 0) { a %= b; swap(a, b); } return a; } int main() { ll a, b; cin >> a >> b; ll g = gcd(a, b); int cnt = 1; for (ll i = 2; i * i <= g; i++) { if (g % i) continue; while (g % i == 0) g /= i; cnt++; } if (g != 1) cnt++; cout << cnt << endl; }
replace
25
26
25
26
TLE
p02900
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define all(x) x.begin(), x.end() #define fi first #define se second #define pb push_back #define umax(x, y) x = max(x, (y)) #define umin(x, y) x = min(x, (y)) #define For(i, a) for (int i = 1; i <= a; i++) #define ort (b + s) / 2 #define y2 asrwjaelkf #define y1 asseopirwjaelkf #define set multiset using namespace std; typedef long long Lint; typedef double db; typedef pair<int, int> ii; typedef pair<int, char> ic; typedef pair<db, db> dd; typedef pair<ii, int> iii; typedef pair<ii, ii> i4; const int maxn = 100020; const int maxm = 1000020; const int MOd = 998244353; Lint a, b; Lint gcd(Lint a, Lint b) { if (b == 0) return a; return gcd(b, a % b); } void solve() { scanf("%lld %lld", &a, &b); Lint x = gcd(a, b); Lint cnt = 1; for (int i = 2; i * i <= x; i++) if (x % i == 0) { while (x % i == 0) x /= i; cnt++; } if (x != 1) cnt++; cout << cnt << endl; } int main() { // freopen("asd.in","r",stdin); // freopen("output17.txt","w",stdout); int n = 1; // scanf("%d",&n); while (n--) solve(); return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define all(x) x.begin(), x.end() #define fi first #define se second #define pb push_back #define umax(x, y) x = max(x, (y)) #define umin(x, y) x = min(x, (y)) #define For(i, a) for (int i = 1; i <= a; i++) #define ort (b + s) / 2 #define y2 asrwjaelkf #define y1 asseopirwjaelkf #define set multiset using namespace std; typedef long long Lint; typedef double db; typedef pair<int, int> ii; typedef pair<int, char> ic; typedef pair<db, db> dd; typedef pair<ii, int> iii; typedef pair<ii, ii> i4; const int maxn = 100020; const int maxm = 1000020; const int MOd = 998244353; Lint a, b; Lint gcd(Lint a, Lint b) { if (b == 0) return a; return gcd(b, a % b); } void solve() { scanf("%lld %lld", &a, &b); Lint x = gcd(a, b); Lint cnt = 1; for (Lint i = 2; i * i <= x; i++) if (x % i == 0) { while (x % i == 0) x /= i; cnt++; } if (x != 1) cnt++; cout << cnt << endl; } int main() { // freopen("asd.in","r",stdin); // freopen("output17.txt","w",stdout); int n = 1; // scanf("%d",&n); while (n--) solve(); return 0; }
replace
52
53
52
53
TLE
p02900
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define mi map<int, int> #define mii map<pii, int> #define all(a) (a).begin(), (a).end() #define x first #define y second #define sz(x) (int)x.size() #define endl '\n' #define hell 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) using namespace std; int a, b, cnt; void solve() { cin >> a >> b; a = __gcd(a, b); for (int i = 2; i * i <= a; i++) { if (a % i == 0) { cnt++; while (a % i == 0) a /= i; } } if (a > 1) cnt++; cout << cnt + 1 << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define int long long #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define mi map<int, int> #define mii map<pii, int> #define all(a) (a).begin(), (a).end() #define x first #define y second #define sz(x) (int)x.size() #define endl '\n' #define hell 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) using namespace std; int a, b, cnt; void solve() { cin >> a >> b; a = __gcd(a, b); for (int i = 2; i * i <= a; i++) { if (a % i == 0) { cnt++; while (a % i == 0) a /= i; } } if (a > 1) cnt++; cout << cnt + 1 << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
2
3
2
3
TLE
p02901
C++
Runtime Error
/* while(!cin.eof()) */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod (int)(1e9 + 7) #define MAXI (int)(1e15 + 100) #define N 1000050 int n, m; vector<int> vec; int dp[(1 << 12) + 1][1005][2]; int cost[1005]; int fun(int mask, int ind, int stage) { if (ind > m - 1) { if (mask == (1 << n) - 1) return 0; return MAXI; } int ans = dp[mask][ind][stage]; if (ans != -1) return ans; ans = MAXI; int x = vec[ind] | mask; if (x > mask) ans = min(ans, cost[ind] + fun(x, ind + 1, 1)); ans = min(ans, fun(mask, ind + 1, 0)); return dp[mask][ind][stage] = ans; } // Driver code to test above functions int32_t main() { #ifndef ONLINE_JUDGE // for getting input from inpu.txt freopen("input.txt", "r", stdin); // for writing output to output.txt // freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> cost[i]; int sz; cin >> sz; int mask = 0; for (int j = 0; j < sz; j++) { int temp; cin >> temp; temp--; mask |= (1 << temp); } vec.push_back(mask); } memset(dp, -1, sizeof dp); int x = fun(0, 0, 0); if (x == MAXI) cout << -1; else cout << x; return 0; }
/* while(!cin.eof()) */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod (int)(1e9 + 7) #define MAXI (int)(1e15 + 100) #define N 1000050 int n, m; vector<int> vec; int dp[(1 << 12) + 1][1005][2]; int cost[1005]; int fun(int mask, int ind, int stage) { if (ind > m - 1) { if (mask == (1 << n) - 1) return 0; return MAXI; } int ans = dp[mask][ind][stage]; if (ans != -1) return ans; ans = MAXI; int x = vec[ind] | mask; if (x > mask) ans = min(ans, cost[ind] + fun(x, ind + 1, 1)); ans = min(ans, fun(mask, ind + 1, 0)); return dp[mask][ind][stage] = ans; } // Driver code to test above functions int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> cost[i]; int sz; cin >> sz; int mask = 0; for (int j = 0; j < sz; j++) { int temp; cin >> temp; temp--; mask |= (1 << temp); } vec.push_back(mask); } memset(dp, -1, sizeof dp); int x = fun(0, 0, 0); if (x == MAXI) cout << -1; else cout << x; return 0; }
delete
37
44
37
37
0
p02901
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long typedef int ll; typedef long double ld; const ll N = 1005; char en = '\n'; ll inf = 1e16; ll mod = 1e9 + 7; ll power(ll x, ll n, ll mod) { ll res = 1; x %= mod; while (n) { if (n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } ll n, m; ll mask1[N]; ll cost[N]; ll dp[N][1 << 12]; ll recur(ll pos, ll mask) { if (mask == ((1 << n) - 1)) return 0; if (pos == m + 1) { return inf; } ll &ans = dp[pos][mask]; ans = min(recur(pos + 1, mask), cost[pos] + recur(pos + 1, mask | mask1[pos])); return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (ll i = 1; i <= m; i++) { cin >> cost[i]; mask1[i] = 0; ll b; cin >> b; while (b--) { ll x; cin >> x; x--; mask1[i] |= (1 << x); } } memset(dp, -1, sizeof(dp)); ll res = recur(1, 0); if (res > 1e12) cout << -1 << en; else cout << recur(1, 0) << en; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef int ll; typedef long double ld; const ll N = 1005; char en = '\n'; ll inf = 1e16; ll mod = 1e9 + 7; ll power(ll x, ll n, ll mod) { ll res = 1; x %= mod; while (n) { if (n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } ll n, m; ll mask1[N]; ll cost[N]; ll dp[N][1 << 12]; ll recur(ll pos, ll mask) { if (mask == ((1 << n) - 1)) return 0; if (pos == m + 1) { return inf; } ll &ans = dp[pos][mask]; if (ans != -1) return ans; ans = min(recur(pos + 1, mask), cost[pos] + recur(pos + 1, mask | mask1[pos])); return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (ll i = 1; i <= m; i++) { cin >> cost[i]; mask1[i] = 0; ll b; cin >> b; while (b--) { ll x; cin >> x; x--; mask1[i] |= (1 << x); } } memset(dp, -1, sizeof(dp)); ll res = recur(1, 0); if (res > 1e12) cout << -1 << en; else cout << recur(1, 0) << en; return 0; }
replace
34
35
34
36
TLE
p02901
C++
Runtime Error
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author parsa bahrami */ #pragma GCC optimize("O2") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; typedef pair<string, string> pss; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sz(x) (ll) x.size() #define jjoin(x) \ for (auto i : x) \ cout << i << endl; #define all(x) (x).begin(), (x).end() #define F first #define S second #define Mp make_pair #define sep ' ' #define error(x) cerr << #x << " = " << x << endl #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define set_random \ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define kill(x) return cout << x << endl, 0; #define Hkill(x) \ cout << x << endl; \ exit(0); #define endl '\n' ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } const ll MAXN = 2e5 + 10; const ll MAXA = 101; const ll INF = 8e18; const ll MOD = 998244353; // 1e9 + 7 const ld PI = 4 * atan((ld)1); const ll LOG = 15; ll cost[MAXA], SUB[MAXA][MAXA], dp[1LL << LOG], T[MAXA]; int main() { fast_io; set_random; ll n, m; cin >> n >> m; for (ll i = 0; i < m; i++) { ll b, mask = 0; cin >> cost[i] >> b; for (ll j = 0; j < b; j++) { cin >> SUB[i][j]; mask |= (1LL << (SUB[i][j] - 1)); } T[i] = mask; } fill(dp, dp + (1LL << LOG), INF); dp[0] = 0; for (ll i = 0; i < m; i++) { for (ll mask = 0; mask < (1LL << n); mask++) { dp[mask | T[i]] = min(dp[mask | T[i]], dp[mask] + cost[i]); } } cout << (dp[(1LL << n) - 1] == INF ? -1 : dp[(1LL << n) - 1]) << endl; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author parsa bahrami */ #pragma GCC optimize("O2") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; typedef pair<string, string> pss; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sz(x) (ll) x.size() #define jjoin(x) \ for (auto i : x) \ cout << i << endl; #define all(x) (x).begin(), (x).end() #define F first #define S second #define Mp make_pair #define sep ' ' #define error(x) cerr << #x << " = " << x << endl #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define set_random \ mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define kill(x) return cout << x << endl, 0; #define Hkill(x) \ cout << x << endl; \ exit(0); #define endl '\n' ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } const ll MAXN = 2e5 + 10; const ll MAXA = 1010; const ll INF = 8e18; const ll MOD = 998244353; // 1e9 + 7 const ld PI = 4 * atan((ld)1); const ll LOG = 15; ll cost[MAXA], SUB[MAXA][MAXA], dp[1LL << LOG], T[MAXA]; int main() { fast_io; set_random; ll n, m; cin >> n >> m; for (ll i = 0; i < m; i++) { ll b, mask = 0; cin >> cost[i] >> b; for (ll j = 0; j < b; j++) { cin >> SUB[i][j]; mask |= (1LL << (SUB[i][j] - 1)); } T[i] = mask; } fill(dp, dp + (1LL << LOG), INF); dp[0] = 0; for (ll i = 0; i < m; i++) { for (ll mask = 0; mask < (1LL << n); mask++) { dp[mask | T[i]] = min(dp[mask | T[i]], dp[mask] + cost[i]); } } cout << (dp[(1LL << n) - 1] == INF ? -1 : dp[(1LL << n) - 1]) << endl; return 0; }
replace
54
55
54
55
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define inf 9000000000000 #define mx 1003 int n, m; int a[mx], b[mx], c[mx]; ll dp[15][1 << 15]; ll solve(int i, int mask) { if (i == m) { if (mask == (1 << n) - 1) return 0; return inf; } if (mask == (1 << n) - 1) return 0; auto &ans = dp[i][mask]; if (ans != -1) return ans; ans = inf; int nask = mask | c[i]; ans = a[i] + solve(i + 1, nask); ans = min(ans, solve(i + 1, mask)); return ans; } int main() { cin >> n >> m; int mark = 0; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; int mask = 0; for (int j = 0; j < b[i]; j++) { int x; cin >> x; x--; mask |= (1 << x); } c[i] = mask; mark |= mask; } if (mark != (1 << n) - 1) { cout << -1 << endl; return 0; } memset(dp, -1, sizeof dp); auto ans = solve(0, 0); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define inf 9000000000000 #define mx 1003 int n, m; int a[mx], b[mx], c[mx]; ll dp[mx][1 << 15]; ll solve(int i, int mask) { if (i == m) { if (mask == (1 << n) - 1) return 0; return inf; } if (mask == (1 << n) - 1) return 0; auto &ans = dp[i][mask]; if (ans != -1) return ans; ans = inf; int nask = mask | c[i]; ans = a[i] + solve(i + 1, nask); ans = min(ans, solve(i + 1, mask)); return ans; } int main() { cin >> n >> m; int mark = 0; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; int mask = 0; for (int j = 0; j < b[i]; j++) { int x; cin >> x; x--; mask |= (1 << x); } c[i] = mask; mark |= mask; } if (mark != (1 << n) - 1) { cout << -1 << endl; return 0; } memset(dp, -1, sizeof dp); auto ans = solve(0, 0); cout << ans << endl; }
replace
10
11
10
11
0
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int di[] = {0, 0, 1, -1}; constexpr int dj[] = {1, -1, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, a[1123], b[1123], c[1123][15]; cin >> n >> m; REP(i, m) { cin >> a[i] >> b[i]; REP(j, b[i]) cin >> c[i][j]; } int dp[110][(1 << 12) + 10]; memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < (1 << n); j++) { if (dp[i][j] == -1) continue; if (dp[i + 1][j] > dp[i][j] || dp[i + 1][j] == -1) dp[i + 1][j] = dp[i][j]; int val = dp[i][j] + a[i]; int nj = j; for (int k = 0; k < b[i]; k++) nj |= (1 << (c[i][k] - 1)); if (dp[i + 1][nj] > val || dp[i + 1][nj] == -1) dp[i + 1][nj] = val; } } cout << dp[m][(1 << n) - 1] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int di[] = {0, 0, 1, -1}; constexpr int dj[] = {1, -1, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, a[1123], b[1123], c[1123][15]; cin >> n >> m; REP(i, m) { cin >> a[i] >> b[i]; REP(j, b[i]) cin >> c[i][j]; } int dp[1010][(1 << 12) + 10]; memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < (1 << n); j++) { if (dp[i][j] == -1) continue; if (dp[i + 1][j] > dp[i][j] || dp[i + 1][j] == -1) dp[i + 1][j] = dp[i][j]; int val = dp[i][j] + a[i]; int nj = j; for (int k = 0; k < b[i]; k++) nj |= (1 << (c[i][k] - 1)); if (dp[i + 1][nj] > val || dp[i + 1][nj] == -1) dp[i + 1][nj] = val; } } cout << dp[m][(1 << n) - 1] << endl; return 0; }
replace
46
47
46
47
0
p02901
C++
Time Limit Exceeded
#define DEBUG 1 #include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; #define all(v) (v).begin(), (v).end() #define for1(i, n) for (ll i = 0; i < (n); i++) #define for2(i, m, n) for (ll i = (m); i < (n); i++) #define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d)) #define rfor2(i, m, n) for (ll i = (m); i > (n); i--) #define rfor3(i, m, n, d) for (ll i = (m); i > (n); i += (d)) #define INF 1111111111111111111LL #define MOD 1000000007LL // 10**9 + 7 #define print(...) print_1(__VA_ARGS__) #define in(...) in_1(__VA_ARGS__) #if DEBUG #define dump(...) dump_1(#__VA_ARGS__, __VA_ARGS__) #else #define dump(...) #endif template <typename Head> void dump_1(const char *str, Head &&h) { cerr << str << ": " << h << '\n'; } template <typename Head, typename... Tail> void dump_1(const char *str, Head &&h, Tail &&...t) { while (*str != ',') { cerr << *str++; } cerr << ": " << h << ' '; dump_1(str + 1, t...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &v) { os << '(' << v.first << ", " << v.second << ')'; return os; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v) { os << '(' << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto 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) { for (auto it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { os << ' '; } os << *it; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { os << ' '; } os << *it; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { os << '{'; for (auto it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { os << ", "; } os << it->first << ':' << it->second; } os << '}'; return os; } void Yes(void) { cout << "Yes" << '\n'; } void No(void) { cout << "No" << '\n'; } void YES(void) { cout << "YES" << '\n'; } void NO(void) { cout << "NO" << '\n'; } template <typename T> void chmax(T &a, const T &b) { if (a < b) { a = b; } } template <typename T> void chmin(T &a, const T &b) { if (a > b) { a = b; } } template <typename T> void vin(vector<T> &v, ll len) { for1(i, len) { cin >> v[i]; } } template <typename Head> void in_1(Head &h) { cin >> h; } template <typename Head, typename... Tail> void in_1(Head &h, Tail &...t) { cin >> h; in_1(t...); } template <typename Head> void print_1(Head &&h) { cout << h << '\n'; } template <typename Head, typename... Tail> void print_1(Head &&h, Tail &&...t) { cout << h << ' '; print_1(t...); } //--------------------------------------------------------- void solve() { ll N, M; in(N, M); vll price(M); vll door(M); for1(i, M) { ll a, b; in(a, b); price[i] = a; door[i] = 0; for1(j, b) { ll c; in(c); --c; door[i] |= (1LL << c); } } // dump(price); // dump(door); // dp[2][a] 扉a(bit)を開けるための最小の費用 map<ll, ll> dp[2]; ll i1 = 1; ll i2 = 0; dp[i2][0] = 0; for1(i, N) { i1 ^= 1; i2 ^= 1; dp[i2] = dp[i1]; for (auto pa : dp[i1]) { // dump(pa); for1(m, M) { ll d2 = pa.first | door[m]; if (dp[i2].find(d2) == dp[i2].end()) { dp[i2][d2] = pa.second + price[m]; } else { chmin(dp[i2][d2], pa.second + price[m]); } } } } ll ans = dp[i2][(1LL << N) - 1]; if (ans == 0) { print(-1); } else { print(ans); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); solve(); }
#define DEBUG 1 #include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; #define all(v) (v).begin(), (v).end() #define for1(i, n) for (ll i = 0; i < (n); i++) #define for2(i, m, n) for (ll i = (m); i < (n); i++) #define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d)) #define rfor2(i, m, n) for (ll i = (m); i > (n); i--) #define rfor3(i, m, n, d) for (ll i = (m); i > (n); i += (d)) #define INF 1111111111111111111LL #define MOD 1000000007LL // 10**9 + 7 #define print(...) print_1(__VA_ARGS__) #define in(...) in_1(__VA_ARGS__) #if DEBUG #define dump(...) dump_1(#__VA_ARGS__, __VA_ARGS__) #else #define dump(...) #endif template <typename Head> void dump_1(const char *str, Head &&h) { cerr << str << ": " << h << '\n'; } template <typename Head, typename... Tail> void dump_1(const char *str, Head &&h, Tail &&...t) { while (*str != ',') { cerr << *str++; } cerr << ": " << h << ' '; dump_1(str + 1, t...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &v) { os << '(' << v.first << ", " << v.second << ')'; return os; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v) { os << '(' << get<0>(v) << ", " << get<1>(v) << ", " << get<2>(v) << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto 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) { for (auto it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { os << ' '; } os << *it; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { os << ' '; } os << *it; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { os << '{'; for (auto it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { os << ", "; } os << it->first << ':' << it->second; } os << '}'; return os; } void Yes(void) { cout << "Yes" << '\n'; } void No(void) { cout << "No" << '\n'; } void YES(void) { cout << "YES" << '\n'; } void NO(void) { cout << "NO" << '\n'; } template <typename T> void chmax(T &a, const T &b) { if (a < b) { a = b; } } template <typename T> void chmin(T &a, const T &b) { if (a > b) { a = b; } } template <typename T> void vin(vector<T> &v, ll len) { for1(i, len) { cin >> v[i]; } } template <typename Head> void in_1(Head &h) { cin >> h; } template <typename Head, typename... Tail> void in_1(Head &h, Tail &...t) { cin >> h; in_1(t...); } template <typename Head> void print_1(Head &&h) { cout << h << '\n'; } template <typename Head, typename... Tail> void print_1(Head &&h, Tail &&...t) { cout << h << ' '; print_1(t...); } //--------------------------------------------------------- void solve() { ll N, M; in(N, M); vll price(M); vll door(M); for1(i, M) { ll a, b; in(a, b); price[i] = a; door[i] = 0; for1(j, b) { ll c; in(c); --c; door[i] |= (1LL << c); } } // dump(price); // dump(door); // dp[2][a] 扉a(bit)を開けるための最小の費用 map<ll, ll> dp[2]; ll i1 = 1; ll i2 = 0; dp[i2][0] = 0; for1(i, N) { i1 ^= 1; i2 ^= 1; dp[i2] = dp[i1]; ll key = 1LL << i; for1(m, M) { if (door[m] & key) { for (auto pa : dp[i1]) { ll d2 = pa.first | door[m]; if (dp[i2].find(d2) == dp[i2].end()) { dp[i2][d2] = pa.second + price[m]; } else { chmin(dp[i2][d2], pa.second + price[m]); } } } } } ll ans = dp[i2][(1LL << N) - 1]; if (ans == 0) { print(-1); } else { print(ans); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(16); cerr << fixed << setprecision(16); solve(); }
replace
153
161
153
163
TLE
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, x, n) for (int i = x; i < n; i++) typedef long long ll; const int INF = 1e9 + 7; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(m); vector<int> b(m); vector<vector<int>> c; rep(i, 0, m) { cin >> a[i] >> b[i]; vector<int> tmp(b[i]); rep(j, 0, b[i]) cin >> tmp[j]; c.push_back(tmp); } vector<vector<int>> dp(1000, vector<int>(5000, INF)); dp[0][0] = 0; for (int i = 0; i < m; i++) { int open_id = 0; for (int j = 0; j < b[i]; j++) open_id |= (1 << (c[i][j] - 1)); dp[i + 1] = dp[i]; for (int j = 0; j < (1 << n); j++) { dp[i + 1][j | open_id] = min({dp[i + 1][j | open_id], dp[i][j | open_id], dp[i][j] + a[i]}); // dp[i][0]は常にゼロ } } if (dp[m][(1 << n) - 1] == INF) cout << -1 << endl; else cout << dp[m][(1 << n) - 1] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, x, n) for (int i = x; i < n; i++) typedef long long ll; const int INF = 1e9 + 7; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(m); vector<int> b(m); vector<vector<int>> c; rep(i, 0, m) { cin >> a[i] >> b[i]; vector<int> tmp(b[i]); rep(j, 0, b[i]) cin >> tmp[j]; c.push_back(tmp); } vector<vector<int>> dp(2000, vector<int>(5000, INF)); dp[0][0] = 0; for (int i = 0; i < m; i++) { int open_id = 0; for (int j = 0; j < b[i]; j++) open_id |= (1 << (c[i][j] - 1)); dp[i + 1] = dp[i]; for (int j = 0; j < (1 << n); j++) { dp[i + 1][j | open_id] = min({dp[i + 1][j | open_id], dp[i][j | open_id], dp[i][j] + a[i]}); // dp[i][0]は常にゼロ } } if (dp[m][(1 << n) - 1] == INF) cout << -1 << endl; else cout << dp[m][(1 << n) - 1] << endl; return 0; }
replace
26
27
26
27
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; #define FOR(i, start, end) \ for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \ i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define REPS(i, n) for (i64 i = 1; i <= n; ++i) #define RREP(i, n) for (i64 i = n - 1; i >= 0; --i) #define RREPS(i, n) for (i64 i = n; i >= 1; --i) #define ALL(f, c, ...) \ (([&](decltype((c)) cccc) { \ return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \ })(c)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back #define mp make_pair #define F first #define S second template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; #define MAX_N 12 #define MAX_M 1000 #define INF 1152921504606846976 using P = pair<i64, i64>; i64 dp[MAX_M + 1][1 << MAX_N]; int main() { i64 N, M; cin >> N >> M; vector<i64> A(M); vector<i64> B(M, 0); REP(i, M) { i64 b, c; cin >> A[i] >> b; REP(j, b) { cin >> c; c--; B[i] |= 1 << c; } } REP(i, M + 1) REP(j, 1 << N) dp[i][j] = INF; dp[0][0] = 0; REP(i, M) { for (i64 bit = 0; bit < (1 << M); bit++) { chmin(dp[i + 1][bit], dp[i][bit]); chmin(dp[i + 1][bit | B[i]], dp[i][bit] + A[i]); } } i64 ans = dp[M][(1 << N) - 1]; if (ans < INF) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; #define FOR(i, start, end) \ for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \ i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define REPS(i, n) for (i64 i = 1; i <= n; ++i) #define RREP(i, n) for (i64 i = n - 1; i >= 0; --i) #define RREPS(i, n) for (i64 i = n; i >= 1; --i) #define ALL(f, c, ...) \ (([&](decltype((c)) cccc) { \ return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \ })(c)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back #define mp make_pair #define F first #define S second template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; #define MAX_N 12 #define MAX_M 1000 #define INF 1152921504606846976 using P = pair<i64, i64>; i64 dp[MAX_M + 1][1 << MAX_N]; int main() { i64 N, M; cin >> N >> M; vector<i64> A(M); vector<i64> B(M, 0); REP(i, M) { i64 b, c; cin >> A[i] >> b; REP(j, b) { cin >> c; c--; B[i] |= 1 << c; } } REP(i, M + 1) REP(j, 1 << N) dp[i][j] = INF; dp[0][0] = 0; REP(i, M) { for (i64 bit = 0; bit < (1 << N); bit++) { chmin(dp[i + 1][bit], dp[i][bit]); chmin(dp[i + 1][bit | B[i]], dp[i][bit] + A[i]); } } i64 ans = dp[M][(1 << N) - 1]; if (ans < INF) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
replace
101
102
101
102
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #include <map> using namespace std; int main() { int N, M; cin >> N >> M; int INF = 1e9 + 7; int A[15] = {}; int B[15] = {}; for (int i = 0; i < N; i++) { cin >> A[i]; int b; cin >> b; for (int j = 0; j < b; j++) { int c; cin >> c; B[i] += (1 << (c - 1)); } } int dp[4100] = {}; fill(dp, dp + (1 << N), INF); dp[0] = 0; for (int i = 0; i < (1 << N) - 1; i++) { for (int j = 0; j < M; j++) { dp[i | B[j]] = min(dp[i | B[j]], dp[i] + A[j]); } } if (dp[(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; }
#include <bits/stdc++.h> #include <map> using namespace std; int main() { int N, M; cin >> N >> M; int INF = 1e9 + 7; int A[1005] = {}; int B[1005] = {}; for (int i = 0; i < M; i++) { cin >> A[i]; int b; cin >> b; for (int j = 0; j < b; j++) { int c; cin >> c; B[i] += (1 << (c - 1)); } } int dp[4100] = {}; fill(dp, dp + (1 << N), INF); dp[0] = 0; for (int i = 0; i < (1 << N) - 1; i++) { for (int j = 0; j < M; j++) { dp[i | B[j]] = min(dp[i | B[j]], dp[i] + A[j]); } } if (dp[(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; }
replace
7
10
7
10
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; // #include <boost/multiprecision/cpp_int.hpp> // typedef boost::multiprecision::cpp_int ll; typedef long double dd; #define i_7 (ll)(1E9 + 7) // #define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); //////////////////////////// int main() { fastio ll n, m; cin >> n >> m; ll dp[1 << n][m + 1]; // jまで見てiを開けるための最小cost rep(i, 0, (1 << n) - 1) rep(j, 0, m) dp[i][j] = inf; dp[0][0] = 0; rep(i, 1, m) { ll a, b; ll c = 0; cin >> a >> b; rep(x, 1, b) { ll p; cin >> p; p--; c += (1ll << p); } rep(j, 0, (1 << n) - 1) { Min(dp[j][i], dp[j][i - 1]); Min(dp[j | c][i], dp[j][i - 1] + a); } for (ll j = (1 << n) - 1; j >= 0; j--) { rep(k, 0, n - 1) { ll p = 1 << k; if (j & p) { ll next = j - p; Min(dp[i][next], dp[i][j]); } } } } /* rep(i,0,(1<<n)-1){ rep(j,0,m){ cout<<dp[i][j]<<" "; }cout<<endl; } */ if (dp[(1 << n) - 1][m] == inf) cout << -1; else cout << dp[(1 << n) - 1][m] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; // #include <boost/multiprecision/cpp_int.hpp> // typedef boost::multiprecision::cpp_int ll; typedef long double dd; #define i_7 (ll)(1E9 + 7) // #define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); //////////////////////////// int main() { fastio ll n, m; cin >> n >> m; ll dp[1 << n][m + 1]; // jまで見てiを開けるための最小cost rep(i, 0, (1 << n) - 1) rep(j, 0, m) dp[i][j] = inf; dp[0][0] = 0; rep(i, 1, m) { ll a, b; ll c = 0; cin >> a >> b; rep(x, 1, b) { ll p; cin >> p; p--; c += (1ll << p); } rep(j, 0, (1 << n) - 1) { Min(dp[j][i], dp[j][i - 1]); Min(dp[j | c][i], dp[j][i - 1] + a); } for (ll j = (1 << n) - 1; j >= 0; j--) { rep(k, 0, n - 1) { ll p = 1 << k; if (j & p) { ll next = j - p; Min(dp[next][i], dp[j][i]); } } } } /* rep(i,0,(1<<n)-1){ rep(j,0,m){ cout<<dp[i][j]<<" "; }cout<<endl; } */ if (dp[(1 << n) - 1][m] == inf) cout << -1; else cout << dp[(1 << n) - 1][m] << endl; return 0; }
replace
70
71
70
71
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double db; typedef pair<int, int> pii; const int N = 10000; const db pi = acos(-1.0); #define lowbit(x) (x) & (-x) #define sqr(x) (x) * (x) #define rep(i, a, b) for (register int i = a; i <= b; i++) #define per(i, a, b) for (register int i = a; i >= b; i--) #define fir first #define sec second #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define maxd 998244353 #define eps 1e-8 int n, m, cost[20], p[20], f[5020], g[5020]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9')) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } int main() { n = read(); m = read(); rep(i, 1, m) { cost[i] = read(); int len = read(); rep(j, 1, len) { int tmp = read(); p[i] |= (1 << (tmp - 1)); } } memset(f, 0x3f, sizeof(f)); f[0] = 0; int lim = (1 << n) - 1; rep(i, 1, m) { memcpy(g, f, sizeof(g)); rep(j, 0, lim) g[j | p[i]] = min(g[j | p[i]], f[j] + cost[i]); // rep(j,0,5) cout << g[i] << " ";cout << endl; memcpy(f, g, sizeof(f)); // rep(j,0,5) cout << f[i] << " ";cout << endl; } if (f[lim] < maxd) printf("%d", f[lim]); else puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double db; typedef pair<int, int> pii; const int N = 10000; const db pi = acos(-1.0); #define lowbit(x) (x) & (-x) #define sqr(x) (x) * (x) #define rep(i, a, b) for (register int i = a; i <= b; i++) #define per(i, a, b) for (register int i = a; i >= b; i--) #define fir first #define sec second #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define maxd 998244353 #define eps 1e-8 int n, m, cost[1020], p[1020], f[5020], g[5020]; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9')) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } int main() { n = read(); m = read(); rep(i, 1, m) { cost[i] = read(); int len = read(); rep(j, 1, len) { int tmp = read(); p[i] |= (1 << (tmp - 1)); } } memset(f, 0x3f, sizeof(f)); f[0] = 0; int lim = (1 << n) - 1; rep(i, 1, m) { memcpy(g, f, sizeof(g)); rep(j, 0, lim) g[j | p[i]] = min(g[j | p[i]], f[j] + cost[i]); // rep(j,0,5) cout << g[i] << " ";cout << endl; memcpy(f, g, sizeof(f)); // rep(j,0,5) cout << f[i] << " ";cout << endl; } if (f[lim] < maxd) printf("%d", f[lim]); else puts("-1"); return 0; }
replace
17
18
17
18
0
p02901
C++
Runtime Error
// // Created by Hideaki Imamura on 2020-03-23. // #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) // const ll mod = 1000000007; int N, M; vector<ll> a, b; vector<int> c; vector<vector<ll>> dp; int main() { cin >> N >> M; a.resize(N); b.resize(M); c.assign(M, 0); for (int i = 0; i < M; ++i) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; ++j) { int tmp; cin >> tmp; c[i] += 1 << (tmp - 1); } } dp.assign(M + 1, vector<ll>(1 << N, INF)); dp[0][0] = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < (1 << N); ++j) { chmin(dp[i + 1][j], dp[i][j]); chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]); } } cout << (dp[M][(1 << N) - 1] < INF ? dp[M][(1 << N) - 1] : -1) << endl; return 0; }
// // Created by Hideaki Imamura on 2020-03-23. // #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) // const ll mod = 1000000007; int N, M; vector<ll> a, b; vector<int> c; vector<vector<ll>> dp; int main() { cin >> N >> M; a.resize(M); b.resize(M); c.assign(M, 0); for (int i = 0; i < M; ++i) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; ++j) { int tmp; cin >> tmp; c[i] += 1 << (tmp - 1); } } dp.assign(M + 1, vector<ll>(1 << N, INF)); dp[0][0] = 0; for (int i = 0; i < M; ++i) { for (int j = 0; j < (1 << N); ++j) { chmin(dp[i + 1][j], dp[i][j]); chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]); } } cout << (dp[M][(1 << N) - 1] < INF ? dp[M][(1 << N) - 1] : -1) << endl; return 0; }
replace
38
39
38
39
0
p02901
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); } const int max_n = 15; vector<Int> key[max_n]; vector<Int> value; Int dp[1 << max_n]; // set int main(void) { int N, M; cin >> N >> M; for (int i = 0; i < (1 << N); i++) { dp[i] = TEN(10); } for (int i = 0; i < M; i++) { Int a, b; cin >> a >> b; value.push_back(a); for (int j = 0; j < b; j++) { int c; cin >> c; key[i].push_back(c); } } dp[0] = 0; for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < M; j++) { int bit = i; for (int k = 0; k < key[j].size(); k++) { bit |= (1 << (key[j][k] - 1)); } dp[bit] = min(dp[bit], dp[i] + value[j]); } } if (dp[(1 << N) - 1] == TEN(10)) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); } const int max_n = 15; const int max_m = 1000 + 10; vector<Int> key[max_m]; vector<Int> value; Int dp[1 << max_n]; // set int main(void) { int N, M; cin >> N >> M; for (int i = 0; i < (1 << N); i++) { dp[i] = TEN(10); } for (int i = 0; i < M; i++) { Int a, b; cin >> a >> b; value.push_back(a); for (int j = 0; j < b; j++) { int c; cin >> c; key[i].push_back(c); } } dp[0] = 0; for (int i = 0; i < (1 << N); i++) { for (int j = 0; j < M; j++) { int bit = i; for (int k = 0; k < key[j].size(); k++) { bit |= (1 << (key[j][k] - 1)); } dp[bit] = min(dp[bit], dp[i] + value[j]); } } if (dp[(1 << N) - 1] == TEN(10)) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; return 0; }
replace
25
26
25
27
0
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define all(i, n) (i), (i + n) int dx4[4] = {1, 0, -1, 0}; int dy4[4] = {0, -1, 0, 1}; int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1}; int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6 + 1; const ll mod = 1000000007; // << fixed << setprecision // -------------------------------------- int n, m; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; vector<int> a(n); vector<int> t[m]; REP(i, m) { int b; cin >> a[i] >> b; REP(j, b) { int c; cin >> c; c--; t[i].push_back(c); } } int dp[10000]; REP(i, 10000) dp[i] = INF; dp[0] = 0; REP(i, m) { int h = 0; for (int u : t[i]) h |= (1 << u); REP(j, 1 << n) { int now = j | h; dp[now] = min(dp[now], dp[j] + a[i]); } } cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]) << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define all(i, n) (i), (i + n) int dx4[4] = {1, 0, -1, 0}; int dy4[4] = {0, -1, 0, 1}; int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1}; int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6 + 1; const ll mod = 1000000007; // << fixed << setprecision // -------------------------------------- int n, m; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; vector<int> a(m); vector<int> t[m]; REP(i, m) { int b; cin >> a[i] >> b; REP(j, b) { int c; cin >> c; c--; t[i].push_back(c); } } int dp[10000]; REP(i, 10000) dp[i] = INF; dp[0] = 0; REP(i, m) { int h = 0; for (int u : t[i]) h |= (1 << u); REP(j, 1 << n) { int now = j | h; dp[now] = min(dp[now], dp[j] + a[i]); } } cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]) << endl; }
replace
44
45
44
45
0
p02901
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, j) for (int i = 0; i < j; i++) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<pii> vpii; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; vi a(m), bits(m); vi s(1 << n, (1 << 30)); rep(i, m) { cin >> a[i]; int b; cin >> b; int bit = 0; rep(j, b) { int c; cin >> c; c--; bit |= 1 << c; } bits[i] = bit; s[bit] = min(s[bit], a[i]); // cout << bit << " " << a[i] << endl; } rep(k, m) { rep(i, m) { rep(j, 1 << n) if (s[j] != (1 << 30)) { // cout << i << " " << (j | bits[i]) << " " << s[j] << " " << a[i] << // endl; s[j | bits[i]] = min(s[j | bits[i]], s[j] + a[i]); } } } if (s[(1 << n) - 1] == (1 << 30)) { cout << "-1" << endl; } else { cout << s[(1 << n) - 1] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, j) for (int i = 0; i < j; i++) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<pii> vpii; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; vi a(m), bits(m); vi s(1 << n, (1 << 30)); rep(i, m) { cin >> a[i]; int b; cin >> b; int bit = 0; rep(j, b) { int c; cin >> c; c--; bit |= 1 << c; } bits[i] = bit; s[bit] = min(s[bit], a[i]); // cout << bit << " " << a[i] << endl; } rep(i, m) { rep(j, 1 << n) if (s[j] != (1 << 30)) { // cout << i << " " << (j | bits[i]) << " " << s[j] << " " << a[i] << // endl; s[j | bits[i]] = min(s[j | bits[i]], s[j] + a[i]); } } if (s[(1 << n) - 1] == (1 << 30)) { cout << "-1" << endl; } else { cout << s[(1 << n) - 1] << endl; } return 0; }
replace
41
48
41
46
TLE
p02901
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define M 1000000000000000000LL #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; typedef vector<ll> vll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ll n, m, x; cin >> n >> m; vll a(m), b(m); vector<vll> c(m); rep(i, m) { cin >> a[i] >> b[i]; // push_backよりemplace_backの方が速いらしい。改宗します。 rep(j, b[i]) cin >> x; c[i].emplace_back(x); } vll dp(1 << n, M); dp[0] = 0; rep(i, m) { ll now = 0; // get 'OR' of all c[i][j] rep(j, b[i]) now |= 1 << (c[i][j] - 1); // cout << bitset<10>(now)<< endl; rep(bit, 1 << n) chmin(dp[bit | now], dp[bit] + a[i]); } if (dp[(1 << n) - 1] == M) dp[(1 << n) - 1] = -1; cout << dp[(1 << n) - 1] << endl; }
#include "bits/stdc++.h" using namespace std; #define M 1000000000000000000LL #define rep(i, n) for (int i = 0; i < n; ++i) typedef long long ll; typedef vector<ll> vll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ll n, m, x; cin >> n >> m; vll a(m), b(m); vector<vll> c(m); rep(i, m) { cin >> a[i] >> b[i]; // push_backよりemplace_backの方が速いらしい。改宗します。 rep(j, b[i]) { cin >> x; c[i].emplace_back(x); } } vll dp(1 << n, M); dp[0] = 0; rep(i, m) { ll now = 0; // get 'OR' of all c[i][j] rep(j, b[i]) now |= 1 << (c[i][j] - 1); // cout << bitset<10>(now)<< endl; rep(bit, 1 << n) chmin(dp[bit | now], dp[bit] + a[i]); } if (dp[(1 << n) - 1] == M) dp[(1 << n) - 1] = -1; cout << dp[(1 << n) - 1] << endl; }
replace
29
31
29
33
-11
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; /**** Type Define ****/ typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; /**** Const List ****/ const ll INF = 1LL << 60; const ll mod = 1000000007; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const ll NCK_MAX = 510000; /**** General Functions ****/ ll ketawa(ll n) { ll a = 0; while (n != 0) { a += n % 10; n /= 10; } return a; } ll RS(ll N, ll P) { // modがだるいときにつかう if (P == 0) return 1; if (P % 2 == 0) { ll t = RS(N, P / 2); return t * t; } return (N * RS(N, P - 1)); } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } bool IsPrime(ll a) { // order root a if (a == 1) return false; for (int i = 2; i * i <= a; i++) { if (a % i == 0 && a != i) { return false; } } return true; } 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 extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_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; } } ll nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } ll lmin(ll a, ll b) { return a > b ? b : a; }; ll lmax(ll a, ll b) { return a > b ? a : b; }; ll lsum(ll a, ll b) { return a + b; }; void warshall_floyd(int n) { for (int k = 0; k < n; k++) { // 経由する頂点 for (int i = 0; i < n; i++) { // 始点 for (int j = 0; j < n; j++) { // 終点 // d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } // 汎用的な二分探索のテンプレ /* int binary_search(int key) { ll ng = -1; //絶対falseの値、なければ最小値-1 ll ok = (int)a.size(); // 絶対trueの値 なければ最大値+1 // ok と ng のどちらが大きいかわからないことを考慮 while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid, key)) ok = mid; else ng = mid; } return ok; } */ /**** Zip ****/ template <typename T> class Zip { vector<T> d; bool flag; public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { // T need to have operator < !! if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return (ll)d.size(); } }; /**** Union Find ****/ class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: void init(ll n) { par.resize(n, 1); rank.resize(n, 0); } ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; /**** Segment Tree ****/ class SegmentTree { public: vector<pair<double, double>> node; // node[0]は使用しない ll n; // データの個数(nodeの最下層には何個並んでいるか) pair<double, double> initial_value; // 初期値 public: void Init(ll n_, pair<double, double> initial_value_) { n = 1; while (n < n_) n *= 2; node.resize(2 * n); for (ll i = 0; i < 2 * n; i++) { node[i] = initial_value_; } initial_value = initial_value_; } void Update(ll k, pair<double, double> a) { // node[k]をaにする // それに従って先祖も変わっていく k += n; node[k] = a; while (k > 1) { k = k / 2; node[k] = pair<double, double>( node[k * 2].first * node[k * 2 + 1].first, node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second); } } /*void Watch(){ for(ll i=0;i<2*n;i++){ cout<<node[i]<<endl; } }*/ double Query() { //[a,b) return node[1].first + node[1].second; } }; /**** LIS ****/ ll lis(ll *a, ll n, ll *dp) { fill(dp, dp + n, INF); // INFを代入 for (ll i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i]; return (ll)(lower_bound(dp, dp + n, INF) - dp); } /**** main function ****/ ll n, m; string s; P ans[101]; map<ll, ll> mp; ll sw = 0; ll nedan[100]; bitset<12> kagi[1000]; ll dp[1003][4197]; int main() { cin >> n >> m; for (ll i = 0; i < m; i++) { ll aa, bb; cin >> nedan[i] >> bb; for (ll j = 0; j < bb; j++) { ll cc; cin >> cc; kagi[i].set(cc - 1); } // cout<<kagi[i]<<endl; } ll aaa = pow(2, n); // cout<<aaa<<endl; for (ll i = 0; i <= m; i++) { for (ll j = 0; j < aaa; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (ll i = 0; i < m; i++) { for (ll j = 0; j < pow(2, n); j++) { bitset<12> k(j); k = k | kagi[i]; ll result = k.to_ullong(); // cout<<i<<j<<endl; dp[i + 1][result] = lmin(dp[i + 1][result], dp[i][j] + nedan[i]); // cout<<i+1<<" "<<result<<" "<<dp[i+1][result]; dp[i + 1][j] = lmin(dp[i + 1][j], dp[i][j]); // cout<<i+1<<" "<<j<<" "<<dp[i+1][j]<<endl; } } if (dp[m][aaa - 1] == INF) { cout << -1 << endl; return 0; } cout << dp[m][aaa - 1] << endl; }
#include <algorithm> #include <bitset> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; /**** Type Define ****/ typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; /**** Const List ****/ const ll INF = 1LL << 60; const ll mod = 1000000007; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const ll NCK_MAX = 510000; /**** General Functions ****/ ll ketawa(ll n) { ll a = 0; while (n != 0) { a += n % 10; n /= 10; } return a; } ll RS(ll N, ll P) { // modがだるいときにつかう if (P == 0) return 1; if (P % 2 == 0) { ll t = RS(N, P / 2); return t * t; } return (N * RS(N, P - 1)); } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } bool IsPrime(ll a) { // order root a if (a == 1) return false; for (int i = 2; i * i <= a; i++) { if (a % i == 0 && a != i) { return false; } } return true; } 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 extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_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; } } ll nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } ll lmin(ll a, ll b) { return a > b ? b : a; }; ll lmax(ll a, ll b) { return a > b ? a : b; }; ll lsum(ll a, ll b) { return a + b; }; void warshall_floyd(int n) { for (int k = 0; k < n; k++) { // 経由する頂点 for (int i = 0; i < n; i++) { // 始点 for (int j = 0; j < n; j++) { // 終点 // d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } } // 汎用的な二分探索のテンプレ /* int binary_search(int key) { ll ng = -1; //絶対falseの値、なければ最小値-1 ll ok = (int)a.size(); // 絶対trueの値 なければ最大値+1 // ok と ng のどちらが大きいかわからないことを考慮 while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid, key)) ok = mid; else ng = mid; } return ok; } */ /**** Zip ****/ template <typename T> class Zip { vector<T> d; bool flag; public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { // T need to have operator < !! if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return (ll)d.size(); } }; /**** Union Find ****/ class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: void init(ll n) { par.resize(n, 1); rank.resize(n, 0); } ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; /**** Segment Tree ****/ class SegmentTree { public: vector<pair<double, double>> node; // node[0]は使用しない ll n; // データの個数(nodeの最下層には何個並んでいるか) pair<double, double> initial_value; // 初期値 public: void Init(ll n_, pair<double, double> initial_value_) { n = 1; while (n < n_) n *= 2; node.resize(2 * n); for (ll i = 0; i < 2 * n; i++) { node[i] = initial_value_; } initial_value = initial_value_; } void Update(ll k, pair<double, double> a) { // node[k]をaにする // それに従って先祖も変わっていく k += n; node[k] = a; while (k > 1) { k = k / 2; node[k] = pair<double, double>( node[k * 2].first * node[k * 2 + 1].first, node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second); } } /*void Watch(){ for(ll i=0;i<2*n;i++){ cout<<node[i]<<endl; } }*/ double Query() { //[a,b) return node[1].first + node[1].second; } }; /**** LIS ****/ ll lis(ll *a, ll n, ll *dp) { fill(dp, dp + n, INF); // INFを代入 for (ll i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i]; return (ll)(lower_bound(dp, dp + n, INF) - dp); } /**** main function ****/ ll n, m; string s; P ans[101]; map<ll, ll> mp; ll sw = 0; ll nedan[1001]; bitset<12> kagi[1001]; ll dp[1003][4197]; int main() { cin >> n >> m; for (ll i = 0; i < m; i++) { ll aa, bb; cin >> nedan[i] >> bb; for (ll j = 0; j < bb; j++) { ll cc; cin >> cc; kagi[i].set(cc - 1); } // cout<<kagi[i]<<endl; } ll aaa = pow(2, n); // cout<<aaa<<endl; for (ll i = 0; i <= m; i++) { for (ll j = 0; j < aaa; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (ll i = 0; i < m; i++) { for (ll j = 0; j < pow(2, n); j++) { bitset<12> k(j); k = k | kagi[i]; ll result = k.to_ullong(); // cout<<i<<j<<endl; dp[i + 1][result] = lmin(dp[i + 1][result], dp[i][j] + nedan[i]); // cout<<i+1<<" "<<result<<" "<<dp[i+1][result]; dp[i + 1][j] = lmin(dp[i + 1][j], dp[i][j]); // cout<<i+1<<" "<<j<<" "<<dp[i+1][j]<<endl; } } if (dp[m][aaa - 1] == INF) { cout << -1 << endl; return 0; } cout << dp[m][aaa - 1] << endl; }
replace
274
276
274
276
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #define ll long long using namespace std; int n, m, a[310], dp[310][(1 << 12) + 10]; vector<int> v[310]; const int Inf = 1e9; int Rec(int i, int Mask) { if (i == m) return (Mask == ((1 << n) - 1) ? 0 : Inf); if (dp[i][Mask] != -1) return dp[i][Mask]; int Res = Inf, temp = 0; for (auto j : v[i]) temp |= (1 << j); Res = min(Res, a[i] + Rec(i + 1, Mask | temp)); Res = min(Res, Rec(i + 1, Mask)); return dp[i][Mask] = Res; } int main() { memset(dp, -1, sizeof(dp)); cin >> n >> m; for (int i = 0; i < m; i++) { int b; cin >> a[i] >> b; for (int j = 0; j < b; j++) { int c; cin >> c; v[i].push_back(c - 1); } } cout << (Rec(0, 0) == Inf ? -1 : Rec(0, 0)); return 0; }
#include <bits/stdc++.h> #include <iostream> #define ll long long using namespace std; int n, m, a[1010], dp[1010][(1 << 12) + 10]; vector<int> v[1010]; const int Inf = 1e9; int Rec(int i, int Mask) { if (i == m) return (Mask == ((1 << n) - 1) ? 0 : Inf); if (dp[i][Mask] != -1) return dp[i][Mask]; int Res = Inf, temp = 0; for (auto j : v[i]) temp |= (1 << j); Res = min(Res, a[i] + Rec(i + 1, Mask | temp)); Res = min(Res, Rec(i + 1, Mask)); return dp[i][Mask] = Res; } int main() { memset(dp, -1, sizeof(dp)); cin >> n >> m; for (int i = 0; i < m; i++) { int b; cin >> a[i] >> b; for (int j = 0; j < b; j++) { int c; cin >> c; v[i].push_back(c - 1); } } cout << (Rec(0, 0) == Inf ? -1 : Rec(0, 0)); return 0; }
replace
5
7
5
7
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair<int, int>; const int Max_N = 15; const int Max_M = 1e3 + 5; int c[Max_M][Max_N]; const int INF = 1e9; int main() { int N, M; cin >> N >> M; vector<int> a(M), b(M); rep(i, M) { cin >> a[i] >> b[i]; rep(j, b[i]) cin >> c[i][j]; rep(j, b[i]) c[i][j]--; } vector<int> dp(1 << N, INF); dp[0] = 0; rep(bit, 1 << N) { rep(i, M) { int bit_next = bit; rep(j, b[i]) if (!(bit & 1 << j)) bit_next += 1 << c[i][j]; dp[bit_next] = min(dp[bit_next], dp[bit] + a[i]); } } if (dp[(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair<int, int>; const int Max_N = 15; const int Max_M = 1e3 + 5; int c[Max_M][Max_N]; const int INF = 1e9; int main() { int N, M; cin >> N >> M; vector<int> a(M), b(M); rep(i, M) { cin >> a[i] >> b[i]; rep(j, b[i]) cin >> c[i][j]; rep(j, b[i]) c[i][j]--; } vector<int> dp(1 << N, INF); dp[0] = 0; rep(bit, 1 << N) { rep(i, M) { int bit_next = bit; rep(j, b[i]) if (!(bit & 1 << c[i][j])) bit_next += 1 << c[i][j]; dp[bit_next] = min(dp[bit_next], dp[bit] + a[i]); } } if (dp[(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[(1 << N) - 1] << endl; return 0; }
replace
25
26
25
26
0
p02901
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> #define N 15 #define M 1005 using namespace std; int n, m, a[M], b[M], c[M][N], d[1 << N]; int f(int p, int q) { int i, j, ne, re = 1e9; if (p == 0) return 0; if (q == m) return 1e9; if (d[p]) return d[p]; for (i = q; i < m; i++) { ne = p; for (j = 0; j < b[i]; j++) { ne &= (1 << n) - 1 - (1 << c[i][j] - 1); } re = min(re, f(ne, i + 1) + a[i]); } return d[p] = re; } int main() { int i, j, t; cin >> n >> m; for (i = 0; i < m; i++) { scanf("%d %d", &a[i], &b[i]); for (j = 0; j < b[i]; j++) { scanf("%d", &c[i][j]); } } t = f((1 << n) - 1, 0); if (t == 1e9) puts("-1"); else cout << t; return 0; }
#include <cstdio> #include <iostream> #define N 15 #define M 1005 using namespace std; int n, m, a[M], b[M], c[M][N], d[1 << N]; int f(int p, int q) { int i, j, ne, re = 1e9; if (p == 0) return 0; if (q == m) return 1e9; if (d[p]) return d[p]; for (i = q; i < m; i++) { ne = p; for (j = 0; j < b[i]; j++) { ne &= (1 << n) - 1 - (1 << c[i][j] - 1); } if (ne != p) re = min(re, f(ne, i + 1) + a[i]); } return d[p] = re; } int main() { int i, j, t; cin >> n >> m; for (i = 0; i < m; i++) { scanf("%d %d", &a[i], &b[i]); for (j = 0; j < b[i]; j++) { scanf("%d", &c[i][j]); } } t = f((1 << n) - 1, 0); if (t == 1e9) puts("-1"); else cout << t; return 0; }
replace
21
22
21
23
TLE
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAXN = 11; const int INF = 0x3f3f3f3f; int n, m, f[1 << MAXN]; int main() { cin >> n >> m; memset(f, 255, sizeof(f)); f[0] = 0; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; int msk = 0; while (b--) { int t; cin >> t; msk |= (1 << (t - 1)); } for (int k = 0; k < (1 << n); k++) { if (f[k] == -1) continue; if (f[k | msk] == -1) f[k | msk] = f[k] + a; else f[k | msk] = min(f[k | msk], f[k] + a); } } if (f[(1 << n) - 1] == INF) cout << -1 << endl; else cout << f[(1 << n) - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 15; const int INF = 0x3f3f3f3f; int n, m, f[1 << MAXN]; int main() { cin >> n >> m; memset(f, 255, sizeof(f)); f[0] = 0; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; int msk = 0; while (b--) { int t; cin >> t; msk |= (1 << (t - 1)); } for (int k = 0; k < (1 << n); k++) { if (f[k] == -1) continue; if (f[k | msk] == -1) f[k | msk] = f[k] + a; else f[k | msk] = min(f[k | msk], f[k] + a); } } if (f[(1 << n) - 1] == INF) cout << -1 << endl; else cout << f[(1 << n) - 1] << endl; return 0; }
replace
2
3
2
3
0
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n, m) for (int i = (n); i < (int)(m); i++) #define reps(i, n, m) for (int i = (n); i <= (int)(m); i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define fs first #define sc second #define lb lower_bound #define ub upper_bound #define LB(a, x) lb(all(a), x) - a.begin() #define UB(a, x) ub(all(a), x) - a.begin() #define printfdouble(x) printf("%.12f\n", (x)) #define chartoint(c) (int)((c) - '0') #define chartoll(c) (long long)((c) - '0') #define MOD 1000000007 #define itn int #define enld endl #define ednl endl #define icn cin #define Endl endl #define stirng string using namespace std; typedef long long ll; const double pi = 3.141592653589793; using Graph = vector<vector<int>>; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } const ll INFLL = 100100100100100100; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; ll a[1005]; ll b[1005]; ll c[1005]; Fill(c, 0); rep(i, 0, M) { cin >> a[i] >> b[i]; rep(j, 0, b[i]) { ll k; cin >> k; k--; c[i] += (1 << k); } } ll dp[15][5000]; Fill(dp, INFLL); dp[0][0] = 0; rep(i, 0, M) { rep(j, 0, (1 << N)) { chmin(dp[i + 1][j], dp[i][j]); chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]); } } if (dp[M][(1 << N) - 1] < INFLL) { cout << dp[M][(1 << N) - 1] << ednl; } else { cout << -1 << enld; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n, m) for (int i = (n); i < (int)(m); i++) #define reps(i, n, m) for (int i = (n); i <= (int)(m); i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define fs first #define sc second #define lb lower_bound #define ub upper_bound #define LB(a, x) lb(all(a), x) - a.begin() #define UB(a, x) ub(all(a), x) - a.begin() #define printfdouble(x) printf("%.12f\n", (x)) #define chartoint(c) (int)((c) - '0') #define chartoll(c) (long long)((c) - '0') #define MOD 1000000007 #define itn int #define enld endl #define ednl endl #define icn cin #define Endl endl #define stirng string using namespace std; typedef long long ll; const double pi = 3.141592653589793; using Graph = vector<vector<int>>; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } const ll INFLL = 100100100100100100; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; ll a[1005]; ll b[1005]; ll c[1005]; Fill(c, 0); rep(i, 0, M) { cin >> a[i] >> b[i]; rep(j, 0, b[i]) { ll k; cin >> k; k--; c[i] += (1 << k); } } ll dp[1005][5000]; Fill(dp, INFLL); dp[0][0] = 0; rep(i, 0, M) { rep(j, 0, (1 << N)) { chmin(dp[i + 1][j], dp[i][j]); chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]); } } if (dp[M][(1 << N) - 1] < INFLL) { cout << dp[M][(1 << N) - 1] << ednl; } else { cout << -1 << enld; } return 0; }
replace
80
81
80
81
0
p02901
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vii vector<int> #define vll vector<ll> #define lb lower_bound #define pb push_back #define mp make_pair #define rep(i, n) for (ll i = 0; i < n; i++) #define rep2(i, a, b) for (ll i = a; i < b; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() // #define int ll using namespace std; const int INF(1 << 30); const ll LLINF(1LL << 55LL); const int MOD = 1000000007; const int MAX = 510000; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n, m, dp[1 << 14]; ll a[100010], b[20], c[2000][30]; cin >> n >> m; rep(i, m) { cin >> a[i] >> b[i]; rep(j, b[i]) { cin >> c[i][j]; } } rep(i, 1 << 14) { dp[i] = LLINF; } dp[0] = 0; rep(i, m) { ll now = 0; rep(j, b[i]) { now |= 1 << (c[i][j] - 1); } rep(j, 1 << n) { dp[j | now] = min(dp[j | now], dp[j] + a[i]); } } if (dp[(1 << n) - 1] == LLINF) dp[(1 << n) - 1] = -1; cout << dp[(1 << n) - 1] << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vii vector<int> #define vll vector<ll> #define lb lower_bound #define pb push_back #define mp make_pair #define rep(i, n) for (ll i = 0; i < n; i++) #define rep2(i, a, b) for (ll i = a; i < b; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() // #define int ll using namespace std; const int INF(1 << 30); const ll LLINF(1LL << 55LL); const int MOD = 1000000007; const int MAX = 510000; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n, m, dp[1 << 14]; ll a[100010], b[2000], c[2000][30]; cin >> n >> m; rep(i, m) { cin >> a[i] >> b[i]; rep(j, b[i]) { cin >> c[i][j]; } } rep(i, 1 << 14) { dp[i] = LLINF; } dp[0] = 0; rep(i, m) { ll now = 0; rep(j, b[i]) { now |= 1 << (c[i][j] - 1); } rep(j, 1 << n) { dp[j | now] = min(dp[j | now], dp[j] + a[i]); } } if (dp[(1 << n) - 1] == LLINF) dp[(1 << n) - 1] = -1; cout << dp[(1 << n) - 1] << endl; return 0; }
replace
41
42
41
42
0
p02901
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; const ll MOD = 998244353; const ll INF = 1LL << 60; int dp[1001][1 << 12]; int a[12], b[12], c[12]; int main() { int N, M; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; j++) { int k; cin >> k; c[i] |= (1 << (k - 1)); } } fill((int *)dp, (int *)(dp + 1001), 1 << 30); dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int bit = 0; bit < (1 << N); bit++) { dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]); dp[i + 1][bit | c[i]] = min(dp[i + 1][bit | c[i]], dp[i][bit] + a[i]); } } if (dp[M][(1 << N) - 1] == 1 << 30) cout << -1 << endl; else cout << dp[M][(1 << N) - 1] << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; const ll MOD = 998244353; const ll INF = 1LL << 60; int dp[1001][1 << 12]; int a[1000], b[1000], c[1000]; int main() { int N, M; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; j++) { int k; cin >> k; c[i] |= (1 << (k - 1)); } } fill((int *)dp, (int *)(dp + 1001), 1 << 30); dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int bit = 0; bit < (1 << N); bit++) { dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]); dp[i + 1][bit | c[i]] = min(dp[i + 1][bit | c[i]], dp[i][bit] + a[i]); } } if (dp[M][(1 << N) - 1] == 1 << 30) cout << -1 << endl; else cout << dp[M][(1 << N) - 1] << endl; }
replace
6
7
6
7
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m), c(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; j++) { int x; cin >> x; x--; c[i] += (1 << x); } } vector<int> dp(1 << n, 1e9); dp[0] = 0; for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { dp[i | c[j]] = min(dp[i | c[j]], dp[i] + a[i]); } } if (dp[(1 << n) - 1] == 1e9) { cout << -1 << endl; } else { cout << dp[(1 << n) - 1] << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m), c(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; j++) { int x; cin >> x; x--; c[i] += (1 << x); } } vector<int> dp(1 << n, 1e9); dp[0] = 0; for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < m; j++) { dp[i | c[j]] = min(dp[i | c[j]], dp[i] + a[j]); } } if (dp[(1 << n) - 1] == 1e9) { cout << -1 << endl; } else { cout << dp[(1 << n) - 1] << endl; } }
replace
18
20
18
20
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <utility> #include <vector> #define chmin(x, y) x = min(x, y); #define chmax(x, y) x = max(x, y); #define rep(i, j) for (int(i) = 0; (i) < (j); (i)++) #define dump(x) cout << #x << " = " << (x) << endl; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long int ll; const int INF = 1e8; int N, M; vector<pair<int, int>> key; void input() { cin >> N >> M; rep(i, M) { int a, b; cin >> a >> b; int s = 0; // bitで集合をとる rep(j, b) { int c; cin >> c; c--; s |= 1 << c; } key.emplace_back(s, a); } } void solve() { input(); vector<int> dp(1 << N, INF); dp[0] = 0; rep(i, 1 << N) { rep(j, M) { int t = i | key[i].first; int cost = dp[i] + key[j].second; dp[t] = min(dp[t], cost); } } int ans = dp.back(); if (ans == INF) ans = -1; cout << ans << endl; return; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #include <iostream> #include <utility> #include <vector> #define chmin(x, y) x = min(x, y); #define chmax(x, y) x = max(x, y); #define rep(i, j) for (int(i) = 0; (i) < (j); (i)++) #define dump(x) cout << #x << " = " << (x) << endl; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long int ll; const int INF = 1e8; int N, M; vector<pair<int, int>> key; void input() { cin >> N >> M; rep(i, M) { int a, b; cin >> a >> b; int s = 0; // bitで集合をとる rep(j, b) { int c; cin >> c; c--; s |= 1 << c; } key.emplace_back(s, a); } } void solve() { input(); vector<int> dp(1 << N, INF); dp[0] = 0; rep(i, 1 << N) { rep(j, M) { int t = i | key[j].first; int cost = dp[i] + key[j].second; dp[t] = min(dp[t], cost); } } int ans = dp.back(); if (ans == INF) ans = -1; cout << ans << endl; return; } int main() { solve(); return 0; }
replace
42
43
42
43
0
p02901
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++) #define REPR(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < ll(n); i++) #define ALL(v) v.begin(), v.end() #define SIZE(x) ll(x.size()) using P = pair<int, int>; 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 int INF = 2e9; const ll LINF = (1LL << 60); int dp[105][4100]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(m), key(m, 0); REP(i, m) { int b; cin >> a[i] >> b; REP(k, b) { int c; cin >> c; c--; key[i] |= (1 << c); } } REP(i, m + 1) REP(j, (1 << n)) dp[i][j] = INF; dp[0][0] = 0; REP(i, m) REP(j, (1 << n)) { chmin(dp[i + 1][j], dp[i][j]); chmin(dp[i + 1][j | key[i]], dp[i][j] + a[i]); } cout << (dp[m][(1 << n) - 1] == INF ? -1 : dp[m][(1 << n) - 1]) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define REPR(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < ll(n); i++) #define ALL(v) v.begin(), v.end() #define SIZE(x) ll(x.size()) using P = pair<int, int>; 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 int INF = 2e9; const ll LINF = (1LL << 60); int dp[1005][4100]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(m), key(m, 0); REP(i, m) { int b; cin >> a[i] >> b; REP(k, b) { int c; cin >> c; c--; key[i] |= (1 << c); } } REP(i, m + 1) REP(j, (1 << n)) dp[i][j] = INF; dp[0][0] = 0; REP(i, m) REP(j, (1 << n)) { chmin(dp[i + 1][j], dp[i][j]); chmin(dp[i + 1][j | key[i]], dp[i][j] + a[i]); } cout << (dp[m][(1 << n) - 1] == INF ? -1 : dp[m][(1 << n) - 1]) << endl; return 0; }
replace
26
27
26
27
0
p02901
C++
Runtime Error
// g++ -std=c++14 test.cpp -o test.out #include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <utility> #include <vector> using namespace std; #define LL long long int const LL INF = (LL)(1e18) + 1; const int INF_INT = 2147483647 - 1e6 - 1; const LL mod = 1000000007ll; const int mod_int = 1000000007; int N, M; vector<LL> a, b; vector<int> c; // どの宝箱が開錠可能かを表す LL ans = 0; void solve() { // dp[i][j]:i番目の鍵まで見たとき、 // bit列jで表されるような宝箱を開けるときの // 最小費用 const int opened_all = (1 << N) - 1; // 全部開けた時を表すビット列 vector<vector<LL>> dp(M + 1, vector<LL>(opened_all + 1, INF)); dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int j = 0; j <= opened_all; j++) { // i番目の鍵を購入する場合 dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]); // しない場合 dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ans = dp[N][opened_all]; if (ans == INF) ans = -1; } int main() { cin >> N >> M; a = vector<LL>(M); b = vector<LL>(M); c = vector<int>(M, 0); for (int i = 0; i < M; i++) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; j++) { LL c_input; cin >> c_input; c[i] |= (1 << (c_input - 1)); } } solve(); cout << ans << endl; return 0; }
// g++ -std=c++14 test.cpp -o test.out #include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <utility> #include <vector> using namespace std; #define LL long long int const LL INF = (LL)(1e18) + 1; const int INF_INT = 2147483647 - 1e6 - 1; const LL mod = 1000000007ll; const int mod_int = 1000000007; int N, M; vector<LL> a, b; vector<int> c; // どの宝箱が開錠可能かを表す LL ans = 0; void solve() { // dp[i][j]:i番目の鍵まで見たとき、 // bit列jで表されるような宝箱を開けるときの // 最小費用 const int opened_all = (1 << N) - 1; // 全部開けた時を表すビット列 vector<vector<LL>> dp(M + 1, vector<LL>(opened_all + 1, INF)); dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int j = 0; j <= opened_all; j++) { // i番目の鍵を購入する場合 dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]); // しない場合 dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ans = dp[M][opened_all]; if (ans == INF) ans = -1; } int main() { cin >> N >> M; a = vector<LL>(M); b = vector<LL>(M); c = vector<int>(M, 0); for (int i = 0; i < M; i++) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; j++) { LL c_input; cin >> c_input; c[i] |= (1 << (c_input - 1)); } } solve(); cout << ans << endl; return 0; }
replace
46
47
46
47
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INCANT \ cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), \ cout << fixed << setprecision(20); #define int long long #define gcd __gcd #define all(x) (x).begin(), (x).end() template <class T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; } template <class T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; } #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__) #define _rev(i, n) revi(i, n, 0) #define revi(i, a, b) for (int i = (int)(a - 1); i >= (int)(b); i--) #define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__) #define each(i, n) for (auto &&i : n) const int INF = 1e18, MOD = 1e9 + 7; signed main() { INCANT; int n, m, a, b, c, sesame, dp[5555]; rep(i, 5555) dp[i] = INF; dp[0] = 0; cin >> n >> m; rep(i, m) { cin >> a >> b; sesame = 0; while (b--) { cin >> c; c--; sesame += (int)pow(2, c); } rep(i, 5000) { chmin(dp[i | sesame], dp[i] + a); } } cout << (dp[(int)pow(2, n) - 1] == INF ? -1 : dp[(int)pow(2, n) - 1]) << endl; }
#include <bits/stdc++.h> using namespace std; #define INCANT \ cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), \ cout << fixed << setprecision(20); #define int long long #define gcd __gcd #define all(x) (x).begin(), (x).end() template <class T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; } template <class T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; } #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__) #define _rev(i, n) revi(i, n, 0) #define revi(i, a, b) for (int i = (int)(a - 1); i >= (int)(b); i--) #define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__) #define each(i, n) for (auto &&i : n) const int INF = 1e18, MOD = 1e9 + 7; signed main() { INCANT; int n, m, a, b, c, sesame, dp[5555]; rep(i, 5555) dp[i] = INF; dp[0] = 0; cin >> n >> m; rep(i, m) { cin >> a >> b; sesame = 0; while (b--) { cin >> c; c--; sesame += (int)pow(2, c); } rep(i, (int)pow(2, n)) { chmin(dp[i | sesame], dp[i] + a); } } cout << (dp[(int)pow(2, n) - 1] == INF ? -1 : dp[(int)pow(2, n) - 1]) << endl; }
replace
33
34
33
34
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int INF = 1001001001; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> key; rep(i, M) { int a, b; cin >> a >> b; int s; rep(j, b) { int c; cin >> c; c--; s |= 1 << c; } key.emplace_back(s, a); // push_back(要素の追加)の上位互換 } // bit演算子でcを管理 vector<int> dp(1 << N, INF); // 2の12乗は4096. dp=コストの最小値。 dp[0] = 0; rep(s, 1 << N) { rep(i, M) { int t = s | key[i].first; int cost = dp[s] + key[i].second; dp[t] = min(dp[t], cost); } } int ans = dp.back(); if (ans == INF) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int INF = 1001001001; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> key; rep(i, M) { int a, b; cin >> a >> b; int s = 0; rep(j, b) { int c; cin >> c; c--; s |= 1 << c; } key.emplace_back(s, a); // push_back(要素の追加)の上位互換 } // bit演算子でcを管理 vector<int> dp(1 << N, INF); // 2の12乗は4096. dp=コストの最小値。 dp[0] = 0; rep(s, 1 << N) { rep(i, M) { int t = s | key[i].first; int cost = dp[s] + key[i].second; dp[t] = min(dp[t], cost); } } int ans = dp.back(); if (ans == INF) ans = -1; cout << ans << endl; return 0; }
replace
13
14
13
14
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef string str; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef map<str, int> mapsi; typedef map<str, int>::iterator mapsitr; typedef map<int, int> mint; typedef map<ll, ll> mll; typedef set<int> si; typedef set<ll> sll; typedef si ::iterator sitr; typedef si ::reverse_iterator rsitr; typedef sll ::iterator sltr; typedef sll ::reverse_iterator rsltr; #define mset multiset typedef mset<int> msi; typedef mset<ll> msll; typedef msi ::iterator msitr; typedef msi ::reverse_iterator msritr; typedef msll ::iterator msltr; typedef msll ::reverse_iterator mslritr; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define fi first #define se second #define fs first.second #define ss second.second #define ff first.first #define sf second.first #define newl '\n' #define fbo find_by_order #define ook order_of_key char to_upper(char x) { if (97 <= int(x) && int(x) <= 122) return char(x - 32); else if (65 <= int(x) && int(x) <= 90) return x; } char to_lower(char x) { if (97 <= int(x) && int(x) <= 122) return x; else if (65 <= int(x) && int(x) <= 90) return char(x + 32); } int numerize(char x) { if (48 <= int(x) && int(x) <= 57) return int(x - '0'); else if (97 <= int(x) && int(x) <= 122) return int(x - 96); else if (65 <= int(x) && int(x) <= 90) return int(x - 64); } bool isect(int l1, int r1, int l2, int r2) { pii p1, p2; p1 = mp(l1, r1); p2 = mp(l2, r2); if (p1 > p2) swap(p1, p2); if (p2.fi <= p1.se) return true; else return false; } ll quickpow(ll num1, ll num2, ll MOD) { if (num2 == 0) return 1; else if (num2 == 1) return num1; else { ll temp = quickpow(num1, num2 / 2, MOD); ll res = ((temp % MOD) * (temp % MOD)) % MOD; if (num2 % 2 == 1) res = ((res % MOD) * (num1 % MOD)) % MOD; return res; } } ll invmod(ll num, ll MOD) { return quickpow(num, MOD - 2, MOD); } ll gcd(ll num1, ll num2) { if (num1 < num2) swap(num1, num2); ll num3 = num1 % num2; while (num3 > 0) { num1 = num2; num2 = num3; num3 = num1 % num2; } return num2; } ll lcm(ll num1, ll num2) { return (ll)(num1 / __gcd(num1, num2)) * num2; } // end of Template int n, m, a[20], v[20]; ll dp[20][5000]; ll dua[30]; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); dua[0] = 1; for (int i = 1; i <= 13; i++) dua[i] = 2 * dua[i - 1]; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i]; int b; cin >> b; for (int j = 1; j <= b; j++) { int c; cin >> c; v[i] += dua[c - 1]; } } dp[0][0] = 0; int lim = dua[n] - 1; for (int i = 1; i <= lim; i++) dp[0][i] = INT_MAX; for (int i = 0; i < m; i++) { for (int j = 0; j <= lim; j++) dp[i + 1][j] = dp[i][j]; for (int j = 0; j <= lim; j++) { dp[i + 1][j | v[i + 1]] = min(dp[i + 1][j | v[i + 1]], dp[i][j] + a[i + 1]); } } if (dp[m][lim] == INT_MAX) dp[m][lim] = -1; cout << dp[m][lim] << newl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef string str; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef map<str, int> mapsi; typedef map<str, int>::iterator mapsitr; typedef map<int, int> mint; typedef map<ll, ll> mll; typedef set<int> si; typedef set<ll> sll; typedef si ::iterator sitr; typedef si ::reverse_iterator rsitr; typedef sll ::iterator sltr; typedef sll ::reverse_iterator rsltr; #define mset multiset typedef mset<int> msi; typedef mset<ll> msll; typedef msi ::iterator msitr; typedef msi ::reverse_iterator msritr; typedef msll ::iterator msltr; typedef msll ::reverse_iterator mslritr; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define fi first #define se second #define fs first.second #define ss second.second #define ff first.first #define sf second.first #define newl '\n' #define fbo find_by_order #define ook order_of_key char to_upper(char x) { if (97 <= int(x) && int(x) <= 122) return char(x - 32); else if (65 <= int(x) && int(x) <= 90) return x; } char to_lower(char x) { if (97 <= int(x) && int(x) <= 122) return x; else if (65 <= int(x) && int(x) <= 90) return char(x + 32); } int numerize(char x) { if (48 <= int(x) && int(x) <= 57) return int(x - '0'); else if (97 <= int(x) && int(x) <= 122) return int(x - 96); else if (65 <= int(x) && int(x) <= 90) return int(x - 64); } bool isect(int l1, int r1, int l2, int r2) { pii p1, p2; p1 = mp(l1, r1); p2 = mp(l2, r2); if (p1 > p2) swap(p1, p2); if (p2.fi <= p1.se) return true; else return false; } ll quickpow(ll num1, ll num2, ll MOD) { if (num2 == 0) return 1; else if (num2 == 1) return num1; else { ll temp = quickpow(num1, num2 / 2, MOD); ll res = ((temp % MOD) * (temp % MOD)) % MOD; if (num2 % 2 == 1) res = ((res % MOD) * (num1 % MOD)) % MOD; return res; } } ll invmod(ll num, ll MOD) { return quickpow(num, MOD - 2, MOD); } ll gcd(ll num1, ll num2) { if (num1 < num2) swap(num1, num2); ll num3 = num1 % num2; while (num3 > 0) { num1 = num2; num2 = num3; num3 = num1 % num2; } return num2; } ll lcm(ll num1, ll num2) { return (ll)(num1 / __gcd(num1, num2)) * num2; } // end of Template int n, m, a[2000], v[2000]; ll dp[2000][5000]; ll dua[30]; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); dua[0] = 1; for (int i = 1; i <= 13; i++) dua[i] = 2 * dua[i - 1]; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i]; int b; cin >> b; for (int j = 1; j <= b; j++) { int c; cin >> c; v[i] += dua[c - 1]; } } dp[0][0] = 0; int lim = dua[n] - 1; for (int i = 1; i <= lim; i++) dp[0][i] = INT_MAX; for (int i = 0; i < m; i++) { for (int j = 0; j <= lim; j++) dp[i + 1][j] = dp[i][j]; for (int j = 0; j <= lim; j++) { dp[i + 1][j | v[i + 1]] = min(dp[i + 1][j | v[i + 1]], dp[i][j] + a[i + 1]); } } if (dp[m][lim] == INT_MAX) dp[m][lim] = -1; cout << dp[m][lim] << newl; }
replace
116
118
116
118
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define loop(i, n) rep(i, 0, n) using namespace std; using ll = long long; // dp[i][j]={鍵1,...,iを用いて宝箱j(bitsetで管理)を開けるための費用の最小値} constexpr int n_max = 12, m_max = 100; int dp[m_max + 1][1 << n_max]; constexpr int infty = 1e9; int main() { int n, m; cin >> n >> m; loop(i, 1 + m) { loop(j, 1 << n) { dp[i][j] = infty; } } dp[0][0] = 0; rep(i, 1, 1 + m) { int a, b, key = 0; cin >> a >> b; loop(j, b) { int c; cin >> c; key |= (1 << (c - 1)); } loop(j, 1 << n) dp[i][j] = dp[i - 1][j]; loop(j, 1 << n) { dp[i][j | key] = min(dp[i][j | key], min(dp[i - 1][j | key], dp[i - 1][j] + a)); } } if (dp[m][(1 << n) - 1] == infty) cout << -1 << endl; else cout << dp[m][(1 << n) - 1] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define loop(i, n) rep(i, 0, n) using namespace std; using ll = long long; // dp[i][j]={鍵1,...,iを用いて宝箱j(bitsetで管理)を開けるための費用の最小値} constexpr int n_max = 12, m_max = 1000; int dp[m_max + 1][1 << n_max]; constexpr int infty = 1e9; int main() { int n, m; cin >> n >> m; loop(i, 1 + m) { loop(j, 1 << n) { dp[i][j] = infty; } } dp[0][0] = 0; rep(i, 1, 1 + m) { int a, b, key = 0; cin >> a >> b; loop(j, b) { int c; cin >> c; key |= (1 << (c - 1)); } loop(j, 1 << n) dp[i][j] = dp[i - 1][j]; loop(j, 1 << n) { dp[i][j | key] = min(dp[i][j | key], min(dp[i - 1][j | key], dp[i - 1][j] + a)); } } if (dp[m][(1 << n) - 1] == infty) cout << -1 << endl; else cout << dp[m][(1 << n) - 1] << endl; return 0; }
replace
6
7
6
7
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/hash_map> #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define REP(i, n) for ((i) = 0; (i) < (n); (i)++) #define rep(i, x, n) for ((i) = (x); (i) < (n); (i)++) #define REV(i, n) for ((i) = (n); (i) >= 0; (i)--) #define FORIT(it, x) for ((it) = (x).begin(); (it) != (x).end(); (it)++) #define foreach(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define rforeach(it, c) \ for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) #define foreach2d(i, j, v) \ foreach (i, v) \ foreach (j, *i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SZ(x) ((int)(x).size()) #define MMS(x, n) memset(x, n, sizeof(x)) #define mms(x, n, s) memset(x, n, sizeof(x) * s) #define pb push_back #define mp make_pair #define NX next_permutation #define UN(x) sort(all(x)), x.erase(unique(all(x)), x.end()) #define CV(x, n) count(all(x), (n)) #define FIND(x, n) find(all(x), (n)) - (x).begin() #define ACC(x) accumulate(all(x), 0) #define PPC(x) __builtin_popcountll(x) #define LZ(x) __builtin_clz(x) #define TZ(x) __builtin_ctz(x) #define mxe(x) *max_element(all(x)) #define mne(x) *min_element(all(x)) #define low(x, i) lower_bound(all(x), i) #define upp(x, i) upper_bound(all(x), i) #define NXPOW2(x) (1ll << ((int)log2(x) + 1)) #define PR(x) cout << #x << " = " << (x) << endl; typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<ll, ll> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int OO = (int)2e9; const double eps = 1e-9; const int N = 1e3 + 3; int n, m; int a[N], b[N]; int dp[12][1 << 12]; int calc(int idx, int msk) { if (msk == (1 << n) - 1) return 0; if (idx == m) return OO; int &ret = dp[idx][msk]; if (ret != -1) return ret; ret = calc(idx + 1, msk); ret = min(ret, calc(idx + 1, msk | b[idx]) + a[idx]); return ret; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // freopen("in.txt", "rt", stdin); // freopen("out.txt", "wt", stdout); #endif cin >> n >> m; for (int i = 0; i < m; i++) { int c, x; cin >> a[i] >> c; for (int j = 0; j < c; j++) { cin >> x; x--; b[i] |= 1 << x; } } MMS(dp, -1); int res = calc(0, 0); if (res == OO) res = -1; cout << res << endl; return 0; }
#include <bits/stdc++.h> #include <ext/hash_map> #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define REP(i, n) for ((i) = 0; (i) < (n); (i)++) #define rep(i, x, n) for ((i) = (x); (i) < (n); (i)++) #define REV(i, n) for ((i) = (n); (i) >= 0; (i)--) #define FORIT(it, x) for ((it) = (x).begin(); (it) != (x).end(); (it)++) #define foreach(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define rforeach(it, c) \ for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) #define foreach2d(i, j, v) \ foreach (i, v) \ foreach (j, *i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SZ(x) ((int)(x).size()) #define MMS(x, n) memset(x, n, sizeof(x)) #define mms(x, n, s) memset(x, n, sizeof(x) * s) #define pb push_back #define mp make_pair #define NX next_permutation #define UN(x) sort(all(x)), x.erase(unique(all(x)), x.end()) #define CV(x, n) count(all(x), (n)) #define FIND(x, n) find(all(x), (n)) - (x).begin() #define ACC(x) accumulate(all(x), 0) #define PPC(x) __builtin_popcountll(x) #define LZ(x) __builtin_clz(x) #define TZ(x) __builtin_ctz(x) #define mxe(x) *max_element(all(x)) #define mne(x) *min_element(all(x)) #define low(x, i) lower_bound(all(x), i) #define upp(x, i) upper_bound(all(x), i) #define NXPOW2(x) (1ll << ((int)log2(x) + 1)) #define PR(x) cout << #x << " = " << (x) << endl; typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<ll, ll> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int OO = (int)2e9; const double eps = 1e-9; const int N = 1e3 + 3; int n, m; int a[N], b[N]; int dp[N][1 << 12]; int calc(int idx, int msk) { if (msk == (1 << n) - 1) return 0; if (idx == m) return OO; int &ret = dp[idx][msk]; if (ret != -1) return ret; ret = calc(idx + 1, msk); ret = min(ret, calc(idx + 1, msk | b[idx]) + a[idx]); return ret; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // freopen("in.txt", "rt", stdin); // freopen("out.txt", "wt", stdout); #endif cin >> n >> m; for (int i = 0; i < m; i++) { int c, x; cin >> a[i] >> c; for (int j = 0; j < c; j++) { cin >> x; x--; b[i] |= 1 << x; } } MMS(dp, -1); int res = calc(0, 0); if (res == OO) res = -1; cout << res << endl; return 0; }
replace
60
61
60
61
0
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cout << #x << " = " << (x) << endl; 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 int long long void solve() { int n, m; cin >> n >> m; int dp[1000][4400]; rep(i, m + 1) { rep(bit, (1 << n)) { dp[i][bit] = INF; } } dp[0][0] = 0; rep(i, m) { int a, b; cin >> a >> b; int mask = 0; rep(i, b) { int d; cin >> d; --d; mask += (1 << d); } rep(bit, (1 << n)) { chmin(dp[i + 1][bit | mask], dp[i][bit] + a); chmin(dp[i + 1][bit], dp[i][bit]); } } if (dp[m][(1 << n) - 1] == INF) { cout << -1 << endl; } else { cout << dp[m][(1 << n) - 1] << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // init(); solve(); // cout << "finish" << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cout << #x << " = " << (x) << endl; 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 int long long void solve() { int n, m; cin >> n >> m; int dp[1010][4400]; rep(i, m + 1) { rep(bit, (1 << n)) { dp[i][bit] = INF; } } dp[0][0] = 0; rep(i, m) { int a, b; cin >> a >> b; int mask = 0; rep(i, b) { int d; cin >> d; --d; mask += (1 << d); } rep(bit, (1 << n)) { chmin(dp[i + 1][bit | mask], dp[i][bit] + a); chmin(dp[i + 1][bit], dp[i][bit]); } } if (dp[m][(1 << n) - 1] == INF) { cout << -1 << endl; } else { cout << dp[m][(1 << n) - 1] << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // init(); solve(); // cout << "finish" << endl; return 0; }
replace
66
67
66
67
-11
p02901
C++
Time Limit Exceeded
#include <iostream> #include <vector> #define ANS_MAX 1000000000 #define M_MAX 1000 #define N_MAX 12 using namespace std; long dp[M_MAX][1 << N_MAX]; long price[M_MAX]; vector<vector<int>> keys(M_MAX); int n, m; long caldp(int k, int close) { if (k == m) return close == 0 ? 0 : ANS_MAX; if (dp[k][close] > 0) return dp[k][close]; long ret = caldp(k + 1, close); int nextClose = close; for (int key : keys[k]) { if ((close & (1 << key)) != 0) nextClose -= (1 << key); } return dp[k][close] = min(ret, caldp(k + 1, nextClose) + price[k]); } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int b; int key; cin >> price[i] >> b; for (int j = 0; j < b; j++) { cin >> key; keys[i].push_back(key - 1); } } long ans = caldp(0, (1 << n) - 1); ans = ans < ANS_MAX ? ans : -1; cout << ans << endl; }
#include <iostream> #include <vector> #define ANS_MAX 1000000000 #define M_MAX 1000 #define N_MAX 12 using namespace std; long dp[M_MAX][1 << N_MAX]; long price[M_MAX]; vector<vector<int>> keys(M_MAX); int n, m; long caldp(int k, int close) { if (k == m) return close == 0 ? 0 : ANS_MAX; if (close == 0) return dp[k][close] = 0; if (dp[k][close] > 0) return dp[k][close]; long ret = caldp(k + 1, close); int nextClose = close; for (int key : keys[k]) { if ((close & (1 << key)) != 0) nextClose -= (1 << key); } return dp[k][close] = min(ret, caldp(k + 1, nextClose) + price[k]); } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int b; int key; cin >> price[i] >> b; for (int j = 0; j < b; j++) { cin >> key; keys[i].push_back(key - 1); } } long ans = caldp(0, (1 << n) - 1); ans = ans < ANS_MAX ? ans : -1; cout << ans << endl; }
insert
15
15
15
17
TLE
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define all(x) begin(x), end(x) #define dbg(x) cerr << #x << " = " << x << endl #define _ << ' ' << using namespace std; using ll = long long; using vi = vector<int>; int a[100], mask[100]; int n, m, b, dp[100][1 << 12]; int f(int k, int m) { if (k == ::m) { if (m == (1 << n) - 1) return 0; return 1e9; } if (dp[k][m] != -1) return dp[k][m]; return dp[k][m] = min(f(k + 1, m), a[k] + f(k + 1, m | mask[k])); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> a[i] >> b; for (int j = 0; j < b; ++j) { int c; cin >> c; mask[i] |= (1 << (c - 1)); } } memset(dp, -1, sizeof dp); if (f(0, 0) >= 1e9) cout << -1; else cout << dp[0][0]; }
#include <bits/stdc++.h> #define all(x) begin(x), end(x) #define dbg(x) cerr << #x << " = " << x << endl #define _ << ' ' << using namespace std; using ll = long long; using vi = vector<int>; int a[1000], mask[1000]; int n, m, b, dp[1000][1 << 12]; int f(int k, int m) { if (k == ::m) { if (m == (1 << n) - 1) return 0; return 1e9; } if (dp[k][m] != -1) return dp[k][m]; return dp[k][m] = min(f(k + 1, m), a[k] + f(k + 1, m | mask[k])); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> a[i] >> b; for (int j = 0; j < b; ++j) { int c; cin >> c; mask[i] |= (1 << (c - 1)); } } memset(dp, -1, sizeof dp); if (f(0, 0) >= 1e9) cout << -1; else cout << dp[0][0]; }
replace
8
10
8
10
0
p02901
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define MEMSET(v, h) memset((v), h, sizeof(v)) typedef long long ll; using namespace std; int main(void) { ll N, M; ll key[10004], cost[10004]; ll dp[15][10000]; ll a, b, c; cin >> N >> M; ll goal = pow(2, N) - 1; MEMSET(key, 0); MEMSET(cost, 0); rep(i, M) { cin >> a >> b; cost[i] = a; rep(j, b) { cin >> c; key[i] += pow(2, c - 1); } // cout<<key[i]<<endl; } rep(i, M + 1) rep(j, goal + 1) dp[i][j] = 10000000001; dp[0][0] = 0; rep(i, M) rep(j, goal + 1) { dp[i + 1][j | key[i]] = min(dp[i + 1][j | key[i]], dp[i][j] + cost[i]); dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]); /*rep(k, M+1){ rep(l, goal+1) cout<<dp[k][l]<<" "; cout<<endl; } cout<<endl;*/ } cout << ((dp[M][goal] > 10000000000) ? (ll)-1 : dp[M][goal]) << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define MEMSET(v, h) memset((v), h, sizeof(v)) typedef long long ll; using namespace std; int main(void) { ll N, M; ll key[10004], cost[10004]; ll dp[1024][10000]; ll a, b, c; cin >> N >> M; ll goal = pow(2, N) - 1; MEMSET(key, 0); MEMSET(cost, 0); rep(i, M) { cin >> a >> b; cost[i] = a; rep(j, b) { cin >> c; key[i] += pow(2, c - 1); } // cout<<key[i]<<endl; } rep(i, M + 1) rep(j, goal + 1) dp[i][j] = 10000000001; dp[0][0] = 0; rep(i, M) rep(j, goal + 1) { dp[i + 1][j | key[i]] = min(dp[i + 1][j | key[i]], dp[i][j] + cost[i]); dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]); /*rep(k, M+1){ rep(l, goal+1) cout<<dp[k][l]<<" "; cout<<endl; } cout<<endl;*/ } cout << ((dp[M][goal] > 10000000000) ? (ll)-1 : dp[M][goal]) << endl; return 0; }
replace
22
23
22
23
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define PI 3.14159265358979 #define MOD 1000000007 // = 10^9 + 7 using namespace std; using ll = long long; void solve() { int n, m; cin >> n >> m; vector<int> a(m); vector<int> b(m); int c[1007]; for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; ++j) { int input; cin >> input; input--; c[i] += (1 << input); } } const int INF = 1000000000; vector<int> dp(5000, INF); dp[0] = 0; for (int i = 0; i < m; i++) { int now = c[i]; for (int mask = 0; mask < (1 << n); mask++) { dp[mask | now] = min(dp[mask | now], dp[mask] + a[i]); } } cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]); } int main() { fastio; solve(); return 0; }
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define PI 3.14159265358979 #define MOD 1000000007 // = 10^9 + 7 using namespace std; using ll = long long; void solve() { int n, m; cin >> n >> m; vector<int> a(m); vector<int> b(m); vector<int> c(m); for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i]; for (int j = 0; j < b[i]; ++j) { int input; cin >> input; input--; c[i] += (1 << input); } } const int INF = 1000000000; vector<int> dp(5000, INF); dp[0] = 0; for (int i = 0; i < m; i++) { int now = c[i]; for (int mask = 0; mask < (1 << n); mask++) { dp[mask | now] = min(dp[mask | now], dp[mask] + a[i]); } } cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]); } int main() { fastio; solve(); return 0; }
replace
18
19
18
19
0
p02901
C++
Runtime Error
// header {{{ #include <bits/stdc++.h> using namespace std; // {U}{INT,LONG,LLONG}_{MAX,MIN} #define INF INT_MAX / 3 #define LLINF LLONG_MAX / 3 #define MOD (1000000007LL) #define MODA(a, b) a = ((a) + (b)) % MOD #define MODP(a, b) a = ((a) * (b)) % MOD #define inc(i, l, r) for (int i = (l); i < (r); i++) #define dec(i, l, r) for (int i = (r)-1; i >= (l); i--) #define pb push_back #define se second #define fi first #define mset(a, b) memset(a, b, sizeof(a)) using LL = long long; using G = vector<vector<int>>; int di[] = {0, -1, 0, 1}; int dj[] = {1, 0, -1, 0}; // }}} int dp[1005][1 << 12]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n), b(n), k(n, 0); inc(i, 0, m) { cin >> a[i] >> b[i]; inc(j, 0, b[i]) { int c; cin >> c; c--; k[i] |= (1 << c); } } int inf = 1000000000; inc(i, 0, m + 1) inc(j, 0, 1 << n) dp[i][j] = inf; dp[0][0] = 0; inc(i, 0, m) { inc(j, 0, 1 << 12) { if (dp[i][j] != inf) { dp[i + 1][j | k[i]] = min(dp[i + 1][j | k[i]], dp[i][j] + a[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } } // inc(i, 0, m+1){ // inc(j, 0, 1<<n){ // cout << dp[i][j] << " "; //} // cout << endl; //} int ans = dp[m][(1 << n) - 1]; if (ans == inf) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
// header {{{ #include <bits/stdc++.h> using namespace std; // {U}{INT,LONG,LLONG}_{MAX,MIN} #define INF INT_MAX / 3 #define LLINF LLONG_MAX / 3 #define MOD (1000000007LL) #define MODA(a, b) a = ((a) + (b)) % MOD #define MODP(a, b) a = ((a) * (b)) % MOD #define inc(i, l, r) for (int i = (l); i < (r); i++) #define dec(i, l, r) for (int i = (r)-1; i >= (l); i--) #define pb push_back #define se second #define fi first #define mset(a, b) memset(a, b, sizeof(a)) using LL = long long; using G = vector<vector<int>>; int di[] = {0, -1, 0, 1}; int dj[] = {1, 0, -1, 0}; // }}} int dp[1005][1 << 12]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(m), b(m), k(m, 0); inc(i, 0, m) { cin >> a[i] >> b[i]; inc(j, 0, b[i]) { int c; cin >> c; c--; k[i] |= (1 << c); } } int inf = 1000000000; inc(i, 0, m + 1) inc(j, 0, 1 << n) dp[i][j] = inf; dp[0][0] = 0; inc(i, 0, m) { inc(j, 0, 1 << 12) { if (dp[i][j] != inf) { dp[i + 1][j | k[i]] = min(dp[i + 1][j | k[i]], dp[i][j] + a[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } } // inc(i, 0, m+1){ // inc(j, 0, 1<<n){ // cout << dp[i][j] << " "; //} // cout << endl; //} int ans = dp[m][(1 << n) - 1]; if (ans == inf) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
replace
31
32
31
32
0
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define END cout << endl; #else #define DEB(X) \ {} #define END \ {} #endif typedef long long ll; #define int ll #define uset unordered_set #define umap unordered_map typedef std::pair<int, int> P; struct edge { int to, cost; }; const int INF = 100000000000000000; const int INF2 = 9223372036854775807; const int MOD = 1000000007; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y)) #define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y)) #define MAX(X, Y) (*max_element(X, Y)) #define MIN(X, Y) (*min_element(X, Y)) #define NP(X, Y) next_permutation(X, Y) #define setp(X, Y) cout << fixed << setprecision(Y) << X; int ceil2(int a, int b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int pow2(int a, int b) { int r = 1; for (int i = 1; i <= b; i++) { r *= a; } return r; } int Log2(int a) { int t = 0; while (1) { if (a == 0 || a == 1) { break; } a /= 2; t++; } return t; } int N, M; int A[13], B[13]; int C[13][13]; set<int> U; int dp[1005][4097]; signed main() { cin >> N >> M; REP(i, M) { cin >> A[i] >> B[i]; REP(j, B[i]) { cin >> C[i][j]; U.insert(C[i][j]); } } if (U.size() != N) { cout << -1 << endl; return 0; } REP(i, 1005) REP(j, 4097) { dp[i][j] = INF; } REP(i, 4097) { dp[0][0] = 0; } int b = 0; REP(i, B[0]) { b |= (1 << (C[0][i] - 1)); } dp[0][b] = A[0]; for (int i = 1; i < M; i++) { b = 0; REP(j, B[i]) { b |= (1 << (C[i][j] - 1)); } DEB(b) END for (int j = 0; j <= 4096; j++) { if (dp[i - 1][j] != INF) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); dp[i][j | b] = min(dp[i - 1][j] + A[i], dp[i][j | b]); if (j | b == 15) { DEB(dp[i - 1][13]) DEB(dp[i][15]) DEB((13 | 14)) END } } } DEB(dp[i - 1][13]) DEB(dp[i][15]) DEB((13 | 14)) END } b = 0; REP(i, N) { b |= (1 << i); } cout << dp[M - 1][b] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define END cout << endl; #else #define DEB(X) \ {} #define END \ {} #endif typedef long long ll; #define int ll #define uset unordered_set #define umap unordered_map typedef std::pair<int, int> P; struct edge { int to, cost; }; const int INF = 100000000000000000; const int INF2 = 9223372036854775807; const int MOD = 1000000007; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y)) #define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y)) #define MAX(X, Y) (*max_element(X, Y)) #define MIN(X, Y) (*min_element(X, Y)) #define NP(X, Y) next_permutation(X, Y) #define setp(X, Y) cout << fixed << setprecision(Y) << X; int ceil2(int a, int b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int pow2(int a, int b) { int r = 1; for (int i = 1; i <= b; i++) { r *= a; } return r; } int Log2(int a) { int t = 0; while (1) { if (a == 0 || a == 1) { break; } a /= 2; t++; } return t; } int N, M; int A[1005], B[1005]; int C[1005][13]; set<int> U; int dp[1005][4097]; signed main() { cin >> N >> M; REP(i, M) { cin >> A[i] >> B[i]; REP(j, B[i]) { cin >> C[i][j]; U.insert(C[i][j]); } } if (U.size() != N) { cout << -1 << endl; return 0; } REP(i, 1005) REP(j, 4097) { dp[i][j] = INF; } REP(i, 4097) { dp[0][0] = 0; } int b = 0; REP(i, B[0]) { b |= (1 << (C[0][i] - 1)); } dp[0][b] = A[0]; for (int i = 1; i < M; i++) { b = 0; REP(j, B[i]) { b |= (1 << (C[i][j] - 1)); } DEB(b) END for (int j = 0; j <= 4096; j++) { if (dp[i - 1][j] != INF) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); dp[i][j | b] = min(dp[i - 1][j] + A[i], dp[i][j | b]); if (j | b == 15) { DEB(dp[i - 1][13]) DEB(dp[i][15]) DEB((13 | 14)) END } } } DEB(dp[i - 1][13]) DEB(dp[i][15]) DEB((13 | 14)) END } b = 0; REP(i, N) { b |= (1 << i); } cout << dp[M - 1][b] << endl; return 0; }
replace
74
76
74
76
0
p02901
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = int(a); i < int(b); 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; } typedef long long ll; using namespace std; vector<vector<int>> dp(1001, vector<int>(2048, 1e9)); int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; dp[0][0] = 0; rep(i, m) { int a, b; cin >> a >> b; int num = 0; rep(j, b) { int t; cin >> t; num += 1 << (t - 1); } // cout<<"num"<<num<<endl; rep(j, 1 << n) { dp[i + 1][j] = dp[i][j]; } rep(j, 1 << n) { chmin(dp[i + 1][j | num], dp[i][j] + a); // cout<<dp[i+1][j|num]<<endl; } } int res = dp[m][(1 << n) - 1]; if (res == 1e9) cout << -1 << endl; else cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = int(a); i < int(b); 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; } typedef long long ll; using namespace std; vector<vector<int>> dp(1001, vector<int>(4096, 1e9)); int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; dp[0][0] = 0; rep(i, m) { int a, b; cin >> a >> b; int num = 0; rep(j, b) { int t; cin >> t; num += 1 << (t - 1); } // cout<<"num"<<num<<endl; rep(j, 1 << n) { dp[i + 1][j] = dp[i][j]; } rep(j, 1 << n) { chmin(dp[i + 1][j | num], dp[i][j] + a); // cout<<dp[i+1][j|num]<<endl; } } int res = dp[m][(1 << n) - 1]; if (res == 1e9) cout << -1 << endl; else cout << res << endl; return 0; }
replace
38
39
38
39
0
p02901
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using lint = int64_t; int main() { const int INF = 1000000000; int N, M; cin >> N >> M; vector<int> a(M, 0), c(M, 0); rep(i, M) { int b; cin >> a[i] >> b; rep(j, b) { int x; cin >> x; --x; c[i] += (1 << x); } } vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF)); dp[0][0] = 0; rep(i, M) rep(j, 1 << N) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]); } if (dp[M][(1 << M) - 1] == INF) cout << -1 << "\n"; else cout << dp[M][(1 << N) - 1] << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using lint = int64_t; int main() { const int INF = 1000000000; int N, M; cin >> N >> M; vector<int> a(M, 0), c(M, 0); rep(i, M) { int b; cin >> a[i] >> b; rep(j, b) { int x; cin >> x; --x; c[i] += (1 << x); } } vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF)); dp[0][0] = 0; rep(i, M) rep(j, 1 << N) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]); } if (dp[M][(1 << N) - 1] == INF) cout << -1 << "\n"; else cout << dp[M][(1 << N) - 1] << "\n"; return 0; }
replace
38
39
38
39
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second const int mod = 1e9 + 7, A = 1e3 + 2; int n, m, price[A], masks[888]; ll dp[A][888]; ll solve(int ind, int mask) { if (ind == m) return (mask == (1 << n) - 1 ? 0 : 1e18); if (~dp[ind][mask]) return dp[ind][mask]; ll val = solve(ind + 1, mask); val = min(val, solve(ind + 1, mask | masks[ind]) + price[ind]); return dp[ind][mask] = val; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> price[i] >> x; while (x--) cin >> y, masks[i] |= (1 << (y - 1)); } memset(dp, -1, sizeof dp); ll ans = solve(0, 0); cout << (ans >= 1e18 ? -1 : ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second const int mod = 1e9 + 7, A = 1e3 + 2; int n, m, price[A], masks[8888]; ll dp[A][8888]; ll solve(int ind, int mask) { if (ind == m) return (mask == (1 << n) - 1 ? 0 : 1e18); if (~dp[ind][mask]) return dp[ind][mask]; ll val = solve(ind + 1, mask); val = min(val, solve(ind + 1, mask | masks[ind]) + price[ind]); return dp[ind][mask] = val; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> price[i] >> x; while (x--) cin >> y, masks[i] |= (1 << (y - 1)); } memset(dp, -1, sizeof dp); ll ans = solve(0, 0); cout << (ans >= 1e18 ? -1 : ans); return 0; }
replace
7
9
7
9
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 typedef long long int ll; // const ll INF=(ll)1e18; const int INF = (1 << 21); int dp[13][100000]; int main() { int N, M; cin >> N >> M; REP(i, M + 1) REP(j, 1 << N) dp[i][j] = INF; dp[0][0] = 0; REP(i, M) { int a, b; cin >> a >> b; int m = 0; REP(j, b) { int c; cin >> c; m += 1 << (c - 1); } REP(j, 1 << N) { if (dp[i][j] == INF) continue; dp[i + 1][j] = dp[i][j]; } REP(j, 1 << N) { if (dp[i][j] == INF) continue; // printf("%d %d: %d %d\n", i,j|m, dp[i][j|m], dp[i][j] + a); int tmp = min(dp[i][j | m], dp[i][j] + a); dp[i + 1][j | m] = min(tmp, dp[i + 1][j | m]); } } // REP(i,M+1){ // REP(j,1<<N){ // cout << dp[i][j] << " "; // } // cout << endl; // } if (dp[M][(1 << N) - 1] == INF) { cout << -1 << endl; } else { cout << dp[M][(1 << N) - 1] << endl; } }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define MOD 1000000007 typedef long long int ll; // const ll INF=(ll)1e18; const int INF = (1 << 21); int dp[1001][4096]; int main() { int N, M; cin >> N >> M; REP(i, M + 1) REP(j, 1 << N) dp[i][j] = INF; dp[0][0] = 0; REP(i, M) { int a, b; cin >> a >> b; int m = 0; REP(j, b) { int c; cin >> c; m += 1 << (c - 1); } REP(j, 1 << N) { if (dp[i][j] == INF) continue; dp[i + 1][j] = dp[i][j]; } REP(j, 1 << N) { if (dp[i][j] == INF) continue; // printf("%d %d: %d %d\n", i,j|m, dp[i][j|m], dp[i][j] + a); int tmp = min(dp[i][j | m], dp[i][j] + a); dp[i + 1][j | m] = min(tmp, dp[i + 1][j | m]); } } // REP(i,M+1){ // REP(j,1<<N){ // cout << dp[i][j] << " "; // } // cout << endl; // } if (dp[M][(1 << N) - 1] == INF) { cout << -1 << endl; } else { cout << dp[M][(1 << N) - 1] << endl; } }
replace
12
13
12
13
0
p02901
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } int N, M, a[1123], b[1123], c[1123][123]; int memo[1123][1 << 13]; int dp(int i, int j) { if (memo[i][j] != -1) return memo[i][j]; if (!i) { if (j) { return 1000000000; } else { return 0; } } int ret = dp(i - 1, j); int mask = 0; //(1 << N) - 1; rep(t, b[i - 1]) { mask ^= 1 << (c[i - 1][t] - 1); } for (int t = 0; t < (1 << N); ++t) { ret = min(ret, dp(i - 1, j & (~(t & mask))) + a[i - 1]); } return memo[i][j] = ret; } int main() { memset(memo, 0xff, sizeof(memo)); set<int> s; scanf("%d%d", &N, &M); rep(i, M) { scanf("%d%d", &a[i], &b[i]); rep(j, b[i]) { scanf("%d", &c[i][j]); s.insert(c[i][j]); } } if (s.size() != N) { printf("-1\n"); return 0; } printf("%d\n", dp(M, (1 << N) - 1)); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } int N, M, a[1123], b[1123], c[1123][123]; int memo[1123][1 << 13]; int dp(int i, int j) { if (memo[i][j] != -1) return memo[i][j]; if (!i) { if (j) { return 1000000000; } else { return 0; } } int ret = dp(i - 1, j); int mask = 0; //(1 << N) - 1; rep(t, b[i - 1]) { mask ^= 1 << (c[i - 1][t] - 1); } for (int t = 0 + (1 << N) - 1; t < (1 << N); ++t) { ret = min(ret, dp(i - 1, j & (~(t & mask))) + a[i - 1]); } return memo[i][j] = ret; } int main() { memset(memo, 0xff, sizeof(memo)); set<int> s; scanf("%d%d", &N, &M); rep(i, M) { scanf("%d%d", &a[i], &b[i]); rep(j, b[i]) { scanf("%d", &c[i][j]); s.insert(c[i][j]); } } if (s.size() != N) { printf("-1\n"); return 0; } printf("%d\n", dp(M, (1 << N) - 1)); return 0; }
replace
44
45
44
45
TLE
p02901
C++
Runtime Error
// fifer a tak luboin #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define ll long long #define mp make_pair #define pb push_back #define s second #define f first #define endl "\n" using namespace std; const ll inf = 1e14; const int mod = 998244353; const int N = (int)100100; const double eps = 1e-10; const double pi = acos(-1.0); int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; ll cost[100]; vector<int> g[120]; ll dp[1 << 12]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("lshape.in", "r", stdin); // freopen("lshape.out", "w", stdout); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x; cin >> cost[i] >> x; for (int j = 0; j < x; j++) { int xx; cin >> xx; g[i].pb(xx); } } for (int mask = 0; mask < (1 << 12); mask++) { dp[mask] = inf; } dp[0] = 0; for (int mask = 0; mask < (1 << n); mask++) { for (int i = 0; i < m; i++) { int nmask = mask; for (int j = 0; j < g[i].size(); j++) { if ((nmask & (1 << (g[i][j] - 1))) > 0) nmask -= (1 << (g[i][j] - 1)); } dp[mask] = min(dp[mask], dp[nmask] + cost[i]); } } if (dp[(1 << n) - 1] == inf) cout << -1 << endl; else cout << dp[(1 << n) - 1] << endl; return 0; }
// fifer a tak luboin #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define ll long long #define mp make_pair #define pb push_back #define s second #define f first #define endl "\n" using namespace std; const ll inf = 1e14; const int mod = 998244353; const int N = (int)100100; const double eps = 1e-10; const double pi = acos(-1.0); int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; ll cost[N]; vector<int> g[N]; ll dp[1 << 12]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("lshape.in", "r", stdin); // freopen("lshape.out", "w", stdout); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x; cin >> cost[i] >> x; for (int j = 0; j < x; j++) { int xx; cin >> xx; g[i].pb(xx); } } for (int mask = 0; mask < (1 << 12); mask++) { dp[mask] = inf; } dp[0] = 0; for (int mask = 0; mask < (1 << n); mask++) { for (int i = 0; i < m; i++) { int nmask = mask; for (int j = 0; j < g[i].size(); j++) { if ((nmask & (1 << (g[i][j] - 1))) > 0) nmask -= (1 << (g[i][j] - 1)); } dp[mask] = min(dp[mask], dp[nmask] + cost[i]); } } if (dp[(1 << n) - 1] == inf) cout << -1 << endl; else cout << dp[(1 << n) - 1] << endl; return 0; }
replace
36
38
36
38
0
p02901
C++
Runtime Error
/* Author : Aaryan Srivastava ^__^ */ #include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <random> #define pb push_back #define popb pop_back #define mt make_tuple #define eb emplace_back #define mp make_pair #define ff first #define ss second #define ull unsigned long long #define pii pair<int, int> #define piii pair<int, pii> #define beg begin #define rep(i, n) for (int(i) = 0; i < (n); i++) #define repA(i, x, y) for (int i = (x); i <= (y); i++) #define repD(i, x, y) for (int i = (x); i >= (y); i--) #define all(c) (c).begin(), (c).end() #define fill(a, val) memset(a, val, sizeof(a)) #define Randomize \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define int ll using ll = long long; const int N = 3 * 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e18; const int SZ = 101; const double eps = 1e-9; using namespace __gnu_pbds; using namespace std; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; #ifdef AaryanS #define mycout cout #define mycerr cerr #endif #ifndef AaryanS #define mycout \ if (false) \ cout #define mycerr \ if (false) \ cerr #endif int dp[(1 << 20) + 5]; void solve() { int n, m; cin >> n >> m; int a[n], b[n], c[n]; rep(i, m) { cin >> a[i] >> b[i]; int tmp = 0; rep(j, b[i]) { int x; cin >> x; x--; tmp += (1LL << x); } c[i] = tmp; } rep(msk, (1 << n)) dp[msk] = inf; dp[0] = 0; rep(msk, (1 << n)) { rep(i, m) { if ((msk | c[i]) == msk) continue; // no use; dp[msk | c[i]] = min(dp[msk] + a[i], dp[msk | c[i]]); } } // rep(msk,(1<<n)) cout << msk << " " << (dp[msk] == inf ? -1 : dp[msk]) << // endl; cout << (dp[(1 << n) - 1] == inf ? -1 : dp[(1 << n) - 1]); } int32_t main(int32_t argc, char *argv[]) { double t1 = clock(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC = 1, t = 0; // cin >> TC ; while (t++ < TC) { // cout << "Case #" << t << ": " ; solve(); // cout << endl ; } mycerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n"; return 0; }
/* Author : Aaryan Srivastava ^__^ */ #include <bits/stdc++.h> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <random> #define pb push_back #define popb pop_back #define mt make_tuple #define eb emplace_back #define mp make_pair #define ff first #define ss second #define ull unsigned long long #define pii pair<int, int> #define piii pair<int, pii> #define beg begin #define rep(i, n) for (int(i) = 0; i < (n); i++) #define repA(i, x, y) for (int i = (x); i <= (y); i++) #define repD(i, x, y) for (int i = (x); i >= (y); i--) #define all(c) (c).begin(), (c).end() #define fill(a, val) memset(a, val, sizeof(a)) #define Randomize \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define int ll using ll = long long; const int N = 3 * 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e18; const int SZ = 101; const double eps = 1e-9; using namespace __gnu_pbds; using namespace std; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; #ifdef AaryanS #define mycout cout #define mycerr cerr #endif #ifndef AaryanS #define mycout \ if (false) \ cout #define mycerr \ if (false) \ cerr #endif int dp[(1 << 20) + 5]; void solve() { int n, m; cin >> n >> m; int a[m], b[m], c[m]; rep(i, m) { cin >> a[i] >> b[i]; int tmp = 0; rep(j, b[i]) { int x; cin >> x; x--; tmp += (1LL << x); } c[i] = tmp; } rep(msk, (1 << n)) dp[msk] = inf; dp[0] = 0; rep(msk, (1 << n)) { rep(i, m) { if ((msk | c[i]) == msk) continue; // no use; dp[msk | c[i]] = min(dp[msk] + a[i], dp[msk | c[i]]); } } // rep(msk,(1<<n)) cout << msk << " " << (dp[msk] == inf ? -1 : dp[msk]) << // endl; cout << (dp[(1 << n) - 1] == inf ? -1 : dp[(1 << n) - 1]); } int32_t main(int32_t argc, char *argv[]) { double t1 = clock(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC = 1, t = 0; // cin >> TC ; while (t++ < TC) { // cout << "Case #" << t << ": " ; solve(); // cout << endl ; } mycerr << "Time : " << 1000 * (clock() - t1) / CLOCKS_PER_SEC << " ms\n"; return 0; }
replace
55
56
55
56
0
p02901
C++
Runtime Error
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // repetition #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (int)(n); i++) // container util #define all(x) (x).begin(), (x).end() // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // typedef typedef long long lint; typedef unsigned long long ull; typedef complex<long double> Complex; typedef pair<int, int> P; typedef tuple<int, int, int> TP; typedef vector<int> vec; typedef vector<vec> mat; // constant const int MOD = (int)1e9 + 7; const int INF = (int)1e18; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1}; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // 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; } // int N, M; lint a[110], b[110], c[110][20]; lint dp[1 << 12]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; rep(i, M) { cin >> a[i] >> b[i]; rep(j, b[i]) { cin >> c[i][j]; c[i][j]--; } } for (int i = 0; i < 1 << N; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < M; i++) { int now = 0; for (int j = 0; j < b[i]; j++) { now |= (1 << (c[i][j])); } for (int bit = 0; bit < 1 << N; bit++) { chmin(dp[bit | now], dp[bit] + a[i]); } } if (dp[(1 << N) - 1] == INF) dp[(1 << N) - 1] = -1; cout << dp[(1 << N) - 1] << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // repetition #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (int)(n); i++) // container util #define all(x) (x).begin(), (x).end() // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // typedef typedef long long lint; typedef unsigned long long ull; typedef complex<long double> Complex; typedef pair<int, int> P; typedef tuple<int, int, int> TP; typedef vector<int> vec; typedef vector<vec> mat; // constant const int MOD = (int)1e9 + 7; const int INF = (int)1e18; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1}; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // 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; } // int N, M; lint a[1010], b[1010], c[1010][20]; lint dp[1 << 12]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; rep(i, M) { cin >> a[i] >> b[i]; rep(j, b[i]) { cin >> c[i][j]; c[i][j]--; } } for (int i = 0; i < 1 << N; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < M; i++) { int now = 0; for (int j = 0; j < b[i]; j++) { now |= (1 << (c[i][j])); } for (int bit = 0; bit < 1 << N; bit++) { chmin(dp[bit | now], dp[bit] + a[i]); } } if (dp[(1 << N) - 1] == INF) dp[(1 << N) - 1] = -1; cout << dp[(1 << N) - 1] << endl; return 0; }
replace
66
67
66
67
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long MIN(long long x, long long y) { if (x > y) return y; else return x; } int main() { long long INF = 100000000 + 100; // 情報を取り込む int N, M; cin >> N >> M; vector<int> a(M); vector<int> b(M); vector<vector<int>> c(M); for (int i = 0; i < N; i++) { cin >> a[i]; cin >> b[i]; for (int j = 0; j < b[i]; j++) { int p; cin >> p; c[i].push_back(p - 1); } } // dp vector<vector<long long>> dp(M + 1, vector<long long>((1 << N))); // 0個のカギで開けることができる箱は存在しない for (long long bit = 1; bit < (1 << N); bit++) { dp[0][bit] = INF; } // 漸化式部分 for (int i = 0; i < M; i++) { for (long long bit = 0; bit < (1 << N); bit++) { long long BIT = bit; for (int j = 0; j < b[i]; j++) { BIT &= ~(1 << c[i][j]); } dp[i + 1][bit] = MIN(dp[i][bit], dp[i][BIT] + a[i]); } } // 出力 if (dp[M][(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[M][(1 << N) - 1] << endl; }
#include <bits/stdc++.h> using namespace std; long long MIN(long long x, long long y) { if (x > y) return y; else return x; } int main() { long long INF = 100000000 + 100; // 情報を取り込む int N, M; cin >> N >> M; vector<int> a(M); vector<int> b(M); vector<vector<int>> c(M); for (int i = 0; i < M; i++) { cin >> a[i]; cin >> b[i]; for (int j = 0; j < b[i]; j++) { int p; cin >> p; c[i].push_back(p - 1); } } // dp vector<vector<long long>> dp(M + 1, vector<long long>((1 << N))); // 0個のカギで開けることができる箱は存在しない for (long long bit = 1; bit < (1 << N); bit++) { dp[0][bit] = INF; } // 漸化式部分 for (int i = 0; i < M; i++) { for (long long bit = 0; bit < (1 << N); bit++) { long long BIT = bit; for (int j = 0; j < b[i]; j++) { BIT &= ~(1 << c[i][j]); } dp[i + 1][bit] = MIN(dp[i][bit], dp[i][BIT] + a[i]); } } // 出力 if (dp[M][(1 << N) - 1] == INF) cout << -1 << endl; else cout << dp[M][(1 << N) - 1] << endl; }
replace
23
24
23
24
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(), x.end() #define pb(x) push_back(x) #define INF 1000000000000000000 #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define x first #define y second const int maxx = 1000006; const int maxlog = 20; const ll mod = 1000000007; int arr[maxx]; int main() { IOS int N, M; cin >> N >> M; int arr[M]; int brr[M]; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; arr[i] = a; for (int j = 0; j < b; j++) { int e; cin >> e; e--; brr[i] |= (1 << e); } } int dp[(1 << N) + 2]; for (int i = 0; i < (1 << N); i++) dp[i] = mod; dp[0] = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < (1 << N); j++) { dp[j | brr[i]] = min(dp[j | brr[i]], dp[j] + arr[i]); } } cout << (dp[(1 << N) - 1] == mod ? -1 : dp[(1 << N) - 1]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(), x.end() #define pb(x) push_back(x) #define INF 1000000000000000000 #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define x first #define y second const int maxx = 1000006; const int maxlog = 20; const ll mod = 1000000007; int arr[maxx]; int main() { IOS int N, M; cin >> N >> M; int arr[M]; int brr[M]; for (int i = 0; i < M; i++) brr[i] = 0; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; arr[i] = a; for (int j = 0; j < b; j++) { int e; cin >> e; e--; brr[i] |= (1 << e); } } int dp[(1 << N) + 2]; for (int i = 0; i < (1 << N); i++) dp[i] = mod; dp[0] = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < (1 << N); j++) { dp[j | brr[i]] = min(dp[j | brr[i]], dp[j] + arr[i]); } } cout << (dp[(1 << N) - 1] == mod ? -1 : dp[(1 << N) - 1]); }
insert
23
23
23
25
-11
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e18; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> a(M), T(M); for (int i = 0; i < M; i++) { int k; cin >> a[i] >> k; while (k--) { int c; cin >> c; c--; T[i] |= 1 << c; } } vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF)); dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int S = 0; S < (1 << N); S++) { chmin(dp[i + 1][S], dp[i][S]); chmin(dp[i + 1][S | T[i]], dp[i][S] + a[i]); } } int ans = dp[N][(1 << N) - 1]; cout << (ans == INF ? -1 : ans) << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e18; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> a(M), T(M); for (int i = 0; i < M; i++) { int k; cin >> a[i] >> k; while (k--) { int c; cin >> c; c--; T[i] |= 1 << c; } } vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF)); dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int S = 0; S < (1 << N); S++) { chmin(dp[i + 1][S], dp[i][S]); chmin(dp[i + 1][S | T[i]], dp[i][S] + a[i]); } } int ans = dp[M][(1 << N) - 1]; cout << (ans == INF ? -1 : ans) << endl; return 0; }
replace
46
47
46
47
0
p02901
C++
Runtime Error
#include <bits/stdc++.h> #define fio ios_base::sync_with_stdio(false) #define pdl cout << "*" << endl #define MOD 1000000007 #define INF 1000000000 #define INFLL 1000000000000000000ll #define ff first #define ss second #define long int64_t using namespace std; typedef pair<int, int> pii; typedef pair<long, long> pll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<> dis(0, INF << 1); #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int N = 12; const int M = 1001; int km[M], a[N], n, m; int dp[M][1 << N]; int solve(int i, int mask) { if ((1 << n) == mask + 1) return 0; if (i == m) return INF; if (dp[i][mask] != -1) return dp[i][mask]; int ret = INF; ret = min(ret, a[i] + solve(i + 1, mask | km[i])); ret = min(ret, solve(i + 1, mask)); return dp[i][mask] = ret; } int main() { fio; memset(dp, -1, sizeof dp); cin >> n >> m; for (int i = 0; i < m; i++) { int b, mask = 0; cin >> a[i] >> b; for (int j = 0; j < b; j++) { int x; cin >> x; mask |= (1 << x - 1); } km[i] = mask; } int ans = solve(0, 0); if (ans >= INF) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fio ios_base::sync_with_stdio(false) #define pdl cout << "*" << endl #define MOD 1000000007 #define INF 1000000000 #define INFLL 1000000000000000000ll #define ff first #define ss second #define long int64_t using namespace std; typedef pair<int, int> pii; typedef pair<long, long> pll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<> dis(0, INF << 1); #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int N = 12; const int M = 1001; int km[M], a[M], n, m; int dp[M][1 << N]; int solve(int i, int mask) { if ((1 << n) == mask + 1) return 0; if (i == m) return INF; if (dp[i][mask] != -1) return dp[i][mask]; int ret = INF; ret = min(ret, a[i] + solve(i + 1, mask | km[i])); ret = min(ret, solve(i + 1, mask)); return dp[i][mask] = ret; } int main() { fio; memset(dp, -1, sizeof dp); cin >> n >> m; for (int i = 0; i < m; i++) { int b, mask = 0; cin >> a[i] >> b; for (int j = 0; j < b; j++) { int x; cin >> x; mask |= (1 << x - 1); } km[i] = mask; } int ans = solve(0, 0); if (ans >= INF) ans = -1; cout << ans << endl; return 0; }
replace
28
29
28
29
0