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
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t a = 100; int64_t x; cin >> x; int count = 0; while (a < x) { a = a * 101 / 100; count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t a = 100; int64_t x; cin >> x; int count = 0; while (a < x) { a += a / 100; count++; } cout << count << endl; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; int t = 100; int count = 0; cin >> n; while (n > t) { count++; t *= 1.01; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { uint64_t n; uint64_t t = 100; uint64_t count = 0; cin >> n; while (n > t) { count++; t *= 1.01; } cout << count << endl; }
replace
4
7
4
7
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long X; cin >> X; long long a = 100; for (long long i = 0; i < X; i++) { a = a * 101 / 100; if (a >= X) { cout << i + 1 << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; int main() { long long X; cin >> X; long long a = 100; for (int i = 0; i < 100000; i++) { a = a + a / 100; if (a >= X) { cout << i + 1 << endl; return 0; } } }
replace
7
9
7
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long int #define F first #define S second const ll mod = 1e9 + 7; const ll INF = 10000000000000; #define pb push_back #define deb(x) cout << '>' << #x << ':' << x << endl; #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); using namespace std; int main() { fastio; ll n = 0; cin >> n; ll sum = 100; ll c = 0; while (sum < n) { sum = sum * 101; sum = sum / 100; ++c; } cout << c; return 0; }
#include <bits/stdc++.h> #define ll long long int #define F first #define S second const ll mod = 1e9 + 7; const ll INF = 10000000000000; #define pb push_back #define deb(x) cout << '>' << #x << ':' << x << endl; #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); using namespace std; int main() { fastio; ll n = 0; cin >> n; ll sum = 100; ll c = 0; while (sum < n) { ll i = sum / 100; sum += i; ++c; } cout << c; return 0; }
replace
19
21
19
21
TLE
p02694
C++
Time Limit Exceeded
#include <cstdio> int main() { long int x; scanf("%ld", &x); long int moto = 100; long int ans = 0; while (moto < x) { ans++; moto = moto * 101 / 100; } printf("%ld", ans); return 0; }
#include <cstdio> int main() { long int x; scanf("%ld", &x); long int moto = 100; long int ans = 0; while (moto < x) { ans++; double motof = (double)moto; moto = (long int)motof * 1.01; } printf("%ld", ans); return 0; }
replace
9
10
9
11
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll x; cin >> x; ll w = 100; ll cnt = 0; while (w < x) { cnt++; w = w * 101; w = w / 100; // cout << w << endl; } cout << cnt << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll x; cin >> x; ll w = 100; ll cnt = 0; while (w < x) { cnt++; w += w / 100; // cout << w << endl; } cout << cnt << "\n"; return 0; }
replace
12
14
12
13
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; long long p = 100LL; long long num = 0LL; while (p < x) { num++; p *= 101; p /= 100; } cout << num; }
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; long long p = 100LL; long long num = 0LL; while (p < x) { num++; p += p / 100; } cout << num; }
replace
9
11
9
10
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long s = 100, x = 0; do { s = s * 1.01 / 1; x++; } while (s != n); cout << x; }
#include <bits/stdc++.h> using namespace std; int main() { long long X; cin >> X; long long F = 100; long long year = 0; while (F < X) { year++; F = F * 1.01 / 1; } cout << year; }
replace
3
11
3
12
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long s; int t = 100; int c = 0; cin >> s; while (t < s) { t += t / 100; c++; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long s; long t = 100; long c = 0; cin >> s; while (t < s) { t += t / 100; c++; } cout << c << endl; return 0; }
replace
5
7
5
7
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long #define f first #define s second using namespace std; const int inf = 1e18; int32_t main() { ios::sync_with_stdio(0), cin.tie(0); int x, p = 100, c = 0; cin >> x; while (p < x) { p = (p * 101) / 100; c++; } cout << c; }
#include <bits/stdc++.h> #define int long long #define f first #define s second using namespace std; const int inf = 1e18; int32_t main() { ios::sync_with_stdio(0), cin.tie(0); int x, p = 100, c = 0; cin >> x; while (p < x) { p += p / 100; c++; } cout << c; }
replace
11
12
11
12
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int x, num = 100, h = 0; cin >> x; while (x > num) { num += num / 100; h++; } cout << h << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long x, num = 100, h = 0; cin >> x; while (x > num) { num += num / 100; h++; } cout << h << endl; }
replace
4
5
4
5
TLE
p02694
C++
Time Limit Exceeded
// #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") // #pragma GCC target("avx,avx2,fma") #include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> constexpr auto INF = 9223372036854775807; typedef long long int ll; typedef unsigned long long int ull; typedef unsigned long int ul; #define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1) #define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1) #define endl '\n' #define N 1000000007 // prime modulo value #define C 1000000001 #define M 998244353 #define all(x) x.begin(), x.end() using namespace std; // From Geeksforgeeks inline ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // Power function took from geeksforgeeks ll power(ll x, ll y) { ll res = 1; x = x; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } double dist(ll x1, ll y1, ll x2, ll y2) { double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); return ans; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ll x, a = 0; cin >> x; ll ans = 100, count = 0; while (ans != x) { ans += (ans / 100); count += 1; } cout << count; return 0; }
// #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") // #pragma GCC target("avx,avx2,fma") #include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> constexpr auto INF = 9223372036854775807; typedef long long int ll; typedef unsigned long long int ull; typedef unsigned long int ul; #define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1) #define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1) #define endl '\n' #define N 1000000007 // prime modulo value #define C 1000000001 #define M 998244353 #define all(x) x.begin(), x.end() using namespace std; // From Geeksforgeeks inline ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // Power function took from geeksforgeeks ll power(ll x, ll y) { ll res = 1; x = x; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } double dist(ll x1, ll y1, ll x2, ll y2) { double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); return ans; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ll x, a = 0; cin >> x; ll ans = 100, count = 0; while (1) { if (ans >= x) break; ans += (ans / 100); count += 1; } cout << count; return 0; }
replace
60
61
60
63
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t x; cin >> x; int h = 100; int ans = 0; while (h < x) { h *= 1.01; ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t x; cin >> x; int64_t h = 100; int64_t ans = 0; while (h < x) { h *= 1.01; ans++; } cout << ans << endl; }
replace
7
9
7
9
TLE
p02694
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { long long X, n = 0; int yen = 100; cin >> X; while (++n) { yen = yen + yen * 0.01; if (yen >= X) break; } cout << n << endl; // cout << round(log((double) X/100) / log(1.01)) << endl; }
#include <cmath> #include <iostream> using namespace std; int main() { long long X, n = 0; long long yen = 100; cin >> X; while (++n) { yen = yen + yen * 0.01; if (yen >= X) break; } cout << n << endl; // cout << round(log((double) X/100) / log(1.01)) << endl; }
replace
6
7
6
7
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll x; cin >> x; int a = 100; int ans = 0; while (a < x) { a *= 1.01; ans++; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main() { ll x; cin >> x; ll a = 100; int ans = 0; while (a < x) { a *= 1.01; ans++; } cout << ans << endl; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll r = 0; ll x; cin >> x; ll i = 100; while (i < x) { i = i * 101 / 100; r++; } cout << r; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll r = 0; ll x; cin >> x; ll i = 100; while (i < x) { i = i + i / 100; r++; } cout << r; return 0; }
replace
10
11
10
11
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll X; cin >> X; ll sum = 100; ll n = 0; while (sum < X) { sum = sum * 101 / 100; n++; } cout << n << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll X; cin >> X; ll sum = 100; ll n = 0; while (sum < X) { sum = sum + sum / 100; n++; } cout << n << endl; }
replace
12
13
12
13
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, as = 100; cin >> n; for (int64_t i = 1;; i++) { as += (int)as * 0.01; if (as >= n) { cout << i << endl; break; } } }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, as = 100; cin >> n; for (int64_t i = 1;; i++) { as += (int64_t)as * 1 / 100; if (as >= n) { cout << i << endl; break; } } }
replace
6
7
6
7
TLE
p02694
C++
Time Limit Exceeded
#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>; int main() { ll x; cin >> x; ll ans = 0; ll yen = 100; while (1) { if (yen >= x) break; yen *= 101; yen /= 100; ans++; } cout << ans << endl; }
#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>; int main() { ll x; cin >> x; ll ans = 0; ll yen = 100; while (1) { if (yen >= x) break; yen += yen / 100; ans++; } cout << ans << endl; }
replace
15
17
15
16
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long X; cin >> X; long long a = 0; long long i = 100; while (i < X) { i = i + int(i * 0.01); a += 1; } cout << a << endl; }
#include <iostream> using namespace std; int main() { long long X; cin >> X; long long a = 0; long long i = 100; while (i < X) { i *= 1.01; a += 1; } cout << a << endl; }
replace
10
11
10
11
TLE
p02694
C++
Time Limit Exceeded
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //------------------------------- Type Names -------------------------------// using i64 = int_fast64_t; using seika = string; //{akari : 1D, yukari : 2D, maki : 3D} vector template <class kizuna> using akari = vector<kizuna>; template <class yuzuki> using yukari = akari<akari<yuzuki>>; template <class tsurumaki> using maki = akari<yukari<tsurumaki>>; //{akane : ascending order, aoi : decending order} priority queue template <class kotonoha> using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>; template <class kotonoha> using aoi = priority_queue<kotonoha>; //------------------------------- Libraries ---------------------------------// //------------------------------- Dubug Functions ---------------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &...rest) { cout << first << ' '; print(rest...); } //------------------------------- Solver ------------------------------------// void solve() { i64 x; cin >> x; i64 c = 100; for (int i = 1;; i++) { c = c * 101 / 100; if (c >= x) { cout << i << endl; return; } } } int main() { solve(); return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; //------------------------------- Type Names -------------------------------// using i64 = int_fast64_t; using seika = string; //{akari : 1D, yukari : 2D, maki : 3D} vector template <class kizuna> using akari = vector<kizuna>; template <class yuzuki> using yukari = akari<akari<yuzuki>>; template <class tsurumaki> using maki = akari<yukari<tsurumaki>>; //{akane : ascending order, aoi : decending order} priority queue template <class kotonoha> using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>; template <class kotonoha> using aoi = priority_queue<kotonoha>; //------------------------------- Libraries ---------------------------------// //------------------------------- Dubug Functions ---------------------------// inline void print() { cout << endl; } template <typename First, typename... Rest> void print(const First &first, const Rest &...rest) { cout << first << ' '; print(rest...); } //------------------------------- Solver ------------------------------------// void solve() { i64 x; cin >> x; i64 c = 100; for (int i = 1;; i++) { c = c * 1.01; if (c >= x) { cout << i << endl; return; } } } int main() { solve(); return 0; }
replace
37
38
37
38
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long x; cin >> x; long long m = 100; int i; for (i = 0; m < x; i++) { m = m * 101 / 100; } cout << i << endl; }
#include <iostream> using namespace std; int main() { long long x; cin >> x; long long m = 100; int i; for (i = 0; m < x; i++) { m = m + m / 100; } cout << i << endl; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long x; cin >> x; long long money = 100; int i; for (i = 0; money < x; i++) { money = money * 101 / 100; } cout << i << endl; }
#include <iostream> using namespace std; int main() { long long x; cin >> x; long long money = 100; int i; for (i = 0; money < x; i++) { money = money + money / 100; } cout << i << endl; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, cc, n) for (int i = cc; i < n; ++i) #define lrep(i, cc, n) for (long i = cc; i < n; ++i) #define rrep(i, cc, n) for (long i = cc; i > n; --i) int main() { long X; cin >> X; long a = 100; long ans = 0; while (a < X) { a = (a * 101) / 100; ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, cc, n) for (int i = cc; i < n; ++i) #define lrep(i, cc, n) for (long i = cc; i < n; ++i) #define rrep(i, cc, n) for (long i = cc; i > n; --i) int main() { long X; cin >> X; long a = 100; long ans = 0; while (a < X) { a += a / 100; ans++; } cout << ans << endl; }
replace
12
13
12
13
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <cstdio> #include <fstream> using namespace std; // vector<pair<int,int> > v; // cin.ignore();//twice getline(cin,s); // g++ iterator.cpp -std=c++17 // cout<<(A + B == C ? "YES" : "NO")<<endl; // __gcd(a,b) // string s=to_string(i); // sort(arr, arr+n, greater<int>()); // const long double pi = acos(-1.0); #define ff first #define ss second #define pb push_back #define mk make_pair #define vll vector<ll> #define mll map<ll, ll> #define mlli map<ll, ll>::iterator #define size size() #define endl "\n" #define ll long long int #define ld long double void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main(void) { fast(); ll x; cin >> x; ll c = 0; ll an = 100; while (1) { if (an < x) { an = an + (an * double(1 / 100)); c++; } else { break; } } cout << c << endl; return 0; }
#include <bits/stdc++.h> #include <cstdio> #include <fstream> using namespace std; // vector<pair<int,int> > v; // cin.ignore();//twice getline(cin,s); // g++ iterator.cpp -std=c++17 // cout<<(A + B == C ? "YES" : "NO")<<endl; // __gcd(a,b) // string s=to_string(i); // sort(arr, arr+n, greater<int>()); // const long double pi = acos(-1.0); #define ff first #define ss second #define pb push_back #define mk make_pair #define vll vector<ll> #define mll map<ll, ll> #define mlli map<ll, ll>::iterator #define size size() #define endl "\n" #define ll long long int #define ld long double void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main(void) { fast(); ll x; cin >> x; ll c = 0; ll an = 100; while (1) { if (an < x) { // an=an+(an*0.01); an = an + (an * double(double(1) / double(100))); c++; } else { break; } } cout << c << endl; return 0; }
replace
37
38
37
39
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int x, year = 0, i = 100; cin >> x; while (i < x) { i = i * 1.01; year++; } cout << year << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long X; cin >> X; long long i = 100, year = 0; while (i < X) { i = i * 1.01; year++; } cout << year << endl; }
replace
3
6
3
7
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long x, i, tt = 0; cin >> x; while (i < x) { i += i / 100; tt++; } cout << tt; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long x, i = 100, tt = 0; cin >> x; while (i < x) { i += i / 100; tt++; } cout << tt; return 0; }
replace
3
4
3
4
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t X; cin >> X; int i = 0; int money = 100; while (true) { i++; money *= 1.01; if (money >= X) break; } cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t X; cin >> X; int i = 0; int64_t money = 100; while (true) { i++; money *= 1.01; if (money >= X) break; } cout << i << endl; return 0; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll x; cin >> x; ll val = 100; int i; for (i = 0; val < x; i++) val = (int)(val * 1.01); cout << i << endl; return 0; }
#include <bits/stdc++.h> #define ll long long int using namespace std; int main() { ll x; cin >> x; ll val = 100; int i; for (i = 0; val < x; i++) val = (ll)(val * 1.01); cout << i << endl; return 0; }
replace
9
10
9
10
TLE
p02694
C++
Time Limit Exceeded
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll using vi = vector<int>; using vvi = vector<vi>; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(x) (x).begin(), (x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) 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 <class T> ostream &operator<<(ostream &out, vector<T> const &v) { for (auto &&a : v) out << a << " "; out << endl; return out; } // debug methods // usage: debug(x,y); #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << endl #define debug_4(x1, x2, x3, x4) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #ifdef _DEBUG #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #else #define debug(...) #endif #pragma endregion void Main() { int N; cin >> N; int a = 100; int count = 0; while (a < N) { a *= a / 100; count++; } cout << count; } #pragma region main signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); Main(); cout << flush; } #pragma endregion
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll using vi = vector<int>; using vvi = vector<vi>; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(x) (x).begin(), (x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) 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 <class T> ostream &operator<<(ostream &out, vector<T> const &v) { for (auto &&a : v) out << a << " "; out << endl; return out; } // debug methods // usage: debug(x,y); #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x #define debug_1(x1) cout << #x1 << ": " << x1 << endl #define debug_2(x1, x2) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl #define debug_3(x1, x2, x3) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << endl #define debug_4(x1, x2, x3, x4) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << endl #define debug_5(x1, x2, x3, x4, x5) \ cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \ << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl #ifdef _DEBUG #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #else #define debug(...) #endif #pragma endregion void Main() { int N; cin >> N; int a = 100; int count = 0; while (a < N) { a += a / 100; count++; } cout << count; } #pragma region main signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); Main(); cout << flush; } #pragma endregion
replace
70
71
70
71
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array ll solve() { ll t = 0, a = 0, x; cin >> x; while (a < x) { a += a / 100; t++; } cout << t << endl; return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array ll solve() { ll t = 0, a = 100, x; cin >> x; while (a < x) { a += a / 100; t++; } cout << t << endl; return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
replace
7
8
7
8
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int x; cin >> x; int d = 100; int cnt = 0; while (d < x) { d = d + d * 0.01; cnt++; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int x; cin >> x; long long int d = 100; long long int cnt = 0; while (d < x) { d = d + d * 0.01; cnt++; } cout << cnt << endl; }
replace
5
7
5
7
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit) #define ll long long using namespace std; int main() { ll X; cin >> X; ll money = 100; ll time = 0; while (money < X) { money = int(money * 1.01); time++; } cout << time << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit) #define ll long long using namespace std; int main() { ll X; cin >> X; ll money = 100; ll time = 0; while (money < X) { money = money * 1.01; time++; } cout << time << endl; }
replace
13
14
13
14
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x, cnt = 0; int total = 100; cin >> x; while (total < x) { total += total / 100; cnt++; } cout << cnt << endl; return 0; }
#include <iostream> using namespace std; int main() { int cnt = 0; long long total = 100; long long x; cin >> x; while (total < x) { total += total / 100; cnt++; } cout << cnt << endl; return 0; }
replace
4
6
4
7
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x, res = 0, curr = 100; cin >> x; while (curr < x) { res++; curr += curr * 0.01; } cout << res << endl; return 0; }
#include <iostream> using namespace std; int main() { long long x, res = 0, curr = 100; cin >> x; while (curr < x) { res++; curr += curr * 0.01; } cout << res << endl; return 0; }
replace
6
7
6
7
TLE
p02694
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int func(int a, int b, int cnt) { if (a >= b) { return cnt; } func(a + a * 0.01, b, cnt + 1); } signed main() { int x; cin >> x; cout << func(100, x, 0) << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int func(int a, int b, int cnt) { if (a >= b) { return cnt; } return func(a + a * 0.01, b, cnt + 1); } signed main() { int x; cin >> x; cout << func(100, x, 0) << endl; }
replace
7
8
7
8
0
p02694
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define int long long #define _CRT_SECURE_NO_WARNINGS #define rep(i, n) for (int i = 0; i < n; i++) #define _GLIBCXX_DEBUG const int MOD = 1e9 + 7; const int INF = 1e18 + 9; constexpr long double pi = 3.141592653589793238462643383279; // 円周率 /*---------------------便利な関数--------------------------------------*/ int fact(int i) { // 階乗 if (i == 0) return 1; return (fact(i - 1)) * i; } int gcd(int a, int b) { // 最大公約数 if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { // 最小公倍数 return a * b / gcd(a, b); } int keta(int n) { // 桁数を求める if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } int ketasum(int n) { // 各桁の和 int sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } /*-------------ここまで---------------------------------------------*/ // C++(GCC9.2.1) signed main() { // 宣言 int x; cin >> x; bool flag = true; int sum = 100, count = 0; while (flag) { sum *= sum / 100; ++count; if (sum >= x) { flag = false; } } cout << count << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define int long long #define _CRT_SECURE_NO_WARNINGS #define rep(i, n) for (int i = 0; i < n; i++) #define _GLIBCXX_DEBUG const int MOD = 1e9 + 7; const int INF = 1e18 + 9; constexpr long double pi = 3.141592653589793238462643383279; // 円周率 /*---------------------便利な関数--------------------------------------*/ int fact(int i) { // 階乗 if (i == 0) return 1; return (fact(i - 1)) * i; } int gcd(int a, int b) { // 最大公約数 if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { // 最小公倍数 return a * b / gcd(a, b); } int keta(int n) { // 桁数を求める if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } int ketasum(int n) { // 各桁の和 int sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } /*-------------ここまで---------------------------------------------*/ // C++(GCC9.2.1) signed main() { // 宣言 int x; cin >> x; bool flag = true; int sum = 100, count = 0; while (flag) { sum += sum / 100; ++count; if (sum >= x) { flag = false; } } cout << count << endl; }
replace
89
90
89
90
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n = 100; int x; int count = 0; cin >> x; while (n < x) { count += 1; n += n / 100; } cout << count << '\n'; return 0; }
#include <iostream> using namespace std; int main() { long long int n = 100; long long int x; int count = 0; cin >> x; while (n < x) { count += 1; n += n / 100; } cout << count << '\n'; return 0; }
replace
4
6
4
6
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int32_t main() { FIO; int cur = 100; int x; cin >> x; int yr = 0; while (cur < x) cur = (101 * cur) / 100, yr++; cout << yr << '\n'; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int32_t main() { FIO; int cur = 100; int x; cin >> x; int yr = 0; while (cur < x) { cur = cur + cur / 100; yr++; } cout << yr << '\n'; return 0; }
replace
41
43
41
45
TLE
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int N, M, Q; vector<int> a, b, c, d; long long ans; long long res, res2; vector<int> num; long long dfs(int i, int u) { long long t2 = 0; if (u == N) { long long t = 0; for (int j = 0; j < Q; j++) { if (num[b[j] - 1] - num[a[j] - 1] == c[j]) t += d[j]; } return t; } num[u] = i; for (int j = 0; j + i <= M; j++) { t2 = max(t2, dfs(i + j, u + 1)); } return t2; } int main() { cin >> N >> M >> Q; a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q); for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } ans = 0; for (int i = 1; i <= M; i++) { ans = max(ans, dfs(i, 0)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int N, M, Q; vector<int> a, b, c, d; long long ans; long long res, res2; vector<int> num; long long dfs(int i, int u) { long long t2 = 0; if (u == N) { long long t = 0; for (int j = 0; j < Q; j++) { if (num[b[j] - 1] - num[a[j] - 1] == c[j]) t += d[j]; } return t; } num[u] = i; for (int j = 0; j + i <= M; j++) { t2 = max(t2, dfs(i + j, u + 1)); } return t2; } int main() { cin >> N >> M >> Q; a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q); for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } ans = 0; num.resize(N); for (int i = 1; i <= M; i++) { ans = max(ans, dfs(i, 0)); } cout << ans << endl; }
insert
34
34
34
35
-11
p02695
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, q; vector<int> a, b, c, d, A; int saiki(int k, int l, int p, vector<int> A); int main() { int as; // cerr << "test"; cin >> n >> m >> q; for (int i = 0; i < q; i++) { int e, f, g, h; cin >> e >> f >> g >> h; a.push_back(e); b.push_back(f); c.push_back(g); d.push_back(h); } // cerr << "test"; as = saiki(n, m, q, A); cout << as << endl; } int saiki(int k, int l, int p, vector<int> A) { int ans = 0; vector<int> B = A; // cerr << k << l << p <<endl; if (k != 0) { for (int i = 1; i <= l; i++) { B.push_back(i); ans = max(ans, saiki(k - 1, i, p, B)); B.pop_back(); } return ans; } else { for (int i = 0; i < p; i++) { for (int j = 0; j < A.size(); j++) cerr << A[j]; cerr << endl; if (A.at(A.size() - b.at(i)) - A.at(A.size() - a.at(i)) == c.at(i)) ans += d.at(i); } return ans; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, q; vector<int> a, b, c, d, A; int saiki(int k, int l, int p, vector<int> A); int main() { int as; // cerr << "test"; cin >> n >> m >> q; for (int i = 0; i < q; i++) { int e, f, g, h; cin >> e >> f >> g >> h; a.push_back(e); b.push_back(f); c.push_back(g); d.push_back(h); } // cerr << "test"; as = saiki(n, m, q, A); cout << as << endl; } int saiki(int k, int l, int p, vector<int> A) { int ans = 0; vector<int> B = A; // cerr << k << l << p <<endl; if (k != 0) { for (int i = 1; i <= l; i++) { B.push_back(i); ans = max(ans, saiki(k - 1, i, p, B)); B.pop_back(); } return ans; } else { for (int i = 0; i < p; i++) { // for(int j=0;j<A.size();j++)cerr << A[j]; // cerr << endl; if (A.at(A.size() - b.at(i)) - A.at(A.size() - a.at(i)) == c.at(i)) ans += d.at(i); } return ans; } }
replace
37
40
37
39
TLE
p02695
C++
Runtime Error
#include <iostream> #include <stdio.h> // #include <bits/stdc++.h> #include <algorithm> #include <cassert> #include <cmath> #include <cmath> #include <cstdint> #include <cstring> #include <float.h> #include <iomanip> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define INF 1e9 #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++) #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define vec(type, n) vector<type>(n) #define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n)) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using Graph = vector<vector<int>>; using P = pair<ll, ll>; int n, m, q; vector<int> a(20), b(20), c(20), d(20), A(20); int res = 0; void dfs(int dep, int x) { if (dep == n) { int sum = 0; rep(i, q) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i]; } res = max(res, sum); return; } REP(i, x, m) { A[dep] = i; dfs(dep + 1, i); } } int main() { cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(0, 1); cout << res << endl; }
#include <iostream> #include <stdio.h> // #include <bits/stdc++.h> #include <algorithm> #include <cassert> #include <cmath> #include <cmath> #include <cstdint> #include <cstring> #include <float.h> #include <iomanip> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define INF 1e9 #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++) #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define vec(type, n) vector<type>(n) #define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n)) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using Graph = vector<vector<int>>; using P = pair<ll, ll>; int n, m, q; vector<int> a(100), b(100), c(100), d(100), A(20); int res = 0; void dfs(int dep, int x) { if (dep == n) { int sum = 0; rep(i, q) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i]; } res = max(res, sum); return; } REP(i, x, m) { A[dep] = i; dfs(dep + 1, i); } } int main() { cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(0, 1); cout << res << endl; }
replace
36
37
36
37
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N, M, Q; cin >> N >> M >> Q; vec a(N), b(N), c(N), d(N); rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i], --a[i], --b[i]; auto culc_score = [&](vec &v) { ll score = 0; rep(i, Q) if (v[b[i]] - v[a[i]] == c[i]) score += d[i]; return score; }; vec ans{1}; ll res = -1; auto dfs = [&](auto self) -> void { if (ans.size() == N) { chmax(res, culc_score(ans)); return; } for (ll i = ans.back(); i <= M; ++i) { ans.pb(i); self(self); ans.pop_back(); } }; dfs(dfs); print(res); return 0; }
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N, M, Q; cin >> N >> M >> Q; vec a(Q), b(Q), c(Q), d(Q); rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i], --a[i], --b[i]; auto culc_score = [&](vec &v) { ll score = 0; rep(i, Q) if (v[b[i]] - v[a[i]] == c[i]) score += d[i]; return score; }; vec ans{1}; ll res = -1; auto dfs = [&](auto self) -> void { if (ans.size() == N) { chmax(res, culc_score(ans)); return; } for (ll i = ans.back(); i <= M; ++i) { ans.pb(i); self(self); ans.pop_back(); } }; dfs(dfs); print(res); return 0; }
replace
132
133
132
133
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[20], b[20], c[20], d[20]; long long ans = 0; int l[20]; int n, m, q; void dfs(int x, int y) // x当前第几位,这一位是几 { l[x] = y; if (x == n) { long long sum = 0; for (int i = 1; i <= q; i++) if (l[b[i]] - l[a[i]] == c[i]) sum += d[i]; ans = max(ans, sum); return; } else { for (int i = y; i <= m; i++) { dfs(x + 1, i); } } } int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(1, 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[100], b[100], c[100], d[100]; long long ans = 0; int l[20]; int n, m, q; void dfs(int x, int y) // x当前第几位,这一位是几 { l[x] = y; if (x == n) { long long sum = 0; for (int i = 1; i <= q; i++) if (l[b[i]] - l[a[i]] == c[i]) sum += d[i]; ans = max(ans, sum); return; } else { for (int i = y; i <= m; i++) { dfs(x + 1, i); } } } int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(1, 1); cout << ans << endl; return 0; }
replace
4
5
4
5
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define name "" #define ini \ freopen(name ".inp", "r", stdin); \ freopen(name ".out", "w", stdout) #define foe(it, c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++) #define long long long #define db double #define pii pair<int, int> #define pll pair<long, long> #define all(c) c.begin(), c.end() #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {-1, 1, 0, 0}; const int N = 11; int x[N], a[N], b[N], c[N], d[N]; long res = 0; int n, m, Q; void Try(int u) { for (int i = x[u - 1]; i <= m; i++) { x[u] = i; if (u == n) { long cur = 0; for (int j = 1; j <= Q; j++) { if (x[b[j]] - x[a[j]] == c[j]) cur += d[j]; } res = max(res, cur); } else Try(u + 1); } } int main() { fastio; cin >> n >> m >> Q; for (int i = 1; i <= Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } x[0] = 1; Try(1); cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; #define name "" #define ini \ freopen(name ".inp", "r", stdin); \ freopen(name ".out", "w", stdout) #define foe(it, c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++) #define long long long #define db double #define pii pair<int, int> #define pll pair<long, long> #define all(c) c.begin(), c.end() #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {-1, 1, 0, 0}; const int N = 51; int x[N], a[N], b[N], c[N], d[N]; long res = 0; int n, m, Q; void Try(int u) { for (int i = x[u - 1]; i <= m; i++) { x[u] = i; if (u == n) { long cur = 0; for (int j = 1; j <= Q; j++) { if (x[b[j]] - x[a[j]] == c[j]) cur += d[j]; } res = max(res, cur); } else Try(u + 1); } } int main() { fastio; cin >> n >> m >> Q; for (int i = 1; i <= Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } x[0] = 1; Try(1); cout << res; return 0; }
replace
23
24
23
24
0
p02695
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " "); return os; } #ifdef _DEBUG template <class T> void dump(const char *str, T &&h) { cerr << str << " = " << h << "\n"; }; template <class Head, class... Tail> void dump(const char *str, Head &&h, Tail &&...t) { while (*str != ',') cerr << *str++; cerr << " = " << h << "\n"; dump(str + (*(str + 1) == ' ' ? 2 : 1), t...); } #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif template <class T> inline bool chmax(T &a, const T b) { return a < b && (a = b, true); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M, Q; cin >> N >> M >> Q; vector<vector<int>> v(Q, vector<int>(4)); for (int i = 0; i < Q; i++) { cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3]; v[i][0]--, v[i][1]--; } auto dfs = [&](auto &&f, int ind, int now, vector<int> num) -> int { num[ind] = now; if (ind == N) { int sum = 0; for (int i = 0; i < Q; i++) { if (num[v[i][1]] - num[v[i][0]] == v[i][2]) sum += v[i][3]; } return sum; } int res = 0; for (int i = now; i <= M; i++) { chmax(res, f(f, ind + 1, i, num)); } return res; }; int ans = 0; for (int i = 1; i <= M; i++) { chmax(ans, dfs(dfs, 0, i, vector<int>(10))); } cout << ans << "\n"; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " "); return os; } #ifdef _DEBUG template <class T> void dump(const char *str, T &&h) { cerr << str << " = " << h << "\n"; }; template <class Head, class... Tail> void dump(const char *str, Head &&h, Tail &&...t) { while (*str != ',') cerr << *str++; cerr << " = " << h << "\n"; dump(str + (*(str + 1) == ' ' ? 2 : 1), t...); } #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif template <class T> inline bool chmax(T &a, const T b) { return a < b && (a = b, true); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M, Q; cin >> N >> M >> Q; vector<vector<int>> v(Q, vector<int>(4)); for (int i = 0; i < Q; i++) { cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3]; v[i][0]--, v[i][1]--; } auto dfs = [&](auto &&f, int ind, int now, vector<int> num) -> int { num[ind] = now; if (ind == N) { int sum = 0; for (int i = 0; i < Q; i++) { if (num[v[i][1]] - num[v[i][0]] == v[i][2]) sum += v[i][3]; } return sum; } int res = 0; for (int i = now; i <= M; i++) { chmax(res, f(f, ind + 1, i, num)); } return res; }; int ans = 0; for (int i = 1; i <= M; i++) { chmax(ans, dfs(dfs, 0, i, vector<int>(11))); } cout << ans << "\n"; return 0; }
replace
80
81
80
81
0
p02695
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int odp = 0, n, m, q; void rec(vector<int> x, int nr, int co, vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d) { x[nr] = co; if (nr == n) { int wyn = 0; for (int i = 0; i < q; ++i) if (x[b[i]] - x[a[i]] == c[i]) wyn += d[i]; odp = max(odp, wyn); return; } for (int i = co; i <= m; ++i) rec(x, nr + 1, i, a, b, c, d); } int main() { ios_base::sync_with_stdio(0); cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; ++i) { cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i]; --b[i]; } vector<int> x(n); for (int i = 1; i <= m; ++i) rec(x, 0, i, a, b, c, d); cout << odp; return 0; }
#include <iostream> #include <vector> using namespace std; int odp = 0, n, m, q; void rec(vector<int> x, int nr, int co, vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d) { x[nr] = co; if (nr == n - 1) { int wyn = 0; for (int i = 0; i < q; ++i) if (x[b[i]] - x[a[i]] == c[i]) wyn += d[i]; odp = max(odp, wyn); return; } for (int i = co; i <= m; ++i) rec(x, nr + 1, i, a, b, c, d); } int main() { ios_base::sync_with_stdio(0); cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; ++i) { cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i]; --b[i]; } vector<int> x(n); for (int i = 1; i <= m; ++i) rec(x, 0, i, a, b, c, d); cout << odp; return 0; }
replace
10
11
10
11
0
p02695
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int A[15], n, m, q, a[55], b[55], c[55], d[55], ans; int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } for (int i = 1; i <= n; i++) A[i] = 1; // 1 1 1 while (!a[0]) // a[0]=0是标志位 不等于0时说明序列生成结束 { int res = 0; for (int i = 1; i <= q; i++) { if ((A[b[i]] - A[a[i]]) == c[i]) res += d[i]; } ans = max(res, ans); for (int i = n; i >= 0; i--) { if (A[i] < m) { A[i]++; for (int j = i + 1; j <= n; j++) A[j] = A[i]; break; } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int A[15], n, m, q, a[55], b[55], c[55], d[55], ans; int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } for (int i = 1; i <= n; i++) A[i] = 1; // 1 1 1 while (!A[0]) // A[0]=0是标志位 不等于0时说明序列生成结束 { int res = 0; for (int i = 1; i <= q; i++) { if ((A[b[i]] - A[a[i]]) == c[i]) res += d[i]; } ans = max(res, ans); for (int i = n; i >= 0; i--) { if (A[i] < m) { A[i]++; for (int j = i + 1; j <= n; j++) A[j] = A[i]; break; } } } cout << ans; return 0; }
replace
11
12
11
12
TLE
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int recursive(int col, vector<int> &current, int n, int m, int q, vector<vector<int>> &aa, vector<vector<int>> &cc, vector<vector<int>> &dd); int main() { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; ++i) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<vector<int>> aa(m + 1), cc(m + 1), dd(m + 1); for (int i = 0; i < q; ++i) { aa.at(b[i]).push_back(a[i]); cc[b[i]].push_back(c[i]); dd[b[i]].push_back(d[i]); } vector<int> current(n + 1); current[0] = 1; // fprintf(stderr,"prepared completedn"); cout << recursive(1, current, n, m, q, aa, cc, dd) << endl; } int recursive(int col, vector<int> &current, int n, int m, int q, vector<vector<int>> &aa, vector<vector<int>> &cc, vector<vector<int>> &dd) { int score, maxscore; // fprintf(stderr,"col %d, current %d\n",col,current[col-1]); maxscore = 0; for (int i = current[col - 1]; i <= m; ++i) { score = 0; for (int j = 0; j < aa[col].size(); ++j) { if (i - current[aa[col][j]] == cc[col][j]) { score += dd[col][j]; } } current[col] = i; if (col < n) { score += recursive(col + 1, current, n, m, q, aa, cc, dd); } if (score > maxscore) { maxscore = score; } } return maxscore; }
#include <bits/stdc++.h> using namespace std; int recursive(int col, vector<int> &current, int n, int m, int q, vector<vector<int>> &aa, vector<vector<int>> &cc, vector<vector<int>> &dd); int main() { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; ++i) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<vector<int>> aa(n + 1), cc(n + 1), dd(n + 1); for (int i = 0; i < q; ++i) { aa.at(b[i]).push_back(a[i]); cc[b[i]].push_back(c[i]); dd[b[i]].push_back(d[i]); } vector<int> current(n + 1); current[0] = 1; // fprintf(stderr,"prepared completedn"); cout << recursive(1, current, n, m, q, aa, cc, dd) << endl; } int recursive(int col, vector<int> &current, int n, int m, int q, vector<vector<int>> &aa, vector<vector<int>> &cc, vector<vector<int>> &dd) { int score, maxscore; // fprintf(stderr,"col %d, current %d\n",col,current[col-1]); maxscore = 0; for (int i = current[col - 1]; i <= m; ++i) { score = 0; for (int j = 0; j < aa[col].size(); ++j) { if (i - current[aa[col][j]] == cc[col][j]) { score += dd[col][j]; } } current[col] = i; if (col < n) { score += recursive(col + 1, current, n, m, q, aa, cc, dd); } if (score > maxscore) { maxscore = score; } } return maxscore; }
replace
16
17
16
17
0
p02695
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #define rep(i, s, g) for (i = s; i < g; i++) using namespace std; using ll = long long; const int inf = 1000000000; // 10^9 ll N, M, Q; ll ans = 0; vector<int> a, b, c, d; void search(int x, vector<int> A) { if (x == N) { ll cost = 0; for (int i = 0; i < Q; i++) { if (A[b[i]] - A[a[i]] == c[i]) { cost += d[i]; } } ans = max(ans, cost); // max,minは型を揃える return; // 関数が終了する } for (int i = A[x - 1]; i <= M; i++) { A.push_back(i); search(x + 1, A); A.pop_back(); // 一番最後の数字を削除する,次のループに備える } } int main() { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } for (int i = 1; i <= M; i++) { vector<int> A; A.push_back(i); search(1, A); } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #define rep(i, s, g) for (i = s; i < g; i++) using namespace std; using ll = long long; const int inf = 1000000000; // 10^9 ll N, M, Q; ll ans = 0; vector<int> a, b, c, d; void search(int x, vector<int> A) { if (x == N) { ll cost = 0; for (int i = 0; i < Q; i++) { if (A[b[i]] - A[a[i]] == c[i]) { cost += d[i]; } } ans = max(ans, cost); // max,minは型を揃える return; // 関数が終了する } for (int i = A[x - 1]; i <= M; i++) { A.push_back(i); search(x + 1, A); A.pop_back(); // 一番最後の数字を削除する,次のループに備える } } int main() { cin >> N >> M >> Q; a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q); for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } for (int i = 1; i <= M; i++) { vector<int> A; A.push_back(i); search(1, A); } cout << ans << endl; }
insert
41
41
41
46
-11
p02695
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <string> #include <vector> using namespace std; vector<string> split(const string &s, char delim) { vector<string> elems; string item; for (char ch : s) { if (ch == delim) { if (!item.empty()) { elems.push_back(item); } item.clear(); } else { item += ch; } } if (!item.empty()) { elems.push_back(item); } return elems; } string to_str_with_zero(int i, int w) { ostringstream sout; sout << std::setfill('0') << std::setw(w) << i; string s = sout.str(); return s; } int letter_to_int(char c) { return tolower(c) - 'a'; } int compare_array(vector<int> a1, vector<int> a2) { if (a1.size() != a2.size()) { return a1.size() - a2.size(); } for (int i = 0; i < a1.size(); i++) { if (a1.at(i) != a2.at(i)) { return a1.at(i) - a2.at(i); } } return 0; } int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } char int_to_char(int a) { if (a == -1) { return 'z'; } else { return 'a' + a; } } long nCr(int n, int r) { long ans = 1; for (int i = n; i > n - r; --i) { ans = ans * i; } for (int i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int divide_count(int a, int divider) { int r = 0; while (a % divider == 0) { a /= divider; r++; } return r; } bool is_prime(int a) { int i = 2; while (i * i <= a) { if (a % i == 0) { return false; } i++; } return true; } vector<vector<int>> all_comb(int n, int k) { vector<vector<int>> combs(nCr(n, k), vector<int>(k)); for (int i = 0; i < k; i++) { combs[0][i] = i; combs[1][i] = i; } for (long i = 1; i < nCr(n, k); i++) { int p = 1; while (combs[i][k - p] == n - p) { p++; if (p > k) { break; } } combs[i][k - p]++; int q = combs[i][k - p]; for (int j = 1; j < p; j++) { combs[i][k - p + j] = q + j; } if (i < nCr(n, k) - 1) { for (int j = 0; j < k; j++) { combs[i + 1][j] = combs[i][j]; } } } return combs; } int main() { std::cout << std::setprecision(9); int n, m, q; cin >> n >> m >> q; vector<vector<int>> c(q, vector<int>(4)); for (int i = 0; i < q; i++) { cin >> c[i][0] >> c[i][1] >> c[i][2] >> c[i][3]; } vector<vector<int>> combs = all_comb(m, n); int max = 0; vector<int> comb(n); for (int i = 0; i < n; i++) { comb[i] = 0; } while (true) { int score = 0; for (int i = 0; i < q; i++) { if (comb[c[i][1] - 1] - comb[c[i][0] - 1] == c[i][2]) { score += c[i][3]; } } if (score > max) { max = score; } int p = n - 1; while (comb[p] == m - 1) { p--; if (p < 0) { break; } } if (p < 0) { break; } comb[p]++; for (int i = p + 1; i < n; i++) { comb[i] = comb[p]; } } cout << max << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <string> #include <vector> using namespace std; vector<string> split(const string &s, char delim) { vector<string> elems; string item; for (char ch : s) { if (ch == delim) { if (!item.empty()) { elems.push_back(item); } item.clear(); } else { item += ch; } } if (!item.empty()) { elems.push_back(item); } return elems; } string to_str_with_zero(int i, int w) { ostringstream sout; sout << std::setfill('0') << std::setw(w) << i; string s = sout.str(); return s; } int letter_to_int(char c) { return tolower(c) - 'a'; } int compare_array(vector<int> a1, vector<int> a2) { if (a1.size() != a2.size()) { return a1.size() - a2.size(); } for (int i = 0; i < a1.size(); i++) { if (a1.at(i) != a2.at(i)) { return a1.at(i) - a2.at(i); } } return 0; } int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } char int_to_char(int a) { if (a == -1) { return 'z'; } else { return 'a' + a; } } long nCr(int n, int r) { long ans = 1; for (int i = n; i > n - r; --i) { ans = ans * i; } for (int i = 1; i < r + 1; ++i) { ans = ans / i; } return ans; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int divide_count(int a, int divider) { int r = 0; while (a % divider == 0) { a /= divider; r++; } return r; } bool is_prime(int a) { int i = 2; while (i * i <= a) { if (a % i == 0) { return false; } i++; } return true; } vector<vector<int>> all_comb(int n, int k) { vector<vector<int>> combs(nCr(n, k), vector<int>(k)); for (int i = 0; i < k; i++) { combs[0][i] = i; combs[1][i] = i; } for (long i = 1; i < nCr(n, k); i++) { int p = 1; while (combs[i][k - p] == n - p) { p++; if (p > k) { break; } } combs[i][k - p]++; int q = combs[i][k - p]; for (int j = 1; j < p; j++) { combs[i][k - p + j] = q + j; } if (i < nCr(n, k) - 1) { for (int j = 0; j < k; j++) { combs[i + 1][j] = combs[i][j]; } } } return combs; } int main() { std::cout << std::setprecision(9); int n, m, q; cin >> n >> m >> q; vector<vector<int>> c(q, vector<int>(4)); for (int i = 0; i < q; i++) { cin >> c[i][0] >> c[i][1] >> c[i][2] >> c[i][3]; } int max = 0; vector<int> comb(n); for (int i = 0; i < n; i++) { comb[i] = 0; } while (true) { int score = 0; for (int i = 0; i < q; i++) { if (comb[c[i][1] - 1] - comb[c[i][0] - 1] == c[i][2]) { score += c[i][3]; } } if (score > max) { max = score; } int p = n - 1; while (comb[p] == m - 1) { p--; if (p < 0) { break; } } if (p < 0) { break; } comb[p]++; for (int i = p + 1; i < n; i++) { comb[i] = comb[p]; } } cout << max << endl; }
delete
149
151
149
149
0
p02695
C++
Runtime Error
/*ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ` ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、 ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/ #include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") #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 ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define l00p(i, a, b) for (int i = a; i < (b); i++) #define loop(i, a) for (int i = 0; i < (a); i++) #define rep1(i, a, b) for (int i = (b)-1; i >= a; i--) #define rep(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert // #define MOD 998244353 template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ld pii = 3.14159265359; const int MOD = 1000000007; const char nl = '\n'; const ll INF = 1e18; const int MX = 100001; // check the limits, dummy int n, m, q; vi a(10), c(10), b(10), d(10); int ans = 0; void solve(vi &A) { int sum = 0; loop(i, q) if (A[b[i]] - A[a[i]] == c[i]) sum += d[i]; ckmax(ans, sum); } void rec(int last_element, vi A) { if (sz(A) == n) { solve(A); return; } l00p(i, last_element, m + 1) { A.pb(i); rec(i, A); A.pop_back(); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; loop(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } vi A; A.pb(1); rec(1, A); cout << ans; return 0; } // read the question correctly (ll vs int) // template by bqi343
/*ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ` ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、 ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/ #include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") #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 ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define l00p(i, a, b) for (int i = a; i < (b); i++) #define loop(i, a) for (int i = 0; i < (a); i++) #define rep1(i, a, b) for (int i = (b)-1; i >= a; i--) #define rep(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert // #define MOD 998244353 template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ld pii = 3.14159265359; const int MOD = 1000000007; const char nl = '\n'; const ll INF = 1e18; const int MX = 100001; // check the limits, dummy int n, m, q; vi a(50), c(50), b(50), d(50); int ans = 0; void solve(vi &A) { int sum = 0; loop(i, q) if (A[b[i]] - A[a[i]] == c[i]) sum += d[i]; ckmax(ans, sum); } void rec(int last_element, vi A) { if (sz(A) == n) { solve(A); return; } l00p(i, last_element, m + 1) { A.pb(i); rec(i, A); A.pop_back(); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> q; loop(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } vi A; A.pb(1); rec(1, A); cout << ans; return 0; } // read the question correctly (ll vs int) // template by bqi343
replace
59
60
59
60
0
p02695
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; int A[15], n, m, q, a[55], b[55], c[55], d[55], res, ans; int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } for (int i = 1; i <= n; i++) A[i] = 1; while (!a[0]) { int res = 0; for (int i = 1; i <= q; i++) { if (A[b[i]] - A[a[i]] == c[i]) res += d[i]; } ans = max(res, ans); for (int i = n; i >= 0; i--) { if (A[i] < m) { A[i]++; for (int j = i + 1; j <= n; j++) A[j] = A[i]; break; } } } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int A[15], n, m, q, a[55], b[55], c[55], d[55], res, ans; int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } for (int i = 1; i <= n; i++) A[i] = 1; while (!A[0]) { int res = 0; for (int i = 1; i <= q; i++) { if (A[b[i]] - A[a[i]] == c[i]) res += d[i]; } ans = max(res, ans); for (int i = n; i >= 0; i--) { if (A[i] < m) { A[i]++; for (int j = i + 1; j <= n; j++) A[j] = A[i]; break; } } } cout << ans; return 0; }
replace
11
12
11
12
TLE
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (n + 1); i++) using namespace std; using ll = long long; int n, m, q; vector<int> a, b, c, d; int ans; void dfs(vector<int> A) { if (A.size() == n + 1) { int now = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; } ans = max(ans, now); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int n, m, q; vector<int> a, b, c, d; int ans; void dfs(vector<int> A) { if (A.size() == n + 1) { int now = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; } ans = max(ans, now); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
replace
1
2
1
2
0
p02695
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const ll INF = 1e9; const ll MOD = 1e9 + 7; #define all(v) v.begin(), v.end() #define repi(i, n, init) for (ll i = init; i < (n); i++) #define repd(i, n, init) for (ll i = (n); i >= init; i--) #define repm(i, m) for (auto i = m.begin(); i != m.end(); i++) #define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit) template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } int main() { int n, m, q; cin >> n >> m >> q; int a[n], b[n], c[n], d[n]; repi(i, q, 0) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<int> vec(n + m, 1); repi(i, m, 0) { vec[i] = 0; ; } int ans = 0; do { int zero_cnt = 0; vector<int> A; repi(i, n + m, 0) { if (vec[i] == 0) zero_cnt++; else { A.push_back(zero_cnt); if (zero_cnt == 0) { A.clear(); break; } } } if (A.size() != n) continue; int s = 0; repi(i, q, 0) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) s += d[i]; } ans = max(ans, s); } while (next_permutation(vec.begin(), vec.end())); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const ll INF = 1e9; const ll MOD = 1e9 + 7; #define all(v) v.begin(), v.end() #define repi(i, n, init) for (ll i = init; i < (n); i++) #define repd(i, n, init) for (ll i = (n); i >= init; i--) #define repm(i, m) for (auto i = m.begin(); i != m.end(); i++) #define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit) template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } int main() { int n, m, q; cin >> n >> m >> q; int a[55], b[55], c[55], d[55]; repi(i, q, 0) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<int> vec(n + m, 1); repi(i, m, 0) { vec[i] = 0; ; } int ans = 0; do { int zero_cnt = 0; vector<int> A; repi(i, n + m, 0) { if (vec[i] == 0) zero_cnt++; else { A.push_back(zero_cnt); if (zero_cnt == 0) { A.clear(); break; } } } if (A.size() != n) continue; int s = 0; repi(i, q, 0) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) s += d[i]; } ans = max(ans, s); } while (next_permutation(vec.begin(), vec.end())); cout << ans << endl; return 0; }
replace
21
22
21
22
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int n, m, q; ll ans = 0; vector<int> a(10), b(10), c(10), d(10); void dfs(vector<int> A) { if (A.size() == n + 1) { // calc score ll now = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; } ans = max(ans, now); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main(void) { cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; }
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int n, m, q; ll ans = 0; vector<int> a(50), b(50), c(50), d(50); void dfs(vector<int> A) { if (A.size() == n + 1) { // calc score ll now = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; } ans = max(ans, now); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main(void) { cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; }
replace
23
24
23
24
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; #define MOD 1000000007 #define INF 1000000000 #define mp make_pair #define pb push_back #define ss second #define ff first #define endl '\n' #define pl cout << endl; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long INFll = 1ll * INF * INF; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define debug(x) cout << x << endl; #define sz(a) int((a).size()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } // unordered_map<long long, int, custom_hash> // gp_hash_table<long long, int, custom_hash> }; long long genrand(long long L, long long R) { return uniform_int_distribution<long long>(L, R)(rng); } int mul(int a, int b, int mod = MOD) { return int(a * 1ll * b % mod); } int norm(int a, int mod = MOD) { while (a >= mod) a -= mod; while (a < 0) a += mod; return a; } int powmod(int x, int y, int mod = MOD) { int res = 1; while (y > 0) { if (y & 1) res = mul(res, x, mod); x = mul(x, x, mod); y = y >> 1; } return res; } int inv(int a, int mod = MOD) { return powmod(a, mod - 2); } int n, m, q, ans = 0; vector<int> v; int a[10], b[10], c[10], d[10]; void solve(int idx) { if (idx == n) { int res = 0; for (int i = 0; i < q; i++) { if (v[b[i]] - v[a[i]] == c[i]) { res += d[i]; } } ans = max(ans, res); return; } int st = 1; if (idx) st = v[idx - 1]; for (int i = st; i <= m; i++) { v.pb(i); solve(idx + 1); v.pop_back(); } } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 0; i < q; i++) { scanf("%d%d%d%d", a + i, b + i, c + i, d + i); a[i]--; b[i]--; } solve(0); printf("%d", ans); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; #define MOD 1000000007 #define INF 1000000000 #define mp make_pair #define pb push_back #define ss second #define ff first #define endl '\n' #define pl cout << endl; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long INFll = 1ll * INF * INF; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define debug(x) cout << x << endl; #define sz(a) int((a).size()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } // unordered_map<long long, int, custom_hash> // gp_hash_table<long long, int, custom_hash> }; long long genrand(long long L, long long R) { return uniform_int_distribution<long long>(L, R)(rng); } int mul(int a, int b, int mod = MOD) { return int(a * 1ll * b % mod); } int norm(int a, int mod = MOD) { while (a >= mod) a -= mod; while (a < 0) a += mod; return a; } int powmod(int x, int y, int mod = MOD) { int res = 1; while (y > 0) { if (y & 1) res = mul(res, x, mod); x = mul(x, x, mod); y = y >> 1; } return res; } int inv(int a, int mod = MOD) { return powmod(a, mod - 2); } int n, m, q, ans = 0; vector<int> v; int a[50], b[50], c[50], d[50]; void solve(int idx) { if (idx == n) { int res = 0; for (int i = 0; i < q; i++) { if (v[b[i]] - v[a[i]] == c[i]) { res += d[i]; } } ans = max(ans, res); return; } int st = 1; if (idx) st = v[idx - 1]; for (int i = st; i <= m; i++) { v.pb(i); solve(idx + 1); v.pop_back(); } } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 0; i < q; i++) { scanf("%d%d%d%d", a + i, b + i, c + i, d + i); a[i]--; b[i]--; } solve(0); printf("%d", ans); return 0; }
replace
69
70
69
70
0
p02695
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> using namespace std; int funcovf(int *Ax, int i, int M) { Ax[i]++; if (Ax[i] > M) { funcovf(Ax, i - 1, M); Ax[i] = Ax[i - 1]; } return 0; } int main() { int N, M, Q; cin >> N >> M >> Q; int ai[50]; int bi[50]; int ci[50]; int di[50]; for (int i = 0; i < Q; i++) { cin >> ai[i] >> bi[i] >> ci[i] >> di[i]; } int Ax[10]; for (int i = 0; i < 10; i++) { Ax[i] = 1; } int maxnum = 0; while (1) { // check int tempnum = 0; for (int i = 0; i < Q; i++) { if ((Ax[bi[i] - 1] - Ax[ai[i] - 1]) == ci[i]) { tempnum = tempnum + di[i]; } } if (tempnum > maxnum) { maxnum = tempnum; } // Ax[i] change funcovf(Ax, N - 1, M); if (Ax[0] > 1) { break; } } cout << maxnum << std::endl; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int funcovf(int *Ax, int i, int M) { if (i == 0) { Ax[0] = 2; return 0; } Ax[i]++; if (Ax[i] > M) { funcovf(Ax, i - 1, M); Ax[i] = Ax[i - 1]; } return 0; } int main() { int N, M, Q; cin >> N >> M >> Q; int ai[50]; int bi[50]; int ci[50]; int di[50]; for (int i = 0; i < Q; i++) { cin >> ai[i] >> bi[i] >> ci[i] >> di[i]; } int Ax[10]; for (int i = 0; i < 10; i++) { Ax[i] = 1; } int maxnum = 0; while (1) { // check int tempnum = 0; for (int i = 0; i < Q; i++) { if ((Ax[bi[i] - 1] - Ax[ai[i] - 1]) == ci[i]) { tempnum = tempnum + di[i]; } } if (tempnum > maxnum) { maxnum = tempnum; } // Ax[i] change funcovf(Ax, N - 1, M); if (Ax[0] > 1) { break; } } cout << maxnum << std::endl; }
insert
7
7
7
12
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using lint = long long; int arr[50][4] = {0}; int Q; int dfs(vector<int> A, int digit, int max, int N, int M) { if (A.size() < digit) { int sum = 0; for (int i = 0; i <= Q; i++) { if (A[arr[i][1]] - A[arr[i][0]] == arr[i][2]) { sum += arr[i][3]; } } return sum; } for (int i = A[digit - 1]; i < M; i++) { A[digit] = i; int x = dfs(A, digit + 1, max, N, M); if (x > max) { max = x; } } return max; } int main(void) { int N, M; cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2] >> arr[i][3]; } vector<int> A(N + 1, 0); cout << dfs(A, 1, 0, N, M) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; int arr[50][4] = {0}; int Q; int dfs(vector<int> A, int digit, int max, int N, int M) { if (N < digit) { int sum = 0; for (int i = 0; i <= Q; i++) { if (A[arr[i][1]] - A[arr[i][0]] == arr[i][2]) { sum += arr[i][3]; } } return sum; } for (int i = A[digit - 1]; i < M; i++) { A[digit] = i; int x = dfs(A, digit + 1, max, N, M); if (x > max) { max = x; } } return max; } int main(void) { int N, M; cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> arr[i][0] >> arr[i][1] >> arr[i][2] >> arr[i][3]; } vector<int> A(N + 1, 0); cout << dfs(A, 1, 0, N, M) << endl; return 0; }
replace
9
10
9
10
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; using namespace std; int a[50], b[50], c[50], d[50]; int n, m, q; int mx = 0; vector<int> t; int check() { int curr = 0; for (int i = 0; i < q; i++) { if (t[b[i]] - t[a[i]] == c[i]) curr += d[i]; } return curr; } void dfs(int i, int cur) { if (i >= n) { mx = max(mx, check()); } for (int j = cur; j <= m; j++) { t.push_back(j); dfs(i + 1, j); t.pop_back(); } } void solve() { cin >> n >> m >> q; for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } dfs(0, 1); cout << mx << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> typedef long long int ll; using namespace std; int a[50], b[50], c[50], d[50]; int n, m, q; int mx = 0; vector<int> t; int check() { int curr = 0; for (int i = 0; i < q; i++) { if (t[b[i]] - t[a[i]] == c[i]) curr += d[i]; } return curr; } void dfs(int i, int cur) { if (i >= n) { mx = max(mx, check()); return; } for (int j = cur; j <= m; j++) { t.push_back(j); dfs(i + 1, j); t.pop_back(); } } void solve() { cin >> n >> m >> q; for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } dfs(0, 1); cout << mx << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
insert
21
21
21
22
-11
p02695
C++
Runtime Error
#include <cmath> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; long mod = (long)1e9 + 7; int n, m, q, a[10], b[10], c[10], d[10], ans = 0; int bfs(vector<int> t) { if (t.size() == n) { int sum = 0; rep(i, q) { if (t[b[i]] - t[a[i]] == c[i]) sum += d[i]; } ans = max(ans, sum); } else { int back = 1; if (t.size() > 0) back = t.back(); for (int i = back; i <= m; i++) { t.push_back(i); bfs(t); t.pop_back(); } } return 0; } int main() { cin >> n >> m >> q; rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i]; rep(i, q) a[i]--, b[i]--; bfs({}); cout << ans << "\n"; return 0; }
#include <cmath> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; long mod = (long)1e9 + 7; int n, m, q, a[50], b[50], c[50], d[50], ans = 0; int bfs(vector<int> t) { if (t.size() == n) { int sum = 0; rep(i, q) { if (t[b[i]] - t[a[i]] == c[i]) sum += d[i]; } ans = max(ans, sum); } else { int back = 1; if (t.size() > 0) back = t.back(); for (int i = back; i <= m; i++) { t.push_back(i); bfs(t); t.pop_back(); } } return 0; } int main() { cin >> n >> m >> q; rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i]; rep(i, q) a[i]--, b[i]--; bfs({}); cout << ans << "\n"; return 0; }
replace
10
11
10
11
0
p02695
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int N, M, Q; long long ans = 0; vector<int> a(M), b(M), c(M), d(M); void dfs(vector<int> v, int depth, int lastNum) { if (depth == N) { // 数列が完成したらスコア計算 long long score = 0; for (int i = 0; i < Q; i++) { if (v[b[i] - 1] - v[a[i] - 1] == c[i]) score += d[i]; } ans = max(ans, score); } else { for (int i = lastNum; i < M + 1; i++) { // 末尾の数字以上の数字を結合したパターン分岐 vector<int> nw = v; nw.push_back(i); dfs(nw, depth + 1, i); } } } int main() { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<int> v; dfs(v, 0, 1); cout << ans; }
#include "bits/stdc++.h" using namespace std; int N, M, Q; long long ans = 0; vector<int> a(50), b(50), c(50), d(50); void dfs(vector<int> v, int depth, int lastNum) { if (depth == N) { // 数列が完成したらスコア計算 long long score = 0; for (int i = 0; i < Q; i++) { if (v[b[i] - 1] - v[a[i] - 1] == c[i]) score += d[i]; } ans = max(ans, score); } else { for (int i = lastNum; i < M + 1; i++) { // 末尾の数字以上の数字を結合したパターン分岐 vector<int> nw = v; nw.push_back(i); dfs(nw, depth + 1, i); } } } int main() { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<int> v; dfs(v, 0, 1); cout << ans; }
replace
5
6
5
6
-11
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, q; vector<int> a, b, c, d; int ans = 0; void dfs(int cnt, vector<int> A, int now) { if (cnt == n) { int num = 0; for (int i = 0; i < q; i++) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) { num += d[i]; } } ans = max(num, ans); } else { for (int i = now; i <= m; i++) { A[cnt] = i; dfs(cnt + 1, A, i); } } } int main() { cin >> n >> m >> q; for (int i = 0; i < q; i++) { int aa, bb, cc, dd; cin >> aa >> bb >> cc >> dd; a.push_back(aa); b.push_back(bb); c.push_back(cc); d.push_back(dd); } vector<int> A(q, 1); A[0] = 1; dfs(0, A, 1); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, q; vector<int> a, b, c, d; int ans = 0; void dfs(int cnt, vector<int> A, int now) { if (cnt == n) { int num = 0; for (int i = 0; i < q; i++) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) { num += d[i]; } } ans = max(num, ans); } else { for (int i = now; i <= m; i++) { A[cnt] = i; dfs(cnt + 1, A, i); } } } int main() { cin >> n >> m >> q; for (int i = 0; i < q; i++) { int aa, bb, cc, dd; cin >> aa >> bb >> cc >> dd; a.push_back(aa); b.push_back(bb); c.push_back(cc); d.push_back(dd); } vector<int> A(n, 0); A[0] = 1; dfs(0, A, 1); cout << ans << endl; }
replace
36
37
36
37
0
p02695
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repe(i, n) for (int i = 1; i <= (int)(n); ++i) #define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit) #define ll long long using namespace std; typedef vector<vector<int>> Graph; int ans = 0; int N, M, Q; vector<int> a, b, c, d; void dfs(vector<int> vec) { int now = 0; if (vec.size() == N + 1) { rep(i, Q) { if (vec.at(b.at(i)) - vec.at(a.at(i)) == c.at(i)) now += d.at(i); } ans = max(ans, now); } vec.push_back(vec.back()); while (vec.back() <= M) { dfs(vec); vec.back()++; } } int main() { cin >> N >> M >> Q; a = b = c = d = vector<int>(Q); rep(i, Q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i); vector<int> vec(1, 1); dfs(vec); cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repe(i, n) for (int i = 1; i <= (int)(n); ++i) #define rep_bit(n) for (int bit = 0; bit < (1 << n); ++bit) #define ll long long using namespace std; typedef vector<vector<int>> Graph; int ans = 0; int N, M, Q; vector<int> a, b, c, d; void dfs(vector<int> vec) { int now = 0; if (vec.size() == N + 1) { rep(i, Q) { if (vec.at(b.at(i)) - vec.at(a.at(i)) == c.at(i)) now += d.at(i); } ans = max(ans, now); return; } vec.push_back(vec.back()); while (vec.back() <= M) { dfs(vec); vec.back()++; } } int main() { cin >> N >> M >> Q; a = b = c = d = vector<int>(Q); rep(i, Q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i); vector<int> vec(1, 1); dfs(vec); cout << ans << endl; }
insert
19
19
19
20
TLE
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct point { int a, b, c, d; }; int n, m, q; point query[55]; int arr[15]; int mx, call; int f(int curr, int before) { call++; for (int i = before; i <= m; i++) { arr[curr] = i; if (curr == n) { int sum = 0; for (int j = 0; j < q; j++) { point &k = query[j]; if (arr[k.b] - arr[k.a] == k.c) sum += k.d; } mx = max(mx, sum); } else f(curr + 1, i); } } int main() { cin >> n >> m >> q; for (int i = 0; i < q; i++) { cin >> query[i].a >> query[i].b >> query[i].c >> query[i].d; } f(1, 1); cout << mx; }
#include <bits/stdc++.h> using namespace std; struct point { int a, b, c, d; }; int n, m, q; point query[55]; int arr[15]; int mx, call; void f(int curr, int before) { call++; for (int i = before; i <= m; i++) { arr[curr] = i; if (curr == n) { int sum = 0; for (int j = 0; j < q; j++) { point &k = query[j]; if (arr[k.b] - arr[k.a] == k.c) sum += k.d; } mx = max(mx, sum); } else f(curr + 1, i); } } int main() { cin >> n >> m >> q; for (int i = 0; i < q; i++) { cin >> query[i].a >> query[i].b >> query[i].c >> query[i].d; } f(1, 1); cout << mx; }
replace
9
10
9
10
0
p02695
C++
Runtime Error
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <cstdint> #include <iostream> #include <string> constexpr int32_t kMaxArraySize = 10; constexpr int32_t kMinArrayValue = 1; constexpr int32_t kMaxArrayValue = 10; constexpr int32_t kMaxNumberOfConditions = 10; void CallDepthFirstSearch(std::istream &input_stream) noexcept; struct Condition { int32_t size{0}; int32_t a[kMaxNumberOfConditions]; int32_t b[kMaxNumberOfConditions]; int32_t c[kMaxNumberOfConditions]; int64_t score[kMaxNumberOfConditions]; }; struct Array { int32_t size{0}; int32_t max_value{0}; int32_t values[kMaxArraySize]; }; class DepthFirstSearch { public: DepthFirstSearch() noexcept; ~DepthFirstSearch() noexcept; void ConfigureArray(const int32_t size, const int32_t max_value); void AddCondition(const int32_t a, const int32_t b, const int32_t c, const int64_t score); int64_t SearchMaxScore(); private: void DoDepthFirstSearch(const int32_t target_index); bool IsOkay(const int32_t index_condition) const; private: int64_t max_score_; Condition condition_; Array array_; }; void CallDepthFirstSearch(std::istream &input_stream) noexcept { input_stream.tie(0); std::ios::sync_with_stdio(false); DepthFirstSearch *depth_first_search = new DepthFirstSearch(); int32_t array_length, max_value, number_of_conditions; input_stream >> array_length >> max_value >> number_of_conditions; depth_first_search->ConfigureArray(array_length, max_value); for (int32_t index_condition = 0; index_condition < number_of_conditions; ++index_condition) { int32_t a, b, c; int64_t score; input_stream >> a >> b >> c >> score; depth_first_search->AddCondition(a - 1, b - 1, c, score); } std::cout << depth_first_search->SearchMaxScore() << std::endl; delete depth_first_search; } DepthFirstSearch::DepthFirstSearch() noexcept : max_score_(0) { array_.size = 0; condition_.size = 0; } DepthFirstSearch::~DepthFirstSearch() noexcept {} void DepthFirstSearch::ConfigureArray(const int32_t size, const int32_t max_value) { if (size <= 1 || size > kMaxArraySize) { std::cerr << "ERROR: ConfigureArray(): Invalid arg size=" << size << std::endl; throw 1; } else if ((max_value < kMinArrayValue) || (max_value > kMaxArrayValue)) { std::cerr << "ERROR: ConfigureArray(): Invalid arg max_value=" << max_value << std::endl; throw 1; } else { array_.size = size; array_.max_value = max_value; } } void DepthFirstSearch::AddCondition(const int32_t a, const int32_t b, const int32_t c, const int64_t score) { if (condition_.size >= kMaxNumberOfConditions) { std::cerr << "ERROR: AddCondition(): Full." << std::endl; throw 1; } else if ((a < 0) || (a >= array_.size)) { std::cerr << "ERROR: Invalid arg a=" << a << std::endl; } else if ((b < 0) || (b >= array_.size)) { std::cerr << "ERROR: Invalid arg b=" << b << std::endl; } else { const int32_t index_stored = condition_.size; condition_.a[index_stored] = a; condition_.b[index_stored] = b; condition_.c[index_stored] = c; condition_.score[index_stored] = score; ++condition_.size; } } int64_t DepthFirstSearch::SearchMaxScore() { try { DoDepthFirstSearch(0); } catch (...) { std::cerr << "ERROR: ConfigureArray()" << std::endl; throw; } return max_score_; } void DepthFirstSearch::DoDepthFirstSearch(const int32_t target_index) { if (target_index < 0 || target_index > array_.size) { std::cerr << "ERROR: DoDepthFirstSearch(): Invalid arg target_index=" << target_index << std::endl; throw 1; } try { if (target_index == array_.size) { int64_t score_sum = 0; for (int32_t index_condition = 0; index_condition < condition_.size; ++index_condition) { score_sum += IsOkay(index_condition) ? condition_.score[index_condition] : 0; } if (score_sum > max_score_) { max_score_ = score_sum; } } else { int32_t &target_value = array_.values[target_index]; const int32_t start_value = (target_index == 0) ? kMinArrayValue : array_.values[target_index - 1]; for (target_value = start_value; target_value <= array_.max_value; ++target_value) { DoDepthFirstSearch(target_index + 1); } } } catch (...) { std::cerr << "ERROR: DoDepthFirstSearch()" << std::endl; throw; } } bool DepthFirstSearch::IsOkay(const int32_t index_condition) const { if ((index_condition) < 0 || (index_condition >= condition_.size)) { std::cerr << "ERROR: IsOkay(): Invalid arg index_condition=" << index_condition << std::endl; throw 1; } const int32_t a = condition_.a[index_condition]; const int32_t b = condition_.b[index_condition]; const int32_t c = condition_.c[index_condition]; const bool is_okay = (array_.values[b] - array_.values[a] == c); return is_okay; } int main() { try { CallDepthFirstSearch(std::cin); } catch (...) { std::cerr << "ERROR: main()" << std::endl; } return 0; }
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <cstdint> #include <iostream> #include <string> constexpr int32_t kMaxArraySize = 10; constexpr int32_t kMinArrayValue = 1; constexpr int32_t kMaxArrayValue = 10; constexpr int32_t kMaxNumberOfConditions = 50; void CallDepthFirstSearch(std::istream &input_stream) noexcept; struct Condition { int32_t size{0}; int32_t a[kMaxNumberOfConditions]; int32_t b[kMaxNumberOfConditions]; int32_t c[kMaxNumberOfConditions]; int64_t score[kMaxNumberOfConditions]; }; struct Array { int32_t size{0}; int32_t max_value{0}; int32_t values[kMaxArraySize]; }; class DepthFirstSearch { public: DepthFirstSearch() noexcept; ~DepthFirstSearch() noexcept; void ConfigureArray(const int32_t size, const int32_t max_value); void AddCondition(const int32_t a, const int32_t b, const int32_t c, const int64_t score); int64_t SearchMaxScore(); private: void DoDepthFirstSearch(const int32_t target_index); bool IsOkay(const int32_t index_condition) const; private: int64_t max_score_; Condition condition_; Array array_; }; void CallDepthFirstSearch(std::istream &input_stream) noexcept { input_stream.tie(0); std::ios::sync_with_stdio(false); DepthFirstSearch *depth_first_search = new DepthFirstSearch(); int32_t array_length, max_value, number_of_conditions; input_stream >> array_length >> max_value >> number_of_conditions; depth_first_search->ConfigureArray(array_length, max_value); for (int32_t index_condition = 0; index_condition < number_of_conditions; ++index_condition) { int32_t a, b, c; int64_t score; input_stream >> a >> b >> c >> score; depth_first_search->AddCondition(a - 1, b - 1, c, score); } std::cout << depth_first_search->SearchMaxScore() << std::endl; delete depth_first_search; } DepthFirstSearch::DepthFirstSearch() noexcept : max_score_(0) { array_.size = 0; condition_.size = 0; } DepthFirstSearch::~DepthFirstSearch() noexcept {} void DepthFirstSearch::ConfigureArray(const int32_t size, const int32_t max_value) { if (size <= 1 || size > kMaxArraySize) { std::cerr << "ERROR: ConfigureArray(): Invalid arg size=" << size << std::endl; throw 1; } else if ((max_value < kMinArrayValue) || (max_value > kMaxArrayValue)) { std::cerr << "ERROR: ConfigureArray(): Invalid arg max_value=" << max_value << std::endl; throw 1; } else { array_.size = size; array_.max_value = max_value; } } void DepthFirstSearch::AddCondition(const int32_t a, const int32_t b, const int32_t c, const int64_t score) { if (condition_.size >= kMaxNumberOfConditions) { std::cerr << "ERROR: AddCondition(): Full." << std::endl; throw 1; } else if ((a < 0) || (a >= array_.size)) { std::cerr << "ERROR: Invalid arg a=" << a << std::endl; } else if ((b < 0) || (b >= array_.size)) { std::cerr << "ERROR: Invalid arg b=" << b << std::endl; } else { const int32_t index_stored = condition_.size; condition_.a[index_stored] = a; condition_.b[index_stored] = b; condition_.c[index_stored] = c; condition_.score[index_stored] = score; ++condition_.size; } } int64_t DepthFirstSearch::SearchMaxScore() { try { DoDepthFirstSearch(0); } catch (...) { std::cerr << "ERROR: ConfigureArray()" << std::endl; throw; } return max_score_; } void DepthFirstSearch::DoDepthFirstSearch(const int32_t target_index) { if (target_index < 0 || target_index > array_.size) { std::cerr << "ERROR: DoDepthFirstSearch(): Invalid arg target_index=" << target_index << std::endl; throw 1; } try { if (target_index == array_.size) { int64_t score_sum = 0; for (int32_t index_condition = 0; index_condition < condition_.size; ++index_condition) { score_sum += IsOkay(index_condition) ? condition_.score[index_condition] : 0; } if (score_sum > max_score_) { max_score_ = score_sum; } } else { int32_t &target_value = array_.values[target_index]; const int32_t start_value = (target_index == 0) ? kMinArrayValue : array_.values[target_index - 1]; for (target_value = start_value; target_value <= array_.max_value; ++target_value) { DoDepthFirstSearch(target_index + 1); } } } catch (...) { std::cerr << "ERROR: DoDepthFirstSearch()" << std::endl; throw; } } bool DepthFirstSearch::IsOkay(const int32_t index_condition) const { if ((index_condition) < 0 || (index_condition >= condition_.size)) { std::cerr << "ERROR: IsOkay(): Invalid arg index_condition=" << index_condition << std::endl; throw 1; } const int32_t a = condition_.a[index_condition]; const int32_t b = condition_.b[index_condition]; const int32_t c = condition_.c[index_condition]; const bool is_okay = (array_.values[b] - array_.values[a] == c); return is_okay; } int main() { try { CallDepthFirstSearch(std::cin); } catch (...) { std::cerr << "ERROR: main()" << std::endl; } return 0; }
replace
11
12
11
12
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m, q; long long ans = 0; vector<int> a(10), b(10), c(10), d(10); void calc(vector<int> &A) { long long cur = 0; for (int i = 0; i < q; i++) { if (A[a[i] - 1] + c[i] == A[b[i] - 1]) cur += d[i]; } ans = max(ans, cur); } void rec(vector<int> &A, int idx) { if (idx < n) { for (int nx = A[idx - 1]; nx <= m; nx++) { vector<int> B(A.begin(), A.end()); B[idx] = nx; rec(B, idx + 1); } } else { calc(A); } } int main() { cin >> n >> m >> q; for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; vector<int> A(n, 1); rec(A, 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, q; long long ans = 0; vector<int> a(50), b(50), c(50), d(50); void calc(vector<int> &A) { long long cur = 0; for (int i = 0; i < q; i++) { if (A[a[i] - 1] + c[i] == A[b[i] - 1]) cur += d[i]; } ans = max(ans, cur); } void rec(vector<int> &A, int idx) { if (idx < n) { for (int nx = A[idx - 1]; nx <= m; nx++) { vector<int> B(A.begin(), A.end()); B[idx] = nx; rec(B, idx + 1); } } else { calc(A); } } int main() { cin >> n >> m >> q; for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; vector<int> A(n, 1); rec(A, 1); cout << ans << endl; return 0; }
replace
5
6
5
6
0
p02695
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int n, m, q; vector<int> a, b, c, d; int ans = 0; void dfs(vector<int> s) { if (s.size() == n + 1) { int now = 0; for (int i = 0; i < q; i++) if (s[b[i]] - s[a[i]] == c[i]) now += d[i]; ans = max(ans, now); } s.push_back(s.back()); while (s.back() <= m) { dfs(s); s.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int n, m, q; vector<int> a, b, c, d; int ans = 0; void dfs(vector<int> s) { if (s.size() == n + 1) { int now = 0; for (int i = 0; i < q; i++) if (s[b[i]] - s[a[i]] == c[i]) now += d[i]; ans = max(ans, now); return; } s.push_back(s.back()); while (s.back() <= m) { dfs(s); s.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
insert
13
13
13
14
TLE
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &istr, vector<T> &v) { for (T &x : v) istr >> x; return istr; } template <typename T, typename U> istream &operator>>(istream &istr, pair<T, U> &p) { istr >> p.first >> p.second; return istr; } template <typename T> ostream &operator<<(ostream &ostr, vector<T> &v) { if (!v.empty()) { ostr << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) // ostr << *itr; ostr << " " << *itr; } return ostr; } template <typename T, typename U> ostream &operator<<(ostream &ostr, pair<T, U> &p) { // ostr << p.first << p.second; // ostr << p.first << ", " << p.second; ostr << "(" << p.first << ", " << p.second << ")"; return ostr; } template <typename T> ostream &operator<<(ostream &ostr, vector<vector<T>> &vv) { if (!vv.empty()) { ostr << vv.front(); for (auto itr = ++vv.begin(); itr != vv.end(); itr++) ostr << endl << *itr; } return ostr; } template <typename T, typename U> ostream &operator<<(ostream &ostr, vector<pair<T, U>> &vp) { if (!vp.empty()) { ostr << vp.front(); for (auto itr = ++vp.begin(); itr != vp.end(); itr++) ostr << endl << *itr; } return ostr; } typedef long long ll; typedef vector<ll> vll; typedef vector<char> vc; typedef vector<double> vd; // vll v(n); v[i]=x; typedef vector<vll> vvll; typedef vector<vc> vvc; typedef vector<vd> vvd; // vvll v(m,vll(n)); v[i][j]=x; typedef pair<ll, ll> pll; typedef pair<double, double> pd; typedef vector<pll> vpll; typedef vector<pd> vpd; // vpll v(n); v[i]=make_pair(x,y); v[i].first/second; // v.front() : v[0] // v.back() : v[v.size()-1] #define PI 3.1415926535897932 #define EPS 1e-12 #define INF ((ll)1e+12) #define REP(i, n) for (ll i = 0; i < (n); i++) #define RREP(i, n) for (ll i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define FORR(i, a, b) for (ll i = (b); i >= (a); i--) #define fix(x) cout << fixed << setprecision(x) #define dump(x) cout << #x << " = " << (x) << endl #define all(x) (x).begin(), (x).end() template <typename T> T sum(vector<T> &v) { return accumulate(all(v), (T)0); } template <typename T> inline void sort(vector<T> &v) { sort(all(v)); } template <typename T> inline void rsort(vector<T> &v) { sort(all(v), greater<T>()); } template <typename T> inline void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> inline void chmax(T &a, T b) { if (a < b) a = b; } int main() { ll n, m, q, ans = 0; cin >> n >> m >> q; vvll x(q, vll(4)); REP(i, q) REP(j, 4) cin >> x[i][j]; REP(i, q) { x[i][0]--; x[i][1]--; } sort(x); vll a(n, 1); while (1) { ll tmp = 0; REP(i, q) { if (a[x[i][1]] - a[x[i][0]] == x[i][2]) tmp += x[i][3]; // dump(tmp); chmax(ans, tmp); } RREP(i, n) { if (a[i] != m) { a[i]++; FOR(j, i + 1, n) a[j] = a[i]; break; } } // dump(a); if (a[0] == m) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &istr, vector<T> &v) { for (T &x : v) istr >> x; return istr; } template <typename T, typename U> istream &operator>>(istream &istr, pair<T, U> &p) { istr >> p.first >> p.second; return istr; } template <typename T> ostream &operator<<(ostream &ostr, vector<T> &v) { if (!v.empty()) { ostr << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) // ostr << *itr; ostr << " " << *itr; } return ostr; } template <typename T, typename U> ostream &operator<<(ostream &ostr, pair<T, U> &p) { // ostr << p.first << p.second; // ostr << p.first << ", " << p.second; ostr << "(" << p.first << ", " << p.second << ")"; return ostr; } template <typename T> ostream &operator<<(ostream &ostr, vector<vector<T>> &vv) { if (!vv.empty()) { ostr << vv.front(); for (auto itr = ++vv.begin(); itr != vv.end(); itr++) ostr << endl << *itr; } return ostr; } template <typename T, typename U> ostream &operator<<(ostream &ostr, vector<pair<T, U>> &vp) { if (!vp.empty()) { ostr << vp.front(); for (auto itr = ++vp.begin(); itr != vp.end(); itr++) ostr << endl << *itr; } return ostr; } typedef long long ll; typedef vector<ll> vll; typedef vector<char> vc; typedef vector<double> vd; // vll v(n); v[i]=x; typedef vector<vll> vvll; typedef vector<vc> vvc; typedef vector<vd> vvd; // vvll v(m,vll(n)); v[i][j]=x; typedef pair<ll, ll> pll; typedef pair<double, double> pd; typedef vector<pll> vpll; typedef vector<pd> vpd; // vpll v(n); v[i]=make_pair(x,y); v[i].first/second; // v.front() : v[0] // v.back() : v[v.size()-1] #define PI 3.1415926535897932 #define EPS 1e-12 #define INF ((ll)1e+12) #define REP(i, n) for (ll i = 0; i < (n); i++) #define RREP(i, n) for (ll i = (n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i = (a); i <= (b); i++) #define FORR(i, a, b) for (ll i = (b); i >= (a); i--) #define fix(x) cout << fixed << setprecision(x) #define dump(x) cout << #x << " = " << (x) << endl #define all(x) (x).begin(), (x).end() template <typename T> T sum(vector<T> &v) { return accumulate(all(v), (T)0); } template <typename T> inline void sort(vector<T> &v) { sort(all(v)); } template <typename T> inline void rsort(vector<T> &v) { sort(all(v), greater<T>()); } template <typename T> inline void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> inline void chmax(T &a, T b) { if (a < b) a = b; } int main() { ll n, m, q, ans = 0; cin >> n >> m >> q; vvll x(q, vll(4)); REP(i, q) REP(j, 4) cin >> x[i][j]; REP(i, q) { x[i][0]--; x[i][1]--; } sort(x); vll a(n, 1); while (1) { ll tmp = 0; REP(i, q) { if (a[x[i][1]] - a[x[i][0]] == x[i][2]) tmp += x[i][3]; // dump(tmp); chmax(ans, tmp); } RREP(i, n) { if (a[i] != m) { a[i]++; FOR(j, i + 1, n - 1) a[j] = a[i]; break; } } // dump(a); if (a[0] == m) break; } cout << ans << endl; return 0; }
replace
119
120
119
120
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for (int64 i = 0; i < (n); i++) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } int64 N; vector<int64> a; vector<int64> G[212345]; vector<int64> res; stack<PLL> undo; vector<int64> lis; void dfs(int64 v, int64 p) { int64 idx = lower_bound(all(lis), a[v]) - lis.begin(); undo.emplace(idx, lis[idx]); lis[idx] = a[v]; res[v] = lower_bound(all(lis), INF_LL) - lis.begin(); for (auto &u : G[v]) { if (u == p) continue; dfs(u, v); } lis[undo.top().fs] = undo.top().sc; undo.pop(); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int64 N, M, Q; cin >> N >> M >> Q; vector<int> comb(M + N - 1, 0); REP(i, N) comb[M - i - 1] = 1; vector<int64> a(Q), b(Q), c(Q), d(Q); REP(i, Q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int64 res = 0; do { vector<int64> A; int64 cnt = 0; REP(i, comb.size()) { if (comb[i]) A.push_back(cnt + 1); else cnt++; } int64 sum = 0; REP(i, Q) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i]; } chmax(res, sum); } while (next_permutation(all(comb))); cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for (int64 i = 0; i < (n); i++) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } int64 N; vector<int64> a; vector<int64> G[212345]; vector<int64> res; stack<PLL> undo; vector<int64> lis; void dfs(int64 v, int64 p) { int64 idx = lower_bound(all(lis), a[v]) - lis.begin(); undo.emplace(idx, lis[idx]); lis[idx] = a[v]; res[v] = lower_bound(all(lis), INF_LL) - lis.begin(); for (auto &u : G[v]) { if (u == p) continue; dfs(u, v); } lis[undo.top().fs] = undo.top().sc; undo.pop(); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int64 N, M, Q; cin >> N >> M >> Q; vector<int> comb(M + N - 1, 0); REP(i, N) comb[M + N - 1 - i - 1] = 1; vector<int64> a(Q), b(Q), c(Q), d(Q); REP(i, Q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int64 res = 0; do { vector<int64> A; int64 cnt = 0; REP(i, comb.size()) { if (comb[i]) A.push_back(cnt + 1); else cnt++; } int64 sum = 0; REP(i, Q) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i]; } chmax(res, sum); } while (next_permutation(all(comb))); cout << res << endl; }
replace
76
77
76
77
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<int> a, b, c, d; int n, m, q; int ans; void dfs(vector<int> A) { if (A.size() == n + 1) { int sum = 0; for (int i = 0; i < q; i++) { if (A[b[i]] - A[a[i]] == c[i]) { sum += d[i]; } } ans = max(ans, sum); return; } a.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<int> A(1, 1); dfs(A); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> a, b, c, d; int n, m, q; int ans; void dfs(vector<int> A) { if (A.size() == n + 1) { int sum = 0; for (int i = 0; i < q; i++) { if (A[b[i]] - A[a[i]] == c[i]) { sum += d[i]; } } ans = max(ans, sum); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector<int> A(1, 1); dfs(A); cout << ans << endl; return 0; }
replace
17
18
17
18
-11
p02695
C++
Runtime Error
#include <algorithm> #include <iostream> int A[10], a[10], b[10], c[10], d[10]; int ans; int n, m, q; void dfs(int k) { if (k == n) { int sum = 0; for (int i = 0; i < q; ++i) { if (A[b[i]] - A[a[i]] == c[i]) sum += d[i]; } ans = std::max(ans, sum); return; } for (int i = A[k - 1]; i <= m; ++i) { A[k] = i; dfs(k + 1); } } int main() { A[0] = 1; std::cin >> n >> m >> q; for (int i = 0; i < q; ++i) { std::cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i]; --b[i]; } dfs(1); std::cout << ans << std::endl; return 0; }
#include <algorithm> #include <iostream> int A[10], a[50], b[50], c[50], d[50]; int ans; int n, m, q; void dfs(int k) { if (k == n) { int sum = 0; for (int i = 0; i < q; ++i) { if (A[b[i]] - A[a[i]] == c[i]) sum += d[i]; } ans = std::max(ans, sum); return; } for (int i = A[k - 1]; i <= m; ++i) { A[k] = i; dfs(k + 1); } } int main() { A[0] = 1; std::cin >> n >> m >> q; for (int i = 0; i < q; ++i) { std::cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i]; --b[i]; } dfs(1); std::cout << ans << std::endl; return 0; }
replace
3
4
3
4
0
p02695
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; using ll = long long int; int main(void) { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int mx = 0, score; vector<int> s(n, 1); do { score = 0; // for (int i = 0; i < n; i++) cout << s[i]; // cout << " "; for (int i = 0; i < q; i++) { if (s[b[i] - 1] - s[a[i] - 1] == c[i]) score += d[i]; } // cout << score << endl; mx = max(mx, score); for (int i = 0; i < n; i++) { if (i == 0) s[n - 1 - i]++; if (s[n - 1 - i] > m) { s[n - 2 - i]++; s[n - 1 - i] = s[n - 2 - i]; } } } while (s[0] != m); cout << mx << endl; }
#include <iostream> #include <vector> using namespace std; using ll = long long int; int main(void) { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int mx = 0, score; vector<int> s(n, 1); do { score = 0; // for (int i = 0; i < n; i++) cout << s[i]; // cout << " "; for (int i = 0; i < q; i++) { if (s[b[i] - 1] - s[a[i] - 1] == c[i]) score += d[i]; } // cout << score << endl; mx = max(mx, score); s[n - 1]++; if (m != 1) { for (int i = 0; i < n; i++) { if (s[n - 1 - i] > m) { s[n - 2 - i]++; for (int j = 0; j <= i; j++) { s[n - 1 - i + j] = s[n - 2 - i]; } } } } } while (s[0] != m); cout << mx << endl; }
replace
25
31
25
34
0
p02695
C++
Runtime Error
#include <iostream> using namespace std; #ifndef ONLINE_JUDGE #include <fstream> #define cin fin #define cout fout ifstream fin("test.in"); ofstream fout("test.out"); #endif int p[10]; int n, m, q; int a[60], b[60], c[60], d[60]; int f(int i, int fn) { if (i == n + 1) { int r = 0; /*for (int j = 1; j <= n; j++) cout << p[j] << ' ';*/ for (int j = 1; j <= q; j++) { if (p[b[j]] - p[a[j]] == c[j]) r += d[j]; } // cout << r << endl; return r; } int r = 0; for (int j = fn; j <= m; j++) { // intram cu toate permutarile de lungime n cu valori de la 1 la m p[i] = j; r = max(r, f(i + 1, j)); } return r; } int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; /*for (int i = 0; i < q; i++) { a[i]--; b[i]--; }*/ cout << f(1, 1) << endl; return 0; }
#include <iostream> using namespace std; #ifndef ONLINE_JUDGE #include <fstream> #define cin fin #define cout fout ifstream fin("test.in"); ofstream fout("test.out"); #endif int p[11]; int n, m, q; int a[60], b[60], c[60], d[60]; int f(int i, int fn) { if (i == n + 1) { int r = 0; /*for (int j = 1; j <= n; j++) cout << p[j] << ' ';*/ for (int j = 1; j <= q; j++) { if (p[b[j]] - p[a[j]] == c[j]) r += d[j]; } // cout << r << endl; return r; } int r = 0; for (int j = fn; j <= m; j++) { // intram cu toate permutarile de lungime n cu valori de la 1 la m p[i] = j; r = max(r, f(i + 1, j)); } return r; } int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; /*for (int i = 0; i < q; i++) { a[i]--; b[i]--; }*/ cout << f(1, 1) << endl; return 0; }
replace
12
13
12
13
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int MOD = 1e9 + 7; using ll = long long; int main() { int n, m, q; cin >> n >> m >> q; vector<ll> a(n), b(n), c(n), d(n); rep(i, q) { int A, B, C, D; cin >> A >> B >> C >> D; A--; B--; a[i] = A; b[i] = B; c[i] = C; d[i] = D; } vector<vector<ll>> memo; for (int A = 1; A <= m; A++) { for (int B = A; B <= m; B++) { for (int C = B; C <= m; C++) { for (int D = C; D <= m; D++) { for (int E = D; E <= m; E++) { for (int F = E; F <= m; F++) { for (int G = F; G <= m; G++) { for (int H = G; H <= m; H++) { for (int I = H; I <= m; I++) { for (int J = I; J <= m; J++) { memo.push_back({A, B, C, D, E, F, G, H, I, J}); } } } } } } } } } } ll ans = 0; ll l = memo.size(); for (ll i = 0; i < l; i++) { const vector<ll> test = memo[i]; if (test.size() == 0) continue; ll res = 0; rep(j, q) { if (test[b[j]] - test[a[j]] == c[j]) res += d[j]; } ans = max(ans, res); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int MOD = 1e9 + 7; using ll = long long; int main() { int n, m, q; cin >> n >> m >> q; vector<ll> a(q), b(q), c(q), d(q); rep(i, q) { int A, B, C, D; cin >> A >> B >> C >> D; A--; B--; a[i] = A; b[i] = B; c[i] = C; d[i] = D; } vector<vector<ll>> memo; for (int A = 1; A <= m; A++) { for (int B = A; B <= m; B++) { for (int C = B; C <= m; C++) { for (int D = C; D <= m; D++) { for (int E = D; E <= m; E++) { for (int F = E; F <= m; F++) { for (int G = F; G <= m; G++) { for (int H = G; H <= m; H++) { for (int I = H; I <= m; I++) { for (int J = I; J <= m; J++) { memo.push_back({A, B, C, D, E, F, G, H, I, J}); } } } } } } } } } } ll ans = 0; ll l = memo.size(); for (ll i = 0; i < l; i++) { const vector<ll> test = memo[i]; if (test.size() == 0) continue; ll res = 0; rep(j, q) { if (test[b[j]] - test[a[j]] == c[j]) res += d[j]; } ans = max(ans, res); } cout << ans << endl; }
replace
9
10
9
10
0
p02695
C++
Runtime Error
#include <iostream> #include <math.h> #include <set> #include <stdio.h> #include <stdlib.h> // などの必要なインクルードファイルすべて(3章の各標準ライブラリの説明でそれぞれ書いています) using namespace std; int N, M, Q; int a[50][4]; int A[10]; int t, c; int tokuten(int k) { int i, j; if (k == N) { c = 0; for (j = 0; j < Q; j++) { if ((A[a[j][1] - 1] - A[a[j][0] - 1]) == a[j][2]) { c = c + a[j][3]; } } if ((t < c)) { t = c; } // 最高点dしたら入れ替え } else { if (k == 0) { for (i = 1; i < M + 1; i++) { A[k] = i; tokuten(k + 1); } } else { for (i = A[k - 1]; i < M + 1; i++) { A[k] = i; tokuten(k + 1); } } } } int main(void) { int i, j; t = 0; scanf("%d%d%d", &N, &M, &Q); for (i = 0; i < Q; i++) { scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]); } for (i = 0; i < N; i++) { A[i] = 1; } tokuten(0); printf("%d", t); }
#include <iostream> #include <math.h> #include <set> #include <stdio.h> #include <stdlib.h> // などの必要なインクルードファイルすべて(3章の各標準ライブラリの説明でそれぞれ書いています) using namespace std; int N, M, Q; int a[50][4]; int A[10]; int t, c; void tokuten(int k) { int i, j; if (k == N) { c = 0; for (j = 0; j < Q; j++) { if ((A[a[j][1] - 1] - A[a[j][0] - 1]) == a[j][2]) { c = c + a[j][3]; } } if ((t < c)) { t = c; } // 最高点dしたら入れ替え } else { if (k == 0) { for (i = 1; i < M + 1; i++) { A[k] = i; tokuten(k + 1); } } else { for (i = A[k - 1]; i < M + 1; i++) { A[k] = i; tokuten(k + 1); } } } } int main(void) { int i, j; t = 0; scanf("%d%d%d", &N, &M, &Q); for (i = 0; i < Q; i++) { scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]); } for (i = 0; i < N; i++) { A[i] = 1; } tokuten(0); printf("%d", t); }
replace
17
18
17
18
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> a, b, c, d; int ans = 0; void dfs(vector<int> k) { if ((int)k.size() == m + 1) { int sco = 0; for (int i = 0; i < q; i++) { if (k.at(b.at(i)) - k.at(a.at(i)) == c.at(i)) sco += d.at(i); } ans = max(ans, sco); return; } k.push_back(k.back()); while (k.back() <= m) { dfs(k); k.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); for (int i = 0; i < q; i++) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i); vector<int> sam(1, 1); dfs(sam); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, m, q; vector<int> a, b, c, d; int ans = 0; void dfs(vector<int> k) { if ((int)k.size() == n + 1) { int sco = 0; for (int i = 0; i < q; i++) { if (k.at(b.at(i)) - k.at(a.at(i)) == c.at(i)) sco += d.at(i); } ans = max(ans, sco); return; } k.push_back(k.back()); while (k.back() <= m) { dfs(k); k.back()++; } } int main() { cin >> n >> m >> q; a = b = c = d = vector<int>(q); for (int i = 0; i < q; i++) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i); vector<int> sam(1, 1); dfs(sam); cout << ans << endl; }
replace
7
8
7
8
0
p02695
C++
Runtime Error
/*input 10 10 1 1 10 9 1 */ #include "bits/stdc++.h" using namespace std; #define pb push_back #define mod 998244353 #define int long long int n, m, q; struct node { int a, b, c, d; node(int a1, int b1, int c1, int d1) : a(a1), b(b1), c(c1), d(d1) {} node() {} }; vector<node> Q; int ans = 0; int cal(vector<int> &v) { int ans = 0; for (auto it : Q) { if (v[it.b] - v[it.a] == it.c) ans += it.d; } return ans; } void rec(int index, int val, vector<int> &v) { if (index == n) { ans = max(ans, cal(v)); return; } v[index] = val; for (int i = val; i <= m; i++) { rec(index + 1, i, v); } } signed main() { cin >> n >> m >> q; Q.resize(q); for (int i = 0; i <= q; i++) { int a, b, c, d; cin >> a >> b >> c >> d; b--; a--; Q[i] = node(a, b, c, d); } vector<int> v(n); rec(0, 1, v); cout << ans << endl; }
/*input 10 10 1 1 10 9 1 */ #include "bits/stdc++.h" using namespace std; #define pb push_back #define mod 998244353 #define int long long int n, m, q; struct node { int a, b, c, d; node(int a1, int b1, int c1, int d1) : a(a1), b(b1), c(c1), d(d1) {} node() {} }; vector<node> Q; int ans = 0; int cal(vector<int> &v) { int ans = 0; for (auto it : Q) { if (v[it.b] - v[it.a] == it.c) ans += it.d; } return ans; } void rec(int index, int val, vector<int> &v) { if (index == n) { ans = max(ans, cal(v)); return; } v[index] = val; for (int i = val; i <= m; i++) { rec(index + 1, i, v); } } signed main() { cin >> n >> m >> q; Q.resize(q); for (int i = 0; i < q; i++) { int a, b, c, d; cin >> a >> b >> c >> d; b--; a--; Q[i] = node(a, b, c, d); } vector<int> v(n); rec(0, 1, v); cout << ans << endl; }
replace
43
44
43
44
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1LL << 60; long long N; long long M; long long Q; vector<ll> a, b, c, d; ll ans = 0; // i: 何回めか // v: 配列 void dfs(int cnt, int i, vector<int> v) { if (cnt >= N) { // 操作 // rep(k, v.size()) { // cout << v[k] << " "; // } // cout << endl; ll tmp = 0; rep(k, Q) { ll diff = v[b[k]] - v[a[k]]; if (diff == c[k]) { tmp += d[k]; } } ans = max(ans, tmp); return; } for (int m = i; m <= M; m++) { dfs(cnt + 1, m, v); } } int main() { scanf("%lld", &N); scanf("%lld", &M); scanf("%lld", &Q); a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q); for (int i = 0; i < Q; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); scanf("%lld", &d[i]); a[i]--; b[i]--; } // vector<int> tmp; // dfs(0, 1, tmp); // return 0; for (int i = 1; i <= M; i++) { vector<int> tmp; dfs(0, i, tmp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1LL << 60; long long N; long long M; long long Q; vector<ll> a, b, c, d; ll ans = 0; // i: 何回めか // v: 配列 void dfs(int cnt, int i, vector<int> v) { if (cnt >= N) { // 操作 // rep(k, v.size()) { // cout << v[k] << " "; // } // cout << endl; ll tmp = 0; rep(k, Q) { ll diff = v[b[k]] - v[a[k]]; if (diff == c[k]) { tmp += d[k]; } } ans = max(ans, tmp); return; } v.push_back(i); for (int m = i; m <= M; m++) { dfs(cnt + 1, m, v); } } int main() { scanf("%lld", &N); scanf("%lld", &M); scanf("%lld", &Q); a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q); for (int i = 0; i < Q; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); scanf("%lld", &d[i]); a[i]--; b[i]--; } // vector<int> tmp; // dfs(0, 1, tmp); // return 0; for (int i = 1; i <= M; i++) { vector<int> tmp; dfs(0, i, tmp); } cout << ans << endl; return 0; }
insert
33
33
33
34
-11
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int check(vector<int> A, int Q, int r[11][4]) { int score = 0; for (int i = 0; i < Q; i++) { if (A[r[i][1]] - A[r[i][0]] == r[i][2]) { score += r[i][3]; } } return score; } int main(void) { int N, M, Q; std::cin >> N >> M >> Q; int r[11][4]; for (int i = 0; i < Q; i++) { cin >> r[i][0] >> r[i][1] >> r[i][2] >> r[i][3]; } vector<int> A(N + 10); for (int i = 0; i <= N; i++) { A[i] = 1; } A[N + 1] = M; int digit = N, score = 0; while (true) { score = max(score, check(A, Q, r)); if (digit < 1) { digit = 1; } while (A[digit] == A[digit + 1]) { A[digit] = 1; ++digit; if (digit > N) { break; } } if (digit > N) { break; } ++A[digit]; --digit; } printf("%d\n", score); return 0; }
#include <bits/stdc++.h> using namespace std; int check(vector<int> A, int Q, int r[11][4]) { int score = 0; for (int i = 0; i < Q; i++) { if (A[r[i][1]] - A[r[i][0]] == r[i][2]) { score += r[i][3]; } } return score; } int main(void) { int N, M, Q; std::cin >> N >> M >> Q; int r[55][4]; for (int i = 0; i < Q; i++) { cin >> r[i][0] >> r[i][1] >> r[i][2] >> r[i][3]; } vector<int> A(N + 10); for (int i = 0; i <= N; i++) { A[i] = 1; } A[N + 1] = M; int digit = N, score = 0; while (true) { score = max(score, check(A, Q, r)); if (digit < 1) { digit = 1; } while (A[digit] == A[digit + 1]) { A[digit] = 1; ++digit; if (digit > N) { break; } } if (digit > N) { break; } ++A[digit]; --digit; } printf("%d\n", score); return 0; }
replace
15
16
15
16
0
p02695
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) #define fs first #define sc second #define _GLIBCXX_DEBUG template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } template <class S> void print(vector<S> &v) { for (ll i = 0; i < (ll)v.size(); i++) { cerr << v[i] << ' '; } cerr << endl; } template <class S> void print(vector<vector<S>> &v) { for (ll i = 0; i < (ll)v.size(); i++) { for (ll j = 0; j < (ll)v[i].size(); j++) { cerr << v[i][j] << ' '; } cerr << endl; } } int ans = 0; int n, m, q; void dfs(int i, int j, vector<int> A, vector<tuple<int, int, int, int>> &data) { if (i == n) { print(A); int asw = 0; for (auto [a, b, c, d] : data) { if (A[b - 1] - A[a - 1] == c) { asw += d; } } ans = max(ans, asw); return; } for (int k = j; k <= m; k++) { A[i] = k; dfs(i + 1, k, A, data); } } int main(void) { cin >> n >> m >> q; vector<tuple<int, int, int, int>> data; Rep(q) { int a, b, c, d; cin >> a >> b >> c >> d; data.push_back(make_tuple(a, b, c, d)); } dfs(0, 1, vector<int>(n, 0), data); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) #define fs first #define sc second #define _GLIBCXX_DEBUG template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } template <class S> void print(vector<S> &v) { for (ll i = 0; i < (ll)v.size(); i++) { cerr << v[i] << ' '; } cerr << endl; } template <class S> void print(vector<vector<S>> &v) { for (ll i = 0; i < (ll)v.size(); i++) { for (ll j = 0; j < (ll)v[i].size(); j++) { cerr << v[i][j] << ' '; } cerr << endl; } } int ans = 0; int n, m, q; void dfs(int i, int j, vector<int> A, vector<tuple<int, int, int, int>> &data) { if (i == n) { // print(A); int asw = 0; for (auto [a, b, c, d] : data) { if (A[b - 1] - A[a - 1] == c) { asw += d; } } ans = max(ans, asw); return; } for (int k = j; k <= m; k++) { A[i] = k; dfs(i + 1, k, A, data); } } int main(void) { cin >> n >> m >> q; vector<tuple<int, int, int, int>> data; Rep(q) { int a, b, c, d; cin >> a >> b >> c >> d; data.push_back(make_tuple(a, b, c, d)); } dfs(0, 1, vector<int>(n, 0), data); cout << ans << endl; }
replace
38
39
38
39
TLE
p02695
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long const int N = 100005; using namespace std; int A[15], n, m, q, a[55], b[55], c[55], d[55], ans; int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; for (int i = 1; i <= n; i++) A[i] = 1; while (!a[0]) { int res = 0; for (int i = 1; i <= q; i++) if (A[b[i]] - A[a[i]] == c[i]) res += d[i]; ans = max(ans, res); for (int i = n; i >= 0; i--) { if (A[i] < m) { A[i]++; for (int j = i + 1; j <= n; j++) A[j] = A[i]; break; } } } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long const int N = 100005; using namespace std; int A[15], n, m, q, a[55], b[55], c[55], d[55], ans; int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; for (int i = 1; i <= n; i++) A[i] = 1; while (!A[0]) { int res = 0; for (int i = 1; i <= q; i++) if (A[b[i]] - A[a[i]] == c[i]) res += d[i]; ans = max(ans, res); for (int i = n; i >= 0; i--) { if (A[i] < m) { A[i]++; for (int j = i + 1; j <= n; j++) A[j] = A[i]; break; } } } cout << ans; return 0; }
replace
11
12
11
12
TLE
p02695
C++
Runtime Error
#include <iostream> using namespace std; int maxv = 0; struct node { int a, b, c, d; }; node tmp[20]; int arr[20]; int n, m, q; void dfs(int u, int last) { if (u == n + 1) { int sum = 0; for (int i = 1; i <= q; i++) { if (arr[tmp[i].b] - arr[tmp[i].a] == tmp[i].c) { sum += tmp[i].d; } } maxv = max(maxv, sum); return; } for (int i = last; i <= m; i++) { arr[u] = i; dfs(u + 1, i); } } int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { int a, b, c, d; cin >> a >> b >> c >> d; tmp[i] = {a, b, c, d}; } dfs(1, 1); cout << maxv << endl; }
#include <iostream> using namespace std; int maxv = 0; struct node { int a, b, c, d; }; node tmp[100]; int arr[20]; int n, m, q; void dfs(int u, int last) { if (u == n + 1) { int sum = 0; for (int i = 1; i <= q; i++) { if (arr[tmp[i].b] - arr[tmp[i].a] == tmp[i].c) { sum += tmp[i].d; } } maxv = max(maxv, sum); return; } for (int i = last; i <= m; i++) { arr[u] = i; dfs(u + 1, i); } } int main() { cin >> n >> m >> q; for (int i = 1; i <= q; i++) { int a, b, c, d; cin >> a >> b >> c >> d; tmp[i] = {a, b, c, d}; } dfs(1, 1); cout << maxv << endl; }
replace
7
8
7
8
0
p02695
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 = 13; int A[max_n]; int B[max_n]; int C[max_n]; int D[max_n]; int N, M, Q; int G[max_n]; Int rec(int cp, int num) { Int ans = 0; if (cp == N) { for (int i = 0; i < Q; i++) { if (G[B[i]] - G[A[i]] == C[i]) ans += D[i]; } } else { for (int j = num; j <= M; j++) { G[cp] = j; ans = max(ans, rec(cp + 1, j)); } } return ans; } Int solve(void) { Int ans = 0; for (int i = 1; i <= M; i++) { G[0] = i; ans = max(ans, rec(1, i)); } return ans; } int main(void) { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i]; A[i]--; B[i]--; } cout << solve() << 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 = 100; int A[max_n]; int B[max_n]; int C[max_n]; int D[max_n]; int N, M, Q; int G[max_n]; Int rec(int cp, int num) { Int ans = 0; if (cp == N) { for (int i = 0; i < Q; i++) { if (G[B[i]] - G[A[i]] == C[i]) ans += D[i]; } } else { for (int j = num; j <= M; j++) { G[cp] = j; ans = max(ans, rec(cp + 1, j)); } } return ans; } Int solve(void) { Int ans = 0; for (int i = 1; i <= M; i++) { G[0] = i; ans = max(ans, rec(1, i)); } return ans; } int main(void) { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i]; A[i]--; B[i]--; } cout << solve() << endl; return 0; }
replace
24
25
24
25
0
p02695
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <tuple> #include <utility> #include <vector> #define ll long long using namespace std; int main() { int N, M, Q; int ans = 0; cin >> N >> M >> Q; vector<int> A(N + 2); vector<int> v(4 + 2, 0); vector<vector<int>> S(Q + 2, v); for (int i = 0; i < Q; i++) { cin >> S[i][0] >> S[i][1] >> S[i][2] >> S[i][3]; } for (A[0] = 1; A[0] <= M; A[0]++) { for (A[1] = A[0]; A[1] <= M; A[1]++) { for (A[2] = A[1]; A[2] <= M; A[2]++) { for (A[3] = A[2]; A[3] <= M; A[3]++) { for (A[4] = A[3]; A[4] <= M; A[4]++) { for (A[5] = A[4]; A[5] <= M; A[5]++) { for (A[6] = A[5]; A[6] <= M; A[6]++) { for (A[7] = A[6]; A[7] <= M; A[7]++) { for (A[8] = A[7]; A[8] <= M; A[8]++) { for (A[9] = A[8]; A[9] <= M; A[9]++) { int tmp = 0; for (int i = 0; i < Q; i++) { int e = S[i][0]; int f = S[i][1]; int g = S[i][2]; int h = S[i][3]; if (A[f - 1] - A[e - 1] == g) { tmp += h; } } ans = max(ans, tmp); } } } } } } } } } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <tuple> #include <utility> #include <vector> #define ll long long using namespace std; int main() { int N, M, Q; int ans = 0; cin >> N >> M >> Q; vector<int> A(N + 5); vector<int> v(4 + 5, 0); vector<vector<int>> S(Q + 5, v); for (int i = 0; i < Q; i++) { cin >> S[i][0] >> S[i][1] >> S[i][2] >> S[i][3]; } for (A[0] = 1; A[0] <= M; A[0]++) { for (A[1] = A[0]; A[1] <= M; A[1]++) { for (A[2] = A[1]; A[2] <= M; A[2]++) { for (A[3] = A[2]; A[3] <= M; A[3]++) { for (A[4] = A[3]; A[4] <= M; A[4]++) { for (A[5] = A[4]; A[5] <= M; A[5]++) { for (A[6] = A[5]; A[6] <= M; A[6]++) { for (A[7] = A[6]; A[7] <= M; A[7]++) { for (A[8] = A[7]; A[8] <= M; A[8]++) { for (A[9] = A[8]; A[9] <= M; A[9]++) { int tmp = 0; for (int i = 0; i < Q; i++) { int e = S[i][0]; int f = S[i][1]; int g = S[i][2]; int h = S[i][3]; if (A[f - 1] - A[e - 1] == g) { tmp += h; } } ans = max(ans, tmp); } } } } } } } } } } cout << ans << endl; }
replace
13
16
13
16
-11
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<long long> factorial; long long fact(long long n) { if (factorial[n] == -1) factorial[n] = n * fact(n - 1); return factorial[n]; } long long binom(long long n, long long r) { return fact(n) / fact(r) / fact(n - r); } int main() { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i]; vector<int> B(n + m, 0); for (int i = 1; i <= n; ++i) B[i] = 1; factorial.assign(n + m, -1); factorial[0] = 1; int ans = 0; long long t = binom(n + m - 1, n); for (long long j = 0; j < t; ++j) { int cnt = 1; vector<int> A(n + 1, 0); for (int i = 0; i < n + m; ++i) { if (B[i] == 0) { ++A[cnt]; } else { A[cnt + 1] = A[cnt]; ++cnt; } } int tmp = 0; for (int i = 0; i < q; ++i) { if (A[b[i]] - A[a[i]] == c[i]) tmp += d[i]; } ans = max(ans, tmp); next_permutation(B.begin() + 1, B.end()); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; vector<long long> factorial; long long fact(long long n) { if (factorial[n] == -1) factorial[n] = n * fact(n - 1); return factorial[n]; } long long binom(long long n, long long r) { return fact(n) / fact(r) / fact(n - r); } int main() { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; ++i) cin >> a[i] >> b[i] >> c[i] >> d[i]; vector<int> B(n + m, 0); for (int i = 1; i <= n; ++i) B[i] = 1; factorial.assign(n + m, -1); factorial[0] = 1; int ans = 0; long long t = binom(n + m - 1, n); for (long long j = 0; j < t; ++j) { int cnt = 1; vector<int> A(n + 1, 0); for (int i = 0; i < n + m; ++i) { if (B[i] == 0) { ++A[cnt]; } else { if (cnt == n) break; A[cnt + 1] = A[cnt]; ++cnt; } } int tmp = 0; for (int i = 0; i < q; ++i) { if (A[b[i]] - A[a[i]] == c[i]) tmp += d[i]; } ans = max(ans, tmp); next_permutation(B.begin() + 1, B.end()); } cout << ans << endl; }
insert
33
33
33
35
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int N, M, Q; vector<int> a, b, c, d; ll ans; // 参考:解説放送 void dfs(vector<int> A) { if (A.size() == M + 1) //([0]を1にしてi-indexedにしているため) { // calc ans ll ans2 = 0; rep(j, Q) // それぞれのクエリについて { if (A.at(b[j] - 1) - A.at(a[j] - 1) == c[j]) ans2 += d[j]; } ans = max(ans, ans2); return; } A.push_back(A.back()); while (A.back() <= M) { dfs(A); A.back()++; } } int main() { cin >> N >> M >> Q; a = b = c = d = vector<int>(Q); rep(i, Q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; } /*vector <int> a(3); for (int i = 0; i < n; i++) { cin >> a.at(i); }*/
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int N, M, Q; vector<int> a, b, c, d; ll ans; // 参考:解説放送 void dfs(vector<int> A) { if (A.size() == N + 1) //([0]を1にしてi-indexedにしているため) { // calc ans ll ans2 = 0; rep(j, Q) // それぞれのクエリについて { if (A.at(b[j] - 1) - A.at(a[j] - 1) == c[j]) ans2 += d[j]; } ans = max(ans, ans2); return; } A.push_back(A.back()); while (A.back() <= M) { dfs(A); A.back()++; } } int main() { cin >> N >> M >> Q; a = b = c = d = vector<int>(Q); rep(i, Q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; } /*vector <int> a(3); for (int i = 0; i < n; i++) { cin >> a.at(i); }*/
replace
12
13
12
13
0
p02695
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using vi = vector<int>; // 特別に1を最初の要素とする int64_t f(vector<int> &A, int i, int m, vi const &a, vi const &b, vi const &c, vi const &d) { int64_t high = 0; if (i < A.size()) { for (A[i + 1] = A[i]; A[i + 1] <= m; A[i + 1]++) { auto ret = f(A, i + 1, m, a, b, c, d); if (high < ret) high = ret; } return high; } else { // スコアを求める int q = a.size(); int64_t score = 0; for (int j = 0; j < q; j++) { if ((A[b[j]] - A[a[j]]) == c[j]) score += d[j]; } return score; } } int main() { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int64_t high = 0; vi A(n + 1); // 特別に1を最初の要素とする A[0] = 1; high = f(A, 0, m, a, b, c, d); cout << high; }
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using vi = vector<int>; // 特別に1を最初の要素とする int64_t f(vector<int> &A, int i, int m, vi const &a, vi const &b, vi const &c, vi const &d) { int64_t high = 0; if ((i + 1) < A.size()) { for (A[i + 1] = A[i]; A[i + 1] <= m; A[i + 1]++) { auto ret = f(A, i + 1, m, a, b, c, d); if (high < ret) high = ret; } return high; } else { // スコアを求める int q = a.size(); int64_t score = 0; for (int j = 0; j < q; j++) { if ((A[b[j]] - A[a[j]]) == c[j]) score += d[j]; } return score; } } int main() { int n, m, q; cin >> n >> m >> q; vector<int> a(q), b(q), c(q), d(q); for (int i = 0; i < q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int64_t high = 0; vi A(n + 1); // 特別に1を最初の要素とする A[0] = 1; high = f(A, 0, m, a, b, c, d); cout << high; }
replace
18
19
18
19
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef pair<int, int> P; typedef tuple<int, int, int, int> T; #define PI 3.14159265359 #define MOD 1000000007 const int MAX = 510000; int maxd = 0; vector<int> A(11); int N, M, Q; vector<int> a(51); vector<int> b(51); vector<int> c(51); vector<int> d(51); int dfs(int n, int m, int x) { int dn = N - n; A[dn] = x; if (n != 1) { for (int i = x; i <= m; i++) { dfs(n - 1, m, i); } } else { int memo = 0; rep(i, Q) { if (A[b[i]] == (A[a[i]] + c[i])) memo += d[i]; } ::maxd = max(memo, ::maxd); } } int main() { cin >> N >> M >> Q; rep(i, Q) { int x, y, z, w; cin >> x >> y >> z >> w; a[i] = x - 1; b[i] = y - 1; c[i] = z; d[i] = w; } dfs(N, M, 1); cout << maxd; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef pair<int, int> P; typedef tuple<int, int, int, int> T; #define PI 3.14159265359 #define MOD 1000000007 const int MAX = 510000; int maxd = 0; vector<int> A(11); int N, M, Q; vector<int> a(51); vector<int> b(51); vector<int> c(51); vector<int> d(51); void dfs(int n, int m, int x) { int dn = N - n; A[dn] = x; if (n != 1) { for (int i = x; i <= m; i++) { dfs(n - 1, m, i); } } else { int memo = 0; rep(i, Q) { if (A[b[i]] == (A[a[i]] + c[i])) memo += d[i]; } ::maxd = max(memo, ::maxd); } } int main() { cin >> N >> M >> Q; rep(i, Q) { int x, y, z, w; cin >> x >> y >> z >> w; a[i] = x - 1; b[i] = y - 1; c[i] = z; d[i] = w; } dfs(N, M, 1); cout << maxd; }
replace
17
18
17
18
0
p02695
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> //abs()かfabs()で少数絶対値 #include <cstdlib> //abs()で整数絶対値 #include <functional> //sort第三引数greater<型名>()で降順 #include <iomanip> //cout<<setw(数字) で空白による桁揃え #include <iostream> //cout<<right で右揃え #include <queue> #include <string> #include <vector> using namespace std; using ll = long long int; int main() { int N, M, Q; cin >> N >> M >> Q; vector<int> A(N, 1), a(Q), b(Q), c(Q), d(Q); for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int max = 0; do { A[N - 1]++; for (int i = N - 1; i >= 1; i--) { if (A[i] == M + 1) { A[i - 1]++; for (int j = i; j < N; j++) { A[j] = A[i - 1]; } } } int sum = 0; for (int i = 0; i < Q; i++) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) { sum += d[i]; } } if (sum > max) max = sum; } while (A[0] != M); cout << max << endl; return 0; }
#include <algorithm> #include <cmath> //abs()かfabs()で少数絶対値 #include <cstdlib> //abs()で整数絶対値 #include <functional> //sort第三引数greater<型名>()で降順 #include <iomanip> //cout<<setw(数字) で空白による桁揃え #include <iostream> //cout<<right で右揃え #include <queue> #include <string> #include <vector> using namespace std; using ll = long long int; int main() { int N, M, Q; cin >> N >> M >> Q; vector<int> A(N, 1), a(Q), b(Q), c(Q), d(Q); A[N - 1] = 0; for (int i = 0; i < Q; i++) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } int max = 0; do { A[N - 1]++; for (int i = N - 1; i >= 1; i--) { if (A[i] == M + 1) { A[i - 1]++; for (int j = i; j < N; j++) { A[j] = A[i - 1]; } } } int sum = 0; for (int i = 0; i < Q; i++) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) { sum += d[i]; } } if (sum > max) max = sum; } while (A[0] != M); cout << max << endl; return 0; }
insert
17
17
17
18
TLE
p02695
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cassert> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; using edge = struct { ll to; ll cost; }; using point = struct { ll x; ll y; }; typedef string str; typedef std::pair<ll, ll> pl; typedef std::pair<ll, pl> pl3; typedef std::map<string, ll> msl; typedef std::map<char, ll> mcl; typedef std::map<ll, ll> mll; typedef std::vector<ll> vl; typedef std::vector<pl> vpl; typedef std::vector<point> points; typedef std::vector<pl3> vpl3; typedef std::priority_queue<ll> pq; typedef std::priority_queue<ll, vl, greater<ll>> pql; // priority queue taking from the lower value. typedef std::vector<edge> gr; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll INF = MOD * MOD; const long double EPS = 1e-9; const long double PI = 3.14159265358979323846; vpl dirs = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}, // four directions {1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // diagonal {0, 0} // self }; #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define revrep(i, n) for (ll(i) = n - 1; (i) >= 0; (i)--) #define For(i, a, b) for (ll(i) = (a); (i) < (b); (i)++) #define revFor(i, b, a) for (ll(i) = (b)-1; (i) >= (a); (i)--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define isUpper(c) ('a' - c > 0) #define isNum(c) (0 <= (c) - '0' && (c) - '0' <= 9) #define toLower(c) char((c) + 0x20) #define toUpper(c) char((c)-0x20) #define pb push_back #define mp make_pair #define pr(a) cout << (a) #define prl(a) cout << (a) << endl #define prl2(a, b) cout << (a) << " " << (b) << endl #define prl3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define prl4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define prs(a) cout << (a) << " " #define yn(condition) \ if ((condition)) \ prl("Yes"); \ else \ prl("No"); #define YN(condition) \ if ((condition)) \ prl("YES"); \ else \ prl("NO"); #define in1(a) cin >> (a) #define in2(a, b) cin >> (a) >> (b) #define in3(a, b, c) cin >> (a) >> (b) >> (c) #define in4(a, b, c, d) cin >> (a) >> (b) >> (c) >> (d) #define e1 first #define e2 second #define ctol(c) ll((c)) - ll('0') #define ltos(n) to_string((n)) #define items(kv, v) for (auto &(kv) : (v)) #define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)])) #define rsort(a, n) sort(a, a + n, greater<>()) #define Forchar(c, a, z) for (char(c) = (a); (c) <= (z); (c)++) #define cntchar(s, c) count(all((s)), c) #define substring(s, start, end) s.substr((start), (end) - (start) + 1) #define prl_nd(num, digits) \ cout << fixed << setprecision(digits) << (num) << endl; #define XOR(a, b) (a) ^ (b) #define prl_time(s) \ prl3("Elapsed Time:", 1000.0 * (clock() - s) / CLOCKS_PER_SEC, "[ms]"); #define char_to_str(c) string(1, (c)) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define DEBUG(x) cerr << #x << ": " << (x) << endl #define DEBUG_VEC(v) \ cerr << #v << ": "; \ rep(__i, (v).size()) cerr << ((v)[__i]) << ", "; \ cerr << endl struct MaxFlow { struct F_edge { ll to, rev, capacity; F_edge(ll to, ll rev, ll capacity) : to(to), rev(rev), capacity(capacity) {} }; typedef vector<F_edge> F_edges; vector<F_edges> graph; ll n_vertex; // level is the shortest path to get a given node from the source node. vl level, iter; MaxFlow(ll n_vertex) : n_vertex(n_vertex) { graph.resize(n_vertex); } void add_edge(ll from, ll to, ll capacity) { graph[from].pb({to, ll(graph[to].size()), capacity}); graph[to].pb({from, ll(graph[from].size()) - 1, 0}); } void bfs(ll source) { level = vl(n_vertex, -1); level[source] = 0; queue<ll> q; q.push(source); while (!q.empty()) { ll vertex = q.front(); q.pop(); rep(i, graph[vertex].size()) { ll target = graph[vertex][i].to; ll cap_target = graph[vertex][i].capacity; // if the flow can be into the target node, implement below. if (cap_target > 0 && level[target] < 0) { level[target] = level[vertex] + 1; q.push(target); } } } } ll dfs(ll vertex, ll sink, ll flow) { if (vertex == sink) return flow; for (ll &i = iter[vertex]; i < graph[vertex].size(); i++) { ll target = graph[vertex][i].to; ll cap_target = graph[vertex][i].capacity; ll rev_target = graph[vertex][i].rev; // if capasitiy is not full yet and target is farther, // then assign current flow if (cap_target > 0 && level[vertex] < level[target]) { ll d = dfs(target, sink, min(cap_target, flow)); if (d > 0) { // if the flow successfully reaches the sink, reduce the // flow from the capacity graph[vertex][i].capacity -= d; graph[target][rev_target].capacity += d; return d; } } } return 0; } ll dinic(ll source, ll sink) { ll flow = 0; while (true) { bfs(source); // if there is no path leading to the sink, the maximum flow is 0. if (level[sink] < 0) return flow; iter = vl(n_vertex, 0); ll f; while ((f = dfs(source, sink, INF)) > 0) flow += f; } } }; class UnionFind { vl parents, set_size; public: UnionFind() {} UnionFind(ll n) { parents = set_size = vl(n); rep(i, n) { parents[i] = i; set_size[i] = 1LL; } } ll root_find(ll x) { if (parents[x] == x) return x; return parents[x] = root_find(parents[x]); } void unite(ll x, ll y) { x = root_find(x); y = root_find(y); if (x == y) return; if (set_size[x] < set_size[y]) { parents[y] = x; set_size[x] += set_size[y]; } else { parents[x] = y; set_size[y] += set_size[x]; } } bool is_same(ll x, ll y) { // connected or not return root_find(x) == root_find(y); } ll size(ll x) { return set_size[root_find(x)]; } }; /* class LCA{ public: ll N, logN; vl depth, len; gr tree[200005]; // global declaration later. vector<vl> parents; LCA(ll n){ N = n; logN = 0; while (N > (1LL << logN)) logN++; depth = vl(N); len = vl(N); parents = vector<vl>(logN, vl(N)); init(0, -1, 0, 0); build(); } void init(ll source, ll parent, ll d, ll l){ depth[source] = d; parents[0][source] = parent; len[source] = l; rep(i, tree[source].size()){ ll target = tree[source][i].to; ll cost = tree[source][i].cost; if (target == parent) continue; init(target, source, d + 1, cost + l); } } void build(){ rep(k, logN - 1) rep(n, N){ // if there is no parent, -1. // otherwise, the parent of the parent is the parent. if (parents[k][n] < 0) parents[k + 1][n] = -1; else parents[k + 1][n] = parents[k][parents[k][n]]; } } ll query(ll u, ll v){ if (depth[u] > depth[v]) swap(u, v); rep(k, logN) if ((depth[v] - depth[u]) >> k & 1) v = parents[k][v]; if (u == v) return u; revrep(k, logN){ if (parents[k][u] != parents[k][v]){ u = parents[k][u]; v = parents[k][v]; } } return parents[0][u]; } ll distance(ll u, ll v){ ll w = query(u, v); return len[u] + len[v] - 2 * len[w]; } }; */ struct BIT { ll n; vl tree_dat; BIT(ll n) : tree_dat(n + 1, 0), n(n){}; // x: 1001 1010 1100 1011 1101 1111 // x & - x: 0001 0010 0100 0001 0001 0001 // ->: 1010 1100 10000 1100 1100 10000 ll update_func(ll val, ll dat) { // if maximum -> max(val, dat) // return max(val, dat); // if cumulative sum return val + dat; } ll query(ll i) { /* e.g.) i = 10101 itr1. 10101 -> 10100 itr2. 10100 -> 10000 itr3. 10000 -> 00000 (break) */ ll ret = 0; for (ll j = i; j >= 0; j = (j & (j + 1)) - 1) { ret = update_func(ret, tree_dat[j]); } return ret; } ll lower_bound(ll key) { if (key <= 0) return 0; ll left = 0, right = 1; while (right <= n) right *= 2; for (ll i = right; i > 0; i /= 2) { if (left + i <= n && tree_dat[left + i - 1] < key) { key -= tree_dat[left + i - 1]; left += i; } } return left; } void update(ll i, ll val) { /* e.g.) i = 10101, n = 11111 itr1. 10101 -> 10110 itr2. 10110 -> 11000 itr3. 11000 -> 100000 (break) */ if (i < 0) return; for (ll j = i; j < n; j |= j + 1) { tree_dat[j] = update_func(val, tree_dat[j]); } } }; ll gcd(ll m, ll n) { ll a = max(m, n); ll b = min(m, n); while (b != 1 && b != 0) { a %= b; swap(a, b); } return b == 1 ? 1 : a; } ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } ll power_mod(ll a, ll power, ll mod) { ll value = 1; while (power != 0) { if (power & 1) value = (value * a) % mod; a = (a * a) % mod; power = power >> 1; } return value % mod; } ll modinv(ll a, ll mod) { return power_mod(a, mod - 2, mod); } ll power_normal(ll a, ll power) { ll value = 1; while (power != 0) { if (power & 1) value = value * a; a = a * a; power = power >> 1; } return value; } ll comb_memo[55][55]; ll pascal_triangle(ll n) { comb_memo[0][0] = 1; For(i, 1, n + 1) rep(j, i + 1) { comb_memo[i][j] += comb_memo[i - 1][j]; if (j > 0) comb_memo[i][j] += comb_memo[i - 1][j - 1]; } } ll combination(ll n, ll r, ll mod) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { ll num = (n - i) % mod, den = (i + 1) % mod; (numerator *= num) %= mod; (denomenator *= modinv(den, mod)) %= mod; } return (numerator * denomenator) % mod; } ll combination_memo(ll n, ll r, ll pre, ll mod) { // pre = nCr-1 // return nCr if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = ll(n - r + 1) % mod; ll denomenator = modinv(r, mod) % mod; ll val = (numerator * denomenator) % mod; val *= pre; return val % mod; } ll combination_no_mod(ll n, ll r) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { numerator *= n - i; denomenator *= i + 1; ll g = gcd(numerator, denomenator); numerator /= g; denomenator /= g; } return numerator; } ld log_combination(ll n, ll r) { if (n == r && n == 0) return 0; else if (n <= 0 || r < 0 || r > n) return -INF; ld val = 0; for (ll i = 0; i < r; i++) { val += log(n - i); val -= log(i + 1); } return val; } ll bin_search(ll key, ll A[], ll left, ll right) { // return the index idx where A[idx] = key. // A[left] is start and A[right] is end.. // In other words, A[right], not A[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (A[mid] == key) return mid; else if (A[mid] > key) right = mid - 1; else if (A[mid] < key) left = mid + 1; } return -1; } /* ll bin_search_temp(ll left, ll right, callable judge){ while(right > left){ // when seeking lower bound ll mid = (right + left) / 2; if (judge(mid)) right = mid; else left = mid + 1; // when seeking upper bound ll mid = (right + left + 1) / 2; if (judge(mid)) left = mid; else right = mid - 1; } return right; } trinary_search // Care the value EPS!!! Compare to the condition ld left = 0; ld right = p; while(abs(right - left) > EPS){ ld left2 = (2 * left + right) / 3.0; ld right2 = (left + 2 * right) / 3.0; ld f1 = tak_func(left2); ld f2 = tak_func(right2); if (f1 <= f2) right = right2; else if (f2 <= f1) left = left2; } */ ll lower_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] >= key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] < key && key <= A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] < key && key <= A[mid]) return mid; else if (A[mid - 1] >= key) right = mid - 1; else if (A[mid] < key) left = mid; } return -1; // all the elements < key } ll inf_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] > key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] <= key && key < A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] <= key && key < A[mid]) return mid; else if (A[mid - 1] > key) right = mid - 1; else if (A[mid] <= key) left = mid; } return -1; // all the elements <= key } ll upper_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] <= key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] <= key && key < A[right]) return right - 1; else return -1; } if (A[mid] <= key && key < A[mid + 1]) return mid; else if (A[mid] > key) right = mid; else if (A[mid + 1] <= key) left = mid + 1; } return -1; // all the elements > key } ll sup_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] < key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] < key && key <= A[right]) return right - 1; else return -1; } if (A[mid] < key && key <= A[mid + 1]) return mid; else if (A[mid] >= key) right = mid; else if (A[mid + 1] < key) left = mid + 1; } return -1; // all the elements >= key } ll bin_search_vector(ll key, vl v, ll left, ll right) { // return the index idx where v[idx] = key. // v[left] is start and v[right] is end.. // In other words, v[right], not v[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (v[mid] == key) return mid; else if (v[mid] > key) right = mid - 1; else if (v[mid] < key) left = mid + 1; } return -1; } ll lower_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] < key <= v[N] // N == -1 if all the elements < key return lower_bound(all(v), key) - v.begin(); } ll inf_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] <= key < v[N] <= key + 1 // N == -1 if all the elements <= key return lower_bound(all(v), key + 1) - v.begin(); } ll upper_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key < v[N + 1] // N == -1 if all the elements > key return upper_bound(all(v), key) - v.begin(); // (- 1) } ll sup_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key - 1 < key <= v[N + 1] // N == -1 if all the elements >= key return upper_bound(all(v), key - 1) - v.begin() - 1; } ll fact(ll n) { if (n == 0) return 1; return n * fact(n - 1); } ll fact_mod(ll n, ll mod) { if (n == 0) return 1; return n * fact_mod(n - 1, mod); } bool is_prime(ll n) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } ll bool_sum(ll a1, ll a2) { if (a1 == 1 || a2 == 1) return 1; return 0; } mll prime_factorization(ll n) { ll i = 2; mll table; while (i * i <= n) { while (n % i == 0) { table[i]++; n /= i; } i++; } if (n > 1) table[n] = 1; return table; } vl divisor_table(ll n) { vl table; ll i = 1; while (i * i <= n) { if (n % i == 0) { table.pb(i); if (i * i != n) table.pb(n / i); } i++; } sort(all(table)); return table; } ll char_to_idx(char c) { ll idx = 0; Forchar(cc, 'a', 'z') { if (c == cc) return idx; else idx++; } } vl z_algorithm(str s) { ll n = s.length(); vl res(n); res[0] = n; ll i1 = 1, i2 = 0; while (i1 < n) { while (i1 + i2 < n && s[i2] == s[i1 + i2]) ++i2; res[i1] = i2; if (i2 == 0) { ++i1; continue; } ll i3 = 1; while (i1 + i3 < n && i3 + res[i3] < i2) { res[i1 + i3] = res[i3]; ++i3; } i1 += i3, i2 -= i3; } return res; } ll big_number_mod(str s, ll mod) { ll l = s.length(); ll idx = 0; ll val = 0; ll tenth = 1; while (idx < l) { ll m = ctol(s[l - 1 - idx]); val += (m * tenth) % mod; val %= mod; tenth *= 10; tenth %= mod; idx++; } return val; } str bin_expression(ll n, ll dig) { str s = ""; rep(i, dig) { s += ltos(n % 2); n /= 2; } reverse(all(s)); return s; } ll string_to_ll(str s) { ll l = s.length(); ll idx = 0; ll val = 0; ll tenth = 1; while (idx < l) { ll m = ctol(s[l - 1 - idx]); val += (m * tenth); tenth *= 10; idx++; } return val; } str reflected_string(str s) { str t, u; ll n = s.length(); t = s; reverse(all(t)); u = substring(t, 0, n - 2) + s + substring(t, 1, n - 1); return u; } ld distance_between_point_line(point l_begin, point l_end, point p) { ll xl1 = l_begin.x, yl1 = l_begin.y; ll xl2 = l_end.x, yl2 = l_end.y; ll xp = p.x, yp = p.y; ll a = yl2 - yl1; ll b = -xl2 + xl1; ll c = -a * xl2 - b * yl2; return abs(ld(a * xp + b * yp + c)) / ld(sqrt(a * a + b * b)); } bool is_cross(point l1_begin, point l1_end, point l2_begin, point l2_end) { ll x1 = l1_begin.x, y1 = l1_begin.y; ll x2 = l1_end.x, y2 = l1_end.y; ll x3 = l2_begin.x, y3 = l2_begin.y; ll x4 = l2_end.x, y4 = l2_end.y; ll val1 = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3); ll val2 = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4); ll val3 = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1); ll val4 = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2); return val1 * val2 < 0 && val3 * val4 < 0; } ld space_of_triangle(point p1, point p2, point p3) { ll x1 = p1.x, y1 = p1.y; ll x2 = p2.x, y2 = p2.y; ll x3 = p3.x, y3 = p3.y; ll v1 = x2 - x1; ll u1 = y2 - y1; ll v2 = x3 - x1; ll u2 = y3 - y1; ld s = ld(v1 * u2 - u1 * v2) / ld(2); return abs(s); } pair<point, ll> center_2det_of_3points(point p1, point p2, point p3) { ll x1 = p1.x, y1 = p1.y; ll x2 = p2.x, y2 = p2.y; ll x3 = p3.x, y3 = p3.y; ll c2x_2 = x2 + x1, c2y_2 = y2 + y1; ll c3x_2 = x3 + x1, c3y_2 = y3 + y1; ll b2y = x2 - x1, b2x = -y2 + y1; ll b3y = x3 - x1, b3x = -y3 + y1; ll x1_2 = c3x_2 * b3y - c3y_2 * b3x, y1_2 = c2x_2 * b2y - c2y_2 * b2x; ll det = -b3y * b2x + b3x * b2y; if (det == 0) return {{INF, INF}, det}; ll cx_2det = -b2x * x1_2 + b3x * y1_2, cy_2det = -b2y * x1_2 + b3y * y1_2; return {{cx_2det, cy_2det}, det}; } ll inversion_number(vl a, ll a_max) { /* Paramters --------- a: vector<ll> All the elements must be non-negative. Prefably the elements are compressed to reduce the computational cost. a_max: ll The maximum value of the vector a or the value bigger than the value stated previously. */ BIT bit(a_max + 1); ll val = 0; rep(i, a.size()) { // i is the number of elements that have lower index than a[i]. // call the number of elements that have lower value than a[i] // by subtracting these two, the residual number is the number of elements // that have larger value val += i - bit.query(a[i] - 1); // cumulative sum from 0 to a[i] - 1 bit.update(a[i], 1); } return val; } template <typename T> vector<T> compress(vector<T> v) { // sort and remove all the duplicated values sort(all(v)); v.erase(unique(all(v)), v.end()); return v; } template <typename T> map<T, ll> dict(const vector<T> &v) { map<T, ll> d; rep(i, v.size()) d[v[i]] = i; return d; } /* const ll N_VERTEX = 310; ll a, b, t; ll dist[N_VERTEX][N_VERTEX]; void warshall_floyd(ll n){ // rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(k, n) rep(i, n) rep(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } int main(void){ in2(n, m); rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(i, m){ in3(a, b, t); a--; b--; dist[a][b] = t; dist[b][a] = t; } warshall_floyd(n); } ll dist[1005], vertex_pre[1005]; void dijkstra(ll start, ll n) { priority_queue<pl, vector<pl>, greater<pl>> edge_costs; fill(dist, dist + n, INF); // fill(vertex_pre, vertex_pre + n, -1); dist[start] = 0; edge_costs.push(pl(0, start)); while (!edge_costs.empty()) { pl edge_cost = edge_costs.top(); edge_costs.pop(); ll idx = edge_cost.second; ll cost = edge_cost.first; if (dist[idx] < cost) continue; rep(i, graph[idx].size()){ edge e = graph[idx][i]; if (dist[e.to] > dist[idx] + e.cost){ dist[e.to] = dist[idx] + e.cost; // vertex_pre[e.to] = idx; edge_costs.push(pl(dist[e.to], e.to)); } } } } vl get_predecessor(ll g){ vl path; for (; g != -1; g = vertex_pre[g]) path.pb(g); reverse(all(path)); return path; } int main(void){ in2(n, m); rep(i, m){ in3(a, b, t); a--; b--; G[a].pb({b, t}); G[b].pb({a, t}); } dijkstra(0, n); } # ABC061D bool find_negative_cycle(ll goal){ rep(i, n) rep(v, n) rep(k, graph[v].size()){ edge e = graph[v][k]; if (dist[e.to] != INF && dist[e.to] > dist[v] + e.cost){ dist[e.to] = -INF; if (goal == -1) return true; else if (goal == e.to) return true; } } return false; } bool bellman_ford(ll start, ll n, ll goal){ // if there is a closed circuit, it returns false. (when goal == -1) // if the distance to goal cannot be obtained, it returns false (when goal != -1) fill(dist, dist + n, INF); dist[start] = 0; rep(i, n) rep(v, n) rep(k, graph[v].size()){ edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) dist[e.to] = dist[v] + e.cost; } if (find_negative_cycle(goal)) return false; return true; } */ /* # 1. The usage of map pair map<pl, ll> cnt; cnt[{i, j}] = 0; items(kv, cnt){ prl2(kv.first, kv.second); } # 2. The usage of next_permutation and combination (factorial search) ll a[8]; rep(i, 8) a[i] = i; sort(a, a + 8); do{ }while(next_permutation(a, a+n)); // here, combination ll n, r; ll i1, i2, ..., ir; For(i1, n - r, n) For(i2, n - r - 1, i1) ... For(ir, n - 2 * r + 1, irr){ process;} # 3. bit search ll n; in1(n); const ll base = 3; ll upper = power_normal(base, n); rep(i, upper){ ll tmp = i; rep(j, n){ rep(k, base) if (tmp % base == k) prl(k); tmp /= base; } } # 4. imos method // used when we would like to count the number which // shows how many times the numbers between l and r belongs to smt. // This method is composed of three process. ll n, m, s[MAX_M], l, r; in2(n, m); rep(i, m) s[i] = 0; // 1st step rep(i, n){ in3(l, r, c); l--; r--; // if l starts from 1. s[l] += c; s[r + 1] -= c; } // 2nd step rep(i, m - 1) s[i + 1] += s[i]; // 3rd step: judgement... #5. shakutori method (syakutori) // 1. strech right side while the condition is met. // 2. renew the answer // 3. increments left side // 4. Back to 1. (l <= r must be satisfied all the time.) ll l = 0; ll r = 0; while (l < n){ r = max(r, l); if (l == r) r++; while(r < n && cond) r++; answer += r - l; l++; } prl(answer); #6. priority queue pq q; ll answer = 0; ll v; rep(i, n) q.push(a[i]); rep(i, m){ v = q.top(); q.pop(); // get the top value and dump the value from queue v /= 2; q.push(v); // add the new value } while(!q.empty()){ answer += q.top(); q.pop(); } #7. The shortest path (distance) between the k-th edge and another edge (Tree) ll depth[MAX_N]; gr tree[MAX_N]; void dfs(ll source, ll parent, ll all_cost){ depth[source] = all_cost; items(e, tree[source]){ if (e.to == parent) continue; dfs(e.to, source, all_cost + e.cost); } } ll n, k, a, b, c; in2(n, k); rep(i, n - 1){ in3(a, b, c); a--; b--; tree[a].pb({b, c}); tree[b].pb({a, c}); } k--; dfs(k, -1, 0); #10. Visiting Subtree using recurrent function (ABC138D) gr tree[MAX_N]; ll c[MAX_N]; bool visited[MAX_N]; void dfs(ll source, ll parent, ll val){ visited[source] = true; c[source] += val; rep(i, tree[source].size()){ rep(i, m){ll res = n % match[i].e1;} ll vertex = tree[source][i].to; if (vertex == parent) continue; dfs(vertex, source, c[source]); } } #11. bfs ABC146D, ABC007C 1. first create a tree. 2. start searching from a node. 3. do some processes and push nodes connected with a given target node in BFS. 4. repeat a series of procedure until queue is empty. queue<pl> q; void bfs(ll source, ll parents){ ll n_edge = G[source].size(); if (parents != -1) dist[source] = min(dist[source], dist[parents] + 1); if (visited[source]) return; visited[source] = true; rep(idx, n_edge){ ll target = G[source][idx].to; if (target == parents) continue; q.push(mp(target, source)); } } q.push(mp(sg.e1, -1)); while(!q.empty()){ pl source = q.front(); q.pop(); bfs(source.e1, source.e2); } #12. grid to distance matrix (dx, dy) ll w, h; ll pos_to_idx(ll x, ll y){ return y * w + x; } pl idx_to_pos(ll idx){ return mp(idx % w, idx / w); } int main(void){ in2(h, w); rep(y, h){ in1(s); rep(x, w){ if (s[x] == '#') wall[x][y] = true; else wall[x][y] = false; } } rep(i1, h * w)rep(i2, h * w) dist[i1][i2] = INF * (i1 != i2); rep(x, w)rep(y, h){ ll idx1 = pos_to_idx(x, y); ll idx2; if (wall[x][y]) continue; if (x != 0 && !wall[x - 1][y]){ idx2 = pos_to_idx(x - 1, y); // if warshall floyd dist[idx1][idx2] = 1; // if dijkstra // graph[idx1].pb({idx2, 1}); } if (x != w - 1 && !wall[x + 1][y]){ idx2 = pos_to_idx(x + 1, y); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != 0 && !wall[x][y - 1]){ idx2 = pos_to_idx(x, y - 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != h - 1 && !wall[x][y + 1]){ idx2 = pos_to_idx(x, y + 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } } } */ /* # the operators regarding bit & (AND), | (OR), ^ (XOR) - (REVERSE), >> (SMALLER SHIFT) << (BIGGER SHIFT) x1: 0000 0001 0010 0101 0110 0111 0111 x2: xxxx 0001 0011 0100 0101 1000 0110 x1 & x2: 0000 0001 0010 0100 0100 0000 0110 x: 1001 1010 1100 1011 1101 1111 x & - x: 0001 0010 0100 0001 0001 0001 sum: 1010 1100 10000 1100 1100 10000 x << y is x * 2 ** y x >> y is rep(i, y) x = x // 2 ####### Attention ####### 1 << i and 1LL << i is different. If programs show WA, try switch to this one. Let S be a bit sequence and i be a non-negative integer S & (1 << i) -> if true, i in S S | (1 << i) -> S union {i} S & -(1 << i) -> S - {i} __builtin_popcount(S) -> the number of elements in S S = 0 -> S is an empty set __builtin_popcountl(i) -> the number of 1 in binary S = (1 << n) - 1 -> S includes all the elements up to the n-th #Conditional Operator condition ? true : false; #iterator type declaration: auto value reference: *itr increment: itr++ decrement: itr-- substitution of value: *itr = smt # inclusion-exclusion principle |U[i = 1 to n] Ai| = sum[i = 1 to n] |Ai| - sum[i < j]|Ai ^ Aj| + ... + (-1)^(n - 1) |^[i = 1 to n]Ai| */ const ll MAX_N = 200005; bool okay = false; ll answer = 0; ll n, m, q; vl a, b, c, d; ll target[140000]; ll next_combination(ll sub) { /* ll n, k; ll bit = (1 << k) - 1; for (; bit < (1 << n); bit = next_combination(bit)){ bool ith = bit & (1 << i); procedures... } */ ll x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } void solve() { a = b = c = d = vl(q); rep(i, q) { in4(a[i], b[i], c[i], d[i]); a[i]--; b[i]--; } ll N = n + m - 1, k = m - 1, bit = (1LL << k) - 1; for (; bit < (1LL << N); bit = next_combination(bit)) { ll num = 1, cnt = 0; // prl(bin_expression(bit, N)); rep(i, N) { if ((1LL << i) & bit) num++; else { target[cnt] = num; cnt++; } } ll tot = 0; rep(i, q) { if (target[b[i]] - target[a[i]] == c[i]) tot += d[i]; } answer = max(answer, tot); } prl(answer); // check negative MOD // check index flow // check overwrite of the input variables } int main(void) { in3(n, m, q); // assert(n <= 400); solve(); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cassert> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; using edge = struct { ll to; ll cost; }; using point = struct { ll x; ll y; }; typedef string str; typedef std::pair<ll, ll> pl; typedef std::pair<ll, pl> pl3; typedef std::map<string, ll> msl; typedef std::map<char, ll> mcl; typedef std::map<ll, ll> mll; typedef std::vector<ll> vl; typedef std::vector<pl> vpl; typedef std::vector<point> points; typedef std::vector<pl3> vpl3; typedef std::priority_queue<ll> pq; typedef std::priority_queue<ll, vl, greater<ll>> pql; // priority queue taking from the lower value. typedef std::vector<edge> gr; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll INF = MOD * MOD; const long double EPS = 1e-9; const long double PI = 3.14159265358979323846; vpl dirs = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}, // four directions {1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // diagonal {0, 0} // self }; #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define revrep(i, n) for (ll(i) = n - 1; (i) >= 0; (i)--) #define For(i, a, b) for (ll(i) = (a); (i) < (b); (i)++) #define revFor(i, b, a) for (ll(i) = (b)-1; (i) >= (a); (i)--) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define isUpper(c) ('a' - c > 0) #define isNum(c) (0 <= (c) - '0' && (c) - '0' <= 9) #define toLower(c) char((c) + 0x20) #define toUpper(c) char((c)-0x20) #define pb push_back #define mp make_pair #define pr(a) cout << (a) #define prl(a) cout << (a) << endl #define prl2(a, b) cout << (a) << " " << (b) << endl #define prl3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define prl4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define prs(a) cout << (a) << " " #define yn(condition) \ if ((condition)) \ prl("Yes"); \ else \ prl("No"); #define YN(condition) \ if ((condition)) \ prl("YES"); \ else \ prl("NO"); #define in1(a) cin >> (a) #define in2(a, b) cin >> (a) >> (b) #define in3(a, b, c) cin >> (a) >> (b) >> (c) #define in4(a, b, c, d) cin >> (a) >> (b) >> (c) >> (d) #define e1 first #define e2 second #define ctol(c) ll((c)) - ll('0') #define ltos(n) to_string((n)) #define items(kv, v) for (auto &(kv) : (v)) #define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)])) #define rsort(a, n) sort(a, a + n, greater<>()) #define Forchar(c, a, z) for (char(c) = (a); (c) <= (z); (c)++) #define cntchar(s, c) count(all((s)), c) #define substring(s, start, end) s.substr((start), (end) - (start) + 1) #define prl_nd(num, digits) \ cout << fixed << setprecision(digits) << (num) << endl; #define XOR(a, b) (a) ^ (b) #define prl_time(s) \ prl3("Elapsed Time:", 1000.0 * (clock() - s) / CLOCKS_PER_SEC, "[ms]"); #define char_to_str(c) string(1, (c)) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define DEBUG(x) cerr << #x << ": " << (x) << endl #define DEBUG_VEC(v) \ cerr << #v << ": "; \ rep(__i, (v).size()) cerr << ((v)[__i]) << ", "; \ cerr << endl struct MaxFlow { struct F_edge { ll to, rev, capacity; F_edge(ll to, ll rev, ll capacity) : to(to), rev(rev), capacity(capacity) {} }; typedef vector<F_edge> F_edges; vector<F_edges> graph; ll n_vertex; // level is the shortest path to get a given node from the source node. vl level, iter; MaxFlow(ll n_vertex) : n_vertex(n_vertex) { graph.resize(n_vertex); } void add_edge(ll from, ll to, ll capacity) { graph[from].pb({to, ll(graph[to].size()), capacity}); graph[to].pb({from, ll(graph[from].size()) - 1, 0}); } void bfs(ll source) { level = vl(n_vertex, -1); level[source] = 0; queue<ll> q; q.push(source); while (!q.empty()) { ll vertex = q.front(); q.pop(); rep(i, graph[vertex].size()) { ll target = graph[vertex][i].to; ll cap_target = graph[vertex][i].capacity; // if the flow can be into the target node, implement below. if (cap_target > 0 && level[target] < 0) { level[target] = level[vertex] + 1; q.push(target); } } } } ll dfs(ll vertex, ll sink, ll flow) { if (vertex == sink) return flow; for (ll &i = iter[vertex]; i < graph[vertex].size(); i++) { ll target = graph[vertex][i].to; ll cap_target = graph[vertex][i].capacity; ll rev_target = graph[vertex][i].rev; // if capasitiy is not full yet and target is farther, // then assign current flow if (cap_target > 0 && level[vertex] < level[target]) { ll d = dfs(target, sink, min(cap_target, flow)); if (d > 0) { // if the flow successfully reaches the sink, reduce the // flow from the capacity graph[vertex][i].capacity -= d; graph[target][rev_target].capacity += d; return d; } } } return 0; } ll dinic(ll source, ll sink) { ll flow = 0; while (true) { bfs(source); // if there is no path leading to the sink, the maximum flow is 0. if (level[sink] < 0) return flow; iter = vl(n_vertex, 0); ll f; while ((f = dfs(source, sink, INF)) > 0) flow += f; } } }; class UnionFind { vl parents, set_size; public: UnionFind() {} UnionFind(ll n) { parents = set_size = vl(n); rep(i, n) { parents[i] = i; set_size[i] = 1LL; } } ll root_find(ll x) { if (parents[x] == x) return x; return parents[x] = root_find(parents[x]); } void unite(ll x, ll y) { x = root_find(x); y = root_find(y); if (x == y) return; if (set_size[x] < set_size[y]) { parents[y] = x; set_size[x] += set_size[y]; } else { parents[x] = y; set_size[y] += set_size[x]; } } bool is_same(ll x, ll y) { // connected or not return root_find(x) == root_find(y); } ll size(ll x) { return set_size[root_find(x)]; } }; /* class LCA{ public: ll N, logN; vl depth, len; gr tree[200005]; // global declaration later. vector<vl> parents; LCA(ll n){ N = n; logN = 0; while (N > (1LL << logN)) logN++; depth = vl(N); len = vl(N); parents = vector<vl>(logN, vl(N)); init(0, -1, 0, 0); build(); } void init(ll source, ll parent, ll d, ll l){ depth[source] = d; parents[0][source] = parent; len[source] = l; rep(i, tree[source].size()){ ll target = tree[source][i].to; ll cost = tree[source][i].cost; if (target == parent) continue; init(target, source, d + 1, cost + l); } } void build(){ rep(k, logN - 1) rep(n, N){ // if there is no parent, -1. // otherwise, the parent of the parent is the parent. if (parents[k][n] < 0) parents[k + 1][n] = -1; else parents[k + 1][n] = parents[k][parents[k][n]]; } } ll query(ll u, ll v){ if (depth[u] > depth[v]) swap(u, v); rep(k, logN) if ((depth[v] - depth[u]) >> k & 1) v = parents[k][v]; if (u == v) return u; revrep(k, logN){ if (parents[k][u] != parents[k][v]){ u = parents[k][u]; v = parents[k][v]; } } return parents[0][u]; } ll distance(ll u, ll v){ ll w = query(u, v); return len[u] + len[v] - 2 * len[w]; } }; */ struct BIT { ll n; vl tree_dat; BIT(ll n) : tree_dat(n + 1, 0), n(n){}; // x: 1001 1010 1100 1011 1101 1111 // x & - x: 0001 0010 0100 0001 0001 0001 // ->: 1010 1100 10000 1100 1100 10000 ll update_func(ll val, ll dat) { // if maximum -> max(val, dat) // return max(val, dat); // if cumulative sum return val + dat; } ll query(ll i) { /* e.g.) i = 10101 itr1. 10101 -> 10100 itr2. 10100 -> 10000 itr3. 10000 -> 00000 (break) */ ll ret = 0; for (ll j = i; j >= 0; j = (j & (j + 1)) - 1) { ret = update_func(ret, tree_dat[j]); } return ret; } ll lower_bound(ll key) { if (key <= 0) return 0; ll left = 0, right = 1; while (right <= n) right *= 2; for (ll i = right; i > 0; i /= 2) { if (left + i <= n && tree_dat[left + i - 1] < key) { key -= tree_dat[left + i - 1]; left += i; } } return left; } void update(ll i, ll val) { /* e.g.) i = 10101, n = 11111 itr1. 10101 -> 10110 itr2. 10110 -> 11000 itr3. 11000 -> 100000 (break) */ if (i < 0) return; for (ll j = i; j < n; j |= j + 1) { tree_dat[j] = update_func(val, tree_dat[j]); } } }; ll gcd(ll m, ll n) { ll a = max(m, n); ll b = min(m, n); while (b != 1 && b != 0) { a %= b; swap(a, b); } return b == 1 ? 1 : a; } ll lcm(ll m, ll n) { return m / gcd(m, n) * n; } ll power_mod(ll a, ll power, ll mod) { ll value = 1; while (power != 0) { if (power & 1) value = (value * a) % mod; a = (a * a) % mod; power = power >> 1; } return value % mod; } ll modinv(ll a, ll mod) { return power_mod(a, mod - 2, mod); } ll power_normal(ll a, ll power) { ll value = 1; while (power != 0) { if (power & 1) value = value * a; a = a * a; power = power >> 1; } return value; } ll comb_memo[55][55]; ll pascal_triangle(ll n) { comb_memo[0][0] = 1; For(i, 1, n + 1) rep(j, i + 1) { comb_memo[i][j] += comb_memo[i - 1][j]; if (j > 0) comb_memo[i][j] += comb_memo[i - 1][j - 1]; } } ll combination(ll n, ll r, ll mod) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { ll num = (n - i) % mod, den = (i + 1) % mod; (numerator *= num) %= mod; (denomenator *= modinv(den, mod)) %= mod; } return (numerator * denomenator) % mod; } ll combination_memo(ll n, ll r, ll pre, ll mod) { // pre = nCr-1 // return nCr if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = ll(n - r + 1) % mod; ll denomenator = modinv(r, mod) % mod; ll val = (numerator * denomenator) % mod; val *= pre; return val % mod; } ll combination_no_mod(ll n, ll r) { if (n == r && n == 0) return 1; else if (n <= 0 || r < 0 || r > n) return 0; ll numerator = 1; ll denomenator = 1; for (ll i = 0; i < r; i++) { numerator *= n - i; denomenator *= i + 1; ll g = gcd(numerator, denomenator); numerator /= g; denomenator /= g; } return numerator; } ld log_combination(ll n, ll r) { if (n == r && n == 0) return 0; else if (n <= 0 || r < 0 || r > n) return -INF; ld val = 0; for (ll i = 0; i < r; i++) { val += log(n - i); val -= log(i + 1); } return val; } ll bin_search(ll key, ll A[], ll left, ll right) { // return the index idx where A[idx] = key. // A[left] is start and A[right] is end.. // In other words, A[right], not A[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (A[mid] == key) return mid; else if (A[mid] > key) right = mid - 1; else if (A[mid] < key) left = mid + 1; } return -1; } /* ll bin_search_temp(ll left, ll right, callable judge){ while(right > left){ // when seeking lower bound ll mid = (right + left) / 2; if (judge(mid)) right = mid; else left = mid + 1; // when seeking upper bound ll mid = (right + left + 1) / 2; if (judge(mid)) left = mid; else right = mid - 1; } return right; } trinary_search // Care the value EPS!!! Compare to the condition ld left = 0; ld right = p; while(abs(right - left) > EPS){ ld left2 = (2 * left + right) / 3.0; ld right2 = (left + 2 * right) / 3.0; ld f1 = tak_func(left2); ld f2 = tak_func(right2); if (f1 <= f2) right = right2; else if (f2 <= f1) left = left2; } */ ll lower_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] >= key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] < key && key <= A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] < key && key <= A[mid]) return mid; else if (A[mid - 1] >= key) right = mid - 1; else if (A[mid] < key) left = mid; } return -1; // all the elements < key } ll inf_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value right instead of -1. if (A[left] > key) return left; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == left) { if (A[left] <= key && key < A[left + 1]) return left + 1; else return -1; } if (A[mid - 1] <= key && key < A[mid]) return mid; else if (A[mid - 1] > key) right = mid - 1; else if (A[mid] <= key) left = mid; } return -1; // all the elements <= key } ll upper_bound_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] <= key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] <= key && key < A[right]) return right - 1; else return -1; } if (A[mid] <= key && key < A[mid + 1]) return mid; else if (A[mid] > key) right = mid; else if (A[mid + 1] <= key) left = mid + 1; } return -1; // all the elements > key } ll sup_bin_search_temp(ll key, ll A[], ll left, ll right) { // Pay attention to the return value -1. // For example, sometimes you may want the value left instead of -1. if (A[right] < key) return right; ll mid = left + (right - left) / 2; while (right >= left) { mid = left + (right - left) / 2; if (mid == right) { if (A[right - 1] < key && key <= A[right]) return right - 1; else return -1; } if (A[mid] < key && key <= A[mid + 1]) return mid; else if (A[mid] >= key) right = mid; else if (A[mid + 1] < key) left = mid + 1; } return -1; // all the elements >= key } ll bin_search_vector(ll key, vl v, ll left, ll right) { // return the index idx where v[idx] = key. // v[left] is start and v[right] is end.. // In other words, v[right], not v[right - 1], must be defined. while (right >= left) { ll mid = left + (right - left) / 2; if (v[mid] == key) return mid; else if (v[mid] > key) right = mid - 1; else if (v[mid] < key) left = mid + 1; } return -1; } ll lower_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] < key <= v[N] // N == -1 if all the elements < key return lower_bound(all(v), key) - v.begin(); } ll inf_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N - 1] <= key < v[N] <= key + 1 // N == -1 if all the elements <= key return lower_bound(all(v), key + 1) - v.begin(); } ll upper_bound_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key < v[N + 1] // N == -1 if all the elements > key return upper_bound(all(v), key) - v.begin(); // (- 1) } ll sup_bin_search_vector(ll key, vl v) { // the return value N satisfies // v[N] <= key - 1 < key <= v[N + 1] // N == -1 if all the elements >= key return upper_bound(all(v), key - 1) - v.begin() - 1; } ll fact(ll n) { if (n == 0) return 1; return n * fact(n - 1); } ll fact_mod(ll n, ll mod) { if (n == 0) return 1; return n * fact_mod(n - 1, mod); } bool is_prime(ll n) { if (n <= 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } ll bool_sum(ll a1, ll a2) { if (a1 == 1 || a2 == 1) return 1; return 0; } mll prime_factorization(ll n) { ll i = 2; mll table; while (i * i <= n) { while (n % i == 0) { table[i]++; n /= i; } i++; } if (n > 1) table[n] = 1; return table; } vl divisor_table(ll n) { vl table; ll i = 1; while (i * i <= n) { if (n % i == 0) { table.pb(i); if (i * i != n) table.pb(n / i); } i++; } sort(all(table)); return table; } ll char_to_idx(char c) { ll idx = 0; Forchar(cc, 'a', 'z') { if (c == cc) return idx; else idx++; } } vl z_algorithm(str s) { ll n = s.length(); vl res(n); res[0] = n; ll i1 = 1, i2 = 0; while (i1 < n) { while (i1 + i2 < n && s[i2] == s[i1 + i2]) ++i2; res[i1] = i2; if (i2 == 0) { ++i1; continue; } ll i3 = 1; while (i1 + i3 < n && i3 + res[i3] < i2) { res[i1 + i3] = res[i3]; ++i3; } i1 += i3, i2 -= i3; } return res; } ll big_number_mod(str s, ll mod) { ll l = s.length(); ll idx = 0; ll val = 0; ll tenth = 1; while (idx < l) { ll m = ctol(s[l - 1 - idx]); val += (m * tenth) % mod; val %= mod; tenth *= 10; tenth %= mod; idx++; } return val; } str bin_expression(ll n, ll dig) { str s = ""; rep(i, dig) { s += ltos(n % 2); n /= 2; } reverse(all(s)); return s; } ll string_to_ll(str s) { ll l = s.length(); ll idx = 0; ll val = 0; ll tenth = 1; while (idx < l) { ll m = ctol(s[l - 1 - idx]); val += (m * tenth); tenth *= 10; idx++; } return val; } str reflected_string(str s) { str t, u; ll n = s.length(); t = s; reverse(all(t)); u = substring(t, 0, n - 2) + s + substring(t, 1, n - 1); return u; } ld distance_between_point_line(point l_begin, point l_end, point p) { ll xl1 = l_begin.x, yl1 = l_begin.y; ll xl2 = l_end.x, yl2 = l_end.y; ll xp = p.x, yp = p.y; ll a = yl2 - yl1; ll b = -xl2 + xl1; ll c = -a * xl2 - b * yl2; return abs(ld(a * xp + b * yp + c)) / ld(sqrt(a * a + b * b)); } bool is_cross(point l1_begin, point l1_end, point l2_begin, point l2_end) { ll x1 = l1_begin.x, y1 = l1_begin.y; ll x2 = l1_end.x, y2 = l1_end.y; ll x3 = l2_begin.x, y3 = l2_begin.y; ll x4 = l2_end.x, y4 = l2_end.y; ll val1 = (x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3); ll val2 = (x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4); ll val3 = (x3 - x4) * (y1 - y3) + (y3 - y4) * (x3 - x1); ll val4 = (x3 - x4) * (y2 - y3) + (y3 - y4) * (x3 - x2); return val1 * val2 < 0 && val3 * val4 < 0; } ld space_of_triangle(point p1, point p2, point p3) { ll x1 = p1.x, y1 = p1.y; ll x2 = p2.x, y2 = p2.y; ll x3 = p3.x, y3 = p3.y; ll v1 = x2 - x1; ll u1 = y2 - y1; ll v2 = x3 - x1; ll u2 = y3 - y1; ld s = ld(v1 * u2 - u1 * v2) / ld(2); return abs(s); } pair<point, ll> center_2det_of_3points(point p1, point p2, point p3) { ll x1 = p1.x, y1 = p1.y; ll x2 = p2.x, y2 = p2.y; ll x3 = p3.x, y3 = p3.y; ll c2x_2 = x2 + x1, c2y_2 = y2 + y1; ll c3x_2 = x3 + x1, c3y_2 = y3 + y1; ll b2y = x2 - x1, b2x = -y2 + y1; ll b3y = x3 - x1, b3x = -y3 + y1; ll x1_2 = c3x_2 * b3y - c3y_2 * b3x, y1_2 = c2x_2 * b2y - c2y_2 * b2x; ll det = -b3y * b2x + b3x * b2y; if (det == 0) return {{INF, INF}, det}; ll cx_2det = -b2x * x1_2 + b3x * y1_2, cy_2det = -b2y * x1_2 + b3y * y1_2; return {{cx_2det, cy_2det}, det}; } ll inversion_number(vl a, ll a_max) { /* Paramters --------- a: vector<ll> All the elements must be non-negative. Prefably the elements are compressed to reduce the computational cost. a_max: ll The maximum value of the vector a or the value bigger than the value stated previously. */ BIT bit(a_max + 1); ll val = 0; rep(i, a.size()) { // i is the number of elements that have lower index than a[i]. // call the number of elements that have lower value than a[i] // by subtracting these two, the residual number is the number of elements // that have larger value val += i - bit.query(a[i] - 1); // cumulative sum from 0 to a[i] - 1 bit.update(a[i], 1); } return val; } template <typename T> vector<T> compress(vector<T> v) { // sort and remove all the duplicated values sort(all(v)); v.erase(unique(all(v)), v.end()); return v; } template <typename T> map<T, ll> dict(const vector<T> &v) { map<T, ll> d; rep(i, v.size()) d[v[i]] = i; return d; } /* const ll N_VERTEX = 310; ll a, b, t; ll dist[N_VERTEX][N_VERTEX]; void warshall_floyd(ll n){ // rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(k, n) rep(i, n) rep(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } int main(void){ in2(n, m); rep(i, n) rep(j, n) dist[i][j] = INF * (i != j); rep(i, m){ in3(a, b, t); a--; b--; dist[a][b] = t; dist[b][a] = t; } warshall_floyd(n); } ll dist[1005], vertex_pre[1005]; void dijkstra(ll start, ll n) { priority_queue<pl, vector<pl>, greater<pl>> edge_costs; fill(dist, dist + n, INF); // fill(vertex_pre, vertex_pre + n, -1); dist[start] = 0; edge_costs.push(pl(0, start)); while (!edge_costs.empty()) { pl edge_cost = edge_costs.top(); edge_costs.pop(); ll idx = edge_cost.second; ll cost = edge_cost.first; if (dist[idx] < cost) continue; rep(i, graph[idx].size()){ edge e = graph[idx][i]; if (dist[e.to] > dist[idx] + e.cost){ dist[e.to] = dist[idx] + e.cost; // vertex_pre[e.to] = idx; edge_costs.push(pl(dist[e.to], e.to)); } } } } vl get_predecessor(ll g){ vl path; for (; g != -1; g = vertex_pre[g]) path.pb(g); reverse(all(path)); return path; } int main(void){ in2(n, m); rep(i, m){ in3(a, b, t); a--; b--; G[a].pb({b, t}); G[b].pb({a, t}); } dijkstra(0, n); } # ABC061D bool find_negative_cycle(ll goal){ rep(i, n) rep(v, n) rep(k, graph[v].size()){ edge e = graph[v][k]; if (dist[e.to] != INF && dist[e.to] > dist[v] + e.cost){ dist[e.to] = -INF; if (goal == -1) return true; else if (goal == e.to) return true; } } return false; } bool bellman_ford(ll start, ll n, ll goal){ // if there is a closed circuit, it returns false. (when goal == -1) // if the distance to goal cannot be obtained, it returns false (when goal != -1) fill(dist, dist + n, INF); dist[start] = 0; rep(i, n) rep(v, n) rep(k, graph[v].size()){ edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) dist[e.to] = dist[v] + e.cost; } if (find_negative_cycle(goal)) return false; return true; } */ /* # 1. The usage of map pair map<pl, ll> cnt; cnt[{i, j}] = 0; items(kv, cnt){ prl2(kv.first, kv.second); } # 2. The usage of next_permutation and combination (factorial search) ll a[8]; rep(i, 8) a[i] = i; sort(a, a + 8); do{ }while(next_permutation(a, a+n)); // here, combination ll n, r; ll i1, i2, ..., ir; For(i1, n - r, n) For(i2, n - r - 1, i1) ... For(ir, n - 2 * r + 1, irr){ process;} # 3. bit search ll n; in1(n); const ll base = 3; ll upper = power_normal(base, n); rep(i, upper){ ll tmp = i; rep(j, n){ rep(k, base) if (tmp % base == k) prl(k); tmp /= base; } } # 4. imos method // used when we would like to count the number which // shows how many times the numbers between l and r belongs to smt. // This method is composed of three process. ll n, m, s[MAX_M], l, r; in2(n, m); rep(i, m) s[i] = 0; // 1st step rep(i, n){ in3(l, r, c); l--; r--; // if l starts from 1. s[l] += c; s[r + 1] -= c; } // 2nd step rep(i, m - 1) s[i + 1] += s[i]; // 3rd step: judgement... #5. shakutori method (syakutori) // 1. strech right side while the condition is met. // 2. renew the answer // 3. increments left side // 4. Back to 1. (l <= r must be satisfied all the time.) ll l = 0; ll r = 0; while (l < n){ r = max(r, l); if (l == r) r++; while(r < n && cond) r++; answer += r - l; l++; } prl(answer); #6. priority queue pq q; ll answer = 0; ll v; rep(i, n) q.push(a[i]); rep(i, m){ v = q.top(); q.pop(); // get the top value and dump the value from queue v /= 2; q.push(v); // add the new value } while(!q.empty()){ answer += q.top(); q.pop(); } #7. The shortest path (distance) between the k-th edge and another edge (Tree) ll depth[MAX_N]; gr tree[MAX_N]; void dfs(ll source, ll parent, ll all_cost){ depth[source] = all_cost; items(e, tree[source]){ if (e.to == parent) continue; dfs(e.to, source, all_cost + e.cost); } } ll n, k, a, b, c; in2(n, k); rep(i, n - 1){ in3(a, b, c); a--; b--; tree[a].pb({b, c}); tree[b].pb({a, c}); } k--; dfs(k, -1, 0); #10. Visiting Subtree using recurrent function (ABC138D) gr tree[MAX_N]; ll c[MAX_N]; bool visited[MAX_N]; void dfs(ll source, ll parent, ll val){ visited[source] = true; c[source] += val; rep(i, tree[source].size()){ rep(i, m){ll res = n % match[i].e1;} ll vertex = tree[source][i].to; if (vertex == parent) continue; dfs(vertex, source, c[source]); } } #11. bfs ABC146D, ABC007C 1. first create a tree. 2. start searching from a node. 3. do some processes and push nodes connected with a given target node in BFS. 4. repeat a series of procedure until queue is empty. queue<pl> q; void bfs(ll source, ll parents){ ll n_edge = G[source].size(); if (parents != -1) dist[source] = min(dist[source], dist[parents] + 1); if (visited[source]) return; visited[source] = true; rep(idx, n_edge){ ll target = G[source][idx].to; if (target == parents) continue; q.push(mp(target, source)); } } q.push(mp(sg.e1, -1)); while(!q.empty()){ pl source = q.front(); q.pop(); bfs(source.e1, source.e2); } #12. grid to distance matrix (dx, dy) ll w, h; ll pos_to_idx(ll x, ll y){ return y * w + x; } pl idx_to_pos(ll idx){ return mp(idx % w, idx / w); } int main(void){ in2(h, w); rep(y, h){ in1(s); rep(x, w){ if (s[x] == '#') wall[x][y] = true; else wall[x][y] = false; } } rep(i1, h * w)rep(i2, h * w) dist[i1][i2] = INF * (i1 != i2); rep(x, w)rep(y, h){ ll idx1 = pos_to_idx(x, y); ll idx2; if (wall[x][y]) continue; if (x != 0 && !wall[x - 1][y]){ idx2 = pos_to_idx(x - 1, y); // if warshall floyd dist[idx1][idx2] = 1; // if dijkstra // graph[idx1].pb({idx2, 1}); } if (x != w - 1 && !wall[x + 1][y]){ idx2 = pos_to_idx(x + 1, y); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != 0 && !wall[x][y - 1]){ idx2 = pos_to_idx(x, y - 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } if (y != h - 1 && !wall[x][y + 1]){ idx2 = pos_to_idx(x, y + 1); dist[idx1][idx2] = 1; // graph[idx1].pb({idx2, 1}); } } } */ /* # the operators regarding bit & (AND), | (OR), ^ (XOR) - (REVERSE), >> (SMALLER SHIFT) << (BIGGER SHIFT) x1: 0000 0001 0010 0101 0110 0111 0111 x2: xxxx 0001 0011 0100 0101 1000 0110 x1 & x2: 0000 0001 0010 0100 0100 0000 0110 x: 1001 1010 1100 1011 1101 1111 x & - x: 0001 0010 0100 0001 0001 0001 sum: 1010 1100 10000 1100 1100 10000 x << y is x * 2 ** y x >> y is rep(i, y) x = x // 2 ####### Attention ####### 1 << i and 1LL << i is different. If programs show WA, try switch to this one. Let S be a bit sequence and i be a non-negative integer S & (1 << i) -> if true, i in S S | (1 << i) -> S union {i} S & -(1 << i) -> S - {i} __builtin_popcount(S) -> the number of elements in S S = 0 -> S is an empty set __builtin_popcountl(i) -> the number of 1 in binary S = (1 << n) - 1 -> S includes all the elements up to the n-th #Conditional Operator condition ? true : false; #iterator type declaration: auto value reference: *itr increment: itr++ decrement: itr-- substitution of value: *itr = smt # inclusion-exclusion principle |U[i = 1 to n] Ai| = sum[i = 1 to n] |Ai| - sum[i < j]|Ai ^ Aj| + ... + (-1)^(n - 1) |^[i = 1 to n]Ai| */ const ll MAX_N = 200005; bool okay = false; ll answer = 0; ll n, m, q; vl a, b, c, d; ll target[140000]; ll next_combination(ll sub) { /* ll n, k; ll bit = (1 << k) - 1; for (; bit < (1 << n); bit = next_combination(bit)){ bool ith = bit & (1 << i); procedures... } */ ll x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } void solve() { a = b = c = d = vl(q); rep(i, q) { in4(a[i], b[i], c[i], d[i]); a[i]--; b[i]--; } if (m == 1) { rep(i, n) target[i] = 1; rep(i, q) { if (target[b[i]] - target[a[i]] == c[i]) answer += d[i]; } prl(answer); return; } ll N = n + m - 1, k = m - 1, bit = (1LL << k) - 1; for (; bit < (1LL << N); bit = next_combination(bit)) { ll num = 1, cnt = 0; // prl(bin_expression(bit, N)); rep(i, N) { if ((1LL << i) & bit) num++; else { target[cnt] = num; cnt++; } } ll tot = 0; rep(i, q) { if (target[b[i]] - target[a[i]] == c[i]) tot += d[i]; } answer = max(answer, tot); } prl(answer); // check negative MOD // check index flow // check overwrite of the input variables } int main(void) { in3(n, m, q); // assert(n <= 400); solve(); return 0; }
insert
1,263
1,263
1,263
1,272
0
p02695
C++
Runtime Error
// raja1999 // #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64 // setfill - cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77 // setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx // cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> // #define int ll typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // std::ios::sync_with_stdio(false); int n, m, q; int res = 0; int a[55], b[55], c[55], d[55]; int gen(int pos, vi v, int x) { int j, i; if (pos == n) { int ans = 0; rep(i, q) { if (v[b[i]] - v[a[i]] == c[i]) { ans += d[i]; } } res = max(res, ans); return 0; } vi v1; f(j, x, m + 1) { v1 = v; v1.pb(j); gen(pos + 1, v1, j); } } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int i; cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } vi vec; gen(0, vec, 1); cout << res << endl; return 0; }
// raja1999 // #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64 // setfill - cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77 // setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx // cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> // #define int ll typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // std::ios::sync_with_stdio(false); int n, m, q; int res = 0; int a[55], b[55], c[55], d[55]; int gen(int pos, vi v, int x) { int j, i; if (pos == n) { int ans = 0; rep(i, q) { if (v[b[i]] - v[a[i]] == c[i]) { ans += d[i]; } } res = max(res, ans); return 0; } vi v1; f(j, x, m + 1) { v1 = v; v1.pb(j); gen(pos + 1, v1, j); } return 0; } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); int i; cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; a[i]--; b[i]--; } vi vec; gen(0, vec, 1); cout << res << endl; return 0; }
insert
79
79
79
80
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define BOUND 27182818284 #define MAT 2 typedef long long ll; typedef long long int lli; typedef pair<ll, ll> P; ll MOD = 1000000007; const ll INF = (1ll << 60); const int INFint = (1 << 30); #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) template <class T> bool umax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool umin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } // gcd template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } ll findGCD(vector<ll> arr) { ll result = arr[0]; for (auto a : arr) { result = gcd(a, result); } return result; } template <typename T> T getlcm(T m, T n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } // v.front() = -BOUND; // v.back() = BOUND; // struct edge{ // int cost, to; // // edge(int in_cost, int in_to){ // cost=in_cost; // to=in_to; // } // bool operator<(const edge &a) const // { // return cost > a.cost; // } // }; ll euler_phi(ll n) { ll ret = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { ret -= ret / i; while (n % i == 0) n /= i; } } if (n > 1) ret -= ret / n; return ret; } class Combination { long long powmod(long long a, long long p) { long long ans = 1LL; long long mul = a; while (p > 0) { if ((p & 1) == 1) { ans = (ans * mul) % mod; } mul = (mul * mul) % mod; p >>= 1; } return ans; } public: int N; long long mod; vector<long long> fact; vector<long long> revfact; Combination(int n, long long m) : N(n), mod(m), fact(n + 1), revfact(n + 1) { fact[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = fact[i - 1] * i; fact[i] %= mod; } revfact[N] = powmod(fact[N], mod - 2); for (int i = N - 1; i >= 0; i--) { revfact[i] = revfact[i + 1] * (i + 1) % mod; } } long long getCombination(int a, int b) { if (a < 0 || b < 0) return 0; if (b > a) return 0; return (fact[a] * revfact[b]) % mod * revfact[a - b] % mod; } }; struct mint { const int mod = 1000000007; ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; struct UnionFind { int n, cnt; vector<int> par, rank, sz; UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) { iota(par.begin(), par.end(), 0); } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return sz[find(x)]; } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; sz[y] += sz[x]; } else { par[y] = x; sz[x] += sz[y]; if (rank[x] == rank[y]) { rank[x]++; } } cnt--; } }; const string Yes = "Yes"; const string YES = "YES"; const string No = "No"; const string NO = "NO"; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; template <typename T> vector<T> DIVISOR(T n) { vector<T> v; for (T i = 1; i * i <= n; ++i) { if (n % i == 0) { v.push_back(i); if (i != n / i) { v.push_back(n / i); } } } sort(v.begin(), v.end()); return v; } ll permutation(ll n) { ll ans = 1LL; if (n <= 0) { return ans; } for (ll i = 1; i <= n; i++) { ans *= i; } return ans; } template <typename T> struct PrimeFact { vector<T> spf; PrimeFact(T N) { init(N); } void init(T N) { // 前処理。spf を求める spf.assign(N + 1, 0); for (T i = 0; i <= N; i++) spf[i] = i; for (T i = 2; i * i <= N; i++) { if (spf[i] == i) { for (T j = i * i; j <= N; j += i) { if (spf[j] == j) { spf[j] = i; } } } } } map<T, T> get(T n) { // nの素因数分解を求める map<T, T> m; while (n != 1) { m[spf[n]]++; n /= spf[n]; } return m; } }; int N, M, Q; int ans = 0; vector<int> a, b, c, d; ll solve(int number, vector<int> A, int pre) { if (number == N) { int ans_part = 0; for (int i = 0; i < Q; i++) { if (A[b[i]] - A[a[i]] == c[i]) { ans_part += d[i]; } } ans = max(ans, ans_part); return ans_part; } for (int current = pre; current <= M; current++) { A.push_back(current); solve(number + 1, A, current); A.pop_back(); } } int main() { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { int temp; cin >> temp; a.push_back(temp - 1); cin >> temp; b.push_back(temp - 1); cin >> temp; c.push_back(temp); cin >> temp; d.push_back(temp); } vector<int> A; solve(0, A, 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define BOUND 27182818284 #define MAT 2 typedef long long ll; typedef long long int lli; typedef pair<ll, ll> P; ll MOD = 1000000007; const ll INF = (1ll << 60); const int INFint = (1 << 30); #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) template <class T> bool umax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool umin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } // gcd template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } ll findGCD(vector<ll> arr) { ll result = arr[0]; for (auto a : arr) { result = gcd(a, result); } return result; } template <typename T> T getlcm(T m, T n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } // v.front() = -BOUND; // v.back() = BOUND; // struct edge{ // int cost, to; // // edge(int in_cost, int in_to){ // cost=in_cost; // to=in_to; // } // bool operator<(const edge &a) const // { // return cost > a.cost; // } // }; ll euler_phi(ll n) { ll ret = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { ret -= ret / i; while (n % i == 0) n /= i; } } if (n > 1) ret -= ret / n; return ret; } class Combination { long long powmod(long long a, long long p) { long long ans = 1LL; long long mul = a; while (p > 0) { if ((p & 1) == 1) { ans = (ans * mul) % mod; } mul = (mul * mul) % mod; p >>= 1; } return ans; } public: int N; long long mod; vector<long long> fact; vector<long long> revfact; Combination(int n, long long m) : N(n), mod(m), fact(n + 1), revfact(n + 1) { fact[0] = 1; for (int i = 1; i <= N; i++) { fact[i] = fact[i - 1] * i; fact[i] %= mod; } revfact[N] = powmod(fact[N], mod - 2); for (int i = N - 1; i >= 0; i--) { revfact[i] = revfact[i + 1] * (i + 1) % mod; } } long long getCombination(int a, int b) { if (a < 0 || b < 0) return 0; if (b > a) return 0; return (fact[a] * revfact[b]) % mod * revfact[a - b] % mod; } }; struct mint { const int mod = 1000000007; ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; struct UnionFind { int n, cnt; vector<int> par, rank, sz; UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) { iota(par.begin(), par.end(), 0); } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return sz[find(x)]; } void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; sz[y] += sz[x]; } else { par[y] = x; sz[x] += sz[y]; if (rank[x] == rank[y]) { rank[x]++; } } cnt--; } }; const string Yes = "Yes"; const string YES = "YES"; const string No = "No"; const string NO = "NO"; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; template <typename T> vector<T> DIVISOR(T n) { vector<T> v; for (T i = 1; i * i <= n; ++i) { if (n % i == 0) { v.push_back(i); if (i != n / i) { v.push_back(n / i); } } } sort(v.begin(), v.end()); return v; } ll permutation(ll n) { ll ans = 1LL; if (n <= 0) { return ans; } for (ll i = 1; i <= n; i++) { ans *= i; } return ans; } template <typename T> struct PrimeFact { vector<T> spf; PrimeFact(T N) { init(N); } void init(T N) { // 前処理。spf を求める spf.assign(N + 1, 0); for (T i = 0; i <= N; i++) spf[i] = i; for (T i = 2; i * i <= N; i++) { if (spf[i] == i) { for (T j = i * i; j <= N; j += i) { if (spf[j] == j) { spf[j] = i; } } } } } map<T, T> get(T n) { // nの素因数分解を求める map<T, T> m; while (n != 1) { m[spf[n]]++; n /= spf[n]; } return m; } }; int N, M, Q; int ans = 0; vector<int> a, b, c, d; ll solve(int number, vector<int> A, int pre) { if (number == N) { int ans_part = 0; for (int i = 0; i < Q; i++) { if (A[b[i]] - A[a[i]] == c[i]) { ans_part += d[i]; } } ans = max(ans, ans_part); return ans_part; } for (int current = pre; current <= M; current++) { A.push_back(current); solve(number + 1, A, current); A.pop_back(); } return 0; } int main() { cin >> N >> M >> Q; for (int i = 0; i < Q; i++) { int temp; cin >> temp; a.push_back(temp - 1); cin >> temp; b.push_back(temp - 1); cin >> temp; c.push_back(temp); cin >> temp; d.push_back(temp); } vector<int> A; solve(0, A, 1); cout << ans << endl; return 0; }
insert
413
413
413
414
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m, q, a[50], b[50], c[50], d[50], ans = 0, A[10]; int dfs(int p, int k) { if (p == n) { int sum = 0; for (int i = 0; i < q; i++) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i]; } ans = max(ans, sum); } else { for (int i = k; i <= m; i++) { A[p] = i; dfs(p + 1, i); } } } int main() { cin >> n >> m >> q; A[0] = 1; for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; dfs(1, 1); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, m, q, a[50], b[50], c[50], d[50], ans = 0, A[10]; void dfs(int p, int k) { if (p == n) { int sum = 0; for (int i = 0; i < q; i++) { if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i]; } ans = max(ans, sum); } else { for (int i = k; i <= m; i++) { A[p] = i; dfs(p + 1, i); } } } int main() { cin >> n >> m >> q; A[0] = 1; for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i]; dfs(1, 1); cout << ans << endl; }
replace
3
4
3
4
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repo(i, n) for (int i = 1; i <= n; i++) #define INF 1001001001 #define INFll 100100100100100 // debug用 #define PrintVec(x) \ for (auto elementPrintVec : x) { \ cout << elementPrintVec << " "; \ } \ cout << endl; using namespace std; using ull = unsigned long long; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; vector<int> a; vector<int> b; vector<int> c; vector<int> d; int ans = 0; int n, m, q; void dfs(vector<int> A) { if (A.size() == n + 1) { int score = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) { score += d[i]; } } ans = max(ans, score); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; a.resize(n); b.resize(n); c.resize(n); d.resize(n); rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repo(i, n) for (int i = 1; i <= n; i++) #define INF 1001001001 #define INFll 100100100100100 // debug用 #define PrintVec(x) \ for (auto elementPrintVec : x) { \ cout << elementPrintVec << " "; \ } \ cout << endl; using namespace std; using ull = unsigned long long; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; vector<int> a; vector<int> b; vector<int> c; vector<int> d; int ans = 0; int n, m, q; void dfs(vector<int> A) { if (A.size() == n + 1) { int score = 0; rep(i, q) { if (A[b[i]] - A[a[i]] == c[i]) { score += d[i]; } } ans = max(ans, score); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; a.resize(q); b.resize(q); c.resize(q); d.resize(q); rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
replace
45
49
45
49
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; int main() { int N, M, Q; int dsum = 0; cin >> N >> M >> Q; vector<vector<int>> kumi(Q, vector<int>(4)); for (int i = 0; i < Q; i++) { cin >> kumi[i][0] >> kumi[i][1] >> kumi[i][2] >> kumi[i][3]; } vector<int> A(N); for (int tmp = 0; tmp < (1 << 19); tmp++) { bitset<19> s(tmp); if (s.count() != M - 1) continue; if (s.test(N + M - 1)) break; int kazu = 1; int j = 0; int sum = 0; for (int i = N + M - 2; i >= 0; --i) { if (s.test(i)) { ++kazu; } else { A[j] = kazu; ++j; } } for (int i = 0; i < Q; i++) { if (A[kumi[i][1] - 1] - A[kumi[i][0] - 1] == kumi[i][2]) sum += kumi[i][3]; } dsum = max(dsum, sum); } cout << dsum << endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; int main() { int N, M, Q; int dsum = 0; cin >> N >> M >> Q; vector<vector<int>> kumi(Q, vector<int>(4)); for (int i = 0; i < Q; i++) { cin >> kumi[i][0] >> kumi[i][1] >> kumi[i][2] >> kumi[i][3]; } vector<int> A(N); for (int tmp = 0; tmp < (1 << 19); tmp++) { bitset<19> s(tmp); if (s.count() != M - 1) continue; if (N + M - 1 != 19) { if (s.test(N + M - 1)) break; } int kazu = 1; int j = 0; int sum = 0; for (int i = N + M - 2; i >= 0; --i) { if (s.test(i)) { ++kazu; } else { A[j] = kazu; ++j; } } for (int i = 0; i < Q; i++) { if (A[kumi[i][1] - 1] - A[kumi[i][0] - 1] == kumi[i][2]) sum += kumi[i][3]; } dsum = max(dsum, sum); } cout << dsum << endl; }
replace
17
19
17
21
0
p02695
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; int ans; int a[10], b[10], c[10], d[10]; int n, m, q; void dfs(vector<int> A) { if (A.size() == n + 1) { int now = 0; rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; ans = max(ans, now); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i]; dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; int ans; int a[50], b[50], c[50], d[50]; int n, m, q; void dfs(vector<int> A) { if (A.size() == n + 1) { int now = 0; rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) now += d[i]; ans = max(ans, now); return; } A.push_back(A.back()); while (A.back() <= m) { dfs(A); A.back()++; } } int main() { cin >> n >> m >> q; rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i]; dfs(vector<int>(1, 1)); cout << ans << endl; return 0; }
replace
6
7
6
7
0
p02695
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; return; } int a[20], b[20], c[20], d[20], x[20]; int n, m, q, ans; void dfs(int now, int last) { if (now > n) { int s = 0; for (int i = 1; i <= q; ++i) { if (x[b[i]] - x[a[i]] == c[i]) { s += d[i]; } } ans = std::max(ans, s); return; } for (int i = last; i <= m; ++i) { x[now] = i; dfs(now + 1, i); } } int main() { read(n), read(m), read(q); for (int i = 1; i <= q; ++i) read(a[i]), read(b[i]), read(c[i]), read(d[i]); dfs(1, 1); printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; return; } int a[60], b[60], c[60], d[60], x[20]; int n, m, q, ans; void dfs(int now, int last) { if (now > n) { int s = 0; for (int i = 1; i <= q; ++i) { if (x[b[i]] - x[a[i]] == c[i]) { s += d[i]; } } ans = std::max(ans, s); return; } for (int i = last; i <= m; ++i) { x[now] = i; dfs(now + 1, i); } } int main() { read(n), read(m), read(q); for (int i = 1; i <= q; ++i) read(a[i]), read(b[i]), read(c[i]), read(d[i]); dfs(1, 1); printf("%d\n", ans); return 0; }
replace
21
22
21
22
0
p02695
C++
Runtime Error
#pragma GCC optimize("O3") #define _GLIBCXX_DEBUG #include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <string_view> #include <vector> using namespace std; /*----------macros----------*/ // output================ #define endl '\n' #define fcout(a) cout << fixed << setprecision((int)(a)) // typedef=============== typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; // const number========== constexpr ll INF9 = (ll)1e9 + 1; constexpr ll INF18 = (ll)1e18 + 1; constexpr ll MOD = 1000000007; constexpr ll MOD2 = 998244353; constexpr ld PI = 3.141592653589793L; // member================ #define pb push_back #define eb emplace_back #define pf push_front #define mp make_pair #define fi first #define se second // others================ #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; (i) < (n); ++(i)) #define reps(i, n) for (int i = 1; (i) <= (n); ++(i)) #define rrep(i, n) for (int i = n - 1; (i) >= 0; --(i)) #define repbit(bit, n) for (int bit = 0; (bit) < (1 << (n)); ++(bit)) #define ifbit(bit, i) if ((bit) & (1 << (i))) #define CtoI(c) int((c)) - int('0') #define ItoC(c) char((c) + '0') // functions============= template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; // vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; /*--------additional--------*/ int n, m, q; vector<int> a(100), b(100), c(100), d(100); ll ans = 0; void dfs(vector<int> _v, int _cnt, int _init) { if (_cnt == n) { int res = 0; rep(i, q) { if (_v[b[i]] - _v[a[i]] == c[i]) res += d[i]; } chmax(ans, res); } else { for (int i = _init; i <= m; ++i) { vector<int> _nv = _v; _nv.pb(i); dfs(_nv, ++_cnt, i); } } } /*----------main------------*/ int main() { /*----------fastio----------*/ std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); /*----------solve-----------*/ cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i], --b[i]; } vector<int> v; dfs(v, 0, 1); cout << ans << endl; return 0; }
#pragma GCC optimize("O3") #define _GLIBCXX_DEBUG #include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <string_view> #include <vector> using namespace std; /*----------macros----------*/ // output================ #define endl '\n' #define fcout(a) cout << fixed << setprecision((int)(a)) // typedef=============== typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; // const number========== constexpr ll INF9 = (ll)1e9 + 1; constexpr ll INF18 = (ll)1e18 + 1; constexpr ll MOD = 1000000007; constexpr ll MOD2 = 998244353; constexpr ld PI = 3.141592653589793L; // member================ #define pb push_back #define eb emplace_back #define pf push_front #define mp make_pair #define fi first #define se second // others================ #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; (i) < (n); ++(i)) #define reps(i, n) for (int i = 1; (i) <= (n); ++(i)) #define rrep(i, n) for (int i = n - 1; (i) >= 0; --(i)) #define repbit(bit, n) for (int bit = 0; (bit) < (1 << (n)); ++(bit)) #define ifbit(bit, i) if ((bit) & (1 << (i))) #define CtoI(c) int((c)) - int('0') #define ItoC(c) char((c) + '0') // functions============= template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; // vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; /*--------additional--------*/ int n, m, q; vector<int> a(100), b(100), c(100), d(100); ll ans = 0; void dfs(vector<int> _v, int _cnt, int _init) { if (_cnt == n) { int res = 0; rep(i, q) { if (_v[b[i]] - _v[a[i]] == c[i]) res += d[i]; } chmax(ans, res); } else { for (int i = _init; i <= m; ++i) { vector<int> _nv = _v; _nv.pb(i); dfs(_nv, _cnt + 1, i); } } } /*----------main------------*/ int main() { /*----------fastio----------*/ std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); /*----------solve-----------*/ cin >> n >> m >> q; rep(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i], --b[i]; } vector<int> v; dfs(v, 0, 1); cout << ans << endl; return 0; }
replace
87
88
87
88
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02695
C++
Runtime Error
// #include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) // #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int N, M, Q; int A[11], B[11], C[11], D[11]; int T[11]; int ans; void dfs(int d, int par) { if (d == N) { int res = 0; rep(i, 0, Q) { if (T[B[i]] - T[A[i]] == C[i]) res += D[i]; } chmax(ans, res); return; } rep(i, par, M + 1) { T[d] = i; dfs(d + 1, i); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> Q; rep(i, 0, Q) { cin >> A[i] >> B[i] >> C[i] >> D[i]; A[i]--, B[i]--; } dfs(0, 1); cout << ans << endl; return 0; }
// #include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) // #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int N, M, Q; int A[55], B[55], C[55], D[55]; int T[11]; int ans; void dfs(int d, int par) { if (d == N) { int res = 0; rep(i, 0, Q) { if (T[B[i]] - T[A[i]] == C[i]) res += D[i]; } chmax(ans, res); return; } rep(i, par, M + 1) { T[d] = i; dfs(d + 1, i); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> Q; rep(i, 0, Q) { cin >> A[i] >> B[i] >> C[i] >> D[i]; A[i]--, B[i]--; } dfs(0, 1); cout << ans << endl; return 0; }
replace
68
69
68
69
0