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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<int> F(N);
for (int i = 0; i < N; i++) {
cin >> F.at(i);
}
sort(A.begin(), A.end());
sort(F.rbegin(), F.rend());
int64_t l = -1, r = 1e12;
while (l + 1 < r) {
int64_t m = (l + r) / 2;
int64_t k = 0;
for (int i = 0; i < N; i++) {
k += max((int64_t)0, A.at(i) - m / F.at(i));
}
if (k <= K) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int64_t K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<int> F(N);
for (int i = 0; i < N; i++) {
cin >> F.at(i);
}
sort(A.begin(), A.end());
sort(F.rbegin(), F.rend());
int64_t l = -1, r = 1e12;
while (l + 1 < r) {
int64_t m = (l + r) / 2;
int64_t k = 0;
for (int i = 0; i < N; i++) {
k += max((int64_t)0, A.at(i) - m / F.at(i));
}
if (k <= K) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
} | replace | 4 | 5 | 4 | 6 | 0 | |
p02883 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう!
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう?
lint a[100100], f[100100];
int main() {
int n;
lint k;
cin >> n >> k;
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a, a + n);
reverse(a, a + n);
sort(f, f + n);
lint hi = 123456789012345678LL, lo = 0;
while (hi > lo) {
lint mi = (hi + lo) / 2;
lint sum = 0;
rep(i, n) { sum += max(0LL, a[i] - mi / f[i]); }
if (sum <= k)
hi = mi;
else
lo = mi + 1;
}
cout << hi << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう!
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう?
lint a[200100], f[200100];
int main() {
int n;
lint k;
cin >> n >> k;
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a, a + n);
reverse(a, a + n);
sort(f, f + n);
lint hi = 123456789012345678LL, lo = 0;
while (hi > lo) {
lint mi = (hi + lo) / 2;
lint sum = 0;
rep(i, n) { sum += max(0LL, a[i] - mi / f[i]); }
if (sum <= k)
hi = mi;
else
lo = mi + 1;
}
cout << hi << endl;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
vector<ll> a, b;
ll n, k;
bool check(long long x) {
long long cnt = 0;
rep(i, n) {
cnt += max(0ll, a[i] - x / b[i]);
if (cnt > k)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
a.resize(n);
b.resize(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end(), greater<ll>());
ll l = -1, r = 1e12 + 1;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r;
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
vector<ll> a, b;
ll n, k;
bool check(long long x) {
long long cnt = 0;
rep(i, n) {
cnt += max(0ll, a[i] - x / b[i]);
if (cnt > k)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
a.resize(n);
b.resize(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end(), greater<ll>());
ll l = -1, r = 1e12 + 1;
while (r - l > 1) {
ll mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r;
return 0;
}
| replace | 28 | 29 | 28 | 29 | TLE | |
p02883 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<long long> a(n);
vector<long long> f(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
long long l = -1;
long long r = 1e12;
while (l + 1 < r) {
long long g = (l + r) / 2;
bool flag = true;
long long count = 0;
for (long long i = 0; i < n; i++) {
count += max(0LL, (a[i] - g / f[i]));
if (count > k) {
flag = false;
break;
}
}
(flag ? r : l) = g;
}
cout << r << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
vector<long long> f(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
long long l = -1;
long long r = 1e12;
while (l + 1 < r) {
long long g = (l + r) / 2;
bool flag = true;
long long count = 0;
for (long long i = 0; i < n; i++) {
count += max(0LL, (a[i] - g / f[i]));
if (count > k) {
flag = false;
break;
}
}
(flag ? r : l) = g;
}
cout << r << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
bool ok = [&]() {
ll s = 0;
rep(i, n) { s += max(0ll, a[i] - c / f[i]); }
return s <= k;
}();
if (ok)
r = c;
else
l = c;
}
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
int n;
ll k;
cin >> n >> k;
vector<int> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
bool ok = [&]() {
ll s = 0;
rep(i, n) { s += max(0ll, a[i] - c / f[i]); }
return s <= k;
}();
if (ok)
r = c;
else
l = c;
}
cout << r << endl;
return 0;
}
| replace | 8 | 9 | 8 | 10 | 0 | |
p02883 | C++ | Time Limit Exceeded | // #pragma once
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib> // srand,rand
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define lp(i, n) for (ll i = 0; i < n; i++)
#define modd 1000000007
#define mod2 998244353
#define INF 8223372036854775807ll
#define ALL(a) (a).begin(), (a).end()
typedef pair<long long, long long> pl;
typedef pair<double, double> pd;
typedef pair<ll, string> pls;
typedef string::const_iterator State;
class ParseError {};
/*
class SegmentTree {
private:
ll cont_num = 2;
pd initial_v;
vector<pd> dat;
public:
SegmentTree() {};
void init(ll size, double initial_value_first, double
initial_value_second) {
cont_num = 2;
initial_v.first = initial_value_first;
initial_v.second = initial_value_second;
while (cont_num < size) {
cont_num *= 2;
}
dat.resize(2 * cont_num);//サイズ設定
for (int i = 0; i < 2 * cont_num; i++)dat[i] =
initial_v;//初期化
}
void Update(ll position, double value_f, double value_s) {
ll k = cont_num + position;
dat[k].first = value_f;
dat[k].second = value_s;
while (k > 1) {
k /= 2;
dat[k].first = dat[k * 2 + 1].first * dat[k * 2].first;
dat[k].second = dat[k * 2 + 1].first * dat[k * 2].second
+ dat[k * 2 + 1].second;
}
}
/*
ll query_proces(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)return initial_v;
if (a <= l && r <= b)return dat[k];
else {
ll vl = query_proces(a, b, k * 2, l, (l + r) / 2);
ll vr = query_proces(a, b, k * 2 + 1, (l + r) / 2, r);
return min(vl, vr);
}
}
ll query(ll left, ll right) {
return query_proces(left, right, 1, 0, cont_num);
}
*/
/*
double query() {
return dat[1].first + dat[1].second;
}
};*/
template <typename T> class Zip {
vector<T> d;
bool flag;
void init() {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag)
init();
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag)
init();
return (ll)d.size();
}
};
ll N, M, K, a, b, c, d, e, H, W, L, T;
ll x, y, z;
ll A[2000004] = {};
ll B[2000004] = {};
ll C[2000004] = {};
ll D[1000006] = {};
ll E[1000006] = {};
bool f;
string S[200000];
string SS;
set<long long> sll;
pl bufpl;
vector<long long> vl[200005];
vector<long long> llv[30005];
vector<long long> vll;
vector<long long> v;
vector<pl> vpl;
vector<string> vs;
set<ll> llset;
set<string> Sset;
multiset<ll> llmset;
queue<ll> ql;
multiset<pl> plmset;
typedef struct ST {
ll first;
ll second;
ll cost;
bool operator<(const ST &another) const {
return first < another.first; // 比較
};
bool operator>(const ST &another) const {
return first > another.first; // 比較
};
} ST;
// queue<ST> qst;
priority_queue<ST, vector<ST>, greater<ST>> qst;
multiset<ST> stmset;
ST bufst;
ST stt[100000];
/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/
long long modinv(long long aa, long long mm) {
long long bb = mm, uu = 1, vv = 0;
while (bb) {
long long tt = aa / bb;
aa -= tt * bb;
swap(aa, bb);
uu -= tt * vv;
swap(uu, vv);
}
uu %= mm;
if (uu < 0)
uu += mm;
return uu;
}
ll zettai(ll aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
float zettai(float aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
/*
class UnionFind
{
public:
vector <ll>pairent;
vector <ll>depth;
vector <ll>size;
UnionFind(ll Amount) : pairent(Amount, 1), depth(Amount, 1),
size(Amount, 1) {
for (ll i = 0; i < Amount; i++) {
pairent[i] = i;
}
}
ll FindPairent(ll x) {
if (pairent[x] == x)return x;
else return pairent[x] = FindPairent(pairent[x]);
}
ll Merge(ll x, ll y) {
x = FindPairent(x);
y = FindPairent(y);
if (x != y) {
if (depth[x] > depth[y]) {
pairent[y] = pairent[x];
return size[x] += size[y];
}
else {
pairent[x] = pairent[y];
if (depth[x] == depth[y]) {
depth[y] ++;
}
return size[y] += size[x];
}
}
else {
return -1;
}
}
bool IsSame(ll x, ll y) {
if (FindPairent(x) == FindPairent(y))return true;
else return false;
}
ll GetSize(ll x) {
x = FindPairent(x);
return size[x];
}
};
*/
class UnionFind {
public:
vector<ll> pairent;
vector<ll> depth;
vector<ll> size;
UnionFind(ll Amount) : pairent(Amount, 1), depth(Amount, 1), size(Amount, 1) {
for (ll i = 0; i < Amount; i++) {
pairent[i] = i;
}
}
ll FindPairent(ll x) {
if (pairent[x] == x)
return x;
else
return pairent[x] = FindPairent(pairent[x]);
}
ll Merge(ll x, ll y) {
x = FindPairent(x);
y = FindPairent(y);
if (x != y) {
if (depth[x] > depth[y]) {
pairent[y] = pairent[x];
return size[x] += size[y];
} else {
pairent[x] = pairent[y];
if (depth[x] == depth[y]) {
depth[y]++;
}
return size[y] += size[x];
}
} else {
return -1;
}
}
bool IsSame(ll x, ll y) {
if (FindPairent(x) == FindPairent(y))
return true;
else
return false;
}
ll GetSize(ll x) {
x = FindPairent(x);
return size[x];
}
};
class Nibutan {
public:
ll hidari = 0;
ll migi = 0;
ll abc;
vector<ll> contents;
bool Jouken(int ser) {
if (contents[ser] > abc) {
return true;
} else {
return false;
}
}
void Settings(int amount, ll terget) {
migi = amount - 1;
abc = terget;
}
ll tansaku() {
hidari = -1;
migi = contents.size();
ll jud;
while (hidari != migi - 1) {
jud = hidari + migi;
jud /= 2;
if (Jouken(jud)) {
migi = jud;
} else {
hidari = jud;
}
}
return hidari;
}
};
ll RepeatSquaring(ll N, ll P, ll M) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, M) % M;
return t * t % M;
}
return N * RepeatSquaring(N, P - 1, M) % M;
}
/*
ll KurikaesiNijou(ll a, ll b, ll P) {
if (b == 0)return 1;
if (b % 2 == 0) {
ll c=KurikaesiNijou(a,b/2,P)%P;
return c * c %P;
}
else {
ll c = KurikaesiNijou(a, b/2, P) % P;
return a * c * c % P;
}
}*/
ll GCD(int a, int b) {
if (a % b == 0)
return b;
else
return GCD(b, a % b);
}
ll Min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll Max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
ll Sum(ll a, ll b) { return a + b; }
template <typename T> class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out,
function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num)
n *= 2;
node.resize(2 * n - 1);
fill(node.begin(), node.end(), init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n - 1;
if (customChange)
node[num] = fun2(value, node[num]);
else
node[num] = value;
while (num > 0)
num = (num - 1) / 2,
node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1)
r = n;
if (a <= l && r <= b)
return node[k];
if (b <= l || r <= a)
return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
rangeQuery(a, b, mid, r, 2 * k + 2));
}
};
class Combination {
vector<ll> factorial;
vector<ll> factorial_inv;
ll mod;
ll max_n;
public:
void Init(ll init_max_n, ll init_mod) {
max_n = init_max_n;
mod = init_mod;
factorial.resize(max_n + 1);
factorial[0] = 1;
for (ll i = 1; i < factorial.size(); i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
factorial_inv.resize(max_n + 1);
factorial_inv[0] = 1;
for (ll i = 1; i < factorial_inv.size(); i++) {
factorial_inv[i] = factorial_inv[i - 1] * modinv(i, mod);
factorial_inv[i] %= mod;
}
}
ll GetComb(ll n, ll k) {
ll comb = factorial[n];
comb *= factorial_inv[k];
comb %= mod;
comb *= factorial_inv[n - k];
comb %= mod;
return comb;
}
};
class Tree {
ll node_N;
vector<ll> node;
vector<vector<pl>> pass;
ll diameter = -1;
vector<ll> dist_Diamieter[2];
pl maxDist_Num;
public:
void Init(ll node_Num) {
node_N = node_Num;
node.resize(node_N + 1);
pass.resize(node_N + 1);
dist_Diamieter[0].resize(node_N + 1);
lp(i, node_N + 1) dist_Diamieter[0][i] = -1;
dist_Diamieter[1].resize(node_N + 1);
lp(i, node_N + 1) dist_Diamieter[1][i] = -1;
}
void AddEdge(ll a, ll b, ll dist) {
bufpl.first = b;
bufpl.second = dist;
pass[a].push_back(bufpl);
bufpl.first = a;
pass[b].push_back(bufpl);
}
void DFS(ll step, ll now, ll dist) {
dist_Diamieter[step][now] = dist;
if (dist_Diamieter[step][now] > maxDist_Num.first) {
maxDist_Num.first = dist_Diamieter[step][now];
maxDist_Num.second = now;
}
for (ll i = 0; i < pass[now].size(); i++) {
ll next_node = pass[now][i].first;
if (dist_Diamieter[step][next_node] == -1) {
DFS(step, next_node, dist + pass[now][i].second);
}
}
}
ll GetDiameter(ll min_node_num) {
if (diameter >= 0)
return diameter;
else {
maxDist_Num.first = -1;
maxDist_Num.second = -1;
DFS(0, min_node_num, 0ll);
ll step2_start = maxDist_Num.second;
maxDist_Num.first = -1;
maxDist_Num.second = -1;
DFS(1, step2_start, 0ll);
diameter = maxDist_Num.first;
return diameter;
}
}
ll GetDistFromMinNode(ll num) { return dist_Diamieter[0][num]; }
};
void Nibu(ll node, ll co) {
C[node] = co % 2;
D[co % 2]++;
lp(i, vl[node].size()) {
ll next = vl[node][i];
if (C[next] == -1) {
Nibu(next, co + 1);
}
}
}
Combination combi;
SegmentTree<ll> st;
int main() {
cin >> N >> K;
lp(i, N) cin >> A[i];
lp(i, N) cin >> B[i];
sort(A, A + N);
reverse(A, A + N);
sort(B, B + N);
a = -1;
b = 1000000 * 1000000;
while (a + 1 != b) {
c = (a + b) / 2ll;
d = 0;
lp(i, N) {
e = max(0ll, A[i] * B[i] - c);
d += e / B[i];
if (e % B[i] != 0)
d++;
}
if (d <= K)
b = c;
else
a = c;
}
cout << b << endl;
// cout << fixed << setpql.ecision(10) << ansa << endl;
return 0;
}
| // #pragma once
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdlib> // srand,rand
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define lp(i, n) for (ll i = 0; i < n; i++)
#define modd 1000000007
#define mod2 998244353
#define INF 8223372036854775807ll
#define ALL(a) (a).begin(), (a).end()
typedef pair<long long, long long> pl;
typedef pair<double, double> pd;
typedef pair<ll, string> pls;
typedef string::const_iterator State;
class ParseError {};
/*
class SegmentTree {
private:
ll cont_num = 2;
pd initial_v;
vector<pd> dat;
public:
SegmentTree() {};
void init(ll size, double initial_value_first, double
initial_value_second) {
cont_num = 2;
initial_v.first = initial_value_first;
initial_v.second = initial_value_second;
while (cont_num < size) {
cont_num *= 2;
}
dat.resize(2 * cont_num);//サイズ設定
for (int i = 0; i < 2 * cont_num; i++)dat[i] =
initial_v;//初期化
}
void Update(ll position, double value_f, double value_s) {
ll k = cont_num + position;
dat[k].first = value_f;
dat[k].second = value_s;
while (k > 1) {
k /= 2;
dat[k].first = dat[k * 2 + 1].first * dat[k * 2].first;
dat[k].second = dat[k * 2 + 1].first * dat[k * 2].second
+ dat[k * 2 + 1].second;
}
}
/*
ll query_proces(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)return initial_v;
if (a <= l && r <= b)return dat[k];
else {
ll vl = query_proces(a, b, k * 2, l, (l + r) / 2);
ll vr = query_proces(a, b, k * 2 + 1, (l + r) / 2, r);
return min(vl, vr);
}
}
ll query(ll left, ll right) {
return query_proces(left, right, 1, 0, cont_num);
}
*/
/*
double query() {
return dat[1].first + dat[1].second;
}
};*/
template <typename T> class Zip {
vector<T> d;
bool flag;
void init() {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag)
init();
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag)
init();
return (ll)d.size();
}
};
ll N, M, K, a, b, c, d, e, H, W, L, T;
ll x, y, z;
ll A[2000004] = {};
ll B[2000004] = {};
ll C[2000004] = {};
ll D[1000006] = {};
ll E[1000006] = {};
bool f;
string S[200000];
string SS;
set<long long> sll;
pl bufpl;
vector<long long> vl[200005];
vector<long long> llv[30005];
vector<long long> vll;
vector<long long> v;
vector<pl> vpl;
vector<string> vs;
set<ll> llset;
set<string> Sset;
multiset<ll> llmset;
queue<ll> ql;
multiset<pl> plmset;
typedef struct ST {
ll first;
ll second;
ll cost;
bool operator<(const ST &another) const {
return first < another.first; // 比較
};
bool operator>(const ST &another) const {
return first > another.first; // 比較
};
} ST;
// queue<ST> qst;
priority_queue<ST, vector<ST>, greater<ST>> qst;
multiset<ST> stmset;
ST bufst;
ST stt[100000];
/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/
long long modinv(long long aa, long long mm) {
long long bb = mm, uu = 1, vv = 0;
while (bb) {
long long tt = aa / bb;
aa -= tt * bb;
swap(aa, bb);
uu -= tt * vv;
swap(uu, vv);
}
uu %= mm;
if (uu < 0)
uu += mm;
return uu;
}
ll zettai(ll aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
float zettai(float aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
/*
class UnionFind
{
public:
vector <ll>pairent;
vector <ll>depth;
vector <ll>size;
UnionFind(ll Amount) : pairent(Amount, 1), depth(Amount, 1),
size(Amount, 1) {
for (ll i = 0; i < Amount; i++) {
pairent[i] = i;
}
}
ll FindPairent(ll x) {
if (pairent[x] == x)return x;
else return pairent[x] = FindPairent(pairent[x]);
}
ll Merge(ll x, ll y) {
x = FindPairent(x);
y = FindPairent(y);
if (x != y) {
if (depth[x] > depth[y]) {
pairent[y] = pairent[x];
return size[x] += size[y];
}
else {
pairent[x] = pairent[y];
if (depth[x] == depth[y]) {
depth[y] ++;
}
return size[y] += size[x];
}
}
else {
return -1;
}
}
bool IsSame(ll x, ll y) {
if (FindPairent(x) == FindPairent(y))return true;
else return false;
}
ll GetSize(ll x) {
x = FindPairent(x);
return size[x];
}
};
*/
class UnionFind {
public:
vector<ll> pairent;
vector<ll> depth;
vector<ll> size;
UnionFind(ll Amount) : pairent(Amount, 1), depth(Amount, 1), size(Amount, 1) {
for (ll i = 0; i < Amount; i++) {
pairent[i] = i;
}
}
ll FindPairent(ll x) {
if (pairent[x] == x)
return x;
else
return pairent[x] = FindPairent(pairent[x]);
}
ll Merge(ll x, ll y) {
x = FindPairent(x);
y = FindPairent(y);
if (x != y) {
if (depth[x] > depth[y]) {
pairent[y] = pairent[x];
return size[x] += size[y];
} else {
pairent[x] = pairent[y];
if (depth[x] == depth[y]) {
depth[y]++;
}
return size[y] += size[x];
}
} else {
return -1;
}
}
bool IsSame(ll x, ll y) {
if (FindPairent(x) == FindPairent(y))
return true;
else
return false;
}
ll GetSize(ll x) {
x = FindPairent(x);
return size[x];
}
};
class Nibutan {
public:
ll hidari = 0;
ll migi = 0;
ll abc;
vector<ll> contents;
bool Jouken(int ser) {
if (contents[ser] > abc) {
return true;
} else {
return false;
}
}
void Settings(int amount, ll terget) {
migi = amount - 1;
abc = terget;
}
ll tansaku() {
hidari = -1;
migi = contents.size();
ll jud;
while (hidari != migi - 1) {
jud = hidari + migi;
jud /= 2;
if (Jouken(jud)) {
migi = jud;
} else {
hidari = jud;
}
}
return hidari;
}
};
ll RepeatSquaring(ll N, ll P, ll M) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, M) % M;
return t * t % M;
}
return N * RepeatSquaring(N, P - 1, M) % M;
}
/*
ll KurikaesiNijou(ll a, ll b, ll P) {
if (b == 0)return 1;
if (b % 2 == 0) {
ll c=KurikaesiNijou(a,b/2,P)%P;
return c * c %P;
}
else {
ll c = KurikaesiNijou(a, b/2, P) % P;
return a * c * c % P;
}
}*/
ll GCD(int a, int b) {
if (a % b == 0)
return b;
else
return GCD(b, a % b);
}
ll Min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll Max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
ll Sum(ll a, ll b) { return a + b; }
template <typename T> class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out,
function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num)
n *= 2;
node.resize(2 * n - 1);
fill(node.begin(), node.end(), init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n - 1;
if (customChange)
node[num] = fun2(value, node[num]);
else
node[num] = value;
while (num > 0)
num = (num - 1) / 2,
node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1)
r = n;
if (a <= l && r <= b)
return node[k];
if (b <= l || r <= a)
return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
rangeQuery(a, b, mid, r, 2 * k + 2));
}
};
class Combination {
vector<ll> factorial;
vector<ll> factorial_inv;
ll mod;
ll max_n;
public:
void Init(ll init_max_n, ll init_mod) {
max_n = init_max_n;
mod = init_mod;
factorial.resize(max_n + 1);
factorial[0] = 1;
for (ll i = 1; i < factorial.size(); i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
factorial_inv.resize(max_n + 1);
factorial_inv[0] = 1;
for (ll i = 1; i < factorial_inv.size(); i++) {
factorial_inv[i] = factorial_inv[i - 1] * modinv(i, mod);
factorial_inv[i] %= mod;
}
}
ll GetComb(ll n, ll k) {
ll comb = factorial[n];
comb *= factorial_inv[k];
comb %= mod;
comb *= factorial_inv[n - k];
comb %= mod;
return comb;
}
};
class Tree {
ll node_N;
vector<ll> node;
vector<vector<pl>> pass;
ll diameter = -1;
vector<ll> dist_Diamieter[2];
pl maxDist_Num;
public:
void Init(ll node_Num) {
node_N = node_Num;
node.resize(node_N + 1);
pass.resize(node_N + 1);
dist_Diamieter[0].resize(node_N + 1);
lp(i, node_N + 1) dist_Diamieter[0][i] = -1;
dist_Diamieter[1].resize(node_N + 1);
lp(i, node_N + 1) dist_Diamieter[1][i] = -1;
}
void AddEdge(ll a, ll b, ll dist) {
bufpl.first = b;
bufpl.second = dist;
pass[a].push_back(bufpl);
bufpl.first = a;
pass[b].push_back(bufpl);
}
void DFS(ll step, ll now, ll dist) {
dist_Diamieter[step][now] = dist;
if (dist_Diamieter[step][now] > maxDist_Num.first) {
maxDist_Num.first = dist_Diamieter[step][now];
maxDist_Num.second = now;
}
for (ll i = 0; i < pass[now].size(); i++) {
ll next_node = pass[now][i].first;
if (dist_Diamieter[step][next_node] == -1) {
DFS(step, next_node, dist + pass[now][i].second);
}
}
}
ll GetDiameter(ll min_node_num) {
if (diameter >= 0)
return diameter;
else {
maxDist_Num.first = -1;
maxDist_Num.second = -1;
DFS(0, min_node_num, 0ll);
ll step2_start = maxDist_Num.second;
maxDist_Num.first = -1;
maxDist_Num.second = -1;
DFS(1, step2_start, 0ll);
diameter = maxDist_Num.first;
return diameter;
}
}
ll GetDistFromMinNode(ll num) { return dist_Diamieter[0][num]; }
};
void Nibu(ll node, ll co) {
C[node] = co % 2;
D[co % 2]++;
lp(i, vl[node].size()) {
ll next = vl[node][i];
if (C[next] == -1) {
Nibu(next, co + 1);
}
}
}
Combination combi;
SegmentTree<ll> st;
int main() {
cin >> N >> K;
lp(i, N) cin >> A[i];
lp(i, N) cin >> B[i];
sort(A, A + N);
reverse(A, A + N);
sort(B, B + N);
a = -1;
b = 1000000ll * 1000000ll;
while (a + 1 != b) {
c = (a + b) / 2ll;
d = 0;
lp(i, N) {
e = max(0ll, A[i] * B[i] - c);
d += e / B[i];
if (e % B[i] != 0)
d++;
}
if (d <= K)
b = c;
else
a = c;
}
cout << b << endl;
// cout << fixed << setpql.ecision(10) << ansa << endl;
return 0;
}
| replace | 625 | 626 | 625 | 626 | TLE | |
p02883 | C++ | Runtime Error | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
/* INCLUDES */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
/* TYPES */
#define long long long
#define all(v) v.begin(), v.end()
typedef pair<int, int> pii;
typedef pair<int64_t, int> pli;
typedef pair<int64_t, int64_t> pll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<int64_t>> vvl;
/* CONSTANTS */
const long MOD = 1e9 + 7, LINF = 1e18 + 1e16;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
/* FUNCTIONS */
template <typename T, typename U> inline void setMin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void setMax(T &x, U y) {
if (x < y)
x = y;
}
template <typename T> inline T gcd(T a, T b) {
T c;
while (b)
c = b, b = a % b, a = c;
return a;
}
template <typename T> inline T square(T a, T b) { return a * b; }
const int N = 1e5 + 1;
class TaskE {
long n, k, a[N], f[N];
public:
void solve(istream &cin, ostream &cout) {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++)
cin >> f[i];
long l = 0, r = 1e12;
while (l < r) {
long mid = l + r >> 1;
vector<long> b;
for (int i = 0; i < n; i++) {
b.push_back(mid / f[i]);
}
sort(b.begin(), b.end());
long req = 0;
for (int i = 0; i < n; i++) {
req += max(a[i] - b[i], 0ll);
}
if (req > k)
l = mid + 1;
else
r = mid;
}
cout << l << endl;
}
};
class Solver {
public:
void solve(std::istream &in, std::ostream &out) {
TaskE *obj = new TaskE();
obj->solve(in, out);
delete obj;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
} | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
/* INCLUDES */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
/* TYPES */
#define long long long
#define all(v) v.begin(), v.end()
typedef pair<int, int> pii;
typedef pair<int64_t, int> pli;
typedef pair<int64_t, int64_t> pll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<int64_t>> vvl;
/* CONSTANTS */
const long MOD = 1e9 + 7, LINF = 1e18 + 1e16;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
/* FUNCTIONS */
template <typename T, typename U> inline void setMin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void setMax(T &x, U y) {
if (x < y)
x = y;
}
template <typename T> inline T gcd(T a, T b) {
T c;
while (b)
c = b, b = a % b, a = c;
return a;
}
template <typename T> inline T square(T a, T b) { return a * b; }
const int N = 2e5 + 1;
class TaskE {
long n, k, a[N], f[N];
public:
void solve(istream &cin, ostream &cout) {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++)
cin >> f[i];
long l = 0, r = 1e12;
while (l < r) {
long mid = l + r >> 1;
vector<long> b;
for (int i = 0; i < n; i++) {
b.push_back(mid / f[i]);
}
sort(b.begin(), b.end());
long req = 0;
for (int i = 0; i < n; i++) {
req += max(a[i] - b[i], 0ll);
}
if (req > k)
l = mid + 1;
else
r = mid;
}
cout << l << endl;
}
};
class Solver {
public:
void solve(std::istream &in, std::ostream &out) {
TaskE *obj = new TaskE();
obj->solve(in, out);
delete obj;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
Solver solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
} | replace | 68 | 69 | 68 | 69 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<lint> a(n), f(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> f[i];
}
sort(all(a), greater<lint>());
sort(all(f));
lint cand_top = 1e+12, cand_bot = 0, cand_mid;
while (cand_top > cand_bot) {
lint need = 0;
cand_mid = (cand_top + cand_bot) / 2;
for (int i = 0; i < n; i++) {
// temp:必要なマンパワー
lint temp = cand_mid / f[i];
need += max(a[i] - temp, (lint)0);
}
if (need <= k) {
cand_top = cand_mid;
} else {
cand_bot = cand_mid;
}
if (cand_top - cand_bot <= 1) {
break;
}
}
// cand_botが実現できるか
lint need = 0;
for (int i = 0; i < n; i++) {
// temp:必要なマンパワー
lint temp = cand_bot / f[i];
need += max(a[i] - temp, (lint)0);
}
if (need <= k) {
cout << cand_bot << endl;
} else {
cout << cand_top << endl;
}
} | #include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;
int main() {
lint n, k;
cin >> n >> k;
vector<lint> a(n), f(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> f[i];
}
sort(all(a), greater<lint>());
sort(all(f));
lint cand_top = 1e+12, cand_bot = 0, cand_mid;
while (cand_top > cand_bot) {
lint need = 0;
cand_mid = (cand_top + cand_bot) / 2;
for (int i = 0; i < n; i++) {
// temp:必要なマンパワー
lint temp = cand_mid / f[i];
need += max(a[i] - temp, (lint)0);
}
if (need <= k) {
cand_top = cand_mid;
} else {
cand_bot = cand_mid;
}
if (cand_top - cand_bot <= 1) {
break;
}
}
// cand_botが実現できるか
lint need = 0;
for (int i = 0; i < n; i++) {
// temp:必要なマンパワー
lint temp = cand_bot / f[i];
need += max(a[i] - temp, (lint)0);
}
if (need <= k) {
cout << cand_bot << endl;
} else {
cout << cand_top << endl;
}
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#define debug(x) cerr << #x " => " << x << endl
#else
#define debug(x) 0
#endif
using lint = long long;
constexpr int INF = 1 << 30;
constexpr lint INFL = 1LL << 62;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} INIT;
} // namespace
int main(void) {
int n, k;
cin >> n >> k;
vector<int> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(all(a));
sort(all(f), greater<int>());
lint ok = 1e13, ng = -1;
while (ok - ng > 1) {
lint mid = (ok + ng) / 2, x = 0;
rep(i, n) x += max(0LL, a[i] - mid / f[i]);
if (x <= k)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
return 0;
} | #include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#define debug(x) cerr << #x " => " << x << endl
#else
#define debug(x) 0
#endif
using lint = long long;
constexpr int INF = 1 << 30;
constexpr lint INFL = 1LL << 62;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} INIT;
} // namespace
int main(void) {
lint n, k;
cin >> n >> k;
vector<int> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(all(a));
sort(all(f), greater<int>());
lint ok = 1e13, ng = -1;
while (ok - ng > 1) {
lint mid = (ok + ng) / 2, x = 0;
rep(i, n) x += max(0LL, a[i] - mid / f[i]);
if (x <= k)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02883 | C++ | Time Limit Exceeded | //** aman**/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define dl double
#define hell 1000000007
#define endl '\n'
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
ll chk(vector<ll> a, vector<ll> b, ll n, ll k, ll mid) {
for (ll i = 0; i < n; i++) {
while (a[i] * b[i] > mid && k > 0) {
a[i]--;
k--;
}
if (a[i] * b[i] > mid)
return 0;
}
return 1;
}
int main() {
ios;
ll n, k;
cin >> n >> k;
vector<ll> a(n), b(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
for (ll i = 0; i < n; i++)
cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(a.begin(), a.end());
ll s = 0, e = 1e15, mid, ans;
while (s <= e) {
mid = (s + e) / 2;
// cout<<mid<<endl;
// cout<<(a,b,n,k,mid)<<endl;
if (chk(a, b, n, k, mid)) {
ans = mid;
e = mid - 1;
} else {
s = mid + 1;
}
}
// cout<<k<<endl;
// for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
cout << ans << endl;
return 0;
} | //** aman**/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define dl double
#define hell 1000000007
#define endl '\n'
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
ll chk(vector<ll> a, vector<ll> b, ll n, ll k, ll mid) {
for (ll i = 0; i < n; i++) {
while (a[i] * b[i] > mid && k > 0) {
int x = a[i] - mid / b[i];
a[i] = mid / b[i];
k = k - x;
if (k < 0)
return 0;
}
if (a[i] * b[i] > mid)
return 0;
}
return 1;
}
int main() {
ios;
ll n, k;
cin >> n >> k;
vector<ll> a(n), b(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
for (ll i = 0; i < n; i++)
cin >> b[i];
sort(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(a.begin(), a.end());
ll s = 0, e = 1e15, mid, ans;
while (s <= e) {
mid = (s + e) / 2;
// cout<<mid<<endl;
// cout<<(a,b,n,k,mid)<<endl;
if (chk(a, b, n, k, mid)) {
ans = mid;
e = mid - 1;
} else {
s = mid + 1;
}
}
// cout<<k<<endl;
// for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
cout << ans << endl;
return 0;
} | replace | 24 | 26 | 24 | 29 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
vector<ll> f(n);
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
ll s = 0;
rep(i, n) { s += max(ll(0), a[i] - c / f[i]); }
if (s <= k)
r = c;
else
l = c;
}
cout << r << 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;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y);
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
vector<ll> f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
ll s = 0;
rep(i, n) { s += max(ll(0), a[i] - c / f[i]); }
if (s <= k)
r = c;
else
l = c;
}
cout << r << endl;
return 0;
} | insert | 13 | 13 | 13 | 15 | -8 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
vector<ll> a, f;
ll n;
ll binarySearch_latest(bool (*callback)(ll, ll), ll userQuery = 0) {
int ng = -1;
ll ok = 10e12;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (callback(mid, userQuery)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
bool judge1(ll arrValue, ll user) {
ll ans = 0;
for (int i = 0; i < n; i++) {
ll sa = a[i] * f[i] - arrValue;
if (sa <= 0)
continue;
ll tmp = sa / f[i];
if (sa % f[i] != 0)
tmp++;
ans += tmp;
}
return ans <= user;
}
int main() {
ll k;
cin >> n >> k;
rep(i, n) {
int tmp;
cin >> tmp;
a.push_back(tmp);
}
rep(i, n) {
int tmp;
cin >> tmp;
f.push_back(tmp);
}
sort(a.begin(), a.end(), greater<ll>());
sort(f.begin(), f.end());
cout << binarySearch_latest(judge1, k) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
vector<ll> a, f;
ll n;
ll binarySearch_latest(bool (*callback)(ll, ll), ll userQuery = 0) {
ll ng = -1;
ll ok = 10e12;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (callback(mid, userQuery)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
bool judge1(ll arrValue, ll user) {
ll ans = 0;
for (int i = 0; i < n; i++) {
ll sa = a[i] * f[i] - arrValue;
if (sa <= 0)
continue;
ll tmp = sa / f[i];
if (sa % f[i] != 0)
tmp++;
ans += tmp;
}
return ans <= user;
}
int main() {
ll k;
cin >> n >> k;
rep(i, n) {
int tmp;
cin >> tmp;
a.push_back(tmp);
}
rep(i, n) {
int tmp;
cin >> tmp;
f.push_back(tmp);
}
sort(a.begin(), a.end(), greater<ll>());
sort(f.begin(), f.end());
cout << binarySearch_latest(judge1, k) << endl;
}
| replace | 10 | 11 | 10 | 11 | TLE | |
p02883 | C++ | Runtime Error | // AUTHOR: *Akash Shrivastva*
// Birla Institute of Technology,Mesra,India
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define F first
#define S second
#define PII pair<ll, ll>
ll a[200001], f[200001], n, k;
ll check(ll mid) {
ll i, c = 0;
for (i = 0; i < n; i++) {
if (a[i] * f[i] > mid)
c += a[i] - mid / f[i];
}
if (c <= k)
return 1;
else
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n >> k;
a[n];
f[n];
ll i;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
cin >> f[i];
sort(a, a + n);
sort(f, f + n);
reverse(f, f + n);
ll lb = 0, up = pow(10, 12), ans, mid, cnt;
while (lb <= up) {
mid = (lb + up) / 2;
if (check(mid))
ans = mid, up = mid - 1;
else
lb = mid + 1;
}
cout << ans << endl;
} | // AUTHOR: *Akash Shrivastva*
// Birla Institute of Technology,Mesra,India
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define M 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define F first
#define S second
#define PII pair<ll, ll>
ll a[200001], f[200001], n, k;
ll check(ll mid) {
ll i, c = 0;
for (i = 0; i < n; i++) {
if (a[i] * f[i] > mid)
c += a[i] - mid / f[i];
}
if (c <= k)
return 1;
else
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
a[n];
f[n];
ll i;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = 0; i < n; i++)
cin >> f[i];
sort(a, a + n);
sort(f, f + n);
reverse(f, f + n);
ll lb = 0, up = pow(10, 12), ans, mid, cnt;
while (lb <= up) {
mid = (lb + up) / 2;
if (check(mid))
ans = mid, up = mid - 1;
else
lb = mid + 1;
}
cout << ans << endl;
} | delete | 30 | 34 | 30 | 30 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<long long, long long> Pdd;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
Sort(f);
Sort(a);
Reverse(f);
vector<Pdd> af(n);
rep(i, n) af[i] = Pdd(a[i] * f[i], f[i]);
ll l = 0, r = 2e12;
int cnt = 0;
while (cnt != 100) {
cnt++;
ll mid = (l + r) / 2;
ll sum = 0;
rep(i, n) {
if (af[i].first > mid) {
sum += (af[i].first - mid - 1) / af[i].second + 1;
}
}
if (sum > k) {
l = mid;
} else if (sum <= k) {
r = mid;
}
}
r = min(r, 500ll);
while (1) {
ll sum = 0;
rep(i, n) {
if (af[i].first > r) {
sum += (af[i].first - r - 1) / af[i].second + 1;
}
}
if (sum <= k) {
cout << r << endl;
return 0;
}
r++;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i, k, n) for (int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<long long, long long> Pdd;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
Sort(f);
Sort(a);
Reverse(f);
vector<Pdd> af(n);
rep(i, n) af[i] = Pdd(a[i] * f[i], f[i]);
ll l = 0, r = 2e12;
int cnt = 0;
while (cnt != 100) {
cnt++;
ll mid = (l + r) / 2;
ll sum = 0;
rep(i, n) {
if (af[i].first > mid) {
sum += (af[i].first - mid - 1) / af[i].second + 1;
}
}
if (sum > k) {
l = mid;
} else if (sum <= k) {
r = mid;
}
}
r = max(0ll, r - 500ll);
while (1) {
ll sum = 0;
rep(i, n) {
if (af[i].first > r) {
sum += (af[i].first - r - 1) / af[i].second + 1;
}
}
if (sum <= k) {
cout << r << endl;
return 0;
}
r++;
}
return 0;
}
| replace | 41 | 42 | 41 | 42 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for (auto it = li.begin(); it != li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.rbegin(), a.rend());
sort(f.begin(), f.end());
ll l = -1, r = 1000000000000; // l ng r ok
while (l + 1 < r) {
ll m = (l + r) / 2;
ll c = 0;
rep(i, n) c += max((ll)0, (ll)a[i] - m / f[i]);
if (c <= k)
r = m;
else
l = m;
}
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for (auto it = li.begin(); it != li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
ll k;
cin >> n >> k;
vector<int> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.rbegin(), a.rend());
sort(f.begin(), f.end());
ll l = -1, r = 1000000000000; // l ng r ok
while (l + 1 < r) {
ll m = (l + r) / 2;
ll c = 0;
rep(i, n) c += max((ll)0, (ll)a[i] - m / f[i]);
if (c <= k)
r = m;
else
l = m;
}
cout << r << endl;
return 0;
}
| replace | 8 | 9 | 8 | 10 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long limit = 2e12;
long long a[N], b[N];
void usain_bolt() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int main() {
usain_bolt();
long long n, m, mn = 2000000000005LL;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
reverse(a + 1, a + 1 + n);
long long left = 0, right = 2000000000005LL;
while (left <= right) {
long long mid = (left + right) / 2LL;
long long need = 0;
for (int i = 1; i <= n; ++i) {
if (b[i]) {
long long sterg = mid / b[i];
need += max(0LL, a[i] - sterg);
}
}
if (need <= m)
mn = min(mn, mid), right = mid - 1LL;
else
left = mid + 1LL;
}
cout << mn;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const long long limit = 2e12;
long long a[N], b[N];
void usain_bolt() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int main() {
usain_bolt();
long long n, m, mn = 2000000000005LL;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
reverse(a + 1, a + 1 + n);
long long left = 0, right = 2000000000005LL;
while (left <= right) {
long long mid = (left + right) / 2LL;
long long need = 0;
for (int i = 1; i <= n; ++i) {
if (b[i]) {
long long sterg = mid / b[i];
need += max(0LL, a[i] - sterg);
}
}
if (need <= m)
mn = min(mn, mid), right = mid - 1LL;
else
left = mid + 1LL;
}
cout << mn;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define IFOR(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define RPT(i, a, b) for (int i = (a); i < ((a) + (b)); ++i)
#define IRPT(i, a, b) for (int i = ((a) + (b)-1); i >= (a); --i)
#define ALL(x) x.begin(), x.end()
void solve() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), f(n);
FOR(i, 0, n) cin >> a[i];
FOR(i, 0, n) cin >> f[i];
sort(ALL(a));
sort(ALL(f));
reverse(ALL(f));
vector<pair<ll, ll>> af(n + 1);
FOR(i, 0, n) {
af[i].first = a[i];
af[i].second = f[i];
}
af[n].first = 0;
af[n].second = 1;
sort(ALL(af), [&](pair<ll, ll> a, pair<ll, ll> b) {
if (a.first * a.second >= b.first * b.second)
return true;
else
return false;
});
// for(auto x: af) cout << x.first << " " << x.second << endl; cout << endl;
ll cost = (ll)1 << 45;
ll cr = cost + 1, cl = -1, cm;
while (cr - cl > 1) {
cm = (cl + cr) / 2;
ll sk = 0;
FOR(i, 0, n) {
if (a[i] * f[i] > cm) {
ll tmp = (a[i] * f[i] - cm + f[i] - 1) / f[i];
sk += tmp;
}
}
if (sk > k)
cl = cm;
else
cr = cm;
}
cout << cr << endl;
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define IFOR(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define RPT(i, a, b) for (int i = (a); i < ((a) + (b)); ++i)
#define IRPT(i, a, b) for (int i = ((a) + (b)-1); i >= (a); --i)
#define ALL(x) x.begin(), x.end()
void solve() {
ll n, k;
cin >> n >> k;
vector<ll> a(n), f(n);
FOR(i, 0, n) cin >> a[i];
FOR(i, 0, n) cin >> f[i];
sort(ALL(a));
sort(ALL(f));
reverse(ALL(f));
// for(auto x: af) cout << x.first << " " << x.second << endl; cout << endl;
ll cost = (ll)1 << 45;
ll cr = cost + 1, cl = -1, cm;
while (cr - cl > 1) {
cm = (cl + cr) / 2;
ll sk = 0;
FOR(i, 0, n) {
if (a[i] * f[i] > cm) {
ll tmp = (a[i] * f[i] - cm + f[i] - 1) / f[i];
sk += tmp;
}
}
if (sk > k)
cl = cm;
else
cr = cm;
}
cout << cr << endl;
}
int main() {
solve();
return 0;
} | delete | 19 | 32 | 19 | 19 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define f(i, a, b) for (ll i = a; i < b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define inter \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
// policy-based
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
const ll MAX = 1e5 + 100;
const ll inf = 1e15;
const ll mod = 1e9 + 7;
ll a[MAX], b[MAX], n, k;
bool go(ll x) {
vi num;
f(i, 0, n) num.push_back(x / b[i]);
sort(all(num));
ll ans = 0;
f(i, 0, n) ans += max(0LL, a[i] - num[i]);
return ans <= k;
}
int main() {
fastio;
cin >> n >> k;
f(i, 0, n) cin >> a[i];
f(i, 0, n) cin >> b[i];
sort(a, a + n);
ll ini = 0, fin = 1e12;
while (ini < fin) {
ll mid = (ini + fin) / 2;
if (go(mid))
fin = mid;
else
ini = mid + 1;
}
cout << ini << endl;
} | #include <bits/stdc++.h>
#define f(i, a, b) for (ll i = a; i < b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define inter \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
// policy-based
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
const ll MAX = 1e6 + 100;
const ll inf = 1e15;
const ll mod = 1e9 + 7;
ll a[MAX], b[MAX], n, k;
bool go(ll x) {
vi num;
f(i, 0, n) num.push_back(x / b[i]);
sort(all(num));
ll ans = 0;
f(i, 0, n) ans += max(0LL, a[i] - num[i]);
return ans <= k;
}
int main() {
fastio;
cin >> n >> k;
f(i, 0, n) cin >> a[i];
f(i, 0, n) cin >> b[i];
sort(a, a + n);
ll ini = 0, fin = 1e12;
while (ini < fin) {
ll mid = (ini + fin) / 2;
if (go(mid))
fin = mid;
else
ini = mid + 1;
}
cout << ini << endl;
} | replace | 44 | 45 | 44 | 45 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n;
long long k;
long long a[maxn], f[maxn];
bool cmp(int x, int y) { return x > y; }
bool check(long long t) {
long long tmp = 0;
for (int i = 0; i < n; i++) {
tmp += max(0LL, a[i] - t / f[i]);
}
// printf("%lld %lldss\n",t,tmp);
return tmp <= k;
}
int main() {
scanf("%d%lld", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", a + i);
}
for (int i = 0; i < n; i++) {
scanf("%lld", f + i);
}
sort(f, f + n, cmp);
sort(a, a + n);
long long l = 0, r = 1LL * a[n - 1] * f[0], ans;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n;
long long k;
long long a[maxn], f[maxn];
bool cmp(int x, int y) { return x > y; }
bool check(long long t) {
long long tmp = 0;
for (int i = 0; i < n; i++) {
tmp += max(0LL, a[i] - t / f[i]);
}
// printf("%lld %lldss\n",t,tmp);
return tmp <= k;
}
int main() {
scanf("%d%lld", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", a + i);
}
for (int i = 0; i < n; i++) {
scanf("%lld", f + i);
}
sort(f, f + n, cmp);
sort(a, a + n);
long long l = 0, r = 1LL * a[n - 1] * f[0], ans;
while (l <= r) {
long long mid = (l + r) >> 1;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int>> RHEAP;
const int N = 100010, M = 1010;
int n;
LL m;
LL a[N], b[N];
bool check(LL x) {
LL cnt = 0;
for (int i = 0; i < n; i++)
if (a[i] * b[i] > x)
cnt += a[i] - x / b[i];
return cnt <= m;
}
int main() {
scanf("%d%lld", &n, &m);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
for (int i = 0; i < n; i++)
scanf("%lld", &b[i]);
sort(a, a + n);
sort(b, b + n);
reverse(a, a + n);
LL l = 0LL, r = 1e12 + 10;
while (l < r) {
LL mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1LL;
}
printf("%lld\n", r);
return 0;
} | #include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int>> RHEAP;
const int N = 200010, M = 1010;
int n;
LL m;
LL a[N], b[N];
bool check(LL x) {
LL cnt = 0;
for (int i = 0; i < n; i++)
if (a[i] * b[i] > x)
cnt += a[i] - x / b[i];
return cnt <= m;
}
int main() {
scanf("%d%lld", &n, &m);
for (int i = 0; i < n; i++)
scanf("%lld", &a[i]);
for (int i = 0; i < n; i++)
scanf("%lld", &b[i]);
sort(a, a + n);
sort(b, b + n);
reverse(a, a + n);
LL l = 0LL, r = 1e12 + 10;
while (l < r) {
LL mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1LL;
}
printf("%lld\n", r);
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;
const ll MOD = (ll)998244353;
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) \
for (auto a_ : x_) \
cerr << a_ << " "; \
cerr << endl;
#define dbg3(x_, sx_) \
rep(i, sx_) cerr << x_[i] << " "; \
cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }
void finish() {
cout << -1 << endl;
exit(0);
}
//------------------------------------------------------
ll n, k;
ll a[100010], f[100010];
bool can(ll Max_score) {
ll cnt = 0;
rep(i, n) {
if (a[i] * f[i] <= Max_score)
continue;
cnt += a[i] - (Max_score / f[i]);
}
return cnt <= k;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << setiosflags(ios::fixed);
cin >> n >> k;
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a, a + n);
sort(f, f + n);
reverse(f, f + n);
ll lo = -1, hi = (ll)(1e12);
while (hi - lo > 1) {
ll mi = (lo + hi) / 2;
if (can(mi))
hi = mi;
else
lo = mi;
}
cout << hi << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;
const ll MOD = (ll)998244353;
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) \
for (auto a_ : x_) \
cerr << a_ << " "; \
cerr << endl;
#define dbg3(x_, sx_) \
rep(i, sx_) cerr << x_[i] << " "; \
cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }
void finish() {
cout << -1 << endl;
exit(0);
}
//------------------------------------------------------
ll n, k;
ll a[200010], f[200010];
bool can(ll Max_score) {
ll cnt = 0;
rep(i, n) {
if (a[i] * f[i] <= Max_score)
continue;
cnt += a[i] - (Max_score / f[i]);
}
return cnt <= k;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << setiosflags(ios::fixed);
cin >> n >> k;
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a, a + n);
sort(f, f + n);
reverse(f, f + n);
ll lo = -1, hi = (ll)(1e12);
while (hi - lo > 1) {
ll mi = (lo + hi) / 2;
if (can(mi))
hi = mi;
else
lo = mi;
}
cout << hi << endl;
return 0;
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, K, A[20005], F[20005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i < N; i++)
cin >> F[i];
sort(A, A + N);
sort(F, F + N, greater<ll>());
ll lo = 0, hi = 1e18 + 1;
while (lo < hi) {
ll mid = (lo + hi) / 2;
ll train = K;
for (int i = 0; i < N; i++) {
if (A[i] * F[i] > mid) {
train -= A[i] - mid / F[i];
}
}
if (train < 0)
lo = mid + 1;
else
hi = mid;
}
cout << lo << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, K, A[200005], F[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 0; i < N; i++)
cin >> F[i];
sort(A, A + N);
sort(F, F + N, greater<ll>());
ll lo = 0, hi = 1e18 + 1;
while (lo < hi) {
ll mid = (lo + hi) / 2;
ll train = K;
for (int i = 0; i < N; i++) {
if (A[i] * F[i] > mid) {
train -= A[i] - mid / F[i];
}
}
if (train < 0)
lo = mid + 1;
else
hi = mid;
}
cout << lo << '\n';
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02883 | C++ | Runtime Error | // #include <windows.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// #define int ll
typedef vector<vector<pair<int, int>>> vvp;
typedef vector<pair<int, int>> vp;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;
typedef vector<vector<bool>> vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
// #define unix ((unsigned int)time(NULL))
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define inputv(v) \
for (int i = 0; i < (v.size()); i++) \
cin >> v[i];
#define inputvv(v) \
for (int i = 0; i < (v.size()); i++) \
for (int j = 0; j < (v[0].size()); j++) \
cin >> v[i][j];
#define all(x) (x).begin(), (x).end()
#define yn(f) cout << (f ? "yes" : "no") << endl
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define POSSIBLE(f) cout << ((f) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(f) cout << ((f) ? "Possible" : "Impossible") << endl
#define nil -1
const int inf8 = 1e8;
const int inf = 1e9 + 7;
const ll inf18 = 1e18;
void puts() { cout << endl; }
template <class T>
void puts(T a) {
cout << (a) << endl;
}
/*
template <class Head, class... Tail>
void puts(Head&& head, Tail&& ... tail) {
cout << head;
if (sizeof...(tail) == 0) {
puts();
}
else {
cout << " ";
puts(forward<Tail>(tail)...);
}
}
*/
void puts(pair<int, int> A) {
cout << "(" << A.first << "," << A.second << ")" << endl;
;
}
void puts(vector<pair<int, int>> &A) {
for (int i = 0; i < A.size(); i++) {
cout << "(" << A[i].first << "," << A[i].second << ")";
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
void puts(vector<vector<pair<int, int>>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
template <class T> void puts(vector<T> &A) {
for (int i = 0; i < A.size(); i++) {
cout << A[i];
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
template <class T> void puts(const vector<T> &A) {
for (int i = 0; i < A.size(); i++) {
cout << A[i];
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
template <class T> void puts(vector<vector<T>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
template <class T> void puts(const vector<vector<T>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
class disjoint_set {
public:
vi p, rank;
disjoint_set(int size) {
p.resize(size, 0);
rank.resize(size, 0);
for (int i = 0; i < size; i++)
makeSet(i);
}
void makeSet(int x) {
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y) { return findSet(x) == findSet(y); }
void unite(int x, int y) { link(findSet(x), findSet(y)); }
void link(int x, int y) {
if (rank[x] < rank[y]) {
p[x] = y;
} else {
p[y] = x;
if (rank[x] == rank[y]) {
rank[x]++;
}
}
}
int findSet(int x) {
if (x != p[x]) {
p[x] = findSet(p[x]);
}
return p[x];
}
};
class rmq {
public:
int n, inf_, max_n;
vi A;
rmq(int n_) {
n = 1;
inf_ = INT_MAX;
max_n = (1 << 18);
while (n < n_)
n *= 2;
A.resize(max_n * 2 - 1);
for (int i = 0; i < n * 2 - 1; i++)
A[i] = inf_;
}
void update(int i, int x) {
i += n - 1;
A[i] = x;
while (i > 0) {
i = (i - 1) / 2;
A[i] = min(A[i * 2 + 1], A[i * 2 + 2]);
}
}
int query(int left, int right, int i = 0, int left2 = 0, int right2 = -1) {
if (right2 == -1)
right2 = n;
if (right2 <= left || right <= left2) {
return inf_;
}
if (left <= left2 && right2 <= right) {
return A[i];
} else {
int mid = (left2 + right2) / 2;
return min(query(left, right, i * 2 + 1, left2, mid),
query(left, right, i * 2 + 2, mid, right2));
}
}
};
class rsq { // 遅延セグ木
public:
int n, max_n;
vl A, Lazy;
rsq(int n_) {
n = 1;
max_n = (1 << 18);
while (n < n_)
n *= 2;
A.resize(max_n * 2 - 1);
Lazy.resize(max_n * 2 - 1);
}
void propagate(int i, int left, int right) {
if (Lazy[i] != 0) {
A[i] += Lazy[i];
if (right - left > 1) {
Lazy[i * 2 + 1] += Lazy[i] / 2;
Lazy[i * 2 + 2] += Lazy[i] / 2;
}
Lazy[i] = 0;
}
}
void add(int left, int right, int x, int i = 0, int left2 = 0,
int right2 = -1) {
if (right2 == -1)
right2 = n;
propagate(i, left2, right2);
if (right <= left2 || right2 <= left)
return;
if (left <= left2 && right2 <= right) {
Lazy[i] += (right2 - left2) * x;
propagate(i, left2, right2);
} else {
int mid = (left2 + right2) / 2;
add(left, right, x, i * 2 + 1, left2, mid);
add(left, right, x, i * 2 + 2, mid, right2);
A[i] = A[i * 2 + 1] + A[i * 2 + 2];
}
}
ll sum(int left, int right, int i = 0, int left2 = 0, int right2 = -1) {
if (right2 == -1)
right2 = n;
if (right2 <= left || right <= left2)
return 0;
propagate(i, left2, right2);
if (left <= left2 && right2 <= right) {
return A[i];
} else {
int mid = (left2 + right2) / 2;
ll res = 0;
res += sum(left, right, i * 2 + 1, left2, mid);
res += sum(left, right, i * 2 + 2, mid, right2);
return res;
}
}
};
class binary_indexed_tree { // 1-indexed
public:
int n;
vl A;
binary_indexed_tree(int n_) {
n = n_;
A.resize(n + 1); // 1-indexed
}
ll sum(int i) { //[0,i]の和を返す
ll res = 0;
while (i > 0) {
res += A[i];
i -= i & -i;
}
return res;
}
void add(int i, int x) {
while (0 < i && i <= n) {
A[i] += x;
i += i & -i;
}
}
};
void dedupe(vi &A) {
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
}
int gcd(int a, int b) { // log N
return (b == 0) ? a : gcd(b, a % b);
}
ll gcd(ll a, ll b) { // log N
return (b == 0) ? a : gcd(b, a % b);
}
int lcm(int a, int b) { // log N
return (a * b) / gcd(a, b);
}
ll lcm(ll a, ll b) { // log N
return (a * b) / gcd(a, b);
}
int extgcd(int a, int b, int &x, int &y) { // log N
int d = a;
if (b == 0) {
x = 1;
y = 0;
} else {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
return d;
}
vi get_primes(int limit) { // N log N
vb A(limit + 1, true);
for (int i = 2; i < A.size(); i++) {
if (!A[i])
continue;
for (int j = i * 2; j < A.size(); j += i)
A[j] = false;
}
vi B;
for (int i = 2; i < A.size(); i++) {
if (A[i])
B.push_back(i);
}
return B;
}
template <class T> bool is_prime(T num) { // sqrt(N)
if (num < 2)
return false;
for (ll i = 2; i <= sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
ll merge_count(vi &A) { // N log N
const int inf = 1000000007;
int n = A.size();
if (n <= 1)
return 0;
long long count = 0;
int mid = n / 2;
vector<int> B(A.begin(), A.begin() + mid);
vector<int> C(A.begin() + mid, A.end());
count += merge_count(B);
count += merge_count(C);
B.push_back(inf);
C.push_back(inf);
int B_i = 0;
int C_i = 0;
for (int i = 0; i < n; i++) {
if (B[B_i] <= C[C_i]) {
A[i] = B[B_i++];
} else {
count += (n / 2) - B_i;
A[i] = C[C_i++];
}
}
return count;
}
vi bit(int num, int size) {
vi A;
for (int j = 0; j < size; j++) {
if ((num & (1 << (size - j - 1))) > 0) {
A.push_back(1);
} else {
A.push_back(0);
}
}
return A;
}
vvi bit_z(int size) { // 2**N
vvi A;
for (int i = 0; i < (1 << size); i++) {
vi temp = bit(i, size);
A.push_back(temp);
}
return A;
}
vvi bit_z(int size, int n) {
vvi A;
int s = (1 << n) - 1;
A.push_back(bit(s, size));
while (true) {
int x = s & (-s);
int y = s + x;
int z = s & (~y);
z /= x;
z = z >> 1;
s = (y | z);
if (s >= (1 << size))
break;
A.push_back(bit(s, size));
}
return A;
}
vvi bit_z(int size, int min, int max) {
vvi A;
for (int i = min; i <= max; i++) {
vvi B = bit_z(size, i);
A.insert(A.end(), B.begin(), B.end());
}
return A;
}
int random(int min, int max) {
int r = rand() % (max + 1 - min) + min;
return r;
}
vector<pair<ll, int>> factorize(ll n) {
ll count = 0;
vector<pair<ll, int>> res;
for (ll i = 2; i * i <= n; i++) {
if (n % i)
continue;
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
signed main() {
int n, k;
cin >> n >> k;
vi A(n);
rep(i, 0, n) cin >> A[i];
vi F(n);
rep(i, 0, n) cin >> F[i];
sort(all(A));
sort(all(F));
reverse(all(F));
ll l = -1;
ll r = 100000000000000;
while (r - l > 1) {
ll mid = (l + r) / 2;
ll k_count = 0;
for (int i = 0; i < n; i++) {
k_count += max(0ll, A[i] - mid / F[i]);
}
if (k_count > k)
l = mid;
else
r = mid;
}
puts(r);
}
| // #include <windows.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// #define int ll
typedef vector<vector<pair<int, int>>> vvp;
typedef vector<pair<int, int>> vp;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;
typedef vector<vector<bool>> vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
// #define unix ((unsigned int)time(NULL))
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define inputv(v) \
for (int i = 0; i < (v.size()); i++) \
cin >> v[i];
#define inputvv(v) \
for (int i = 0; i < (v.size()); i++) \
for (int j = 0; j < (v[0].size()); j++) \
cin >> v[i][j];
#define all(x) (x).begin(), (x).end()
#define yn(f) cout << (f ? "yes" : "no") << endl
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define POSSIBLE(f) cout << ((f) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(f) cout << ((f) ? "Possible" : "Impossible") << endl
#define nil -1
const int inf8 = 1e8;
const int inf = 1e9 + 7;
const ll inf18 = 1e18;
void puts() { cout << endl; }
template <class T>
void puts(T a) {
cout << (a) << endl;
}
/*
template <class Head, class... Tail>
void puts(Head&& head, Tail&& ... tail) {
cout << head;
if (sizeof...(tail) == 0) {
puts();
}
else {
cout << " ";
puts(forward<Tail>(tail)...);
}
}
*/
void puts(pair<int, int> A) {
cout << "(" << A.first << "," << A.second << ")" << endl;
;
}
void puts(vector<pair<int, int>> &A) {
for (int i = 0; i < A.size(); i++) {
cout << "(" << A[i].first << "," << A[i].second << ")";
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
void puts(vector<vector<pair<int, int>>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
template <class T> void puts(vector<T> &A) {
for (int i = 0; i < A.size(); i++) {
cout << A[i];
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
template <class T> void puts(const vector<T> &A) {
for (int i = 0; i < A.size(); i++) {
cout << A[i];
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
template <class T> void puts(vector<vector<T>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
template <class T> void puts(const vector<vector<T>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
class disjoint_set {
public:
vi p, rank;
disjoint_set(int size) {
p.resize(size, 0);
rank.resize(size, 0);
for (int i = 0; i < size; i++)
makeSet(i);
}
void makeSet(int x) {
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y) { return findSet(x) == findSet(y); }
void unite(int x, int y) { link(findSet(x), findSet(y)); }
void link(int x, int y) {
if (rank[x] < rank[y]) {
p[x] = y;
} else {
p[y] = x;
if (rank[x] == rank[y]) {
rank[x]++;
}
}
}
int findSet(int x) {
if (x != p[x]) {
p[x] = findSet(p[x]);
}
return p[x];
}
};
class rmq {
public:
int n, inf_, max_n;
vi A;
rmq(int n_) {
n = 1;
inf_ = INT_MAX;
max_n = (1 << 18);
while (n < n_)
n *= 2;
A.resize(max_n * 2 - 1);
for (int i = 0; i < n * 2 - 1; i++)
A[i] = inf_;
}
void update(int i, int x) {
i += n - 1;
A[i] = x;
while (i > 0) {
i = (i - 1) / 2;
A[i] = min(A[i * 2 + 1], A[i * 2 + 2]);
}
}
int query(int left, int right, int i = 0, int left2 = 0, int right2 = -1) {
if (right2 == -1)
right2 = n;
if (right2 <= left || right <= left2) {
return inf_;
}
if (left <= left2 && right2 <= right) {
return A[i];
} else {
int mid = (left2 + right2) / 2;
return min(query(left, right, i * 2 + 1, left2, mid),
query(left, right, i * 2 + 2, mid, right2));
}
}
};
class rsq { // 遅延セグ木
public:
int n, max_n;
vl A, Lazy;
rsq(int n_) {
n = 1;
max_n = (1 << 18);
while (n < n_)
n *= 2;
A.resize(max_n * 2 - 1);
Lazy.resize(max_n * 2 - 1);
}
void propagate(int i, int left, int right) {
if (Lazy[i] != 0) {
A[i] += Lazy[i];
if (right - left > 1) {
Lazy[i * 2 + 1] += Lazy[i] / 2;
Lazy[i * 2 + 2] += Lazy[i] / 2;
}
Lazy[i] = 0;
}
}
void add(int left, int right, int x, int i = 0, int left2 = 0,
int right2 = -1) {
if (right2 == -1)
right2 = n;
propagate(i, left2, right2);
if (right <= left2 || right2 <= left)
return;
if (left <= left2 && right2 <= right) {
Lazy[i] += (right2 - left2) * x;
propagate(i, left2, right2);
} else {
int mid = (left2 + right2) / 2;
add(left, right, x, i * 2 + 1, left2, mid);
add(left, right, x, i * 2 + 2, mid, right2);
A[i] = A[i * 2 + 1] + A[i * 2 + 2];
}
}
ll sum(int left, int right, int i = 0, int left2 = 0, int right2 = -1) {
if (right2 == -1)
right2 = n;
if (right2 <= left || right <= left2)
return 0;
propagate(i, left2, right2);
if (left <= left2 && right2 <= right) {
return A[i];
} else {
int mid = (left2 + right2) / 2;
ll res = 0;
res += sum(left, right, i * 2 + 1, left2, mid);
res += sum(left, right, i * 2 + 2, mid, right2);
return res;
}
}
};
class binary_indexed_tree { // 1-indexed
public:
int n;
vl A;
binary_indexed_tree(int n_) {
n = n_;
A.resize(n + 1); // 1-indexed
}
ll sum(int i) { //[0,i]の和を返す
ll res = 0;
while (i > 0) {
res += A[i];
i -= i & -i;
}
return res;
}
void add(int i, int x) {
while (0 < i && i <= n) {
A[i] += x;
i += i & -i;
}
}
};
void dedupe(vi &A) {
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
}
int gcd(int a, int b) { // log N
return (b == 0) ? a : gcd(b, a % b);
}
ll gcd(ll a, ll b) { // log N
return (b == 0) ? a : gcd(b, a % b);
}
int lcm(int a, int b) { // log N
return (a * b) / gcd(a, b);
}
ll lcm(ll a, ll b) { // log N
return (a * b) / gcd(a, b);
}
int extgcd(int a, int b, int &x, int &y) { // log N
int d = a;
if (b == 0) {
x = 1;
y = 0;
} else {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
return d;
}
vi get_primes(int limit) { // N log N
vb A(limit + 1, true);
for (int i = 2; i < A.size(); i++) {
if (!A[i])
continue;
for (int j = i * 2; j < A.size(); j += i)
A[j] = false;
}
vi B;
for (int i = 2; i < A.size(); i++) {
if (A[i])
B.push_back(i);
}
return B;
}
template <class T> bool is_prime(T num) { // sqrt(N)
if (num < 2)
return false;
for (ll i = 2; i <= sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
ll merge_count(vi &A) { // N log N
const int inf = 1000000007;
int n = A.size();
if (n <= 1)
return 0;
long long count = 0;
int mid = n / 2;
vector<int> B(A.begin(), A.begin() + mid);
vector<int> C(A.begin() + mid, A.end());
count += merge_count(B);
count += merge_count(C);
B.push_back(inf);
C.push_back(inf);
int B_i = 0;
int C_i = 0;
for (int i = 0; i < n; i++) {
if (B[B_i] <= C[C_i]) {
A[i] = B[B_i++];
} else {
count += (n / 2) - B_i;
A[i] = C[C_i++];
}
}
return count;
}
vi bit(int num, int size) {
vi A;
for (int j = 0; j < size; j++) {
if ((num & (1 << (size - j - 1))) > 0) {
A.push_back(1);
} else {
A.push_back(0);
}
}
return A;
}
vvi bit_z(int size) { // 2**N
vvi A;
for (int i = 0; i < (1 << size); i++) {
vi temp = bit(i, size);
A.push_back(temp);
}
return A;
}
vvi bit_z(int size, int n) {
vvi A;
int s = (1 << n) - 1;
A.push_back(bit(s, size));
while (true) {
int x = s & (-s);
int y = s + x;
int z = s & (~y);
z /= x;
z = z >> 1;
s = (y | z);
if (s >= (1 << size))
break;
A.push_back(bit(s, size));
}
return A;
}
vvi bit_z(int size, int min, int max) {
vvi A;
for (int i = min; i <= max; i++) {
vvi B = bit_z(size, i);
A.insert(A.end(), B.begin(), B.end());
}
return A;
}
int random(int min, int max) {
int r = rand() % (max + 1 - min) + min;
return r;
}
vector<pair<ll, int>> factorize(ll n) {
ll count = 0;
vector<pair<ll, int>> res;
for (ll i = 2; i * i <= n; i++) {
if (n % i)
continue;
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
signed main() {
ll n, k;
cin >> n >> k;
vi A(n);
rep(i, 0, n) cin >> A[i];
vi F(n);
rep(i, 0, n) cin >> F[i];
sort(all(A));
sort(all(F));
reverse(all(F));
ll l = -1;
ll r = 100000000000000;
while (r - l > 1) {
ll mid = (l + r) / 2;
ll k_count = 0;
for (int i = 0; i < n; i++) {
k_count += max(0ll, A[i] - mid / F[i]);
}
if (k_count > k)
l = mid;
else
r = mid;
}
puts(r);
}
| replace | 402 | 403 | 402 | 403 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
ll n, k, A[N], F[N];
bool chk(ll x) {
ll t = 0;
for (int i = 0; i < n; ++i) {
ll m = x / F[n - i - 1];
if (A[i] > m) {
t += A[i] - m;
if (t > k)
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> A[i];
for (int i = 0; i < n; ++i)
cin >> F[i];
sort(A, A + n);
sort(F, F + n);
ll l = 0, r = 0;
for (int i = 0; i < n; ++i)
r = max(r, A[i] * F[n - i - 1]);
while (l <= r) {
ll mid = (l + r) / 2;
if (chk(mid))
r = mid - 1;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
ll n, k, A[N], F[N];
bool chk(ll x) {
ll t = 0;
for (int i = 0; i < n; ++i) {
ll m = x / F[n - i - 1];
if (A[i] > m) {
t += A[i] - m;
if (t > k)
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; ++i)
cin >> A[i];
for (int i = 0; i < n; ++i)
cin >> F[i];
sort(A, A + n);
sort(F, F + n);
ll l = 0, r = 0;
for (int i = 0; i < n; ++i)
r = max(r, A[i] * F[n - i - 1]);
while (l <= r) {
ll mid = (l + r) / 2;
if (chk(mid))
r = mid - 1;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02883 | C++ | Runtime Error | //------------------------------>> tsukasa_diary's template
//<<------------------------------//
#include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
#define allof(a) (a).begin(), (a).end()
#define minit(a, b) memset(a, b, sizeof(a))
using lint = long long;
using pii = pair<int, int>;
template <typename T> using Vec = vector<T>;
template <typename T> bool in_range(T x, T lb, T ub) {
return lb <= x && x < ub;
}
template <typename T> bool in_range(T x, T y, T lb, T ub) {
return in_range(x, lb, ub) && in_range(y, lb, ub);
}
template <typename T> void modAdd(T &a, T b, T mod) { a = (a + b + mod) % mod; }
template <typename T> void modMul(T &a, T b, T mod) { a = (a * b) % mod; }
template <typename T> void minUpdate(T &a, T b) { a = min(a, b); }
template <typename T> void maxUpdate(T &a, T b) { a = max(a, b); }
int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const double EPS = 1e-9;
const double PI = acos(-1);
//--------------8---------------->> coding space
//<<-----------------8-------------//
int main() {
int N, K;
cin >> N >> K;
vector<lint> A(N), F(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
for (int i = 0; i < N; ++i)
cin >> F[i];
sort(allof(A));
sort(allof(F), greater<lint>());
auto valid = [&](lint x) {
lint sum = 0LL;
for (int i = 0; i < N; ++i) {
lint y = x / F[i];
sum += max(0LL, A[i] - y);
}
return sum <= K;
};
lint lb = -1, ub = (lint)1e15;
while (ub - lb > 1) {
lint med = (lb + ub) / 2;
if (valid(med))
ub = med;
else
lb = med;
}
cout << ub << endl;
}
//--------------8---------------->> coding space
//<<-----------------8-------------// | //------------------------------>> tsukasa_diary's template
//<<------------------------------//
#include <bits/stdc++.h>
using namespace std;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define for_rev(i, a, b) for (int i = (a); i >= (b); --i)
#define allof(a) (a).begin(), (a).end()
#define minit(a, b) memset(a, b, sizeof(a))
using lint = long long;
using pii = pair<int, int>;
template <typename T> using Vec = vector<T>;
template <typename T> bool in_range(T x, T lb, T ub) {
return lb <= x && x < ub;
}
template <typename T> bool in_range(T x, T y, T lb, T ub) {
return in_range(x, lb, ub) && in_range(y, lb, ub);
}
template <typename T> void modAdd(T &a, T b, T mod) { a = (a + b + mod) % mod; }
template <typename T> void modMul(T &a, T b, T mod) { a = (a * b) % mod; }
template <typename T> void minUpdate(T &a, T b) { a = min(a, b); }
template <typename T> void maxUpdate(T &a, T b) { a = max(a, b); }
int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const double EPS = 1e-9;
const double PI = acos(-1);
//--------------8---------------->> coding space
//<<-----------------8-------------//
int main() {
int N;
lint K;
cin >> N >> K;
vector<lint> A(N), F(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
for (int i = 0; i < N; ++i)
cin >> F[i];
sort(allof(A));
sort(allof(F), greater<lint>());
auto valid = [&](lint x) {
lint sum = 0LL;
for (int i = 0; i < N; ++i) {
lint y = x / F[i];
sum += max(0LL, A[i] - y);
}
return sum <= K;
};
lint lb = -1, ub = (lint)1e15;
while (ub - lb > 1) {
lint med = (lb + ub) / 2;
if (valid(med))
ub = med;
else
lb = med;
}
cout << ub << endl;
}
//--------------8---------------->> coding space
//<<-----------------8-------------// | replace | 40 | 41 | 40 | 42 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
ll k;
int n;
bool check(ll mid, vector<ll> a, vector<ll> b) {
ll sum = 0;
for (int i = 0; i < n; i++) {
sum += max(a[i] - mid / b[i], 0ll);
}
if (sum > k)
return 0;
else
return 1;
}
int main() {
cout << fixed << setprecision(10);
cin >> n >> k;
vector<ll> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.begin(), a.end());
sort(f.begin(), f.end());
reverse(f.begin(), f.end());
ll left = 0, right = (ll)1e13;
ll mid;
ll cnt = 0;
while (cnt < 1000) {
mid = (left + right) / 2;
if (check(mid, a, f)) {
right = mid;
} else {
left = mid;
}
cnt++;
}
cout << right << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
ll k;
int n;
bool check(ll mid, vector<ll> a, vector<ll> b) {
ll sum = 0;
for (int i = 0; i < n; i++) {
sum += max(a[i] - mid / b[i], 0ll);
}
if (sum > k)
return 0;
else
return 1;
}
int main() {
cout << fixed << setprecision(10);
cin >> n >> k;
vector<ll> a(n), f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
sort(a.begin(), a.end());
sort(f.begin(), f.end());
reverse(f.begin(), f.end());
ll left = 0, right = (ll)1e13;
ll mid;
ll cnt = 0;
while (cnt < 100) {
mid = (left + right) / 2;
if (check(mid, a, f)) {
right = mid;
} else {
left = mid;
}
cnt++;
}
cout << right << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
int main() {
std::ifstream in("input");
std::cin.rdbuf(in.rdbuf());
ll n, k, mx = 0;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
vector<ll> f(n);
rep(i, n) { cin >> f[i]; }
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
rep(i, n) mx = max(a[i] * f[i], mx);
auto judge = [&](ll val) {
ll num = 0;
rep(i, n) {
if (a[i] * f[i] > val)
num += a[i] - val / f[i];
}
if (num > k)
return false;
else
return true;
};
auto binarysearch = [&](ll lowerbound, ll upperbound) {
if (!judge(lowerbound))
return -1LL;
ll lower = lowerbound, upper = upperbound;
while (1) {
if (judge((lower + upper) / 2))
lower = (lower + upper) / 2;
else
upper = (lower + upper) / 2;
if (abs(upper - lower) <= 1) {
if (judge(upper))
return upper;
else
return lower;
}
}
};
cout << binarysearch(mx, 0) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
int main() {
ll n, k, mx = 0;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
vector<ll> f(n);
rep(i, n) { cin >> f[i]; }
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
rep(i, n) mx = max(a[i] * f[i], mx);
auto judge = [&](ll val) {
ll num = 0;
rep(i, n) {
if (a[i] * f[i] > val)
num += a[i] - val / f[i];
}
if (num > k)
return false;
else
return true;
};
auto binarysearch = [&](ll lowerbound, ll upperbound) {
if (!judge(lowerbound))
return -1LL;
ll lower = lowerbound, upper = upperbound;
while (1) {
if (judge((lower + upper) / 2))
lower = (lower + upper) / 2;
else
upper = (lower + upper) / 2;
if (abs(upper - lower) <= 1) {
if (judge(upper))
return upper;
else
return lower;
}
}
};
cout << binarysearch(mx, 0) << endl;
return 0;
} | replace | 6 | 8 | 6 | 7 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long N, K;
cin >> N >> K;
vector<long> A(N), F(N);
for (int i = 0; i < N; i++)
cin >> A.at(i);
for (int i = 0; i < N; i++)
cin >> F.at(i);
sort(A.begin(), A.end());
sort(F.begin(), F.end());
reverse(F.begin(), F.end());
long left = -1;
long right = 1000000000001;
while (left < right) {
long count = 0;
long X = (left + right) / 2;
for (int i = 0; i < N; i++) {
if (A.at(i) * F.at(i) > X)
count += A.at(i) - X / F.at(i);
}
if (count > K)
left = X + 1;
else
right = X;
}
cout << right << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long N, K;
cin >> N >> K;
vector<long> A(N), F(N);
for (int i = 0; i < N; i++)
cin >> A.at(i);
for (int i = 0; i < N; i++)
cin >> F.at(i);
sort(A.begin(), A.end());
sort(F.begin(), F.end());
reverse(F.begin(), F.end());
long left = 0;
long right = 1000000000001;
while (left < right) {
long count = 0;
long X = (left + right) / 2;
for (int i = 0; i < N; i++) {
if (A.at(i) * F.at(i) > X)
count += A.at(i) - X / F.at(i);
}
if (count > K)
left = X + 1;
else
right = X;
}
cout << right << endl;
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
long long k, s = 0;
int a[100100];
int b[100100];
bool cmp(int &s1, int &s2) { return s1 > s2; }
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++)
cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n, cmp);
long long l = 0, r = 1e14;
while (l < r) {
long long mid = (l + r) / 2;
s = 0;
for (int i = 1; i <= n; i++)
s += max(0LL, a[i] - mid / b[i]);
if (s <= k)
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n;
long long k, s = 0;
int a[1000100];
int b[1000100];
bool cmp(int &s1, int &s2) { return s1 > s2; }
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++)
cin >> b[i];
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n, cmp);
long long l = 0, r = 1e14;
while (l < r) {
long long mid = (l + r) / 2;
s = 0;
for (int i = 1; i <= n; i++)
s += max(0LL, a[i] - mid / b[i]);
if (s <= k)
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| replace | 4 | 6 | 4 | 6 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> i) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= x; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
using namespace std;
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0)
DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define DUMP(...)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define MAXN 100100
int a[MAXN];
int f[MAXN];
int N, K;
int sumV = 0;
//----//
//
bool isOK(int mid) {
int tmp = 0;
REP(i, N) {
int tmpval = mid / f[i];
if (tmpval > a[i])
tmpval = a[i];
tmp += a[i] - tmpval;
}
return tmp <= K;
}
signed main() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cin >> N >> K;
REP(i, N) cin >> a[i];
REP(i, N) cin >> f[i];
sort(a, a + N);
reverse(a, a + N);
sort(f, f + N);
int right = 0;
REP(i, N) chmax(right, a[i] * f[i]);
REP(i, N) sumV += a[i];
if (K >= sumV)
print(0);
else {
int left = 0;
while (right - left > 1) {
int mid = (left + right) / 2;
// left trueの場合
if (isOK(mid))
right = mid;
else
left = mid;
} // 不可能 可能
print(right);
}
} | #include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> i) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= x; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
using namespace std;
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0)
DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define DUMP(...)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define MAXN 200200
int a[MAXN];
int f[MAXN];
int N, K;
int sumV = 0;
//----//
//
bool isOK(int mid) {
int tmp = 0;
REP(i, N) {
int tmpval = mid / f[i];
if (tmpval > a[i])
tmpval = a[i];
tmp += a[i] - tmpval;
}
return tmp <= K;
}
signed main() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cin >> N >> K;
REP(i, N) cin >> a[i];
REP(i, N) cin >> f[i];
sort(a, a + N);
reverse(a, a + N);
sort(f, f + N);
int right = 0;
REP(i, N) chmax(right, a[i] * f[i]);
REP(i, N) sumV += a[i];
if (K >= sumV)
print(0);
else {
int left = 0;
while (right - left > 1) {
int mid = (left + right) / 2;
// left trueの場合
if (isOK(mid))
right = mid;
else
left = mid;
} // 不可能 可能
print(right);
}
} | replace | 109 | 110 | 109 | 110 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define maxn 200010
using namespace std;
long long n, k, a[maxn], f[maxn];
inline bool cmp(long long x, long long y) { return x > y; }
inline bool check(long long x) {
long long limit = 0;
for (register int i = 1; i <= n; ++i) {
if (a[i] * f[i] > x)
limit += a[i] - (x / f[i]);
}
return limit <= k;
}
int main() {
scanf("%lld%lld", &n, &k);
for (register int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
for (register int i = 1; i <= n; ++i)
scanf("%lld", &f[i]);
sort(a + 1, a + n + 1);
sort(f + 1, f + n + 1, cmp);
long long head = 0, tail = 1e12 + 10, ans;
while (head <= tail) {
long long mid = (head + tail) >> 1;
if (check(mid))
ans = mid, tail = mid - 1;
else
head = head + 1;
}
printf("%lld", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define maxn 200010
using namespace std;
long long n, k, a[maxn], f[maxn];
inline bool cmp(long long x, long long y) { return x > y; }
inline bool check(long long x) {
long long limit = 0;
for (register int i = 1; i <= n; ++i) {
if (a[i] * f[i] > x)
limit += a[i] - (x / f[i]);
}
return limit <= k;
}
int main() {
scanf("%lld%lld", &n, &k);
for (register int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
for (register int i = 1; i <= n; ++i)
scanf("%lld", &f[i]);
sort(a + 1, a + n + 1);
sort(f + 1, f + n + 1, cmp);
long long head = 0, tail = 1e12 + 10, ans;
while (head <= tail) {
long long mid = (head + tail) >> 1;
if (check(mid))
ans = mid, tail = mid - 1;
else
head = mid + 1;
}
printf("%lld", ans);
return 0;
} | replace | 35 | 36 | 35 | 36 | TLE | |
p02883 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
#define maxn 200005
using namespace std;
typedef long long loli;
loli A[maxn], F[maxn];
loli N, K;
bool cal(loli x) {
loli tmp, cnt = 0;
for (int i = 1; i <= N; i++) {
tmp = x / F[i];
if (A[N - i + 1] > tmp) {
cnt += A[N - i + 1] - tmp;
}
}
return cnt <= K;
}
int main() {
scanf("%lld%lld", &N, &K);
for (int i = 1; i <= N; i++) {
scanf("%lld", A + i);
}
for (int i = 1; i <= N; i++) {
scanf("%lld", F + i);
}
sort(A + 1, A + N + 1);
sort(F + 1, F + N + 1);
loli L = -1, R = 1e12;
while (R - L > 1) {
int M = (L + R) >> 1;
if (cal(M))
R = M;
else
L = M;
}
printf("%lld\n", R);
return 0;
}
| #pragma GCC optimize("Ofast")
#include <algorithm>
#include <stdio.h>
#define maxn 200005
using namespace std;
typedef long long loli;
loli A[maxn], F[maxn];
loli N, K;
bool cal(loli x) {
loli tmp, cnt = 0;
for (int i = 1; i <= N; i++) {
tmp = x / F[i];
if (A[N - i + 1] > tmp) {
cnt += A[N - i + 1] - tmp;
}
}
return cnt <= K;
}
int main() {
scanf("%lld%lld", &N, &K);
for (int i = 1; i <= N; i++) {
scanf("%lld", A + i);
}
for (int i = 1; i <= N; i++) {
scanf("%lld", F + i);
}
sort(A + 1, A + N + 1);
sort(F + 1, F + N + 1);
loli L = -1, R = 1e12;
while (R - L > 1) {
loli M = (L + R) >> 1;
if (cal(M))
R = M;
else
L = M;
}
printf("%lld\n", R);
return 0;
} | replace | 33 | 34 | 33 | 34 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1001001001;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(0);
vector<int> f(0);
for (int i = 0; i < n; i++) {
int input;
cin >> input;
a.push_back(input);
}
for (int i = 0; i < n; i++) {
int input;
cin >> input;
f.push_back(input);
}
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
bool ok = [&] {
ll s = 0;
for (int i = 0; i < n; i++) {
s += max(0ll, a.at(i) - (c / f.at(i)));
}
return s <= k;
}();
if (ok)
r = c;
else
l = c;
}
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1001001001;
int main() {
int n;
ll k;
cin >> n >> k;
vector<int> a(0);
vector<int> f(0);
for (int i = 0; i < n; i++) {
int input;
cin >> input;
a.push_back(input);
}
for (int i = 0; i < n; i++) {
int input;
cin >> input;
f.push_back(input);
}
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
bool ok = [&] {
ll s = 0;
for (int i = 0; i < n; i++) {
s += max(0ll, a.at(i) - (c / f.at(i)));
}
return s <= k;
}();
if (ok)
r = c;
else
l = c;
}
cout << r << endl;
} | replace | 7 | 8 | 7 | 9 | 0 | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;
using namespace std;
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
vector<ll> f(n);
REP(i, n) { cin >> a[i]; }
REP(i, n) { cin >> f[i]; }
sort(a.begin(), a.end());
sort(f.begin(), f.end(), greater<ll>());
ll ng = -1;
ll ok = 1000000002000;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
ll c = 0;
REP(i, n) {
if (a[i] * f[i] <= mid)
continue;
c += (a[i] * f[i] - mid + f[i] - 1) / f[i];
}
if (c <= k) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;
using namespace std;
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
vector<ll> f(n);
REP(i, n) { cin >> a[i]; }
REP(i, n) { cin >> f[i]; }
sort(a.begin(), a.end());
sort(f.begin(), f.end(), greater<ll>());
ll ng = -1;
ll ok = 1000000002000;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
ll c = 0;
REP(i, n) {
if (a[i] * f[i] <= mid)
continue;
c += (a[i] * f[i] - mid + f[i] - 1) / f[i];
}
if (c <= k) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
int n, a[maxn], f[maxn];
ll k, le, ri;
bool check(ll x) {
ll cnt = k;
for (int i = 0; i < n; ++i) {
if (1LL * a[i] * f[i] <= x)
continue;
ll need = 1LL * a[i] - x / f[i];
if (cnt >= need)
cnt -= need;
else
return false;
}
return true;
}
int main() {
scanf("%d%lld", &n, &k);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
for (int i = 0; i < n; ++i)
scanf("%d", &f[i]);
sort(a, a + n);
sort(f, f + n, greater<int>());
le = -1;
for (int i = 0; i < n; ++i) {
ri += 1LL * a[i] * f[i];
}
while (le + 1 < ri) {
ll mid = (le + ri) >> 1;
if (check(mid))
ri = mid;
else
le = mid;
}
printf("%lld\n", ri);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 50;
int n, a[maxn], f[maxn];
ll k, le, ri;
bool check(ll x) {
ll cnt = k;
for (int i = 0; i < n; ++i) {
if (1LL * a[i] * f[i] <= x)
continue;
ll need = 1LL * a[i] - x / f[i];
if (cnt >= need)
cnt -= need;
else
return false;
}
return true;
}
int main() {
scanf("%d%lld", &n, &k);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
for (int i = 0; i < n; ++i)
scanf("%d", &f[i]);
sort(a, a + n);
sort(f, f + n, greater<int>());
le = -1;
for (int i = 0; i < n; ++i) {
ri += 1LL * a[i] * f[i];
}
while (le + 1 < ri) {
ll mid = (le + ri) >> 1;
if (check(mid))
ri = mid;
else
le = mid;
}
printf("%lld\n", ri);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
ll a[maxn], f[maxn];
int n;
ll k;
bool check(ll x) {
ll sum = k;
for (int i = 0; i < n; i++) {
ll now = a[i] * f[i];
if (now > x) {
ll num = (now - x) / f[i];
if ((now - x) % f[i])
num++;
sum -= num;
}
}
if (sum < 0)
return false;
else
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> f[i];
sort(a, a + n);
sort(f, f + n, greater<ll>());
ll l = 0, r = 1e15;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
if (check(l))
cout << l << '\n';
else
cout << r << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
ll a[maxn], f[maxn];
int n;
ll k;
bool check(ll x) {
ll sum = k;
for (int i = 0; i < n; i++) {
ll now = a[i] * f[i];
if (now > x) {
ll num = (now - x) / f[i];
if ((now - x) % f[i])
num++;
sum -= num;
}
}
if (sum < 0)
return false;
else
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> f[i];
sort(a, a + n);
sort(f, f + n, greater<ll>());
ll l = 0, r = 1e15;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
if (check(l))
cout << l << '\n';
else
cout << r << '\n';
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02883 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long LL;
#define exp double(1e-6)
#define PI acos(-1)
const int MAXN = int(1e5 + 5);
int n;
LL k, K;
int a[MAXN], f[MAXN];
int a2[MAXN], f2[MAXN];
bool cmp(int a, int b) { return a > b; }
void Debug() {
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
puts("");
for (int i = 1; i <= n; i++)
printf("%d ", f[i]);
puts("");
}
bool Check(LL x) {
for (int i = 1; i <= n; i++) {
if ((LL)a[i] * f[i] <= x)
continue;
else
k -= ((LL)a[i] * f[i] - x + f[i] - 1) / f[i];
}
return k >= 0;
}
LL BS() {
LL l = 0, r = (LL)a[n] * f[1];
while (l + 1 < r) {
k = K;
LL mid = (l + r) / 2;
if (Check(mid))
r = mid;
else
l = mid;
}
k = K;
return Check(l) ? l : r;
}
int main() {
scanf("%d%lld", &n, &k);
K = k;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &f[i]);
sort(a + 1, a + n + 1);
sort(f + 1, f + n + 1, cmp);
// Debug();
printf("%lld", BS());
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long LL;
#define exp double(1e-6)
#define PI acos(-1)
const int MAXN = int(2e5 + 5);
int n;
LL k, K;
int a[MAXN], f[MAXN];
int a2[MAXN], f2[MAXN];
bool cmp(int a, int b) { return a > b; }
void Debug() {
for (int i = 1; i <= n; i++)
printf("%d ", a[i]);
puts("");
for (int i = 1; i <= n; i++)
printf("%d ", f[i]);
puts("");
}
bool Check(LL x) {
for (int i = 1; i <= n; i++) {
if ((LL)a[i] * f[i] <= x)
continue;
else
k -= ((LL)a[i] * f[i] - x + f[i] - 1) / f[i];
}
return k >= 0;
}
LL BS() {
LL l = 0, r = (LL)a[n] * f[1];
while (l + 1 < r) {
k = K;
LL mid = (l + r) / 2;
if (Check(mid))
r = mid;
else
l = mid;
}
k = K;
return Check(l) ? l : r;
}
int main() {
scanf("%d%lld", &n, &k);
K = k;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
scanf("%d", &f[i]);
sort(a + 1, a + n + 1);
sort(f + 1, f + n + 1, cmp);
// Debug();
printf("%lld", BS());
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<ll> as(N);
vector<ll> fs(N);
rep(i, N) cin >> as[i];
rep(i, N) cin >> fs[i];
sort(as.begin(), as.end());
sort(fs.begin(), fs.end());
reverse(fs.begin(), fs.end());
ll l = -1;
ll r = 1001001001001;
while (l + 1 < r) {
ll m = (l + r) / 2;
ll k = 0;
rep(i, N) { k += max(0, as[i] - m / fs[i]); }
if (k > K)
l = m;
else
r = m;
}
cout << r << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
vector<ll> as(N);
vector<ll> fs(N);
rep(i, N) cin >> as[i];
rep(i, N) cin >> fs[i];
sort(as.begin(), as.end());
sort(fs.begin(), fs.end());
reverse(fs.begin(), fs.end());
ll l = -1;
ll r = 1001001001001;
while (l + 1 < r) {
ll m = (l + r) / 2;
ll k = 0;
rep(i, N) { k += max(0, as[i] - m / fs[i]); }
if (k > K)
l = m;
else
r = m;
}
cout << r << endl;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02883 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
const int maxn = 1e6 + 5;
ll a[maxn], f[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> f[i];
sort(a, a + n);
sort(f, f + n, greater<ll>());
ll l = 0, r = 1e12;
while (l < r) {
ll x = (l + r) >> 1;
ll need = 0;
for (int i = 0; i < n; i++) {
need += max(0ll, a[i] - x / f[i]);
}
if (need <= k) {
r = x;
} else {
l = x + 1;
}
}
cout << r << endl;
}
| #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
const int maxn = 1e6 + 5;
ll a[maxn], f[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> f[i];
sort(a, a + n);
sort(f, f + n, greater<ll>());
ll l = 0, r = 1e12;
while (l < r) {
ll x = (l + r) >> 1;
ll need = 0;
for (int i = 0; i < n; i++) {
need += max(0ll, a[i] - x / f[i]);
}
if (need <= k) {
r = x;
} else {
l = x + 1;
}
}
cout << r << endl;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p02883 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
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 GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
signed main() {
int n, k;
cin >> n >> k;
vi a(n);
vi f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
vsort(a);
rvisort(f);
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
bool ok = [&]() {
ll s = 0;
rep(i, n) { s += max(0ll, a[i] - c / f[i]); }
return s <= k;
}();
if (ok)
r = c;
else
l = c;
}
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
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 GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
signed main() {
ll n, k;
cin >> n >> k;
vi a(n);
vi f(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> f[i];
vsort(a);
rvisort(f);
ll l = -1, r = 1e12;
while (l + 1 < r) {
ll c = (l + r) / 2;
bool ok = [&]() {
ll s = 0;
rep(i, n) { s += max(0ll, a[i] - c / f[i]); }
return s <= k;
}();
if (ok)
r = c;
else
l = c;
}
cout << r << endl;
}
| replace | 54 | 55 | 54 | 55 | 0 | |
p02883 | C++ | Runtime Error | // Gaurav Aggarwal
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for (__typeof(a) i = a; i <= b; i++)
#define inp_arr(a, n) \
for (__typeof(n) i = 0; i < n; ++i) { \
cin >> a[i]; \
}
#define debug_arr(a, n) \
{ \
{ \
for (__typeof(n) i = 0; i < n; ++i) { \
cout << a[i] << " "; \
} \
cout << "\n"; \
} \
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n;
cin >> n;
ll k;
cin >> k;
ll a[n], b[n];
inp_arr(a, n);
inp_arr(b, n);
sort(a, a + n);
sort(b, b + n);
vector<ll> v;
for (int i = 0; i < n; ++i) {
v.pb(a[i] * b[n - i - 1]);
}
ll start = 0, end = 1e18;
ll ans = 0;
while (start <= end) {
ll mid = (start + end) / 2;
ll f = 0;
for (int i = 0; i < n; ++i) {
if (v[i] > mid) {
ll diff = v[i] - mid;
ll need = ceil((diff * 1.0) / b[n - i - 1]);
f += need;
}
}
// cout<<mid<<" "<<f<<"\n";
if (f <= k) {
ans = mid;
end = mid - 1;
} else
start = mid + 1;
}
cout << ans << "\n";
return 0;
} | // Gaurav Aggarwal
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for (__typeof(a) i = a; i <= b; i++)
#define inp_arr(a, n) \
for (__typeof(n) i = 0; i < n; ++i) { \
cin >> a[i]; \
}
#define debug_arr(a, n) \
{ \
{ \
for (__typeof(n) i = 0; i < n; ++i) { \
cout << a[i] << " "; \
} \
cout << "\n"; \
} \
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// #endif
int n;
cin >> n;
ll k;
cin >> k;
ll a[n], b[n];
inp_arr(a, n);
inp_arr(b, n);
sort(a, a + n);
sort(b, b + n);
vector<ll> v;
for (int i = 0; i < n; ++i) {
v.pb(a[i] * b[n - i - 1]);
}
ll start = 0, end = 1e18;
ll ans = 0;
while (start <= end) {
ll mid = (start + end) / 2;
ll f = 0;
for (int i = 0; i < n; ++i) {
if (v[i] > mid) {
ll diff = v[i] - mid;
ll need = ceil((diff * 1.0) / b[n - i - 1]);
f += need;
}
}
// cout<<mid<<" "<<f<<"\n";
if (f <= k) {
ans = mid;
end = mid - 1;
} else
start = mid + 1;
}
cout << ans << "\n";
return 0;
} | replace | 50 | 54 | 50 | 54 | 0 | |
p02883 | C++ | Time Limit Exceeded | // https://atcoder.jp/contests/past-sample/tasks/abc129_d
// config
const int __SETW__ = 6;
// IO
#include <iomanip> // setw
#include <iostream> // cin, cout
// MATH & ALGROTHM
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// CONTAINER
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// FUNCTION
#include <functional>
// META
#include <type_traits>
///////
using std::cin;
using std::cout;
using std::endl;
using INT = unsigned long long int;
const INT INF = INT(1) << 60;
#define FOR(i, N) for (INT i = 0; i < N; i++)
#define FORR(i, N) for (INT i = (N - 1); i >= 0; i--)
#define RANGE(v) begin(v), end(v)
using VEC = std::vector<INT>;
using VECVEC = std::vector<VEC>;
using VECVECVEC = std::vector<VEC>;
template <class T> T safe_get(const std::vector<T> &v, INT idx, T def = -1) {
if (idx < 0 || v.size() <= idx) {
return def;
} else {
return v[idx];
}
}
template <class T>
T safe_get(const std::vector<std::vector<T>> &vv, INT idx1, INT idx2,
T def = -1) {
if (idx1 < 0 || vv.size() <= idx1) {
return def;
} else {
return safe_get(vv[idx1], idx2, def);
}
}
template <class T, class F> inline bool ANY(T sequence, F func) {
for (auto &&t : sequence) {
if (func(t)) {
return true;
}
}
return false;
}
template <class T, class F> inline bool ALL(T sequence, F func) {
for (auto &&t : sequence) {
if (!func(t)) {
return false;
}
}
return true;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::priority_queue<T> &rhs) {
std::queue<T> copy = rhs;
while (!copy.empty()) {
lhs << std::setw(__SETW__) << copy.front() << " ";
copy.pop();
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::queue<T> &rhs) {
std::queue<T> copy = rhs;
while (!copy.empty()) {
lhs << std::setw(__SETW__) << copy.front() << " ";
copy.pop();
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::stack<T> &rhs) {
std::stack<T> copy = rhs;
while (!copy.empty()) {
lhs << std::setw(__SETW__) << copy.top() << " ";
copy.pop();
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs,
const std::vector<std::vector<T>> &rhs) {
for (auto &&v : rhs) {
lhs << v << endl;
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::vector<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::list<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &lhs, const std::map<T1, T2> &rhs) {
for (auto &&m : rhs) {
lhs << std::setw(__SETW__) << m.first << ":" << std::setw(__SETW__)
<< m.second << endl;
}
return lhs;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &lhs, const std::multimap<T1, T2> &rhs) {
for (auto &&m : rhs) {
lhs << std::setw(__SETW__) << m.first << ":" << std::setw(__SETW__)
<< m.second << endl;
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::set<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::multiset<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::complex<T> &rhs) {
std::streamsize ss = lhs.precision();
lhs << "(" << std::setw(5) << std::setprecision(4) << rhs.real() << ","
<< std::setw(5) << std::setprecision(4) << rhs.imag() << ") ";
lhs.precision(ss);
return lhs;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &lhs, const std::pair<T1, T2> &rhs) {
lhs << "(" << rhs.first << "," << rhs.second << ")";
return lhs;
}
template <class T> T chmax(T &lhs, const T &rhs) {
lhs = std::max(lhs, rhs);
return lhs;
}
template <class T> T chmin(T &lhs, const T &rhs) {
lhs = std::min(lhs, rhs);
return lhs;
}
using namespace std;
int main() {
INT N, K;
cin >> N >> K;
VEC A(N);
VEC F(N);
FOR(i, N) cin >> A[i];
FOR(i, N) cin >> F[i];
std::sort(RANGE(A));
std::sort(RANGE(F), [](INT x, INT y) { return x > y; });
std::priority_queue<pair<INT, INT>, vector<pair<INT, INT>>,
std::less<pair<INT, INT>>>
que;
FOR(i, N) { que.emplace(A[i] * F[i], i); }
FOR(i, K) {
INT cost, idx;
tie(cost, idx) = que.top();
que.pop();
if (cost == 0)
break;
A[idx]--;
que.emplace(A[idx] * F[idx], idx);
}
INT ans = 0;
FOR(i, N) { chmax(ans, A[i] * F[i]); }
cout << ans << endl;
return 0;
}
| // https://atcoder.jp/contests/past-sample/tasks/abc129_d
// config
const int __SETW__ = 6;
// IO
#include <iomanip> // setw
#include <iostream> // cin, cout
// MATH & ALGROTHM
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// CONTAINER
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// FUNCTION
#include <functional>
// META
#include <type_traits>
///////
using std::cin;
using std::cout;
using std::endl;
using INT = unsigned long long int;
const INT INF = INT(1) << 60;
#define FOR(i, N) for (INT i = 0; i < N; i++)
#define FORR(i, N) for (INT i = (N - 1); i >= 0; i--)
#define RANGE(v) begin(v), end(v)
using VEC = std::vector<INT>;
using VECVEC = std::vector<VEC>;
using VECVECVEC = std::vector<VEC>;
template <class T> T safe_get(const std::vector<T> &v, INT idx, T def = -1) {
if (idx < 0 || v.size() <= idx) {
return def;
} else {
return v[idx];
}
}
template <class T>
T safe_get(const std::vector<std::vector<T>> &vv, INT idx1, INT idx2,
T def = -1) {
if (idx1 < 0 || vv.size() <= idx1) {
return def;
} else {
return safe_get(vv[idx1], idx2, def);
}
}
template <class T, class F> inline bool ANY(T sequence, F func) {
for (auto &&t : sequence) {
if (func(t)) {
return true;
}
}
return false;
}
template <class T, class F> inline bool ALL(T sequence, F func) {
for (auto &&t : sequence) {
if (!func(t)) {
return false;
}
}
return true;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::priority_queue<T> &rhs) {
std::queue<T> copy = rhs;
while (!copy.empty()) {
lhs << std::setw(__SETW__) << copy.front() << " ";
copy.pop();
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::queue<T> &rhs) {
std::queue<T> copy = rhs;
while (!copy.empty()) {
lhs << std::setw(__SETW__) << copy.front() << " ";
copy.pop();
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::stack<T> &rhs) {
std::stack<T> copy = rhs;
while (!copy.empty()) {
lhs << std::setw(__SETW__) << copy.top() << " ";
copy.pop();
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs,
const std::vector<std::vector<T>> &rhs) {
for (auto &&v : rhs) {
lhs << v << endl;
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::vector<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::list<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &lhs, const std::map<T1, T2> &rhs) {
for (auto &&m : rhs) {
lhs << std::setw(__SETW__) << m.first << ":" << std::setw(__SETW__)
<< m.second << endl;
}
return lhs;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &lhs, const std::multimap<T1, T2> &rhs) {
for (auto &&m : rhs) {
lhs << std::setw(__SETW__) << m.first << ":" << std::setw(__SETW__)
<< m.second << endl;
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::set<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::multiset<T> &rhs) {
for (auto &&t : rhs) {
lhs << std::setw(__SETW__) << t << " ";
}
return lhs;
}
template <class T>
std::ostream &operator<<(std::ostream &lhs, const std::complex<T> &rhs) {
std::streamsize ss = lhs.precision();
lhs << "(" << std::setw(5) << std::setprecision(4) << rhs.real() << ","
<< std::setw(5) << std::setprecision(4) << rhs.imag() << ") ";
lhs.precision(ss);
return lhs;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &lhs, const std::pair<T1, T2> &rhs) {
lhs << "(" << rhs.first << "," << rhs.second << ")";
return lhs;
}
template <class T> T chmax(T &lhs, const T &rhs) {
lhs = std::max(lhs, rhs);
return lhs;
}
template <class T> T chmin(T &lhs, const T &rhs) {
lhs = std::min(lhs, rhs);
return lhs;
}
using namespace std;
int main() {
INT N, K;
cin >> N >> K;
VEC A(N);
VEC F(N);
FOR(i, N) cin >> A[i];
FOR(i, N) cin >> F[i];
std::sort(RANGE(A));
std::sort(RANGE(F), [](INT x, INT y) { return x > y; });
INT mn = 0, mx = INF;
do {
INT mid = (mx + mn) / 2;
INT s = 0;
FOR(i, N) {
if (A[i] * F[i] > mid) {
s += (A[i] - mid / F[i]);
}
}
if (K >= s) {
mx = mid;
} else {
mn = mid;
}
} while (mn != mx && mn + 1 != mx);
INT s = 0;
FOR(i, N) {
if (A[i] * F[i] > mn) {
s += (A[i] - mn / F[i]);
}
}
if (s <= K) {
cout << mn << endl;
} else {
cout << mx << endl;
}
return 0;
}
| replace | 201 | 221 | 201 | 229 | TLE | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
int main() {
LL N, K;
cin >> N >> K;
vector<LL> a(N), f(N);
for (int i = 0; i < N; i++)
cin >> a[i];
for (int i = 0; i < N; i++)
cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
vector<P> pp(N);
for (int i = 0; i < N; i++) {
pp[i] = P(a[i] * f[i], f[i]);
}
LL cnt2 = 0;
for (int i = 0; i < N; i++)
cnt2 += a[i];
sort(pp.begin(), pp.end());
vector<LL> p2(N);
for (int i = 0; i < N; i++)
p2[i] = pp[i].first;
LL l = 0, r = 1e12;
while (l + 1 < r) {
int mm = (l + r) / 2;
auto itr = lower_bound(p2.begin(), p2.end(), mm);
int id = itr - p2.begin();
if (itr == p2.end()) {
r = mm;
} else {
LL cnt = 0;
for (int i = id; i < N; i++) {
cnt += (p2[i] - mm + pp[i].second - 1) / (pp[i].second);
}
if (cnt <= K)
r = mm;
else
l = mm;
}
}
if (cnt2 <= K)
cout << 0 << endl;
else
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
int main() {
LL N, K;
cin >> N >> K;
vector<LL> a(N), f(N);
for (int i = 0; i < N; i++)
cin >> a[i];
for (int i = 0; i < N; i++)
cin >> f[i];
sort(a.begin(), a.end());
sort(f.rbegin(), f.rend());
vector<P> pp(N);
for (int i = 0; i < N; i++) {
pp[i] = P(a[i] * f[i], f[i]);
}
LL cnt2 = 0;
for (int i = 0; i < N; i++)
cnt2 += a[i];
sort(pp.begin(), pp.end());
vector<LL> p2(N);
for (int i = 0; i < N; i++)
p2[i] = pp[i].first;
LL l = 0, r = 1e12;
while (l + 1 < r) {
LL mm = (l + r) / 2;
auto itr = lower_bound(p2.begin(), p2.end(), mm);
int id = itr - p2.begin();
if (itr == p2.end()) {
r = mm;
} else {
LL cnt = 0;
for (int i = id; i < N; i++) {
cnt += (p2[i] - mm + pp[i].second - 1) / (pp[i].second);
}
if (cnt <= K)
r = mm;
else
l = mm;
}
}
if (cnt2 <= K)
cout << 0 << endl;
else
cout << r << endl;
} | replace | 28 | 29 | 28 | 29 | TLE | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long n, a[200002], v[200002];
long long k;
bool ok(long long x) {
long long sum = 0;
for (int i = 1; i <= n; i++) {
long long t = x / v[i];
sum += max(0ll, a[i] - t);
}
if (sum <= k)
return 1;
else
return 0;
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> v[i];
sort(a + 1, a + n + 1);
sort(v + 1, v + n + 1);
reverse(v + 1, v + n + 1);
long long st = 0, dr = 0, ans;
for (int i = 1; i <= n; i++)
dr = max(dr, a[i] * v[i]);
while (st <= dr) {
int mij = (st + dr) / 2;
if (ok(mij)) {
ans = mij;
dr = mij - 1;
} else
st = mij + 1;
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long n, a[200002], v[200002];
long long k;
bool ok(long long x) {
long long sum = 0;
for (int i = 1; i <= n; i++) {
long long t = x / v[i];
sum += max(0ll, a[i] - t);
}
if (sum <= k)
return 1;
else
return 0;
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> v[i];
sort(a + 1, a + n + 1);
sort(v + 1, v + n + 1);
reverse(v + 1, v + n + 1);
long long st = 0, dr = 0, ans;
for (int i = 1; i <= n; i++)
dr = max(dr, a[i] * v[i]);
while (st <= dr) {
long long mij = (st + dr) / 2;
if (ok(mij)) {
ans = mij;
dr = mij - 1;
} else
st = mij + 1;
}
cout << ans;
return 0;
}
| replace | 32 | 33 | 32 | 33 | TLE | |
p02883 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define stp fixed << setprecision(20)
#define endl '\n'
ll a[200009], f[200009];
ll h[200009];
ll n;
void fill(ll x) {
for (ll i = 0; i < n; i++) {
h[i] = x / f[i];
}
}
ll check() {
ll res = 0;
for (ll i = 0; i < n; i++) {
res += max((ll)0, a[i] - h[i]);
}
return res;
}
void solve() {
ll k;
cin >> n >> k;
;
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
for (ll i = 0; i < n; i++) {
cin >> f[i];
}
sort(a, a + n);
sort(f, f + n, greater<ll>());
ll l = 0, u = 1e18, mid;
ll ans = inf;
while (l <= u) {
mid = (l + u / 2);
fill(mid);
ll z = check();
if (z > k) {
l = mid + 1;
} else {
ans = mid;
u = mid - 1;
}
}
cout << ans;
}
int main() {
FAST
#ifdef ayk_16
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
time_taken_start ll t = 1;
// cin>>t;
for (ll i = 0; i < t; i++) {
// cout<<"Case #"<<i+1<<": ";
solve();
}
time_taken_end
}
| #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define stp fixed << setprecision(20)
#define endl '\n'
ll a[200009], f[200009];
ll h[200009];
ll n;
void fill(ll x) {
for (ll i = 0; i < n; i++) {
h[i] = x / f[i];
}
}
ll check() {
ll res = 0;
for (ll i = 0; i < n; i++) {
res += max((ll)0, a[i] - h[i]);
}
return res;
}
void solve() {
ll k;
cin >> n >> k;
;
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
for (ll i = 0; i < n; i++) {
cin >> f[i];
}
sort(a, a + n);
sort(f, f + n, greater<ll>());
ll l = 0, u = 1e18, mid;
ll ans = inf;
while (l <= u) {
mid = (l + u) / 2;
fill(mid);
ll z = check();
if (z > k) {
l = mid + 1;
} else {
ans = mid;
u = mid - 1;
}
}
cout << ans;
}
int main() {
FAST
#ifdef ayk_16
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
time_taken_start ll t = 1;
// cin>>t;
for (ll i = 0; i < t; i++) {
// cout<<"Case #"<<i+1<<": ";
solve();
}
time_taken_end
}
| replace | 63 | 64 | 63 | 64 | TLE | |
p02884 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> edg(n), eid(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
edg[u].push_back(v);
eid[u].push_back(i);
}
double ans = 1e18;
vector<double> dp(n);
for (int i = -1; i < m; i++) {
for (int j = 0; j < n; j++)
dp[j] = 0.;
for (int j = n - 2; j >= 0; j--) {
int c = edg[j].size();
double ma = 0.;
for (int t = 0; t < c; t++) {
dp[j] += dp[edg[j][t]];
if (edg[j][t] != n - 1) {
ma = max(ma, dp[edg[j][t]]);
}
}
if (j == i && c > 1) {
dp[j] -= ma;
dp[j] /= (c - 1);
} else {
dp[j] /= c;
}
dp[j]++;
}
ans = min(ans, dp[0]);
}
printf("%.15f\n", ans);
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> edg(n), eid(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
edg[u].push_back(v);
eid[u].push_back(i);
}
double ans = 1e18;
vector<double> dp(n);
for (int i = -1; i < n; i++) {
for (int j = 0; j < n; j++)
dp[j] = 0.;
for (int j = n - 2; j >= 0; j--) {
int c = edg[j].size();
double ma = 0.;
for (int t = 0; t < c; t++) {
dp[j] += dp[edg[j][t]];
if (edg[j][t] != n - 1) {
ma = max(ma, dp[edg[j][t]]);
}
}
if (j == i && c > 1) {
dp[j] -= ma;
dp[j] /= (c - 1);
} else {
dp[j] /= c;
}
dp[j]++;
}
ans = min(ans, dp[0]);
}
printf("%.15f\n", ans);
return 0;
}
| replace | 30 | 31 | 30 | 31 | TLE | |
p02884 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(), V.end()
#define ll long long
#define MOD 1000000007
vector<int> G[610];
pair<int, int> E[100000];
double cost[610], les[610];
int main() {
int N, M, s, t, sz;
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> s >> t;
G[s].push_back(t);
E[i] = {s, t};
}
for (int i = N; i > 0; i--) {
cost[i] = 1.0;
//(接続先の期待値+1)*(そこに進む確率)
for (int j = i - 1; j > 0; j--) {
sz = G[j].size();
for (int k : G[j]) {
cost[j] += cost[k] / sz;
}
}
les[i] = cost[1];
for (int j = 1; j <= N; j++)
cost[j] = 0.0;
}
for (int i = N; i > 0; i--) {
sz = G[i].size();
for (int k : G[i]) {
cost[i] += (cost[k] + 1) / sz;
}
}
double ans = 0, tp;
for (int i = 0; i < M; i++) {
tie(s, t) = E[i];
sz = G[s].size();
if (sz == 1)
continue;
tp = cost[s] - (cost[t] + 1.0) / sz;
tp *= (double)sz / (sz - 1);
tp = (cost[s] - tp) * les[s];
ans = max(tp, ans);
}
printf("%.10f", cost[1] - ans);
} | #include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(), V.end()
#define ll long long
#define MOD 1000000007
vector<int> G[610];
pair<int, int> E[200000];
double cost[610], les[610];
int main() {
int N, M, s, t, sz;
cin >> N >> M;
for (int i = 0; i < M; i++) {
cin >> s >> t;
G[s].push_back(t);
E[i] = {s, t};
}
for (int i = N; i > 0; i--) {
cost[i] = 1.0;
//(接続先の期待値+1)*(そこに進む確率)
for (int j = i - 1; j > 0; j--) {
sz = G[j].size();
for (int k : G[j]) {
cost[j] += cost[k] / sz;
}
}
les[i] = cost[1];
for (int j = 1; j <= N; j++)
cost[j] = 0.0;
}
for (int i = N; i > 0; i--) {
sz = G[i].size();
for (int k : G[i]) {
cost[i] += (cost[k] + 1) / sz;
}
}
double ans = 0, tp;
for (int i = 0; i < M; i++) {
tie(s, t) = E[i];
sz = G[s].size();
if (sz == 1)
continue;
tp = cost[s] - (cost[t] + 1.0) / sz;
tp *= (double)sz / (sz - 1);
tp = (cost[s] - tp) * les[s];
ans = max(tp, ans);
}
printf("%.10f", cost[1] - ans);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02884 | C++ | Runtime Error | #include <stdio.h>
#include <vector>
using namespace std;
vector<int> e[611];
double dis1[611], dis0[611];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int t1, t2;
scanf("%d%d", &t1, &t2);
e[t1].push_back(t2);
}
for (int i = 0; i < m; ++i)
dis0[i] = dis1[i] = 0;
for (int i = n - 1; i > 0; --i) {
for (int j = 0; j < e[i].size(); ++j) {
dis0[i] += dis0[e[i][j]];
}
if (!e[i].size())
continue;
dis0[i] /= (1.0 * e[i].size());
dis0[i] += 1.0;
dis1[i] = dis0[i];
}
double ans = dis0[1];
for (int i = 1; i < n; ++i) {
double tmp_max = 0;
if (e[i].size() == 1)
continue;
dis1[i] = 0;
for (int j = 0; j < e[i].size(); ++j) {
if (dis1[e[i][j]] > tmp_max)
tmp_max = dis1[e[i][j]];
dis1[i] += dis1[e[i][j]];
}
dis1[i] -= tmp_max;
dis1[i] /= (1.0 * e[i].size() - 1.0);
dis1[i] += 1.0;
for (int j = i - 1; j > 0; --j) {
dis1[j] = 0;
for (int k = 0; k < e[j].size(); ++k)
dis1[j] += dis1[e[j][k]];
if (!e[j].size())
continue;
dis1[j] /= (1.0 * e[j].size());
dis1[j] += 1.0;
}
if (dis1[1] < ans)
ans = dis1[1];
}
printf("%.8lf", ans);
}
| #include <stdio.h>
#include <vector>
using namespace std;
vector<int> e[611];
double dis1[611], dis0[611];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int t1, t2;
scanf("%d%d", &t1, &t2);
e[t1].push_back(t2);
}
for (int i = 0; i <= n; ++i)
dis0[i] = dis1[i] = 0;
for (int i = n - 1; i > 0; --i) {
for (int j = 0; j < e[i].size(); ++j) {
dis0[i] += dis0[e[i][j]];
}
if (!e[i].size())
continue;
dis0[i] /= (1.0 * e[i].size());
dis0[i] += 1.0;
dis1[i] = dis0[i];
}
double ans = dis0[1];
for (int i = 1; i < n; ++i) {
double tmp_max = 0;
if (e[i].size() == 1)
continue;
dis1[i] = 0;
for (int j = 0; j < e[i].size(); ++j) {
if (dis1[e[i][j]] > tmp_max)
tmp_max = dis1[e[i][j]];
dis1[i] += dis1[e[i][j]];
}
dis1[i] -= tmp_max;
dis1[i] /= (1.0 * e[i].size() - 1.0);
dis1[i] += 1.0;
for (int j = i - 1; j > 0; --j) {
dis1[j] = 0;
for (int k = 0; k < e[j].size(); ++k)
dis1[j] += dis1[e[j][k]];
if (!e[j].size())
continue;
dis1[j] /= (1.0 * e[j].size());
dis1[j] += 1.0;
}
if (dis1[1] < ans)
ans = dis1[1];
}
printf("%.8lf", ans);
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02884 | C++ | Time Limit Exceeded | #include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#define llint long long
#define inf 1e9
using namespace std;
llint n, m;
vector<llint> G[605], revG[605];
double dp[605], dp2[605];
void dfs(int v, int f) {
if (f) {
double sum = 0;
for (int j = 0; j < G[v].size(); j++) {
sum += dp2[G[v][j]];
}
dp2[v] = sum / (int)G[v].size() + 1;
}
for (int i = 0; i < revG[v].size(); i++)
dfs(revG[v][i], 1);
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
llint u, v;
for (int i = 0; i < m; i++) {
cin >> u >> v;
G[u].push_back(v);
revG[v].push_back(u);
}
dp[n] = 0;
for (int i = n - 1; i >= 1; i--) {
double sum = 0;
for (int j = 0; j < G[i].size(); j++) {
sum += dp[G[i][j]];
}
dp[i] = sum / (int)G[i].size() + 1;
}
// for(int i = 1; i <= n; i++) cout << dp[i] << " "; cout << endl;
double ans = dp[1];
for (int i = 1; i <= n; i++) {
int N = G[i].size();
if (N <= 1)
continue;
double mx = 0;
for (int j = 0; j < G[i].size(); j++) {
mx = max(mx, dp[G[i][j]]);
}
for (int j = 1; j <= n; j++)
dp2[j] = dp[j];
dp2[i] = ((dp[i] - 1) * N - mx) / (N - 1) + 1;
dfs(i, 0);
ans = min(ans, dp2[1]);
// for(int i = 1; i <= n; i++) cout << dp2[i] << " "; cout << endl;
}
printf("%.11f\n", ans);
return 0;
} | #include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#define llint long long
#define inf 1e9
using namespace std;
llint n, m;
vector<llint> G[605], revG[605];
double dp[605], dp2[605];
void dfs(int v, int f) {
if (f) {
double sum = 0;
for (int j = 0; j < G[v].size(); j++) {
sum += dp2[G[v][j]];
}
dp2[v] = sum / (int)G[v].size() + 1;
}
for (int i = 0; i < revG[v].size(); i++)
dfs(revG[v][i], 1);
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
llint u, v;
for (int i = 0; i < m; i++) {
cin >> u >> v;
G[u].push_back(v);
revG[v].push_back(u);
}
dp[n] = 0;
for (int i = n - 1; i >= 1; i--) {
double sum = 0;
for (int j = 0; j < G[i].size(); j++) {
sum += dp[G[i][j]];
}
dp[i] = sum / (int)G[i].size() + 1;
}
// for(int i = 1; i <= n; i++) cout << dp[i] << " "; cout << endl;
double ans = dp[1];
for (int i = 1; i <= n; i++) {
int N = G[i].size();
if (N <= 1)
continue;
double mx = 0;
for (int j = 0; j < G[i].size(); j++) {
mx = max(mx, dp[G[i][j]]);
}
for (int j = 1; j <= n; j++)
dp2[j] = dp[j];
dp2[i] = ((dp[i] - 1) * N - mx) / (N - 1) + 1;
for (int v = i - 1; v >= 1; v--) {
double sum = 0;
for (int j = 0; j < G[v].size(); j++) {
sum += dp2[G[v][j]];
}
dp2[v] = sum / (int)G[v].size() + 1;
}
ans = min(ans, dp2[1]);
// for(int i = 1; i <= n; i++) cout << dp2[i] << " "; cout << endl;
}
printf("%.11f\n", ans);
return 0;
} | replace | 63 | 64 | 63 | 71 | TLE | |
p02884 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};
int n;
V g[610];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m, s[610], t[610];
cin >> n >> m;
REP(i, m) {
cin >> s[i] >> t[i];
g[s[i]].push_back(t[i]);
}
double dp[610];
dp[n] = 0;
for (int i = n - 1; i >= 1; i--) {
dp[i] = 0;
for (int nex : g[i]) {
dp[i] += (1 + dp[nex]) / g[i].size();
}
}
double res = 1e9;
for (int i = 1; i <= n; i++) {
int mai = -1;
double ma = 0;
if (g[i].size() > 1)
for (int nex : g[i]) {
if (ma < dp[nex]) {
ma = dp[nex];
mai = nex;
}
}
double dp2[610];
dp2[n] = 0;
for (int j = n - 1; j >= 1; j--) {
dp2[j] = 0;
for (int nex : g[j]) {
if (j == i && nex == mai)
continue;
if (j == i && g[j].size() > 1) {
dp2[j] += (1 + dp2[nex]) / (g[j].size() - 1);
} else {
dp2[j] += (1 + dp2[nex]) / (g[j].size());
}
}
}
res = min(res, dp2[1]);
}
cout << setprecision(30) << res << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};
int n;
V g[610];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m, s[180010], t[180010];
cin >> n >> m;
REP(i, m) {
cin >> s[i] >> t[i];
g[s[i]].push_back(t[i]);
}
double dp[610];
dp[n] = 0;
for (int i = n - 1; i >= 1; i--) {
dp[i] = 0;
for (int nex : g[i]) {
dp[i] += (1 + dp[nex]) / g[i].size();
}
}
double res = 1e9;
for (int i = 1; i <= n; i++) {
int mai = -1;
double ma = 0;
if (g[i].size() > 1)
for (int nex : g[i]) {
if (ma < dp[nex]) {
ma = dp[nex];
mai = nex;
}
}
double dp2[610];
dp2[n] = 0;
for (int j = n - 1; j >= 1; j--) {
dp2[j] = 0;
for (int nex : g[j]) {
if (j == i && nex == mai)
continue;
if (j == i && g[j].size() > 1) {
dp2[j] += (1 + dp2[nex]) / (g[j].size() - 1);
} else {
dp2[j] += (1 + dp2[nex]) / (g[j].size());
}
}
}
res = min(res, dp2[1]);
}
cout << setprecision(30) << res << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | 0 | |
p02884 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
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 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;
}
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);
}
template <typename T = int64> 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 V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
template <typename F> struct FixPoint : F {
explicit FixPoint(F &&f) : F(forward<F>(f)) {}
template <typename... Args> decltype(auto) operator()(Args &&...args) const {
return F::operator()(*this, forward<Args>(args)...);
}
};
template <typename F> inline decltype(auto) MFP(F &&f) {
return FixPoint<F>{forward<F>(f)};
}
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
int main() {
int N, M;
cin >> N >> M;
auto dp = make_v<double>(N, N + 1);
fill_v(dp, infll);
UnWeightedGraph g(N);
auto rec = MFP([&](auto rec, int idx) -> void {
if (dp[idx][0] < infll) {
return;
}
if (idx + 1 == N) {
dp[idx][N] = 0.0;
return;
}
for (auto &to : g[idx])
rec(to);
int sz = (int)g[idx].size();
{
double ret = 0.0;
for (auto &to : g[idx])
ret += dp[to][N];
dp[idx][N] = ret / sz + 1;
}
{
for (int k = idx + 1; k < N; k++) {
double ret = 0.0;
for (auto &to : g[idx])
ret += min(dp[to][N], dp[to][k]);
chmin(dp[idx][k], ret / sz + 1);
}
}
if (sz > 1) {
double ret = 0.0;
for (auto &to : g[idx])
ret += dp[to][N];
for (auto &to : g[idx])
chmin(dp[idx][idx], (ret - dp[to][N]) / (sz - 1) + 1);
}
});
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
--a, --b;
g[a].emplace_back(b);
}
rec(0);
cout << *min_element(begin(dp[0]), end(dp[0])) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
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 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;
}
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);
}
template <typename T = int64> 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 V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
template <typename F> struct FixPoint : F {
explicit FixPoint(F &&f) : F(forward<F>(f)) {}
template <typename... Args> decltype(auto) operator()(Args &&...args) const {
return F::operator()(*this, forward<Args>(args)...);
}
};
template <typename F> inline decltype(auto) MFP(F &&f) {
return FixPoint<F>{forward<F>(f)};
}
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
int main() {
int N, M;
cin >> N >> M;
auto dp = make_v<double>(N, N + 1);
fill_v(dp, infll);
UnWeightedGraph g(N);
auto rec = MFP([&](auto rec, int idx) -> void {
if (dp[idx][N] < infll) {
return;
}
if (idx + 1 == N) {
dp[idx][N] = 0.0;
return;
}
for (auto &to : g[idx])
rec(to);
int sz = (int)g[idx].size();
{
double ret = 0.0;
for (auto &to : g[idx])
ret += dp[to][N];
dp[idx][N] = ret / sz + 1;
}
{
for (int k = idx + 1; k < N; k++) {
double ret = 0.0;
for (auto &to : g[idx])
ret += min(dp[to][N], dp[to][k]);
chmin(dp[idx][k], ret / sz + 1);
}
}
if (sz > 1) {
double ret = 0.0;
for (auto &to : g[idx])
ret += dp[to][N];
for (auto &to : g[idx])
chmin(dp[idx][idx], (ret - dp[to][N]) / (sz - 1) + 1);
}
});
for (int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
--a, --b;
g[a].emplace_back(b);
}
rec(0);
cout << *min_element(begin(dp[0]), end(dp[0])) << endl;
}
| replace | 112 | 113 | 112 | 113 | TLE | |
p02884 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for (LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for (LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for (LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for (auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c, x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL << (i))
#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif
#define gcd __gcd
using namespace std;
template <class T> constexpr T lcm(T m, T n) { return m / gcd(m, n) * n; }
template <typename I> void join(ostream &ost, I s, I t, string d = " ") {
for (auto i = s; i != t; ++i) {
if (i != s)
ost << d;
ost << *i;
}
ost << endl;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &a : v)
is >> a;
return is;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
return (a > b ? a = b, true : false);
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
return (a < b ? a = b, true : false);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
struct Init {
Init() {
cin.tie(0);
ios::sync_with_stdio(false);
}
} init;
template <typename Cost = int> class Edge {
public:
int from, to;
Cost cost;
Edge() {}
Edge(int to, Cost cost) : to(to), cost(cost) {}
Edge(int from, int to, Cost cost) : from(from), to(to), cost(cost) {}
Edge rev() const { return Edge(to, from, cost); }
friend ostream &operator<<(ostream &os, const Edge &e) {
os << "(FROM: " << e.from << ","
<< "TO: " << e.to << ","
<< "COST: " << e.cost << ")";
return os;
}
};
template <typename T> using Graph = vector<vector<Edge<T>>>;
template <typename T> using Tree = vector<vector<Edge<T>>>;
template <typename C, typename T> void add_edge(C &g, int from, int to, T w) {
g[from].push_back(Edge<T>(from, to, w));
}
template <typename C, typename T> void add_undirected(C &g, int a, int b, T w) {
g[a].push_back(Edge<T>(a, b, w));
g[b].push_back(Edge<T>(b, a, w));
}
double solve(int cur, const Graph<int> &g, vector<double> &dp, int proh) {
if (dp[cur] >= 0)
return dp[cur];
double ret = 0;
if (cur == proh) {
int n = g[cur].size();
n -= 1;
if (n == 0) {
return dp[cur] = INT_MAX;
}
vector<double> temp;
for (auto &e : g[cur]) {
temp.push_back(solve(e.to, g, dp, proh));
}
ret = accumulate(ALL(temp), 0.0) - *max_element(ALL(temp));
ret /= n;
ret += 1;
} else {
int n = g[cur].size();
for (auto &e : g[cur]) {
ret += solve(e.to, g, dp, proh) / n;
}
ret += 1;
}
return dp[cur] = ret;
}
int main() {
int N, M;
while (cin >> N >> M) {
Graph<int> g(N);
vector<pair<int, int>> edges;
REP(i, M) {
int s, t;
cin >> s >> t;
--s, --t;
add_edge(g, s, t, 1);
edges.emplace_back(s, t);
}
dump(g);
double ans = M;
{
vector<double> dp(N, -1);
dp[N - 1] = 0;
auto res = solve(0, g, dp, -1);
chmin(ans, res);
}
REP(i, M) {
vector<double> dp(N, -1);
dp[N - 1] = 0;
auto res = solve(0, g, dp, i);
chmin(ans, res);
}
cout << fixed << setprecision(12) << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for (LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for (LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for (LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for (auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c, x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL << (i))
#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif
#define gcd __gcd
using namespace std;
template <class T> constexpr T lcm(T m, T n) { return m / gcd(m, n) * n; }
template <typename I> void join(ostream &ost, I s, I t, string d = " ") {
for (auto i = s; i != t; ++i) {
if (i != s)
ost << d;
ost << *i;
}
ost << endl;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &a : v)
is >> a;
return is;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
return (a > b ? a = b, true : false);
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
return (a < b ? a = b, true : false);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
struct Init {
Init() {
cin.tie(0);
ios::sync_with_stdio(false);
}
} init;
template <typename Cost = int> class Edge {
public:
int from, to;
Cost cost;
Edge() {}
Edge(int to, Cost cost) : to(to), cost(cost) {}
Edge(int from, int to, Cost cost) : from(from), to(to), cost(cost) {}
Edge rev() const { return Edge(to, from, cost); }
friend ostream &operator<<(ostream &os, const Edge &e) {
os << "(FROM: " << e.from << ","
<< "TO: " << e.to << ","
<< "COST: " << e.cost << ")";
return os;
}
};
template <typename T> using Graph = vector<vector<Edge<T>>>;
template <typename T> using Tree = vector<vector<Edge<T>>>;
template <typename C, typename T> void add_edge(C &g, int from, int to, T w) {
g[from].push_back(Edge<T>(from, to, w));
}
template <typename C, typename T> void add_undirected(C &g, int a, int b, T w) {
g[a].push_back(Edge<T>(a, b, w));
g[b].push_back(Edge<T>(b, a, w));
}
double solve(int cur, const Graph<int> &g, vector<double> &dp, int proh) {
if (dp[cur] >= 0)
return dp[cur];
double ret = 0;
if (cur == proh) {
int n = g[cur].size();
n -= 1;
if (n == 0) {
return dp[cur] = INT_MAX;
}
vector<double> temp;
for (auto &e : g[cur]) {
temp.push_back(solve(e.to, g, dp, proh));
}
ret = accumulate(ALL(temp), 0.0) - *max_element(ALL(temp));
ret /= n;
ret += 1;
} else {
int n = g[cur].size();
for (auto &e : g[cur]) {
ret += solve(e.to, g, dp, proh) / n;
}
ret += 1;
}
return dp[cur] = ret;
}
int main() {
int N, M;
while (cin >> N >> M) {
Graph<int> g(N);
vector<pair<int, int>> edges;
REP(i, M) {
int s, t;
cin >> s >> t;
--s, --t;
add_edge(g, s, t, 1);
edges.emplace_back(s, t);
}
dump(g);
double ans = M;
{
vector<double> dp(N, -1);
dp[N - 1] = 0;
auto res = solve(0, g, dp, -1);
chmin(ans, res);
}
REP(i, N) {
vector<double> dp(N, -1);
dp[N - 1] = 0;
auto res = solve(0, g, dp, i);
chmin(ans, res);
}
cout << fixed << setprecision(12) << ans << endl;
}
return 0;
}
| replace | 152 | 153 | 152 | 153 | TLE | |
p02884 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i, n) for (auto &i : n)
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void init() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
#ifdef DEBUG
template <class T, class N> void verr(const T &a, const N &n) {
rep(i, n) cerr << a[i] << " ";
cerr << "\n" << flush;
}
ll dbgt = 1;
void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template <class H, class... T> void err(H &&h, T &&...t) {
cerr << h << (sizeof...(t) ? " " : "\n") << flush;
if (sizeof...(t) > 0)
err(forward<T>(t)...);
}
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
init();
ll N, M;
cin >> N >> M;
vvc<ll> G(N);
rep(i, M) {
ll s, t;
cin >> s >> t;
s--, t--;
G[s].eb(t);
}
// 頂点iからN-1までのパス長の期待値, その頂点にたどり着く確率
vc<ld> E(N), T(N);
repr(i, N - 1) {
repa(to, G[i]) E[i] += E[to];
E[i] /= G[i].size();
E[i] += 1;
}
auto dfs = [&](auto &&dfs, ll now, ld p) -> void {
T[now] += p;
p *= 1.0L / G[now].size();
repa(to, G[now]) { dfs(dfs, to, p); }
};
dfs(dfs, 0, 1.0L);
ld ans = E[0];
rep(now, N) {
ll gsize = G[now].size();
if (gsize <= 1)
continue;
repa(to, G[now]) {
chmin(ans, E[0] - T[now] * (E[now] -
(E[now] * gsize - E[to] - 1) / (gsize - 1)));
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i, n) for (auto &i : n)
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void init() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
#ifdef DEBUG
template <class T, class N> void verr(const T &a, const N &n) {
rep(i, n) cerr << a[i] << " ";
cerr << "\n" << flush;
}
ll dbgt = 1;
void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template <class H, class... T> void err(H &&h, T &&...t) {
cerr << h << (sizeof...(t) ? " " : "\n") << flush;
if (sizeof...(t) > 0)
err(forward<T>(t)...);
}
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
init();
ll N, M;
cin >> N >> M;
vvc<ll> G(N);
rep(i, M) {
ll s, t;
cin >> s >> t;
s--, t--;
G[s].eb(t);
}
// 頂点iからN-1までのパス長の期待値, その頂点にたどり着く確率
vc<ld> E(N), T(N);
repr(i, N - 1) {
repa(to, G[i]) E[i] += E[to];
E[i] /= G[i].size();
E[i] += 1;
}
T[0] = 1;
rep(now, N - 1) {
ll gsize = G[now].size();
repa(to, G[now]) T[to] += T[now] / gsize;
}
ld ans = E[0];
rep(now, N) {
ll gsize = G[now].size();
if (gsize <= 1)
continue;
repa(to, G[now]) {
chmin(ans, E[0] - T[now] * (E[now] -
(E[now] * gsize - E[to] - 1) / (gsize - 1)));
}
}
cout << ans << endl;
} | replace | 77 | 83 | 77 | 82 | TLE | |
p02884 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
const int N = (int)3e5;
ll mpow(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0) {
ll memo = mpow(a, b / 2);
return memo * memo % MOD;
} else
return mpow(a, b - 1) * a % MOD;
}
ll lpow(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0) {
ll memo = lpow(a, b / 2);
return memo * memo;
} else
return lpow(a, b - 1) * a;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n) {
if (kaijo_memo.size() > n)
return kaijo_memo[n];
if (kaijo_memo.size() == 0)
kaijo_memo.push_back(1);
while (kaijo_memo.size() <= n)
kaijo_memo.push_back(kaijo_memo[kaijo_memo.size() - 1] * kaijo_memo.size() %
MOD);
return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n) {
if (gyaku_kaijo_memo.size() > n)
return gyaku_kaijo_memo[n];
if (gyaku_kaijo_memo.size() == 0)
gyaku_kaijo_memo.push_back(1);
while (gyaku_kaijo_memo.size() <= n)
gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size() - 1] *
mpow(gyaku_kaijo_memo.size(), MOD - 2) % MOD);
return gyaku_kaijo_memo[n];
}
ll nCr(ll n, ll r) {
if (n == r)
return 1; // 0個の丸と-1個の棒みたいな時に時に効く?不安.
if (n < r || r < 0)
return 0;
ll ret = 1;
ret *= kaijo(n);
ret %= MOD;
ret *= gyaku_kaijo(r);
ret %= MOD;
ret *= gyaku_kaijo(n - r);
ret %= MOD;
return ret;
}
int n, m;
list<int> G[1000];
double dp[1000], p[1000], dp2[1000];
void func(int now) {
if (now == n - 1) {
rep(i, n) {
dp[i] = 0.0;
p[i] = 0.0;
}
p[0] = 1.0;
}
for (auto itr = G[now].begin(); itr != G[now].end(); itr++) {
int to = *itr;
dp[now] += (dp[to] + 1.0) / G[now].size();
}
if (now != 0)
func(now - 1);
}
void func2(int now, double dp_val, bool init) {
if (init) {
rep(i, n) { dp2[i] = dp[i]; }
dp2[now] = dp_val;
func2(now - 1, 0, false);
return;
}
if (now == -1)
return;
dp2[now] = 0.0;
for (auto itr = G[now].begin(); itr != G[now].end(); itr++) {
int to = *itr;
dp2[now] += (dp2[to] + 1.0) / G[now].size();
}
func2(now - 1, 0, false);
}
int main(void) {
cin >> n >> m;
rep(i, m) {
ll s, t;
cin >> s >> t;
s--;
t--;
G[s].push_back(t);
}
func(n - 1);
double ans = dp[0];
rep(i, n) {
int best_to = -1;
double best = -1;
if (G[i].size() <= 1)
continue;
for (auto itr = G[i].begin(); itr != G[i].end(); itr++) {
int to = *itr;
if (dp[to] > best) {
best_to = to;
best = dp[to];
}
}
double sum_new = 0.0;
for (auto itr = G[i].begin(); itr != G[i].end(); itr++) {
int to = *itr;
if (best_to == to)
continue;
sum_new += (dp[to] + 1.0) / (G[i].size() - 1.0);
}
func2(i, sum_new, true);
chmin(ans, dp2[0]);
}
cout << setprecision(10) << ans << endl;
return 0;
}
| #include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
const int N = (int)3e5;
ll mpow(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0) {
ll memo = mpow(a, b / 2);
return memo * memo % MOD;
} else
return mpow(a, b - 1) * a % MOD;
}
ll lpow(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0) {
ll memo = lpow(a, b / 2);
return memo * memo;
} else
return lpow(a, b - 1) * a;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n) {
if (kaijo_memo.size() > n)
return kaijo_memo[n];
if (kaijo_memo.size() == 0)
kaijo_memo.push_back(1);
while (kaijo_memo.size() <= n)
kaijo_memo.push_back(kaijo_memo[kaijo_memo.size() - 1] * kaijo_memo.size() %
MOD);
return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n) {
if (gyaku_kaijo_memo.size() > n)
return gyaku_kaijo_memo[n];
if (gyaku_kaijo_memo.size() == 0)
gyaku_kaijo_memo.push_back(1);
while (gyaku_kaijo_memo.size() <= n)
gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size() - 1] *
mpow(gyaku_kaijo_memo.size(), MOD - 2) % MOD);
return gyaku_kaijo_memo[n];
}
ll nCr(ll n, ll r) {
if (n == r)
return 1; // 0個の丸と-1個の棒みたいな時に時に効く?不安.
if (n < r || r < 0)
return 0;
ll ret = 1;
ret *= kaijo(n);
ret %= MOD;
ret *= gyaku_kaijo(r);
ret %= MOD;
ret *= gyaku_kaijo(n - r);
ret %= MOD;
return ret;
}
int n, m;
vector<int> G[1000];
double dp[1000], p[1000], dp2[1000];
void func(int now) {
if (now == n - 1) {
rep(i, n) {
dp[i] = 0.0;
p[i] = 0.0;
}
p[0] = 1.0;
}
for (auto itr = G[now].begin(); itr != G[now].end(); itr++) {
int to = *itr;
dp[now] += (dp[to] + 1.0) / G[now].size();
}
if (now != 0)
func(now - 1);
}
void func2(int now, double dp_val, bool init) {
if (init) {
rep(i, n) { dp2[i] = dp[i]; }
dp2[now] = dp_val;
func2(now - 1, 0, false);
return;
}
if (now == -1)
return;
dp2[now] = 0.0;
for (auto itr = G[now].begin(); itr != G[now].end(); itr++) {
int to = *itr;
dp2[now] += (dp2[to] + 1.0) / G[now].size();
}
func2(now - 1, 0, false);
}
int main(void) {
cin >> n >> m;
rep(i, m) {
ll s, t;
cin >> s >> t;
s--;
t--;
G[s].push_back(t);
}
func(n - 1);
double ans = dp[0];
rep(i, n) {
int best_to = -1;
double best = -1;
if (G[i].size() <= 1)
continue;
for (auto itr = G[i].begin(); itr != G[i].end(); itr++) {
int to = *itr;
if (dp[to] > best) {
best_to = to;
best = dp[to];
}
}
double sum_new = 0.0;
for (auto itr = G[i].begin(); itr != G[i].end(); itr++) {
int to = *itr;
if (best_to == to)
continue;
sum_new += (dp[to] + 1.0) / (G[i].size() - 1.0);
}
func2(i, sum_new, true);
chmin(ans, dp2[0]);
}
cout << setprecision(10) << ans << endl;
return 0;
}
| replace | 92 | 93 | 92 | 93 | TLE | |
p02884 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils {
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
template <class T, class Compare>
using p_queue = priority_queue<T, vector<T>, Compare>;
template <class T> using min_queue = p_queue<T, greater<T>>;
template <class T> using max_queue = p_queue<T, less<T>>;
template <class T> bool up_min(T &X, const T &A) {
if (X > A) {
X = A;
return true;
}
return false;
}
template <class T> bool up_max(T &X, const T &A) {
if (X < A) {
X = A;
return true;
}
return false;
}
ll operator"" _64(unsigned long long x) { return ll(x); }
ull operator"" _64u(unsigned long long x) { return ull(x); }
template <class T> vector<T> make_mdvector(int n, T t) {
return vector<T>(n, t);
}
template <class... Ts> auto make_mdvector(int n, Ts... ts) {
return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
}
inline ll bit(int x) { return 1ll << x; }
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v) {
is >> x;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &&x : v) {
os << x << ' ';
}
cout << endl;
return os;
}
} // namespace utils
using namespace utils;
class solver {
istream &is;
ostream &os;
public:
solver(istream &I, ostream &O) : is(I), os(O) {}
ll N, M;
vector<vector<int>> in, out;
void run();
};
int main(int argc, char *argv[]) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(16) << scientific;
#ifdef XELMH
string test_cases = "test_F.txt";
cerr << test_cases << " -->" << endl;
auto fs = fstream(test_cases, fstream::in);
int loop = 0;
while (fs) {
loop++;
cout << '#' << loop << "#------\n";
solver(fs, cout).run();
}
if (loop <= 1) {
cout << "===" << endl;
while (cin)
solver(cin, cout).run();
}
#else
solver(cin, cout).run();
#endif
return 0;
}
void solver::run() {
is >> N >> M;
if (!is)
return;
out.resize(N);
for (int ii = 0; ii < M; ++ii) {
int s, t;
is >> s >> t;
s--;
t--;
out[s].push_back(t);
} // end ii
double ans = INF;
for (int i = 0; i < N; ++i) {
auto dp = make_mdvector(N, 1e+9);
dp[N - 1] = 0;
dp[N - 1] = 0;
for (int v = N - 2; v >= 0; --v) {
vector<double> es0;
double mxe = 0;
for (auto &&u : out[v]) {
es0.push_back(dp[u] + 1);
up_max(mxe, dp[u] + 1);
} // end u
if (es0.empty())
continue;
sort(ALL(es0));
dp[v] = 0;
for (int t = 0; t < es0.size(); ++t) {
dp[v] += (es0[t]);
} // end t
if (i == v and es0.size() > 1) {
dp[v] -= mxe;
dp[v] /= es0.size() - 1;
} else
dp[v] /= es0.size();
} // end v
up_min(ans, dp[0]);
} // end i
os << ans << endl;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils {
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
template <class T, class Compare>
using p_queue = priority_queue<T, vector<T>, Compare>;
template <class T> using min_queue = p_queue<T, greater<T>>;
template <class T> using max_queue = p_queue<T, less<T>>;
template <class T> bool up_min(T &X, const T &A) {
if (X > A) {
X = A;
return true;
}
return false;
}
template <class T> bool up_max(T &X, const T &A) {
if (X < A) {
X = A;
return true;
}
return false;
}
ll operator"" _64(unsigned long long x) { return ll(x); }
ull operator"" _64u(unsigned long long x) { return ull(x); }
template <class T> vector<T> make_mdvector(int n, T t) {
return vector<T>(n, t);
}
template <class... Ts> auto make_mdvector(int n, Ts... ts) {
return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
}
inline ll bit(int x) { return 1ll << x; }
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v) {
is >> x;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &&x : v) {
os << x << ' ';
}
cout << endl;
return os;
}
} // namespace utils
using namespace utils;
class solver {
istream &is;
ostream &os;
public:
solver(istream &I, ostream &O) : is(I), os(O) {}
ll N, M;
vector<vector<int>> in, out;
void run();
};
int main(int argc, char *argv[]) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(16) << scientific;
#ifdef XELMH
string test_cases = "test_F.txt";
cerr << test_cases << " -->" << endl;
auto fs = fstream(test_cases, fstream::in);
int loop = 0;
while (fs) {
loop++;
cout << '#' << loop << "#------\n";
solver(fs, cout).run();
}
if (loop <= 1) {
cout << "===" << endl;
while (cin)
solver(cin, cout).run();
}
#else
solver(cin, cout).run();
#endif
return 0;
}
void solver::run() {
is >> N >> M;
if (!is)
return;
out.resize(N);
for (int ii = 0; ii < M; ++ii) {
int s, t;
is >> s >> t;
s--;
t--;
out[s].push_back(t);
} // end ii
double ans = INF;
for (int i = 0; i < N; ++i) {
auto dp = make_mdvector(N, 1e+9);
dp[N - 1] = 0;
dp[N - 1] = 0;
for (int v = N - 2; v >= 0; --v) {
vector<double> es0;
double mxe = 0;
for (auto &&u : out[v]) {
es0.push_back(dp[u] + 1);
up_max(mxe, dp[u] + 1);
} // end u
if (es0.empty())
continue;
dp[v] = 0;
for (int t = 0; t < es0.size(); ++t) {
dp[v] += (es0[t]);
} // end t
if (i == v and es0.size() > 1) {
dp[v] -= mxe;
dp[v] /= es0.size() - 1;
} else
dp[v] /= es0.size();
} // end v
up_min(ans, dp[0]);
} // end i
os << ans << endl;
}
| delete | 146 | 147 | 146 | 146 | TLE | |
p02885 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int, int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i, p, q) for (int i = p; i < q; i++)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pi(a) printf("%d\n", a)
#define psi(a) printf(" %d", a)
#define poi(a) printf("%d", a)
#define sl(a) scanf("%lld", &a)
#define pl(a) printf("%lld\n", a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s", str)
#define pstr(str) printf("%s\n", str)
#define SET(a) memset(a, -1, sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(), (v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a, n) \
vi a(n); \
rep(i, n) cin >> a[i];
#define sq(n) (n) * (n)
#define iso \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(NULL);
#define cases \
int t; \
cin >> t; \
while (t--)
int main() {
iso;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a, b;
cin >> a >> b;
b = max(0, a - 2 * b);
cout << b;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<int, int>
#define pb push_back
#define INF INT_MAX
#define mod 1000000007ll
#define fi first
#define se second
#define f(i, p, q) for (int i = p; i < q; i++)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pi(a) printf("%d\n", a)
#define psi(a) printf(" %d", a)
#define poi(a) printf("%d", a)
#define sl(a) scanf("%lld", &a)
#define pl(a) printf("%lld\n", a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s", str)
#define pstr(str) printf("%s\n", str)
#define SET(a) memset(a, -1, sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(), (v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a, n) \
vi a(n); \
rep(i, n) cin >> a[i];
#define sq(n) (n) * (n)
#define iso \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(NULL);
#define cases \
int t; \
cin >> t; \
while (t--)
int main() {
iso;
/* #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
int a, b;
cin >> a >> b;
b = max(0, a - 2 * b);
cout << b;
}
| replace | 42 | 46 | 42 | 46 | 0 | |
p02885 | Python | Runtime Error | a = int(input())
b = int(input())
ans = a // (b * 2)
if ans <= 0:
ans = 0
print(ans)
| a, b = map(int, input().split())
ans = a - (b * 2)
if ans <= 0:
ans = 0
print(ans)
| replace | 0 | 4 | 0 | 2 | ValueError: invalid literal for int() with base 10: '12 4' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02885/Python/s927098253.py", line 1, in <module>
a = int(input())
ValueError: invalid literal for int() with base 10: '12 4'
|
p02885 | Python | Runtime Error | a = int(input())
b = int(input())
if a > b * 2:
print(a - b * 2)
else:
print(0)
| list = input().split()
a = int(list[0])
b = int(list[1])
if a > b * 2:
print(a - b * 2)
else:
print(0)
| replace | 0 | 2 | 0 | 4 | ValueError: invalid literal for int() with base 10: '12 4' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02885/Python/s894876689.py", line 1, in <module>
a = int(input())
ValueError: invalid literal for int() with base 10: '12 4'
|
p02885 | C++ | Runtime Error | #include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d", a, b);
if (a > 2 * b) {
c = a - 2 * b;
printf("%d", c);
} else {
printf("%d", 0);
}
} | #include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d", &a, &b);
if (a > 2 * b) {
c = a - 2 * b;
printf("%d", c);
} else {
printf("%d", 0);
}
} | replace | 4 | 5 | 4 | 5 | -11 | |
p02885 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
int A, B;
cin >> A >> B;
if (B * 2 > A) {
cout << "0" << endl;
} else {
cout << (A - B * 2) << endl;
}
return 1;
}
| #include <iostream>
using namespace std;
int main(void) {
int A, B;
cin >> A >> B;
if (B * 2 > A) {
cout << "0" << endl;
} else {
cout << (A - B * 2) << endl;
}
return 0;
} | replace | 15 | 16 | 15 | 16 | 1 | |
p02885 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define lv vector<ll>
#define cv vector<char>
#define dv vector<ld>
#define rall(c) (c).rbegin(), (c).rend()
#define lpr pair<ll, ll>
#define mp make_pair
#define input(c) \
ll c; \
cin >> c;
#define lmap map<ll, ll>
#define vinp(a, n) \
inc(i, 1, n) { \
input(k); \
a.pb(k); \
}
#define LIM 1000000007
#define F first
#define S second
#define fr(n) inc(i, 0, n - 1)
#define fri(n, a) \
inc(i, 0, n - 1) { cin >> a[i]; }
void solve() {
ll i, j;
ll a, b;
cin >> a >> b;
if (a - 2 * b < 0)
cout << 0;
else
cout << a - 2 * b;
}
int main() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin>>t;
while (t--)
solve();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define lv vector<ll>
#define cv vector<char>
#define dv vector<ld>
#define rall(c) (c).rbegin(), (c).rend()
#define lpr pair<ll, ll>
#define mp make_pair
#define input(c) \
ll c; \
cin >> c;
#define lmap map<ll, ll>
#define vinp(a, n) \
inc(i, 1, n) { \
input(k); \
a.pb(k); \
}
#define LIM 1000000007
#define F first
#define S second
#define fr(n) inc(i, 0, n - 1)
#define fri(n, a) \
inc(i, 0, n - 1) { cin >> a[i]; }
void solve() {
ll i, j;
ll a, b;
cin >> a >> b;
if (a - 2 * b < 0)
cout << 0;
else
cout << a - 2 * b;
}
int main() {
fast;
ll t = 1;
// cin>>t;
while (t--)
solve();
}
| delete | 44 | 48 | 44 | 44 | 0 | |
p02885 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
if (!a) {
*x = 0;
*y = 1;
return b;
}
ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
ll modI(ll b, ll m) {
ll x, y;
gcdEx(b, m, &x, &y);
return (x % m + m) % m;
}
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef set<ll> si;
typedef map<string, ll> msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) \
sort(all((x))); \
(x).resize(unique(all((x))) - (x).begin())
#define loop(i, b, n) for (ll i = b; i < n; i++)
#define loopv(b, n, a) for (ll i = b; i < n; i += a)
#define loopr(b, n) for (ll i = n; i >= 0; i--)
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
#define modA(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modS(a, b) \
(((((a % MOD) - (b % MOD)) % MOD) < 0) \
? (int)(MOD + ((a % MOD) - (b % MOD)) % MOD) \
: (int)(((a % MOD) - (b % MOD)) % MOD))
#define modM(a, b) (ll)((((ll)(a % MOD)) * ((ll)(b % MOD))) % MOD)
#define modD(a, b) ((modI(b, MOD) * (a % MOD)) % MOD)
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
ll modP(ll x, ll y) {
ll r = 1;
x %= MOD;
while (y > 0) {
if (y & 1) {
r = (r * x) % MOD;
}
y = y >> 1;
x = (x * x) % MOD;
}
return r;
}
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
ll t, ans;
ll n, m;
cin >> n >> m;
ans = n - 2 * m;
if (ans < 0)
ans = 0;
cout << ans << "\n";
return 0;
}
/* The judge is never wrong! Your code is buggy
Look for:
* * Read the problem carefully.
* * Don't forget to sort(), mod, ll!!!!
* * Initial value = +/- infinity instead of zero!!!
* * an easier and alternate approach
* * read the problem statement carefully
* * if concept is correct and still WA, try with a different implementation
* * special cases (n=1?)
* * if you have no idea just guess the appropriate well-known algorithm instead
of doing nothing :/
*/
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
if (!a) {
*x = 0;
*y = 1;
return b;
}
ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
ll modI(ll b, ll m) {
ll x, y;
gcdEx(b, m, &x, &y);
return (x % m + m) % m;
}
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef set<ll> si;
typedef map<string, ll> msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) \
sort(all((x))); \
(x).resize(unique(all((x))) - (x).begin())
#define loop(i, b, n) for (ll i = b; i < n; i++)
#define loopv(b, n, a) for (ll i = b; i < n; i += a)
#define loopr(b, n) for (ll i = n; i >= 0; i--)
#define sum(a) (accumulate((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define MOD 1000000007
#define modA(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modS(a, b) \
(((((a % MOD) - (b % MOD)) % MOD) < 0) \
? (int)(MOD + ((a % MOD) - (b % MOD)) % MOD) \
: (int)(((a % MOD) - (b % MOD)) % MOD))
#define modM(a, b) (ll)((((ll)(a % MOD)) * ((ll)(b % MOD))) % MOD)
#define modD(a, b) ((modI(b, MOD) * (a % MOD)) % MOD)
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
ll modP(ll x, ll y) {
ll r = 1;
x %= MOD;
while (y > 0) {
if (y & 1) {
r = (r * x) % MOD;
}
y = y >> 1;
x = (x * x) % MOD;
}
return r;
}
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
ll t, ans;
ll n, m;
cin >> n >> m;
ans = n - 2 * m;
if (ans < 0)
ans = 0;
cout << ans << "\n";
return 0;
}
/* The judge is never wrong! Your code is buggy
Look for:
* * Read the problem carefully.
* * Don't forget to sort(), mod, ll!!!!
* * Initial value = +/- infinity instead of zero!!!
* * an easier and alternate approach
* * read the problem statement carefully
* * if concept is correct and still WA, try with a different implementation
* * special cases (n=1?)
* * if you have no idea just guess the appropriate well-known algorithm instead
of doing nothing :/
*/
| replace | 104 | 107 | 104 | 106 | 0 | |
p02885 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N = 200005;
ll modulo(ll num, ll MOD = mod) {
return ((num % MOD) + MOD) % MOD;
} // for negative integer
ll power(ll b, ll e, ll MOD = mod) {
ll ans = 1;
while (e) {
if (e % 2)
ans = (ans * b) % MOD;
b = (b * b) % MOD;
e /= 2;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
cout << fixed << setprecision(15);
ll a, b;
cin >> a >> b;
cout << max(0LL, a - 2LL * b);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N = 200005;
ll modulo(ll num, ll MOD = mod) {
return ((num % MOD) + MOD) % MOD;
} // for negative integer
ll power(ll b, ll e, ll MOD = mod) {
ll ans = 1;
while (e) {
if (e % 2)
ans = (ans * b) % MOD;
b = (b * b) % MOD;
e /= 2;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/* #ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif*/
cout << fixed << setprecision(15);
ll a, b;
cin >> a >> b;
cout << max(0LL, a - 2LL * b);
return 0;
} | replace | 25 | 31 | 25 | 31 | 0 | |
p02885 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
const ll mod = 1000000007;
ll po(ll k, ll n) {
if (n == 1)
return k % mod;
else {
ll a = po(k, n / 2) % mod;
if (n % 2 == 0)
return (a * a) % mod;
else
return (((a * a) % mod) * k) % mod;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (a - 2 * b > 0)
cout << a - 2 * b << endl;
else
cout << "0" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
const ll mod = 1000000007;
ll po(ll k, ll n) {
if (n == 1)
return k % mod;
else {
ll a = po(k, n / 2) % mod;
if (n % 2 == 0)
return (a * a) % mod;
else
return (((a * a) % mod) * k) % mod;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r" , stdin);
// freopen("output.txt", "w" , stdout);
// #endif
int t = 1;
// cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (a - 2 * b > 0)
cout << a - 2 * b << endl;
else
cout << "0" << endl;
}
return 0;
}
| replace | 35 | 39 | 35 | 39 | 0 | |
p02885 | C++ | Runtime Error | //--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using namespace std::chrono;
#define REDL(a, n) \
vll a(n); \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define REPR(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(X) X.begin(), X.end()
#define reset(X) memset(X, 0, sizeof(X))
#define endl '\n'
#define int long long
//------------------------------_WARNINGG---------------
//-----------------------------TEMPLATES------------------TEMPLATES---------------------------TEMPLATES---------------------------------
//-----------------------------TEMPLATES------------------TEMPLATES---------------------------TEMPLATES---------------------------------
//--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF----------------------------TYPEDEF
//--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF----------------------------TYPEDEF
typedef long long ll;
typedef double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
//--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS
//--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS
const int INF = 1e18 + 10;
const ll mod = 1000000007;
const ld PI = acos(-1);
//------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT
// To find GCD of a and b
ll gcd(ll a, ll b);
// To compute x raised to power y under modulo m
// To compute x^y under modulo m
int power(int x, int y, int p) {
int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Function to find modular inverse of a under modulo m
// Assumption: m is prime
ll modInverse(ll a, ll m = mod) {
ll g = 1;
if (g != 1)
cout << "Inverse doesn't exist";
else {
// If a and m are relatively prime, then modulo inverse
// is a^(m-2) mode m
return power(a, m - 2, m);
}
}
// Function to return gcd of a and b
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
void coordinate_compress(vector<int> &a) {
set<int> b;
for (auto i : a)
b.insert(i);
map<int, int> da;
int counter = 0;
for (auto i : b)
da[i] = counter++;
for (auto &i : a)
i = da[i];
}
//----------------WORK__________________________________
//----------------------MAIN______________________________MAIN__________________MAINco
signed main() {
auto start = high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("INPUT.txt", "r", stdin);
// freopen ("OUTPUT.txt" , "w" , stdout);
#endif
//-----------------------------------------------------------------------------------------------------------
int a, b;
cin >> a >> b;
cout << max((int)0, a - 2 * b);
//----------------------------------------------------------------------------------------------------------
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
// cerr <<finishl<<"Time in microseconds:" <<duration.count()
// <<finishl<<"Time in seconds:"<<duration.count()/(1000000.0)<< finishl;
}
| //--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR--------PREPROCESSOR
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using namespace std::chrono;
#define REDL(a, n) \
vll a(n); \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define REPR(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(X) X.begin(), X.end()
#define reset(X) memset(X, 0, sizeof(X))
#define endl '\n'
#define int long long
//------------------------------_WARNINGG---------------
//-----------------------------TEMPLATES------------------TEMPLATES---------------------------TEMPLATES---------------------------------
//-----------------------------TEMPLATES------------------TEMPLATES---------------------------TEMPLATES---------------------------------
//--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF----------------------------TYPEDEF
//--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF--------------TYPEDEF----------------------------TYPEDEF
typedef long long ll;
typedef double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
//--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS
//--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS--------------CONSTANTS
const int INF = 1e18 + 10;
const ll mod = 1000000007;
const ld PI = acos(-1);
//------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT------------------IGNOREABLE_CONTENT
// To find GCD of a and b
ll gcd(ll a, ll b);
// To compute x raised to power y under modulo m
// To compute x^y under modulo m
int power(int x, int y, int p) {
int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Function to find modular inverse of a under modulo m
// Assumption: m is prime
ll modInverse(ll a, ll m = mod) {
ll g = 1;
if (g != 1)
cout << "Inverse doesn't exist";
else {
// If a and m are relatively prime, then modulo inverse
// is a^(m-2) mode m
return power(a, m - 2, m);
}
}
// Function to return gcd of a and b
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
void coordinate_compress(vector<int> &a) {
set<int> b;
for (auto i : a)
b.insert(i);
map<int, int> da;
int counter = 0;
for (auto i : b)
da[i] = counter++;
for (auto &i : a)
i = da[i];
}
//----------------WORK__________________________________
//----------------------MAIN______________________________MAIN__________________MAINco
signed main() {
auto start = high_resolution_clock::now();
ios_base::sync_with_stdio(false);
cin.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen ("INPUT.txt" , "r" , stdin);
// // freopen ("OUTPUT.txt" , "w" , stdout);
// #endif
//-----------------------------------------------------------------------------------------------------------
int a, b;
cin >> a >> b;
cout << max((int)0, a - 2 * b);
//----------------------------------------------------------------------------------------------------------
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
// cerr <<finishl<<"Time in microseconds:" <<duration.count()
// <<finishl<<"Time in seconds:"<<duration.count()/(1000000.0)<< finishl;
}
| replace | 108 | 112 | 108 | 112 | 0 | |
p02885 | Python | Runtime Error | A = int(input())
B = int(input())
remain = max(0, A - B * 2)
print(remain)
| data = input().split()
A = int(data[0])
B = int(data[1])
remain = max(0, A - B * 2)
print(remain)
| replace | 0 | 2 | 0 | 3 | ValueError: invalid literal for int() with base 10: '12 4' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02885/Python/s165633108.py", line 1, in <module>
A = int(input())
ValueError: invalid literal for int() with base 10: '12 4'
|
p02885 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii pair<long long int, long long int>
#define vi vector<long long int>
#define vii vector<pair<long long int, long long int>>
#define all(cont) cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#pragma GCC optimize("Ofast")
int main() {
IOS;
clock_t clk = clock();
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int a, b;
cin >> a >> b;
if (2 * b <= a)
cout << a - (2 * b);
else
cout << 0;
cerr << endl
<< setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii pair<long long int, long long int>
#define vi vector<long long int>
#define vii vector<pair<long long int, long long int>>
#define all(cont) cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#pragma GCC optimize("Ofast")
int main() {
IOS;
clock_t clk = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b;
cin >> a >> b;
if (2 * b <= a)
cout << a - (2 * b);
else
cout << 0;
cerr << endl
<< setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
return 0;
} | replace | 25 | 27 | 25 | 27 | 0 |
0.0003420000 |
p02886 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int MAX = 50;
int main() {
int N;
cin >> N;
int ans = 0;
vector<int> d(MAX);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
int k = 0;
for (int i = 0; i < N; i++) {
for (int j = 1; j < N; j++) {
ans += d.at(i) * d.at(j + k);
}
k++;
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int MAX = 100;
int main() {
int N;
cin >> N;
int ans = 0;
vector<int> d(MAX);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
int k = 0;
for (int i = 0; i < N; i++) {
for (int j = 1; j < N; j++) {
ans += d.at(i) * d.at(j + k);
}
k++;
}
cout << ans;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02886 | C++ | Runtime Error |
/// HR_Bappy
//
///*******
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define maxx 1000000005
#define MOD 1000003
#define sf(n) scanf("%lld", &n);
#define sff(n, m) scanf("%lld %lld", &n, &m)
#define pf(n) printf("%lld\n", n)
#define pff(n, m) printf("%lld %lld\n", n, m)
#define mem(a) memset(a, 0, sizeof(a))
#define fr(i, n) for (ll i = 0; i < n; i++)
#define my_sizeof(type) ((char *)(&type + 1) - (char *)(&type))
#define pi 2 * acos(0.0)
#define F first
#define S second
#define EPS 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
if (b)
v.pb(b);
}
int c = 0;
for (int i = 0; i < v.size() - 1; i++) {
if (!v[i])
continue;
for (int j = i + 1; j < v.size(); j++) {
c += v[i] * v[j];
}
}
cout << c << endl;
return 0;
}
|
/// HR_Bappy
//
///*******
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define maxx 1000000005
#define MOD 1000003
#define sf(n) scanf("%lld", &n);
#define sff(n, m) scanf("%lld %lld", &n, &m)
#define pf(n) printf("%lld\n", n)
#define pff(n, m) printf("%lld %lld\n", n, m)
#define mem(a) memset(a, 0, sizeof(a))
#define fr(i, n) for (ll i = 0; i < n; i++)
#define my_sizeof(type) ((char *)(&type + 1) - (char *)(&type))
#define pi 2 * acos(0.0)
#define F first
#define S second
#define EPS 1e-9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
if (b)
v.pb(b);
}
int c = 0;
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
c += v[i] * v[j];
}
}
cout << c << endl;
return 0;
}
| replace | 37 | 40 | 37 | 38 | 0 | |
p02886 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<long long> d;
for (int i = 0; i < n; i++)
cin >> d[i];
long long sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
sum += d[i] * d[j];
}
}
cout << sum << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<long long> d(n);
for (int i = 0; i < n; i++)
cin >> d[i];
long long sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
sum += d[i] * d[j];
}
}
cout << sum << endl;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p02886 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int n;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
int sum = 0;
rep(i, n) {
for (int j = i + 1; i < n; j++) {
sum += d[i] * d[j];
}
}
cout << sum << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int n;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
int sum = 0;
rep(i, n) {
for (int j = i + 1; j < n; j++) {
sum += d[i] * d[j];
}
}
cout << sum << endl;
return 0;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02886 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
int s[51];
cin >> a;
for (int i = 0; i < a; i++) {
cin >> s[i];
}
int sum = 0;
for (int i = 0; i < a - 1; i++) {
for (int j = i + 1; i < a; j++) {
sum = sum + s[i] * s[j];
}
}
cout << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
int s[51];
cin >> a;
for (int i = 0; i < a; i++) {
cin >> s[i];
}
int sum = 0;
for (int i = 0; i < a - 1; i++) {
for (int j = i + 1; j < a; j++) {
sum = sum + s[i] * s[j];
}
}
cout << sum;
return 0;
} | replace | 11 | 12 | 11 | 12 | TLE | |
p02886 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define rep(i, beg, end) for (auto i = (beg); i < (end); i++)
#define rep2(name, container) \
for (auto name = begin(container); name != end(container); name++)
#define all(cont) begin(cont), end(cont)
#define rall(cont) rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vi d;
rep(i, 0, n) {
ll t;
cin >> t;
if (t > 0)
d.push_back(t);
}
const ll SENTINEL_D = 101;
ll dp[SENTINEL_D][SENTINEL_D] = {
0,
};
ll sum = 0;
rep(i, 0, d.size() - 1) {
ll x = d[i];
rep(j, i + 1, d.size()) {
ll y = d[j];
if (dp[x][y])
sum += dp[x][y];
else
sum += dp[x][y] = x * y;
}
}
cout << sum << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define rep(i, beg, end) for (auto i = (beg); i < (end); i++)
#define rep2(name, container) \
for (auto name = begin(container); name != end(container); name++)
#define all(cont) begin(cont), end(cont)
#define rall(cont) rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vi d;
rep(i, 0, n) {
ll t;
cin >> t;
if (t > 0)
d.push_back(t);
}
if (d.empty())
d.push_back(0);
const ll SENTINEL_D = 101;
ll dp[SENTINEL_D][SENTINEL_D] = {
0,
};
ll sum = 0;
rep(i, 0, d.size() - 1) {
ll x = d[i];
rep(j, i + 1, d.size()) {
ll y = d[j];
if (dp[x][y])
sum += dp[x][y];
else
sum += dp[x][y] = x * y;
}
}
cout << sum << endl;
return 0;
}
| insert | 27 | 27 | 27 | 29 | 0 | |
p02886 | C++ | Runtime Error | #include <iostream> //atcoder143B
using namespace std;
int main(void) {
int n, d[n], a, i, j, all = 0;
cin >> n;
for (a = 0; a < n; a++)
cin >> d[a];
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
all += d[i] * d[j];
}
}
cout << all << endl;
return 0;
} | #include <iostream> //atcoder143B
using namespace std;
int main(void) {
int n, d[100], a, i, j, all = 0;
cin >> n;
for (a = 0; a < n; a++)
cin >> d[a];
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
all += d[i] * d[j];
}
}
cout << all << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02886 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
v.push_back(a);
}
long long sum = 0;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++i) {
sum += (v[i] * v[j]);
}
}
cout << sum << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
v.push_back(a);
}
long long sum = 0;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
sum += (v[i] * v[j]);
}
}
cout << sum << endl;
} | replace | 17 | 18 | 17 | 18 | TLE | |
p02886 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; i++) {
sum = sum + a[i] * a[j];
}
}
cout << sum << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
sum = sum + a[i] * a[j];
}
}
cout << sum << "\n";
} | replace | 10 | 11 | 10 | 11 | TLE | |
p02886 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<int> a;
for (int i = 0; i < n; i++)
cin >> a[i];
int sum = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sum += a[i] * a[j];
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int sum = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sum += a[i] * a[j];
}
}
cout << sum << endl;
} | replace | 5 | 6 | 5 | 6 | -11 | |
p02886 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int n;
int d[101];
cin >> n;
for (size_t i = 0; i < n; i++) {
cin >> d[i];
}
int ans = 0;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; i++) {
if (i < j) {
ans += d[i] * d[j];
}
}
}
cout << ans;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int n;
int d[101];
cin >> n;
for (size_t i = 0; i < n; i++) {
cin >> d[i];
}
int ans = 0;
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
if (i < j) {
ans += d[i] * d[j];
}
}
}
cout << ans;
return 0;
}
| replace | 22 | 23 | 22 | 23 | TLE | |
p02886 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int all = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; i < N; j++) {
all += vec.at(i) * vec.at(j);
}
}
int same = 0;
for (int i = 0; i < N; i++) {
same += vec.at(i) * vec.at(i);
}
cout << (all - same) / 2 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int all = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
all += vec.at(i) * vec.at(j);
}
}
int same = 0;
for (int i = 0; i < N; i++) {
same += vec.at(i) * vec.at(i);
}
cout << (all - same) / 2 << endl;
}
| replace | 12 | 13 | 12 | 13 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02886 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
int s = 0;
rep(i, n) for (int j = i + 1; j < n; ++i) { s += d[i] * d[j]; }
cout << s << 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 main() {
int n;
cin >> n;
vector<int> d(n);
rep(i, n) cin >> d[i];
int s = 0;
rep(i, n) for (int j = i + 1; j < n; ++j) { s += d[i] * d[j]; }
cout << s << endl;
return 0;
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p02886 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d;
for (int i = 0; i < n; i++)
cin >> d.at(i);
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
else {
ans += d.at(i) * d.at(j);
}
}
}
long long t = 2;
cout << ans / t << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++)
cin >> d.at(i);
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
else {
ans += d.at(i) * d.at(j);
}
}
}
long long t = 2;
cout << ans / t << endl;
} | replace | 5 | 6 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p02886 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
ans += d[i] * d[j];
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> d(n);
for (int i = 0; i < n; i++) {
cin >> d[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
ans += d[i] * d[j];
}
}
cout << ans << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | -11 | |
p02886 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
rep(i, N) cin >> d[i];
int ans = 0;
rep(i, N) {
for (int j = i + 1; j < N; i++) {
ans += d[i] * d[j];
}
}
cout << ans;
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 main() {
int N;
cin >> N;
vector<int> d(N);
rep(i, N) cin >> d[i];
int ans = 0;
rep(i, N) {
for (int j = i + 1; j < N; j++) {
ans += d[i] * d[j];
}
}
cout << ans;
return 0;
}
| replace | 13 | 14 | 13 | 14 | TLE | |
p02886 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> list(n);
for (int i = 0; i < n; ++i) {
cin >> list[i];
}
long long total = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++i) {
total += list[i] * list[j];
}
}
cout << total << endl;
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> list(n);
for (int i = 0; i < n; ++i) {
cin >> list[i];
}
long long total = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
total += list[i] * list[j];
}
}
cout << total << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p02886 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N, sum = 0;
cin >> N;
int d[N];
for (int i = 0; i < N; i++) {
cin >> d[i];
}
int rep = N * (N - 1) / 2;
for (int i = 0; i < rep; i++) {
for (int j = i; j < rep; j++) {
if (i != j) {
sum += d[i] * d[j];
}
}
}
cout << sum << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N, sum = 0;
cin >> N;
int d[N];
for (int i = 0; i < N; i++) {
cin >> d[i];
}
int rep = N * (N - 1) / 2;
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
if (i != j) {
sum += d[i] * d[j];
}
}
}
cout << sum << endl;
return 0;
} | replace | 15 | 17 | 15 | 17 | 0 | |
p02886 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d;
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
int count = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
count += d.at(i) * d.at(j);
}
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++) {
cin >> d.at(i);
}
int count = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
count += d.at(i) * d.at(j);
}
}
cout << count << endl;
} | replace | 5 | 6 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p02886 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int d[n];
for (int i = 0; i < n; i++)
cin >> d[i];
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; i < n; j++) {
ans += d[i] * d[j];
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int d[n];
for (int i = 0; i < n; i++)
cin >> d[i];
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
ans += d[i] * d[j];
}
}
cout << ans << endl;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p02886 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i += 1) {
cin >> a[i];
}
int A = 0;
for (int i = 0; i < N; i += 1) {
for (int j = i + 1; i < N; j += 1) {
A += a[i] * a[j];
}
}
cout << A << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i += 1) {
cin >> a[i];
}
int A = 0;
for (int i = 0; i < N - 1; i += 1) {
for (int j = i + 1; j < N; j += 1) {
A += a[i] * a[j];
}
}
cout << A << endl;
} | replace | 11 | 13 | 11 | 13 | TLE | |
p02886 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
void func143b() {
int n, d[50] = {};
int i, j, x, y, cnt = 0;
cin >> n;
for (i = 1; i <= n; i++)
cin >> d[i];
for (i = 1; i < n; i++) {
x = d[i];
// cout << "takoyaki_" << i << ": " << x << endl;
for (j = i + 1; j <= n; j++) {
y = d[j];
cnt += x * y;
// cout << "takoyaki_" << j << ": " << y << endl;
// cout << "x * y: " << x * y << endl;
// cout << "cnt: " << cnt << endl;
}
}
cout << cnt;
}
int main() {
while (true) {
// func140b();
// func141b();
// func142b();
func143b();
// func144b();
// func145b();
// func146b();
// func147b();
// func148b();
// func149b();
// func150b();
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
void func143b() {
int n, d[50] = {};
int i, j, x, y, cnt = 0;
cin >> n;
for (i = 1; i <= n; i++)
cin >> d[i];
for (i = 1; i < n; i++) {
x = d[i];
// cout << "takoyaki_" << i << ": " << x << endl;
for (j = i + 1; j <= n; j++) {
y = d[j];
cnt += x * y;
// cout << "takoyaki_" << j << ": " << y << endl;
// cout << "x * y: " << x * y << endl;
// cout << "cnt: " << cnt << endl;
}
}
cout << cnt;
}
int main() {
func143b();
return 0;
} | replace | 25 | 38 | 25 | 26 | TLE | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s;
cin >> s;
int count = 0;
int i = 0;
while (i < N - 1) {
count++;
int j = i + 1;
while (j < N) {
if (s.at(i) == s.at(j)) {
j++;
if (j == N - 1) {
break;
}
} else {
break;
}
}
i = j;
}
if (s.at(N - 2) != s.at(N - 1)) {
count++;
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s;
cin >> s;
int count = 0;
int i = 0;
while (i < N - 1) {
count++;
int j = i + 1;
while (j < N) {
if (s.at(i) == s.at(j)) {
j++;
if (j == N - 1) {
break;
}
} else {
break;
}
}
i = j;
}
if (N == 1) {
count = 1;
} else if (s.at(N - 2) != s.at(N - 1)) {
count++;
}
cout << count << endl;
} | replace | 25 | 26 | 25 | 28 | 0 | |
p02887 | C++ | Runtime Error | #include <cstring>
#include <iostream>
using namespace std;
int main() {
int N;
int ans = 1;
char S[10005] = "A";
cin >> N >> S;
for (int i = 0; i < N - 1; ++i) {
if (S[i] != S[i + 1]) {
ans++;
}
}
cout << ans << endl;
} | #include <cstring>
#include <iostream>
using namespace std;
int main() {
int N;
int ans = 1;
char S[100005] = "A";
cin >> N >> S;
for (int i = 0; i < N - 1; ++i) {
if (S[i] != S[i + 1]) {
ans++;
}
}
cout << ans << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02887 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
using namespace std;
char a[20000];
int main() {
int n;
int sum = 0;
scanf("%d", &n);
scanf("%s", a);
for (int i = 0; i <= n - 1; i++) {
int j = i + 1;
if (a[i] != a[j]) {
sum += 1;
}
}
printf("%d\n", sum);
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
char a[200000];
int main() {
int n;
int sum = 0;
scanf("%d", &n);
scanf("%s", a);
for (int i = 0; i <= n - 1; i++) {
int j = i + 1;
if (a[i] != a[j]) {
sum += 1;
}
}
printf("%d\n", sum);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int r = n;
for (int i = 0; i < n - 1; i++) {
if (s.at(i) == s.at(i + 1)) {
r--;
}
}
if (s.at(n - 2) == s.at(n - 1)) {
r--;
}
if (r != 0)
cout << r << endl;
else
cout << 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int r = n;
for (int i = 0; i < n - 1; i++) {
if (s.at(i) == s.at(i + 1)) {
r--;
}
}
cout << r << endl;
} | replace | 13 | 20 | 13 | 14 | 0 | |
p02887 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define allr(s) s.rbegin(), s.rend()
#define RT(s) return cout << s, 0
#define watch(x) cout << (#x) << " = " << x << endl
#define sz(s) (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#else
// freopen("street.in", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int main() {
file();
fast();
int n;
cin >> n;
int ans = 0;
string str;
cin >> str;
for (int i = 0; i < n; i++) {
int j = i;
while (j < n && str[j] == str[i])
j++;
i = j - 1;
ans++;
}
cout << ans << endl;
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define allr(s) s.rbegin(), s.rend()
#define RT(s) return cout << s, 0
#define watch(x) cout << (#x) << " = " << x << endl
#define sz(s) (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#else
// freopen("street.in", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int main() {
// file();
fast();
int n;
cin >> n;
int ans = 0;
string str;
cin >> str;
for (int i = 0; i < n; i++) {
int j = i;
while (j < n && str[j] == str[i])
j++;
i = j - 1;
ans++;
}
cout << ans << endl;
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
int count = 0;
cin >> n;
char ar[100];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < n; i++) {
if (ar[i] == ar[i + 1]) {
continue;
}
count++;
}
cout << count;
}
| #include <iostream>
using namespace std;
int main() {
int n;
int count = 0;
cin >> n;
char ar[100000];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < n; i++) {
if (ar[i] == ar[i + 1]) {
continue;
}
count++;
}
cout << count;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02887 | C++ | Runtime Error | #include <iostream>
int main() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
int index = 1;
while (s.size() - 1 != index) {
if (s.at(index - 1) == s.at(index)) {
s.erase(index, 1);
--index;
}
++index;
}
std::cout << s.size() << std::endl;
return 0;
} | #include <iostream>
int main() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
int index = 1;
while (s.size() != index) {
if (s.at(index - 1) == s.at(index)) {
s.erase(index, 1);
--index;
}
++index;
}
std::cout << s.size() << std::endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, ans;
ans = 1;
string S;
cin >> N, S;
for (int i = 0; i < N - 1; i++) {
if (S.at(i) != S.at(i + 1)) {
ans++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, ans;
ans = 1;
string S;
cin >> N >> S;
for (int i = 0; i < N - 1; i++) {
if (S.at(i) != S.at(i + 1)) {
ans++;
}
}
cout << ans << endl;
}
| replace | 8 | 9 | 8 | 9 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
char ch[20001];
int n, ans = 1;
cin >> n;
cin >> ch;
for (int i = 1; i < n; ++i) {
if (ch[i] != ch[i - 1])
++ans;
}
cout << ans;
} | #include <iostream>
using namespace std;
int main() {
char ch[200001];
int n, ans = 1;
cin >> n;
cin >> ch;
for (int i = 1; i < n; ++i) {
if (ch[i] != ch[i - 1])
++ans;
}
cout << ans;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
string V;
for (int j = 0; j < N; j++) {
for (int i = 0; i < S.size(); i++) {
V += S[i];
if (S[i] == S[i + 1]) {
i++;
}
}
S = V;
V = "";
}
size_t size = S.size();
cout << size << endl;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
string V;
for (int j = 0; j < N; j++) {
for (int i = 0; i < S.size(); i++) {
V += S[i];
if (S[i] == S[i + 1]) {
i++;
}
}
if (S.size() == V.size()) {
break;
}
S = V;
V = "";
}
size_t size = S.size();
cout << size << endl;
} | insert | 20 | 20 | 20 | 23 | TLE | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int n;
char a[1001];
int main() {
int d = 1;
int res = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] != a[d]) {
res++;
d = i;
}
}
cout << res;
} | #include <iostream>
using namespace std;
int n;
char a[100001];
int main() {
int d = 1;
int res = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] != a[d]) {
res++;
d = i;
}
}
cout << res;
} | replace | 3 | 4 | 3 | 4 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.