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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';
#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _
// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)
// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")
ll x(ll a) {
if (a % 4 == 0)
return a;
if (a % 4 == 1)
return 1;
if (a % 4 == 2)
return a + 1;
return 0;
}
signed main() {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<ll> as(x), bs(y), cs(z);
rep(i, x) cin >> as[i];
rep(i, y) cin >> bs[i];
rep(i, z) cin >> cs[i];
sort(be(as), greater<ll>());
sort(be(bs), greater<ll>());
sort(be(cs), greater<ll>());
vector<ll> ans;
rep(i, x) {
rep(j, y) {
rep(k, z) {
if (i + j + k > K)
break;
ans.push_back(as[i] + bs[j] + cs[k]);
}
}
}
sort(be(ans), greater<ll>());
ans.resize(K);
for (auto e : ans) {
cout << e << nl;
}
}
| #include <bits/stdc++.h>
using namespace std;
// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';
#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _
// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)
// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")
ll x(ll a) {
if (a % 4 == 0)
return a;
if (a % 4 == 1)
return 1;
if (a % 4 == 2)
return a + 1;
return 0;
}
signed main() {
int x, y, z, K;
cin >> x >> y >> z >> K;
vector<ll> as(x), bs(y), cs(z);
rep(i, x) cin >> as[i];
rep(i, y) cin >> bs[i];
rep(i, z) cin >> cs[i];
sort(be(as), greater<ll>());
sort(be(bs), greater<ll>());
sort(be(cs), greater<ll>());
vector<ll> ans;
rep(i, x) {
rep(j, y) {
rep(k, z) {
if ((i + 1) * (j + 1) * (k + 1) > K)
break;
ans.push_back(as[i] + bs[j] + cs[k]);
}
}
}
sort(be(ans), greater<ll>());
ans.resize(K);
for (auto e : ans) {
cout << e << nl;
}
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p03078 | C++ | Runtime Error | #pragma region _head
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#pragma region _define
#define int LL
#define f(i, a, b) for (LL i = a; i < b; i++)
#define f_vI(v, n) f(i, 0, n) cin >> v[i]
#define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i]
#define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i]
#define f_vO(v, n) f(i, 0, n) cout << v[i] << endl
#define ei else if
#define all(a) a.begin(), a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout << "! ! !"
#define endl "\n"
#define _y() cout << "Yes" << endl
#define _Y() cout << "YES" << endl
#define _n() cout << "No" << endl
#define _N() cout << "NO" << endl
#define int_INF 1 << 29
#define ll_INF 1LL << 60
#define MOD 1000000007
#pragma endregion
#pragma region _using
using namespace std;
using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
#pragma endregion
#pragma region _graph
#define node 50 // グラフの最大位数 適宜変更
// bool graph[node][node]; bool visited[node] = { false };
#define link(a, b, m) \
f(i, 0, m) { \
cin >> a[i] >> b[i]; \
a[i]--; \
b[i]--; \
graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; \
}
#pragma endregion
void _yn(bool p) { p ? _y() : _n(); }
void _YN(bool p) { p ? _Y() : _N(); }
LL gcd(LL a, LL b) {
LL r;
while ((r = a % b) != 0) {
a = b;
b = r;
}
return b;
}
LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); }
// 素数判定
bool is_prime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
// 階乗計算
LL factorial(LL n) {
LL a = 1, ret = 1;
while (a < n) {
a++;
ret *= a;
ret %= MOD;
}
return ret;
}
#pragma endregion
/*****************************************************************************/
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vi a(x), b(y), c(z);
f_vI(a, x);
f_vI(b, y);
f_vI(c, z);
sort(all(a), greater<int>());
sort(all(b), greater<int>());
sort(all(c), greater<int>());
vi ans;
f(i, 0, x) {
f(j, 0, y) {
f(o, 0, z) { ans.push_back(a[i] + b[j] + c[o]); }
}
}
sort(all(ans), greater<int>());
f(i, 0, k) { cout << ans[i] << endl; }
return 0;
} | #pragma region _head
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#pragma region _define
#define int LL
#define f(i, a, b) for (LL i = a; i < b; i++)
#define f_vI(v, n) f(i, 0, n) cin >> v[i]
#define f_v2I(v1, v2, n) f(i, 0, n) cin >> v1[i] >> v2[i]
#define f_v3I(v1, v2, v3, n) f(i, 0, n) cin >> v1[i] >> v2[i] >> v3[i]
#define f_vO(v, n) f(i, 0, n) cout << v[i] << endl
#define ei else if
#define all(a) a.begin(), a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout << "! ! !"
#define endl "\n"
#define _y() cout << "Yes" << endl
#define _Y() cout << "YES" << endl
#define _n() cout << "No" << endl
#define _N() cout << "NO" << endl
#define int_INF 1 << 29
#define ll_INF 1LL << 60
#define MOD 1000000007
#pragma endregion
#pragma region _using
using namespace std;
using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;
#pragma endregion
#pragma region _graph
#define node 50 // グラフの最大位数 適宜変更
// bool graph[node][node]; bool visited[node] = { false };
#define link(a, b, m) \
f(i, 0, m) { \
cin >> a[i] >> b[i]; \
a[i]--; \
b[i]--; \
graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; \
}
#pragma endregion
void _yn(bool p) { p ? _y() : _n(); }
void _YN(bool p) { p ? _Y() : _N(); }
LL gcd(LL a, LL b) {
LL r;
while ((r = a % b) != 0) {
a = b;
b = r;
}
return b;
}
LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); }
// 素数判定
bool is_prime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
// 階乗計算
LL factorial(LL n) {
LL a = 1, ret = 1;
while (a < n) {
a++;
ret *= a;
ret %= MOD;
}
return ret;
}
#pragma endregion
/*****************************************************************************/
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vi a(x), b(y), c(z);
f_vI(a, x);
f_vI(b, y);
f_vI(c, z);
sort(all(a), greater<int>());
sort(all(b), greater<int>());
sort(all(c), greater<int>());
vi ans;
f(i, 0, x) {
f(j, 0, y) {
f(o, 0, z) {
if ((i + 1) * (j + 1) * (o + 1) <= k) {
ans.push_back(a[i] + b[j] + c[o]);
}
}
}
}
sort(all(ans), greater<int>());
f(i, 0, k) { cout << ans[i] << endl; }
return 0;
} | replace | 137 | 138 | 137 | 142 | 0 | |
p03078 | Python | Time Limit Exceeded | import sys
input = sys.stdin.readline
X, Y, Z, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
ablst = [m + n for n in b for m in a]
ablst.sort(reverse=True)
c.sort(reverse=True)
abclst = [m + n for n in c[:K] for m in ablst[:K]]
abclst.sort(reverse=True)
print(*abclst[:K], sep="\n")
| import sys
input = sys.stdin.readline
X, Y, Z, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
ablst = [m + n for n in b for m in a]
ablst.sort(reverse=True)
c.sort(reverse=True)
abclst = [m + n for n in c[:K] for m in ablst[:K]]
abclst.sort(reverse=True)
print(*abclst[:K], sep="\n")
| insert | 8 | 8 | 8 | 11 | TLE | |
p03078 | Python | Time Limit Exceeded | import itertools
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB = sorted(AB)[::-1]
ans = [ab + c for (ab, c) in list(itertools.product(AB[:3000], C))]
ans = sorted(ans)[::-1]
for i in range(K):
print(ans[i])
| import itertools
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = [a + b for (a, b) in list(itertools.product(A, B))]
AB.sort(reverse=True)
ans = [ab + c for (ab, c) in list(itertools.product(AB[: min(3000, X * Y * Z)], C))]
ans.sort(reverse=True)
for i in range(K):
print(ans[i])
| replace | 9 | 12 | 9 | 12 | TLE | |
p03078 | Python | Time Limit Exceeded | from itertools import product, chain
x, y, z, k = list(map(int, input().split(" ")))
a = sorted(list(map(int, input().split(" "))))
b = sorted(list(map(int, input().split(" "))))
c = sorted(list(map(int, input().split(" "))))
apb_sorted = sorted([a + b for a, b in product(a, b)])
ans_list = sorted(
list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]]))
)
it = reversed(ans_list)
for _ in range(k):
print(next(it))
| from itertools import product, chain
x, y, z, k = list(map(int, input().split(" ")))
a = sorted(list(map(int, input().split(" "))))
b = sorted(list(map(int, input().split(" "))))
c = sorted(list(map(int, input().split(" "))))
apb_sorted = sorted([a + b for a, b in product(a, b)])[-k:]
ans_list = sorted(
list(chain.from_iterable([[_c + ab for ab in apb_sorted] for _c in c[:k]]))
)
it = reversed(ans_list)
for _ in range(k):
print(next(it))
| replace | 7 | 8 | 7 | 8 | TLE | |
p03078 | Python | Time Limit Exceeded | from itertools import product
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
p = [i + k for i, k in product(a, b)]
p.sort(reverse=True)
q = [i + k for i, k in product(p[:k], c)]
q.sort(reverse=True)
print("\n".join(map(str, q[:k])))
| from itertools import product
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
p = [i + k for i, k in product(a, b)]
p.sort(reverse=True)
q = [i + k for i, k in product(p[:k], c)]
q.sort(reverse=True)
print("\n".join(map(str, q[:k])))
| delete | 11 | 12 | 11 | 11 | TLE | |
p03078 | Python | Runtime Error | x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = []
for i in range(x):
for j in range(y):
d.append(a[i] + b[j])
d.sort(reverse=True)
e = []
for i in range(k):
for j in range(z):
e.append(d[i] + c[j])
e.sort(reverse=True)
for i in range(k):
print(e[i])
| x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = []
for i in range(x):
for j in range(y):
d.append(a[i] + b[j])
d.sort(reverse=True)
e = []
for i in range(min(len(d), k)):
for j in range(z):
e.append(d[i] + c[j])
e.sort(reverse=True)
for i in range(k):
print(e[i])
| replace | 12 | 13 | 12 | 13 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03078/Python/s896173078.py", line 15, in <module>
e.append(d[i] + c[j])
IndexError: list index out of range
|
p03078 | Python | Time Limit Exceeded | x, y, z, k = map(int, input().split())
a = map(int, input().split())
b = list(map(int, input().split()))
c = map(int, input().split())
d = sorted((ai + bi for ai in a for bi in b), reverse=True)[:k]
e = sorted((ci + di for ci in c for di in d), reverse=True)
i = 0
while i != k:
print(e[i])
i += 1
| x, y, z, k = map(int, input().split())
a = map(int, input().split())
b = list(map(int, input().split()))
c = map(int, input().split())
d = sorted((ai + bi for ai in a for bi in b), reverse=True)[:k]
e = sorted((ci + di for ci in c for di in d), reverse=True)[:k]
print(*e)
| replace | 5 | 10 | 5 | 7 | TLE | |
p03078 | Python | Time Limit Exceeded | def main():
import sys
input = sys.stdin.readline
x, y, z, k = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
ret = sorted(
(
a + b + c
for p, a in enumerate(A)
for q, b in enumerate(B)
for r, c in enumerate(C)
if p * q * r <= k
),
reverse=True,
)[:k]
print(*ret, sep="\n")
main()
# O(Klog^3K)
# https://img.atcoder.jp/abc123/editorial.pdf
| def main():
import sys
input = sys.stdin.readline
x, y, z, k = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)
ret = []
for p, a in enumerate(A):
for q, b in enumerate(B):
if p * q > k:
break
for r, c in enumerate(C):
if p * q * r > k:
break
ret.append(a + b + c)
ret.sort(reverse=True)
print(*ret[:k], sep="\n")
main()
# O(Klog^3K)
# https://img.atcoder.jp/abc123/editorial.pdf
| replace | 10 | 22 | 10 | 21 | TLE | |
p03078 | Python | Time Limit Exceeded | X, Y, Z, K = [int(i) for i in input().split()]
ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)]
ABSum = sorted([i + j for i in ABCList[0] for j in ABCList[1]], reverse=True)[:K]
for ans in sorted([i + j for i in ABSum for j in ABCList[2]], reverse=True)[:K]:
print(ans)
| X, Y, Z, K = [int(i) for i in input().split()]
ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)]
ansList = []
for i, A in enumerate(ABCList[0]):
for j, B in enumerate(ABCList[1]):
for k, C in enumerate(ABCList[2]):
if (i + 1) * (j + 1) * (k + 1) <= K:
ansList.append(A + B + C)
else:
break
for ans in sorted(ansList, reverse=True)[:K]:
print(ans)
| replace | 3 | 5 | 3 | 13 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int X, Y, Z, K;
vector<long long> A(1001, 0);
vector<long long> B(1001, 0);
vector<long long> C(1001, 0);
vector<long long> ret;
vector<long long> ret2;
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(A.begin(), A.end(), greater<long long>());
sort(B.begin(), B.end(), greater<long long>());
sort(C.begin(), C.end(), greater<long long>());
for (int a = 0; a < X; a++) {
for (int b = 0; b < Y; b++) {
ret.push_back(A[a] + B[b]);
}
}
sort(ret.begin(), ret.end(), greater<long long>());
for (int k = 0; k < X * Y; k++) {
for (int c = 0; c < Z; c++) {
ret2.push_back(ret[k] + C[c]);
}
}
sort(ret2.begin(), ret2.end(), greater<long long>());
for (int i = 0; i < K; i++) {
cout << ret2[i] << endl;
}
} | #include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int X, Y, Z, K;
vector<long long> A(1001, 0);
vector<long long> B(1001, 0);
vector<long long> C(1001, 0);
vector<long long> ret;
vector<long long> ret2;
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(A.begin(), A.end(), greater<long long>());
sort(B.begin(), B.end(), greater<long long>());
sort(C.begin(), C.end(), greater<long long>());
for (int a = 0; a < X; a++) {
for (int b = 0; b < Y; b++) {
ret.push_back(A[a] + B[b]);
}
}
sort(ret.begin(), ret.end(), greater<long long>());
for (int k = 0; k < min(K, X * Y); k++) {
for (int c = 0; c < Z; c++) {
ret2.push_back(ret[k] + C[c]);
}
}
sort(ret2.begin(), ret2.end(), greater<long long>());
for (int i = 0; i < K; i++) {
cout << ret2[i] << endl;
}
} | replace | 35 | 36 | 35 | 36 | TLE | |
p03078 | Python | Time Limit Exceeded | X, Y, Z, K = map(int, input().split())
(*A,) = sorted(map(int, input().split()), reverse=True)
(*B,) = sorted(map(int, input().split()), reverse=True)
(*C,) = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [AB[xy] + C[z] for xy in range(XY) for z in range(Z)]
ABC.sort(reverse=True)
for k in range(K):
print(ABC[k])
| X, Y, Z, K = map(int, input().split())
(*A,) = sorted(map(int, input().split()), reverse=True)
(*B,) = sorted(map(int, input().split()), reverse=True)
(*C,) = sorted(map(int, input().split()), reverse=True)
AB = [A[x] + B[y] for y in range(Y) for x in range(X)]
AB.sort(reverse=True)
AB = AB[:K]
XY = len(AB)
ABC = [AB[xy] + C[z] for z in range(Z) for xy in range(XY)]
ABC.sort(reverse=True)
for k in range(K):
print(ABC[k])
| replace | 8 | 9 | 8 | 9 | TLE | |
p03078 | Python | Time Limit Exceeded | x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
goukei = []
for i in range(x):
for j in range(y):
goukei.append(A[i] + B[j])
goukei.sort()
goukei2 = goukei[-k:]
goukei3 = []
for c in C:
for ab in goukei2:
goukei3.append(ab + c)
goukei3.sort(reverse=True)
print(*goukei3[:k], sep="\n")
| x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
goukei = []
for a in A:
for b in B:
goukei.append(a + b)
goukei.sort()
goukei2 = goukei[-k:]
goukei3 = []
for c in C:
for ab in goukei2:
goukei3.append(ab + c)
goukei3.sort(reverse=True)
print(*goukei3[:k], sep="\n")
| replace | 5 | 8 | 5 | 8 | TLE | |
p03078 | Python | Runtime Error | x, y, z, k = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
AB = []
for a in A:
for b in B:
AB.append(a + b)
AB.sort(reverse=True)
ABC = []
for i in range(min(a * b, k)):
for c in C:
ABC.append(AB[i] + c)
ABC.sort(reverse=True)
for i in range(k):
print(ABC[i])
| x, y, z, k = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
AB = []
for a in A:
for b in B:
AB.append(a + b)
AB.sort(reverse=True)
ABC = []
for i in range(min(x * y, k)):
for c in C:
ABC.append(AB[i] + c)
ABC.sort(reverse=True)
for i in range(k):
print(ABC[i])
| replace | 13 | 14 | 13 | 14 | 0 | |
p03078 | Python | Time Limit Exceeded | x, y, z, k = map(int, input().split())
a_array = sorted([int(x) for x in input().split()], reverse=True)
b_array = sorted([int(x) for x in input().split()], reverse=True)
c_array = sorted([int(x) for x in input().split()], reverse=True)
def solver1():
ab_array = [x + y for x in a_array for y in b_array]
abc_array = sorted([ab + c for ab in ab_array for c in c_array], reverse=True)
for abc in abc_array[:k]:
print(abc)
solver1()
| x, y, z, k = map(int, input().split())
a_array = sorted([int(x) for x in input().split()], reverse=True)
b_array = sorted([int(x) for x in input().split()], reverse=True)
c_array = sorted([int(x) for x in input().split()], reverse=True)
def solver1():
ab_array = sorted([x + y for x in a_array for y in b_array], reverse=True)[:3000]
abc_array = sorted([ab + c for ab in ab_array for c in c_array], reverse=True)
for abc in abc_array[:k]:
print(abc)
solver1()
| replace | 7 | 8 | 7 | 8 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define INF 1000000000000000000
#define MOD 10007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X), B(Y), C(Z);
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(rrng(A));
sort(rrng(B));
sort(rrng(C));
vector<ll> AB;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(rrng(AB));
vector<ll> ABC;
for (int i = 0; i < Z; i++) {
for (int j = 0; j < K && j < ABC.size(); j++) {
ABC.push_back(AB[j] + C[i]);
}
}
sort(rrng(ABC));
for (int i = 0; i < K; i++)
cout << ABC[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define INF 1000000000000000000
#define MOD 10007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X), B(Y), C(Z);
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(rrng(A));
sort(rrng(B));
sort(rrng(C));
vector<ll> AB;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(rrng(AB));
vector<ll> ABC;
for (int i = 0; i < Z; i++) {
for (int j = 0; j < K && j < AB.size(); j++) {
ABC.push_back(AB[j] + C[i]);
}
}
sort(rrng(ABC));
for (int i = 0; i < K; i++)
cout << ABC[i] << endl;
return 0;
}
| replace | 35 | 36 | 35 | 36 | -11 | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
using namespace std;
int count_upper(uint64_t v, vector<uint64_t> &as, vector<uint64_t> &bs,
vector<uint64_t> &cs, int x, int y, int z, int k) {
int count = 0;
multiset<uint64_t> vals;
FOR_LT(a, 0, x) {
if (v <= as[a]) {
count += y * z;
continue;
}
FOR_LT(b, 0, y) {
if (v <= as[a] + bs[b]) {
count += z;
continue;
}
FOR_LT(c, 0, z) {
if (as[a] + bs[b] + cs[c] < v)
break;
count++;
if (k < count)
return count;
}
}
}
return count;
}
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<uint64_t> as(x);
vector<uint64_t> bs(y);
vector<uint64_t> cs(z);
for (auto &a : as) {
cin >> a;
}
for (auto &b : bs) {
cin >> b;
}
for (auto &c : cs) {
cin >> c;
}
sort(as.begin(), as.end(), greater<uint64_t>());
sort(bs.begin(), bs.end(), greater<uint64_t>());
sort(cs.begin(), cs.end(), greater<uint64_t>());
uint64_t h = as.front() + bs.front() + cs.front();
uint64_t l = as.back() + bs.back() + cs.back();
uint64_t h_n = 1;
uint64_t l_n = x * y * z;
while (true) {
if (l == h)
break;
uint64_t m = (h + l) / 2;
int count = count_upper(m, as, bs, cs, x, y, z, k);
if (count == k) {
h = l = m;
} else if (count < k) {
h = max(m - 1, l);
} else {
l = m;
}
}
vector<uint64_t> vals;
FOR_LT(a, 0, x) {
FOR_LT(b, 0, y) {
FOR_LT(c, 0, z) {
if (as[a] + bs[b] + cs[c] < l)
break;
vals.push_back(as[a] + bs[b] + cs[c]);
}
}
}
sort(vals.begin(), vals.end());
int count = 0;
for (auto it = vals.rbegin(); it != vals.rend(); it++) {
cout << *it << endl;
count++;
if (count == k)
break;
}
return 0;
} | #include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
using namespace std;
int count_upper(uint64_t v, vector<uint64_t> &as, vector<uint64_t> &bs,
vector<uint64_t> &cs, int x, int y, int z, int k) {
int count = 0;
multiset<uint64_t> vals;
FOR_LT(a, 0, x) {
if (v <= as[a]) {
count += y * z;
continue;
}
FOR_LT(b, 0, y) {
if (v <= as[a] + bs[b]) {
count += z;
continue;
}
FOR_LT(c, 0, z) {
if (as[a] + bs[b] + cs[c] < v)
break;
count++;
if (k < count)
return count;
}
}
}
return count;
}
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<uint64_t> as(x);
vector<uint64_t> bs(y);
vector<uint64_t> cs(z);
for (auto &a : as) {
cin >> a;
}
for (auto &b : bs) {
cin >> b;
}
for (auto &c : cs) {
cin >> c;
}
sort(as.begin(), as.end(), greater<uint64_t>());
sort(bs.begin(), bs.end(), greater<uint64_t>());
sort(cs.begin(), cs.end(), greater<uint64_t>());
uint64_t h = as.front() + bs.front() + cs.front();
uint64_t l = as.back() + bs.back() + cs.back();
uint64_t h_n = 1;
uint64_t l_n = x * y * z;
while (true) {
if (l == h)
break;
uint64_t m = (h + l) / 2;
int count = count_upper(m, as, bs, cs, x, y, z, k);
if (count == k) {
h = l = m;
} else if (count < k) {
h = max(m - 1, l);
} else {
l = m;
if (h - l == 1) {
h = l;
break;
}
}
}
vector<uint64_t> vals;
FOR_LT(a, 0, x) {
FOR_LT(b, 0, y) {
FOR_LT(c, 0, z) {
if (as[a] + bs[b] + cs[c] < l)
break;
vals.push_back(as[a] + bs[b] + cs[c]);
}
}
}
sort(vals.begin(), vals.end());
int count = 0;
for (auto it = vals.rbegin(); it != vals.rend(); it++) {
cout << *it << endl;
count++;
if (count == k)
break;
}
return 0;
} | insert | 97 | 97 | 97 | 101 | TLE | |
p03078 | Python | Time Limit Exceeded | import heapq
def heappush_max(heap, item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap) - 1)
def heappop_max(heap):
lastelt = heap.pop()
if heap:
return_item = heap[0]
heap[0] = lastelt
heapq._siftup_max(heap, 0)
return return_item
return lastelt
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
ans = []
heap_queue = []
for i in range(X):
for j in range(Y):
for k in range(Z):
heappush_max(heap_queue, A[i] + B[j] + C[k])
for k in range(K):
print(heappop_max(heap_queue))
| import heapq
def heappush_max(heap, item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap) - 1)
def heappop_max(heap):
lastelt = heap.pop()
if heap:
return_item = heap[0]
heap[0] = lastelt
heapq._siftup_max(heap, 0)
return return_item
return lastelt
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
ans = []
heap_queue = [(A[0] + B[0] + C[0], 0, 0, 0)]
arg_hash = {}
for i in range(K):
maxim, a, b, c = heappop_max(heap_queue)
print(maxim)
arg_a = (a + 1, b, c)
arg_b = (a, b + 1, c)
arg_c = (a, b, c + 1)
if a + 1 < X and arg_a not in arg_hash:
heappush_max(heap_queue, (A[a + 1] + B[b] + C[c], a + 1, b, c))
arg_hash[arg_a] = 1
if b + 1 < Y and arg_b not in arg_hash:
heappush_max(heap_queue, (A[a] + B[b + 1] + C[c], a, b + 1, c))
arg_hash[arg_b] = 1
if c + 1 < Z and arg_c not in arg_hash:
heappush_max(heap_queue, (A[a] + B[b] + C[c + 1], a, b, c + 1))
arg_hash[arg_c] = 1
| replace | 23 | 30 | 23 | 42 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
os << "{";
rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> T dup(T x, T y) { return (x + y - 1) / y; };
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
struct in {
const size_t n = 0;
in() = default;
in(size_t n) : n(n){};
template <typename T> operator T() {
T ret;
cin >> ret;
return ret;
}
template <typename T> operator vector<T>() {
assert(n != 0);
vector<T> ret(n);
for (auto &x : ret)
cin >> x;
return ret;
}
};
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;
constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;
void Main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
vll a = in(x), b = in(y), c = in(z);
vll ab;
rep(i, x) rep(j, y) { ab.pb(a[i] + b[j]); }
sort(ALL(ab), greater<ll>());
vll ab2;
rep(i, min(ab.size(), (size_t)k)) { ab2.pb(ab[i]); }
vll abc;
rep(i, ab.size()) rep(j, z) { abc.pb(ab[i] + c[j]); }
sort(ALL(abc), greater<ll>());
rep(i, k) { cout << abc[i] << endl; }
}
signed main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
os << "{";
rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> T dup(T x, T y) { return (x + y - 1) / y; };
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
struct in {
const size_t n = 0;
in() = default;
in(size_t n) : n(n){};
template <typename T> operator T() {
T ret;
cin >> ret;
return ret;
}
template <typename T> operator vector<T>() {
assert(n != 0);
vector<T> ret(n);
for (auto &x : ret)
cin >> x;
return ret;
}
};
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;
constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;
void Main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
vll a = in(x), b = in(y), c = in(z);
vll ab;
rep(i, x) rep(j, y) { ab.pb(a[i] + b[j]); }
sort(ALL(ab), greater<ll>());
vll ab2;
rep(i, min(ab.size(), (size_t)k)) { ab2.pb(ab[i]); }
vll abc;
rep(i, ab2.size()) rep(j, z) { abc.pb(ab2[i] + c[j]); }
sort(ALL(abc), greater<ll>());
rep(i, k) { cout << abc[i] << endl; }
}
signed main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| replace | 86 | 87 | 86 | 87 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#define ASC(vec) vec.begin(), vec.end() // 昇順ソート 例:sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin >> vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;
const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vii = vector<pair<int, int>>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }
// 4,8方向に探索する際に用いる配列
// int dx[4] = { 0, 0, 1, -1 };
// int dy[4] = { 1, -1, 0, 0 };
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr auto MAX = 100010;
// ────────────────────────────────────────────────────
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vl a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
priority_queue<ll> ans;
vector<ll> tmp;
rep(i, x) {
rep(j, y) { tmp.push_back(a[i] + b[j]); }
}
rep(i, x * y) {
rep(j, z) { ans.push(tmp[i] + c[j]); }
}
rep(i, k) {
ll hoge = ans.top();
ans.pop();
cout << hoge << endl;
}
} | #include "bits/stdc++.h"
using namespace std;
#define ASC(vec) vec.begin(), vec.end() // 昇順ソート 例:sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin >> vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;
const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vii = vector<pair<int, int>>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }
// 4,8方向に探索する際に用いる配列
// int dx[4] = { 0, 0, 1, -1 };
// int dy[4] = { 1, -1, 0, 0 };
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr auto MAX = 100010;
// ────────────────────────────────────────────────────
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vl a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
priority_queue<ll> ans;
vector<ll> tmp;
rep(i, x) {
rep(j, y) { tmp.push_back(a[i] + b[j]); }
}
if (tmp.size() > k) {
sort(DESC(tmp));
tmp.resize(k);
}
rep(i, tmp.size()) {
rep(j, z) { ans.push(tmp[i] + c[j]); }
}
rep(i, k) {
ll hoge = ans.top();
ans.pop();
cout << hoge << endl;
}
} | replace | 68 | 69 | 68 | 74 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define cs \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
using namespace std;
int main() {
cs;
int x, y, z, K, t = 0;
cin >> x >> y >> z >> K;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
vector<ll> ans(100000);
rep(i, x) {
rep(j, y) {
rep(k, z) {
if ((i + 1) * (j + 1) * (k + 1) <= K) {
ans[t] = a[i] + b[j] + c[k];
t++;
}
}
}
}
sort(ans.begin(), ans.begin() + t, greater<>());
rep(i, K) cout << ans[i] << '\n';
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define cs \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
using namespace std;
int main() {
cs;
int x, y, z, K, t = 0;
cin >> x >> y >> z >> K;
vector<ll> a(x);
vector<ll> b(y);
vector<ll> c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
vector<ll> ans(1000000);
rep(i, x) {
rep(j, y) {
rep(k, z) {
if ((i + 1) * (j + 1) * (k + 1) <= K) {
ans[t] = a[i] + b[j] + c[k];
t++;
}
}
}
}
sort(ans.begin(), ans.begin() + t, greater<>());
rep(i, K) cout << ans[i] << '\n';
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #include <mylib.h>
using namespace std;
// cin.sync_with_stdio(false);
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR_EQ(i, a, b) for (ll i = (a); i <= (b); ++i)
#define FOR_RE(i, a, b) \
for ( \
ll i = (a); i >= (b); \
--i) // 終端を0じゃなくて、1まですることによってn回。感覚的に1以上にしておいた。
#define rep(i, n) FOR(i, 0, n)
#define rep_eq(i, n) FOR_EQ(i, 0, n)
#define rep_re(i, n) FOR_RE(i, n, 0)
#define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl
#define INFTY (1 << 21) // 10^21
#define INF (1 << 9)
#define WHITE 1 // (未訪問)
#define GRAY \
2 // (訪問)未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3 // (訪問完了)未訪問への頂点への辺を持たない
#define MAX 100000
#define N 100
int M[N][N]; // 隣接行列(頂点と頂点が繋がってる、もしくは重みの値)
int color[N]; // その頂点の探索具合
const int TABLEMAX = 510000;
const int MOD = 1000000007;
// 二項係数用の各階乗の値とその逆元を記録するための配列.
long long fac[TABLEMAX], finv[TABLEMAX], inv[TABLEMAX];
// 1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// 上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef vector<pair<ll, ll>> Vec_Pair;
// 関数prime_factorizationで使う。
// 因数分解で使う。firstは数。secondは指数。
vector<pair<ll, ll>> prime_factor;
// 関数get_factor_listで使う。因数の一覧を取得で使う。
Vector factor_list;
// 2つともエラトステネスの篩で使う。
vector<bool> prime; // 素数かどうか判定。
Vector prime_num; // 素数を記録。
ll n;
template <class X> void printArray(X *array, ll);
template <class X> void printVector(vector<X> &v);
template <class X> void printDimention(vector<vector<X>> &dv);
template <class X> void printMap(X);
template <class X> void printVecPair(vector<X> &v);
// 何個2がかかっているか
ll factor2(ll);
// nCr方式で組み合わせの数を求める
ll combination(int, int);
// nPrで階乗を求める
int factorial(int, int);
// 桁数を返す
int find_digits(int);
// 各桁の和を計算する関数
int findSumOfDigits(int);
// 次数を得る
int degree(int);
// 四捨五入
int shishagonyu(double);
// 切り上げ
int roundUp(double);
// 切り捨て
int roundDown(double);
// 四捨五入
int roundOff(double);
// 最大公約数(Greatest Common Divisor)
ll gcd(ll, ll);
// 最小公倍数(Least Common Multiple)
ll lcm(ll, ll);
// 素因数分解
void prime_factorization(ll);
// エラトステネスの篩
void Eratosthenes(int);
// 偶奇判定。奇数ならtrue。
bool odd_even(int);
// aのmod mにおける逆元を計算する
long long modinv(long long, long long);
// a^n mod を計算する(二分累乗)
long long modpow(long long, long long, long long);
// テーブルを作る前処理
void COMinit();
// 二項係数計算 nCk, 1 <= k <= n <= 10^7
long long COM(int, int);
// longlong型で絶対値を帰す。
long long abs_ll(ll);
// 割り算した時に余りが有る時だけ、+1の商を返す。
long long div_one(ll, ll);
// Stringの各桁をvectorの配列に入れる。でかい桁が添字0。
template <class X> void StringtoVec(string, vector<X> &v);
// 因数の一覧を取得する
void get_factor_list(ll);
int main(int argc, char const *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
ll x, y, z, k;
cin >> x >> y >> z >> k;
ull a[x], b[y], c[z];
rep(i, x) { cin >> a[i]; }
rep(i, y) { cin >> b[i]; }
rep(i, z) { cin >> c[i]; }
vector<ull> ab;
rep(i, x) {
rep(j, y) { ab.push_back(a[i] + b[j]); }
}
sort(ab.begin(), ab.end());
reverse(ab.begin(), ab.end());
vector<ull> abc;
rep(i, x * y) {
rep(j, z) { abc.push_back(ab[i] + c[j]); }
}
sort(abc.begin(), abc.end());
reverse(abc.begin(), abc.end());
rep(i, k) { cout << abc[i] << endl; }
return 0;
}
template <class X> void printArray(X array[], ll n) {
rep(i, n) {
if (i)
cout << " ";
cout << array[i];
}
cout << endl;
}
template <class X> void printVector(vector<X> &v) {
rep(i, (int)v.size()) {
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
}
// 二次元配列の表示
template <class X> void printDimention(vector<vector<X>> &dv) {
rep(i, (ll)dv.size()) {
rep(j, (ll)dv[i].size()) {
if (j)
cout << " ";
cout << dv[i][j];
}
cout << endl;
}
}
// mapの表示
template <class X> void printMap(X mp) {
for (auto it : mp) {
cout << it.first << " " << it.second << endl;
}
}
// 内部にpairを内包したvectorの表示
template <class X> void printVecPair(vector<X> &v) {
rep(i, (int)v.size()) { cout << v[i].first << " " << v[i].second << endl; }
cout << endl;
}
// numの中に何個2がかかってるか
ll factor2(ll num) {
int cnt = 0;
while (num % 2 == 0) {
num /= 2;
cnt++;
}
return cnt;
}
// nCr方式で組み合わせの数を求める
ll combination(int n, int r) {
ll up = 1, down = 1;
// 以下2行はお試し
ll half = n / 2;
if (r >= half)
r = n - r;
ll up_tmp = n, down_tmp = r;
if (r == 0)
return 1;
rep(i, r) {
up *= up_tmp;
up_tmp--;
down *= down_tmp;
down_tmp--;
}
return up / down;
}
// nPr方式で階乗を求める
int factorial(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
} else {
int res = 1;
while (r) {
r--;
res *= n;
n--;
}
return res;
}
}
// 桁数を返す
int find_digits(int n) {
int digit = 0;
while (n) {
n /= 10;
digit++;
}
return digit;
}
// 各桁の和を計算する関数
int findSumOfDigits(int n) {
int sum = 0;
while (n > 0) { // n が 0 になるまで
sum += n % 10;
n /= 10;
}
return sum;
}
// 次数を得る
int degree(int n) {
int count = 0;
while (1) {
if (count <= 0)
break;
count /= 2;
count++;
}
return count;
}
// 四捨五入
int shishagonyu(double x) { return (int)(x < 0.0 ? x - 0.5 : x + 0.5); }
// 切り上げ
int roundUp(double n) {
if (n >= 0) {
return (int)n + 1;
} else {
return (int)n - 1;
}
}
// 切り捨て
int roundDown(double n) { return (int)n; }
// 四捨五入
int roundOff(double n) {
double decimal = 0;
decimal = n - (int)n;
if (decimal >= 0.5 || decimal <= -0.5) {
return roundUp(n);
} else {
return roundDown(n);
}
}
// 最大公約数(Greatest Common Divisor)
ll gcd(ll m, ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// ユークリッドの互除法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
// 最小公倍数(Least Common Multiple)
ll lcm(ll m, ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// lcm = m * n / gcd(m, n)
return ((m / gcd(m, n)) * n);
}
// 素因数分解 firstは数。secondは指数。
void prime_factorization(ll n) {
int div = 2, res;
bool flg = false;
if (n < 2) {
cout << "Error" << endl;
return;
}
while (n >= div * div) {
if (n % div == 0) {
res = div;
// resをグローバルな配列に代入すれば記録できる。
if (flg) {
prime_factor[prime_factor.size() - 1].second++;
} else {
prime_factor.push_back(make_pair(0, 1));
prime_factor[prime_factor.size() - 1].first = res;
}
n /= div;
flg = true;
} else {
div++;
flg = false;
}
}
// ラス1の素因数
res = n;
if (prime_factor[prime_factor.size() - 1].first == res) {
prime_factor[prime_factor.size() - 1].second++;
} else {
prime_factor.push_back(make_pair(res, 1));
}
}
// エラトステネスの篩
void Eratosthenes(int n) {
// prime_bool の添え字と見たい数は一致させたいので、
// prime_boolやprime_numは1つ多く宣言すること。
prime[0] = false;
prime[1] = false;
for (int i = 2; i < sqrt(n); i++) {
if (prime[i]) {
for (int j = 0; i * (j + 2) < n; j++) {
prime[i * (j + 2)] = false;
}
}
}
// 素数をprime_numに記録
rep(i, n) {
if (prime[i])
prime_num.push_back(i);
}
/*
int cnt = 0;
for(int i = 2; i < n; i++){
if(prime[i]){
cnt++;
}
}
return cnt;
*/
}
// 偶奇判定。奇数ならtrue。
bool odd_even(int num) {
bool judge;
if (num % 2) {
judge = true;
} else {
judge = false;
}
return judge;
}
// aのmod mにおける逆元を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// main関数内でCOMinitを呼んだ後,COMを呼ぶ.
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < TABLEMAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算 nCk, nCrのcombinationでも使える
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long abs_ll(ll a) {
if (a >= 0) {
return a;
} else {
return -a;
}
}
// 割り算した時に余りが有る時だけ、+1の商を返す。
long long div_one(ll res, ll div) {
// res 割られる数、div 割る数
return (res + div - 1) / div;
}
// Stringの各桁をvectorの配列に入れる。でかい桁が添字0。
template <class X> void StringtoVec(string str, vector<X> &v) {
ll num = stoll(str);
ll it = str.size() - 1;
// 桁を逆にしたい時、下をon
// ll it = 0;
v.resize(str.size());
while (num) {
v[it] = num % 10;
num /= 10;
it--;
// it++;
if (it < 0) {
cout << "reference error" << endl;
break;
}
}
}
// nに数を入れるとその約数の一覧をfactor_listに格納する
void get_factor_list(ll n) {
int div = 1, res;
while (n >= div * div) {
if (n % div == 0) {
res = div;
ll tmp = n / res;
factor_list.push_back(res);
if (tmp != 1)
factor_list.push_back(tmp);
div++;
} else {
div++;
}
}
sort(factor_list.begin(), factor_list.end());
} | #include <bits/stdc++.h>
// #include <mylib.h>
using namespace std;
// cin.sync_with_stdio(false);
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR_EQ(i, a, b) for (ll i = (a); i <= (b); ++i)
#define FOR_RE(i, a, b) \
for ( \
ll i = (a); i >= (b); \
--i) // 終端を0じゃなくて、1まですることによってn回。感覚的に1以上にしておいた。
#define rep(i, n) FOR(i, 0, n)
#define rep_eq(i, n) FOR_EQ(i, 0, n)
#define rep_re(i, n) FOR_RE(i, n, 0)
#define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl
#define INFTY (1 << 21) // 10^21
#define INF (1 << 9)
#define WHITE 1 // (未訪問)
#define GRAY \
2 // (訪問)未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3 // (訪問完了)未訪問への頂点への辺を持たない
#define MAX 100000
#define N 100
int M[N][N]; // 隣接行列(頂点と頂点が繋がってる、もしくは重みの値)
int color[N]; // その頂点の探索具合
const int TABLEMAX = 510000;
const int MOD = 1000000007;
// 二項係数用の各階乗の値とその逆元を記録するための配列.
long long fac[TABLEMAX], finv[TABLEMAX], inv[TABLEMAX];
// 1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// 上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef vector<pair<ll, ll>> Vec_Pair;
// 関数prime_factorizationで使う。
// 因数分解で使う。firstは数。secondは指数。
vector<pair<ll, ll>> prime_factor;
// 関数get_factor_listで使う。因数の一覧を取得で使う。
Vector factor_list;
// 2つともエラトステネスの篩で使う。
vector<bool> prime; // 素数かどうか判定。
Vector prime_num; // 素数を記録。
ll n;
template <class X> void printArray(X *array, ll);
template <class X> void printVector(vector<X> &v);
template <class X> void printDimention(vector<vector<X>> &dv);
template <class X> void printMap(X);
template <class X> void printVecPair(vector<X> &v);
// 何個2がかかっているか
ll factor2(ll);
// nCr方式で組み合わせの数を求める
ll combination(int, int);
// nPrで階乗を求める
int factorial(int, int);
// 桁数を返す
int find_digits(int);
// 各桁の和を計算する関数
int findSumOfDigits(int);
// 次数を得る
int degree(int);
// 四捨五入
int shishagonyu(double);
// 切り上げ
int roundUp(double);
// 切り捨て
int roundDown(double);
// 四捨五入
int roundOff(double);
// 最大公約数(Greatest Common Divisor)
ll gcd(ll, ll);
// 最小公倍数(Least Common Multiple)
ll lcm(ll, ll);
// 素因数分解
void prime_factorization(ll);
// エラトステネスの篩
void Eratosthenes(int);
// 偶奇判定。奇数ならtrue。
bool odd_even(int);
// aのmod mにおける逆元を計算する
long long modinv(long long, long long);
// a^n mod を計算する(二分累乗)
long long modpow(long long, long long, long long);
// テーブルを作る前処理
void COMinit();
// 二項係数計算 nCk, 1 <= k <= n <= 10^7
long long COM(int, int);
// longlong型で絶対値を帰す。
long long abs_ll(ll);
// 割り算した時に余りが有る時だけ、+1の商を返す。
long long div_one(ll, ll);
// Stringの各桁をvectorの配列に入れる。でかい桁が添字0。
template <class X> void StringtoVec(string, vector<X> &v);
// 因数の一覧を取得する
void get_factor_list(ll);
int main(int argc, char const *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
ll x, y, z, k;
cin >> x >> y >> z >> k;
ull a[x], b[y], c[z];
rep(i, x) { cin >> a[i]; }
rep(i, y) { cin >> b[i]; }
rep(i, z) { cin >> c[i]; }
vector<ull> ab;
rep(i, x) {
rep(j, y) { ab.push_back(a[i] + b[j]); }
}
sort(ab.begin(), ab.end());
reverse(ab.begin(), ab.end());
vector<ull> abc;
rep(i, min(x * y, k)) {
rep(j, z) { abc.push_back(ab[i] + c[j]); }
}
sort(abc.begin(), abc.end());
reverse(abc.begin(), abc.end());
rep(i, k) { cout << abc[i] << endl; }
return 0;
}
template <class X> void printArray(X array[], ll n) {
rep(i, n) {
if (i)
cout << " ";
cout << array[i];
}
cout << endl;
}
template <class X> void printVector(vector<X> &v) {
rep(i, (int)v.size()) {
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
}
// 二次元配列の表示
template <class X> void printDimention(vector<vector<X>> &dv) {
rep(i, (ll)dv.size()) {
rep(j, (ll)dv[i].size()) {
if (j)
cout << " ";
cout << dv[i][j];
}
cout << endl;
}
}
// mapの表示
template <class X> void printMap(X mp) {
for (auto it : mp) {
cout << it.first << " " << it.second << endl;
}
}
// 内部にpairを内包したvectorの表示
template <class X> void printVecPair(vector<X> &v) {
rep(i, (int)v.size()) { cout << v[i].first << " " << v[i].second << endl; }
cout << endl;
}
// numの中に何個2がかかってるか
ll factor2(ll num) {
int cnt = 0;
while (num % 2 == 0) {
num /= 2;
cnt++;
}
return cnt;
}
// nCr方式で組み合わせの数を求める
ll combination(int n, int r) {
ll up = 1, down = 1;
// 以下2行はお試し
ll half = n / 2;
if (r >= half)
r = n - r;
ll up_tmp = n, down_tmp = r;
if (r == 0)
return 1;
rep(i, r) {
up *= up_tmp;
up_tmp--;
down *= down_tmp;
down_tmp--;
}
return up / down;
}
// nPr方式で階乗を求める
int factorial(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
} else {
int res = 1;
while (r) {
r--;
res *= n;
n--;
}
return res;
}
}
// 桁数を返す
int find_digits(int n) {
int digit = 0;
while (n) {
n /= 10;
digit++;
}
return digit;
}
// 各桁の和を計算する関数
int findSumOfDigits(int n) {
int sum = 0;
while (n > 0) { // n が 0 になるまで
sum += n % 10;
n /= 10;
}
return sum;
}
// 次数を得る
int degree(int n) {
int count = 0;
while (1) {
if (count <= 0)
break;
count /= 2;
count++;
}
return count;
}
// 四捨五入
int shishagonyu(double x) { return (int)(x < 0.0 ? x - 0.5 : x + 0.5); }
// 切り上げ
int roundUp(double n) {
if (n >= 0) {
return (int)n + 1;
} else {
return (int)n - 1;
}
}
// 切り捨て
int roundDown(double n) { return (int)n; }
// 四捨五入
int roundOff(double n) {
double decimal = 0;
decimal = n - (int)n;
if (decimal >= 0.5 || decimal <= -0.5) {
return roundUp(n);
} else {
return roundDown(n);
}
}
// 最大公約数(Greatest Common Divisor)
ll gcd(ll m, ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// ユークリッドの互除法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
// 最小公倍数(Least Common Multiple)
ll lcm(ll m, ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// lcm = m * n / gcd(m, n)
return ((m / gcd(m, n)) * n);
}
// 素因数分解 firstは数。secondは指数。
void prime_factorization(ll n) {
int div = 2, res;
bool flg = false;
if (n < 2) {
cout << "Error" << endl;
return;
}
while (n >= div * div) {
if (n % div == 0) {
res = div;
// resをグローバルな配列に代入すれば記録できる。
if (flg) {
prime_factor[prime_factor.size() - 1].second++;
} else {
prime_factor.push_back(make_pair(0, 1));
prime_factor[prime_factor.size() - 1].first = res;
}
n /= div;
flg = true;
} else {
div++;
flg = false;
}
}
// ラス1の素因数
res = n;
if (prime_factor[prime_factor.size() - 1].first == res) {
prime_factor[prime_factor.size() - 1].second++;
} else {
prime_factor.push_back(make_pair(res, 1));
}
}
// エラトステネスの篩
void Eratosthenes(int n) {
// prime_bool の添え字と見たい数は一致させたいので、
// prime_boolやprime_numは1つ多く宣言すること。
prime[0] = false;
prime[1] = false;
for (int i = 2; i < sqrt(n); i++) {
if (prime[i]) {
for (int j = 0; i * (j + 2) < n; j++) {
prime[i * (j + 2)] = false;
}
}
}
// 素数をprime_numに記録
rep(i, n) {
if (prime[i])
prime_num.push_back(i);
}
/*
int cnt = 0;
for(int i = 2; i < n; i++){
if(prime[i]){
cnt++;
}
}
return cnt;
*/
}
// 偶奇判定。奇数ならtrue。
bool odd_even(int num) {
bool judge;
if (num % 2) {
judge = true;
} else {
judge = false;
}
return judge;
}
// aのmod mにおける逆元を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// main関数内でCOMinitを呼んだ後,COMを呼ぶ.
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < TABLEMAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算 nCk, nCrのcombinationでも使える
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long abs_ll(ll a) {
if (a >= 0) {
return a;
} else {
return -a;
}
}
// 割り算した時に余りが有る時だけ、+1の商を返す。
long long div_one(ll res, ll div) {
// res 割られる数、div 割る数
return (res + div - 1) / div;
}
// Stringの各桁をvectorの配列に入れる。でかい桁が添字0。
template <class X> void StringtoVec(string str, vector<X> &v) {
ll num = stoll(str);
ll it = str.size() - 1;
// 桁を逆にしたい時、下をon
// ll it = 0;
v.resize(str.size());
while (num) {
v[it] = num % 10;
num /= 10;
it--;
// it++;
if (it < 0) {
cout << "reference error" << endl;
break;
}
}
}
// nに数を入れるとその約数の一覧をfactor_listに格納する
void get_factor_list(ll n) {
int div = 1, res;
while (n >= div * div) {
if (n % div == 0) {
res = div;
ll tmp = n / res;
factor_list.push_back(res);
if (tmp != 1)
factor_list.push_back(tmp);
div++;
} else {
div++;
}
}
sort(factor_list.begin(), factor_list.end());
} | replace | 131 | 132 | 131 | 132 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void ts() {
cout << "***我只想过个水题抽奖****" << endl;
cout << "***I JUST WANT PASS A WATER-PROBLEM FOR LUCK DRAW***" << endl;
}
#define ll long long
int x, y, z, m;
ll a[1005], b[1005], c[1005];
vector<ll> v;
void solve1() {
scanf("%d%d%d%d", &x, &y, &z, &m);
for (int i = 1; i <= x; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= y; i++)
scanf("%lld", &b[i]);
for (int i = 1; i <= z; i++)
scanf("%lld", &c[i]);
sort(a + 1, a + 1 + x);
sort(b + 1, b + 1 + y);
sort(c + 1, c + 1 + z);
reverse(a + 1, a + 1 + x);
reverse(b + 1, b + 1 + y);
reverse(c + 1, c + 1 + z);
for (int i = 1; i <= min(200, x); i++)
for (int j = 1; j <= min(200, y); j++)
for (int k = 1; k <= min(200, z); k++)
v.push_back(a[i] + b[j] + c[k]);
for (int i = 201; i <= x; i++)
for (int j = 1; j <= min(50, y); j++)
for (int k = 1; k <= min(50, z); k++)
v.push_back(a[i] + b[j] + c[k]);
for (int i = 1; i <= min(50, x); i++)
for (int j = 201; j <= y; j++)
for (int k = 1; k <= min(50, z); k++)
v.push_back(a[i] + b[j] + c[k]);
for (int i = 1; i <= min(50, x); i++)
for (int j = 1; j <= min(50, y); j++)
for (int k = 201; k <= z; k++)
v.push_back(a[i] + b[j] + c[k]);
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < m; i++)
printf("%lld\n", v[i]);
}
bool judge(ll p) {
int tot = 0;
for (int i = 1; i <= x; i++)
for (int j = 1; j <= y; j++) {
if (a[i] + b[j] + c[1] < p)
break;
for (int k = 1; k <= z; k++) {
if (a[i] + b[j] + c[k] < p)
break;
tot++;
if (tot >= m)
return true;
}
}
return false;
}
void solve2() {
scanf("%d%d%d%d", &x, &y, &z, &m);
for (int i = 1; i <= x; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= y; i++)
scanf("%lld", &b[i]);
for (int i = 1; i <= z; i++)
scanf("%lld", &c[i]);
sort(a + 1, a + 1 + x);
sort(b + 1, b + 1 + y);
sort(c + 1, c + 1 + z);
reverse(a + 1, a + 1 + x);
reverse(b + 1, b + 1 + y);
reverse(c + 1, c + 1 + z);
ll l = 0, r = 3e10, ans;
while (r > 0) {
ll m = l + r >> 1;
if (judge(m))
ans = m, l = m + 1;
else
r = m - 1;
}
for (int i = 1; i <= x; i++)
for (int j = 1; j <= y; j++) {
if (a[i] + b[j] + c[1] < ans)
break;
for (int k = 1; k <= z; k++) {
if (a[i] + b[j] + c[k] < ans)
break;
v.push_back(a[i] + b[j] + c[k]);
}
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < m; i++)
printf("%lld\n", v[i]);
}
int main() {
// solve1();
solve2();
}
| #include <bits/stdc++.h>
using namespace std;
void ts() {
cout << "***我只想过个水题抽奖****" << endl;
cout << "***I JUST WANT PASS A WATER-PROBLEM FOR LUCK DRAW***" << endl;
}
#define ll long long
int x, y, z, m;
ll a[1005], b[1005], c[1005];
vector<ll> v;
void solve1() {
scanf("%d%d%d%d", &x, &y, &z, &m);
for (int i = 1; i <= x; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= y; i++)
scanf("%lld", &b[i]);
for (int i = 1; i <= z; i++)
scanf("%lld", &c[i]);
sort(a + 1, a + 1 + x);
sort(b + 1, b + 1 + y);
sort(c + 1, c + 1 + z);
reverse(a + 1, a + 1 + x);
reverse(b + 1, b + 1 + y);
reverse(c + 1, c + 1 + z);
for (int i = 1; i <= min(200, x); i++)
for (int j = 1; j <= min(200, y); j++)
for (int k = 1; k <= min(200, z); k++)
v.push_back(a[i] + b[j] + c[k]);
for (int i = 201; i <= x; i++)
for (int j = 1; j <= min(50, y); j++)
for (int k = 1; k <= min(50, z); k++)
v.push_back(a[i] + b[j] + c[k]);
for (int i = 1; i <= min(50, x); i++)
for (int j = 201; j <= y; j++)
for (int k = 1; k <= min(50, z); k++)
v.push_back(a[i] + b[j] + c[k]);
for (int i = 1; i <= min(50, x); i++)
for (int j = 1; j <= min(50, y); j++)
for (int k = 201; k <= z; k++)
v.push_back(a[i] + b[j] + c[k]);
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < m; i++)
printf("%lld\n", v[i]);
}
bool judge(ll p) {
int tot = 0;
for (int i = 1; i <= x; i++)
for (int j = 1; j <= y; j++) {
if (a[i] + b[j] + c[1] < p)
break;
for (int k = 1; k <= z; k++) {
if (a[i] + b[j] + c[k] < p)
break;
tot++;
if (tot >= m)
return true;
}
}
return false;
}
void solve2() {
scanf("%d%d%d%d", &x, &y, &z, &m);
for (int i = 1; i <= x; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= y; i++)
scanf("%lld", &b[i]);
for (int i = 1; i <= z; i++)
scanf("%lld", &c[i]);
sort(a + 1, a + 1 + x);
sort(b + 1, b + 1 + y);
sort(c + 1, c + 1 + z);
reverse(a + 1, a + 1 + x);
reverse(b + 1, b + 1 + y);
reverse(c + 1, c + 1 + z);
ll l = 0, r = 3e10, ans;
while (l <= r) {
ll m = l + r >> 1;
if (judge(m))
ans = m, l = m + 1;
else
r = m - 1;
}
for (int i = 1; i <= x; i++)
for (int j = 1; j <= y; j++) {
if (a[i] + b[j] + c[1] < ans)
break;
for (int k = 1; k <= z; k++) {
if (a[i] + b[j] + c[k] < ans)
break;
v.push_back(a[i] + b[j] + c[k]);
}
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < m; i++)
printf("%lld\n", v[i]);
}
int main() {
// solve1();
solve2();
}
| replace | 76 | 77 | 76 | 77 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long x, y, z, K, a[1005], b[1005], c[1005];
vector<long long> vec;
int main() {
cin >> x >> y >> z >> K;
for (int i = 0; i < x; ++i)
cin >> a[i];
sort(a, a + x, greater<long long>());
for (int i = 0; i < y; ++i)
cin >> b[i];
sort(b, b + y, greater<long long>());
for (int i = 0; i < z; ++i)
cin >> c[i];
sort(c, c + z, greater<long long>());
for (int i = 0; i < x; ++i) {
for (int j = 0; j < y; ++j) {
for (int k = 1; k < z; ++k) {
if ((i + 1) * (j + 1) * (k + 1) <= K)
vec.push_back(a[i] + b[j] + c[k]);
else
break;
}
}
}
sort(vec.begin(), vec.end(), greater<long long>());
for (int i = 0; i < K; ++i)
cout << vec[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long x, y, z, K, a[1005], b[1005], c[1005];
vector<long long> vec;
int main() {
cin >> x >> y >> z >> K;
for (int i = 0; i < x; ++i)
cin >> a[i];
sort(a, a + x, greater<long long>());
for (int i = 0; i < y; ++i)
cin >> b[i];
sort(b, b + y, greater<long long>());
for (int i = 0; i < z; ++i)
cin >> c[i];
sort(c, c + z, greater<long long>());
for (int i = 0; i < x; ++i) {
for (int j = 0; j < y; ++j) {
for (int k = 0; k < z; ++k) {
if ((i + 1) * (j + 1) * (k + 1) <= K)
vec.push_back(a[i] + b[j] + c[k]);
else
break;
}
}
}
sort(vec.begin(), vec.end(), greater<long long>());
for (int i = 0; i < K; ++i)
cout << vec[i] << endl;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
using namespace std;
typedef long long ll;
ll a[1000] = {};
ll b[1000] = {};
ll c[1000] = {};
ll D[1000000] = {};
ll E[1000000] = {};
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
rep(i, 0, x) cin >> a[i];
rep(i, 0, y) cin >> b[i];
rep(i, 0, z) cin >> c[i];
rep(i, 0, x) rep(j, 0, y) { D[i * y + j] = a[i] + b[j]; }
sort(D, D + x * y);
reverse(D, D + x * y);
rep(i, 0, k) rep(j, 0, z) { E[i * z + j] = D[i] + c[j]; }
sort(E, E + k * z);
reverse(E, E + k * z);
rep(i, 0, k) { cout << E[i] << endl; }
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
using namespace std;
typedef long long ll;
ll a[1000] = {};
ll b[1000] = {};
ll c[1000] = {};
ll D[1000000] = {};
ll E[3000000] = {};
int main() {
ll x, y, z, k;
cin >> x >> y >> z >> k;
rep(i, 0, x) cin >> a[i];
rep(i, 0, y) cin >> b[i];
rep(i, 0, z) cin >> c[i];
rep(i, 0, x) rep(j, 0, y) { D[i * y + j] = a[i] + b[j]; }
sort(D, D + x * y);
reverse(D, D + x * y);
rep(i, 0, k) rep(j, 0, z) { E[i * z + j] = D[i] + c[j]; }
sort(E, E + k * z);
reverse(E, E + k * z);
rep(i, 0, k) { cout << E[i] << endl; }
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p03078 | C++ | Runtime Error | // ~/Remember,remember the 6th of March
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll MOD = 100000000;
const int N = 2e6 + 10;
void fast() { std::ios_base::sync_with_stdio(0); }
int main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt","w",stdout);
#endif*/
ll x, y, z, k;
scanf("%lld%lld%lld%lld", &x, &y, &z, &k);
vector<ll> arrx(x);
for (ll &i : arrx)
scanf("%lld", &i);
vector<ll> arry(y);
for (ll &i : arry)
scanf("%lld", &i);
vector<ll> arrz(z);
for (ll &i : arrz)
scanf("%lld", &i);
sort(arrx.rbegin(), arrx.rend());
sort(arry.rbegin(), arry.rend());
sort(arrz.rbegin(), arrz.rend());
vector<ll> ans;
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
for (int k = 0; k < z; k++)
ans.push_back(arrx[i] + arry[j] + arrz[k]);
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < k; i++)
printf("%lld\n", ans[i]);
return 0;
} | // ~/Remember,remember the 6th of March
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <ctype.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll MOD = 100000000;
const int N = 2e6 + 10;
void fast() { std::ios_base::sync_with_stdio(0); }
int main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt","w",stdout);
#endif*/
ll x, y, z, k;
scanf("%lld%lld%lld%lld", &x, &y, &z, &k);
vector<ll> arrx(x);
for (ll &i : arrx)
scanf("%lld", &i);
vector<ll> arry(y);
for (ll &i : arry)
scanf("%lld", &i);
vector<ll> arrz(z);
for (ll &i : arrz)
scanf("%lld", &i);
sort(arrx.rbegin(), arrx.rend());
sort(arry.rbegin(), arry.rend());
sort(arrz.rbegin(), arrz.rend());
vector<ll> ans;
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
for (int kk = 0; kk < z; kk++)
if ((i + 1) * (j + 1) * (kk + 1) <= k)
ans.push_back(arrx[i] + arry[j] + arrz[kk]);
else
break;
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < k; i++)
printf("%lld\n", ans[i]);
return 0;
} | replace | 57 | 59 | 57 | 62 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using lli = long long int;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<lli> a(x);
vector<lli> b(y);
vector<lli> c(z);
REP(i, x) cin >> a.at(i);
REP(j, y) cin >> b.at(j);
REP(k, z) cin >> c.at(k);
vector<lli> ab(x * y);
int idx = 0;
REP(i, x) {
REP(j, y) {
ab.at(idx) = a.at(i) + b.at(j);
idx++;
}
}
sort(ab.rbegin(), ab.rend());
vector<lli> abc(k * z);
idx = 0;
REP(i, k) {
REP(j, z) {
abc.at(idx) = ab.at(i) + c.at(j);
idx++;
}
}
sort(abc.rbegin(), abc.rend());
REP(i, k) { cout << abc.at(i) << endl; }
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using lli = long long int;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<lli> a(x);
vector<lli> b(y);
vector<lli> c(z);
REP(i, x) cin >> a.at(i);
REP(j, y) cin >> b.at(j);
REP(k, z) cin >> c.at(k);
vector<lli> ab(x * y);
int idx = 0;
REP(i, x) {
REP(j, y) {
ab.at(idx) = a.at(i) + b.at(j);
idx++;
}
}
sort(ab.rbegin(), ab.rend());
vector<lli> abc(k * z);
idx = 0;
REP(i, min(x * y, k)) {
REP(j, z) {
abc.at(idx) = ab.at(i) + c.at(j);
idx++;
}
}
sort(abc.rbegin(), abc.rend());
REP(i, k) { cout << abc.at(i) << endl; }
}
| replace | 31 | 32 | 31 | 32 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()
typedef int64_t ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
cerr << fst << ": ";
dbg(rst...);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
VL a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
VL ab;
ab.reserve(x * y + 5);
rep(i, x) rep(j, y) ab.push_back(a[i] + b[j]);
sort(all(ab), greater<ll>());
VL ans;
ans.reserve(sz(ab) * z + 5);
rep(i, min(3001, sz(ab))) rep(j, z) ans.push_back(ab[i] + c[j]);
sort(all(ans), greater<ll>());
rep(i, k) { cout << ans[i] << "\n"; }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()
typedef int64_t ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
cerr << fst << ": ";
dbg(rst...);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
VL a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
VL ab;
ab.reserve(x * y + 5);
rep(i, x) rep(j, y) ab.push_back(a[i] + b[j]);
sort(all(ab), greater<ll>());
VL ans;
ans.reserve(min(3005, sz(ab)) * z + 5);
rep(i, min(3001, sz(ab))) rep(j, z) ans.push_back(ab[i] + c[j]);
sort(all(ans), greater<ll>());
rep(i, k) { cout << ans[i] << "\n"; }
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) Rep(i, 0, b)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
/*
// 最大公約数
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// 最小公倍数
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) { cin >> a[i]; }
rep(i, y) { cin >> b[i]; }
rep(i, z) { cin >> c[i]; }
vector<ll> ab;
rep(i, x) {
rep(j, y) { ab.push_back(a[i] + b[j]); }
}
sort(allof(ab), greater<ll>());
vector<ll> abc;
rep(i, x * y) {
if (x * y == k)
break;
rep(j, z) {
if (j == k)
break;
abc.push_back(ab[i] + c[j]);
}
}
sort(allof(abc), greater<ll>());
rep(i, k) { cout << abc[i] << endl; }
return 0;
} | #include <algorithm>
#include <array>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) Rep(i, 0, b)
#define rrep(i, a) for (int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
/*
// 最大公約数
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// 最小公倍数
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) { cin >> a[i]; }
rep(i, y) { cin >> b[i]; }
rep(i, z) { cin >> c[i]; }
vector<ll> ab;
rep(i, x) {
rep(j, y) { ab.push_back(a[i] + b[j]); }
}
sort(allof(ab), greater<ll>());
vector<ll> abc;
rep(i, x * y) {
if (i == k)
break;
rep(j, z) {
if (j == k)
break;
abc.push_back(ab[i] + c[j]);
}
}
sort(allof(abc), greater<ll>());
rep(i, k) { cout << abc[i] << endl; }
return 0;
} | replace | 63 | 64 | 63 | 64 | 0 | |
p03078 | C++ | Runtime Error | // D.cpp
#include <bits/stdc++.h>
#define ll long long
#define pr pair<ll, ll>
using namespace std;
const int MAX_N = 1010;
ll seqA[MAX_N], seqB[MAX_N], seqC[MAX_N], x, y, z, k, current_seq[MAX_N << 2],
tmp[MAX_N << 2];
struct node {
ll val, ptr1, ptr2;
bool operator<(const node &nd) const { return val < nd.val; }
};
priority_queue<node> pq;
bool cmp(ll a, ll b) { return a > b; }
void solve(ll *seq) {
pq.push(node{current_seq[1] + seq[1], 1, 1});
memset(tmp, 0, sizeof(tmp));
for (int i = 1; i <= k && (!pq.empty()); i++) {
node curt = pq.top();
tmp[i] = curt.val, pq.pop();
if (curt.ptr2 == 1 && current_seq[curt.ptr1 + 1] != 0)
pq.push(node{current_seq[curt.ptr1 + 1] + seq[curt.ptr2], curt.ptr1 + 1,
curt.ptr2});
if (seq[curt.ptr2 + 1] != 0)
pq.push(node{current_seq[curt.ptr1] + seq[curt.ptr2 + 1], curt.ptr1,
curt.ptr2 + 1});
}
memcpy(current_seq, tmp, sizeof(tmp));
while (!pq.empty())
pq.pop();
}
int main() {
scanf("%d%d%d%d", &x, &y, &z, &k);
for (int i = 1; i <= x; i++)
scanf("%lld", &seqA[i]);
for (int i = 1; i <= y; i++)
scanf("%lld", &seqB[i]);
for (int i = 1; i <= z; i++)
scanf("%lld", &seqC[i]);
sort(seqA + 1, seqA + 1 + x, cmp), sort(seqB + 1, seqB + 1 + y, cmp),
sort(seqC + 1, seqC + 1 + z, cmp);
for (int i = 1; i <= k; i++)
current_seq[i] = seqA[i];
solve(seqB), solve(seqC);
for (int i = 1; i <= k; i++)
printf("%lld\n", current_seq[i]);
return 0;
} | // D.cpp
#include <bits/stdc++.h>
#define ll long long
#define pr pair<ll, ll>
using namespace std;
const int MAX_N = 10100;
ll seqA[MAX_N], seqB[MAX_N], seqC[MAX_N], x, y, z, k, current_seq[MAX_N << 2],
tmp[MAX_N << 2];
struct node {
ll val, ptr1, ptr2;
bool operator<(const node &nd) const { return val < nd.val; }
};
priority_queue<node> pq;
bool cmp(ll a, ll b) { return a > b; }
void solve(ll *seq) {
pq.push(node{current_seq[1] + seq[1], 1, 1});
memset(tmp, 0, sizeof(tmp));
for (int i = 1; i <= k && (!pq.empty()); i++) {
node curt = pq.top();
tmp[i] = curt.val, pq.pop();
if (curt.ptr2 == 1 && current_seq[curt.ptr1 + 1] != 0)
pq.push(node{current_seq[curt.ptr1 + 1] + seq[curt.ptr2], curt.ptr1 + 1,
curt.ptr2});
if (seq[curt.ptr2 + 1] != 0)
pq.push(node{current_seq[curt.ptr1] + seq[curt.ptr2 + 1], curt.ptr1,
curt.ptr2 + 1});
}
memcpy(current_seq, tmp, sizeof(tmp));
while (!pq.empty())
pq.pop();
}
int main() {
scanf("%d%d%d%d", &x, &y, &z, &k);
for (int i = 1; i <= x; i++)
scanf("%lld", &seqA[i]);
for (int i = 1; i <= y; i++)
scanf("%lld", &seqB[i]);
for (int i = 1; i <= z; i++)
scanf("%lld", &seqC[i]);
sort(seqA + 1, seqA + 1 + x, cmp), sort(seqB + 1, seqB + 1 + y, cmp),
sort(seqC + 1, seqC + 1 + z, cmp);
for (int i = 1; i <= k; i++)
current_seq[i] = seqA[i];
solve(seqB), solve(seqC);
for (int i = 1; i <= k; i++)
printf("%lld\n", current_seq[i]);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef unsigned long long u64;
typedef long long i64;
u64 x, y, z, k;
u64 a[1005];
u64 b[1005];
u64 c[1005];
u64 p[3005];
u64 q[3005];
u64 v[1000005];
void d(u64 s[1005], u64 s1, u64 t[1005], u64 t1, u64 u[3005]) {
REP(i, s1) {
REP(j, t1) { v[i * t1 + j] = s[i] + t[j]; }
}
sort(v, v + s1 * t1, greater<u64>());
REP(i, k)
u[i] = v[i];
}
void solve() {
d(a, x, b, y, p);
d(p, k, c, z, q);
REP(i, k)
cout << q[i] << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> x >> y >> z >> k;
REP(i, x)
cin >> a[i];
REP(i, y)
cin >> b[i];
REP(i, z)
cin >> c[i];
sort(a, a + x, greater<u64>());
sort(b, b + x, greater<u64>());
sort(c, c + x, greater<u64>());
solve();
return 0;
}
| #include <algorithm>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef unsigned long long u64;
typedef long long i64;
u64 x, y, z, k;
u64 a[1005];
u64 b[1005];
u64 c[1005];
u64 p[3005];
u64 q[3005];
u64 v[3000005];
void d(u64 s[1005], u64 s1, u64 t[1005], u64 t1, u64 u[3005]) {
REP(i, s1) {
REP(j, t1) { v[i * t1 + j] = s[i] + t[j]; }
}
sort(v, v + s1 * t1, greater<u64>());
REP(i, k)
u[i] = v[i];
}
void solve() {
d(a, x, b, y, p);
d(p, k, c, z, q);
REP(i, k)
cout << q[i] << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> x >> y >> z >> k;
REP(i, x)
cin >> a[i];
REP(i, y)
cin >> b[i];
REP(i, z)
cin >> c[i];
sort(a, a + x, greater<u64>());
sort(b, b + x, greater<u64>());
sort(c, c + x, greater<u64>());
solve();
return 0;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
long long A[X], B[Y], C[Z];
for (int i = 0; i < X; ++i)
cin >> A[i];
for (int i = 0; i < Y; ++i)
cin >> B[i];
for (int i = 0; i < Z; ++i)
cin >> C[i];
vector<long long> tastes;
for (int i = 0; i < X; ++i)
for (int j = 0; j < Y; ++j)
tastes.push_back(A[i] + B[j]);
sort(tastes.begin(), tastes.end(), greater<long long>());
vector<long long> ans;
for (int i = 0; i < Z; ++i)
for (long long taste : tastes)
ans.push_back(taste + C[i]);
sort(ans.begin(), ans.end(), greater<long long>());
for (int i = 0; i < K; ++i)
cout << ans[i] << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
long long A[X], B[Y], C[Z];
for (int i = 0; i < X; ++i)
cin >> A[i];
for (int i = 0; i < Y; ++i)
cin >> B[i];
for (int i = 0; i < Z; ++i)
cin >> C[i];
vector<long long> tastes;
for (int i = 0; i < X; ++i)
for (int j = 0; j < Y; ++j)
tastes.push_back(A[i] + B[j]);
sort(tastes.begin(), tastes.end(), greater<long long>());
vector<long long> ans;
for (int i = 0; i < Z; ++i)
for (int j = 0; j < min((int)tastes.size(), K); ++j)
ans.push_back(tastes[j] + C[i]);
sort(ans.begin(), ans.end(), greater<long long>());
for (int i = 0; i < K; ++i)
cout << ans[i] << "\n";
return 0;
} | replace | 26 | 28 | 26 | 28 | 0 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <cmath>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
sort(a, a + x, greater<ll>());
sort(b, b + y, greater<ll>());
sort(c, c + z, greater<ll>());
vector<ll> ans;
for (int i = 0; i < min(x, 500); i++) {
for (int j = 0; j < min(y, 500); j++) {
for (int l = 0; l < min(z, 500); l++) {
ll sum = a[i] + b[j] + c[l];
ans.pb(sum);
}
}
}
sort(all(ans), greater<ll>());
for (auto it : ans) {
if (k == 0) {
break;
}
cout << it << "\n";
k--;
}
} | #include <bits/stdc++.h>
#include <cmath>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout << #x << '=' << x << endl
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int x, y, z, k;
cin >> x >> y >> z >> k;
ll a[x], b[y], c[z];
for (int i = 0; i < x; i++) {
cin >> a[i];
}
for (int i = 0; i < y; i++) {
cin >> b[i];
}
for (int i = 0; i < z; i++) {
cin >> c[i];
}
sort(a, a + x, greater<ll>());
sort(b, b + y, greater<ll>());
sort(c, c + z, greater<ll>());
vector<ll> ans;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int l = 0; l < z; l++) {
if ((i + 1) * (j + 1) * (l + 1) <= k) {
ll sum = a[i] + b[j] + c[l];
ans.pb(sum);
} else {
break;
}
}
}
}
sort(all(ans), greater<ll>());
for (auto it : ans) {
if (k == 0) {
break;
}
cout << it << "\n";
k--;
}
} | replace | 39 | 44 | 39 | 48 | TLE | |
p03078 | C++ | Time Limit Exceeded | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define int long long
// #define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2 + 1
#define LL_MAX 9223372036854775807 // ない環境用
#define LL_HALFMAX 9223372036854775807 / 2 // ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define mp make_pair
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
using namespace std;
std::mt19937 mt((int)time(0));
int dx[4] = {0, 1, 0, -1}; // x軸方向への変位
int dy[4] = {1, 0, -1, 0}; // y軸方向への変位
using Weight = int;
using Flow = int;
struct Edge {
int src, dst;
Weight weight;
Flow cap;
Edge() : src(0), dst(0), weight(0) {}
Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
}
struct uf_tree {
std::vector<int> parent;
int __size;
uf_tree(int size_) : parent(size_, -1), __size(size_) {}
void unite(int x, int y) {
if ((x = find(x)) != (y = find(y))) {
if (parent[y] < parent[x])
std::swap(x, y);
parent[x] += parent[y];
parent[y] = x;
__size--;
}
}
bool is_same(int x, int y) { return find(x) == find(y); }
int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
int size(int x) { return -parent[find(x)]; }
int size() { return __size; }
};
//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか?!!!
template <signed M, unsigned T> struct mod_int {
constexpr static signed MODULO = M;
constexpr static unsigned TABLE_SIZE = T;
signed x;
mod_int() : x(0) {}
mod_int(long long y)
: x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}
mod_int(signed y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}
mod_int &operator+=(const mod_int &rhs) {
if ((x += rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator-=(const mod_int &rhs) {
if ((x += MODULO - rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator*=(const mod_int &rhs) {
x = static_cast<signed>(1LL * x * rhs.x % MODULO);
return *this;
}
mod_int &operator/=(const mod_int &rhs) {
x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
return *this;
}
mod_int operator-() const { return mod_int(-x); }
mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
bool operator<(const mod_int &rhs) const { return x < rhs.x; }
mod_int inv() const {
assert(x != 0);
if (x <= static_cast<signed>(TABLE_SIZE)) {
if (_inv[1].x == 0)
prepare();
return _inv[x];
} else {
signed a = x, b = MODULO, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return mod_int(u);
}
}
mod_int pow(long long t) const {
assert(!(x == 0 && t == 0));
mod_int e = *this, res = mod_int(1);
for (; t; e *= e, t >>= 1)
if (t & 1)
res *= e;
return res;
}
mod_int fact() {
if (_fact[0].x == 0)
prepare();
return _fact[x];
}
mod_int inv_fact() {
if (_fact[0].x == 0)
prepare();
return _inv_fact[x];
}
mod_int choose(mod_int y) {
assert(y.x <= x);
return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
}
static mod_int _inv[TABLE_SIZE + 1];
static mod_int _fact[TABLE_SIZE + 1];
static mod_int _inv_fact[TABLE_SIZE + 1];
static void prepare() {
_inv[1] = 1;
for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
_inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
}
_fact[0] = 1;
for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
_fact[i] = _fact[i - 1] * signed(i);
}
_inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
_inv_fact[i] = _inv_fact[i + 1] * (i + 1);
}
}
};
template <signed M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
return os << rhs.x;
}
template <signed M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
long long s;
is >> s;
rhs = mod_int<M, F>(s);
return is;
}
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return lhs.x == rhs.x;
}
template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return !(lhs == rhs);
}
const signed MF = 1000010;
const signed MOD = 1000000007;
using mint = mod_int<MOD, MF>;
mint binom(int n, int r) {
return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r);
}
mint fact(int n) { return mint(n).fact(); }
mint inv_fact(int n) { return mint(n).inv_fact(); }
// 出典 http://beet-aizu.hatenablog.com/entry/2017/12/01/225955
/*
コンストラクタ引数説明
int n_
要素数。
f
2つの要素Tをマージするための関数。
区間MAX区間更新の時: max
区間Sum区間Addの時: +
g
1つの要素Tに作用素Eを適用するための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
h
2つの作用素Eをマージするための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
T d1
演算fの単位元。
区間MAX区間更新の時: -INF
区間Sum区間Addの時: 0
E d0,
g, hの単位元。
区間MAX区間更新の時: 定義域外のどこか
区間Sum区間Addの時: 0
vector<T> v = vector<T>()
セグ木を構成するときのvector
P p = [](E a, int b) {return a; }
区間の長さbを引数に取り、区間の長さによって変化する作用素E'を返す関数。
例えば、区間MAX区間Addの時なんかは区間長によって足すべき数が変化するので必要
区間Sum区間Addの時: *
//具体例
//区間chmin, 区間min
auto myMin = [](int a, int b) {return min(a, b); };
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
//区間update、区間min
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
*/
template <typename T, typename E> struct SegmentTree {
typedef function<T(T, T)> F;
typedef function<T(T, E)> G;
typedef function<E(E, E)> H;
typedef function<E(E, int)> P;
int n;
F f;
G g;
H h;
P p;
T d1;
E d0;
vector<T> dat;
vector<E> laz;
SegmentTree(
int n_, F f, G g, H h, T d1, E d0, vector<T> v = vector<T>(),
P p = [](E a, int b) { return a; })
: f(f), g(g), h(h), d1(d1), d0(d0), p(p) {
init(n_);
if (n_ == (int)v.size())
build(n_, v);
}
// 初期化。要素配列と遅延配列を2*n-1個にする
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
dat.clear();
dat.resize(2 * n - 1, d1);
laz.clear();
laz.resize(2 * n - 1, d0);
}
// 既存のvectorからセグ木を構築
void build(int n_, vector<T> v) {
for (int i = 0; i < n_; i++)
dat[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
}
// ノードを評価する。
inline void eval(int len, int k) {
// 遅延配列に単位元が入ってたら評価済みなのでおしまい
if (laz[k] == d0)
return;
// 葉ノードでないなら遅延伝播する
if (k * 2 + 1 < n * 2 - 1) {
// h: 2つの作用素を引数に取り合成した作用素を返す関数
laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]);
laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]);
}
// p:
// このノードに対応する区間長と作用素を引数に取り、区間長に対応する作用素を返す関数
// dat[k] にlaz に溜めていた作用素を適用(g:
// 要素型と作用素型を引数に取り、要素に作用素を作用させた結果を返す関数、ここでの作用素とは区間Sum区間Addなら
// (+ 3) とか)
dat[k] = g(dat[k], p(laz[k], len));
// 適用し終わったので遅延配列をクリア
laz[k] = d0;
}
//[l,r)の区間を再帰的に見ながら0-indexedの[a, b)を更新する
T update(int a, int b, E x, int k, int l, int r) {
// 先に評価
eval(r - l, k);
// 範囲外ならなにもしないでそのノードが持つ値を返す
if (r <= a || b <= l)
return dat[k];
// 完全被覆なら既に遅延配列に入っている作用素と追加したい作用素をマージした後にそれを要素に作用させた結果を返す、pは区間長に対応する作用素を得るための(ry
if (a <= l && r <= b) {
laz[k] = h(laz[k], x);
return g(dat[k], p(laz[k], r - l));
}
// 完全被覆でも範囲外でもないなら(中途半端にかぶっているなら)完全被覆と範囲外の境界が見えるまで木を潜って変化後の値を得る
return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
update(a, b, x, k * 2 + 2, (l + r) / 2, r));
}
T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); }
// a だけ更新(点更新)
T update(int a, E x) { return update(a, a + 1, x, 0, 0, n); }
T query(int a, int b, int k, int l, int r) {
eval(r - l, k);
// 範囲外なら単位元を返す
if (r <= a || b <= l)
return d1;
// 完全被覆ならそのまま返す
if (a <= l && r <= b)
return dat[k];
// 一部被覆なら完全被覆と範囲外に分かれるまで木を潜る
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr);
}
// 0-indexedで[a, b)の区間*を求める
T query(int a, int b) { return query(a, b, 0, 0, n); }
// 点取得
T query(int a) { return query(a, a + 1, 0, 0, n); }
};
// 座標圧縮
class compress {
public:
static const int MAP = 10000000;
map<int, int> zip;
int unzip[MAP];
compress(vector<int> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
for (int i = 0; i < x.size(); i++) {
zip[x[i]] = i;
unzip[i] = x[i];
}
}
};
unsigned euclidean_gcd(unsigned a, unsigned b) {
while (1) {
if (a < b)
swap(a, b);
if (!b)
break;
a %= b;
}
return a;
}
// https://ei1333.github.io/luzhiled/snippets/dp/cumulative-sum-2d.html
template <class T> struct CumulativeSum2D {
vector<vector<T>> data;
CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}
void add(int x, int y, T z) {
++x, ++y;
if (x >= data.size() || y >= data[0].size())
return;
data[x][y] += z;
}
void build() {
for (int i = 1; i < data.size(); i++) {
for (int j = 1; j < data[i].size(); j++) {
data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
}
}
}
T query(int sx, int sy, int gx, int gy) {
return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
}
};
// lib
int nC2(int n) { return n * (n - 1) / 2; }
class node {
public:
int depth;
int num;
node(int d, int n) {
depth = d;
num = n;
}
};
CumulativeSum2D<int> sumB(4001, 4001);
template <class T> struct CumulativeSum {
vector<T> data;
CumulativeSum(int sz) : data(sz, 0){};
void add(int k, T x) { data[k] += x; }
void build() {
for (int i = 1; i < data.size(); i++) {
data[i] += data[i - 1];
}
}
T query(int k) {
if (k < 0)
return (0);
return (data[min(k, (int)data.size() - 1)]);
}
//[left, right]の和
T query(int left, int right) { return query(right) - query(left - 1); }
};
std::vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
int N, K;
vector<int> A;
// k が条件を満たすかどうか
bool isOK(int k) {
vector<int> moded(N);
rep(i, N) { moded[i] = A[i] % k; }
int su = 0;
int su2 = 0;
rep(i, N) {
su += min(moded[i], abs(moded[i] - k));
su2 += moded[i];
}
if (su <= K && su2 % k == 0) {
return true;
}
return false;
}
// 汎用的な二分探索のテンプレ(めぐる式)
int binary_search() {
int ng = 2000000;
int ok = 1;
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
class ExDijkstraNode {
public:
int nowDist;
int parity;
int nowNode;
ExDijkstraNode(int d, int p, int n) {
nowDist = d;
parity = p;
nowNode = n;
}
bool operator<(const ExDijkstraNode &r) const { return nowDist < r.nowDist; }
bool operator>(const ExDijkstraNode &r) const { return nowDist > r.nowDist; }
};
// 型T の値Nについて、繰り返し二乗法でN^Pを計算する関数テンプレート
// http://satanic0258.hatenablog.com/entry/2016/04/29/004730
template <typename T>
T RepeatSquaring(T N, int P, function<T(T, T)> mul, T id) {
if (P == 0)
return id;
if (P % 2 == 0) {
T t = RepeatSquaring(N, P / 2, mul, id);
return mul(t, t);
}
return mul(N, RepeatSquaring(N, P - 1, mul, id));
}
// 行列積 a.b
vector<vector<mint>> dot(vector<vector<mint>> a, vector<vector<mint>> b) {
vector<vector<mint>> ret;
rep(i, a.size()) {
vector<mint> v(b[0].size(), mint(0));
ret.push_back(v);
}
rep(i, a.size()) {
rep(j, b[0].size()) {
rep(k, a.size()) { ret[i][j] += a[i][k] * b[k][j]; }
}
}
return ret;
}
std::pair<std::vector<int>, std::vector<int>> prime_factor_decomp(int n) {
std::vector<int> p, e;
int m = n;
for (int i = 2; i * i <= n; i++) {
if (m % i != 0)
continue;
int c = 0;
while (m % i == 0)
c++, m /= i;
p.push_back(i);
e.push_back(c);
}
if (m > 1) {
p.push_back(m);
e.push_back(1);
}
return std::make_pair(p, e);
}
vector<pair<int, int>> pdecomped;
signed main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<int> A(X), B(Y), C(Z);
rep(i, X) { cin >> A[i]; }
rep(i, Y) { cin >> B[i]; }
rep(i, Z) { cin >> C[i]; }
vector<int> beam[3];
beam[0] = A;
sort(beam[0].begin(), beam[0].end(), greater<int>());
if (beam[0].size() > K) {
beam[0].erase(beam[0].begin() + K, beam[0].end());
}
for (int i : beam[0]) {
for (int j : B) {
beam[1].push_back(i + j);
}
}
sort(beam[1].begin(), beam[1].end(), greater<int>());
if (beam[0].size() > K) {
beam[1].erase(beam[1].begin() + K, beam[1].end());
}
for (int i : beam[1]) {
for (int j : C) {
beam[2].push_back(i + j);
}
}
sort(beam[2].begin(), beam[2].end(), greater<int>());
rep(i, K) { cout << beam[2][i] << "\n"; }
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define int long long
// #define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2 + 1
#define LL_MAX 9223372036854775807 // ない環境用
#define LL_HALFMAX 9223372036854775807 / 2 // ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define mp make_pair
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
using namespace std;
std::mt19937 mt((int)time(0));
int dx[4] = {0, 1, 0, -1}; // x軸方向への変位
int dy[4] = {1, 0, -1, 0}; // y軸方向への変位
using Weight = int;
using Flow = int;
struct Edge {
int src, dst;
Weight weight;
Flow cap;
Edge() : src(0), dst(0), weight(0) {}
Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) {
g[a].emplace_back(a, b, w);
}
struct uf_tree {
std::vector<int> parent;
int __size;
uf_tree(int size_) : parent(size_, -1), __size(size_) {}
void unite(int x, int y) {
if ((x = find(x)) != (y = find(y))) {
if (parent[y] < parent[x])
std::swap(x, y);
parent[x] += parent[y];
parent[y] = x;
__size--;
}
}
bool is_same(int x, int y) { return find(x) == find(y); }
int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
int size(int x) { return -parent[find(x)]; }
int size() { return __size; }
};
//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか?!!!
template <signed M, unsigned T> struct mod_int {
constexpr static signed MODULO = M;
constexpr static unsigned TABLE_SIZE = T;
signed x;
mod_int() : x(0) {}
mod_int(long long y)
: x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {}
mod_int(signed y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {}
mod_int &operator+=(const mod_int &rhs) {
if ((x += rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator-=(const mod_int &rhs) {
if ((x += MODULO - rhs.x) >= MODULO)
x -= MODULO;
return *this;
}
mod_int &operator*=(const mod_int &rhs) {
x = static_cast<signed>(1LL * x * rhs.x % MODULO);
return *this;
}
mod_int &operator/=(const mod_int &rhs) {
x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO);
return *this;
}
mod_int operator-() const { return mod_int(-x); }
mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; }
mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; }
mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; }
mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; }
bool operator<(const mod_int &rhs) const { return x < rhs.x; }
mod_int inv() const {
assert(x != 0);
if (x <= static_cast<signed>(TABLE_SIZE)) {
if (_inv[1].x == 0)
prepare();
return _inv[x];
} else {
signed a = x, b = MODULO, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return mod_int(u);
}
}
mod_int pow(long long t) const {
assert(!(x == 0 && t == 0));
mod_int e = *this, res = mod_int(1);
for (; t; e *= e, t >>= 1)
if (t & 1)
res *= e;
return res;
}
mod_int fact() {
if (_fact[0].x == 0)
prepare();
return _fact[x];
}
mod_int inv_fact() {
if (_fact[0].x == 0)
prepare();
return _inv_fact[x];
}
mod_int choose(mod_int y) {
assert(y.x <= x);
return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact();
}
static mod_int _inv[TABLE_SIZE + 1];
static mod_int _fact[TABLE_SIZE + 1];
static mod_int _inv_fact[TABLE_SIZE + 1];
static void prepare() {
_inv[1] = 1;
for (int i = 2; i <= (int)TABLE_SIZE; ++i) {
_inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO;
}
_fact[0] = 1;
for (unsigned i = 1; i <= TABLE_SIZE; ++i) {
_fact[i] = _fact[i - 1] * signed(i);
}
_inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv();
for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) {
_inv_fact[i] = _inv_fact[i + 1] * (i + 1);
}
}
};
template <signed M, unsigned F>
std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) {
return os << rhs.x;
}
template <signed M, unsigned F>
std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) {
long long s;
is >> s;
rhs = mod_int<M, F>(s);
return is;
}
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1];
template <signed M, unsigned F>
bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return lhs.x == rhs.x;
}
template <int M, unsigned F>
bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) {
return !(lhs == rhs);
}
const signed MF = 1000010;
const signed MOD = 1000000007;
using mint = mod_int<MOD, MF>;
mint binom(int n, int r) {
return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r);
}
mint fact(int n) { return mint(n).fact(); }
mint inv_fact(int n) { return mint(n).inv_fact(); }
// 出典 http://beet-aizu.hatenablog.com/entry/2017/12/01/225955
/*
コンストラクタ引数説明
int n_
要素数。
f
2つの要素Tをマージするための関数。
区間MAX区間更新の時: max
区間Sum区間Addの時: +
g
1つの要素Tに作用素Eを適用するための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
h
2つの作用素Eをマージするための関数。
区間MAX区間更新の時: =
区間Sum区間Addの時: +
T d1
演算fの単位元。
区間MAX区間更新の時: -INF
区間Sum区間Addの時: 0
E d0,
g, hの単位元。
区間MAX区間更新の時: 定義域外のどこか
区間Sum区間Addの時: 0
vector<T> v = vector<T>()
セグ木を構成するときのvector
P p = [](E a, int b) {return a; }
区間の長さbを引数に取り、区間の長さによって変化する作用素E'を返す関数。
例えば、区間MAX区間Addの時なんかは区間長によって足すべき数が変化するので必要
区間Sum区間Addの時: *
//具体例
//区間chmin, 区間min
auto myMin = [](int a, int b) {return min(a, b); };
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
//区間update、区間min
SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX);
*/
template <typename T, typename E> struct SegmentTree {
typedef function<T(T, T)> F;
typedef function<T(T, E)> G;
typedef function<E(E, E)> H;
typedef function<E(E, int)> P;
int n;
F f;
G g;
H h;
P p;
T d1;
E d0;
vector<T> dat;
vector<E> laz;
SegmentTree(
int n_, F f, G g, H h, T d1, E d0, vector<T> v = vector<T>(),
P p = [](E a, int b) { return a; })
: f(f), g(g), h(h), d1(d1), d0(d0), p(p) {
init(n_);
if (n_ == (int)v.size())
build(n_, v);
}
// 初期化。要素配列と遅延配列を2*n-1個にする
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
dat.clear();
dat.resize(2 * n - 1, d1);
laz.clear();
laz.resize(2 * n - 1, d0);
}
// 既存のvectorからセグ木を構築
void build(int n_, vector<T> v) {
for (int i = 0; i < n_; i++)
dat[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
}
// ノードを評価する。
inline void eval(int len, int k) {
// 遅延配列に単位元が入ってたら評価済みなのでおしまい
if (laz[k] == d0)
return;
// 葉ノードでないなら遅延伝播する
if (k * 2 + 1 < n * 2 - 1) {
// h: 2つの作用素を引数に取り合成した作用素を返す関数
laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]);
laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]);
}
// p:
// このノードに対応する区間長と作用素を引数に取り、区間長に対応する作用素を返す関数
// dat[k] にlaz に溜めていた作用素を適用(g:
// 要素型と作用素型を引数に取り、要素に作用素を作用させた結果を返す関数、ここでの作用素とは区間Sum区間Addなら
// (+ 3) とか)
dat[k] = g(dat[k], p(laz[k], len));
// 適用し終わったので遅延配列をクリア
laz[k] = d0;
}
//[l,r)の区間を再帰的に見ながら0-indexedの[a, b)を更新する
T update(int a, int b, E x, int k, int l, int r) {
// 先に評価
eval(r - l, k);
// 範囲外ならなにもしないでそのノードが持つ値を返す
if (r <= a || b <= l)
return dat[k];
// 完全被覆なら既に遅延配列に入っている作用素と追加したい作用素をマージした後にそれを要素に作用させた結果を返す、pは区間長に対応する作用素を得るための(ry
if (a <= l && r <= b) {
laz[k] = h(laz[k], x);
return g(dat[k], p(laz[k], r - l));
}
// 完全被覆でも範囲外でもないなら(中途半端にかぶっているなら)完全被覆と範囲外の境界が見えるまで木を潜って変化後の値を得る
return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
update(a, b, x, k * 2 + 2, (l + r) / 2, r));
}
T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); }
// a だけ更新(点更新)
T update(int a, E x) { return update(a, a + 1, x, 0, 0, n); }
T query(int a, int b, int k, int l, int r) {
eval(r - l, k);
// 範囲外なら単位元を返す
if (r <= a || b <= l)
return d1;
// 完全被覆ならそのまま返す
if (a <= l && r <= b)
return dat[k];
// 一部被覆なら完全被覆と範囲外に分かれるまで木を潜る
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr);
}
// 0-indexedで[a, b)の区間*を求める
T query(int a, int b) { return query(a, b, 0, 0, n); }
// 点取得
T query(int a) { return query(a, a + 1, 0, 0, n); }
};
// 座標圧縮
class compress {
public:
static const int MAP = 10000000;
map<int, int> zip;
int unzip[MAP];
compress(vector<int> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
for (int i = 0; i < x.size(); i++) {
zip[x[i]] = i;
unzip[i] = x[i];
}
}
};
unsigned euclidean_gcd(unsigned a, unsigned b) {
while (1) {
if (a < b)
swap(a, b);
if (!b)
break;
a %= b;
}
return a;
}
// https://ei1333.github.io/luzhiled/snippets/dp/cumulative-sum-2d.html
template <class T> struct CumulativeSum2D {
vector<vector<T>> data;
CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}
void add(int x, int y, T z) {
++x, ++y;
if (x >= data.size() || y >= data[0].size())
return;
data[x][y] += z;
}
void build() {
for (int i = 1; i < data.size(); i++) {
for (int j = 1; j < data[i].size(); j++) {
data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
}
}
}
T query(int sx, int sy, int gx, int gy) {
return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
}
};
// lib
int nC2(int n) { return n * (n - 1) / 2; }
class node {
public:
int depth;
int num;
node(int d, int n) {
depth = d;
num = n;
}
};
CumulativeSum2D<int> sumB(4001, 4001);
template <class T> struct CumulativeSum {
vector<T> data;
CumulativeSum(int sz) : data(sz, 0){};
void add(int k, T x) { data[k] += x; }
void build() {
for (int i = 1; i < data.size(); i++) {
data[i] += data[i - 1];
}
}
T query(int k) {
if (k < 0)
return (0);
return (data[min(k, (int)data.size() - 1)]);
}
//[left, right]の和
T query(int left, int right) { return query(right) - query(left - 1); }
};
std::vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
int N, K;
vector<int> A;
// k が条件を満たすかどうか
bool isOK(int k) {
vector<int> moded(N);
rep(i, N) { moded[i] = A[i] % k; }
int su = 0;
int su2 = 0;
rep(i, N) {
su += min(moded[i], abs(moded[i] - k));
su2 += moded[i];
}
if (su <= K && su2 % k == 0) {
return true;
}
return false;
}
// 汎用的な二分探索のテンプレ(めぐる式)
int binary_search() {
int ng = 2000000;
int ok = 1;
/* ok と ng のどちらが大きいかわからないことを考慮 */
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
class ExDijkstraNode {
public:
int nowDist;
int parity;
int nowNode;
ExDijkstraNode(int d, int p, int n) {
nowDist = d;
parity = p;
nowNode = n;
}
bool operator<(const ExDijkstraNode &r) const { return nowDist < r.nowDist; }
bool operator>(const ExDijkstraNode &r) const { return nowDist > r.nowDist; }
};
// 型T の値Nについて、繰り返し二乗法でN^Pを計算する関数テンプレート
// http://satanic0258.hatenablog.com/entry/2016/04/29/004730
template <typename T>
T RepeatSquaring(T N, int P, function<T(T, T)> mul, T id) {
if (P == 0)
return id;
if (P % 2 == 0) {
T t = RepeatSquaring(N, P / 2, mul, id);
return mul(t, t);
}
return mul(N, RepeatSquaring(N, P - 1, mul, id));
}
// 行列積 a.b
vector<vector<mint>> dot(vector<vector<mint>> a, vector<vector<mint>> b) {
vector<vector<mint>> ret;
rep(i, a.size()) {
vector<mint> v(b[0].size(), mint(0));
ret.push_back(v);
}
rep(i, a.size()) {
rep(j, b[0].size()) {
rep(k, a.size()) { ret[i][j] += a[i][k] * b[k][j]; }
}
}
return ret;
}
std::pair<std::vector<int>, std::vector<int>> prime_factor_decomp(int n) {
std::vector<int> p, e;
int m = n;
for (int i = 2; i * i <= n; i++) {
if (m % i != 0)
continue;
int c = 0;
while (m % i == 0)
c++, m /= i;
p.push_back(i);
e.push_back(c);
}
if (m > 1) {
p.push_back(m);
e.push_back(1);
}
return std::make_pair(p, e);
}
vector<pair<int, int>> pdecomped;
signed main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<int> A(X), B(Y), C(Z);
rep(i, X) { cin >> A[i]; }
rep(i, Y) { cin >> B[i]; }
rep(i, Z) { cin >> C[i]; }
vector<int> beam[3];
beam[0] = A;
sort(beam[0].begin(), beam[0].end(), greater<int>());
if (beam[0].size() > K) {
beam[0].erase(beam[0].begin() + K, beam[0].end());
}
for (int i : beam[0]) {
for (int j : B) {
beam[1].push_back(i + j);
}
}
sort(beam[1].begin(), beam[1].end(), greater<int>());
if (beam[1].size() > K) {
beam[1].erase(beam[1].begin() + K, beam[1].end());
}
for (int i : beam[1]) {
for (int j : C) {
beam[2].push_back(i + j);
}
}
sort(beam[2].begin(), beam[2].end(), greater<int>());
rep(i, K) { cout << beam[2][i] << "\n"; }
return 0;
}
| replace | 637 | 638 | 637 | 638 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool cmp(long long int a, long long int b) { return a > b; }
int main() {
long long int x, y, z, k, t;
cin >> x >> y >> z >> k;
vector<long long int> a, b, c, d, e;
for (long long int i = 0; i < x; i++) {
cin >> t;
a.push_back(t);
}
for (long long int i = 0; i < y; i++) {
cin >> t;
b.push_back(t);
}
for (long long int i = 0; i < z; i++) {
cin >> t;
c.push_back(t);
}
sort(a.begin(), a.end(), cmp);
sort(b.begin(), b.end(), cmp);
sort(c.begin(), c.end(), cmp);
for (long long int i = 0; i < min(k, x); i++) {
for (long long int j = 0; j < min(k, y); j++) {
d.push_back(a[i] + b[j]);
}
}
sort(d.begin(), d.end(), cmp);
for (long long int i = 0; i < d.size(); i++) {
for (long long int j = 0; j < min(k, z); j++) {
e.push_back(d[i] + c[j]);
}
}
sort(e.begin(), e.end(), cmp);
for (long long int i = 0; i < k; i++)
cout << e[i] << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool cmp(long long int a, long long int b) { return a > b; }
int main() {
long long int x, y, z, k, t;
cin >> x >> y >> z >> k;
vector<long long int> a, b, c, d, e;
for (long long int i = 0; i < x; i++) {
cin >> t;
a.push_back(t);
}
for (long long int i = 0; i < y; i++) {
cin >> t;
b.push_back(t);
}
for (long long int i = 0; i < z; i++) {
cin >> t;
c.push_back(t);
}
sort(a.begin(), a.end(), cmp);
sort(b.begin(), b.end(), cmp);
sort(c.begin(), c.end(), cmp);
for (long long int i = 0; i < min(k, x); i++) {
for (long long int j = 0; j < min(k, y); j++) {
d.push_back(a[i] + b[j]);
}
}
sort(d.begin(), d.end(), cmp);
long long int size = d.size();
for (long long int i = 0; i < min(size, k); i++) {
for (long long int j = 0; j < min(k, z); j++) {
e.push_back(d[i] + c[j]);
}
}
sort(e.begin(), e.end(), cmp);
for (long long int i = 0; i < k; i++)
cout << e[i] << endl;
} | replace | 30 | 31 | 30 | 32 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
ll X, Y, Z, K;
ll A[1010], B[1010], C[1010];
ll D[1000100];
ll E[3010];
int main() {
cin >> X >> Y >> Z >> K;
for (ll i = 0; i < X; i++) {
cin >> A[i];
}
for (ll i = 0; i < Y; i++) {
cin >> B[i];
}
for (ll i = 0; i < Z; i++) {
cin >> C[i];
}
// 入力完了
sort(A, A + X, greater<ll>());
sort(B, B + Y, greater<ll>());
sort(C, C + Z, greater<ll>());
ll i_d = 0;
for (ll i = 0; i < X; i++) {
for (ll j = 0; j < Y; j++) {
D[i_d++] = A[i] + B[j];
}
}
sort(D, D + i_d, greater<ll>());
ll i_e = 0;
for (ll i = 0; i < K; i++) {
for (ll j = 0; j < Z; j++) {
E[i_e++] = D[i] + C[j];
}
}
sort(E, E + i_e, greater<ll>());
for (ll i = 0; i < K; i++) {
cout << E[i] << endl;
}
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
ll X, Y, Z, K;
ll A[1010], B[1010], C[1010];
ll D[1000100];
ll E[3000100];
int main() {
cin >> X >> Y >> Z >> K;
for (ll i = 0; i < X; i++) {
cin >> A[i];
}
for (ll i = 0; i < Y; i++) {
cin >> B[i];
}
for (ll i = 0; i < Z; i++) {
cin >> C[i];
}
// 入力完了
sort(A, A + X, greater<ll>());
sort(B, B + Y, greater<ll>());
sort(C, C + Z, greater<ll>());
ll i_d = 0;
for (ll i = 0; i < X; i++) {
for (ll j = 0; j < Y; j++) {
D[i_d++] = A[i] + B[j];
}
}
sort(D, D + i_d, greater<ll>());
ll i_e = 0;
for (ll i = 0; i < K; i++) {
for (ll j = 0; j < Z; j++) {
E[i_e++] = D[i] + C[j];
}
}
sort(E, E + i_e, greater<ll>());
for (ll i = 0; i < K; i++) {
cout << E[i] << endl;
}
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int X, Y, Z, K;
std::cin >> X >> Y >> Z >> K;
std::vector<long long> A(X);
std::vector<long long> B(Y);
std::vector<long long> C(Z);
std::vector<long long> AB;
std::vector<long long> ABt;
std::vector<long long> ABC;
for (int i = 0; i < X; i++)
std::cin >> A[i];
;
for (int i = 0; i < Y; i++)
std::cin >> B[i];
;
for (int i = 0; i < Z; i++)
std::cin >> C[i];
;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end());
reverse(AB.begin(), AB.end());
ABt.assign(&AB[0], &AB[K - 1]);
for (int i = 0; i < K; i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(ABt[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end());
reverse(ABC.begin(), ABC.end());
for (int i = 0; i < K; i++)
std::cout << ABC[i] << '\n';
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
int X, Y, Z, K;
std::cin >> X >> Y >> Z >> K;
std::vector<long long> A(X);
std::vector<long long> B(Y);
std::vector<long long> C(Z);
std::vector<long long> AB;
std::vector<long long> ABt;
std::vector<long long> ABC;
for (int i = 0; i < X; i++)
std::cin >> A[i];
;
for (int i = 0; i < Y; i++)
std::cin >> B[i];
;
for (int i = 0; i < Z; i++)
std::cin >> C[i];
;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end());
reverse(AB.begin(), AB.end());
for (int i = 0; i < min(X * Y, K); i++)
ABt.push_back(AB[i]);
for (int i = 0; i < min(X * Y, K); i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(ABt[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end());
reverse(ABC.begin(), ABC.end());
for (int i = 0; i < K; i++)
std::cout << ABC[i] << '\n';
return 0;
} | replace | 31 | 33 | 31 | 34 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pii;
typedef vector<ll> Vi;
typedef vector<Vi> VVi;
const double EPS = (1e-7);
const ll INF = (1e13);
const double PI = (acos(-1));
const ll MOD = ll(1e9) + 7;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = n; i > -1; i--)
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
// chmax(a, b): a>bならaをbで更新 更新したときにtrueを返す
// chmin(a, b): a<bならaをbで更新 更新したときにtrueを返す
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define dump(x) cerr << #x << "= " << (x) << endl;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll pow(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0)
return pow(a * a, b / 2);
else
return pow(a * a, b / 2) * a;
}
ll pow(ll a, ll b, ll m) {
if (b == 0)
return 1;
else if (a == 0)
return 0;
else if (b % 2 == 0)
return (pow((a * a) % m, b / 2, m) % m);
else
return (pow((a * a) % m, b / 2, m) * a) % m;
}
ll residue(ll a, ll m) { return ((a % m) + m) % m; };
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
map<ll, ll> dp;
ll bs(ll n, const Vi &P, const Vi &Q) {
// p, q: sorted. return #(p, q) : P[p] + Q[q] >= n
if (dp.find(n) != dp.end())
return dp[n];
ll ans = 0;
for (auto &p : P) {
ans += Q.end() - lower_bound(Q.begin(), Q.end(), n - p);
}
dp[n] = ans;
return ans;
}
ll x, y, z, K;
Vi a, b, c, ab;
int main() {
cin >> x >> y >> z >> K;
a.resize(x);
b.resize(y);
c.resize(z);
REP(i, x) cin >> a[i];
REP(i, y) cin >> b[i];
REP(i, z) cin >> c[i];
REP(i, x) {
REP(j, y) { ab.pb(a[i] + b[j]); }
}
SORT(a);
SORT(b), SORT(c);
SORT(ab);
ab.erase(ab.begin(), ab.end() - K - 1);
ll max_sum = a[x - 1] + b[y - 1] + c[z - 1] + 1;
ll temp = 0;
Vi ans(K);
for (ll k = K - 1; k >= 0; k--) {
// a + b + c >= n となる(a, b, c)がk個以上ある最大のnを2分探索.
ll lb = temp, ub = max_sum;
while (ub - lb > 1) {
ll mid = (lb + ub) / 2;
(bs(mid, c, ab) <= k) ? ub = mid : lb = mid;
}
ans[k] = lb;
temp = lb;
}
REP(k, K) cout << ans[k] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pii;
typedef vector<ll> Vi;
typedef vector<Vi> VVi;
const double EPS = (1e-7);
const ll INF = (1e13);
const double PI = (acos(-1));
const ll MOD = ll(1e9) + 7;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = n; i > -1; i--)
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
// chmax(a, b): a>bならaをbで更新 更新したときにtrueを返す
// chmin(a, b): a<bならaをbで更新 更新したときにtrueを返す
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define dump(x) cerr << #x << "= " << (x) << endl;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll pow(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0)
return pow(a * a, b / 2);
else
return pow(a * a, b / 2) * a;
}
ll pow(ll a, ll b, ll m) {
if (b == 0)
return 1;
else if (a == 0)
return 0;
else if (b % 2 == 0)
return (pow((a * a) % m, b / 2, m) % m);
else
return (pow((a * a) % m, b / 2, m) * a) % m;
}
ll residue(ll a, ll m) { return ((a % m) + m) % m; };
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
map<ll, ll> dp;
ll bs(ll n, const Vi &P, const Vi &Q) {
// p, q: sorted. return #(p, q) : P[p] + Q[q] >= n
if (dp.find(n) != dp.end())
return dp[n];
ll ans = 0;
for (auto &p : P) {
ans += Q.end() - lower_bound(Q.begin(), Q.end(), n - p);
}
dp[n] = ans;
return ans;
}
ll x, y, z, K;
Vi a, b, c, ab;
int main() {
cin >> x >> y >> z >> K;
a.resize(x);
b.resize(y);
c.resize(z);
REP(i, x) cin >> a[i];
REP(i, y) cin >> b[i];
REP(i, z) cin >> c[i];
REP(i, x) {
REP(j, y) { ab.pb(a[i] + b[j]); }
}
SORT(a);
SORT(b), SORT(c);
SORT(ab);
if (ab.size() >= K + 2) {
ab.erase(ab.begin(), ab.end() - K - 1);
}
ll max_sum = a[x - 1] + b[y - 1] + c[z - 1] + 1;
ll temp = 0;
Vi ans(K);
for (ll k = K - 1; k >= 0; k--) {
// a + b + c >= n となる(a, b, c)がk個以上ある最大のnを2分探索.
ll lb = temp, ub = max_sum;
while (ub - lb > 1) {
ll mid = (lb + ub) / 2;
(bs(mid, c, ab) <= k) ? ub = mid : lb = mid;
}
ans[k] = lb;
temp = lb;
}
REP(k, K) cout << ans[k] << endl;
}
| replace | 96 | 97 | 96 | 99 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> A(x), B(y), C(z);
rep(i, x) { cin >> A[i]; }
rep(i, y) { cin >> B[i]; }
rep(i, k) { cin >> C[i]; }
vector<ll> AB(max(3000ll, x * y));
rep(i, x) {
rep(j, y) { AB[y * i + j] = A[i] + B[j]; }
}
sort(AB.begin(), AB.end(), greater<ll>());
vector<ll> ABC(AB.size() * y);
rep(i, 3000) {
rep(j, y) { ABC[i * y + j] = AB[i] + C[j]; }
}
sort(ABC.begin(), ABC.end(), greater<ll>());
rep(i, k) { cout << ABC[i] << "\n"; }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> A(x), B(y), C(z);
rep(i, x) { cin >> A[i]; }
rep(i, y) { cin >> B[i]; }
rep(i, k) { cin >> C[i]; }
vector<ll> AB(max(3000ll, x * y));
rep(i, x) {
rep(j, y) { AB[y * i + j] = A[i] + B[j]; }
}
sort(AB.begin(), AB.end(), greater<ll>());
vector<ll> ABC(3000 * y);
rep(i, 3000) {
rep(j, y) { ABC[i * y + j] = AB[i] + C[j]; }
}
sort(ABC.begin(), ABC.end(), greater<ll>());
rep(i, k) { cout << ABC[i] << "\n"; }
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> X >> K;
vll A(X), B(Y), C(Z);
for (int i = 0; i < X; ++i) {
ll a;
cin >> a;
A[i] = a;
}
for (int i = 0; i < Y; ++i) {
ll b;
cin >> b;
B[i] = b;
}
for (int i = 0; i < Z; ++i) {
ll c;
cin >> c;
C[i] = c;
}
vll partial_sum;
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
ll s = A[i] + B[j];
partial_sum.push_back(s);
}
}
sort(partial_sum.begin(), partial_sum.end(), greater<ll>());
vll ans;
int K_ = min(K, X * Y);
for (int i = 0; i < K_; ++i) {
for (int j = 0; j < Z; ++j) {
ll t = partial_sum[i] + C[j];
ans.push_back(t);
}
}
sort(ans.begin(), ans.end(), greater<ll>());
for (int i = 0; i < K; ++i) {
cout << ans[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vll A(X), B(Y), C(Z);
for (int i = 0; i < X; ++i) {
ll a;
cin >> a;
A[i] = a;
}
for (int i = 0; i < Y; ++i) {
ll b;
cin >> b;
B[i] = b;
}
for (int i = 0; i < Z; ++i) {
ll c;
cin >> c;
C[i] = c;
}
vll partial_sum;
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
ll s = A[i] + B[j];
partial_sum.push_back(s);
}
}
sort(partial_sum.begin(), partial_sum.end(), greater<ll>());
vll ans;
int K_ = min(K, X * Y);
for (int i = 0; i < K_; ++i) {
for (int j = 0; j < Z; ++j) {
ll t = partial_sum[i] + C[j];
ans.push_back(t);
}
}
sort(ans.begin(), ans.end(), greater<ll>());
for (int i = 0; i < K; ++i) {
cout << ans[i] << endl;
}
return 0;
} | replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vll A, B, C;
for (int i = 0; i < X; ++i) {
ll a;
cin >> a;
A.push_back(a);
}
for (int i = 0; i < Y; ++i) {
ll b;
cin >> b;
B.push_back(b);
}
for (int i = 0; i < Z; ++i) {
ll c;
cin >> c;
C.push_back(c);
}
sort(A.begin(), A.end(), greater<ll>());
sort(B.begin(), B.end(), greater<ll>());
sort(C.begin(), C.end(), greater<ll>());
vll D;
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
D.push_back(A[i] + B[j]);
}
}
sort(D.begin(), D.end(), greater<ll>());
vll E;
int K_ = min(K, X * Y);
for (int i = 0; i < K_; ++i) {
for (int j = 0; j < Z; ++j) {
E.push_back(D[i] + E[j]);
}
}
sort(E.begin(), E.end(), greater<ll>());
for (int i = 0; i < K; ++i) {
cout << E[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vll A, B, C;
for (int i = 0; i < X; ++i) {
ll a;
cin >> a;
A.push_back(a);
}
for (int i = 0; i < Y; ++i) {
ll b;
cin >> b;
B.push_back(b);
}
for (int i = 0; i < Z; ++i) {
ll c;
cin >> c;
C.push_back(c);
}
sort(A.begin(), A.end(), greater<ll>());
sort(B.begin(), B.end(), greater<ll>());
sort(C.begin(), C.end(), greater<ll>());
vll D;
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
D.push_back(A[i] + B[j]);
}
}
sort(D.begin(), D.end(), greater<ll>());
vll E;
int K_ = min(K, X * Y);
for (int i = 0; i < K_; ++i) {
for (int j = 0; j < Z; ++j) {
E.push_back(D[i] + C[j]);
}
}
sort(E.begin(), E.end(), greater<ll>());
for (int i = 0; i < K; ++i) {
cout << E[i] << endl;
}
return 0;
} | replace | 43 | 44 | 43 | 44 | -11 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long X, Y, Z, K, A[1009], B[1009], C[1009];
vector<long long> vec;
int main() {
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++)
cin >> A[i];
sort(A, A + X, greater<long long>());
for (int i = 0; i < Y; i++)
cin >> B[i];
sort(B, B + Y, greater<long long>());
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(C, C + Z, greater<long long>());
for (int i = 0; i <= K; i++) {
for (int j = 0; j <= K; j++) {
for (int k = 0; k <= K; k++) {
if ((i + 1) * (j + 1) * (k + 1) <= K)
vec.push_back(A[i] + B[j] + C[k]);
else
break;
}
}
}
sort(vec.begin(), vec.end(), greater<long long>());
for (int i = 0; i < K; i++)
cout << vec[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long X, Y, Z, K, A[1009], B[1009], C[1009];
vector<long long> vec;
int main() {
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++)
cin >> A[i];
sort(A, A + X, greater<long long>());
for (int i = 0; i < Y; i++)
cin >> B[i];
sort(B, B + Y, greater<long long>());
for (int i = 0; i < Z; i++)
cin >> C[i];
sort(C, C + Z, greater<long long>());
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) * (k + 1) <= K)
vec.push_back(A[i] + B[j] + C[k]);
else
break;
}
}
}
sort(vec.begin(), vec.end(), greater<long long>());
for (int i = 0; i < K; i++)
cout << vec[i] << endl;
return 0;
}
| replace | 18 | 21 | 18 | 21 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for (int i = s; i <= e; i++)
#define FORR(i, s, e) for (int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9 lli 9.2E±18 double 1.7E±380
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<LLI> a(X), b(Y), c(Z);
REP(i, X) { cin >> a[i]; }
RSORT(a);
REP(i, Y) { cin >> b[i]; }
RSORT(b);
REP(i, Z) { cin >> c[i]; }
RSORT(c);
vector<LLI> v;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) * (k + 1) < K)
v.push_back(a[i] + b[j] + c[k]);
else
break;
}
}
}
RSORT(v);
REP(i, K) { cout << v[i] << endl; }
return 0;
} | #include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for (int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for (int i = s; i <= e; i++)
#define FORR(i, s, e) for (int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9 lli 9.2E±18 double 1.7E±380
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<LLI> a(X), b(Y), c(Z);
REP(i, X) { cin >> a[i]; }
RSORT(a);
REP(i, Y) { cin >> b[i]; }
RSORT(b);
REP(i, Z) { cin >> c[i]; }
RSORT(c);
vector<LLI> v;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) * (k + 1) <= K)
v.push_back(a[i] + b[j] + c[k]);
else
break;
}
}
}
RSORT(v);
REP(i, K) { cout << v[i] << endl; }
return 0;
} | replace | 42 | 43 | 42 | 43 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef int64_t SI;
typedef uint64_t UI;
void read(SI &N, vector<SI> &V) {
cin >> N;
V.resize(N);
for (size_t i = 0; i < N; i++) {
SI x;
cin >> x;
V[i] = x;
}
}
int solve(const vector<SI> &V) { return 0; }
void test() {
{
vector<UI> A = {4, 6};
vector<UI> B = {1, 5};
vector<UI> C = {3, 8};
UI K = 8;
vector<SI> V = {0, 1, 2};
assert(solve(V) == 0);
}
cerr << "OK" << endl;
}
int main() {
UI X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<UI> A(X), B(Y), C(Z);
for (SI i = 0; i < X; i++) {
cin >> A[i];
}
for (SI i = 0; i < Y; i++) {
cin >> B[i];
}
for (SI i = 0; i < Z; i++) {
cin >> C[i];
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
sort(B.begin(), B.end());
reverse(B.begin(), B.end());
sort(C.begin(), C.end());
reverse(C.begin(), C.end());
vector<UI> ABC;
for (size_t i = 0; i < X; i++) {
for (size_t j = 0; j < Y; j++) {
if ((i + 1) * (j + 1) > K)
break;
for (size_t k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) + (k + 1) > K)
break;
ABC.push_back(A[i] + B[j] + C[k]);
}
}
}
sort(ABC.begin(), ABC.end());
reverse(ABC.begin(), ABC.end());
for (size_t i = 0; i < K; i++) {
cout << ABC[i] << std::endl;
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef int64_t SI;
typedef uint64_t UI;
void read(SI &N, vector<SI> &V) {
cin >> N;
V.resize(N);
for (size_t i = 0; i < N; i++) {
SI x;
cin >> x;
V[i] = x;
}
}
int solve(const vector<SI> &V) { return 0; }
void test() {
{
vector<UI> A = {4, 6};
vector<UI> B = {1, 5};
vector<UI> C = {3, 8};
UI K = 8;
vector<SI> V = {0, 1, 2};
assert(solve(V) == 0);
}
cerr << "OK" << endl;
}
int main() {
UI X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<UI> A(X), B(Y), C(Z);
for (SI i = 0; i < X; i++) {
cin >> A[i];
}
for (SI i = 0; i < Y; i++) {
cin >> B[i];
}
for (SI i = 0; i < Z; i++) {
cin >> C[i];
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
sort(B.begin(), B.end());
reverse(B.begin(), B.end());
sort(C.begin(), C.end());
reverse(C.begin(), C.end());
vector<UI> ABC;
for (size_t i = 0; i < X; i++) {
for (size_t j = 0; j < Y; j++) {
if ((i + 1) * (j + 1) > K)
break;
for (size_t k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) * (k + 1) > K)
break;
ABC.push_back(A[i] + B[j] + C[k]);
}
}
}
sort(ABC.begin(), ABC.end());
reverse(ABC.begin(), ABC.end());
for (size_t i = 0; i < K; i++) {
cout << ABC[i] << std::endl;
}
return 0;
}
| replace | 62 | 63 | 62 | 63 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<long long> A(x);
vector<long long> B(y);
vector<long long> C(z);
for (int i = 0; i < x; i++) {
cin >> A[i];
}
for (int i = 0; i < y; i++) {
cin >> B[i];
}
for (int i = 0; i < z; i++) {
cin >> C[i];
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
reverse(A.begin(), A.end());
reverse(B.begin(), B.end());
vector<long long> AB(x * y);
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
AB[i * y + j] = A[i] + B[j];
}
}
sort(AB.begin(), AB.end());
reverse(AB.begin(), AB.end());
int s = max(3000, x * y);
vector<long long> ABC(s * z);
for (int i = 0; i < s; i++) {
for (int j = 0; j < z; j++) {
ABC[i * z + j] = AB[i] + C[j];
}
}
sort(ABC.begin(), ABC.end());
reverse(ABC.begin(), ABC.end());
for (int i = 0; i < k; i++) {
cout << ABC[i] << endl;
}
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
vector<long long> A(x);
vector<long long> B(y);
vector<long long> C(z);
for (int i = 0; i < x; i++) {
cin >> A[i];
}
for (int i = 0; i < y; i++) {
cin >> B[i];
}
for (int i = 0; i < z; i++) {
cin >> C[i];
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
reverse(A.begin(), A.end());
reverse(B.begin(), B.end());
vector<long long> AB(x * y);
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
AB[i * y + j] = A[i] + B[j];
}
}
sort(AB.begin(), AB.end());
reverse(AB.begin(), AB.end());
int s = min(k, x * y);
vector<long long> ABC(s * z);
for (int i = 0; i < s; i++) {
for (int j = 0; j < z; j++) {
ABC[i * z + j] = AB[i] + C[j];
}
}
sort(ABC.begin(), ABC.end());
reverse(ABC.begin(), ABC.end());
for (int i = 0; i < k; i++) {
cout << ABC[i] << endl;
}
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X), B(Y), C(Z);
for (int i = 0; i < X; i++) {
cin >> A[i];
}
for (int i = 0; i < Y; i++) {
cin >> B[i];
}
for (int i = 0; i < Z; i++) {
cin >> C[i];
}
sort(A.rbegin(), A.rend());
sort(B.rbegin(), B.rend());
sort(C.rbegin(), C.rend());
vector<ll> ans;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) * (k + 1) >= K)
break;
ans.push_back(A[i] + B[j] + C[k]);
}
}
}
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
} | #include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X), B(Y), C(Z);
for (int i = 0; i < X; i++) {
cin >> A[i];
}
for (int i = 0; i < Y; i++) {
cin >> B[i];
}
for (int i = 0; i < Z; i++) {
cin >> C[i];
}
sort(A.rbegin(), A.rend());
sort(B.rbegin(), B.rend());
sort(C.rbegin(), C.rend());
vector<ll> ans;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
for (int k = 0; k < Z; k++) {
if ((i + 1) * (j + 1) * (k + 1) > K)
break;
ans.push_back(A[i] + B[j] + C[k]);
}
}
}
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
} | replace | 27 | 28 | 27 | 28 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int x, y, z, q;
cin >> x >> y >> z >> q;
vector<long long> a(x), b(y), c(z);
rep(i, x) cin >> a.at(i);
rep(i, y) cin >> b.at(i);
rep(i, z) cin >> c.at(i);
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
sort(c.begin(), c.end());
reverse(c.begin(), c.end());
vector<long long> u(0);
rep(i, x) {
rep(j, y) {
rep(k, z) {
if (x * y * z > 3000)
break;
u.push_back(a.at(i) + b.at(j) + c.at(k));
}
}
}
sort(u.begin(), u.end());
reverse(u.begin(), u.end());
rep(i, q) { cout << u.at(i) << endl; }
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int x, y, z, q;
cin >> x >> y >> z >> q;
vector<long long> a(x), b(y), c(z);
rep(i, x) cin >> a.at(i);
rep(i, y) cin >> b.at(i);
rep(i, z) cin >> c.at(i);
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
sort(c.begin(), c.end());
reverse(c.begin(), c.end());
vector<long long> u(0);
rep(i, x) {
rep(j, y) {
rep(k, z) {
if (i * j * k > 3000)
break;
u.push_back(a.at(i) + b.at(j) + c.at(k));
}
}
}
sort(u.begin(), u.end());
reverse(u.begin(), u.end());
rep(i, q) { cout << u.at(i) << endl; }
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
long A[X], B[Y], C[Z];
vector<long> A_and_B, result;
for (int i = 0; i < K; i++) {
A_and_B[i] = 0;
result[i] = 0;
}
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
for (int i = 0; i < X; i++)
for (int j = 0; j < Y; j++)
A_and_B.push_back(A[i] + B[j]);
sort(A_and_B.begin(), A_and_B.end(), greater<>());
A_and_B.resize(K);
for (int i = 0; i < K; i++)
for (int j = 0; j < Z; j++)
result.push_back(A_and_B[i] + C[j]);
sort(result.begin(), result.end(), greater<>());
result.resize(K);
for (int i = 0; i < K; i++)
cout << result[i] << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
long A[X], B[Y], C[Z];
vector<long> A_and_B, result;
for (int i = 0; i < X; i++)
cin >> A[i];
for (int i = 0; i < Y; i++)
cin >> B[i];
for (int i = 0; i < Z; i++)
cin >> C[i];
for (int i = 0; i < X; i++)
for (int j = 0; j < Y; j++)
A_and_B.push_back(A[i] + B[j]);
sort(A_and_B.begin(), A_and_B.end(), greater<>());
A_and_B.resize(K);
for (int i = 0; i < K; i++)
for (int j = 0; j < Z; j++)
result.push_back(A_and_B[i] + C[j]);
sort(result.begin(), result.end(), greater<>());
result.resize(K);
for (int i = 0; i < K; i++)
cout << result[i] << endl;
} | delete | 10 | 14 | 10 | 10 | -11 | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define cout16 cout << setprecision(16)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int, int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
int main(void) {
int nx, ny, nz, k;
cin >> nx >> ny >> nz >> k;
vll a(nx), b(ny), c(nz);
rep(ix, nx) cin >> a[ix];
rep(iy, ny) cin >> b[iy];
rep(iz, nz) cin >> c[iz];
vll e;
rep(ix, nx) rep(iy, ny) e.push_back(a[ix] + b[iy]);
SORT(e);
REV(e);
vll f;
rep(ie, nx * ny) rep(iz, nz) f.push_back(e[ie] + c[iz]);
SORT(f);
REV(f);
rep(i, k) cout << f[i] << endl;
}
| #include <bits/stdc++.h>
#define cout16 cout << setprecision(16)
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define MAX(A) *max_element(A.begin(), A.end())
#define MIN(A) *min_element(A.begin(), A.end())
#define SORT(A) sort(A.begin(), A.end())
#define REV(A) reverse(A.begin(), A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int, int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
int main(void) {
int nx, ny, nz, k;
cin >> nx >> ny >> nz >> k;
vll a(nx), b(ny), c(nz);
rep(ix, nx) cin >> a[ix];
rep(iy, ny) cin >> b[iy];
rep(iz, nz) cin >> c[iz];
vll e;
rep(ix, nx) rep(iy, ny) e.push_back(a[ix] + b[iy]);
SORT(e);
REV(e);
vll f;
rep(ie, min(k, nx * ny)) rep(iz, nz) f.push_back(e[ie] + c[iz]);
SORT(f);
REV(f);
rep(i, k) cout << f[i] << endl;
}
| replace | 33 | 34 | 33 | 34 | TLE | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int x, y, z, kk;
long long a[1005], b[1005], c[1005];
long long ans[10005];
int cur = 0;
bool cmp(long long a1, long long a2) { return a1 > a2; }
int main()
{
ios::sync_with_stdio(false);
cin >> x >> y >> z >> kk;
for (int i = 1; i <= x; i++)
cin >> a[i];
for (int i = 1; i <= y; i++)
cin >> b[i];
for (int i = 1; i <= z; i++)
cin >> c[i];
sort(a + 1, a + 1 + x, cmp);
sort(b + 1, b + 1 + y, cmp);
sort(c + 1, c + 1 + z, cmp);
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
for (int k = 1; k <= z; k++) {
if (i * j * k > kk)
break;
ans[++cur] = a[i] + b[j] + c[k];
}
}
}
sort(ans + 1, ans + cur + 1, cmp);
for (int i = 1; i <= kk; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int x, y, z, kk;
long long a[1005], b[1005], c[1005];
long long ans[1000005];
int cur = 0;
bool cmp(long long a1, long long a2) { return a1 > a2; }
int main()
{
ios::sync_with_stdio(false);
cin >> x >> y >> z >> kk;
for (int i = 1; i <= x; i++)
cin >> a[i];
for (int i = 1; i <= y; i++)
cin >> b[i];
for (int i = 1; i <= z; i++)
cin >> c[i];
sort(a + 1, a + 1 + x, cmp);
sort(b + 1, b + 1 + y, cmp);
sort(c + 1, c + 1 + z, cmp);
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
for (int k = 1; k <= z; k++) {
if (i * j * k > kk)
break;
ans[++cur] = a[i] + b[j] + c[k];
}
}
}
sort(ans + 1, ans + cur + 1, cmp);
for (int i = 1; i <= kk; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ll ans[2010] = {0};
int x, y, z, n, fir, i, j, k;
ll a[1010], b[1010], c[1010];
scanf("%d%d%d%d", &x, &y, &z, &n);
for (i = 0; i < x; i++)
scanf("%lld", &a[i]);
for (i = 0; i < y; i++)
scanf("%lld", &b[i]);
for (i = 0; i < z; i++)
scanf("%lld", &c[i]);
sort(a, a + x);
sort(b, b + y);
sort(c, c + z);
fir = 0;
for (i = x - 1; i >= 0; i--) {
if (x - i - 1 >= n)
break;
for (j = y - 1; j >= 0; j--) {
if (y - j - 1 >= n)
break;
for (k = z - 1; k >= 0; k--) {
if (z - k - 1 >= n)
break;
ans[fir] = a[i] + b[j] + c[k];
if (ans[fir] <= ans[n])
break;
else
fir++;
if (fir == n) {
sort(ans, ans + 2 * n);
fir = 0;
}
}
}
}
sort(ans, ans + 2 * n);
for (i = 2 * n - 1; i >= n; i--)
printf("%lld\n", ans[i]);
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ll ans[6010] = {0};
int x, y, z, n, fir, i, j, k;
ll a[1010], b[1010], c[1010];
scanf("%d%d%d%d", &x, &y, &z, &n);
for (i = 0; i < x; i++)
scanf("%lld", &a[i]);
for (i = 0; i < y; i++)
scanf("%lld", &b[i]);
for (i = 0; i < z; i++)
scanf("%lld", &c[i]);
sort(a, a + x);
sort(b, b + y);
sort(c, c + z);
fir = 0;
for (i = x - 1; i >= 0; i--) {
if (x - i - 1 >= n)
break;
for (j = y - 1; j >= 0; j--) {
if (y - j - 1 >= n)
break;
for (k = z - 1; k >= 0; k--) {
if (z - k - 1 >= n)
break;
ans[fir] = a[i] + b[j] + c[k];
if (ans[fir] <= ans[n])
break;
else
fir++;
if (fir == n) {
sort(ans, ans + 2 * n);
fir = 0;
}
}
}
}
sort(ans, ans + 2 * n);
for (i = 2 * n - 1; i >= n; i--)
printf("%lld\n", ans[i]);
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
const int N = 3e6 + 9;
long long ar[N], br[N], cr[N], dr[N], er[N], x, y, z, k, pos = 0, val = 0;
using namespace std;
signed main()
{
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> ar[i];
for (int i = 0; i < y; i++)
cin >> br[i];
for (int i = 0; i < z; i++)
cin >> cr[i];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
dr[pos++] = ar[i] + br[j];
}
}
sort(dr, dr + pos);
reverse(dr, dr + pos);
sort(cr, cr + z);
reverse(cr, cr + z);
for (int i = 0; i < pos; i++) {
for (int j = 0; j < z; j++) {
er[val++] = dr[i] + cr[j];
}
}
sort(er, er + val);
reverse(er, er + val);
for (int i = 0; i < k; i++)
cout << er[i] << "\n";
} | #include <bits/stdc++.h>
#define int long long
const int N = 3e6 + 9;
long long ar[N], br[N], cr[N], dr[N], er[N], x, y, z, k, pos = 0, val = 0;
using namespace std;
signed main()
{
cin >> x >> y >> z >> k;
for (int i = 0; i < x; i++)
cin >> ar[i];
for (int i = 0; i < y; i++)
cin >> br[i];
for (int i = 0; i < z; i++)
cin >> cr[i];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
dr[pos++] = ar[i] + br[j];
}
}
sort(dr, dr + pos);
reverse(dr, dr + pos);
sort(cr, cr + z);
reverse(cr, cr + z);
for (int i = 0; i < z; i++) {
for (int j = 0; j < k; j++) {
er[val++] = dr[j] + cr[i];
}
}
sort(er, er + val);
reverse(er, er + val);
for (int i = 0; i < k; i++)
cout << er[i] << "\n";
} | replace | 29 | 32 | 29 | 32 | -11 | |
p03078 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> AB;
vector<ll> ABC;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll X, Y, Z, K;
cin >> X >> Y >> Z >> K;
ll A[X], B[Y], C[Z];
for (int i = 0; i < X; ++i) {
cin >> A[i];
}
for (int i = 0; i < Y; ++i) {
cin >> B[i];
}
for (int i = 0; i < Z; ++i) {
cin >> C[i];
}
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.rbegin(), AB.rend());
for (int i = 0; i < X * Y; ++i) {
for (int j = 0; j < Z; ++j) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.rbegin(), ABC.rend());
for (int i = 0; i < K; ++i) {
cout << ABC[i] << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> AB;
vector<ll> ABC;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll X, Y, Z, K;
cin >> X >> Y >> Z >> K;
ll A[X], B[Y], C[Z];
for (int i = 0; i < X; ++i) {
cin >> A[i];
}
for (int i = 0; i < Y; ++i) {
cin >> B[i];
}
for (int i = 0; i < Z; ++i) {
cin >> C[i];
}
for (int i = 0; i < X; ++i) {
for (int j = 0; j < Y; ++j) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.rbegin(), AB.rend());
int ab_length = min(K, X * Y);
for (int i = 0; i < ab_length; ++i) {
for (int j = 0; j < Z; ++j) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.rbegin(), ABC.rend());
for (int i = 0; i < K; ++i) {
cout << ABC[i] << '\n';
}
return 0;
}
| replace | 33 | 34 | 33 | 35 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
#define writeln(n) cout << n << "\n"
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;
typedef pair<string, int> Psi;
vector<ll> A(1010), B(1010), C(1010);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
rep(i, x) { cin >> A[i]; }
rep(i, y) { cin >> B[i]; }
rep(i, z) { cin >> C[i]; }
sort(A.begin(), A.end(), greater<ll>());
sort(B.begin(), B.end(), greater<ll>());
sort(C.begin(), C.end(), greater<ll>());
vector<ll> ans;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int l = 0; l < z; l++) {
if ((i + 1) + (j + 1) + (l + 1) > k)
break;
ans.push_back(A[i] + B[j] + C[l]);
}
}
}
sort(ans.begin(), ans.end(), greater<ll>());
rep(i, k) { writeln(ans[i]); }
}
| #include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
#define writeln(n) cout << n << "\n"
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;
typedef pair<string, int> Psi;
vector<ll> A(1010), B(1010), C(1010);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int x, y, z, k;
cin >> x >> y >> z >> k;
rep(i, x) { cin >> A[i]; }
rep(i, y) { cin >> B[i]; }
rep(i, z) { cin >> C[i]; }
sort(A.begin(), A.end(), greater<ll>());
sort(B.begin(), B.end(), greater<ll>());
sort(C.begin(), C.end(), greater<ll>());
vector<ll> ans;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int l = 0; l < z; l++) {
if ((i + 1) * (j + 1) * (l + 1) > k)
break;
ans.push_back(A[i] + B[j] + C[l]);
}
}
}
sort(ans.begin(), ans.end(), greater<ll>());
rep(i, k) { writeln(ans[i]); }
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p03078 | C++ | Runtime Error | /*
* Author: windystreet
* Date : 2019-04-13 11:07:49
* Motto : Think twice, code once.
*/
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define eps 1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x) & (-x)
#define bug printf("!!!!!\n");
#define mem(x, y) memset(x, y, sizeof(x))
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
const int maxn = 1e5 + 7;
const int INF = 1 << 30;
const int mod = 1e9 + 7;
long long A[maxn];
long long B[maxn];
long long C[maxn];
bool cmp(long long a, long long b) { return a > b; }
vector<long long> ans;
void solve() {
long long x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 1; i <= x; i++) {
cin >> A[i];
}
for (int i = 1; i <= y; i++)
cin >> B[i];
for (int i = 1; i <= z; i++)
cin >> C[i];
sort(A + 1, A + 1 + x, cmp);
sort(B + 1, B + 1 + y, cmp);
sort(C + 1, C + 1 + z, cmp);
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
for (int c = 1; c <= z; c++) {
ans.pb(A[i] + B[j] + C[c]);
}
}
}
sort(ans.begin(), ans.end(), cmp);
for (int i = 0; i < k; i++) {
printf("%lld\n", ans[i]);
}
return;
}
int main() {
#ifndef ONLINE_JUDGE
// freopen("F:/in.txt","r",stdin);
#endif
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
int t = 1;
// scanf("%d",&t);
while (t--) {
// printf("Case %d: ",cas++);
solve();
}
return 0;
} | /*
* Author: windystreet
* Date : 2019-04-13 11:07:49
* Motto : Think twice, code once.
*/
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define eps 1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x) & (-x)
#define bug printf("!!!!!\n");
#define mem(x, y) memset(x, y, sizeof(x))
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
const int maxn = 1e5 + 7;
const int INF = 1 << 30;
const int mod = 1e9 + 7;
long long A[maxn];
long long B[maxn];
long long C[maxn];
bool cmp(long long a, long long b) { return a > b; }
vector<long long> ans;
void solve() {
long long x, y, z, k;
cin >> x >> y >> z >> k;
for (int i = 1; i <= x; i++) {
cin >> A[i];
}
for (int i = 1; i <= y; i++)
cin >> B[i];
for (int i = 1; i <= z; i++)
cin >> C[i];
sort(A + 1, A + 1 + x, cmp);
sort(B + 1, B + 1 + y, cmp);
sort(C + 1, C + 1 + z, cmp);
for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
for (int c = 1; c <= z; c++) {
if (i * j * c > k)
break;
ans.pb(A[i] + B[j] + C[c]);
}
}
}
sort(ans.begin(), ans.end(), cmp);
for (int i = 0; i < k; i++) {
printf("%lld\n", ans[i]);
}
return;
}
int main() {
#ifndef ONLINE_JUDGE
// freopen("F:/in.txt","r",stdin);
#endif
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
int t = 1;
// scanf("%d",&t);
while (t--) {
// printf("Case %d: ",cas++);
solve();
}
return 0;
} | insert | 50 | 50 | 50 | 52 | 0 | |
p03078 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
signed main() {
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
int x, y, z, k;
cin >> x >> y >> z >> k;
int a[114514], b[114514], c[114514];
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
vector<int> ab;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end(), greater<int>());
sort(c, c + z, greater<int>());
vector<P> com;
int cnt = 1;
while (1) {
int m = com.size();
for (int i = m - 1; i >= m - cnt + 1; i--) {
com.push_back(make_pair(com[i].first, com[i].second + 1));
}
com.push_back(make_pair(cnt, 1));
cnt++;
if (cnt == k + 1)
break;
}
vector<int> ans;
for (int i = 0; i < com.size(); i++) {
if (com[i].first - 1 < ab.size() && com[i].second - 1 < z) {
ans.push_back(ab[com[i].first - 1] + c[com[i].second - 1]);
}
}
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < k; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
signed main() {
int x, y, z, k;
cin >> x >> y >> z >> k;
int a[114514], b[114514], c[114514];
for (int i = 0; i < x; i++)
cin >> a[i];
for (int i = 0; i < y; i++)
cin >> b[i];
for (int i = 0; i < z; i++)
cin >> c[i];
vector<int> ab;
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
ab.push_back(a[i] + b[j]);
}
}
sort(ab.begin(), ab.end(), greater<int>());
sort(c, c + z, greater<int>());
vector<P> com;
int cnt = 1;
while (1) {
int m = com.size();
for (int i = m - 1; i >= m - cnt + 1; i--) {
com.push_back(make_pair(com[i].first, com[i].second + 1));
}
com.push_back(make_pair(cnt, 1));
cnt++;
if (cnt == k + 1)
break;
}
vector<int> ans;
for (int i = 0; i < com.size(); i++) {
if (com[i].first - 1 < ab.size() && com[i].second - 1 < z) {
ans.push_back(ab[com[i].first - 1] + c[com[i].second - 1]);
}
}
sort(ans.rbegin(), ans.rend());
for (int i = 0; i < k; i++) {
cout << ans[i] << endl;
}
return 0;
}
| delete | 22 | 24 | 22 | 22 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03078 | C++ | Time Limit Exceeded | // g++ -std=c++11 a.cpp
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#define loop(i, a, b) for (long long i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define FOR(i, a) for (auto i : a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define show1d(v) \
{ \
rep(_, v.size()) cout << " " << v[_]; \
cout << endl; \
}
#define show2d(v) \
{ rep(__, v.size()) show1d(v[__]); }
using namespace std;
// kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
#define mt make_tuple
typedef tuple<int, int, int> tp;
typedef vector<tp> vt;
template <typename A, typename B> bool cmin(A &a, const B &b) {
return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10;
#define yes \
cout << "YES" \
<< "\n"
#define no \
cout << "NO" \
<< "\n"
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int x, y, z, k;
cin >> x >> y >> z >> k;
vvi in(3);
rep(i, x) {
int a;
cin >> a;
in[0].pb(a);
}
rep(i, y) {
int a;
cin >> a;
in[1].pb(a);
}
rep(i, z) {
int a;
cin >> a;
in[2].pb(a);
}
vi t;
rep(i, x) rep(j, y) t.pb(in[0][i] + in[1][j]);
sort(all(t));
vi nt;
rep(i, min((ll)t.size(), k)) nt.pb(t[t.size() - 1 - i]);
vi out;
rep(i, t.size()) rep(j, z) out.pb(t[i] + in[2][j]);
sort(all(out));
rep(i, k) cout << out[out.size() - 1 - i] << endl;
}
| // g++ -std=c++11 a.cpp
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
#define loop(i, a, b) for (long long i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define FOR(i, a) for (auto i : a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define show1d(v) \
{ \
rep(_, v.size()) cout << " " << v[_]; \
cout << endl; \
}
#define show2d(v) \
{ rep(__, v.size()) show1d(v[__]); }
using namespace std;
// kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
#define mt make_tuple
typedef tuple<int, int, int> tp;
typedef vector<tp> vt;
template <typename A, typename B> bool cmin(A &a, const B &b) {
return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10;
#define yes \
cout << "YES" \
<< "\n"
#define no \
cout << "NO" \
<< "\n"
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int x, y, z, k;
cin >> x >> y >> z >> k;
vvi in(3);
rep(i, x) {
int a;
cin >> a;
in[0].pb(a);
}
rep(i, y) {
int a;
cin >> a;
in[1].pb(a);
}
rep(i, z) {
int a;
cin >> a;
in[2].pb(a);
}
vi t;
rep(i, x) rep(j, y) t.pb(in[0][i] + in[1][j]);
sort(all(t));
vi nt;
rep(i, min((ll)t.size(), k)) nt.pb(t[t.size() - 1 - i]);
vi out;
rep(i, nt.size()) rep(j, z) out.pb(nt[i] + in[2][j]);
sort(all(out));
rep(i, k) cout << out[out.size() - 1 - i] << endl;
}
| replace | 95 | 96 | 95 | 96 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
#define p(var) std::cout << var << std::endl
#define pp(var) std::cout << #var " = " << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
/*-----8<-----8<-----*/
// Standard partition process of QuickSort().
// It considers the last element as pivot
// and moves all smaller element to left of
// it and greater elements to right
template <typename T> int partition(vector<T> &arr, int l, int r) {
T x = arr[r];
int i = l;
for (int j = l; j <= r - 1; j++) {
if (arr[j] >=
x) { // if (arr[j] <= x) { // if (arr[j] >= x) { //降順にしたい時
swap(arr[i], arr[j]);
i++;
}
}
swap(arr[i], arr[r]);
return i;
}
// This function returns k'th smallest
// element in arr[l..r] using QuickSort
// based method. ASSUMPTION: ALL ELEMENTS
// IN ARR[] ARE DISTINCT
template <typename T> T qselect(vector<T> &arr, int l, int r, int k) {
// If k is smaller than number of
// elements in array
if (k > 0 && k <= r - l + 1) {
// Partition the array around last
// element and get position of pivot
// element in sorted array
int index = partition(arr, l, r);
// If position is same as k
if (index - l == k - 1)
return arr[index];
// If position is more, recur
// for left subarray
if (index - l > k - 1)
return qselect(arr, l, index - 1, k);
// Else recur for right subarray
return qselect(arr, index + 1, r, k - index + l - 1);
}
// If k is more than number of
// elements in array
return INT_MAX;
}
// Driver program to test above methods
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> a(X, 0), b(Y, 0), c(Z, 0);
rep(i, X) cin >> a[i];
rep(i, Y) cin >> b[i];
rep(i, Z) cin >> c[i];
sort(all(a), greater<ll>());
sort(all(b), greater<ll>());
sort(all(c), greater<ll>());
vector<ll> v;
rep(i, X) {
rep(j, Y) {
rep(k, Z) {
if ((i + 1) * (j + 1) * (k + 1) > K)
break;
ll tmp = a[i] + b[j] + c[k];
// pp(tmp);
v.pb(tmp);
}
}
}
ll border = qselect(v, 0, v.size() - 1, K);
vector<ll> vv;
int count = 0;
int i = 0;
while (count < K) {
if (border <= v[i]) {
count++;
vv.pb(v[i]);
}
i++;
}
sort(all(vv), greater<ll>());
rep(i, K) p(vv[i]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
#define p(var) std::cout << var << std::endl
#define pp(var) std::cout << #var " = " << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
/*-----8<-----8<-----*/
// Standard partition process of QuickSort().
// It considers the last element as pivot
// and moves all smaller element to left of
// it and greater elements to right
template <typename T> int partition(vector<T> &arr, int l, int r) {
T x = arr[r];
int i = l;
for (int j = l; j <= r - 1; j++) {
if (arr[j] > x) { // if (arr[j] < x) { // if (arr[j] > x) { //降順にしたい時
swap(arr[i], arr[j]);
i++;
}
}
swap(arr[i], arr[r]);
return i;
}
// This function returns k'th smallest
// element in arr[l..r] using QuickSort
// based method. ASSUMPTION: ALL ELEMENTS
// IN ARR[] ARE DISTINCT
template <typename T> T qselect(vector<T> &arr, int l, int r, int k) {
// If k is smaller than number of
// elements in array
if (k > 0 && k <= r - l + 1) {
// Partition the array around last
// element and get position of pivot
// element in sorted array
int index = partition(arr, l, r);
// If position is same as k
if (index - l == k - 1)
return arr[index];
// If position is more, recur
// for left subarray
if (index - l > k - 1)
return qselect(arr, l, index - 1, k);
// Else recur for right subarray
return qselect(arr, index + 1, r, k - index + l - 1);
}
// If k is more than number of
// elements in array
return INT_MAX;
}
// Driver program to test above methods
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> a(X, 0), b(Y, 0), c(Z, 0);
rep(i, X) cin >> a[i];
rep(i, Y) cin >> b[i];
rep(i, Z) cin >> c[i];
sort(all(a), greater<ll>());
sort(all(b), greater<ll>());
sort(all(c), greater<ll>());
vector<ll> v;
rep(i, X) {
rep(j, Y) {
rep(k, Z) {
if ((i + 1) * (j + 1) * (k + 1) > K)
break;
ll tmp = a[i] + b[j] + c[k];
// pp(tmp);
v.pb(tmp);
}
}
}
ll border = qselect(v, 0, v.size() - 1, K);
vector<ll> vv;
int count = 0;
int i = 0;
while (count < K) {
if (border <= v[i]) {
count++;
vv.pb(v[i]);
}
i++;
}
sort(all(vv), greater<ll>());
rep(i, K) p(vv[i]);
return 0;
}
| replace | 25 | 27 | 25 | 26 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define reps(i, s, n) for (int(i) = (s); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define rept(i, n) rep(i, (n) + 1)
#define repst(i, s, n) reps(i, s, (n) + 1)
#define reprt(i, n, t) for (int(i) = (n); (i) >= (t); --(i))
#define repr(i, n) reprt(i, n, 0)
#define each(i, v) for (auto &(i) : (v))
#define eachr(i, v) for (auto &(i) = (v).rbegin(); (i) != (v).rend(); (i)++)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x, y, z) max(x, max(y, z))
#define tmin(x, y, z) min(x, min(y, z))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define ln '\n'
#define bln(i, n) (((i) == (n)-1) ? '\n' : ' ')
#define dbg(x) cout << #x " = " << (x) << ln << flush
#define dbga(x, n) \
{ \
cout << #x " : "; \
for (int(i) = 0; i < (n); ++i) { \
cout << ((x)[i]) << (i == ((n)-1) ? '\n' : ' ') << flush; \
} \
}
#define zero(a) memset(a, 0, sizeof(a))
#define unq(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define endl "\n"
// typedef complex<double> P;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int>> mat;
const ll inf = (ll)1e9 + 10;
const ll linf = (ll)1e18 + 10;
const ll mod = (ll)(1e9 + 7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
ll mop(ll a, ll b, ll m = mod) {
ll r = 1;
a %= m;
for (; b; b >>= 1) {
if (b & 1)
r = r * a % m;
a = a * a % m;
}
return r;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
bool ool(int x, int y, int h, int w) {
return ((x < 0) || (h <= x) || (y < 0) || (w <= y));
}
bool deq(double a, double b) { return abs(a - b) < eps; }
struct oreno_initializer {
oreno_initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} oreno_initializer;
int x, y, z, k, a[1010], b[1010], c[1010], l, r = 3000000001ll;
bool ok(int m) {
int s = 0;
rep(i, x) rep(j, y) {
int t = a[i] + b[j];
int tt = lower_bound(c, c + z, m - t) - c;
s += z - tt;
}
return s >= k;
}
void solve(int m) {
vector<int> res;
rep(i, x) rep(j, y) {
int t = a[i] + b[j];
int tt = lower_bound(c, c + z, m - t) - c;
reps(id, tt, z) res.push_back(t + c[id]);
}
sort(all(res)), reverse(all(res));
rep(i, k) cout << res[i] << endl;
}
signed main() {
cin >> x >> y >> z >> k;
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(a, a + x); //, reverse(a,a+x);
sort(b, b + y); //, reverse(b,b+y);
sort(c, c + z); //, reverse(c,c+z);
while (r - l > 1) {
int m = (l + r) / 2;
(ok(m) ? l : r) = m;
}
solve(l);
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define reps(i, s, n) for (int(i) = (s); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define rept(i, n) rep(i, (n) + 1)
#define repst(i, s, n) reps(i, s, (n) + 1)
#define reprt(i, n, t) for (int(i) = (n); (i) >= (t); --(i))
#define repr(i, n) reprt(i, n, 0)
#define each(i, v) for (auto &(i) : (v))
#define eachr(i, v) for (auto &(i) = (v).rbegin(); (i) != (v).rend(); (i)++)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x, y, z) max(x, max(y, z))
#define tmin(x, y, z) min(x, min(y, z))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define ln '\n'
#define bln(i, n) (((i) == (n)-1) ? '\n' : ' ')
#define dbg(x) cout << #x " = " << (x) << ln << flush
#define dbga(x, n) \
{ \
cout << #x " : "; \
for (int(i) = 0; i < (n); ++i) { \
cout << ((x)[i]) << (i == ((n)-1) ? '\n' : ' ') << flush; \
} \
}
#define zero(a) memset(a, 0, sizeof(a))
#define unq(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define endl "\n"
// typedef complex<double> P;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int>> mat;
const ll inf = (ll)1e9 + 10;
const ll linf = (ll)1e18 + 10;
const ll mod = (ll)(1e9 + 7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
ll mop(ll a, ll b, ll m = mod) {
ll r = 1;
a %= m;
for (; b; b >>= 1) {
if (b & 1)
r = r * a % m;
a = a * a % m;
}
return r;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
bool ool(int x, int y, int h, int w) {
return ((x < 0) || (h <= x) || (y < 0) || (w <= y));
}
bool deq(double a, double b) { return abs(a - b) < eps; }
struct oreno_initializer {
oreno_initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} oreno_initializer;
int x, y, z, k, a[1010], b[1010], c[1010], l, r = 30000000001ll;
bool ok(int m) {
int s = 0;
rep(i, x) rep(j, y) {
int t = a[i] + b[j];
int tt = lower_bound(c, c + z, m - t) - c;
s += z - tt;
}
return s >= k;
}
void solve(int m) {
vector<int> res;
rep(i, x) rep(j, y) {
int t = a[i] + b[j];
int tt = lower_bound(c, c + z, m - t) - c;
reps(id, tt, z) res.push_back(t + c[id]);
}
sort(all(res)), reverse(all(res));
rep(i, k) cout << res[i] << endl;
}
signed main() {
cin >> x >> y >> z >> k;
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
sort(a, a + x); //, reverse(a,a+x);
sort(b, b + y); //, reverse(b,b+y);
sort(c, c + z); //, reverse(c,c+z);
while (r - l > 1) {
int m = (l + r) / 2;
(ok(m) ? l : r) = m;
}
solve(l);
}
| replace | 92 | 93 | 92 | 93 | TLE | |
p03078 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int
// i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
using namespace std;
// using namespace __gnu_pbds;
#define pb push_back
#define eb emplace_back
#define mp(x, y) make_pair(x, y)
#define mod 1000000007
double PI = 3.1415926535897932384626;
// template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL)
// ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
#define bip(n) __builtin_popcount(n) // no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n) // no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n) // no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n) // index of first one bit!!
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
// #define fi1 ifstream fin("input.txt")
// #define of1 ofstream fout("output.txt")
// typedef
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
// ost;
#define fi first
#define se second
int main() {
int x, y, z, k;
scanf("%d %d %d %d", &x, &y, &z, &k);
vector<ll> xx, yy, zz, ans;
for (int i = 0; i < x; i++) {
ll tmp;
scanf("%lld", &tmp);
xx.eb(tmp);
}
for (int i = 0; i < y; i++) {
ll tmp;
scanf("%lld", &tmp);
yy.eb(tmp);
}
for (int i = 0; i < z; i++) {
ll tmp;
scanf("%lld", &tmp);
zz.eb(tmp);
}
for (int i = 0; i < min(x, k); i++) {
for (int j = 0; j < min(y, k); j++) {
for (int m = 0; m < min(z, k); m++) {
ans.eb(xx[i] + yy[j] + zz[m]);
}
}
}
sort(ans.rbegin(), ans.rend());
int index = 0;
while (index < ans.size() && k > 0) {
printf("%lld\n", ans[index]);
k--;
index++;
}
return 0;
} | #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int
// i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
using namespace std;
// using namespace __gnu_pbds;
#define pb push_back
#define eb emplace_back
#define mp(x, y) make_pair(x, y)
#define mod 1000000007
double PI = 3.1415926535897932384626;
// template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL)
// ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
#define bip(n) __builtin_popcount(n) // no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n) // no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n) // no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n) // index of first one bit!!
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
// #define fi1 ifstream fin("input.txt")
// #define of1 ofstream fout("output.txt")
// typedef
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
// ost;
#define fi first
#define se second
int main() {
int x, y, z, k;
scanf("%d %d %d %d", &x, &y, &z, &k);
vector<ll> xx, yy, zz, ans;
for (int i = 0; i < x; i++) {
ll tmp;
scanf("%lld", &tmp);
xx.eb(tmp);
}
for (int i = 0; i < y; i++) {
ll tmp;
scanf("%lld", &tmp);
yy.eb(tmp);
}
for (int i = 0; i < z; i++) {
ll tmp;
scanf("%lld", &tmp);
zz.eb(tmp);
}
sort(xx.rbegin(), xx.rend());
sort(yy.rbegin(), yy.rend());
sort(zz.rbegin(), zz.rend());
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int m = 0; m < z; m++) {
if (((i + 1) * (j + 1) * (m + 1)) > k)
break;
ans.eb(xx[i] + yy[j] + zz[m]);
}
}
}
sort(ans.rbegin(), ans.rend());
int index = 0;
while (index < ans.size() && k > 0) {
printf("%lld\n", ans[index]);
k--;
index++;
}
return 0;
}
| replace | 60 | 63 | 60 | 68 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int X, Y, Z, K; // X種Y種Z種から一つずつ買う,K:選び方
cin >> X >> Y >> Z >> K;
vector<long> A, B, C; // 価格
long a, b, c;
for (int i = 0; i < X; i++) {
cin >> a;
A.push_back(a);
}
for (int j = 0; j < Y; j++) {
cin >> b;
B.push_back(b);
}
for (int k = 0; k < Z; k++) {
cin >> c;
C.push_back(c);
}
// 降順ソート
sort(A.begin(), A.end(), greater<long>());
sort(B.begin(), B.end(), greater<long>());
sort(C.begin(), C.end(), greater<long>());
tuple<long, int, int, int> d; // (delicious_score, i, j, k)
priority_queue<tuple<long, int, int, int>> q; // scoreの最大値管理用コンテナ
set<tuple<long, int, int, int>>
s; // 重複したものをq.pushしないための検索用コンテナ
int i = 0;
int j = 0;
int k = 0;
while (K > 0) {
// 次に一番美味しいケーキの組み合わせ
if (i + 1 < X) {
d = make_tuple(A[i + 1] + B[j] + C[k], i + 1, j, k);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
}
if (j + 1 < Y) {
d = make_tuple(A[i] + B[j + 1] + C[k], i, j + 1, k);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
}
if (k + 1 < Z) {
d = make_tuple(A[i] + B[j] + C[k + 1], i, j, k + 1);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
}
auto qtop = q.top();
i = get<1>(qtop);
j = get<2>(qtop);
k = get<3>(qtop);
cout << get<0>(qtop) << endl;
q.pop();
K--;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int X, Y, Z, K; // X種Y種Z種から一つずつ買う,K:選び方
cin >> X >> Y >> Z >> K;
vector<long> A, B, C; // 価格
long a, b, c;
for (int i = 0; i < X; i++) {
cin >> a;
A.push_back(a);
}
for (int j = 0; j < Y; j++) {
cin >> b;
B.push_back(b);
}
for (int k = 0; k < Z; k++) {
cin >> c;
C.push_back(c);
}
// 降順ソート
sort(A.begin(), A.end(), greater<long>());
sort(B.begin(), B.end(), greater<long>());
sort(C.begin(), C.end(), greater<long>());
tuple<long, int, int, int> d; // (delicious_score, i, j, k)
priority_queue<tuple<long, int, int, int>> q; // scoreの最大値管理用コンテナ
set<tuple<long, int, int, int>>
s; // 重複したものをq.pushしないための検索用コンテナ
int i = 0;
int j = 0;
int k = 0;
// 一番美味しいケーキの組み合わせ
d = make_tuple(A[i] + B[j] + C[k], i, j, k);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
auto qtop = q.top();
i = get<1>(qtop);
j = get<2>(qtop);
k = get<3>(qtop);
cout << get<0>(qtop) << endl;
q.pop();
K--;
while (K > 0) {
// 次に一番美味しいケーキの組み合わせ
if (i + 1 < X) {
d = make_tuple(A[i + 1] + B[j] + C[k], i + 1, j, k);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
}
if (j + 1 < Y) {
d = make_tuple(A[i] + B[j + 1] + C[k], i, j + 1, k);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
}
if (k + 1 < Z) {
d = make_tuple(A[i] + B[j] + C[k + 1], i, j, k + 1);
if (!s.count(d)) {
q.push(d);
s.insert(d);
}
}
auto qtop = q.top();
i = get<1>(qtop);
j = get<2>(qtop);
k = get<3>(qtop);
cout << get<0>(qtop) << endl;
q.pop();
K--;
}
return 0;
} | insert | 35 | 35 | 35 | 49 | 0 | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vll A(1000, 0), B(1000, 0), C(1000, 0);
rep(i, X) cin >> A[i];
rep(j, Y) cin >> B[j];
rep(k, Z) cin >> C[k];
vll D(1e6 + 1, 0);
rep(i, X) {
rep(j, Y) { D[i * Y + j] = A[i] + B[j]; }
}
sort(all(D), greater<ll>());
vll E(3e6 + 1, 0);
rep(i, min(X * Y, K)) {
rep(j, min(Z, K)) { E[i * K + j] = D[i] + C[j]; }
}
sort(all(E), greater<ll>());
rep(i, K) cout << E[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vll A(1000, 0), B(1000, 0), C(1000, 0);
rep(i, X) cin >> A[i];
rep(j, Y) cin >> B[j];
rep(k, Z) cin >> C[k];
vll D(1e6 + 1, 0);
rep(i, X) {
rep(j, Y) { D[i * Y + j] = A[i] + B[j]; }
}
sort(all(D), greater<ll>());
vll E(9e6 + 1, 0);
int a = min(X * Y, K), b = min(Z, K);
rep(i, a) {
rep(j, b) { E[i * b + j] = D[i] + C[j]; }
}
sort(all(E), greater<ll>());
rep(i, K) cout << E[i] << endl;
}
| replace | 31 | 34 | 31 | 35 | TLE | |
p03078 | C++ | Time Limit Exceeded | #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 x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
vector<ll> result;
rep(i, x) rep(j, y) rep(k, z) result.push_back(a[i] + b[j] + c[k]);
sort(result.rbegin(), result.rend());
rep(i, k) cout << result[i] << 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 x, y, z, k;
cin >> x >> y >> z >> k;
vector<ll> a(x), b(y), c(z);
rep(i, x) cin >> a[i];
rep(i, y) cin >> b[i];
rep(i, z) cin >> c[i];
vector<ll> e;
rep(i, x) rep(j, y) e.push_back(a[i] + b[j]);
sort(e.rbegin(), e.rend());
vector<ll> f;
rep(i, min(x * y, k)) rep(j, z) f.push_back(e[i] + c[j]);
sort(f.rbegin(), f.rend());
rep(i, k) cout << f[i] << endl;
return 0;
}
| replace | 15 | 19 | 15 | 24 | TLE | |
p03078 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
#define rep(i, n) for (int i = 0; i < n; i++)
ll X, Y, Z, K;
vector<ll> a, b, c;
vector<ll> ans;
bool solve(ll T, bool sp) {
int cnt = 0;
rep(i, X) {
rep(j, Y) {
rep(k, Z) {
if (a[i] + b[j] + c[k] < T)
break;
if (sp)
ans.emplace_back(a[i] + b[j] + c[k]);
cnt++;
if (!sp && cnt >= K)
return true;
}
}
}
return false;
}
int main() {
cin >> X >> Y >> Z >> K;
a.resize(X);
b.resize(Y);
c.resize(Z);
rep(i, X) cin >> a[i];
rep(i, Y) cin >> b[i];
rep(i, Z) cin >> c[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
ll front = 0;
ll back = 30000000000;
while (front != back) {
ll half = (back + front) / 2;
if (back = front + 1) {
back = front;
} else if (solve(half, false))
front = half;
else
back = half - 1;
}
solve(front, true);
sort(ans.rbegin(), ans.rend());
rep(i, K) cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
#define rep(i, n) for (int i = 0; i < n; i++)
ll X, Y, Z, K;
vector<ll> a, b, c;
vector<ll> ans;
bool solve(ll T, bool sp) {
int cnt = 0;
rep(i, X) {
rep(j, Y) {
rep(k, Z) {
if (a[i] + b[j] + c[k] < T)
break;
if (sp)
ans.emplace_back(a[i] + b[j] + c[k]);
cnt++;
if (!sp && cnt >= K)
return true;
}
}
}
return false;
}
int main() {
cin >> X >> Y >> Z >> K;
a.resize(X);
b.resize(Y);
c.resize(Z);
rep(i, X) cin >> a[i];
rep(i, Y) cin >> b[i];
rep(i, Z) cin >> c[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
sort(c.rbegin(), c.rend());
ll front = 0;
ll back = 30000000000;
while (front != back) {
ll half = (back + front) / 2;
if (back == front + 1) {
back = front;
} else if (solve(half, false))
front = half;
else
back = half - 1;
}
solve(front, true);
sort(ans.rbegin(), ans.rend());
rep(i, K) cout << ans[i] << endl;
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p03079 | Python | Runtime Error | A = int(input())
B = int(input())
C = int(input())
if A == B and B == C:
print("Yes")
else:
print("No")
| A, B, C = map(int, input().split())
if A == B and B == C:
print("Yes")
else:
print("No")
| replace | 0 | 3 | 0 | 1 | ValueError: invalid literal for int() with base 10: '2 2 2' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03079/Python/s749501224.py", line 1, in <module>
A = int(input())
ValueError: invalid literal for int() with base 10: '2 2 2'
|
p03079 | C++ | Runtime Error | /*author: hyperion_1724
date:
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::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 A, B, C;
cin >> A >> B >> C;
if (A == B && B == C && A == C) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | /*author: hyperion_1724
date:
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int A, B, C;
cin >> A >> B >> C;
if (A == B && B == C && A == C) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | delete | 9 | 13 | 9 | 9 | 0 | |
p03079 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
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
int a, b, c;
cin >> a >> b >> c;
if (a != b || a != c) {
cout << "No";
} else {
cout << "Yes";
}
} | #include <bits/stdc++.h>
using namespace std;
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
int a, b, c;
cin >> a >> b >> c;
if (a != b || a != c) {
cout << "No";
} else {
cout << "Yes";
}
} | replace | 8 | 12 | 8 | 12 | 0 | |
p03079 | Python | Runtime Error | abc = list(map(int, input.split()))
if len(set(abc)) == 1:
print("Yes")
else:
print("No")
| abc = list(map(int, input().split()))
if len(set(abc)) == 1:
print("Yes")
else:
print("No")
| replace | 0 | 1 | 0 | 1 | AttributeError: 'builtin_function_or_method' object has no attribute 'split' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03079/Python/s011676715.py", line 1, in <module>
abc = list(map(int, input.split()))
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
|
p03079 | Python | Runtime Error | a, b, c = input()
if a == b == c:
print("Yes")
else:
print("No")
| a, b, c = input().split()
if a == b == c:
print("Yes")
else:
print("No")
| replace | 0 | 1 | 0 | 1 | ValueError: too many values to unpack (expected 3) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03079/Python/s108336051.py", line 1, in <module>
a, b, c = input()
ValueError: too many values to unpack (expected 3)
|
p03080 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, r = 0, b = 0;
cin >> n;
char s[4];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
if (s[i] == 'B')
b += 1;
else
r += 1;
}
if (r > b)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, r = 0, b = 0;
cin >> n;
char s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
if (s[i] == 'B')
b += 1;
else
r += 1;
}
if (r > b)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03080 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, count = 0;
cin >> N;
string S;
for (int i = 0; i < N; i++) {
cin >> S[i];
if (S[i] == 'R')
count++;
if (S[i] == 'B')
count--;
}
if (count <= 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, count = 0;
cin >> N;
string S;
for (int i = 0; i < N; i++) {
cin >> S;
if (S[i] == 'R')
count++;
if (S[i] == 'B')
count--;
}
if (count <= 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03080 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
int people, count = 0;
string hat;
cin >> people;
cin >> hat;
for (int i = 0; i < people; i++) {
if (hat[i] == 'R') {
count++;
}
}
hat = (count > people / 2) ? "Yes" : "No";
cout << hat;
while (true) {
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int people, count = 0;
string hat;
cin >> people;
cin >> hat;
for (int i = 0; i < people; i++) {
if (hat[i] == 'R') {
count++;
}
}
hat = (count > people / 2) ? "Yes" : "No";
cout << hat;
return 0;
} | delete | 24 | 26 | 24 | 24 | TLE | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, q;
char a[100005], b[100005];
string s;
int sol(int x, int u) {
x--;
for (int i = 1; i <= q; i++)
if (a[i] == s[x]) {
if (b[i] == 'L') {
x--;
if (x < 0 && !u)
return 1;
} else {
x++;
if (x == n && u)
return 1;
}
}
return 0;
}
int main() {
cin >> n >> q;
cin >> s;
for (int j = 1; j <= q; j++)
cin >> a[j] >> b[j];
int rez = n + 1, rez1 = 0;
for (int step = 1 << 17; step; step >>= 1)
if (rez - step >= 0 && sol(rez - step, 1))
rez -= step;
for (int step = 1 << 17; step; step >>= 1)
if (rez1 + step <= n && sol(rez1 + step, 0))
rez1 += step;
if (rez > rez1)
cout << rez - rez1 - 1;
else
cout << 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, q;
char a[200005], b[200005];
string s;
int sol(int x, int u) {
x--;
for (int i = 1; i <= q; i++)
if (a[i] == s[x]) {
if (b[i] == 'L') {
x--;
if (x < 0 && !u)
return 1;
} else {
x++;
if (x == n && u)
return 1;
}
}
return 0;
}
int main() {
cin >> n >> q;
cin >> s;
for (int j = 1; j <= q; j++)
cin >> a[j] >> b[j];
int rez = n + 1, rez1 = 0;
for (int step = 1 << 17; step; step >>= 1)
if (rez - step >= 0 && sol(rez - step, 1))
rez -= step;
for (int step = 1 << 17; step; step >>= 1)
if (rez1 + step <= n && sol(rez1 + step, 0))
rez1 += step;
if (rez > rez1)
cout << rez - rez1 - 1;
else
cout << 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T> inline void init(T &x) {
x = 0;
char ch = getchar();
bool t = 0;
for (; ch > '9' || ch < '0'; ch = getchar())
if (ch == '-')
t = 1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = (x << 1) + (x << 3) + (ch - 48);
if (t)
x = -x;
return;
}
int n, Q;
const int N = 1e5 + 10;
char S[N];
char opt[N];
int LR[N];
inline char Gc() {
char ch = getchar();
while (!(ch >= 'A' && ch <= 'Z'))
ch = getchar();
return ch;
}
inline bool checkL(int p) {
for (int i = 1; i <= Q; ++i) {
if (opt[i] == S[p])
p += LR[i];
if (p <= 0)
return 1;
if (p > n)
return 0;
}
return 0;
}
inline bool checkR(int p) {
for (int i = 1; i <= Q; ++i) {
if (opt[i] == S[p])
p += LR[i];
if (p > n)
return 1;
if (p <= 0)
return 0;
}
return 0;
}
int main() {
init(n), init(Q);
scanf("%s", S + 1);
for (int i = 1; i <= Q; ++i) {
char ch = Gc();
opt[i] = ch;
ch = Gc();
LR[i] = (ch == 'L') ? (-1) : 1;
}
int l = 1, r = n, pos = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (checkL(mid))
pos = mid, l = mid + 1;
else
r = mid - 1;
}
int ans = pos;
l = pos + 1, r = n;
pos = n + 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (checkR(mid))
pos = mid, r = mid - 1;
else
l = mid + 1;
}
ans += (n - pos + 1);
cout << (n - ans) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T> inline void init(T &x) {
x = 0;
char ch = getchar();
bool t = 0;
for (; ch > '9' || ch < '0'; ch = getchar())
if (ch == '-')
t = 1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = (x << 1) + (x << 3) + (ch - 48);
if (t)
x = -x;
return;
}
int n, Q;
const int N = 2e5 + 10;
char S[N];
char opt[N];
int LR[N];
inline char Gc() {
char ch = getchar();
while (!(ch >= 'A' && ch <= 'Z'))
ch = getchar();
return ch;
}
inline bool checkL(int p) {
for (int i = 1; i <= Q; ++i) {
if (opt[i] == S[p])
p += LR[i];
if (p <= 0)
return 1;
if (p > n)
return 0;
}
return 0;
}
inline bool checkR(int p) {
for (int i = 1; i <= Q; ++i) {
if (opt[i] == S[p])
p += LR[i];
if (p > n)
return 1;
if (p <= 0)
return 0;
}
return 0;
}
int main() {
init(n), init(Q);
scanf("%s", S + 1);
for (int i = 1; i <= Q; ++i) {
char ch = Gc();
opt[i] = ch;
ch = Gc();
LR[i] = (ch == 'L') ? (-1) : 1;
}
int l = 1, r = n, pos = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (checkL(mid))
pos = mid, l = mid + 1;
else
r = mid - 1;
}
int ans = pos;
l = pos + 1, r = n;
pos = n + 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (checkR(mid))
pos = mid, r = mid - 1;
else
l = mid + 1;
}
ans += (n - pos + 1);
cout << (n - ans) << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03081 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using lli = long long int;
using namespace std;
int inf = 1000000007;
int N, Q;
string s;
char t, d;
bool solve(vector<tuple<char, char>> q, int x) {
char now = s[x];
for (int i = 0; i < Q; i++) {
tie(t, d) = q[i];
if (t == now) {
if (d == 'R')
x++;
else
x--;
}
if (x == -1 || x == N)
return false;
now = s[x];
}
return true;
}
int main() {
cin >> N >> Q;
cin >> s;
vector<tuple<char, char>> quary(Q);
for (int i = 0; i < Q; i++) {
cin >> t >> d;
quary[i] = make_tuple(t, d);
}
// 左端と右端探す
int ok = -1;
int ng = N;
while (ng - ok != 1) {
int x = (ng + ok) / 2;
if (solve(quary, x))
ok = x;
else
ng = x;
}
int left = ok;
ok = left;
ng = -1;
while (ok - ng != 1) {
int x = (ng + ok) / 2;
if (solve(quary, x))
ok = x;
else
ng = x;
}
cout << max(0, left - ok + 1) << endl;
}
| #include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using lli = long long int;
using namespace std;
int inf = 1000000007;
int N, Q;
string s;
char t, d;
bool solve(vector<tuple<char, char>> q, int x) {
char now = s[x];
for (int i = 0; i < Q; i++) {
tie(t, d) = q[i];
if (t == now) {
if (d == 'R')
x++;
else
x--;
}
if (x == -1 || x == N)
return false;
now = s[x];
}
return true;
}
int main() {
cin >> N >> Q;
cin >> s;
vector<tuple<char, char>> quary(Q);
for (int i = 0; i < Q; i++) {
cin >> t >> d;
quary[i] = make_tuple(t, d);
}
// 左端と右端探す
int ok = -1;
int ng = N;
while (ng - ok != 1) {
int x = (ng + ok) / 2;
if (solve(quary, x))
ok = x;
else
ng = x;
}
int left = ok;
ok = N - 1;
ng = -1;
while (ok - ng != 1) {
int x = (ng + ok) / 2;
if (solve(quary, x))
ok = x;
else
ng = x;
}
cout << max(0, left - ok + 1) << endl;
}
| replace | 57 | 58 | 57 | 58 | TLE | |
p03081 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int N, Q;
string s;
char t[100010], d[100010];
bool judge(int mid, int x) {
int now = mid - 1;
for (int i = 0; i < Q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'L')
now = now - 1;
else
now = now + 1;
}
if (now == x)
return true;
else if (x == N && now == -1)
return false;
else if (x == -1 && now == N)
return false;
}
return false;
}
int main() {
cin >> N >> Q;
cin >> s;
for (int i = 0; i < Q; i++) {
cin >> t[i] >> d[i];
}
int ok = 0, ng = N + 1;
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (judge(mid, -1))
ok = mid;
else
ng = mid;
}
int ans = ok;
ok = N + 1;
ng = 0;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (judge(mid, N))
ok = mid;
else
ng = mid;
}
cout << N - min(ans + N - ok + 1, N) << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define MOD 1000000007
typedef long long ll;
using namespace std;
int N, Q;
string s;
char t[200020], d[200020];
bool judge(int mid, int x) {
int now = mid - 1;
for (int i = 0; i < Q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'L')
now = now - 1;
else
now = now + 1;
}
if (now == x)
return true;
else if (x == N && now == -1)
return false;
else if (x == -1 && now == N)
return false;
}
return false;
}
int main() {
cin >> N >> Q;
cin >> s;
for (int i = 0; i < Q; i++) {
cin >> t[i] >> d[i];
}
int ok = 0, ng = N + 1;
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (judge(mid, -1))
ok = mid;
else
ng = mid;
}
int ans = ok;
ok = N + 1;
ng = 0;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (judge(mid, N))
ok = mid;
else
ng = mid;
}
cout << N - min(ans + N - ok + 1, N) << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03081 | C++ | Time Limit Exceeded | /*
memo for solution
*/
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <utility>
#include <vector>
using namespace std;
double e_time(void) {
static struct timeval now;
gettimeofday(&now, NULL);
return (double)(now.tv_sec + now.tv_usec / 1000000.0);
}
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(C) (C).begin(), (C).end()
#define fe(c, itr) \
for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define BITSHIFT(X) ((1 << (X)))
#define CONTAIN(S, X) (((S)&BITSHIFT(X)) != 0)
typedef complex<double> P;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vint;
template <class T> void vp(T &a, int p) {
rep(i, p) cout << a[i] << " ";
cout << endl;
}
template <class T> T ceilUp(const T &a, const T &b) { return (a + b - 1) / b; }
const ll mod = 1000000009;
inline ll modadd(ll a, ll b) {
a %= mod;
b %= mod;
return (a + b) % mod;
}
inline ll modsub(ll a, ll b) {
a %= mod;
b %= mod;
a -= b;
a %= mod;
if (a < 0)
a += mod;
return a;
}
inline ll modmul(ll a, ll b) {
a %= mod;
b %= mod;
return (a * b) % mod;
}
inline ll modeq(ll a, ll b, ll m) {
a = (a % m + m) % m;
b = (b % m + m) % m;
return a == b;
}
// ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll
// ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;} ll
// getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n, ll p) {
if (p == 0)
return 1;
if (p == 1)
return n;
ll ret = mypow(n, p / 2);
ret = ret * ret;
if (p & 1)
ret = ret * n;
return ret;
}
bool check(int n, const string &in, vector<char> &pos, vector<int> &order,
bool isCountLeft, int my_pos) {
const int q = pos.size();
rep(i, q) {
if (in[my_pos] == pos[i]) {
my_pos += order[i];
}
if (my_pos < 0 || my_pos >= n)
break;
}
if (isCountLeft && my_pos < 0)
return true;
if (!isCountLeft && my_pos >= n)
return true;
return false;
}
int solve(int n, const string &in, vector<char> &pos, vector<int> &order,
bool isCountLeft) {
int l = 0, r = n;
if (isCountLeft && !check(n, in, pos, order, isCountLeft, 0)) {
return 0;
} else if (!isCountLeft && !check(n, in, pos, order, isCountLeft, n - 1)) {
return 0;
}
if (!isCountLeft) {
l = -1;
r = n - 1;
}
while (l + 1 <= r) {
// rep(i,50){
int mid = (l + r) / 2;
bool isGone = check(n, in, pos, order, isCountLeft, mid);
// cout << isCountLeft <<" " << l <<" " << r << " " << mid << " " << isGone
// << endl;
if (isGone) {
if (isCountLeft) {
l = mid; // find max
} else {
r = mid; // find min
}
} else {
if (isCountLeft) {
r = mid; // find max
} else {
l = mid; // find min
}
}
}
// cout << isCountLeft <<" l = " << l <<" r = " << r <<" " << l << " " << n-r
// << endl;
if (isCountLeft) {
return l + 1;
} else {
return n - r;
}
}
int main() {
int n, q;
cin >> n >> q;
string in;
cin >> in;
vector<char> pos(q);
vector<int> order(q);
rep(i, q) {
cin >> pos[i];
char tmp;
cin >> tmp;
if (tmp == 'L')
order[i] = -1;
else if (tmp == 'R')
order[i] = +1;
else
assert(0);
}
int goneLeft = solve(n, in, pos, order, true);
int goneRight = solve(n, in, pos, order, false);
cout << n - goneLeft - goneRight << endl;
return 0;
}
| /*
memo for solution
*/
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <utility>
#include <vector>
using namespace std;
double e_time(void) {
static struct timeval now;
gettimeofday(&now, NULL);
return (double)(now.tv_sec + now.tv_usec / 1000000.0);
}
#define REP(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(C) (C).begin(), (C).end()
#define fe(c, itr) \
for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define BITSHIFT(X) ((1 << (X)))
#define CONTAIN(S, X) (((S)&BITSHIFT(X)) != 0)
typedef complex<double> P;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vint;
template <class T> void vp(T &a, int p) {
rep(i, p) cout << a[i] << " ";
cout << endl;
}
template <class T> T ceilUp(const T &a, const T &b) { return (a + b - 1) / b; }
const ll mod = 1000000009;
inline ll modadd(ll a, ll b) {
a %= mod;
b %= mod;
return (a + b) % mod;
}
inline ll modsub(ll a, ll b) {
a %= mod;
b %= mod;
a -= b;
a %= mod;
if (a < 0)
a += mod;
return a;
}
inline ll modmul(ll a, ll b) {
a %= mod;
b %= mod;
return (a * b) % mod;
}
inline ll modeq(ll a, ll b, ll m) {
a = (a % m + m) % m;
b = (b % m + m) % m;
return a == b;
}
// ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll
// ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;} ll
// getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n, ll p) {
if (p == 0)
return 1;
if (p == 1)
return n;
ll ret = mypow(n, p / 2);
ret = ret * ret;
if (p & 1)
ret = ret * n;
return ret;
}
bool check(int n, const string &in, vector<char> &pos, vector<int> &order,
bool isCountLeft, int my_pos) {
const int q = pos.size();
rep(i, q) {
if (in[my_pos] == pos[i]) {
my_pos += order[i];
}
if (my_pos < 0 || my_pos >= n)
break;
}
if (isCountLeft && my_pos < 0)
return true;
if (!isCountLeft && my_pos >= n)
return true;
return false;
}
int solve(int n, const string &in, vector<char> &pos, vector<int> &order,
bool isCountLeft) {
int l = 0, r = n;
if (isCountLeft && !check(n, in, pos, order, isCountLeft, 0)) {
return 0;
} else if (!isCountLeft && !check(n, in, pos, order, isCountLeft, n - 1)) {
return 0;
}
if (!isCountLeft) {
l = -1;
r = n - 1;
}
// while(l < r){
rep(i, 50) {
int mid = (l + r) / 2;
bool isGone = check(n, in, pos, order, isCountLeft, mid);
// cout << isCountLeft <<" " << l <<" " << r << " " << mid << " " << isGone
// << endl;
if (isGone) {
if (isCountLeft) {
l = mid; // find max
} else {
r = mid; // find min
}
} else {
if (isCountLeft) {
r = mid; // find max
} else {
l = mid; // find min
}
}
}
// cout << isCountLeft <<" l = " << l <<" r = " << r <<" " << l << " " << n-r
// << endl;
if (isCountLeft) {
return l + 1;
} else {
return n - r;
}
}
int main() {
int n, q;
cin >> n >> q;
string in;
cin >> in;
vector<char> pos(q);
vector<int> order(q);
rep(i, q) {
cin >> pos[i];
char tmp;
cin >> tmp;
if (tmp == 'L')
order[i] = -1;
else if (tmp == 'R')
order[i] = +1;
else
assert(0);
}
int goneLeft = solve(n, in, pos, order, true);
int goneRight = solve(n, in, pos, order, false);
cout << n - goneLeft - goneRight << endl;
return 0;
}
| replace | 121 | 123 | 121 | 123 | TLE | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
const ll MOD = ll(1e9 + 7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e4 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
int n, q;
string s, t[MAX_N], d[MAX_N];
bool check(int k, bool f) {
int pos = k;
char now = s[k];
REP(i, q) {
if (now == t[i][0]) {
if (d[i] == "L") {
now = s[pos - 1];
pos--;
} else {
now = s[pos + 1];
pos++;
}
}
}
if (f)
return pos == 0;
else
return pos == n + 1;
}
int main() {
cin >> n >> q >> s;
s.insert(0, "#");
s.push_back('#');
REP(i, q) { cin >> t[i] >> d[i]; }
int l, r;
int ok = 0, ng = n + 1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid, true)) {
ok = mid;
} else {
ng = mid;
}
}
l = ok;
ok = n + 1, ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid, false)) {
ok = mid;
} else {
ng = mid;
}
}
r = ok;
cout << r - l - 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
const ll MOD = ll(1e9 + 7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()
int n, q;
string s, t[MAX_N], d[MAX_N];
bool check(int k, bool f) {
int pos = k;
char now = s[k];
REP(i, q) {
if (now == t[i][0]) {
if (d[i] == "L") {
now = s[pos - 1];
pos--;
} else {
now = s[pos + 1];
pos++;
}
}
}
if (f)
return pos == 0;
else
return pos == n + 1;
}
int main() {
cin >> n >> q >> s;
s.insert(0, "#");
s.push_back('#');
REP(i, q) { cin >> t[i] >> d[i]; }
int l, r;
int ok = 0, ng = n + 1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid, true)) {
ok = mid;
} else {
ng = mid;
}
}
l = ok;
ok = n + 1, ng = 0;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid, false)) {
ok = mid;
} else {
ng = mid;
}
}
r = ok;
cout << r - l - 1 << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sperase(v, n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
int n, q, now, ans;
string s;
bool memo1[200000], memo2[200000];
char t[200000], d[200000];
signed main() {
cin >> n >> q >> s;
rep(i, q) cin >> t[i] >> d[i];
now = 0;
repm(i, q) {
if (t[i] == s[now] && d[i] == 'L')
memo1[now] = true, now++;
if (now)
if (t[i] == s[now - 1] && d[i] == 'R')
now--, memo1[now] = false;
if (now == s.size())
break;
}
now = s.size() - 1;
repm(i, q) {
if (t[i] == s[now] && d[i] == 'R')
memo2[now] = true, now--;
if (now != s.size() - 1)
if (t[i] == s[now + 1] && d[i] == 'L')
n++, memo2[now] = false;
if (now < 0)
break;
}
rep(i, n) if (memo1[i] | memo2[i]) ans++;
cout << n - ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sperase(v, n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
int n, q, now, ans;
string s;
bool memo1[200000], memo2[200000];
char t[200000], d[200000];
signed main() {
cin >> n >> q >> s;
rep(i, q) cin >> t[i] >> d[i];
now = 0;
repm(i, q) {
if (t[i] == s[now] && d[i] == 'L')
memo1[now] = true, now++;
if (now)
if (t[i] == s[now - 1] && d[i] == 'R')
now--, memo1[now] = false;
if (now == s.size())
break;
}
now = s.size() - 1;
repm(i, q) {
if (t[i] == s[now] && d[i] == 'R')
memo2[now] = true, now--;
if (now != s.size() - 1)
if (t[i] == s[now + 1] && d[i] == 'L')
now++, memo2[now] = false;
if (now < 0)
break;
}
rep(i, n) if (memo1[i] | memo2[i]) ans++;
cout << n - ans << endl;
}
| replace | 43 | 44 | 43 | 44 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, q;
char c[N];
char a[N], b[N];
int dl, dr;
int die(int x) {
for (int i = 1; i <= q; i++) {
if (a[i] != c[x])
continue;
if (b[i] == 'R')
x++;
else
x--;
if (x == 0)
return -1;
if (x == n + 1)
return 1;
}
return 0;
}
int main() {
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> c[i];
for (int i = 1; i <= q; i++)
cin >> a[i] >> b[i];
int l = 0, r = n + 1, md;
while (r - l > 1) {
md = (r + l) / 2;
if (die(md) == -1)
l = md;
else
r = md;
}
dl = l;
l = 0, r = n + 1, md;
while (r - l > 1) {
md = (r + l) / 2;
if (die(md) == 1)
r = md;
else
l = md;
}
dr = r;
if (dr <= dl)
dr = dl + 1;
cout << n - dl - (n - (dr) + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, q;
char c[N];
char a[N], b[N];
int dl, dr;
int die(int x) {
for (int i = 1; i <= q; i++) {
if (a[i] != c[x])
continue;
if (b[i] == 'R')
x++;
else
x--;
if (x == 0)
return -1;
if (x == n + 1)
return 1;
}
return 0;
}
int main() {
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> c[i];
for (int i = 1; i <= q; i++)
cin >> a[i] >> b[i];
int l = 0, r = n + 1, md;
while (r - l > 1) {
md = (r + l) / 2;
if (die(md) == -1)
l = md;
else
r = md;
}
dl = l;
l = 0, r = n + 1, md;
while (r - l > 1) {
md = (r + l) / 2;
if (die(md) == 1)
r = md;
else
l = md;
}
dr = r;
if (dr <= dl)
dr = dl + 1;
cout << n - dl - (n - (dr) + 1);
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) \
{ \
if (a < b) \
a = b; \
}
#define chmin(a, b) \
{ \
if (a > b) \
a = b; \
}
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll N, Q;
string s;
char t[MAX], d[MAX];
ll L(ll now) {
ll i;
for (i = 0; i < Q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'L')
now--;
if (d[i] == 'R')
now++;
if (now < 0)
return 1;
}
}
return 0;
}
ll R(ll now) {
ll i;
for (i = 0; i < Q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'L')
now--;
if (d[i] == 'R')
now++;
if (now >= N)
return 1;
}
}
return 0;
}
int main(void) {
cin >> N >> Q;
cin >> s;
ll i, j;
for (i = 0; i < Q; i++)
cin >> t[i] >> d[i];
ll l = 0, r = N;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (L(mid))
l = mid;
else
r = mid;
}
ll le = l;
l = 0;
r = N;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (R(mid))
r = mid;
else
l = mid;
}
ll ri = l;
pt(max(0, ri - le));
}
| #include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) \
{ \
if (a < b) \
a = b; \
}
#define chmin(a, b) \
{ \
if (a > b) \
a = b; \
}
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF = 1e18;
static const ll MAX = 1e5 + 7;
static const ll MOD = 1e9 + 7;
ll max(ll a, ll b) { return a > b ? a : b; }
ll min(ll a, ll b) { return a < b ? a : b; }
ll N, Q;
string s;
char t[MAX * 2], d[MAX * 2];
ll L(ll now) {
ll i;
for (i = 0; i < Q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'L')
now--;
if (d[i] == 'R')
now++;
if (now < 0)
return 1;
}
}
return 0;
}
ll R(ll now) {
ll i;
for (i = 0; i < Q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'L')
now--;
if (d[i] == 'R')
now++;
if (now >= N)
return 1;
}
}
return 0;
}
int main(void) {
cin >> N >> Q;
cin >> s;
ll i, j;
for (i = 0; i < Q; i++)
cin >> t[i] >> d[i];
ll l = 0, r = N;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (L(mid))
l = mid;
else
r = mid;
}
ll le = l;
l = 0;
r = N;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (R(mid))
r = mid;
else
l = mid;
}
ll ri = l;
pt(max(0, ri - le));
}
| replace | 30 | 31 | 30 | 31 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
const int MX = 200005;
#define RET(ans) \
{ \
cout << ans << endl; \
return 0; \
}
// 二次元ベクターの基本
/*
vector<vector<int>> dp; // 宣言
dp.resize(n); // 1次元めの要素数決定
dp[i].push_back(int); // プッシュバック
rep(i,n){
sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
}
*/
// 整数スキャン(複数)
/*
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
// n個の整数のスキャン
/*
ll a[n] = {};
rep(i,n){
scanf("%lld",&a[i]);
}
*/
// 文字列スキャン
/*
string s; cin >> s;
*/
// n個の文字列スキャン
/*
vector<string> slist;
rep(i,n){
string s; cin >> s;
slist.push_back(s);
}
*/
int syori(int x, int q, string s, char t[], char d[]) {
rep(i, s.size()) {
if (s[x] == t[i]) {
if (d[i] == 'L') {
x--;
} else {
x++;
}
if (x == -1) {
return 1;
}
if (x == s.size()) {
return 3;
}
}
}
return 2;
}
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
char t[q];
char d[q];
rep(i, q) { cin >> t[i] >> d[i]; }
int a[n];
// -1:uncertain 1:fall left 2:stand 3:fall right
rep(i, n) { a[i] = -1; }
int l = 0;
int r = n - 1;
while (true) {
if (a[(l + r) / 2] == -1) {
a[(l + r) / 2] = syori((l + r) / 2, q, s, t, d);
if (a[(l + r) / 2] == 1) {
rep(i, (l + r) / 2) { a[i] = 1; }
l = (l + r) / 2 + 1;
}
if (a[(l + r) / 2] == 3) {
srep(i, (l + r) / 2, n) { a[i] = 3; }
r = (l + r) / 2 - 1;
}
if (a[(l + r) / 2] == 2) {
r = (l + r) / 2 - 1;
}
} else {
break;
}
}
l = 0;
r = n - 1;
while (a[l] == 1 || a[l] == 2) {
l++;
}
while (true) {
a[(l + r) / 2] = syori((l + r) / 2, q, s, t, d);
if (a[(l + r) / 2] == 2) {
l = (l + r) / 2 + 1;
}
if (a[(l + r) / 2] == 3) {
srep(i, (l + r) / 2, n) { a[i] = 3; }
r = (l + r) / 2 - 1;
}
if (r < l)
break;
}
int ans = n;
rep(i, n) {
if (a[i] == 1 || a[i] == 3)
ans--;
}
/*
rep(i,n){
cout << a[i];
}
cout << endl;
*/
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
const int MX = 200005;
#define RET(ans) \
{ \
cout << ans << endl; \
return 0; \
}
// 二次元ベクターの基本
/*
vector<vector<int>> dp; // 宣言
dp.resize(n); // 1次元めの要素数決定
dp[i].push_back(int); // プッシュバック
rep(i,n){
sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
}
*/
// 整数スキャン(複数)
/*
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
// n個の整数のスキャン
/*
ll a[n] = {};
rep(i,n){
scanf("%lld",&a[i]);
}
*/
// 文字列スキャン
/*
string s; cin >> s;
*/
// n個の文字列スキャン
/*
vector<string> slist;
rep(i,n){
string s; cin >> s;
slist.push_back(s);
}
*/
int syori(int x, int q, string s, char t[], char d[]) {
rep(i, q) {
if (s[x] == t[i]) {
if (d[i] == 'L') {
x--;
} else {
x++;
}
if (x == -1) {
return 1;
}
if (x == s.size()) {
return 3;
}
}
}
return 2;
}
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
char t[q];
char d[q];
rep(i, q) { cin >> t[i] >> d[i]; }
int a[n];
// -1:uncertain 1:fall left 2:stand 3:fall right
rep(i, n) { a[i] = -1; }
int l = 0;
int r = n - 1;
while (true) {
if (a[(l + r) / 2] == -1) {
a[(l + r) / 2] = syori((l + r) / 2, q, s, t, d);
if (a[(l + r) / 2] == 1) {
rep(i, (l + r) / 2) { a[i] = 1; }
l = (l + r) / 2 + 1;
}
if (a[(l + r) / 2] == 3) {
srep(i, (l + r) / 2, n) { a[i] = 3; }
r = (l + r) / 2 - 1;
}
if (a[(l + r) / 2] == 2) {
r = (l + r) / 2 - 1;
}
} else {
break;
}
}
l = 0;
r = n - 1;
while (a[l] == 1 || a[l] == 2) {
l++;
}
while (true) {
a[(l + r) / 2] = syori((l + r) / 2, q, s, t, d);
if (a[(l + r) / 2] == 2) {
l = (l + r) / 2 + 1;
}
if (a[(l + r) / 2] == 3) {
srep(i, (l + r) / 2, n) { a[i] = 3; }
r = (l + r) / 2 - 1;
}
if (r < l)
break;
}
int ans = n;
rep(i, n) {
if (a[i] == 1 || a[i] == 3)
ans--;
}
/*
rep(i,n){
cout << a[i];
}
cout << endl;
*/
cout << ans << endl;
return 0;
}
| replace | 125 | 126 | 125 | 126 | 0 | |
p03081 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int N, Q;
string s;
char t[123456], d[123456];
bool left(int p) {
for (int i = 0; i < Q; i++) {
if (t[i] == s[p]) {
p += ((d[i] == 'L') ? -1 : 1);
}
if (p < 0)
return true;
}
return false;
}
bool right(int p) {
for (int i = 0; i < Q; i++) {
if (t[i] == s[p]) {
p += ((d[i] == 'L') ? -1 : 1);
}
if (p >= N)
return true;
}
return false;
}
int main(int argc, char *argv[]) {
cin >> N >> Q;
cin >> s;
int ans = N;
for (int i = 0; i < Q; i++) {
cin >> t[i] >> d[i];
}
int ok = 0, ng = N;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (left(mid)) {
ok = mid;
} else {
ng = mid;
}
}
if (left(ok)) {
ans -= (ok + 1);
}
ok = N - 1, ng = -1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (right(mid)) {
ok = mid;
} else {
ng = mid;
}
}
if (right(ok)) {
ans -= N - (ok);
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int N, Q;
string s;
char t[223456], d[223456];
bool left(int p) {
for (int i = 0; i < Q; i++) {
if (t[i] == s[p]) {
p += ((d[i] == 'L') ? -1 : 1);
}
if (p < 0)
return true;
}
return false;
}
bool right(int p) {
for (int i = 0; i < Q; i++) {
if (t[i] == s[p]) {
p += ((d[i] == 'L') ? -1 : 1);
}
if (p >= N)
return true;
}
return false;
}
int main(int argc, char *argv[]) {
cin >> N >> Q;
cin >> s;
int ans = N;
for (int i = 0; i < Q; i++) {
cin >> t[i] >> d[i];
}
int ok = 0, ng = N;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (left(mid)) {
ok = mid;
} else {
ng = mid;
}
}
if (left(ok)) {
ans -= (ok + 1);
}
ok = N - 1, ng = -1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (right(mid)) {
ok = mid;
} else {
ng = mid;
}
}
if (right(ok)) {
ans -= N - (ok);
}
cout << ans << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 20005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
res = 0;
T f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <class T> void out(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N, Q;
char s[MAXN];
pii op[MAXN];
int getplace(int p) {
for (int i = 1; i <= Q; ++i) {
if (s[p] == 'A' + op[i].fi) {
p += op[i].se;
}
}
return p;
}
int findL() {
int L = 0, R = N;
while (L < R) {
int mid = (L + R + 1) >> 1;
if (getplace(mid) == 0)
L = mid;
else
R = mid - 1;
}
return L;
}
int findR() {
int L = 1, R = N + 1;
while (L < R) {
int mid = (L + R) >> 1;
if (getplace(mid) == N + 1)
R = mid;
else
L = mid + 1;
}
return L;
}
void Solve() {
read(N);
read(Q);
scanf("%s", s + 1);
char t[5], d[5];
for (int i = 1; i <= Q; ++i) {
scanf("%s%s", t + 1, d + 1);
int a, b;
if (d[1] == 'L')
b = -1;
else
b = 1;
a = t[1] - 'A';
op[i] = mp(a, b);
}
int L = findL(), R = findR();
out(R - L - 1);
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in", "r", stdin);
#endif
Solve();
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
res = 0;
T f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <class T> void out(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N, Q;
char s[MAXN];
pii op[MAXN];
int getplace(int p) {
for (int i = 1; i <= Q; ++i) {
if (s[p] == 'A' + op[i].fi) {
p += op[i].se;
}
}
return p;
}
int findL() {
int L = 0, R = N;
while (L < R) {
int mid = (L + R + 1) >> 1;
if (getplace(mid) == 0)
L = mid;
else
R = mid - 1;
}
return L;
}
int findR() {
int L = 1, R = N + 1;
while (L < R) {
int mid = (L + R) >> 1;
if (getplace(mid) == N + 1)
R = mid;
else
L = mid + 1;
}
return L;
}
void Solve() {
read(N);
read(Q);
scanf("%s", s + 1);
char t[5], d[5];
for (int i = 1; i <= Q; ++i) {
scanf("%s%s", t + 1, d + 1);
int a, b;
if (d[1] == 'L')
b = -1;
else
b = 1;
a = t[1] - 'A';
op[i] = mp(a, b);
}
int L = findL(), R = findR();
out(R - L - 1);
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in", "r", stdin);
#endif
Solve();
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define f first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
const int N = 2e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const int M = 210;
ll n, q;
char a[N], s[N], d[N];
bool checkleft(ll x) {
ll curpos = x;
for (int i = 1; i <= q; i++) {
if (curpos == 0 || curpos == n + 1)
break;
if (a[curpos] == s[i]) {
if (d[i] == 'L')
curpos--;
else
curpos++;
}
}
return (curpos == 0);
}
bool checkright(ll x) {
ll curpos = x;
for (int i = 1; i <= q; i++) {
if (curpos == 0 || curpos == n + 1)
break;
if (a[curpos] == s[i]) {
if (d[i] == 'L')
curpos--;
else
curpos++;
}
}
return (curpos == n + 1);
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
freopen("input.txt", "r", stdin);
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= q; i++)
cin >> s[i] >> d[i];
ll L = 1, R = n, M, a1 = 0, a2 = n + 1;
while (L <= R) {
M = (L + R) / 2;
if (checkleft(M)) {
a1 = max(a1, M);
L = M + 1;
} else {
R = M - 1;
}
}
L = 1;
R = n;
while (L <= R) {
M = (L + R) / 2;
if (checkright(M)) {
a2 = min(a2, M);
R = M - 1;
} else {
L = M + 1;
}
}
a2 = n - a2 + 1;
cout << n - a1 - a2;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define f first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
const int N = 2e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const int M = 210;
ll n, q;
char a[N], s[N], d[N];
bool checkleft(ll x) {
ll curpos = x;
for (int i = 1; i <= q; i++) {
if (curpos == 0 || curpos == n + 1)
break;
if (a[curpos] == s[i]) {
if (d[i] == 'L')
curpos--;
else
curpos++;
}
}
return (curpos == 0);
}
bool checkright(ll x) {
ll curpos = x;
for (int i = 1; i <= q; i++) {
if (curpos == 0 || curpos == n + 1)
break;
if (a[curpos] == s[i]) {
if (d[i] == 'L')
curpos--;
else
curpos++;
}
}
return (curpos == n + 1);
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
cin >> n >> q;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= q; i++)
cin >> s[i] >> d[i];
ll L = 1, R = n, M, a1 = 0, a2 = n + 1;
while (L <= R) {
M = (L + R) / 2;
if (checkleft(M)) {
a1 = max(a1, M);
L = M + 1;
} else {
R = M - 1;
}
}
L = 1;
R = n;
while (L <= R) {
M = (L + R) / 2;
if (checkright(M)) {
a2 = min(a2, M);
R = M - 1;
} else {
L = M + 1;
}
}
a2 = n - a2 + 1;
cout << n - a1 - a2;
return 0;
} | replace | 53 | 54 | 53 | 54 | 0 | |
p03081 | C++ | Runtime Error | #include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
string s;
cin >> s;
string t;
vi d(q);
REP(i, q) {
char a, b;
cin >> a >> b;
t += a;
if (b == 'R')
d[i] = 1;
else
d[i] = -1;
}
auto check = [&](int p) {
char c = s[p];
int pos = p;
REP(i, q) {
if (t[i] == c) {
pos += d[i];
if (pos == -1)
return -1;
if (pos == n)
return 1;
c = s[pos];
}
}
return 0;
};
int a = check(0), b = check(n - 1);
if (a == 0 && b == 0) {
cout << n << endl;
} else if (a == 0) {
int l = 0, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
if (check(mid) == 0)
l = mid;
else
r = mid;
}
cout << n - l - 1 << endl;
} else if (b == 0) {
int l = 0, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
if (check(mid) == 0)
r = mid;
else
l = mid;
}
cout << n - r << endl;
} else {
int l = 0, r = n;
int m = -1;
while (r - l > 1) {
int mid = (r + l) / 2;
int c = check(mid);
if (c == 0) {
m = mid;
break;
} else if (c == 1) {
r = mid;
} else {
l = mid;
}
}
assert(m != -1);
int res = n;
l = 0, r = m;
while (r - l > 1) {
int mid = (r + l) / 2;
int c = check(mid);
if (c == 0)
r = mid;
else
l = mid;
}
res -= r;
l = m, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
int c = check(mid);
if (c == 0)
l = mid;
else
r = mid;
}
res -= n - r;
cout << res << endl;
}
} | #include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
string s;
cin >> s;
string t;
vi d(q);
REP(i, q) {
char a, b;
cin >> a >> b;
t += a;
if (b == 'R')
d[i] = 1;
else
d[i] = -1;
}
auto check = [&](int p) {
char c = s[p];
int pos = p;
REP(i, q) {
if (t[i] == c) {
pos += d[i];
if (pos == -1)
return -1;
if (pos == n)
return 1;
c = s[pos];
}
}
return 0;
};
int a = check(0), b = check(n - 1);
if (a == 0 && b == 0) {
cout << n << endl;
} else if (a == 0) {
int l = 0, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
if (check(mid) == 0)
l = mid;
else
r = mid;
}
cout << n - l - 1 << endl;
} else if (b == 0) {
int l = 0, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
if (check(mid) == 0)
r = mid;
else
l = mid;
}
cout << n - r << endl;
} else {
int l = 0, r = n;
int m = -1;
while (r - l > 1) {
int mid = (r + l) / 2;
int c = check(mid);
if (c == 0) {
m = mid;
break;
} else if (c == 1) {
r = mid;
} else {
l = mid;
}
}
if (m == -1) {
cout << 0 << endl;
return 0;
}
int res = n;
l = 0, r = m;
while (r - l > 1) {
int mid = (r + l) / 2;
int c = check(mid);
if (c == 0)
r = mid;
else
l = mid;
}
res -= r;
l = m, r = n;
while (r - l > 1) {
int mid = (r + l) / 2;
int c = check(mid);
if (c == 0)
l = mid;
else
r = mid;
}
res -= n - r;
cout << res << endl;
}
} | replace | 114 | 115 | 114 | 118 | 0 | |
p03081 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr << "[" << (x).FI << ", " << (x).SE << "]";
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWVEC(v, e) \
REP(i, e) cerr << (v[i]) << ' '; \
cerr << endl;
#define SHOW2D(a, h, w) \
REP(i, h) { \
REP(j, w) cerr << setw(3) << (a[i][j]) << ' '; \
cerr << endl; \
}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> P;
char t[110000], d[110000];
int N, Q;
string s;
int sim(int idx) {
REP(i, Q) {
if (s[idx] == t[i]) {
if (d[i] == 'L')
idx--;
else
idx++;
}
if (idx < 0 || idx >= N)
return idx;
}
return idx;
}
int main() {
cin >> N >> Q;
cin >> s;
REP(i, Q) cin >> t[i] >> d[i];
int l, r;
int cnt = 0;
l = -1, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
if (sim(mid) >= N)
r = mid;
else
l = mid;
}
cnt += N - r;
l = -1, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
if (sim(mid) < 0)
l = mid;
else
r = mid;
}
cnt += l + 1;
cout << (N - cnt) << endl;
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr << "[" << (x).FI << ", " << (x).SE << "]";
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWVEC(v, e) \
REP(i, e) cerr << (v[i]) << ' '; \
cerr << endl;
#define SHOW2D(a, h, w) \
REP(i, h) { \
REP(j, w) cerr << setw(3) << (a[i][j]) << ' '; \
cerr << endl; \
}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> P;
char t[210000], d[210000];
int N, Q;
string s;
int sim(int idx) {
REP(i, Q) {
if (s[idx] == t[i]) {
if (d[i] == 'L')
idx--;
else
idx++;
}
if (idx < 0 || idx >= N)
return idx;
}
return idx;
}
int main() {
cin >> N >> Q;
cin >> s;
REP(i, Q) cin >> t[i] >> d[i];
int l, r;
int cnt = 0;
l = -1, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
if (sim(mid) >= N)
r = mid;
else
l = mid;
}
cnt += N - r;
l = -1, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
if (sim(mid) < 0)
l = mid;
else
r = mid;
}
cnt += l + 1;
cout << (N - cnt) << endl;
return 0;
} | replace | 37 | 38 | 37 | 38 | 0 | |
p03081 | C++ | Runtime Error | /// supercalifragilisticexpialidocious.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(sum) sum.begin(), sum.end()
#define mem(a, b) memset(a, b, sizeof a)
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef map<string, int> msi;
typedef pair<int, string> pis;
const int MAXN = 1e5 + 10;
int n, q;
string s;
pair<char, char> c[MAXN];
int f(int i) {
int ptr = i;
for (int j = 0; j < q; j++)
if (c[j].f == s[ptr])
if (c[j].s == 'L')
ptr--;
else
ptr++;
if (ptr < 0)
return 0;
if (ptr >= n)
return 1;
return 2;
}
int32_t main() {
cin >> n >> q >> s;
for (int i = 0; i < q; i++)
cin >> c[i].f >> c[i].s;
int l = -1, r = n + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (f(mid) == 1)
r = mid;
else
l = mid;
}
int right = l;
l = -1, r = n + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (!f(mid))
l = mid;
else
r = mid;
}
return cout << n - (n - 1 - right + 1) - (l + 1) + 1 << endl, 0;
}
| /// supercalifragilisticexpialidocious.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(sum) sum.begin(), sum.end()
#define mem(a, b) memset(a, b, sizeof a)
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef map<string, int> msi;
typedef pair<int, string> pis;
const int MAXN = 2e5 + 10;
int n, q;
string s;
pair<char, char> c[MAXN];
int f(int i) {
int ptr = i;
for (int j = 0; j < q; j++)
if (c[j].f == s[ptr])
if (c[j].s == 'L')
ptr--;
else
ptr++;
if (ptr < 0)
return 0;
if (ptr >= n)
return 1;
return 2;
}
int32_t main() {
cin >> n >> q >> s;
for (int i = 0; i < q; i++)
cin >> c[i].f >> c[i].s;
int l = -1, r = n + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (f(mid) == 1)
r = mid;
else
l = mid;
}
int right = l;
l = -1, r = n + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (!f(mid))
l = mid;
else
r = mid;
}
return cout << n - (n - 1 - right + 1) - (l + 1) + 1 << endl, 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03081 | Python | Runtime Error | N, Q = map(int, input().split())
s = input()
Query = [input().split() for i in range(Q)]
left, right = 0, N - 1
for t, d in reversed(Query):
if d == "L":
if t == s[left]:
left += 1
if right < N - 1 and t == s[right + 1]:
right = min(right + 1, N - 1)
else:
if left > 0 and t == s[left - 1]:
left = max(left - 1, 0)
if t == s[right]:
right -= 1
print(max(right - left + 1, 0))
| # N, Q = map(int, input().split())
import sys
input = sys.stdin.readline
N, Q = tuple(map(int, input().split()))
s = input()
Query = [input().split() for i in range(Q)]
left, right = 0, N - 1
for t, d in reversed(Query):
if d == "L":
if t == s[left]:
left += 1
if right < N - 1 and t == s[right + 1]:
right = min(right + 1, N - 1)
else:
if left > 0 and t == s[left - 1]:
left = max(left - 1, 0)
if t == s[right]:
right -= 1
print(max(right - left + 1, 0))
| replace | 0 | 1 | 0 | 6 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define NMAX 7003
using namespace std;
int N, Q;
string s;
pair<char, char> Que[100003];
int fall(int x) {
if (x < 0)
return -1;
if (x >= N)
return 1;
for (int i = 0; i < Q; ++i) {
if (s[x] == Que[i].first) {
if (Que[i].second == 'L')
--x;
else
++x;
}
if (x < 0)
return -1;
if (x >= N)
return 1;
}
return 0;
}
int srch(int left, int right, int type) {
int mid, sol;
while (left <= right) {
mid = (left + right) / 2;
int x = fall(mid); // -1 L 0 STAY 1 R
if (x == 1) {
right = mid - 1;
} else if (x == -1) {
left = mid + 1;
} else {
if (type == 1)
left = mid + 1;
else
right = mid - 1;
}
if (type == x)
sol = mid;
}
return sol;
}
int main() {
cin >> N >> Q;
cin >> s;
for (int i = 0; i < Q; ++i) {
char t, d;
cin >> t >> d;
Que[i] = mp(t, d);
}
cout << N - (srch(-1, N, -1) + 1 + N - srch(0, N, 1));
return 0;
}
| #include <bits/stdc++.h>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define NMAX 7003
using namespace std;
int N, Q;
string s;
pair<char, char> Que[200007];
int fall(int x) {
if (x < 0)
return -1;
if (x >= N)
return 1;
for (int i = 0; i < Q; ++i) {
if (s[x] == Que[i].first) {
if (Que[i].second == 'L')
--x;
else
++x;
}
if (x < 0)
return -1;
if (x >= N)
return 1;
}
return 0;
}
int srch(int left, int right, int type) {
int mid, sol;
while (left <= right) {
mid = (left + right) / 2;
int x = fall(mid); // -1 L 0 STAY 1 R
if (x == 1) {
right = mid - 1;
} else if (x == -1) {
left = mid + 1;
} else {
if (type == 1)
left = mid + 1;
else
right = mid - 1;
}
if (type == x)
sol = mid;
}
return sol;
}
int main() {
cin >> N >> Q;
cin >> s;
for (int i = 0; i < Q; ++i) {
char t, d;
cin >> t >> d;
Que[i] = mp(t, d);
}
cout << N - (srch(-1, N, -1) + 1 + N - srch(0, N, 1));
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03081 | C++ | Runtime Error | #include <iostream>
using namespace std;
typedef long long ll;
char A[100000], B[100000];
ll n, k, s, g, m, ans;
string t;
bool f(ll p, ll q) {
for (int i = 0; i < k; i++) {
if (A[i] == t[p]) {
if (B[i] == 'L')
p--;
else
p++;
}
}
if (p == q)
return true;
return false;
}
int main(void) {
cin >> n >> k >> t;
t = '#' + t + '#';
for (int i = 0; i < k; i++)
cin >> A[i] >> B[i];
s = 0, g = n + 1;
while (g - s > 1) {
m = (g + s) / 2;
if (f(m, 0))
s = m;
else
g = m;
}
ans += s;
s = 0, g = n + 1;
// cout<<ans<<endl;
while (g - s > 1) {
m = (g + s) / 2;
if (f(m, n + 1))
g = m;
else
s = m;
// cout<<s<<g<<endl;
}
ans += n - s;
// cout<<ans<<endl;
cout << n - ans << endl;
}
| #include <iostream>
using namespace std;
typedef long long ll;
char A[200000], B[200000];
ll n, k, s, g, m, ans;
string t;
bool f(ll p, ll q) {
for (int i = 0; i < k; i++) {
if (A[i] == t[p]) {
if (B[i] == 'L')
p--;
else
p++;
}
}
if (p == q)
return true;
return false;
}
int main(void) {
cin >> n >> k >> t;
t = '#' + t + '#';
for (int i = 0; i < k; i++)
cin >> A[i] >> B[i];
s = 0, g = n + 1;
while (g - s > 1) {
m = (g + s) / 2;
if (f(m, 0))
s = m;
else
g = m;
}
ans += s;
s = 0, g = n + 1;
// cout<<ans<<endl;
while (g - s > 1) {
m = (g + s) / 2;
if (f(m, n + 1))
g = m;
else
s = m;
// cout<<s<<g<<endl;
}
ans += n - s;
// cout<<ans<<endl;
cout << n - ans << endl;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, Q;
cin >> N >> Q;
string s;
cin >> s;
vector<char> j(N);
vector<char> LR(Q);
vector<bool> ans1(N, false);
vector<bool> ans2(N, false);
for (int i = 0; i < Q; i++) {
cin >> j[i] >> LR[i];
}
char mL = s[0], mR = s[N - 1];
int lp = 0, rp = N - 1;
for (int i = Q - 1; i >= 0; i--) {
if (LR[i] == 'L') {
if (lp < N && lp >= 0 && j[i] == s[lp]) {
if (lp < N)
ans1[lp] = true;
lp++;
}
if (rp < N - 1 && rp >= 0 && j[i] == s[rp + 1]) {
if (rp < N)
ans2[rp + 1] = false;
rp++;
}
}
if (LR[i] == 'R') {
if (rp < N && rp >= 0 && j[i] == s[rp]) {
if (rp > -1)
ans2[rp] = true;
rp--;
}
if (lp < N && lp > 0 && j[i] == s[lp - 1]) {
if (lp > -1)
ans1[lp - 1] = false;
lp--;
}
}
}
int cnt = 0;
for (int i = 0; i < N; i++) {
if (ans1[i] || ans2[i])
cnt++;
}
cout << N - cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, Q;
cin >> N >> Q;
string s;
cin >> s;
vector<char> j(Q);
vector<char> LR(Q);
vector<bool> ans1(N, false);
vector<bool> ans2(N, false);
for (int i = 0; i < Q; i++) {
cin >> j[i] >> LR[i];
}
char mL = s[0], mR = s[N - 1];
int lp = 0, rp = N - 1;
for (int i = Q - 1; i >= 0; i--) {
if (LR[i] == 'L') {
if (lp < N && lp >= 0 && j[i] == s[lp]) {
if (lp < N)
ans1[lp] = true;
lp++;
}
if (rp < N - 1 && rp >= 0 && j[i] == s[rp + 1]) {
if (rp < N)
ans2[rp + 1] = false;
rp++;
}
}
if (LR[i] == 'R') {
if (rp < N && rp >= 0 && j[i] == s[rp]) {
if (rp > -1)
ans2[rp] = true;
rp--;
}
if (lp < N && lp > 0 && j[i] == s[lp - 1]) {
if (lp > -1)
ans1[lp - 1] = false;
lp--;
}
}
}
int cnt = 0;
for (int i = 0; i < N; i++) {
if (ans1[i] || ans2[i])
cnt++;
}
cout << N - cnt << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03081 | C++ | Runtime Error | // binary search
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define cls(x) memset(x, 0, sizeof(x))
int n, q;
const int INF = 0x3f3f3f3f;
const int SZ = 20005;
string s;
vector<pair<char, char>> ops(SZ);
bool okl(int ind) {
char t = s[ind];
for (int i = 0; i < q; ++i) {
char c = ops[i].first;
char op = ops[i].second;
if (t == c) {
if (op == 'L') {
ind--;
} else {
ind++;
}
if (ind == n)
return false;
if (ind == -1)
return true;
t = s[ind];
}
}
return false;
}
int bs_left() {
int l = 0, r = n;
while (l < r) {
int m = (l + r) >> 1;
if (!okl(m)) {
r = m;
} else {
l = m + 1;
}
}
return l;
}
bool okr(int ind) {
char t = s[ind];
for (int i = 0; i < q; ++i) {
char c = ops[i].first;
char op = ops[i].second;
if (t == c) {
if (op == 'R') {
ind++;
} else {
ind--;
}
if (ind == n)
return true;
if (ind == -1)
return false;
t = s[ind];
}
}
return false;
}
int bs_right() {
int l = 0, r = n;
while (l < r) {
int m = (l + r) >> 1;
if (okr(m)) {
r = m;
} else {
l = m + 1;
}
}
return l;
}
int main() {
cin >> n >> q;
cin >> s;
for (int i = 0; i < q; ++i) {
char ch, dir;
cin >> ch >> dir;
ops[i] = {ch, dir};
}
int left = bs_left();
int right = bs_right();
// cout << left << "," << right << endl;
if (right > left) {
cout << right - left << endl;
} else {
cout << 0 << endl;
}
return 0;
} | // binary search
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define cls(x) memset(x, 0, sizeof(x))
int n, q;
const int INF = 0x3f3f3f3f;
const int SZ = 200009;
string s;
vector<pair<char, char>> ops(SZ);
bool okl(int ind) {
char t = s[ind];
for (int i = 0; i < q; ++i) {
char c = ops[i].first;
char op = ops[i].second;
if (t == c) {
if (op == 'L') {
ind--;
} else {
ind++;
}
if (ind == n)
return false;
if (ind == -1)
return true;
t = s[ind];
}
}
return false;
}
int bs_left() {
int l = 0, r = n;
while (l < r) {
int m = (l + r) >> 1;
if (!okl(m)) {
r = m;
} else {
l = m + 1;
}
}
return l;
}
bool okr(int ind) {
char t = s[ind];
for (int i = 0; i < q; ++i) {
char c = ops[i].first;
char op = ops[i].second;
if (t == c) {
if (op == 'R') {
ind++;
} else {
ind--;
}
if (ind == n)
return true;
if (ind == -1)
return false;
t = s[ind];
}
}
return false;
}
int bs_right() {
int l = 0, r = n;
while (l < r) {
int m = (l + r) >> 1;
if (okr(m)) {
r = m;
} else {
l = m + 1;
}
}
return l;
}
int main() {
cin >> n >> q;
cin >> s;
for (int i = 0; i < q; ++i) {
char ch, dir;
cin >> ch >> dir;
ops[i] = {ch, dir};
}
int left = bs_left();
int right = bs_right();
// cout << left << "," << right << endl;
if (right > left) {
cout << right - left << endl;
} else {
cout << 0 << endl;
}
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p03081 | C++ | Runtime Error | typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
int main() {
ll n, q;
std::cin >> n >> q;
string s;
std::cin >> s;
vector<char> t(n), d(n);
for (int i = 0; i < q; i++) {
std::cin >> t[i] >> d[i];
}
ll l = -1;
ll r = n;
while (r - l > 1) {
ll mid = (r + l) / 2;
ll now = mid;
bool ok = false;
for (int i = 0; i < q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'R') {
now++;
} else {
now--;
}
if (now == -1) {
ok = true;
break;
}
}
}
if (ok) {
l = mid;
} else {
r = mid;
}
}
ll lcnt = l + 1;
// std::cout << lcnt << std::endl;
l = -1;
r = n;
while (r - l > 1) {
ll mid = (r + l) / 2;
ll now = mid;
bool ok = false;
for (int i = 0; i < q; i++) {
if (s[n - 1 - now] == t[i]) {
if (d[i] == 'R') {
now--;
} else {
now++;
}
if (now == -1) {
ok = true;
break;
}
}
}
if (ok) {
l = mid;
} else {
r = mid;
}
}
// std::cout << l+1 << std::endl;
std::cout << n - min(n, lcnt + l + 1) << std::endl;
}
| typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
int main() {
ll n, q;
std::cin >> n >> q;
string s;
std::cin >> s;
vector<char> t(q), d(q);
for (int i = 0; i < q; i++) {
std::cin >> t[i] >> d[i];
}
ll l = -1;
ll r = n;
while (r - l > 1) {
ll mid = (r + l) / 2;
ll now = mid;
bool ok = false;
for (int i = 0; i < q; i++) {
if (s[now] == t[i]) {
if (d[i] == 'R') {
now++;
} else {
now--;
}
if (now == -1) {
ok = true;
break;
}
}
}
if (ok) {
l = mid;
} else {
r = mid;
}
}
ll lcnt = l + 1;
// std::cout << lcnt << std::endl;
l = -1;
r = n;
while (r - l > 1) {
ll mid = (r + l) / 2;
ll now = mid;
bool ok = false;
for (int i = 0; i < q; i++) {
if (s[n - 1 - now] == t[i]) {
if (d[i] == 'R') {
now--;
} else {
now++;
}
if (now == -1) {
ok = true;
break;
}
}
}
if (ok) {
l = mid;
} else {
r = mid;
}
}
// std::cout << l+1 << std::endl;
std::cout << n - min(n, lcnt + l + 1) << std::endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long int ll;
int n, q;
string s;
char t[114514], d[114514];
int sim(int pos) {
for (int i = 0; i < q; i++) {
if (t[i] == s[pos]) {
pos += (d[i] == 'R') ? 1 : -1;
}
if (pos < 0)
return -1;
if (pos >= n)
return 1;
}
return 0;
}
int main(void) {
cin >> n >> q;
cin >> s;
for (int i = 0; i < q; i++)
cin >> t[i] >> d[i];
// 何番目まで左に落ちるか
int lo = -1, hi = n, mid1, mid2;
while (lo + 1 < hi) {
// cerr << lo << " " << hi << endl;
mid1 = (lo + hi) / 2;
if (sim(mid1) == -1) {
lo = mid1;
} else {
hi = mid1;
}
}
int left = lo;
// 何番目まで右に落ちないか
lo = -1, hi = n;
while (lo + 1 < hi) {
// cerr << lo << ":" << hi << endl;
mid2 = (lo + hi) / 2;
if (sim(mid2) == 1) {
hi = mid2;
} else {
lo = mid2;
}
}
int right = lo;
// cerr << left << " and " << right << endl;
cout << right - left << endl;
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long int ll;
int n, q;
string s;
char t[214514], d[214514];
int sim(int pos) {
for (int i = 0; i < q; i++) {
if (t[i] == s[pos]) {
pos += (d[i] == 'R') ? 1 : -1;
}
if (pos < 0)
return -1;
if (pos >= n)
return 1;
}
return 0;
}
int main(void) {
cin >> n >> q;
cin >> s;
for (int i = 0; i < q; i++)
cin >> t[i] >> d[i];
// 何番目まで左に落ちるか
int lo = -1, hi = n, mid1, mid2;
while (lo + 1 < hi) {
// cerr << lo << " " << hi << endl;
mid1 = (lo + hi) / 2;
if (sim(mid1) == -1) {
lo = mid1;
} else {
hi = mid1;
}
}
int left = lo;
// 何番目まで右に落ちないか
lo = -1, hi = n;
while (lo + 1 < hi) {
// cerr << lo << ":" << hi << endl;
mid2 = (lo + hi) / 2;
if (sim(mid2) == 1) {
hi = mid2;
} else {
lo = mid2;
}
}
int right = lo;
// cerr << left << " and " << right << endl;
cout << right - left << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#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 SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#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 PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
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 pll = pair<ll, ll>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll n, q;
string s;
vector<char> t, d;
bool isOkL(ll mid) {
ll pos = mid;
rep(i, q) {
if (s[pos] == t[i]) {
if (d[i] == 'L') {
pos--;
if (pos < 0)
return true;
} else {
pos++;
if (pos >= n)
return false;
}
}
}
return false;
}
bool isOkR(ll mid) {
ll pos = mid;
rep(i, q) {
if (s[pos] == t[i]) {
if (d[i] == 'R') {
pos++;
if (pos >= n)
return true;
} else {
pos--;
if (pos < 0)
return false;
}
}
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> q >> s;
t.resize(n), d.resize(n);
rep(i, q) cin >> t[i] >> d[i];
ll ans = 0;
ll ok = -1, ng = n + 1;
while (abs(ok - ng) > 1) {
ll m = (ok + ng) / 2;
if (isOkL(m))
ok = m;
else
ng = m;
}
ans = ok + 1;
ok = n, ng = -1;
while (abs(ok - ng) > 1) {
ll m = (ok + ng) / 2;
if (isOkR(m))
ok = m;
else
ng = m;
}
ans += n - ok;
ans = n - ans;
chmin(ans, n);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#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 SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#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 PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
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 pll = pair<ll, ll>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll n, q;
string s;
vector<char> t, d;
bool isOkL(ll mid) {
ll pos = mid;
rep(i, q) {
if (s[pos] == t[i]) {
if (d[i] == 'L') {
pos--;
if (pos < 0)
return true;
} else {
pos++;
if (pos >= n)
return false;
}
}
}
return false;
}
bool isOkR(ll mid) {
ll pos = mid;
rep(i, q) {
if (s[pos] == t[i]) {
if (d[i] == 'R') {
pos++;
if (pos >= n)
return true;
} else {
pos--;
if (pos < 0)
return false;
}
}
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> q >> s;
t.resize(q), d.resize(q);
rep(i, q) cin >> t[i] >> d[i];
ll ans = 0;
ll ok = -1, ng = n + 1;
while (abs(ok - ng) > 1) {
ll m = (ok + ng) / 2;
if (isOkL(m))
ok = m;
else
ng = m;
}
ans = ok + 1;
ok = n, ng = -1;
while (abs(ok - ng) > 1) {
ll m = (ok + ng) / 2;
if (isOkR(m))
ok = m;
else
ng = m;
}
ans += n - ok;
ans = n - ans;
chmin(ans, n);
cout << ans << endl;
}
| replace | 94 | 95 | 94 | 95 | 0 | |
p03081 | C++ | Time Limit Exceeded | #include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int N, Q;
string s;
vector<int> c(200000, 0);
vector<vector<int>> td(200000, vector<int>(2, 0));
int bsL(int l, int r) {
// cout << 'L' << ' ' << l << ' ' << r << endl;
int mid = (l + r) / 2;
if (mid == l || r == 0) {
return l;
}
int now = mid;
for (int i = 0; i < Q; i++) {
// cout << now << endl;
if (c[now] == td[i][0]) {
now += td[i][1];
}
if (now < 0) {
return bsL(mid, r);
} else if (now >= N) {
break;
}
}
return bsL(l, mid);
}
int bsR(int l, int r) {
// cout << 'R' << ' ' << l << ' ' << r << endl;
int mid = (l + r) / 2;
if (mid == l) {
return r;
}
int now = mid;
for (int i = 0; i < Q; i++) {
// cout << now << endl;
if (c[now] == td[i][0]) {
now += td[i][1];
}
if (now >= N) {
return bsR(l, mid);
} else if (now < 0) {
break;
}
}
return bsR(mid, r);
}
int main() {
cin >> N >> Q;
cin >> s;
for (int i = 0; i < N; i++) {
c[i] = s[i] - 'A';
}
for (int i = 0; i < Q; i++) {
char t, d;
cin >> t >> d;
td[i][0] = t - 'A';
if (d == 'L') {
td[i][1] = -1;
} else {
td[i][1] = 1;
}
}
int ans = N;
ans -= bsL(-1, N) + 1;
ans -= N - bsR(-1, N);
cout << ans << endl;
} | #include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int N, Q;
string s;
vector<int> c(200000, 0);
vector<vector<int>> td(200000, vector<int>(2, 0));
int bsL(int l, int r) {
// cout << 'L' << ' ' << l << ' ' << r << endl;
int mid = (l + r) / 2;
if (mid == l || r == 0) {
return l;
}
int now = mid;
for (int i = 0; i < Q; i++) {
// cout << now << endl;
if (c[now] == td[i][0]) {
now += td[i][1];
}
if (now < 0) {
return bsL(mid, r);
} else if (now >= N) {
break;
}
}
return bsL(l, mid);
}
int bsR(int l, int r) {
// cout << 'R' << ' ' << l << ' ' << r << endl;
int mid = (l + r) / 2;
if (mid == l || r == 0) {
return r;
}
int now = mid;
for (int i = 0; i < Q; i++) {
// cout << now << endl;
if (c[now] == td[i][0]) {
now += td[i][1];
}
if (now >= N) {
return bsR(l, mid);
} else if (now < 0) {
break;
}
}
return bsR(mid, r);
}
int main() {
cin >> N >> Q;
cin >> s;
for (int i = 0; i < N; i++) {
c[i] = s[i] - 'A';
}
for (int i = 0; i < Q; i++) {
char t, d;
cin >> t >> d;
td[i][0] = t - 'A';
if (d == 'L') {
td[i][1] = -1;
} else {
td[i][1] = 1;
}
}
int ans = N;
ans -= bsL(-1, N) + 1;
ans -= N - bsR(-1, N);
cout << ans << endl;
} | replace | 43 | 44 | 43 | 44 | TLE | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FOR(i, k, n) for (int i = (k); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using vecint = vector<int>;
using ll = int64_t;
int pos(const string &s, const string &t, const vector<bool> &dir, int i) {
int q = t.size();
REP(j, q) {
if (s[i] == t[j]) {
if (dir[j]) {
--i;
} else {
++i;
}
}
}
return i;
}
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
string t;
vector<bool> dir(n);
REP(i, q) {
string c;
string d;
cin >> c >> d;
t.push_back(c[0]);
dir[i] = d[0] == 'L';
}
s = "$" + s + "$";
int lo = 0;
int hi = n + 1;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
if (pos(s, t, dir, mid) == 0) {
lo = mid;
} else {
hi = mid;
}
}
int left = lo;
lo = 0;
hi = n + 1;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
if (pos(s, t, dir, mid) == n + 1) {
hi = mid;
} else {
lo = mid;
}
}
int right = n + 1 - hi;
cout << (n - left - right) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, k, n) for (int i = (k); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using vecint = vector<int>;
using ll = int64_t;
int pos(const string &s, const string &t, const vector<bool> &dir, int i) {
int q = t.size();
REP(j, q) {
if (s[i] == t[j]) {
if (dir[j]) {
--i;
} else {
++i;
}
}
}
return i;
}
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
string t;
vector<bool> dir(q);
REP(i, q) {
string c;
string d;
cin >> c >> d;
t.push_back(c[0]);
dir[i] = d[0] == 'L';
}
s = "$" + s + "$";
int lo = 0;
int hi = n + 1;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
if (pos(s, t, dir, mid) == 0) {
lo = mid;
} else {
hi = mid;
}
}
int left = lo;
lo = 0;
hi = n + 1;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
if (pos(s, t, dir, mid) == n + 1) {
hi = mid;
} else {
lo = mid;
}
}
int right = n + 1 - hi;
cout << (n - left - right) << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03081 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int func(int start, string s, char *t, char *d, int Q, int N);
int main(void) {
int N;
cin >> N;
int Q;
cin >> Q;
string s;
cin >> s;
int min;
int max;
char t[Q];
char d[Q];
for (int i = 0; i < Q; i++) {
cin >> t[i];
cin >> d[i];
}
int A;
A = 0;
int B;
B = N - 1;
int C;
for (int k = 0; k < N; k++) {
if (func(0, s, t, d, Q, N) >= 0) {
min = 0;
break;
}
if (func(N - 1, s, t, d, Q, N) < 0) {
min = N;
break;
}
C = (A + B) / 2;
if (func(C, s, t, d, Q, N) < 0) {
A = C;
} else {
B = C;
}
if (A + 1 == B && func(A, s, t, d, Q, N) < 0 &&
func(B, s, t, d, Q, N) >= 0) {
min = B;
break;
}
}
A = 0;
B = N - 1;
for (int l = 0; l < N; l++) {
if (func(N - 1, s, t, d, Q, N) < N) {
max = N - 1;
break;
}
if (func(0, s, t, d, Q, N) > N) {
max = -1;
break;
}
C = (A + B) / 2;
if (func(C, s, t, d, Q, N) >= N) {
B = C;
} else {
A = C;
}
if (A + 1 == B && func(A, s, t, d, Q, N) < N &&
func(B, s, t, d, Q, N) >= N) {
max = A;
break;
}
}
cout << max - min + 1 << endl;
}
int func(int start, string s, char *t, char *d, int Q, int N) {
for (int i = 0; i < Q; i++) {
if (i > 0) {
++t;
++d;
}
if (*t == s[start]) {
if (*d == 'R') {
start++;
} else {
start = start - 1;
}
if (start < 0 || start >= N) {
return start;
break;
}
}
}
return start;
} | #include <iostream>
#include <string>
using namespace std;
int func(int start, string s, char *t, char *d, int Q, int N);
int main(void) {
int N;
cin >> N;
int Q;
cin >> Q;
string s;
cin >> s;
int min;
int max;
char t[Q];
char d[Q];
for (int i = 0; i < Q; i++) {
cin >> t[i];
cin >> d[i];
}
int A;
A = 0;
int B;
B = N - 1;
int C;
for (int k = 0; k < N; k++) {
if (func(0, s, t, d, Q, N) >= 0) {
min = 0;
break;
}
if (func(N - 1, s, t, d, Q, N) < 0) {
min = N;
break;
}
C = (A + B) / 2;
if (func(C, s, t, d, Q, N) < 0) {
A = C;
} else {
B = C;
}
if (A + 1 == B && func(A, s, t, d, Q, N) < 0 &&
func(B, s, t, d, Q, N) >= 0) {
min = B;
break;
}
}
A = 0;
B = N - 1;
for (int l = 0; l < N; l++) {
if (func(N - 1, s, t, d, Q, N) < N) {
max = N - 1;
break;
}
if (func(0, s, t, d, Q, N) >= N) {
max = -1;
break;
}
C = (A + B) / 2;
if (func(C, s, t, d, Q, N) >= N) {
B = C;
} else {
A = C;
}
if (A + 1 == B && func(A, s, t, d, Q, N) < N &&
func(B, s, t, d, Q, N) >= N) {
max = A;
break;
}
}
cout << max - min + 1 << endl;
}
int func(int start, string s, char *t, char *d, int Q, int N) {
for (int i = 0; i < Q; i++) {
if (i > 0) {
++t;
++d;
}
if (*t == s[start]) {
if (*d == 'R') {
start++;
} else {
start = start - 1;
}
if (start < 0 || start >= N) {
return start;
break;
}
}
}
return start;
} | replace | 56 | 57 | 56 | 57 | TLE | |
p03081 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for (long long i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (long long i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int INF = 1e18;
signed main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
char t[n], d[n];
REP(i, q) cin >> t[i] >> d[i];
int ok = n;
int ng = -1;
int mid;
while (ok - ng > 1) {
mid = (ok + ng) / 2;
int loc = mid;
bool flg = false;
REP(i, q) {
if (loc == -1)
break;
if (loc == n) {
flg = true;
break;
}
if (t[i] == s[loc]) {
if (d[i] == 'R')
loc++;
else
loc--;
if (loc == n) {
flg = true;
break;
}
if (loc == -1)
break;
}
}
if (flg)
ok = mid;
else
ng = mid;
}
int ok2 = -1;
int ng2 = n;
int mid2;
while (ng2 - ok2 > 1) {
mid2 = (ok2 + ng2) / 2;
int loc = mid2;
bool flg = false;
REP(i, q) {
if (loc == n)
break;
if (loc == -1) {
flg = true;
break;
}
if (t[i] == s[loc]) {
if (d[i] == 'R')
loc++;
else
loc--;
if (loc == n)
break;
if (loc == -1) {
flg = true;
break;
}
}
}
if (flg)
ok2 = mid2;
else
ng2 = mid2;
}
cout << max(n - (n - ok) - (ok2 + 1), 0ll) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for (long long i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (long long i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPS(i, n) RFOR(i, n, 1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int INF = 1e18;
signed main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
char t[q], d[q];
REP(i, q) cin >> t[i] >> d[i];
int ok = n;
int ng = -1;
int mid;
while (ok - ng > 1) {
mid = (ok + ng) / 2;
int loc = mid;
bool flg = false;
REP(i, q) {
if (loc == -1)
break;
if (loc == n) {
flg = true;
break;
}
if (t[i] == s[loc]) {
if (d[i] == 'R')
loc++;
else
loc--;
if (loc == n) {
flg = true;
break;
}
if (loc == -1)
break;
}
}
if (flg)
ok = mid;
else
ng = mid;
}
int ok2 = -1;
int ng2 = n;
int mid2;
while (ng2 - ok2 > 1) {
mid2 = (ok2 + ng2) / 2;
int loc = mid2;
bool flg = false;
REP(i, q) {
if (loc == n)
break;
if (loc == -1) {
flg = true;
break;
}
if (t[i] == s[loc]) {
if (d[i] == 'R')
loc++;
else
loc--;
if (loc == n)
break;
if (loc == -1) {
flg = true;
break;
}
}
}
if (flg)
ok2 = mid2;
else
ng2 = mid2;
}
cout << max(n - (n - ok) - (ok2 + 1), 0ll) << endl;
} | replace | 36 | 37 | 36 | 37 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.