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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03204 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define For(i, l, r) for (int i = (l), i##end = (r); i <= i##end; i++)
#define Fordown(i, r, l) for (int i = (r), i##end = (l); i >= i##end; i--)
#define debug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
int to[N << 1], nex[N << 1], beg[N], Max[N], ans[N];
int e, n;
inline int read() {
int x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
flag = -1, ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
return x * flag;
}
inline void add(int x, int y) { to[++e] = y, nex[e] = beg[x], beg[x] = e; }
inline void dfs(int x, int fa, int Las, int Sec) {
Max[x] = Max[fa];
if (fa > Max[x])
Max[x] = fa, Las = Sec = x;
else
chkmax(Sec, x);
if (x > Max[x])
ans[x]++;
else if (Max[Max[x]] > Sec)
ans[Max[x]]++;
else
ans[Las]++;
for (int i = beg[x]; i; i = nex[i]) {
if (to[i] == fa)
continue;
dfs(to[i], x, Las, Sec);
}
}
inline void dfs_ans(int x, int fa) {
ans[x] += ans[fa];
for (int i = beg[x]; i; i = nex[i]) {
if (to[i] == fa)
continue;
dfs_ans(to[i], x);
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("AGC029E.in", "r", stdin);
freopen("AGC029E.out", "w", stdout);
#endif
n = read();
For(i, 2, n) {
int x = read(), y = read();
add(x, y), add(y, x);
}
For(i, 1, n) Max[i] = i;
dfs(1, 0, 0, 0), ans[1] = 0, dfs_ans(1, 0);
For(i, 2, n) printf("%d%c", ans[i], i == n ? '\n' : ' ');
return 0;
}
| #include <bits/stdc++.h>
#define For(i, l, r) for (int i = (l), i##end = (r); i <= i##end; i++)
#define Fordown(i, r, l) for (int i = (r), i##end = (l); i >= i##end; i--)
#define debug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
int to[N << 1], nex[N << 1], beg[N], Max[N], ans[N];
int e, n;
inline int read() {
int x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
flag = -1, ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
return x * flag;
}
inline void add(int x, int y) { to[++e] = y, nex[e] = beg[x], beg[x] = e; }
inline void dfs(int x, int fa, int Las, int Sec) {
Max[x] = Max[fa];
if (fa > Max[x])
Max[x] = fa, Las = Sec = x;
else
chkmax(Sec, x);
if (x > Max[x])
ans[x]++;
else if (Max[Max[x]] > Sec)
ans[Max[x]]++;
else
ans[Las]++;
for (int i = beg[x]; i; i = nex[i]) {
if (to[i] == fa)
continue;
dfs(to[i], x, Las, Sec);
}
}
inline void dfs_ans(int x, int fa) {
ans[x] += ans[fa];
for (int i = beg[x]; i; i = nex[i]) {
if (to[i] == fa)
continue;
dfs_ans(to[i], x);
}
}
int main() {
n = read();
For(i, 2, n) {
int x = read(), y = read();
add(x, y), add(y, x);
}
For(i, 1, n) Max[i] = i;
dfs(1, 0, 0, 0), ans[1] = 0, dfs_ans(1, 0);
For(i, 2, n) printf("%d%c", ans[i], i == n ? '\n' : ' ');
return 0;
}
| delete | 65 | 69 | 65 | 65 | TLE | |
p03204 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const int _ = 1e5 + 7;
struct Edge {
int end, upEd;
} Ed[_ << 1];
int head[_], cntEd, N;
void addEd(int a, int b) {
Ed[++cntEd] = (Edge){b, head[a]};
head[a] = cntEd;
}
int fa[_], mx[_], ts;
vector<int> nxt[_];
void dfs(int x, int p, int m) {
fa[x] = p;
mx[x] = m;
if (m < x) {
nxt[m].push_back(x);
m = x;
}
for (int i = head[x]; i; i = Ed[i].upEd)
if (Ed[i].end != p)
dfs(Ed[i].end, x, m);
}
int sum[_], tmp[_];
void down(int x, int p) {
for (int i = head[x]; i; i = Ed[i].upEd)
if (Ed[i].end != p) {
sum[Ed[i].end] += sum[x];
down(Ed[i].end, x);
}
}
int pre[_], sz[_];
int find(int x) { return pre[x] == x ? x : (pre[x] = find(pre[x])); }
signed main() {
ios::sync_with_stdio(0);
cin >> N;
for (int i = 1; i < N; ++i) {
int a, b;
cin >> a >> b;
addEd(a, b);
addEd(b, a);
}
dfs(1, 0, 0);
for (int i = 1; i <= N; ++i)
pre[i] = i;
for (int i = 1; i <= N; ++i) {
if (mx[i] < i) {
for (auto x : nxt[i]) {
int cur = 0;
for (int j = head[x]; j; j = Ed[j].upEd)
if (Ed[j].end != fa[x])
cur += sz[find(Ed[j].end)];
tmp[x] = 1 + cur;
for (int j = head[x]; j; j = Ed[j].upEd)
if (Ed[j].end != fa[x])
sum[Ed[j].end] += cur - sz[find(Ed[j].end)];
}
for (int j = head[i]; j; j = Ed[j].upEd)
if (Ed[j].end != fa[i])
sum[Ed[j].end] += sz[find(Ed[j].end)] + 1;
}
sz[i] = 1;
for (int j = head[i]; j; j = Ed[j].upEd)
if (Ed[j].end < i) {
sz[find(i)] += sz[find(Ed[j].end)];
pre[find(Ed[j].end)] = find(i);
}
}
down(1, 0);
for (int i = 2; i <= N; ++i)
printf("%d ", sum[i] + tmp[i] - 1);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const int _ = 2e5 + 7;
struct Edge {
int end, upEd;
} Ed[_ << 1];
int head[_], cntEd, N;
void addEd(int a, int b) {
Ed[++cntEd] = (Edge){b, head[a]};
head[a] = cntEd;
}
int fa[_], mx[_], ts;
vector<int> nxt[_];
void dfs(int x, int p, int m) {
fa[x] = p;
mx[x] = m;
if (m < x) {
nxt[m].push_back(x);
m = x;
}
for (int i = head[x]; i; i = Ed[i].upEd)
if (Ed[i].end != p)
dfs(Ed[i].end, x, m);
}
int sum[_], tmp[_];
void down(int x, int p) {
for (int i = head[x]; i; i = Ed[i].upEd)
if (Ed[i].end != p) {
sum[Ed[i].end] += sum[x];
down(Ed[i].end, x);
}
}
int pre[_], sz[_];
int find(int x) { return pre[x] == x ? x : (pre[x] = find(pre[x])); }
signed main() {
ios::sync_with_stdio(0);
cin >> N;
for (int i = 1; i < N; ++i) {
int a, b;
cin >> a >> b;
addEd(a, b);
addEd(b, a);
}
dfs(1, 0, 0);
for (int i = 1; i <= N; ++i)
pre[i] = i;
for (int i = 1; i <= N; ++i) {
if (mx[i] < i) {
for (auto x : nxt[i]) {
int cur = 0;
for (int j = head[x]; j; j = Ed[j].upEd)
if (Ed[j].end != fa[x])
cur += sz[find(Ed[j].end)];
tmp[x] = 1 + cur;
for (int j = head[x]; j; j = Ed[j].upEd)
if (Ed[j].end != fa[x])
sum[Ed[j].end] += cur - sz[find(Ed[j].end)];
}
for (int j = head[i]; j; j = Ed[j].upEd)
if (Ed[j].end != fa[i])
sum[Ed[j].end] += sz[find(Ed[j].end)] + 1;
}
sz[i] = 1;
for (int j = head[i]; j; j = Ed[j].upEd)
if (Ed[j].end < i) {
sz[find(i)] += sz[find(Ed[j].end)];
pre[find(Ed[j].end)] = find(i);
}
}
down(1, 0);
for (int i = 2; i <= N; ++i)
printf("%d ", sum[i] + tmp[i] - 1);
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p03204 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N;
vector<int> g[200000];
int ans[100000];
map<int, int> mp[200000];
int dfs2(int idx, int par, int v) {
if (mp[idx].count(v))
return mp[idx][v];
int ret = 1;
for (auto &to : g[idx]) {
if (to == par)
continue;
if (to < v)
ret += dfs2(to, idx, v);
}
return mp[idx][v] = ret;
}
void dfs(int idx, int par, int c, int delta) {
int add = dfs2(idx, par, max(c, par));
if (c > idx)
add -= dfs2(idx, par, c);
delta += add;
ans[idx] = delta;
for (auto &to : g[idx]) {
if (to == par)
continue;
dfs(to, idx, max(c, par), delta);
}
}
int main() {
cin >> N;
for (int i = 1; i < N; i++) {
int x, y;
cin >> x >> y;
--x, --y;
g[x].push_back(y);
g[y].push_back(x);
}
for (auto to : g[0])
dfs(to, 0, 0, 0);
for (int i = 1; i < N; i++)
cout << ans[i] << " ";
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int N;
vector<int> g[200000];
int ans[200000];
map<int, int> mp[200000];
int dfs2(int idx, int par, int v) {
if (mp[idx].count(v))
return mp[idx][v];
int ret = 1;
for (auto &to : g[idx]) {
if (to == par)
continue;
if (to < v)
ret += dfs2(to, idx, v);
}
return mp[idx][v] = ret;
}
void dfs(int idx, int par, int c, int delta) {
int add = dfs2(idx, par, max(c, par));
if (c > idx)
add -= dfs2(idx, par, c);
delta += add;
ans[idx] = delta;
for (auto &to : g[idx]) {
if (to == par)
continue;
dfs(to, idx, max(c, par), delta);
}
}
int main() {
cin >> N;
for (int i = 1; i < N; i++) {
int x, y;
cin >> x >> y;
--x, --y;
g[x].push_back(y);
g[y].push_back(x);
}
for (auto to : g[0])
dfs(to, 0, 0, 0);
for (int i = 1; i < N; i++)
cout << ans[i] << " ";
cout << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03204 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define MOD 998244353LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define DUMP(a) \
REP(d, a.size()) { \
cout << a[d]; \
if (d != a.size() - 1) \
cout << " "; \
else \
cout << endl; \
}
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) \
sort(ALL(v)); \
v.erase(unique(ALL(v)), v.end());
#define pb push_back
vector<vector<ll>> g;
vector<ll> weight;
vector<ll> ans;
constexpr int MAX_SIZE = 505050;
template <typename T> class SegTree {
private:
int n;
const function<T(T, T)> op; // 演算
const T ie; // 演算の単位元
T seq[MAX_SIZE];
public:
/// op: 演算, ie: 演算の単位元
SegTree(int _n, function<T(T, T)> op, const T ie) : op(op), ie(ie) {
n = 1;
while (n < _n)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
seq[i] = ie;
}
/// k 番目(0-indexed)の要素を e で更新
void update(ll k, const T e) {
k += n - 1;
seq[k] = e;
while (k > 0) {
k = (k - 1) / 2;
seq[k] = op(seq[k * 2 + 1], seq[k * 2 + 2]);
}
}
// k 番目(0-indexed)の要素を取得
T get(ll k) {
k += n - 1;
return seq[k];
}
/// [a, b) 番目(0-indexed)の要素全体の演算結果を返す
T query(ll a, ll b, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = n;
if (r <= a || b <= l)
return ie;
if (a <= l && r <= b)
return seq[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 op(vl, vr);
}
};
// [Range Maximum Query] op: [] (long long a, long long b) { return max(a, b);
// }, ie: -1e18
void dfs(ll pos, ll par, ll dpt, ll maxi_pos, SegTree<ll> &seg) {
seg.update(dpt, pos);
if (seg.get(maxi_pos) > pos) {
if (seg.query(0, maxi_pos) > seg.query(maxi_pos + 1, dpt + 1)) {
weight[seg.get(maxi_pos)]++;
} else
weight[seg.get(maxi_pos + 1)]++;
} else
weight[pos]++;
REP(i, g[pos].size()) {
if (g[pos][i] == par)
continue;
if (seg.get(maxi_pos) < pos) {
dfs(g[pos][i], pos, dpt + 1, dpt, seg);
} else {
dfs(g[pos][i], pos, dpt + 1, maxi_pos, seg);
}
}
seg.update(dpt, -1);
return;
}
void calc(ll pos, ll par, ll cost) {
cost += weight[pos];
if (pos != 0)
ans[pos - 1] = cost - 1;
REP(i, g[pos].size()) {
if (g[pos][i] == par)
continue;
calc(g[pos][i], pos, cost);
}
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
g.resize(n);
weight.assign(n, 0);
REP(i, n - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
g[a].pb(b);
g[b].pb(a);
}
SegTree<ll> seg(
n + 1, [](ll a, ll b) { return max(a, b); }, -1);
dfs(0, -1, 1, 0, seg);
ans.resize(n - 1);
calc(0, -1, 0);
DUMP(ans);
return 0;
}
/* --------------------------------------- */
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <time.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define MOD 998244353LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define REP(i, n) FOR(i, 0, n)
#define DUMP(a) \
REP(d, a.size()) { \
cout << a[d]; \
if (d != a.size() - 1) \
cout << " "; \
else \
cout << endl; \
}
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) \
sort(ALL(v)); \
v.erase(unique(ALL(v)), v.end());
#define pb push_back
vector<vector<ll>> g;
vector<ll> weight;
vector<ll> ans;
constexpr int MAX_SIZE = 1000010;
template <typename T> class SegTree {
private:
int n;
const function<T(T, T)> op; // 演算
const T ie; // 演算の単位元
T seq[MAX_SIZE];
public:
/// op: 演算, ie: 演算の単位元
SegTree(int _n, function<T(T, T)> op, const T ie) : op(op), ie(ie) {
n = 1;
while (n < _n)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
seq[i] = ie;
}
/// k 番目(0-indexed)の要素を e で更新
void update(ll k, const T e) {
k += n - 1;
seq[k] = e;
while (k > 0) {
k = (k - 1) / 2;
seq[k] = op(seq[k * 2 + 1], seq[k * 2 + 2]);
}
}
// k 番目(0-indexed)の要素を取得
T get(ll k) {
k += n - 1;
return seq[k];
}
/// [a, b) 番目(0-indexed)の要素全体の演算結果を返す
T query(ll a, ll b, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = n;
if (r <= a || b <= l)
return ie;
if (a <= l && r <= b)
return seq[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 op(vl, vr);
}
};
// [Range Maximum Query] op: [] (long long a, long long b) { return max(a, b);
// }, ie: -1e18
void dfs(ll pos, ll par, ll dpt, ll maxi_pos, SegTree<ll> &seg) {
seg.update(dpt, pos);
if (seg.get(maxi_pos) > pos) {
if (seg.query(0, maxi_pos) > seg.query(maxi_pos + 1, dpt + 1)) {
weight[seg.get(maxi_pos)]++;
} else
weight[seg.get(maxi_pos + 1)]++;
} else
weight[pos]++;
REP(i, g[pos].size()) {
if (g[pos][i] == par)
continue;
if (seg.get(maxi_pos) < pos) {
dfs(g[pos][i], pos, dpt + 1, dpt, seg);
} else {
dfs(g[pos][i], pos, dpt + 1, maxi_pos, seg);
}
}
seg.update(dpt, -1);
return;
}
void calc(ll pos, ll par, ll cost) {
cost += weight[pos];
if (pos != 0)
ans[pos - 1] = cost - 1;
REP(i, g[pos].size()) {
if (g[pos][i] == par)
continue;
calc(g[pos][i], pos, cost);
}
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
g.resize(n);
weight.assign(n, 0);
REP(i, n - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
g[a].pb(b);
g[b].pb(a);
}
SegTree<ll> seg(
n + 1, [](ll a, ll b) { return max(a, b); }, -1);
dfs(0, -1, 1, 0, seg);
ans.resize(n - 1);
calc(0, -1, 0);
DUMP(ans);
return 0;
}
/* --------------------------------------- */
| replace | 41 | 42 | 41 | 42 | 0 | |
p03204 | C++ | Runtime Error | #include <cstdio>
#include <queue>
using namespace std;
#define N 100050
int fa[N], sz[N], head[N], cnt, mx[N], f[N], ti = 1, as[N], n, a, b, fr[N],
vl[N];
struct edge {
int t, next;
} ed[N * 2];
priority_queue<pair<int, int>> st;
int finds(int x) { return fa[x] == x ? x : fa[x] = finds(fa[x]); }
void adde(int f, int t) {
ed[++cnt] = (edge){t, head[f]};
head[f] = cnt;
ed[++cnt] = (edge){f, head[t]};
head[t] = cnt;
}
void dfs1(int u, int fa) {
f[u] = fa;
mx[u] = mx[f[u]], fr[u] = fr[f[u]];
if (mx[u] < fa)
mx[u] = fa, fr[u] = u;
for (int i = head[u]; i; i = ed[i].next)
if (ed[i].t != fa)
dfs1(ed[i].t, u);
}
int que(int x) {
if (x < ti)
return sz[finds(x)] - 1;
int as = 0;
for (int i = head[x]; i; i = ed[i].next)
if (ed[i].t < ti)
as += sz[finds(ed[i].t)];
return as;
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++)
scanf("%d%d", &a, &b), adde(a, b);
for (int i = 1; i <= n; i++)
fa[i] = i, sz[i] = 1;
dfs1(1, 0);
for (int i = head[1]; i; i = ed[i].next)
st.push(make_pair(-1, ed[i].t));
while (!st.empty()) {
int las = ti;
ti = -st.top().first;
int s = st.top().second;
st.pop();
for (int i = las; i < ti; i++)
for (int j = head[i]; j; j = ed[j].next)
if (ed[j].t < i) {
int a = finds(i), b = finds(ed[j].t);
fa[a] = b, sz[b] += sz[a];
}
as[s] += as[mx[s]] + que(s) + 1 - vl[fr[s]];
for (int i = head[s]; i; i = ed[i].next)
if (ed[i].t != f[s])
st.push(make_pair(-mx[ed[i].t], ed[i].t)),
vl[ed[i].t] = ed[i].t < ti ? sz[finds(ed[i].t)] : 0;
}
for (int i = 2; i <= n; i++)
printf("%d ", as[i]);
} | #include <cstdio>
#include <queue>
using namespace std;
#define N 200050
int fa[N], sz[N], head[N], cnt, mx[N], f[N], ti = 1, as[N], n, a, b, fr[N],
vl[N];
struct edge {
int t, next;
} ed[N * 2];
priority_queue<pair<int, int>> st;
int finds(int x) { return fa[x] == x ? x : fa[x] = finds(fa[x]); }
void adde(int f, int t) {
ed[++cnt] = (edge){t, head[f]};
head[f] = cnt;
ed[++cnt] = (edge){f, head[t]};
head[t] = cnt;
}
void dfs1(int u, int fa) {
f[u] = fa;
mx[u] = mx[f[u]], fr[u] = fr[f[u]];
if (mx[u] < fa)
mx[u] = fa, fr[u] = u;
for (int i = head[u]; i; i = ed[i].next)
if (ed[i].t != fa)
dfs1(ed[i].t, u);
}
int que(int x) {
if (x < ti)
return sz[finds(x)] - 1;
int as = 0;
for (int i = head[x]; i; i = ed[i].next)
if (ed[i].t < ti)
as += sz[finds(ed[i].t)];
return as;
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++)
scanf("%d%d", &a, &b), adde(a, b);
for (int i = 1; i <= n; i++)
fa[i] = i, sz[i] = 1;
dfs1(1, 0);
for (int i = head[1]; i; i = ed[i].next)
st.push(make_pair(-1, ed[i].t));
while (!st.empty()) {
int las = ti;
ti = -st.top().first;
int s = st.top().second;
st.pop();
for (int i = las; i < ti; i++)
for (int j = head[i]; j; j = ed[j].next)
if (ed[j].t < i) {
int a = finds(i), b = finds(ed[j].t);
fa[a] = b, sz[b] += sz[a];
}
as[s] += as[mx[s]] + que(s) + 1 - vl[fr[s]];
for (int i = head[s]; i; i = ed[i].next)
if (ed[i].t != f[s])
st.push(make_pair(-mx[ed[i].t], ed[i].t)),
vl[ed[i].t] = ed[i].t < ti ? sz[finds(ed[i].t)] : 0;
}
for (int i = 2; i <= n; i++)
printf("%d ", as[i]);
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03204 | C++ | Runtime Error | #include <bits/stdc++.h>
#define re register
#define ui unsigned int
#define ull unsigned long long
int c[200100], f[200100], fc[200100], n;
struct eg {
int to;
eg *nx;
} e[200100], *la[200100], *cnt = e;
inline void addE(re int a, re int b) {
*++cnt = (eg){b, la[a]};
la[a] = cnt;
*++cnt = (eg){a, la[b]};
la[b] = cnt;
}
struct nd {
int x;
nd *l, *r;
} pl[5000100], *cct = pl;
nd *no[200100];
nd *meg(re nd *a, re nd *b) {
if (!a)
return b;
if (!b)
return a;
a->x += b->x;
a->l = meg(a->l, b->l);
a->r = meg(a->r, b->r);
return a;
}
int qus(re nd *a, re int l, re int r, re int l1) {
if (!a)
return 0;
if (l == r)
return a->x;
re int mid = (l + r) / 2;
if (l1 <= mid)
return qus(a->l, l, mid, l1);
else
return (a->l ? a->l->x : 0) + qus(a->r, mid + 1, r, l1);
}
void add(re nd *&a, re int l, re int r, re int l1, re int x1) {
if (!a)
a = ++cct;
a->x += x1;
if (l == r)
return;
re int mid = (l + r) / 2;
if (l1 <= mid)
add(a->l, l, mid, l1, x1);
else
x1 += (a->l ? a->l->x : 0), a->l = 0, add(a->r, mid + 1, r, l1, x1);
}
void dfs(re int a, re int fa) {
for (re eg *i = la[a]; i; i = i->nx)
if (i->to != fa) {
f[i->to] = std::max(a, f[a]);
dfs(i->to, a);
fc[i->to] = qus(no[i->to], 1, n, f[a]);
no[a] = meg(no[a], no[i->to]);
}
add(no[a], 1, n, a, 1);
}
void dfs1(re int a, re int fa, re int x1) {
for (re eg *i = la[a]; i; i = i->nx)
if (i->to != fa)
x1 += fc[i->to];
c[a] = x1;
x1++;
for (re eg *i = la[a]; i; i = i->nx)
if (i->to != fa)
dfs1(i->to, a, x1 - fc[i->to]);
}
int main() {
re int x, y;
scanf("%d", &n);
for (re int i = 1; i < n; i++)
scanf("%d%d", &x, &y), addE(x, y);
dfs(1, 0);
dfs1(1, 0, 0);
for (re int i = 2; i <= n; i++)
printf("%d ", c[i]);
} | #include <bits/stdc++.h>
#define re register
#define ui unsigned int
#define ull unsigned long long
int c[200100], f[200100], fc[200100], n;
struct eg {
int to;
eg *nx;
} e[400100], *la[200100], *cnt = e;
inline void addE(re int a, re int b) {
*++cnt = (eg){b, la[a]};
la[a] = cnt;
*++cnt = (eg){a, la[b]};
la[b] = cnt;
}
struct nd {
int x;
nd *l, *r;
} pl[5000100], *cct = pl;
nd *no[200100];
nd *meg(re nd *a, re nd *b) {
if (!a)
return b;
if (!b)
return a;
a->x += b->x;
a->l = meg(a->l, b->l);
a->r = meg(a->r, b->r);
return a;
}
int qus(re nd *a, re int l, re int r, re int l1) {
if (!a)
return 0;
if (l == r)
return a->x;
re int mid = (l + r) / 2;
if (l1 <= mid)
return qus(a->l, l, mid, l1);
else
return (a->l ? a->l->x : 0) + qus(a->r, mid + 1, r, l1);
}
void add(re nd *&a, re int l, re int r, re int l1, re int x1) {
if (!a)
a = ++cct;
a->x += x1;
if (l == r)
return;
re int mid = (l + r) / 2;
if (l1 <= mid)
add(a->l, l, mid, l1, x1);
else
x1 += (a->l ? a->l->x : 0), a->l = 0, add(a->r, mid + 1, r, l1, x1);
}
void dfs(re int a, re int fa) {
for (re eg *i = la[a]; i; i = i->nx)
if (i->to != fa) {
f[i->to] = std::max(a, f[a]);
dfs(i->to, a);
fc[i->to] = qus(no[i->to], 1, n, f[a]);
no[a] = meg(no[a], no[i->to]);
}
add(no[a], 1, n, a, 1);
}
void dfs1(re int a, re int fa, re int x1) {
for (re eg *i = la[a]; i; i = i->nx)
if (i->to != fa)
x1 += fc[i->to];
c[a] = x1;
x1++;
for (re eg *i = la[a]; i; i = i->nx)
if (i->to != fa)
dfs1(i->to, a, x1 - fc[i->to]);
}
int main() {
re int x, y;
scanf("%d", &n);
for (re int i = 1; i < n; i++)
scanf("%d%d", &x, &y), addE(x, y);
dfs(1, 0);
dfs1(1, 0, 0);
for (re int i = 2; i <= n; i++)
printf("%d ", c[i]);
} | replace | 8 | 9 | 8 | 9 | -11 | |
p03204 | C++ | Runtime Error | #include <cstdio>
int n, head[100001], nxt[200001], b[200001], k, ans2[100001];
void push(int s, int t) {
nxt[++k] = head[s];
head[s] = k;
b[k] = t;
}
void dfs(int x, int f, int mx, int skdmx, int down, bool update) {
if (x > mx)
skdmx = mx, mx = x, update = 1;
else if (x > skdmx)
skdmx = x, update = 0;
++ans2[x], --ans2[update ? mx : down];
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
dfs(b[i], x, mx, skdmx, (x == mx) ? b[i] : down, update);
}
void dfs2(int x, int f) {
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
dfs2(b[i], x), ans2[x] += ans2[b[i]];
}
void getans(int x, int f, int sum) {
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
sum += ans2[b[i]];
ans2[x] = ++sum;
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
getans(b[i], x, sum - ans2[b[i]]);
}
int main() {
scanf("%d", &n);
for (int i = 1, u, v; i < n; i++) {
scanf("%d%d", &u, &v);
push(u, v);
push(v, u);
}
dfs(1, 0, 0, 0, 0, 0);
dfs2(1, 0);
getans(1, 0, -1);
for (int i = 2; i <= n; i++)
printf("%d ", ans2[i]);
} | #include <cstdio>
int n, head[200001], nxt[400001], b[400001], k, ans2[200001];
void push(int s, int t) {
nxt[++k] = head[s];
head[s] = k;
b[k] = t;
}
void dfs(int x, int f, int mx, int skdmx, int down, bool update) {
if (x > mx)
skdmx = mx, mx = x, update = 1;
else if (x > skdmx)
skdmx = x, update = 0;
++ans2[x], --ans2[update ? mx : down];
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
dfs(b[i], x, mx, skdmx, (x == mx) ? b[i] : down, update);
}
void dfs2(int x, int f) {
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
dfs2(b[i], x), ans2[x] += ans2[b[i]];
}
void getans(int x, int f, int sum) {
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
sum += ans2[b[i]];
ans2[x] = ++sum;
for (int i = head[x]; i; i = nxt[i])
if (b[i] != f)
getans(b[i], x, sum - ans2[b[i]]);
}
int main() {
scanf("%d", &n);
for (int i = 1, u, v; i < n; i++) {
scanf("%d%d", &u, &v);
push(u, v);
push(v, u);
}
dfs(1, 0, 0, 0, 0, 0);
dfs2(1, 0);
getans(1, 0, -1);
for (int i = 2; i <= n; i++)
printf("%d ", ans2[i]);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03204 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n) \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl
#define svec(v) \
cout << #v << ":"; \
rep(pachico, v.size()) cout << " " << v[pachico]; \
cout << endl
#define svecp(v) \
cout << #v << ":"; \
each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(pachico, s) cout << " " << pachico; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 200005;
vector<int> G[MAX_N], cnt[MAX_N];
int ans[MAX_N], mx[MAX_N];
void dfs(int u, int p, int val) {
mx[u] = val;
each(v, G[u]) {
if (v != p) {
cnt[u].pb(0);
dfs(v, u, max(val, u));
}
}
}
void redfs(int u, int p, const int val, int &num) {
num++;
int id = 0, prv = 0;
each(v, G[u]) {
if (v != p) {
prv = num;
if (v < val)
redfs(v, u, val, num);
cnt[u][id++] = num - prv;
}
}
}
void dfs(int u, int p) {
if (p >= 0) {
if (mx[p] != mx[u] || u > p) {
int num = 0;
redfs(u, p, mx[u], num);
}
}
each(v, G[u]) {
if (v != p) {
dfs(v, u);
}
}
}
void redfs(int u, int p, int val) {
int id = 0, sm = accumulate(all(cnt[u]), 0);
ans[u] = val + sm;
each(v, G[u]) {
if (v != p) {
redfs(v, u, val + sm - cnt[u][id++] + 1);
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
G[a - 1].pb(b - 1), G[b - 1].pb(a - 1);
}
dfs(0, -1, -1);
dfs(0, -1);
redfs(0, -1, 0);
srep(i, 1, n) { cout << ans[i] << " "; }
cout << "\n";
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n) \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl
#define svec(v) \
cout << #v << ":"; \
rep(pachico, v.size()) cout << " " << v[pachico]; \
cout << endl
#define svecp(v) \
cout << #v << ":"; \
each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(pachico, s) cout << " " << pachico; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 200005;
vector<int> G[MAX_N], cnt[MAX_N];
int ans[MAX_N], mx[MAX_N];
void dfs(int u, int p, int val) {
mx[u] = val;
each(v, G[u]) {
if (v != p) {
cnt[u].pb(0);
dfs(v, u, max(val, u));
}
}
}
void redfs(int u, int p, const int val, int &num) {
num++;
int id = 0, prv = 0;
each(v, G[u]) {
if (v != p) {
prv = num;
if (v < val)
redfs(v, u, val, num);
cnt[u][id++] = num - prv;
}
}
}
void dfs(int u, int p) {
if (p >= 0) {
if (mx[p] != mx[u] || u > mx[u]) {
int num = 0;
redfs(u, p, mx[u], num);
}
}
each(v, G[u]) {
if (v != p) {
dfs(v, u);
}
}
}
void redfs(int u, int p, int val) {
int id = 0, sm = accumulate(all(cnt[u]), 0);
ans[u] = val + sm;
each(v, G[u]) {
if (v != p) {
redfs(v, u, val + sm - cnt[u][id++] + 1);
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
rep(i, n - 1) {
int a, b;
cin >> a >> b;
G[a - 1].pb(b - 1), G[b - 1].pb(a - 1);
}
dfs(0, -1, -1);
dfs(0, -1);
redfs(0, -1, 0);
srep(i, 1, n) { cout << ans[i] << " "; }
cout << "\n";
return 0;
} | replace | 84 | 85 | 84 | 85 | TLE | |
p03204 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int N = 2e5 + 5;
int n, c[N];
vector<int> G[N];
inline void addedge(int u = 0, int v = 0) {
scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
}
int calc(int u, int fa, int lim) {
int res = 1;
for (auto v : G[u])
if (v < lim)
res += calc(v, u, lim);
return res;
}
void solve(int u, int fa, int t1, int t2) {
if (u > t2)
c[u] = c[fa] + calc(u, fa, t1);
else if (t1 > t2)
c[u] = c[fa] + calc(u, fa, t1) - calc(u, fa, t2);
else
c[u] = c[fa];
for (auto v : G[u])
if (v != fa)
solve(v, u, max(t1, u), max(t2, fa));
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; ++i)
addedge();
solve(1, 0, 1, 1);
for (int i = 2; i <= n; ++i)
printf("%d ", c[i]);
return puts(""), 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int N = 2e5 + 5;
int n, c[N];
vector<int> G[N];
inline void addedge(int u = 0, int v = 0) {
scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
}
int calc(int u, int fa, int lim) {
int res = 1;
for (auto v : G[u])
if (v < lim && v != fa)
res += calc(v, u, lim);
return res;
}
void solve(int u, int fa, int t1, int t2) {
if (u > t2)
c[u] = c[fa] + calc(u, fa, t1);
else if (t1 > t2)
c[u] = c[fa] + calc(u, fa, t1) - calc(u, fa, t2);
else
c[u] = c[fa];
for (auto v : G[u])
if (v != fa)
solve(v, u, max(t1, u), max(t2, fa));
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; ++i)
addedge();
solve(1, 0, 1, 1);
for (int i = 2; i <= n; ++i)
printf("%d ", c[i]);
return puts(""), 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p03204 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
using namespace std;
const int N = 1010;
vector<int> G[N];
int n, f[N], u, v, fa[N][20], c[N], d[N];
int get(int v, int t) {
int u = v;
per(i, 18, 0) if (c[fa[fa[u][i]][0]] > v && d[fa[u][i]] >= t) u = fa[u][i];
return u;
}
void dfs(int u, int t) {
++f[t];
for (int &v : G[u])
if (v ^ fa[u][0]) {
d[v] = d[u] + 1, c[v] = max(c[u], v), fa[v][0] = u;
rep(i, 1, 18) fa[v][i] = fa[fa[v][i - 1]][i - 1];
dfs(v, get(v, d[t]));
}
}
void DFS(int u) {
for (int &v : G[u])
if (v ^ fa[u][0])
f[v] += f[u], DFS(v);
}
int main() {
scanf("%d", &n);
rep(i, 1, n - 1) scanf("%d%d", &u, &v), G[u].pb(v), G[v].pb(u);
d[1] = 1;
c[1] = 1;
dfs(1, 1);
DFS(1);
rep(i, 2, n) printf("%d ", f[i] - 1);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
using namespace std;
const int N = 2e5 + 10;
vector<int> G[N];
int n, f[N], u, v, fa[N][20], c[N], d[N];
int get(int v, int t) {
int u = v;
per(i, 18, 0) if (c[fa[fa[u][i]][0]] > v && d[fa[u][i]] >= t) u = fa[u][i];
return u;
}
void dfs(int u, int t) {
++f[t];
for (int &v : G[u])
if (v ^ fa[u][0]) {
d[v] = d[u] + 1, c[v] = max(c[u], v), fa[v][0] = u;
rep(i, 1, 18) fa[v][i] = fa[fa[v][i - 1]][i - 1];
dfs(v, get(v, d[t]));
}
}
void DFS(int u) {
for (int &v : G[u])
if (v ^ fa[u][0])
f[v] += f[u], DFS(v);
}
int main() {
scanf("%d", &n);
rep(i, 1, n - 1) scanf("%d%d", &u, &v), G[u].pb(v), G[v].pb(u);
d[1] = 1;
c[1] = 1;
dfs(1, 1);
DFS(1);
rep(i, 2, n) printf("%d ", f[i] - 1);
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03204 | C++ | Runtime Error | #pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 100010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;
int mx[maxn], c[maxn], n;
vector<int> nxt[maxn];
map<int, int> F[maxn];
template <class T> void read(T &x) {
char ch = x = 0;
bool fl = false;
while (!isdigit(ch))
fl |= ch == '-', ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
x = fl ? -x : x;
}
int f(int x, int y, int fa) {
if (F[x].count(y))
return F[x][y];
int ret = 0;
for (auto &v : nxt[x]) {
if (v != fa && v <= y)
ret += 1 + f(v, y, x);
}
return F[x][y] = ret;
}
void dfs(int x, int fa) {
mx[x] = max(mx[fa], fa);
if (x > mx[fa])
c[x] = c[fa] + f(x, mx[x], fa) + 1;
else
c[x] = c[fa] + f(x, mx[x], fa) - f(x, mx[fa], fa);
for (auto &v : nxt[x]) {
if (v != fa)
dfs(v, x);
}
}
int main() {
read(n);
for (int i = 1, u, v; i <= n - 1; i++) {
read(u), read(v), nxt[u].pb(v), nxt[v].pb(u);
}
for (auto &v : nxt[1]) {
dfs(v, 1);
}
for (int i = 2; i <= n; i++) {
printf("%d%c", c[i], i == n ? '\n' : ' ');
}
return 0;
} | #pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 200010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;
int mx[maxn], c[maxn], n;
vector<int> nxt[maxn];
map<int, int> F[maxn];
template <class T> void read(T &x) {
char ch = x = 0;
bool fl = false;
while (!isdigit(ch))
fl |= ch == '-', ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
x = fl ? -x : x;
}
int f(int x, int y, int fa) {
if (F[x].count(y))
return F[x][y];
int ret = 0;
for (auto &v : nxt[x]) {
if (v != fa && v <= y)
ret += 1 + f(v, y, x);
}
return F[x][y] = ret;
}
void dfs(int x, int fa) {
mx[x] = max(mx[fa], fa);
if (x > mx[fa])
c[x] = c[fa] + f(x, mx[x], fa) + 1;
else
c[x] = c[fa] + f(x, mx[x], fa) - f(x, mx[fa], fa);
for (auto &v : nxt[x]) {
if (v != fa)
dfs(v, x);
}
}
int main() {
read(n);
for (int i = 1, u, v; i <= n - 1; i++) {
read(u), read(v), nxt[u].pb(v), nxt[v].pb(u);
}
for (auto &v : nxt[1]) {
dfs(v, 1);
}
for (int i = 2; i <= n; i++) {
printf("%d%c", c[i], i == n ? '\n' : ' ');
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03204 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Edge {
int to, nex;
} e[N << 1];
int head[N], ecnt;
void adde(int fr, int to) {
e[++ecnt] = (Edge){to, head[fr]};
head[fr] = ecnt;
}
void addedge(int fr, int to) {
adde(to, fr);
adde(fr, to);
}
int n, par[N], c[N], mx[N];
map<int, int> exi[N];
void dfs(int x, int fa) {
par[x] = fa;
for (int j = head[x]; j; j = e[j].nex)
if (e[j].to != fa) {
mx[e[j].to] = max(mx[x], x);
dfs(e[j].to, x);
}
}
int Q(int x, int v) {
if (exi[x].count(v))
return exi[x][v];
int res = 0;
for (int j = head[x]; j; j = e[j].nex) {
if (e[j].to <= v && e[j].to != par[x]) {
res += Q(e[j].to, v) + 1;
}
}
return exi[x][v] = res;
}
void dfs2(int x) {
for (int j = head[x]; j; j = e[j].nex) {
if (e[j].to != par[x]) {
if (e[j].to > mx[x]) {
c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) + 1;
} else {
c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) - Q(e[j].to, mx[x]);
}
dfs2(e[j].to);
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
addedge(u, v);
}
mx[1] = -1;
dfs(1, 0);
dfs2(1);
for (int i = 2; i <= n; i++)
printf("%d ", c[i]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct Edge {
int to, nex;
} e[N << 1];
int head[N], ecnt;
void adde(int fr, int to) {
e[++ecnt] = (Edge){to, head[fr]};
head[fr] = ecnt;
}
void addedge(int fr, int to) {
adde(to, fr);
adde(fr, to);
}
int n, par[N], c[N], mx[N];
map<int, int> exi[N];
void dfs(int x, int fa) {
par[x] = fa;
for (int j = head[x]; j; j = e[j].nex)
if (e[j].to != fa) {
mx[e[j].to] = max(mx[x], x);
dfs(e[j].to, x);
}
}
int Q(int x, int v) {
if (exi[x].count(v))
return exi[x][v];
int res = 0;
for (int j = head[x]; j; j = e[j].nex) {
if (e[j].to <= v && e[j].to != par[x]) {
res += Q(e[j].to, v) + 1;
}
}
return exi[x][v] = res;
}
void dfs2(int x) {
for (int j = head[x]; j; j = e[j].nex) {
if (e[j].to != par[x]) {
if (e[j].to > mx[x]) {
c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) + 1;
} else {
c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) - Q(e[j].to, mx[x]);
}
dfs2(e[j].to);
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v;
scanf("%d%d", &u, &v);
addedge(u, v);
}
mx[1] = -1;
dfs(1, 0);
dfs2(1);
for (int i = 2; i <= n; i++)
printf("%d ", c[i]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03205 | C++ | Runtime Error | // Jump, and you will find out how to unfold your wings as you fall.
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n, k) (((n) >> (k)) & 1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e5 + 10, Src = maxn - 3, Snk = maxn - 2, inf = 1e8;
vector<pii> v[maxn];
vector<int> vid[maxn];
bool mark[maxn];
pii ans[maxn];
int n, h[maxn], pt[maxn];
void add_edge(int a, int b) {
vid[a].PB(sz(v[b]));
vid[b].PB(sz(v[a]));
v[a].PB({b, 1});
v[b].PB({a, 0});
}
bool bfs() {
memset(mark, 0, sizeof mark);
queue<int> q;
q.push(Src);
mark[Src] = 1;
while (sz(q)) {
int u = q.front();
if (u == Snk)
return 1;
q.pop();
for (pii p : v[u]) {
if (p.S > 0 && mark[p.F] == 0) {
h[p.F] = h[u] + 1;
mark[p.F] = 1;
q.push(p.F);
}
}
}
return 0;
}
int dfs(int u, int flw = inf) {
if (u == Snk)
return flw;
int ans = 0, &i = pt[u];
while (i < sz(v[u])) {
int y = v[u][i].F, &w = v[u][i].S, &w2 = v[y][vid[u][i]].S;
if (w > 0 && h[u] + 1 == h[y]) {
int num = dfs(y, min(flw - ans, w));
w -= num, w2 += num, ans += num;
if (ans == flw)
return ans;
}
++i;
}
return ans;
}
int flow() {
int ans = 0;
while (bfs()) {
memset(pt, 0, sizeof pt);
ans += dfs(Src);
}
return ans;
}
void go(int u, int par = -1) {
mark[u] = 1;
if (u >= n && u != Src && u != Snk) {
int y = -1;
for (pii p : v[u]) {
if (p.S != 0)
y = p.F;
}
ans[u - n] = {par + 1, y + 1};
}
for (pii p : v[u]) {
if (p.S != 0 && mark[p.F] == 0)
go(p.F, u);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cin >> n;
for (int i = 0; i < n - 1; i++) {
int N;
cin >> N;
while (N--) {
int x;
cin >> x;
add_edge(--x, i + n);
}
}
for (int i = 0; i < n; i++) {
add_edge(Src, i);
}
for (int i = n; i < 2 * n - 1; i++) {
add_edge(i, Snk);
}
int num = flow();
if (num != n - 1)
return cout << -1 << endl, 0;
memset(mark, 0, sizeof mark);
go(Src);
for (int i = 0; i < n - 1; i++) {
if (ans[i].F == 0)
return cout << -1 << endl, 0;
}
for (int i = 0; i < n - 1; i++) {
cout << ans[i].F << " " << ans[i].S << "\n";
}
}
// Deathly mistakes:
// * Read the problem curfully.
// * Check maxn.
// * Overflows.
| // Jump, and you will find out how to unfold your wings as you fall.
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n, k) (((n) >> (k)) & 1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 2e5 + 10, Src = maxn - 3, Snk = maxn - 2, inf = 1e8;
vector<pii> v[maxn];
vector<int> vid[maxn];
bool mark[maxn];
pii ans[maxn];
int n, h[maxn], pt[maxn];
void add_edge(int a, int b) {
vid[a].PB(sz(v[b]));
vid[b].PB(sz(v[a]));
v[a].PB({b, 1});
v[b].PB({a, 0});
}
bool bfs() {
memset(mark, 0, sizeof mark);
queue<int> q;
q.push(Src);
mark[Src] = 1;
while (sz(q)) {
int u = q.front();
if (u == Snk)
return 1;
q.pop();
for (pii p : v[u]) {
if (p.S > 0 && mark[p.F] == 0) {
h[p.F] = h[u] + 1;
mark[p.F] = 1;
q.push(p.F);
}
}
}
return 0;
}
int dfs(int u, int flw = inf) {
if (u == Snk)
return flw;
int ans = 0, &i = pt[u];
while (i < sz(v[u])) {
int y = v[u][i].F, &w = v[u][i].S, &w2 = v[y][vid[u][i]].S;
if (w > 0 && h[u] + 1 == h[y]) {
int num = dfs(y, min(flw - ans, w));
w -= num, w2 += num, ans += num;
if (ans == flw)
return ans;
}
++i;
}
return ans;
}
int flow() {
int ans = 0;
while (bfs()) {
memset(pt, 0, sizeof pt);
ans += dfs(Src);
}
return ans;
}
void go(int u, int par = -1) {
mark[u] = 1;
if (u >= n && u != Src && u != Snk) {
int y = -1;
for (pii p : v[u]) {
if (p.S != 0)
y = p.F;
}
ans[u - n] = {par + 1, y + 1};
}
for (pii p : v[u]) {
if (p.S != 0 && mark[p.F] == 0)
go(p.F, u);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cin >> n;
for (int i = 0; i < n - 1; i++) {
int N;
cin >> N;
while (N--) {
int x;
cin >> x;
add_edge(--x, i + n);
}
}
for (int i = 0; i < n; i++) {
add_edge(Src, i);
}
for (int i = n; i < 2 * n - 1; i++) {
add_edge(i, Snk);
}
int num = flow();
if (num != n - 1)
return cout << -1 << endl, 0;
memset(mark, 0, sizeof mark);
go(Src);
for (int i = 0; i < n - 1; i++) {
if (ans[i].F == 0)
return cout << -1 << endl, 0;
}
for (int i = 0; i < n - 1; i++) {
cout << ans[i].F << " " << ans[i].S << "\n";
}
}
// Deathly mistakes:
// * Read the problem curfully.
// * Check maxn.
// * Overflows.
| replace | 16 | 17 | 16 | 17 | 0 | |
p03205 | C++ | Runtime Error | #include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 100010
#define T n + n + 1
#define add(x, y, z) addedge(x, y, z), addedge(y, x, 0)
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
int head[N], tot = 1, cur[N], vis[N], dis[N], n, p[N], fa[N], s;
vector<int> v[N];
struct Edge {
int v, next, f, w;
} edge[N * 10];
queue<int> q;
inline void addedge(int x, int y, int z) {
edge[++tot] = Edge{y, head[x], 0, z};
head[x] = tot;
}
inline int bfs() {
memset(vis, 0, sizeof(vis));
memcpy(cur, head, sizeof(cur));
q.push(0);
vis[0] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
for (rint i = head[x]; i; i = edge[i].next)
if (!vis[to] && edge[i].f < edge[i].w)
dis[to] = dis[x] + 1, vis[to] = 1, q.push(to);
}
return vis[T];
}
int dfs(int x, int res) {
if (x == T || !res)
return res;
int flow = 0, f;
for (rint &i = cur[x]; i; i = edge[i].next)
if (dis[to] == dis[x] + 1 &&
(f = dfs(to, min(res, edge[i].w - edge[i].f)))) {
edge[i].f += f;
edge[i ^ 1].f -= f;
res -= f;
flow += f;
if (!res)
break;
}
return flow;
}
inline int dinic() {
int A = 0;
while (bfs())
A += dfs(0, INT_MAX);
return A;
}
void dfs(int x) {
vis[x] = 1;
s++;
for (auto y : v[x])
if (!vis[p[y]])
fa[y] = x, dfs(p[y]);
}
int main() {
int m, x;
cin >> n;
for (rint i = 1; i <= n; i++)
add(n + i, T, 1);
for (rint i = 1; i < n; add(0, i, 1), i++)
for (scanf("%d", &m); m--;) {
scanf("%d", &x), v[x].push_back(i);
if (x != 1)
add(i, n + x, 1);
}
if (dinic() != n - 1)
return !printf("-1");
for (rint j = 1; j < n; j++)
for (rint i = head[j]; i; i = edge[i].next)
if (n < to && to <= n + n && edge[i].f)
p[j] = to - n;
dfs(1);
if (s != n)
return !printf("-1");
for (rint i = 1; i < n; i++)
printf("%d %d\n", fa[i], p[i]);
return 0;
}
| #include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 200010
#define T n + n + 1
#define add(x, y, z) addedge(x, y, z), addedge(y, x, 0)
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
int head[N], tot = 1, cur[N], vis[N], dis[N], n, p[N], fa[N], s;
vector<int> v[N];
struct Edge {
int v, next, f, w;
} edge[N * 10];
queue<int> q;
inline void addedge(int x, int y, int z) {
edge[++tot] = Edge{y, head[x], 0, z};
head[x] = tot;
}
inline int bfs() {
memset(vis, 0, sizeof(vis));
memcpy(cur, head, sizeof(cur));
q.push(0);
vis[0] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
for (rint i = head[x]; i; i = edge[i].next)
if (!vis[to] && edge[i].f < edge[i].w)
dis[to] = dis[x] + 1, vis[to] = 1, q.push(to);
}
return vis[T];
}
int dfs(int x, int res) {
if (x == T || !res)
return res;
int flow = 0, f;
for (rint &i = cur[x]; i; i = edge[i].next)
if (dis[to] == dis[x] + 1 &&
(f = dfs(to, min(res, edge[i].w - edge[i].f)))) {
edge[i].f += f;
edge[i ^ 1].f -= f;
res -= f;
flow += f;
if (!res)
break;
}
return flow;
}
inline int dinic() {
int A = 0;
while (bfs())
A += dfs(0, INT_MAX);
return A;
}
void dfs(int x) {
vis[x] = 1;
s++;
for (auto y : v[x])
if (!vis[p[y]])
fa[y] = x, dfs(p[y]);
}
int main() {
int m, x;
cin >> n;
for (rint i = 1; i <= n; i++)
add(n + i, T, 1);
for (rint i = 1; i < n; add(0, i, 1), i++)
for (scanf("%d", &m); m--;) {
scanf("%d", &x), v[x].push_back(i);
if (x != 1)
add(i, n + x, 1);
}
if (dinic() != n - 1)
return !printf("-1");
for (rint j = 1; j < n; j++)
for (rint i = head[j]; i; i = edge[i].next)
if (n < to && to <= n + n && edge[i].f)
p[j] = to - n;
dfs(1);
if (s != n)
return !printf("-1");
for (rint i = 1; i < n; i++)
printf("%d %d\n", fa[i], p[i]);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03205 | C++ | Runtime Error | #include <bits/stdc++.h>
#define il inline
using namespace std;
const int N = 1e5 + 5, M = 2e6;
int n, m, e, S, T, h, t, q[N], lev[N], ax[N], ay[N], o[N];
int to[M], nx[M], cap[M], hd[N], it[N], sze = 1;
std::vector<int> g[N];
il void add(int u, int v, int c) {
to[++sze] = v, nx[sze] = hd[u], cap[sze] = c, hd[u] = sze;
}
il void ins(int u, int v, int c) { add(u, v, c), add(v, u, 0); }
il int bfs() {
memset(lev, 0, 4 * T + 4);
int i, u, v;
q[h = t = lev[S] = 1] = S;
while (h <= t)
for (i = hd[u = q[h++]]; i; i = nx[i])
if (cap[i] && !lev[v = to[i]])
lev[v] = lev[u] + 1, q[++t] = v;
return lev[T];
}
il int dfs(int u, int f) {
if (u == T)
return f;
int z, v, res = 0;
for (int &i = it[u]; i; i = nx[i])
if (lev[v = to[i]] == lev[u] + 1 && cap[i] &&
(z = dfs(v, min(f - res, cap[i])))) {
cap[i] -= z, cap[i ^ 1] += z, res += z;
if (res == f)
break;
}
return res;
}
il int dinic() {
int i, f, res = 0;
while (bfs()) {
for (i = 1; i <= T; i++)
it[i] = hd[i];
while (f = dfs(S, 1e9))
res += f;
}
return res;
}
il int work() {
int i, u, v, s = 0;
for (u = 1; u < n; u++)
for (i = hd[u]; i; i = nx[i])
if ((v = to[i]) != S && !cap[i])
o[u] = v - n + 1;
for (q[++t] = n; h <= t;) {
u = q[h++], s++;
for (int v : g[u])
if (o[v])
ax[v] = u, ay[v] = o[v], q[++t] = o[v], o[v] = 0;
}
return s == n;
}
int main() {
scanf("%d", &n), S = n + n - 1, T = n + n;
int i, c, x;
for (i = 1; i < n; i++)
ins(i + n - 1, T, 1);
for (i = 1; i < n; i++) {
scanf("%d", &c), ins(S, i, 1);
while (c--) {
scanf("%d", &x);
if (x != n)
ins(i, x + n - 1, 1);
g[x].push_back(i);
}
}
if (dinic() < n - 1)
return puts("-1"), 0;
if (!work())
return puts("-1"), 0;
for (i = 1; i < n; i++)
printf("%d %d\n", ax[i], ay[i]);
return 0;
} | #include <bits/stdc++.h>
#define il inline
using namespace std;
const int N = 2e5 + 5, M = 2e6;
int n, m, e, S, T, h, t, q[N], lev[N], ax[N], ay[N], o[N];
int to[M], nx[M], cap[M], hd[N], it[N], sze = 1;
std::vector<int> g[N];
il void add(int u, int v, int c) {
to[++sze] = v, nx[sze] = hd[u], cap[sze] = c, hd[u] = sze;
}
il void ins(int u, int v, int c) { add(u, v, c), add(v, u, 0); }
il int bfs() {
memset(lev, 0, 4 * T + 4);
int i, u, v;
q[h = t = lev[S] = 1] = S;
while (h <= t)
for (i = hd[u = q[h++]]; i; i = nx[i])
if (cap[i] && !lev[v = to[i]])
lev[v] = lev[u] + 1, q[++t] = v;
return lev[T];
}
il int dfs(int u, int f) {
if (u == T)
return f;
int z, v, res = 0;
for (int &i = it[u]; i; i = nx[i])
if (lev[v = to[i]] == lev[u] + 1 && cap[i] &&
(z = dfs(v, min(f - res, cap[i])))) {
cap[i] -= z, cap[i ^ 1] += z, res += z;
if (res == f)
break;
}
return res;
}
il int dinic() {
int i, f, res = 0;
while (bfs()) {
for (i = 1; i <= T; i++)
it[i] = hd[i];
while (f = dfs(S, 1e9))
res += f;
}
return res;
}
il int work() {
int i, u, v, s = 0;
for (u = 1; u < n; u++)
for (i = hd[u]; i; i = nx[i])
if ((v = to[i]) != S && !cap[i])
o[u] = v - n + 1;
for (q[++t] = n; h <= t;) {
u = q[h++], s++;
for (int v : g[u])
if (o[v])
ax[v] = u, ay[v] = o[v], q[++t] = o[v], o[v] = 0;
}
return s == n;
}
int main() {
scanf("%d", &n), S = n + n - 1, T = n + n;
int i, c, x;
for (i = 1; i < n; i++)
ins(i + n - 1, T, 1);
for (i = 1; i < n; i++) {
scanf("%d", &c), ins(S, i, 1);
while (c--) {
scanf("%d", &x);
if (x != n)
ins(i, x + n - 1, 1);
g[x].push_back(i);
}
}
if (dinic() < n - 1)
return puts("-1"), 0;
if (!work())
return puts("-1"), 0;
for (i = 1; i < n; i++)
printf("%d %d\n", ax[i], ay[i]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03205 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define FILL(a, n, x) memset((a), (x), sizeof((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof(a))
#define COPY(a, n, b) memcpy((b), (a), sizeof((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof(a))
typedef unsigned long long lu;
typedef long long li;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) {
x += y;
if (x >= mod)
x -= mod;
}
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }
int Pow(int x, int y) {
int z = 1;
for (; y; y >>= 1) {
if (y & 1)
z = Mul(z, x);
x = Mul(x, x);
}
return z;
}
int Inv(int x) { return Pow(x, mod - 2); }
template <class T> inline void Max(T &x, T y) {
if (y > x)
x = y;
}
template <class T> inline void Min(T &x, T y) {
if (y < x)
x = y;
}
// ----------------------------------------
namespace dinic {
const int maxn = 1e5, maxm = 1e6;
typedef int FlowType;
const FlowType inf_f = ~0U >> 1;
void Init(int n);
void AddEdge(int u, int v, FlowType cap, li id);
FlowType Solve(int s, int t);
vector<pair<li, FlowType>> Result(void);
} // namespace dinic
namespace dinic {
struct Edge {
int v;
li id;
FlowType cap, cap0;
} edge[maxm << 1];
int n, m, s, t;
vector<int> g[maxn];
void Init(int _n) {
n = _n, m = 0;
for (int i = 0; i < n; ++i)
g[i].clear();
}
void AddEdge(int u, int v, FlowType c, li id = -1) {
g[u].push_back(m);
edge[m++] = (Edge){v, id, c, c};
g[v].push_back(m);
edge[m++] = (Edge){u, id, 0, 0};
}
int iter[maxn], dist[maxn];
bool Bfs(void) {
queue<int> que;
que.push(s);
FILL(dist, n, -1);
dist[s] = 0;
while (!que.empty()) {
int u = que.front();
que.pop();
for (int i = 0; i < g[u].size(); ++i) {
Edge &e = edge[g[u][i]];
if (e.cap && dist[e.v] == -1) {
dist[e.v] = dist[u] + 1;
que.push(e.v);
}
}
}
return dist[t] >= 0;
}
FlowType Dfs(int u, FlowType f) {
if (u == t)
return f;
FlowType sum = 0;
for (int &i = iter[u]; i < g[u].size(); ++i) {
Edge &e = edge[g[u][i]], &rev = edge[g[u][i] ^ 1];
if (e.cap && dist[e.v] == dist[u] + 1) {
FlowType res = Dfs(e.v, min(f - sum, e.cap));
e.cap -= res;
rev.cap += res;
if ((sum += res) == f)
break;
}
}
return sum;
}
FlowType Solve(int _s, int _t) {
s = _s, t = _t;
FlowType ans = 0;
while (Bfs()) {
FILL(iter, n, 0);
ans += Dfs(s, inf_f);
}
return ans;
}
vector<pair<li, FlowType>> Result(void) {
vector<pair<li, FlowType>> ans;
for (int u = 0; u < n; ++u) {
for (int i = 0; i < g[u].size(); ++i) {
Edge &e = edge[g[u][i]];
if (e.cap < e.cap0 && e.id != -1) {
ans.push_back(make_pair(e.id, e.cap0 - e.cap));
}
}
}
return ans;
}
} // namespace dinic
// ----------------------------------------
const int maxn = 1e5;
int n;
vector<int> E[maxn];
vector<int> F[maxn];
int match[maxn], par[maxn];
int A[maxn], B[maxn];
void NoSolution(void) {
puts("-1");
exit(0);
}
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n - 1; ++i) {
int c;
scanf("%d", &c);
while (c--) {
int x;
scanf("%d", &x);
--x;
E[i].push_back(x);
F[x].push_back(i);
}
}
// root = 0
int L = 0, R = n, S = R + n - 1, T = S + 1, N = T + 1;
dinic::Init(N);
for (int i = 1; i < n; ++i) {
dinic::AddEdge(S, L + i, 1, -1);
}
for (int i = 0; i < n - 1; ++i) {
dinic::AddEdge(R + i, T, 1, -1);
}
for (int i = 1; i < n; ++i) {
for (int j : F[i]) {
dinic::AddEdge(L + i, R + j, 1, (li)i * n + j);
}
}
int flow = dinic::Solve(S, T);
if (flow < n - 1)
NoSolution();
vector<pair<li, int>> way = dinic::Result();
for (pair<li, int> p : way) {
int x = (int)(p.first / n), y = (int)(p.first % n);
match[y] = x;
}
queue<int> que;
que.push(0);
FILL(par, n, -1);
while (!que.empty()) {
int u = que.front();
que.pop();
for (int j : F[u]) {
int i = match[j];
if (par[i] == -1) {
par[i] = u;
A[j] = i;
B[j] = u;
que.push(i);
}
}
}
for (int i = 1; i < n; ++i) {
if (par[i] == -1)
NoSolution();
}
for (int i = 0; i < n - 1; ++i) {
printf("%d %d\n", A[i] + 1, B[i] + 1);
}
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define FILL(a, n, x) memset((a), (x), sizeof((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof(a))
#define COPY(a, n, b) memcpy((b), (a), sizeof((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof(a))
typedef unsigned long long lu;
typedef long long li;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) {
x += y;
if (x >= mod)
x -= mod;
}
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }
int Pow(int x, int y) {
int z = 1;
for (; y; y >>= 1) {
if (y & 1)
z = Mul(z, x);
x = Mul(x, x);
}
return z;
}
int Inv(int x) { return Pow(x, mod - 2); }
template <class T> inline void Max(T &x, T y) {
if (y > x)
x = y;
}
template <class T> inline void Min(T &x, T y) {
if (y < x)
x = y;
}
// ----------------------------------------
namespace dinic {
const int maxn = 1e6, maxm = 1e6;
typedef int FlowType;
const FlowType inf_f = ~0U >> 1;
void Init(int n);
void AddEdge(int u, int v, FlowType cap, li id);
FlowType Solve(int s, int t);
vector<pair<li, FlowType>> Result(void);
} // namespace dinic
namespace dinic {
struct Edge {
int v;
li id;
FlowType cap, cap0;
} edge[maxm << 1];
int n, m, s, t;
vector<int> g[maxn];
void Init(int _n) {
n = _n, m = 0;
for (int i = 0; i < n; ++i)
g[i].clear();
}
void AddEdge(int u, int v, FlowType c, li id = -1) {
g[u].push_back(m);
edge[m++] = (Edge){v, id, c, c};
g[v].push_back(m);
edge[m++] = (Edge){u, id, 0, 0};
}
int iter[maxn], dist[maxn];
bool Bfs(void) {
queue<int> que;
que.push(s);
FILL(dist, n, -1);
dist[s] = 0;
while (!que.empty()) {
int u = que.front();
que.pop();
for (int i = 0; i < g[u].size(); ++i) {
Edge &e = edge[g[u][i]];
if (e.cap && dist[e.v] == -1) {
dist[e.v] = dist[u] + 1;
que.push(e.v);
}
}
}
return dist[t] >= 0;
}
FlowType Dfs(int u, FlowType f) {
if (u == t)
return f;
FlowType sum = 0;
for (int &i = iter[u]; i < g[u].size(); ++i) {
Edge &e = edge[g[u][i]], &rev = edge[g[u][i] ^ 1];
if (e.cap && dist[e.v] == dist[u] + 1) {
FlowType res = Dfs(e.v, min(f - sum, e.cap));
e.cap -= res;
rev.cap += res;
if ((sum += res) == f)
break;
}
}
return sum;
}
FlowType Solve(int _s, int _t) {
s = _s, t = _t;
FlowType ans = 0;
while (Bfs()) {
FILL(iter, n, 0);
ans += Dfs(s, inf_f);
}
return ans;
}
vector<pair<li, FlowType>> Result(void) {
vector<pair<li, FlowType>> ans;
for (int u = 0; u < n; ++u) {
for (int i = 0; i < g[u].size(); ++i) {
Edge &e = edge[g[u][i]];
if (e.cap < e.cap0 && e.id != -1) {
ans.push_back(make_pair(e.id, e.cap0 - e.cap));
}
}
}
return ans;
}
} // namespace dinic
// ----------------------------------------
const int maxn = 1e5;
int n;
vector<int> E[maxn];
vector<int> F[maxn];
int match[maxn], par[maxn];
int A[maxn], B[maxn];
void NoSolution(void) {
puts("-1");
exit(0);
}
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n - 1; ++i) {
int c;
scanf("%d", &c);
while (c--) {
int x;
scanf("%d", &x);
--x;
E[i].push_back(x);
F[x].push_back(i);
}
}
// root = 0
int L = 0, R = n, S = R + n - 1, T = S + 1, N = T + 1;
dinic::Init(N);
for (int i = 1; i < n; ++i) {
dinic::AddEdge(S, L + i, 1, -1);
}
for (int i = 0; i < n - 1; ++i) {
dinic::AddEdge(R + i, T, 1, -1);
}
for (int i = 1; i < n; ++i) {
for (int j : F[i]) {
dinic::AddEdge(L + i, R + j, 1, (li)i * n + j);
}
}
int flow = dinic::Solve(S, T);
if (flow < n - 1)
NoSolution();
vector<pair<li, int>> way = dinic::Result();
for (pair<li, int> p : way) {
int x = (int)(p.first / n), y = (int)(p.first % n);
match[y] = x;
}
queue<int> que;
que.push(0);
FILL(par, n, -1);
while (!que.empty()) {
int u = que.front();
que.pop();
for (int j : F[u]) {
int i = match[j];
if (par[i] == -1) {
par[i] = u;
A[j] = i;
B[j] = u;
que.push(i);
}
}
}
for (int i = 1; i < n; ++i) {
if (par[i] == -1)
NoSolution();
}
for (int i = 0; i < n - 1; ++i) {
printf("%d %d\n", A[i] + 1, B[i] + 1);
}
return 0;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p03205 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, S, T, d[100010], ans, a[100010], b[100010];
vector<int> v[100010];
int cnt = 1, head[200010], to[800010], nxt[800010], w[800010];
bool used[100010];
void add(int x, int y, int z) {
cnt++;
to[cnt] = y;
nxt[cnt] = head[x];
head[x] = cnt;
w[cnt] = z;
}
void ins(int x, int y, int z) {
add(x, y, z);
add(y, x, 0);
}
bool bfs() {
for (int i = S; i <= T; i++) {
d[i] = -1;
}
queue<int> q;
d[S] = 0;
q.push(S);
while (!q.empty()) {
int x = q.front();
q.pop();
if (x == T) {
return true;
}
for (int i = head[x]; i; i = nxt[i]) {
int y = to[i];
if (w[i] && d[y] == -1) {
d[y] = d[x] + 1;
q.push(y);
}
}
}
return false;
}
int dfs(int x, int f) {
int res = 0;
if (x == T) {
return f;
}
for (int i = head[x]; i; i = nxt[i]) {
int y = to[i];
if (w[i] && d[y] == d[x] + 1) {
int tmp = dfs(y, min(f - res, w[i]));
w[i] -= tmp;
w[i ^ 1] += tmp;
res += tmp;
if (res == f) {
return res;
}
}
}
if (!res) {
d[x] = -1;
}
return res;
}
void dinic() {
while (bfs()) {
ans += dfs(S, inf);
}
}
int main() {
scanf("%d", &n);
S = 1;
T = 2 * n;
for (int i = 1; i < n; i++) {
int k;
scanf("%d", &k);
for (int j = 0; j < k; j++) {
int x;
scanf("%d", &x);
v[x].push_back(i);
if (x != 1) {
ins(x, n + i, 1);
}
}
}
for (int i = 2; i <= n; i++) {
ins(S, i, 1);
}
for (int i = 1; i < n; i++) {
ins(n + i, T, 1);
}
dinic();
if (ans != n - 1) {
puts("-1");
return 0;
}
for (int i = n + 1; i < 2 * n; i++) {
for (int j = head[i]; j; j = nxt[j]) {
if (!w[j]) {
continue;
}
a[i - n] = to[j];
}
}
queue<int> q;
used[1] = true;
q.push(1);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
if (!used[a[y]]) {
used[a[y]] = true;
q.push(a[y]);
b[y] = x;
}
}
}
bool f = true;
for (int i = 1; i < n; i++) {
f &= used[i];
}
if (!f) {
puts("-1");
return 0;
}
for (int i = 1; i < n; i++) {
printf("%d %d\n", a[i], b[i]);
}
return 0;
}
// 霓为衣兮风为马,云之君兮纷纷而来下。
// ——李白《梦游天姥吟留别》 | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, S, T, d[200010], ans, a[100010], b[100010];
vector<int> v[100010];
int cnt = 1, head[200010], to[800010], nxt[800010], w[800010];
bool used[100010];
void add(int x, int y, int z) {
cnt++;
to[cnt] = y;
nxt[cnt] = head[x];
head[x] = cnt;
w[cnt] = z;
}
void ins(int x, int y, int z) {
add(x, y, z);
add(y, x, 0);
}
bool bfs() {
for (int i = S; i <= T; i++) {
d[i] = -1;
}
queue<int> q;
d[S] = 0;
q.push(S);
while (!q.empty()) {
int x = q.front();
q.pop();
if (x == T) {
return true;
}
for (int i = head[x]; i; i = nxt[i]) {
int y = to[i];
if (w[i] && d[y] == -1) {
d[y] = d[x] + 1;
q.push(y);
}
}
}
return false;
}
int dfs(int x, int f) {
int res = 0;
if (x == T) {
return f;
}
for (int i = head[x]; i; i = nxt[i]) {
int y = to[i];
if (w[i] && d[y] == d[x] + 1) {
int tmp = dfs(y, min(f - res, w[i]));
w[i] -= tmp;
w[i ^ 1] += tmp;
res += tmp;
if (res == f) {
return res;
}
}
}
if (!res) {
d[x] = -1;
}
return res;
}
void dinic() {
while (bfs()) {
ans += dfs(S, inf);
}
}
int main() {
scanf("%d", &n);
S = 1;
T = 2 * n;
for (int i = 1; i < n; i++) {
int k;
scanf("%d", &k);
for (int j = 0; j < k; j++) {
int x;
scanf("%d", &x);
v[x].push_back(i);
if (x != 1) {
ins(x, n + i, 1);
}
}
}
for (int i = 2; i <= n; i++) {
ins(S, i, 1);
}
for (int i = 1; i < n; i++) {
ins(n + i, T, 1);
}
dinic();
if (ans != n - 1) {
puts("-1");
return 0;
}
for (int i = n + 1; i < 2 * n; i++) {
for (int j = head[i]; j; j = nxt[j]) {
if (!w[j]) {
continue;
}
a[i - n] = to[j];
}
}
queue<int> q;
used[1] = true;
q.push(1);
while (!q.empty()) {
int x = q.front();
q.pop();
for (int i = 0; i < v[x].size(); i++) {
int y = v[x][i];
if (!used[a[y]]) {
used[a[y]] = true;
q.push(a[y]);
b[y] = x;
}
}
}
bool f = true;
for (int i = 1; i < n; i++) {
f &= used[i];
}
if (!f) {
puts("-1");
return 0;
}
for (int i = 1; i < n; i++) {
printf("%d %d\n", a[i], b[i]);
}
return 0;
}
// 霓为衣兮风为马,云之君兮纷纷而来下。
// ——李白《梦游天姥吟留别》 | replace | 3 | 4 | 3 | 4 | 0 | |
p03205 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 200005, S = 0, T = 200000;
struct node {
int to, next, val;
} e[N << 4];
int head[N], cnt, dep[N], q[N], c[N], n;
void add(int x, int y, int z) {
e[cnt] = (node){y, head[x], z};
head[x] = cnt++;
}
void insert(int x, int y, int z) { add(x, y, z), add(y, x, 0); }
int bfs() {
int l = 0, r = 0;
q[r++] = S;
memset(dep, -1, sizeof(dep));
dep[S] = 1;
while (l < r) {
int x = q[l++];
for (int i = head[x]; i != -1; i = e[i].next) {
int to1 = e[i].to;
if (dep[to1] == -1 && e[i].val)
dep[to1] = dep[x] + 1, q[r++] = to1;
}
}
return dep[T] != -1;
}
int dfs(int x, int maxf) {
if (x == T)
return maxf;
int tflow = maxf, nowf;
for (int i = head[x]; i != -1; i = e[i].next) {
int to1 = e[i].to;
if (dep[to1] == dep[x] + 1 && e[i].val) {
nowf = dfs(to1, min(tflow, e[i].val));
if (nowf && x >= 1 && x <= n - 1 && to1)
c[x] = to1 - n + 2;
e[i].val -= nowf, tflow -= nowf, e[i ^ 1].val += nowf;
if (!tflow)
break;
}
}
return maxf - tflow;
}
vector<int> v[N];
int Dinic() {
int sum = 0;
while (bfs())
sum += dfs(S, 1 << 30);
return sum;
}
int vis[N];
pair<int, int> ans[N];
int main() {
scanf("%d", &n);
memset(head, -1, sizeof(head));
for (int i = 1; i < n; i++) {
int siz;
scanf("%d", &siz);
insert(S, i, 1);
insert(n + i - 1, T, 1);
for (int j = 1, x; j <= siz; j++) {
scanf("%d", &x), v[x].push_back(i);
if (x != 1)
insert(i, n + x - 2, 1);
}
}
// puts("B");
if (Dinic() == n - 1) {
// puts("a");
int l = 0, r = 0;
for (int i = 0; i < v[1].size(); i++)
q[r++] = v[1][i], vis[v[1][i]] = 1;
while (l < r) {
int x = q[l++];
ans[x] = make_pair(vis[x], c[x]);
x = c[x];
for (int i = 0; i < v[x].size(); i++)
if (!vis[v[x][i]])
q[r++] = v[x][i], vis[v[x][i]] = x;
}
if (r == n - 1)
for (int i = 1; i < n; i++)
printf("%d %d\n", ans[i].first, ans[i].second);
else
puts("-1");
} else
puts("-1");
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 200005, S = 0, T = 200000;
struct node {
int to, next, val;
} e[N << 4];
int head[N], cnt, dep[N], q[N], c[N], n;
void add(int x, int y, int z) {
e[cnt] = (node){y, head[x], z};
head[x] = cnt++;
}
void insert(int x, int y, int z) { add(x, y, z), add(y, x, 0); }
int bfs() {
int l = 0, r = 0;
q[r++] = S;
memset(dep, -1, sizeof(dep));
dep[S] = 1;
while (l < r) {
int x = q[l++];
for (int i = head[x]; i != -1; i = e[i].next) {
int to1 = e[i].to;
if (dep[to1] == -1 && e[i].val)
dep[to1] = dep[x] + 1, q[r++] = to1;
}
}
return dep[T] != -1;
}
int dfs(int x, int maxf) {
if (x == T)
return maxf;
int tflow = maxf, nowf;
for (int i = head[x]; i != -1; i = e[i].next) {
int to1 = e[i].to;
if (dep[to1] == dep[x] + 1 && e[i].val) {
nowf = dfs(to1, min(tflow, e[i].val));
if (nowf && x >= 1 && x <= n - 1 && to1)
c[x] = to1 - n + 2;
e[i].val -= nowf, tflow -= nowf, e[i ^ 1].val += nowf;
if (!tflow)
break;
}
}
if (tflow)
dep[x] = -1;
return maxf - tflow;
}
vector<int> v[N];
int Dinic() {
int sum = 0;
while (bfs())
sum += dfs(S, 1 << 30);
return sum;
}
int vis[N];
pair<int, int> ans[N];
int main() {
scanf("%d", &n);
memset(head, -1, sizeof(head));
for (int i = 1; i < n; i++) {
int siz;
scanf("%d", &siz);
insert(S, i, 1);
insert(n + i - 1, T, 1);
for (int j = 1, x; j <= siz; j++) {
scanf("%d", &x), v[x].push_back(i);
if (x != 1)
insert(i, n + x - 2, 1);
}
}
// puts("B");
if (Dinic() == n - 1) {
// puts("a");
int l = 0, r = 0;
for (int i = 0; i < v[1].size(); i++)
q[r++] = v[1][i], vis[v[1][i]] = 1;
while (l < r) {
int x = q[l++];
ans[x] = make_pair(vis[x], c[x]);
x = c[x];
for (int i = 0; i < v[x].size(); i++)
if (!vis[v[x][i]])
q[r++] = v[x][i], vis[v[x][i]] = x;
}
if (r == n - 1)
for (int i = 1; i < n; i++)
printf("%d %d\n", ans[i].first, ans[i].second);
else
puts("-1");
} else
puts("-1");
}
| insert | 42 | 42 | 42 | 44 | TLE | |
p03205 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iterator>
#include <vector>
using namespace std;
struct R {
int v, z, c;
} e[1111111];
int K[222222], cur[222222], ce = 1;
void ins(int a, int b, int c) {
e[++ce] = (R){b, K[a], c};
K[a] = ce;
}
void AE(int a, int b) {
ins(a, b, 1);
ins(b, a, 0);
}
int s, t, d[222222];
bool BFS() {
static int q[222222], du, my;
memset(d, 0, sizeof(d));
memcpy(cur, K, sizeof(cur));
for (d[q[du = my = 1] = s] = 1; du <= my;) {
int u = q[du++];
for (int i = K[u]; i; i = e[i].z)
if (e[i].c && !d[e[i].v]) {
d[e[i].v] = d[u] + 1;
q[++my] = e[i].v;
}
}
return d[t];
}
int DFS(int u, int r) {
if (u == t)
return r;
int tmp = r;
for (int &i = cur[u]; i; i = e[i].z)
if (e[i].c && d[e[i].v] == d[u] + 1) {
int qwq = DFS(e[i].v, min(r, e[i].c));
if (qwq) {
r -= qwq;
e[i].c -= qwq;
e[i ^ 1].c += qwq;
if (!r)
return tmp;
}
}
return tmp - r;
}
int Dinic() {
int r = 0;
for (; BFS();)
r += DFS(s, 2333333);
return r;
}
bool viz[222222];
int n, p[111111], u[111111], v[111111];
void dfs(int u, int pa, int gp) {
viz[u] = 1;
if (u <= n) {
::u[pa - n] = gp;
::v[pa - n] = u;
}
for (int i = K[u]; i; i = e[i].z)
if (!viz[e[i].v] && e[i].c)
dfs(e[i].v, u, pa);
}
int main() {
scanf("%d", &n);
s = 2 * n;
t = 2 * n + 1;
for (int i = 2; i <= n; ++i)
AE(s, i);
for (int i = 1; i < n; ++i) {
int c;
for (scanf("%d", &c); c--;) {
int v;
scanf("%d", &v);
AE(v, i + n);
}
AE(i + n, t);
}
viz[s] = viz[t] = 1;
if (Dinic() != n - 1)
return puts("-1"), 0;
dfs(1, 0, 0);
for (int i = 1; i < n; ++i)
if (!u[i])
return puts("-1"), 0;
for (int i = 1; i < n; ++i)
printf("%d %d\n", u[i], v[i]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iterator>
#include <vector>
using namespace std;
struct R {
int v, z, c;
} e[1111111];
int K[222222], cur[222222], ce = 1;
void ins(int a, int b, int c) {
e[++ce] = (R){b, K[a], c};
K[a] = ce;
}
void AE(int a, int b) {
ins(a, b, 1);
ins(b, a, 0);
}
int s, t, d[222222];
bool BFS() {
static int q[222222], du, my;
memset(d, 0, sizeof(d));
memcpy(cur, K, sizeof(cur));
for (d[q[du = my = 1] = s] = 1; du <= my;) {
int u = q[du++];
for (int i = K[u]; i; i = e[i].z)
if (e[i].c && !d[e[i].v]) {
d[e[i].v] = d[u] + 1;
q[++my] = e[i].v;
}
}
return d[t];
}
int DFS(int u, int r) {
if (u == t)
return r;
int tmp = r;
for (int &i = cur[u]; i; i = e[i].z)
if (e[i].c && d[e[i].v] == d[u] + 1) {
int qwq = DFS(e[i].v, min(r, e[i].c));
if (qwq) {
r -= qwq;
e[i].c -= qwq;
e[i ^ 1].c += qwq;
if (!r)
return tmp;
}
}
return tmp - r;
}
int Dinic() {
int r = 0;
for (; BFS();)
r += DFS(s, 2333333);
return r;
}
bool viz[222222];
int n, p[111111], u[111111], v[111111];
void dfs(int u, int pa, int gp) {
viz[u] = 1;
if (u <= n && pa) {
::u[pa - n] = gp;
::v[pa - n] = u;
}
for (int i = K[u]; i; i = e[i].z)
if (!viz[e[i].v] && e[i].c)
dfs(e[i].v, u, pa);
}
int main() {
scanf("%d", &n);
s = 2 * n;
t = 2 * n + 1;
for (int i = 2; i <= n; ++i)
AE(s, i);
for (int i = 1; i < n; ++i) {
int c;
for (scanf("%d", &c); c--;) {
int v;
scanf("%d", &v);
AE(v, i + n);
}
AE(i + n, t);
}
viz[s] = viz[t] = 1;
if (Dinic() != n - 1)
return puts("-1"), 0;
dfs(1, 0, 0);
for (int i = 1; i < n; ++i)
if (!u[i])
return puts("-1"), 0;
for (int i = 1; i < n; ++i)
printf("%d %d\n", u[i], v[i]);
return 0;
} | replace | 61 | 62 | 61 | 62 | 0 | |
p03205 | C++ | Time Limit Exceeded | #include <stdio.h>
#include <vector>
#define MN 200010
#define MM 800010
#define inf 999999999
using namespace std;
int fr[MN], dy[MN], ne[MM], v[MM], w[MM], bs = 0;
void add(int a, int b, int c) {
v[bs] = b;
w[bs] = c;
ne[bs] = fr[a];
fr[a] = bs++;
}
void addb(int a, int b, int c) {
add(a, b, c);
add(b, a, 0);
}
int dl[100010], jl[100010], N, S, T;
bool bk[100010];
bool bfs() {
for (int i = 1; i <= N; i++) {
bk[i] = false;
jl[i] = inf;
}
bk[S] = true;
jl[S] = 0;
int he = 0, ta = 1;
dl[0] = S;
while (he < ta) {
int u = dl[he++];
for (int i = fr[u]; i != -1; i = ne[i]) {
if (w[i] > 0 && !bk[v[i]]) {
bk[v[i]] = true;
jl[v[i]] = jl[u] + 1;
dl[ta++] = v[i];
}
}
}
return jl[T] < inf;
}
int dfs(int u, int z) {
if (u == T)
return z;
for (int &i = dy[u]; i != -1; i = ne[i]) {
if (w[i] > 0 && jl[v[i]] == jl[u] + 1) {
int t = dfs(v[i], z < w[i] ? z : w[i]);
if (t != -1) {
w[i] -= t;
w[i ^ 1] += t;
return t;
}
}
}
return -1;
}
int dinic() {
int jg = 0;
while (bfs()) {
for (int i = 1; i <= N; i++)
dy[i] = fr[i];
while (1) {
int t = dfs(S, inf);
if (t == -1)
break;
jg += t;
}
}
return jg;
}
vector<int> ve[100010], to[100010];
int pp[100010], fa[100010];
void dfs2(int u, int f) {
if (bk[u])
return;
fa[u] = f;
bk[u] = true;
for (int i = 0; i < to[u].size(); i++)
dfs2(to[u][i], u);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n - 1; i++) {
int s, a;
scanf("%d", &s);
for (int j = 0; j < s; j++) {
scanf("%d", &a);
ve[i].push_back(a);
}
}
N = n * 2 + 1;
S = N - 1;
T = N;
for (int i = 1; i <= N; i++)
fr[i] = -1;
for (int i = 1; i <= n - 1; i++) {
addb(S, i, 1);
for (int j = 0; j < ve[i].size(); j++)
addb(i, ve[i][j] + n - 1, 1);
}
for (int i = 1; i <= n; i++)
addb(i + n - 1, T, 1);
if (dinic() != n - 1) {
printf("-1");
return 0;
}
for (int i = 1; i <= n; i++)
bk[i] = false;
for (int i = 1; i <= n - 1; i++) {
for (int j = fr[i]; j != -1; j = ne[j]) {
int t = v[j];
if (t > n - 1 && w[j] == 0) {
pp[i] = t - (n - 1);
break;
}
}
for (int j = 0; j < ve[i].size(); j++) {
if (ve[i][j] != pp[i])
to[ve[i][j]].push_back(pp[i]);
}
bk[pp[i]] = true;
}
int ro = -1;
for (int i = 1; i <= n; i++) {
if (!bk[i]) {
ro = i;
break;
}
}
for (int i = 1; i <= n; i++)
bk[i] = false;
dfs2(ro, 0);
for (int i = 1; i <= n; i++) {
if (i != ro && fa[i] == 0) {
printf("-1");
return 0;
}
}
for (int i = 1; i <= n - 1; i++)
printf("%d %d\n", pp[i], fa[pp[i]]);
return 0;
} | #include <stdio.h>
#include <vector>
#define MN 200010
#define MM 800010
#define inf 999999999
using namespace std;
int fr[MN], dy[MN], ne[MM], v[MM], w[MM], bs = 0;
void add(int a, int b, int c) {
v[bs] = b;
w[bs] = c;
ne[bs] = fr[a];
fr[a] = bs++;
}
void addb(int a, int b, int c) {
add(a, b, c);
add(b, a, 0);
}
int dl[MN], jl[MN], N, S, T;
bool bk[MN];
bool bfs() {
for (int i = 1; i <= N; i++) {
bk[i] = false;
jl[i] = inf;
}
bk[S] = true;
jl[S] = 0;
int he = 0, ta = 1;
dl[0] = S;
while (he < ta) {
int u = dl[he++];
for (int i = fr[u]; i != -1; i = ne[i]) {
if (w[i] > 0 && !bk[v[i]]) {
bk[v[i]] = true;
jl[v[i]] = jl[u] + 1;
dl[ta++] = v[i];
}
}
}
return jl[T] < inf;
}
int dfs(int u, int z) {
if (u == T)
return z;
for (int &i = dy[u]; i != -1; i = ne[i]) {
if (w[i] > 0 && jl[v[i]] == jl[u] + 1) {
int t = dfs(v[i], z < w[i] ? z : w[i]);
if (t != -1) {
w[i] -= t;
w[i ^ 1] += t;
return t;
}
}
}
return -1;
}
int dinic() {
int jg = 0;
while (bfs()) {
for (int i = 1; i <= N; i++)
dy[i] = fr[i];
while (1) {
int t = dfs(S, inf);
if (t == -1)
break;
jg += t;
}
}
return jg;
}
vector<int> ve[100010], to[100010];
int pp[100010], fa[100010];
void dfs2(int u, int f) {
if (bk[u])
return;
fa[u] = f;
bk[u] = true;
for (int i = 0; i < to[u].size(); i++)
dfs2(to[u][i], u);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n - 1; i++) {
int s, a;
scanf("%d", &s);
for (int j = 0; j < s; j++) {
scanf("%d", &a);
ve[i].push_back(a);
}
}
N = n * 2 + 1;
S = N - 1;
T = N;
for (int i = 1; i <= N; i++)
fr[i] = -1;
for (int i = 1; i <= n - 1; i++) {
addb(S, i, 1);
for (int j = 0; j < ve[i].size(); j++)
addb(i, ve[i][j] + n - 1, 1);
}
for (int i = 1; i <= n; i++)
addb(i + n - 1, T, 1);
if (dinic() != n - 1) {
printf("-1");
return 0;
}
for (int i = 1; i <= n; i++)
bk[i] = false;
for (int i = 1; i <= n - 1; i++) {
for (int j = fr[i]; j != -1; j = ne[j]) {
int t = v[j];
if (t > n - 1 && w[j] == 0) {
pp[i] = t - (n - 1);
break;
}
}
for (int j = 0; j < ve[i].size(); j++) {
if (ve[i][j] != pp[i])
to[ve[i][j]].push_back(pp[i]);
}
bk[pp[i]] = true;
}
int ro = -1;
for (int i = 1; i <= n; i++) {
if (!bk[i]) {
ro = i;
break;
}
}
for (int i = 1; i <= n; i++)
bk[i] = false;
dfs2(ro, 0);
for (int i = 1; i <= n; i++) {
if (i != ro && fa[i] == 0) {
printf("-1");
return 0;
}
}
for (int i = 1; i <= n - 1; i++)
printf("%d %d\n", pp[i], fa[pp[i]]);
return 0;
} | replace | 17 | 19 | 17 | 19 | TLE | |
p03205 | C++ | Runtime Error | #include <bits/stdc++.h>
#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 MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
int n, m;
vector<int> hv[200005];
struct edge {
int to, cap, rev;
} E[400005];
vector<int> G[200005];
void add_edge(int u, int v, int c) {
E[m].to = v;
E[m].cap = c;
E[m].rev = m ^ 1;
G[u].push_back(m++);
E[m].to = u;
E[m].cap = 0;
E[m].rev = m ^ 1;
G[v].push_back(m++);
}
int dis[200005], cur[200005];
bool bfs() {
rep1(i, 2 * n) dis[i] = -1;
queue<int> que;
que.push(0);
dis[0] = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
rep(i, G[v].size()) {
int ce = G[v][i];
if (E[ce].cap > 0 && dis[E[ce].to] == -1) {
que.push(E[ce].to);
dis[E[ce].to] = dis[v] + 1;
}
}
}
if (dis[2 * n] == -1)
return false;
rep(i, 2 * n + 1) cur[i] = 0;
return true;
}
int dfs(int v, int maxf) {
if (v == 2 * n)
return maxf;
if (maxf == 0)
return 0;
int ret = 0;
for (; cur[v] < G[v].size(); cur[v]++) {
int ce = G[v][cur[v]];
if (dis[E[ce].to] == dis[v] + 1 && E[ce].cap > 0) {
int cf = dfs(E[ce].to, min(maxf - ret, E[ce].cap));
E[ce].cap -= cf;
E[E[ce].rev].cap += cf;
ret += cf;
if (ret == maxf)
break;
}
}
return ret;
}
int lp[200005], par[200005];
int dinic() {
int ret = 0;
while (bfs())
ret += dfs(0, INF);
return ret;
}
int main() {
scanf("%d", &n);
rep1(i, n - 1) {
int cs;
scanf("%d", &cs);
hv[i].resize(cs);
rep(j, cs) {
scanf("%d", &hv[i][j]);
add_edge(hv[i][j], i + n, 1);
}
add_edge(i + n, n * 2, 1);
}
rep1(i, n) add_edge(0, i, 1);
if (dinic() != n - 1) {
printf("-1\n");
return 0;
}
rep1(i, n) if (dis[i] == -1) {
printf("-1\n");
return 0;
}
rep1(i, 2 * n - 1) rep(j, G[i].size()) {
int ce = G[i][j];
if (E[ce].cap == 0 && dis[E[ce].to] == dis[i] - 1) {
par[i] = E[ce].to;
break;
}
}
rep1(i, n) if (par[i] != 0) lp[par[i] - n] = i;
rep1(i, n - 1) printf("%d %d\n", par[i + n], lp[i]);
return 0;
} | #include <bits/stdc++.h>
#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 MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
int n, m;
vector<int> hv[200005];
struct edge {
int to, cap, rev;
} E[800005];
vector<int> G[200005];
void add_edge(int u, int v, int c) {
E[m].to = v;
E[m].cap = c;
E[m].rev = m ^ 1;
G[u].push_back(m++);
E[m].to = u;
E[m].cap = 0;
E[m].rev = m ^ 1;
G[v].push_back(m++);
}
int dis[200005], cur[200005];
bool bfs() {
rep1(i, 2 * n) dis[i] = -1;
queue<int> que;
que.push(0);
dis[0] = 0;
while (!que.empty()) {
int v = que.front();
que.pop();
rep(i, G[v].size()) {
int ce = G[v][i];
if (E[ce].cap > 0 && dis[E[ce].to] == -1) {
que.push(E[ce].to);
dis[E[ce].to] = dis[v] + 1;
}
}
}
if (dis[2 * n] == -1)
return false;
rep(i, 2 * n + 1) cur[i] = 0;
return true;
}
int dfs(int v, int maxf) {
if (v == 2 * n)
return maxf;
if (maxf == 0)
return 0;
int ret = 0;
for (; cur[v] < G[v].size(); cur[v]++) {
int ce = G[v][cur[v]];
if (dis[E[ce].to] == dis[v] + 1 && E[ce].cap > 0) {
int cf = dfs(E[ce].to, min(maxf - ret, E[ce].cap));
E[ce].cap -= cf;
E[E[ce].rev].cap += cf;
ret += cf;
if (ret == maxf)
break;
}
}
return ret;
}
int lp[200005], par[200005];
int dinic() {
int ret = 0;
while (bfs())
ret += dfs(0, INF);
return ret;
}
int main() {
scanf("%d", &n);
rep1(i, n - 1) {
int cs;
scanf("%d", &cs);
hv[i].resize(cs);
rep(j, cs) {
scanf("%d", &hv[i][j]);
add_edge(hv[i][j], i + n, 1);
}
add_edge(i + n, n * 2, 1);
}
rep1(i, n) add_edge(0, i, 1);
if (dinic() != n - 1) {
printf("-1\n");
return 0;
}
rep1(i, n) if (dis[i] == -1) {
printf("-1\n");
return 0;
}
rep1(i, 2 * n - 1) rep(j, G[i].size()) {
int ce = G[i][j];
if (E[ce].cap == 0 && dis[E[ce].to] == dis[i] - 1) {
par[i] = E[ce].to;
break;
}
}
rep1(i, n) if (par[i] != 0) lp[par[i] - n] = i;
rep1(i, n - 1) printf("%d %d\n", par[i + n], lp[i]);
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p03205 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5, inf = 1e9;
int n, tot, ter[maxn + 3], wei[maxn + 3], nxt[maxn + 3], lnk[maxn + 3];
int cur[maxn + 3], dep[maxn + 3], num[maxn + 3], ans[maxn + 3];
bool vis[maxn + 3];
vector<int> S[maxn + 3], V[maxn + 3], G[maxn + 3];
int adj(int x) { return x & 1 ? x + 1 : x - 1; }
int add(int u, int v, int w) {
ter[++tot] = v, wei[tot] = w;
nxt[tot] = lnk[u], lnk[u] = tot;
return tot;
}
int add_f(int u, int v) {
int t = add(u, v, 1);
return add(v, u, 0), t;
}
bool bfs() {
queue<int> Q;
Q.push(1);
memset(dep, -1, sizeof(dep));
dep[1] = 0;
while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (int i = lnk[u], v, w; i; i = nxt[i]) {
v = ter[i], w = wei[i];
if ((~dep[v]) || !w)
continue;
dep[v] = dep[u] + 1;
Q.push(v);
}
}
return ~dep[n * 2];
}
int dfs(int u, int t, int lft) {
if (u == t) {
return lft;
}
int ret = 0;
for (int &i = cur[u], v, w; i && ret < lft; i = nxt[i]) {
v = ter[i], w = wei[i];
if (w && dep[u] + 1 == dep[v]) {
int x = dfs(v, t, min(lft - ret, w));
wei[i] -= x, wei[adj(i)] += x, ret += x;
}
}
if (ret < lft) {
dep[u] = -1;
}
return ret;
}
int flow() {
int ret = 0;
while (bfs()) {
memcpy(cur, lnk, sizeof(cur));
ret += dfs(1, n * 2, inf);
}
return ret;
}
void dfs(int u) {
vis[u] = true;
for (int i = 0, v; i < G[u].size(); i++) {
v = G[u][i];
if (vis[v])
continue;
ans[v] = u;
dfs(v);
}
}
int main() {
scanf("%d", &n);
for (int i = 1, m; i <= n - 1; i++) {
scanf("%d", &m);
S[i].resize(m), V[i].resize(m);
for (int j = 0; j < m; j++) {
scanf("%d", &S[i][j]);
if (S[i][j] != 1) {
V[i][j] = add_f(S[i][j], i + n);
}
}
}
for (int i = 2; i <= n; i++) {
add_f(1, i);
}
for (int i = n + 1; i < n * 2; i++) {
add_f(i, n * 2);
}
if (flow() != n - 1) {
puts("-1");
return 0;
}
for (int i = 1; i <= n - 1; i++) {
int x = 0;
for (int j = 0; j < S[i].size(); j++) {
if (S[i][j] != 1 && !wei[V[i][j]]) {
x = S[i][j];
break;
}
}
num[i] = x;
for (int j = 0; j < S[i].size(); j++) {
if (S[i][j] != x) {
G[S[i][j]].push_back(x);
}
}
}
dfs(1);
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
puts("-1");
break;
}
}
for (int i = 1; i <= n - 1; i++) {
printf("%d %d\n", ans[num[i]], num[i]);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6, inf = 1e9;
int n, tot, ter[maxn + 3], wei[maxn + 3], nxt[maxn + 3], lnk[maxn + 3];
int cur[maxn + 3], dep[maxn + 3], num[maxn + 3], ans[maxn + 3];
bool vis[maxn + 3];
vector<int> S[maxn + 3], V[maxn + 3], G[maxn + 3];
int adj(int x) { return x & 1 ? x + 1 : x - 1; }
int add(int u, int v, int w) {
ter[++tot] = v, wei[tot] = w;
nxt[tot] = lnk[u], lnk[u] = tot;
return tot;
}
int add_f(int u, int v) {
int t = add(u, v, 1);
return add(v, u, 0), t;
}
bool bfs() {
queue<int> Q;
Q.push(1);
memset(dep, -1, sizeof(dep));
dep[1] = 0;
while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (int i = lnk[u], v, w; i; i = nxt[i]) {
v = ter[i], w = wei[i];
if ((~dep[v]) || !w)
continue;
dep[v] = dep[u] + 1;
Q.push(v);
}
}
return ~dep[n * 2];
}
int dfs(int u, int t, int lft) {
if (u == t) {
return lft;
}
int ret = 0;
for (int &i = cur[u], v, w; i && ret < lft; i = nxt[i]) {
v = ter[i], w = wei[i];
if (w && dep[u] + 1 == dep[v]) {
int x = dfs(v, t, min(lft - ret, w));
wei[i] -= x, wei[adj(i)] += x, ret += x;
}
}
if (ret < lft) {
dep[u] = -1;
}
return ret;
}
int flow() {
int ret = 0;
while (bfs()) {
memcpy(cur, lnk, sizeof(cur));
ret += dfs(1, n * 2, inf);
}
return ret;
}
void dfs(int u) {
vis[u] = true;
for (int i = 0, v; i < G[u].size(); i++) {
v = G[u][i];
if (vis[v])
continue;
ans[v] = u;
dfs(v);
}
}
int main() {
scanf("%d", &n);
for (int i = 1, m; i <= n - 1; i++) {
scanf("%d", &m);
S[i].resize(m), V[i].resize(m);
for (int j = 0; j < m; j++) {
scanf("%d", &S[i][j]);
if (S[i][j] != 1) {
V[i][j] = add_f(S[i][j], i + n);
}
}
}
for (int i = 2; i <= n; i++) {
add_f(1, i);
}
for (int i = n + 1; i < n * 2; i++) {
add_f(i, n * 2);
}
if (flow() != n - 1) {
puts("-1");
return 0;
}
for (int i = 1; i <= n - 1; i++) {
int x = 0;
for (int j = 0; j < S[i].size(); j++) {
if (S[i][j] != 1 && !wei[V[i][j]]) {
x = S[i][j];
break;
}
}
num[i] = x;
for (int j = 0; j < S[i].size(); j++) {
if (S[i][j] != x) {
G[S[i][j]].push_back(x);
}
}
}
dfs(1);
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
puts("-1");
break;
}
}
for (int i = 1; i <= n - 1; i++) {
printf("%d %d\n", ans[num[i]], num[i]);
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03205 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 200010;
const int INF = 2147483600;
int N;
int Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], C[MAXN << 1], cnt;
inline void addedge(int u, int v, int c) {
Node[cnt] = v;
Next[cnt] = Root[u];
C[cnt] = c;
Root[u] = cnt++;
}
inline void insert(int u, int v, int c) {
addedge(u, v, c);
addedge(v, u, 0);
}
int S, T;
int dis[MAXN + 1];
inline bool BFS() {
for (int i = S; i <= T; i++)
dis[i] = 0;
queue<int> que;
que.push(S);
dis[S] = 1;
while (!que.empty()) {
int k = que.front();
for (int x = Root[k]; x != -1; x = Next[x]) {
int v = Node[x];
if (C[x] > 0 && !dis[v])
dis[v] = dis[k] + 1, que.push(v);
}
que.pop();
}
return (dis[T] ? 1 : 0);
}
inline int DFS(int k, int t) {
if (k == T) {
return t;
}
int ret = 0;
for (int x = Root[k]; x != -1; x = Next[x]) {
int v = Node[x];
if (C[x] > 0 && dis[v] == dis[k] + 1) {
int d = DFS(v, min(t, C[x]));
C[x] -= d;
C[x ^ 1] += d;
ret += d;
t -= d;
if (!t)
return ret;
}
}
if (!ret)
dis[k] = 0;
return ret;
}
int nod;
queue<int> que;
int vis[MAXN + 1], chs[MAXN + 1], root;
vector<int> vec[MAXN + 1];
int P[MAXN + 1];
inline void Add(int k) {
++nod;
for (int i = 0, sz = vec[k].size(); i < sz; i++) {
int j = vec[k][i];
if (!vis[j] && chs[j] != k)
vis[j] = k, que.push(j);
}
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
N = read();
T = 2 * N, S = 0;
memset(Root, -1, sizeof(Root));
for (int i = 1; i < N; i++) {
P[i] = read();
insert(S, i, 1);
for (int j = 1; j <= P[i]; j++) {
int x = read();
vec[x].push_back(i);
insert(i, x + N - 1, 1);
}
}
for (int i = 1; i <= N; i++)
insert(i + N - 1, T, 1);
int sum = 0;
while (BFS())
sum += DFS(S, INF);
if (sum != N - 1) {
puts("-1");
return 0;
}
int id = 1;
int now = 0;
for (int i = 1; i < N; i++) {
now += 2;
for (int j = 1; j <= P[i]; j++) {
if (!C[now])
chs[i] = Node[now] - (N - 1);
now += 2;
}
}
while (now < cnt) {
if (C[now]) {
root = id;
break;
}
now += 2;
++id;
}
Add(root);
while (!que.empty()) {
int k = que.front();
Add(chs[k]);
que.pop();
}
if (nod != N) {
puts("-1");
return 0;
}
for (int i = 1; i < N; i++)
printf("%d %d\n", chs[i], vis[i]);
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 600010;
const int INF = 2147483600;
int N;
int Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], C[MAXN << 1], cnt;
inline void addedge(int u, int v, int c) {
Node[cnt] = v;
Next[cnt] = Root[u];
C[cnt] = c;
Root[u] = cnt++;
}
inline void insert(int u, int v, int c) {
addedge(u, v, c);
addedge(v, u, 0);
}
int S, T;
int dis[MAXN + 1];
inline bool BFS() {
for (int i = S; i <= T; i++)
dis[i] = 0;
queue<int> que;
que.push(S);
dis[S] = 1;
while (!que.empty()) {
int k = que.front();
for (int x = Root[k]; x != -1; x = Next[x]) {
int v = Node[x];
if (C[x] > 0 && !dis[v])
dis[v] = dis[k] + 1, que.push(v);
}
que.pop();
}
return (dis[T] ? 1 : 0);
}
inline int DFS(int k, int t) {
if (k == T) {
return t;
}
int ret = 0;
for (int x = Root[k]; x != -1; x = Next[x]) {
int v = Node[x];
if (C[x] > 0 && dis[v] == dis[k] + 1) {
int d = DFS(v, min(t, C[x]));
C[x] -= d;
C[x ^ 1] += d;
ret += d;
t -= d;
if (!t)
return ret;
}
}
if (!ret)
dis[k] = 0;
return ret;
}
int nod;
queue<int> que;
int vis[MAXN + 1], chs[MAXN + 1], root;
vector<int> vec[MAXN + 1];
int P[MAXN + 1];
inline void Add(int k) {
++nod;
for (int i = 0, sz = vec[k].size(); i < sz; i++) {
int j = vec[k][i];
if (!vis[j] && chs[j] != k)
vis[j] = k, que.push(j);
}
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
N = read();
T = 2 * N, S = 0;
memset(Root, -1, sizeof(Root));
for (int i = 1; i < N; i++) {
P[i] = read();
insert(S, i, 1);
for (int j = 1; j <= P[i]; j++) {
int x = read();
vec[x].push_back(i);
insert(i, x + N - 1, 1);
}
}
for (int i = 1; i <= N; i++)
insert(i + N - 1, T, 1);
int sum = 0;
while (BFS())
sum += DFS(S, INF);
if (sum != N - 1) {
puts("-1");
return 0;
}
int id = 1;
int now = 0;
for (int i = 1; i < N; i++) {
now += 2;
for (int j = 1; j <= P[i]; j++) {
if (!C[now])
chs[i] = Node[now] - (N - 1);
now += 2;
}
}
while (now < cnt) {
if (C[now]) {
root = id;
break;
}
now += 2;
++id;
}
Add(root);
while (!que.empty()) {
int k = que.front();
Add(chs[k]);
que.pop();
}
if (nod != N) {
puts("-1");
return 0;
}
for (int i = 1; i < N; i++)
printf("%d %d\n", chs[i], vis[i]);
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p03205 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int INF = 1e9;
struct Edge {
int u, v, cap, flow;
};
namespace Max_flow {
vector<Edge> E;
vector<int> G[N];
int S, T, n, d[N];
void init(int _n, int _s, int _t) {
n = _n, S = _s, T = _t;
for (int i = 0; i <= n; i++)
G[i].clear();
E.clear();
}
void addedge(int u, int v, int cap) {
E.push_back((Edge){u, v, cap, 0});
E.push_back((Edge){v, u, 0, 0});
int m = E.size();
G[u].push_back(m - 2);
G[v].push_back(m - 1);
}
bool bfs() {
for (int i = 0; i <= n; i++)
d[i] = 0;
d[S] = 1;
queue<int> q;
q.push(S);
while (q.size()) {
int u = q.front();
q.pop();
for (int i : G[u]) {
if (E[i].cap > E[i].flow && !d[E[i].v]) {
d[E[i].v] = d[u] + 1;
q.push(E[i].v);
}
}
}
return d[T];
}
int dfs(int u, int a) {
if (!a || u == T)
return a;
int flow = 0;
for (int i : G[u]) {
if (d[E[i].v] != d[u] + 1)
continue;
int f = dfs(E[i].v, min(E[i].cap - E[i].flow, a));
flow += f;
a -= f;
E[i].flow += f;
E[i ^ 1].flow -= f;
}
if (!flow)
d[u] = 0;
return flow;
}
int max_flow() {
int flow = 0;
while (bfs()) {
flow += dfs(S, INF);
}
return flow;
}
} // namespace Max_flow
int n, c[N], p[N], q[N], vis[N];
vector<int> g[N], bel[N];
int main() {
scanf("%d", &n);
Max_flow::init(2 * n + 1, 0, 2 * n + 1);
for (int i = 1; i < n; i++) {
scanf("%d", &c[i]);
g[i].resize(c[i]);
Max_flow::addedge(0, i, 1);
for (int j = 0; j < c[i]; j++) {
scanf("%d", &g[i][j]);
bel[g[i][j]].push_back(i);
Max_flow::addedge(i, g[i][j] + n, 1);
}
}
for (int i = 1; i <= n; i++) {
Max_flow::addedge(i + n, 2 * n + 1, 1);
}
if (Max_flow::max_flow() != n - 1) {
puts("-1");
return 0;
}
for (Edge e : Max_flow::E) {
if (e.u <= n && e.v > n && e.cap == e.flow) {
p[e.u] = e.v - n;
vis[e.v - n] = 1;
}
}
queue<int> tmp;
for (int i = 1; i <= n; i++) {
if (!vis[i])
tmp.push(i);
vis[i] = 0;
}
int cnt = 0;
while (tmp.size()) {
cnt++;
int u = tmp.front();
tmp.pop();
for (int i : bel[u])
if (!vis[i]) {
vis[i] = 1;
q[i] = u;
tmp.push(p[i]);
}
}
if (cnt != n) {
puts("-1");
return 0;
}
for (int i = 1; i < n; i++) {
printf("%d %d\n", p[i], q[i]);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int INF = 1e9;
struct Edge {
int u, v, cap, flow;
};
namespace Max_flow {
vector<Edge> E;
vector<int> G[N];
int S, T, n, d[N];
void init(int _n, int _s, int _t) {
n = _n, S = _s, T = _t;
for (int i = 0; i <= n; i++)
G[i].clear();
E.clear();
}
void addedge(int u, int v, int cap) {
E.push_back((Edge){u, v, cap, 0});
E.push_back((Edge){v, u, 0, 0});
int m = E.size();
G[u].push_back(m - 2);
G[v].push_back(m - 1);
}
bool bfs() {
for (int i = 0; i <= n; i++)
d[i] = 0;
d[S] = 1;
queue<int> q;
q.push(S);
while (q.size()) {
int u = q.front();
q.pop();
for (int i : G[u]) {
if (E[i].cap > E[i].flow && !d[E[i].v]) {
d[E[i].v] = d[u] + 1;
q.push(E[i].v);
}
}
}
return d[T];
}
int dfs(int u, int a) {
if (!a || u == T)
return a;
int flow = 0;
for (int i : G[u]) {
if (d[E[i].v] != d[u] + 1)
continue;
int f = dfs(E[i].v, min(E[i].cap - E[i].flow, a));
flow += f;
a -= f;
E[i].flow += f;
E[i ^ 1].flow -= f;
}
if (!flow)
d[u] = 0;
return flow;
}
int max_flow() {
int flow = 0;
while (bfs()) {
flow += dfs(S, INF);
}
return flow;
}
} // namespace Max_flow
int n, c[N], p[N], q[N], vis[N];
vector<int> g[N], bel[N];
int main() {
scanf("%d", &n);
Max_flow::init(2 * n + 1, 0, 2 * n + 1);
for (int i = 1; i < n; i++) {
scanf("%d", &c[i]);
g[i].resize(c[i]);
Max_flow::addedge(0, i, 1);
for (int j = 0; j < c[i]; j++) {
scanf("%d", &g[i][j]);
bel[g[i][j]].push_back(i);
Max_flow::addedge(i, g[i][j] + n, 1);
}
}
for (int i = 1; i <= n; i++) {
Max_flow::addedge(i + n, 2 * n + 1, 1);
}
if (Max_flow::max_flow() != n - 1) {
puts("-1");
return 0;
}
for (Edge e : Max_flow::E) {
if (e.u <= n && e.v > n && e.cap == e.flow) {
p[e.u] = e.v - n;
vis[e.v - n] = 1;
}
}
queue<int> tmp;
for (int i = 1; i <= n; i++) {
if (!vis[i])
tmp.push(i);
vis[i] = 0;
}
int cnt = 0;
while (tmp.size()) {
cnt++;
int u = tmp.front();
tmp.pop();
for (int i : bel[u])
if (!vis[i]) {
vis[i] = 1;
q[i] = u;
tmp.push(p[i]);
}
}
if (cnt != n) {
puts("-1");
return 0;
}
for (int i = 1; i < n; i++) {
printf("%d %d\n", p[i], q[i]);
}
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03205 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, lk[maxn + 10], vis[maxn + 10], clk;
int l[maxn + 10], r[maxn + 10];
vector<int> g[maxn + 10];
bool dfs(int p) {
for (int i = 0; i < (int)g[p].size(); ++i) {
int e = g[p][i];
if (vis[e] != clk) {
vis[e] = clk;
if (!lk[e] || dfs(lk[e])) {
lk[e] = p;
return 1;
}
}
}
return 0;
}
void getans(int p, int lst) {
for (int i = 0; i < (int)g[p].size(); ++i) {
int e = g[p][i];
if (e != lst && vis[e] != clk) {
vis[e] = clk;
l[e] = p;
r[e] = lk[e];
getans(lk[e], e);
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; ++i) {
int k;
scanf("%d", &k);
while (k--) {
int x;
scanf("%d", &x);
g[x].push_back(i);
}
}
for (int i = 1; i < n; ++i) {
++clk;
if (!dfs(i)) {
printf("-1");
return 0;
}
}
++clk;
getans(n, 0);
for (int i = 1; i < n; ++i)
if (!l[i]) {
printf("-1");
return 0;
}
for (int i = 1; i < n; ++i)
printf("%d %d\n", l[i], r[i]);
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, lk[maxn + 10], vis[maxn + 10], clk;
int l[maxn + 10], r[maxn + 10];
vector<int> g[maxn + 10];
bool dfs(int p) {
for (int i = 0; i < (int)g[p].size(); ++i) {
int e = g[p][i];
if (vis[e] != clk) {
vis[e] = clk;
if (!lk[e] || dfs(lk[e])) {
lk[e] = p;
return 1;
}
}
}
return 0;
}
void getans(int p, int lst) {
for (int i = 0; i < (int)g[p].size(); ++i) {
int e = g[p][i];
if (e != lst && vis[e] != clk) {
vis[e] = clk;
l[e] = p;
r[e] = lk[e];
getans(lk[e], e);
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i < n; ++i) {
int k;
scanf("%d", &k);
while (k--) {
int x;
scanf("%d", &x);
g[x].push_back(i);
}
}
for (int i = 1; i <= n; ++i)
random_shuffle(g[i].begin(), g[i].end());
for (int i = 1; i < n; ++i) {
++clk;
if (!dfs(i)) {
printf("-1");
return 0;
}
}
++clk;
getans(n, 0);
for (int i = 1; i < n; ++i)
if (!l[i]) {
printf("-1");
return 0;
}
for (int i = 1; i < n; ++i)
printf("%d %d\n", l[i], r[i]);
}
| insert | 44 | 44 | 44 | 46 | TLE | |
p03205 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int max_n = 100111, inf = 1000111222;
int n, p[max_n], nxt[max_n], used[max_n], ans[max_n];
int cur;
vector<int> g[max_n], g2[max_n];
bool dfs(int v) {
if (used[v] == cur) {
return false;
}
used[v] = cur;
for (int to : g[v]) {
if (p[to] == -1 || dfs(p[to])) {
p[to] = v;
nxt[v] = to;
return true;
}
}
return false;
}
void dfs2(int v) {
used[v] = 1;
for (int to : g2[v]) {
if (used[to] == 0) {
dfs2(to);
ans[to] = nxt[v];
}
}
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
for (int i = 0; i + 1 < n; ++i) {
int k;
scanf("%d", &k);
g[i].resize(k);
for (int &x : g[i]) {
scanf("%d", &x);
--x;
}
}
memset(nxt, -1, sizeof(nxt));
memset(p, -1, sizeof(p));
for (int i = 0; i + 1 < n; ++i) {
++cur;
dfs(i);
}
/*for (int run = 1; run; ) {
run = 0;
memset(used, 0, sizeof(used));
for (int i = 0; i + 1 < n; ++i) {
if (nxt[i] == -1 && dfs(i)) {
run = 1;
}
}
}*/
for (int i = 0; i + 1 < n; ++i) {
if (nxt[i] == -1) {
puts("-1");
return 0;
}
}
int root;
for (int i = 0; i < n; ++i) {
if (p[i] == -1) {
root = i;
break;
}
}
p[root] = n - 1;
nxt[n - 1] = root;
for (int i = 0; i + 1 < n; ++i) {
for (int to : g[i]) {
if (to != nxt[i]) {
g2[p[to]].push_back(i);
}
}
}
memset(used, 0, sizeof(used));
dfs2(n - 1);
for (int i = 0; i < n; ++i) {
if (!used[i]) {
puts("-1");
return 0;
}
}
for (int i = 0; i + 1 < n; ++i) {
printf("%d %d\n", nxt[i] + 1, ans[i] + 1);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int max_n = 100111, inf = 1000111222;
int n, p[max_n], nxt[max_n], used[max_n], ans[max_n];
int cur;
vector<int> g[max_n], g2[max_n];
bool dfs(int v) {
if (used[v] == cur) {
return false;
}
used[v] = cur;
for (int to : g[v]) {
if (p[to] == -1 || dfs(p[to])) {
p[to] = v;
nxt[v] = to;
return true;
}
}
return false;
}
void dfs2(int v) {
used[v] = 1;
for (int to : g2[v]) {
if (used[to] == 0) {
dfs2(to);
ans[to] = nxt[v];
}
}
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
for (int i = 0; i + 1 < n; ++i) {
int k;
scanf("%d", &k);
g[i].resize(k);
for (int &x : g[i]) {
scanf("%d", &x);
--x;
}
}
memset(nxt, -1, sizeof(nxt));
memset(p, -1, sizeof(p));
for (int i = 0; i + 1 < n; ++i) {
for (int to : g[i]) {
if (p[to] == -1) {
p[to] = i;
nxt[i] = to;
break;
}
}
}
for (int i = 0; i + 1 < n; ++i) {
if (nxt[i] == -1) {
++cur;
dfs(i);
}
}
/*for (int run = 1; run; ) {
run = 0;
memset(used, 0, sizeof(used));
for (int i = 0; i + 1 < n; ++i) {
if (nxt[i] == -1 && dfs(i)) {
run = 1;
}
}
}*/
for (int i = 0; i + 1 < n; ++i) {
if (nxt[i] == -1) {
puts("-1");
return 0;
}
}
int root;
for (int i = 0; i < n; ++i) {
if (p[i] == -1) {
root = i;
break;
}
}
p[root] = n - 1;
nxt[n - 1] = root;
for (int i = 0; i + 1 < n; ++i) {
for (int to : g[i]) {
if (to != nxt[i]) {
g2[p[to]].push_back(i);
}
}
}
memset(used, 0, sizeof(used));
dfs2(n - 1);
for (int i = 0; i < n; ++i) {
if (!used[i]) {
puts("-1");
return 0;
}
}
for (int i = 0; i + 1 < n; ++i) {
printf("%d %d\n", nxt[i] + 1, ans[i] + 1);
}
return 0;
}
| replace | 51 | 53 | 51 | 64 | TLE | |
p03205 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 201000;
int chosen[N];
namespace MF {
struct Edge {
int v, flow, ne;
} e[N << 3];
int fi[N], tot, S, T, V, cur[N], dis[N], q[N];
void Init(int s, int t, int v) {
S = s;
T = t;
V = v;
tot = 1;
for (int i = 0; i < V; i++) {
fi[i] = 0;
}
}
void Add(int x, int y, int w) {
e[++tot] = {y, w, fi[x]};
fi[x] = tot;
e[++tot] = {x, 0, fi[y]};
fi[y] = tot;
}
bool Bfs(void) {
for (int i = 0; i < V; i++) {
dis[i] = 0;
}
int h = 1, t = 0;
q[++t] = S;
dis[S] = 1;
while (h <= t) {
int x = q[h++];
for (int i = fi[x]; i; i = e[i].ne) {
if (e[i].flow && !dis[e[i].v]) {
dis[e[i].v] = dis[x] + 1;
q[++t] = e[i].v;
}
}
}
return dis[T];
}
int Dfs(int x, int f) {
if (x == T) {
return f;
}
int used = 0;
for (int &i = cur[x]; i; i = e[i].ne) {
if (e[i].flow && dis[e[i].v] == dis[x] + 1) {
int t = Dfs(e[i].v, min(f - used, e[i].flow));
used += t;
e[i].flow -= t;
e[i ^ 1].flow += t;
if (used == f) {
return used;
}
}
}
dis[x] = -1;
return used;
}
int Solve(void) {
int ans = 0;
while (Bfs()) {
for (int i = 0; i < V; i++) {
cur[i] = fi[i];
}
ans += Dfs(S, 1e9);
}
for (int i = 1; i < (V >> 1); i++) {
for (int j = fi[i]; j; j = e[j].ne) {
if (!e[j].flow) {
::chosen[i] = e[j].v - (V >> 1) + 1;
}
}
}
return ans;
}
} // namespace MF
int n, q[N], full[N];
pair<int, int> ans[N];
vector<int> in[N];
int main(void) {
scanf("%d", &n);
MF::Init(0, n << 1 ^ 3, n << 1);
for (int i = 1, k; i < n; i++) {
scanf("%d", &k);
for (int j = 0, x; j < k; j++) {
scanf("%d", &x);
x--;
if (x) {
MF::Add(i, x + n - 1, 1);
}
in[x].push_back(i);
}
}
for (int i = 1; i < n; i++) {
MF::Add(MF::S, i, 1);
MF::Add(i + n - 1, MF::T, 1);
}
if (MF::Solve() < n - 1) {
return puts("-1"), 0;
}
int h = 1, t = 0;
q[++t] = 0;
while (h <= t) {
int x = q[h++];
for (int y : in[x]) {
if (full[y]) {
continue;
}
full[y] = 1;
q[++t] = chosen[y];
ans[y] = {x, chosen[y]};
}
}
if (t < n) {
puts("-1");
} else {
for (int i = 1; i < n; i++) {
printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 201000;
int chosen[N];
namespace MF {
struct Edge {
int v, flow, ne;
} e[N << 3];
int fi[N], tot, S, T, V, cur[N], dis[N], q[N];
void Init(int s, int t, int v) {
S = s;
T = t;
V = v;
tot = 1;
for (int i = 0; i < V; i++) {
fi[i] = 0;
}
}
void Add(int x, int y, int w) {
e[++tot] = {y, w, fi[x]};
fi[x] = tot;
e[++tot] = {x, 0, fi[y]};
fi[y] = tot;
}
bool Bfs(void) {
for (int i = 0; i < V; i++) {
dis[i] = 0;
}
int h = 1, t = 0;
q[++t] = S;
dis[S] = 1;
while (h <= t) {
int x = q[h++];
for (int i = fi[x]; i; i = e[i].ne) {
if (e[i].flow && !dis[e[i].v]) {
dis[e[i].v] = dis[x] + 1;
q[++t] = e[i].v;
}
}
}
return dis[T];
}
int Dfs(int x, int f) {
if (x == T) {
return f;
}
int used = 0;
for (int &i = cur[x]; i; i = e[i].ne) {
if (e[i].flow && dis[e[i].v] == dis[x] + 1) {
int t = Dfs(e[i].v, min(f - used, e[i].flow));
used += t;
e[i].flow -= t;
e[i ^ 1].flow += t;
if (used == f) {
return used;
}
}
}
dis[x] = -1;
return used;
}
int Solve(void) {
int ans = 0;
while (Bfs()) {
for (int i = 0; i < V; i++) {
cur[i] = fi[i];
}
ans += Dfs(S, 1e9);
}
for (int i = 1; i < (V >> 1); i++) {
for (int j = fi[i]; j; j = e[j].ne) {
if (!e[j].flow) {
::chosen[i] = e[j].v - (V >> 1) + 1;
}
}
}
return ans;
}
} // namespace MF
int n, q[N], full[N];
pair<int, int> ans[N];
vector<int> in[N];
int main(void) {
scanf("%d", &n);
MF::Init(0, n * 2 - 1, n << 1);
for (int i = 1, k; i < n; i++) {
scanf("%d", &k);
for (int j = 0, x; j < k; j++) {
scanf("%d", &x);
x--;
if (x) {
MF::Add(i, x + n - 1, 1);
}
in[x].push_back(i);
}
}
for (int i = 1; i < n; i++) {
MF::Add(MF::S, i, 1);
MF::Add(i + n - 1, MF::T, 1);
}
if (MF::Solve() < n - 1) {
return puts("-1"), 0;
}
int h = 1, t = 0;
q[++t] = 0;
while (h <= t) {
int x = q[h++];
for (int y : in[x]) {
if (full[y]) {
continue;
}
full[y] = 1;
q[++t] = chosen[y];
ans[y] = {x, chosen[y]};
}
}
if (t < n) {
puts("-1");
} else {
for (int i = 1; i < n; i++) {
printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
}
}
return 0;
}
| replace | 95 | 96 | 95 | 96 | TLE | |
p03206 | Python | Runtime Error | s = int(input)
if s == 22:
print("Christmas Eve Eve Eve")
if s == 23:
print("Christmas Eve Eve")
if s == 24:
print("Christmas Eve")
if s == 25:
print("Christmas")
| s = int(input())
if s == 22:
print("Christmas Eve Eve Eve")
if s == 23:
print("Christmas Eve Eve")
if s == 24:
print("Christmas Eve")
if s == 25:
print("Christmas")
| replace | 0 | 1 | 0 | 1 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03206/Python/s541869147.py", line 1, in <module>
s = int(input)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
|
p03206 | C++ | Time Limit Exceeded | #include <stdio.h>
int main() {
int n;
while (scanf("%d", &n)) {
if (n == 25)
printf("Christmas\n");
if (n == 24)
printf("Christmas Eve\n");
if (n == 23)
printf("Christmas Eve Eve\n");
if (n == 22)
printf("Christmas Eve Eve Eve\n");
}
return 0;
} | #include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if (n == 25)
printf("Christmas\n");
if (n == 24)
printf("Christmas Eve\n");
if (n == 23)
printf("Christmas Eve Eve\n");
if (n == 22)
printf("Christmas Eve Eve Eve\n");
return 0;
} | replace | 3 | 13 | 3 | 14 | TLE | |
p03206 | C++ | Time Limit Exceeded | #include <stdio.h>
#include <stdlib.h>
int main() {
int d;
while (scanf("%d", &d)) {
if (d == 25)
printf("Christmas\n");
else if (d == 24)
printf("Christmas Eve\n");
else if (d == 23)
printf("Christmas Eve Eve\n");
else if (d == 22)
printf("Christmas Eve Eve Eve\n");
}
}
| #include <stdio.h>
#include <stdlib.h>
int main() {
int d;
scanf("%d", &d);
if (d == 25)
printf("Christmas\n");
else if (d == 24)
printf("Christmas Eve\n");
else if (d == 23)
printf("Christmas Eve Eve\n");
else if (d == 22)
printf("Christmas Eve Eve Eve\n");
}
| replace | 5 | 15 | 5 | 15 | TLE | |
p03206 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int d;
cin >> d;
string ans = "Christmas";
while (d < 25) {
ans += " Eve";
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int d;
cin >> d;
string ans = "Christmas";
while (d++ < 25) {
ans += " Eve";
}
cout << ans << endl;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p03206 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
cin >> a;
vector<string> word;
word.push_back("Christmas");
if (a == 25) {
cout << word[0];
}
if (a < 25) {
for (int i = 25; i > a; i--) {
word.push_back(" Eve");
}
for (int j = 0; j < 25; j++) {
cout << word[j];
}
}
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
cin >> a;
vector<string> word;
word.push_back("Christmas");
if (a == 25) {
cout << word[0];
}
if (a < 25) {
for (int i = 25; i > a; i--) {
word.push_back(" Eve");
}
for (int j = 0; j <= 25 - a; j++) {
cout << word[j];
}
}
} | replace | 18 | 19 | 18 | 19 | 0 | |
p03206 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
cout << "Christmas" << endl;
for (int i = 25; i != N; i++) {
cout << " "
<< "Eve" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
cout << "Christmas" << endl;
for (int i = 25; i != N; i--) {
cout << " "
<< "Eve" << endl;
}
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p03206 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int d;
cin >> d;
string a[4] = {"Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve",
"Christmas"};
cout << a[d - 23] << endl;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int d;
cin >> d;
string a[4] = {"Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve",
"Christmas"};
cout << a[d - 22] << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03206 | Python | Runtime Error | def solve():
d = int(input())
eves = 25 - d
return "Christmas" + " Eve" + eves
if __name__ == "__main__":
print(solve())
| def solve():
d = int(input())
eves = 25 - d
return "Christmas" + " Eve" * eves
if __name__ == "__main__":
print(solve())
| replace | 3 | 4 | 3 | 4 | TypeError: can only concatenate str (not "int") to str | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03206/Python/s602998179.py", line 8, in <module>
print(solve())
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03206/Python/s602998179.py", line 4, in solve
return "Christmas" + " Eve" + eves
TypeError: can only concatenate str (not "int") to str
|
p03206 | Python | Runtime Error | print(f"Christmas {' '.join(['Eve'] * (25 - int(input())))}".strip())
| print("Christmas {}".format(" ".join(["Eve"] * (25 - int(input())))).strip())
| replace | 0 | 1 | 0 | 1 | 0 | |
p03206 | Python | Runtime Error | #!/usr/bin/env python
# -*- coding: utf-8 -*-
al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49
def solve2(ans, x, idx, cnt):
if idx == 1:
return ans + (0, 0, 1, 2, 3, 3, 3)[x] + [0, 1][cnt >= 1]
if x == (al[idx] // 2) + 1:
return ans + bl[idx - 1] + 1 + [0, 1][cnt >= 1]
elif x > (al[idx] // 2) + 1:
ans += bl[idx - 1]
x -= al[idx] // 2
cnt += 1
return solve2(ans, x, idx - 1, cnt)
def solve():
n, x = map(int, input().split())
for i in range(2, n + 1):
al[i] = al[i - 1] * 2 + 3
bl[i] = bl[i - 1] * 2 + 1
ans = solve2(0, x, n, 0)
print(ans)
if __name__ == "__main__":
solve()
| print("Christmas" + (" Eve" * (25 - int(input()))))
| replace | 0 | 30 | 0 | 1 | ValueError: not enough values to unpack (expected 2, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03206/Python/s885341771.py", line 30, in <module>
solve()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03206/Python/s885341771.py", line 21, in solve
n, x = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)
|
p03206 | Python | Runtime Error | D = int(input)
print("Christmas" + " Eve" * (25 - D))
| D = int(input())
print("Christmas" + " Eve" * (25 - D))
| replace | 0 | 1 | 0 | 1 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03206/Python/s854854149.py", line 1, in <module>
D = int(input)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'
|
p03207 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
int N;
int A = 0;
vector<int> p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
A += p[i];
}
sort(p.begin(), p.end()); // {1, 2, 2, 5}
reverse(p.begin(), p.end());
cout << A - p[0] / 2 << endl;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
int N;
cin >> N;
int A = 0;
vector<int> p(N);
for (int i = 0; i < N; i++) {
cin >> p[i];
A += p[i];
}
sort(p.begin(), p.end()); // {1, 2, 2, 5}
reverse(p.begin(), p.end());
cout << A - p[0] / 2 << endl;
} | insert | 38 | 38 | 38 | 39 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03207 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;
int main() {
int n;
cin >> n;
vector<int> p;
rep(i, n) cin >> p[i];
sort(p.begin(), p.end(), greater<int>());
p[0] /= 2;
int price = 0;
rep(i, n) price += p[i];
cout << price << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;
int main() {
int n;
cin >> n;
vector<int> p(n);
rep(i, n) cin >> p[i];
sort(p.begin(), p.end(), greater<int>());
p[0] /= 2;
int price = 0;
rep(i, n) price += p[i];
cout << price << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | -11 | |
p03207 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a, t) for (int a = 0; a < t; ++a)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define print_double(val, a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
vector<int> a(n);
rep(i, n) { cin >> a[i]; }
Sort(a);
int sum = 0;
rep(i, n) { sum += a[i]; }
sum -= a[n - 1] / 2;
cout << sum << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a, t) for (int a = 0; a < t; ++a)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define print_double(val, a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i, n) { cin >> a[i]; }
Sort(a);
int sum = 0;
rep(i, n) { sum += a[i]; }
sum -= a[n - 1] / 2;
cout << sum << endl;
return 0;
}
| insert | 39 | 39 | 39 | 40 | 0 | |
p03207 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
// cant wait for holiday
// string days[7] ={"SUN","MON","TUE","WED","THU","FRI","SAT"};
// string s;
// int n;
// cin>> s;
// for (int i = 0; i< 7; i++){
// if (s== days[i]){
// n = i;
// }
// }
// n = 7-n;
// cout<< n;
// day before christmas eve
int a, b;
int n;
cin >> n;
int prices[n];
for (int i = 0; i < n; i++) {
cin >> prices[i];
}
for (int i = 0; i < n; i++) {
// find the greatest number and the index
if (prices[i] >= a) {
a = prices[i];
b = i;
}
}
// b is index, a is value
a = 0; // a will now be the sum
prices[b] /= 2;
for (int i = 0; i < n; i++) {
a += prices[i];
}
cout << a;
return 0;
} | #include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
// cant wait for holiday
// string days[7] ={"SUN","MON","TUE","WED","THU","FRI","SAT"};
// string s;
// int n;
// cin>> s;
// for (int i = 0; i< 7; i++){
// if (s== days[i]){
// n = i;
// }
// }
// n = 7-n;
// cout<< n;
// day before christmas eve
int a = 0, b;
int n;
cin >> n;
int prices[n];
for (int i = 0; i < n; i++) {
cin >> prices[i];
}
for (int i = 0; i < n; i++) {
// find the greatest number and the index
if (prices[i] >= a) {
a = prices[i];
b = i;
}
}
// b is index, a is value
a = 0; // a will now be the sum
prices[b] /= 2;
for (int i = 0; i < n; i++) {
a += prices[i];
}
cout << a;
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03207 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#include <string>
using namespace std;
typedef long long ll;
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; }
int main() {
int n;
cin >> n;
vector<int> p(n);
rep(i, n) { cin >> p[i]; }
sort(p.begin(), p.end(), greater<int>());
int ans = 0;
rep(i, n) {
if (i = 0)
ans += p[i] / 2;
else
ans += p[i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#include <string>
using namespace std;
typedef long long ll;
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; }
int main() {
int n;
cin >> n;
vector<int> p(n);
rep(i, n) { cin >> p[i]; }
sort(p.begin(), p.end(), greater<int>());
int ans = -p[0] / 2;
rep(i, n) { ans += p[i]; }
cout << ans << endl;
return 0;
} | replace | 14 | 21 | 14 | 16 | TLE | |
p03207 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(n);
}
sort(vec.begin(), vec.end());
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum = sum + vec.at(i);
}
sum = sum + vec.at(n - 1) / 2;
cout << sum << endl;
} | #include <bits/stdc++.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum = sum + vec.at(i);
}
sum = sum + vec.at(n - 1) / 2;
cout << sum << endl;
}
| replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p03207 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;
const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
int main() {
int n;
cin >> n;
vector<int> p;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p.begin(), p.end());
int sum = 0;
for (int i = 0; i < n; i++) {
sum += p[i];
}
sum -= p[n - 1] / 2;
cout << sum << endl;
}
| #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;
const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
int main() {
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
sort(p.begin(), p.end());
int sum = 0;
for (int i = 0; i < n; i++) {
sum += p[i];
}
sum -= p[n - 1] / 2;
cout << sum << endl;
}
| replace | 28 | 29 | 28 | 29 | -11 | |
p03207 | Python | Runtime Error | N = int(input())
p = [int(input()) for _ in N]
print(sum(p) - max(p) // 2)
| N = int(input())
p = [int(input()) for _ in range(N)]
print(sum(p) - max(p) // 2)
| replace | 1 | 2 | 1 | 2 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03207/Python/s805819022.py", line 2, in <module>
p = [int(input()) for _ in N]
TypeError: 'int' object is not iterable
|
p03207 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
// mp::cpp_int
int solve() {
int n;
vi a(n);
rep(i, 0, n) cin >> a[i];
sort(all(a));
int sum = 0;
rep(i, 0, n) sum += a[i];
cout << sum - a[n - 1] + a[n - 1] / 2;
return 0;
}
int main() {
int t = 1;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t time_req;
// Without using pow function
time_req = clock();
// cin>>t;
while (t--) {
solve();
}
time_req = clock() - time_req;
// cout << "Processor time taken is "
// << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
| #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
// mp::cpp_int
int solve() {
int n;
cin >> n;
vi a(n);
rep(i, 0, n) cin >> a[i];
sort(all(a));
int sum = 0;
rep(i, 0, n) sum += a[i];
cout << sum - a[n - 1] + a[n - 1] / 2;
return 0;
}
int main() {
int t = 1;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t time_req;
// Without using pow function
time_req = clock();
// cin>>t;
while (t--) {
solve();
}
time_req = clock() - time_req;
// cout << "Processor time taken is "
// << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
| insert | 58 | 58 | 58 | 59 | -11 | |
p03207 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> value;
for (int i = 0; i < n; i++) {
cin >> value[i];
}
int max = 0;
for (int i = 0; i < n; i++) {
if (max < value[i])
max = value[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + value[i];
}
cout << sum - max / 2 << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> value(10, 0);
for (int i = 0; i < n; i++) {
cin >> value[i];
}
int max = 0;
for (int i = 0; i < n; i++) {
if (max < value[i])
max = value[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + value[i];
}
cout << sum - max / 2 << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p03207 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for ((i) = 0; (i) < (n); ++(i))
#define repr(i, n) for ((i) = (n); (i) > 0; == (i))
#define FOR(i, j, n) for ((i) = (j); (i) < (n); ++(i))
#define forr(i, j, n) for ((i) = (j); (i) > (n); --(i))
#define debg(a) cout << (a) << endl;
#define INF 9999999
#define Int long long
int i, j, k;
int dx, dy;
int a, b, c;
string s, t;
int main() {
int n;
cin >> n;
int p[i];
rep(i, n) cin >> p[i];
int max = 100;
rep(i, n) if (p[i] > max) max = p[i];
int ttl = 0;
rep(i, n) ttl += p[i];
ttl -= max;
ttl += max / 2;
cout << ttl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for ((i) = 0; (i) < (n); ++(i))
#define repr(i, n) for ((i) = (n); (i) > 0; == (i))
#define FOR(i, j, n) for ((i) = (j); (i) < (n); ++(i))
#define forr(i, j, n) for ((i) = (j); (i) > (n); --(i))
#define debg(a) cout << (a) << endl;
#define INF 9999999
#define Int long long
int i, j, k;
int dx, dy;
int a, b, c;
string s, t;
int main() {
int n;
cin >> n;
int p[n];
rep(i, n) cin >> p[i];
int max = 100;
rep(i, n) if (p[i] > max) max = p[i];
int ttl = 0;
rep(i, n) ttl += p[i];
ttl -= max;
ttl += max / 2;
cout << ttl;
return 0;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p03207 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long Int;
int main() {
priority_queue<int> pque;
int n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
pque.push(a);
}
int ans = pque.top();
pque.pop();
ans /= 2;
while (!pque.empty()) {
ans += pque.top();
pque.pop();
}
cout << ans << endl;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long Int;
int main() {
priority_queue<int> pque;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
pque.push(a);
}
int ans = pque.top();
pque.pop();
ans /= 2;
while (!pque.empty()) {
ans += pque.top();
pque.pop();
}
cout << ans << endl;
}
| insert | 10 | 10 | 10 | 11 | 0 | |
p03207 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int main() {
int n;
vector<int> a(n);
for (auto &i : a)
cin >> i;
sort(a.begin(), a.end());
Int s = a.back();
s /= 2;
a.pop_back();
a.push_back(s);
Int ans = 0;
for (auto &i : a)
ans += i;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int main() {
int n;
cin >> n;
int a[n];
rep(i, n) cin >> a[i];
sort(a, a + n);
int ans = 0;
rep(i, n - 1) ans += a[i];
cout << ans + (a[n - 1] / 2) << endl;
}
| replace | 13 | 25 | 13 | 20 | -11 | |
p03207 | Python | Runtime Error | N = input()
p = [int(input()) for i in range(N)]
print(sum(p) - max(p) // 2)
| N = int(input())
p = [int(input()) for i in range(N)]
print(sum(p) - max(p) // 2)
| replace | 0 | 1 | 0 | 1 | TypeError: 'str' object cannot be interpreted as an integer | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03207/Python/s736160846.py", line 2, in <module>
p = [int(input()) for i in range(N)]
TypeError: 'str' object cannot be interpreted as an integer
|
p03207 | C++ | Runtime Error | /* mytemplate.cpp {{{ */
/* header */
#include <bits/stdc++.h>
using namespace std;
/* rep */
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (ll)(n); i += (s))
#define per(...) GET_MACRO(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)
#define per1(a) per2(_, a)
#define per2(i, a) per3(i, a, 0)
#define per3(i, a, n) per4(i, a, n, 1)
#define per4(i, a, n, s) for (ll i = (a)-1; i >= (ll)(n); i -= (s))
#define each(x, c) for (auto &&x : c)
/* short */
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define len(c) ((ll)(c).size())
#define temp_T template <typename T>
#define temp_TU template <typename T, typename U>
/* debug */
#define debug(x) \
{ cerr << #x << " = " << (x) << "\n"; }
/* alias */
temp_T using vec = vector<T>;
temp_T using heap = priority_queue<T>;
temp_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using ll = long long;
using str = string;
using vi = vec<ll>;
using vvi = vec<vi>;
using vs = vec<str>;
using vb = vec<bool>;
using pii = pair<ll, ll>;
using vp = vec<pii>;
/* const */
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
/* function */
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
bool isPrime(ll n) {
if (n < 2)
return false;
rep(i, 2, (sqrt(n) + 1)) {
if (n % i == 0)
return false;
}
return true;
}
void eratosthenes(vb &primes) {
rep(i, len(primes)) primes[i] = true;
primes[0] = primes[1] = false;
rep(i, len(primes) / 2 + 1) {
if (primes[i]) {
rep(j, i + i, len(primes), i) primes[j] = false;
}
}
}
inline ll minMultiple(ll a, ll n) { return n * (a / n + (a % n == 0 ? 0 : 1)); }
vi listDivisors(ll n) {
vi divs;
rep(i, 1, sqrt(n) + 1) {
if (n % i == 0) {
divs.pb(i);
divs.pb(n / i);
}
}
sort(all(divs));
return divs;
}
map<ll, ll> primeFactorize(ll n) {
map<ll, ll> prime_factors;
ll m = n;
rep(i, 2, sqrt(n) + 1) {
if (m < 1)
break;
while (m % i == 0) {
++prime_factors[i];
m /= i;
}
}
if (m != 1)
++prime_factors[m];
return prime_factors;
}
inline ll mod_add(ll a, ll b) { return (a + b) % MOD; }
inline ll mod_sub(ll a, ll b) { return (a + MOD - b) % MOD; }
inline ll mod_mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll mod_pow(ll x, ll y) {
if (y == 0)
return 1;
else if (y == 1)
return x % MOD;
else if (y % 2 == 0) {
ll val = mod_pow(x, (ll)(y / 2));
return mod_mul(val, val);
} else {
ll val = mod_pow(x, (ll)(y / 2));
return mod_mul(mod_mul(val, val), x);
}
}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }
ll mod_div(ll a, ll b) { return mod_mul(a, mod_inv(b)); }
ll fact(ll n) { return n == 0 ? 1 : mod_mul(n, fact(n - 1)); }
ll comb(ll n, ll r) { return fact(n) / fact(n - r) / fact(r); }
temp_T inline bool chmax(T &a, const T b) {
if (a < b)
a = b;
return a < b;
}
temp_T inline bool chmin(T &a, const T b) {
if (a > b)
a = b;
return a > b;
}
template <typename T = ll> inline T in() {
T x;
cin >> x;
return x;
}
temp_T inline void print(const T &x) { cout << x << "\n"; }
temp_T inline void print(const vector<T> &v) {
rep(i, len(v)) cout << v[i] << (i != len(v) - 1 ? " " : "\n");
}
temp_T inline void print(const vector<vector<T>> &vv) {
rep(j, len(vv)) print(vv[j]);
}
temp_TU inline void print(const pair<T, U> &p) {
cout << p.fi << " " << p.se << "\n";
}
temp_TU inline void print(const vector<pair<T, U>> &vp) {
rep(i, len(vp)) print(vp[i]);
}
temp_TU inline void print(const map<T, U> &d) { each(x, d) print(x); }
/* init */
struct Init {
Init() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} init;
/* }}} */
//-----------------------------------------------------------------------------
int main() {
ll N = in();
vi P;
rep(i, N) P[i] = in();
print(accumulate(all(P), 0) - *max_element(all(P)) / 2);
}
| /* mytemplate.cpp {{{ */
/* header */
#include <bits/stdc++.h>
using namespace std;
/* rep */
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (ll)(n); i += (s))
#define per(...) GET_MACRO(__VA_ARGS__, per4, per3, per2, per1)(__VA_ARGS__)
#define per1(a) per2(_, a)
#define per2(i, a) per3(i, a, 0)
#define per3(i, a, n) per4(i, a, n, 1)
#define per4(i, a, n, s) for (ll i = (a)-1; i >= (ll)(n); i -= (s))
#define each(x, c) for (auto &&x : c)
/* short */
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define len(c) ((ll)(c).size())
#define temp_T template <typename T>
#define temp_TU template <typename T, typename U>
/* debug */
#define debug(x) \
{ cerr << #x << " = " << (x) << "\n"; }
/* alias */
temp_T using vec = vector<T>;
temp_T using heap = priority_queue<T>;
temp_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using ll = long long;
using str = string;
using vi = vec<ll>;
using vvi = vec<vi>;
using vs = vec<str>;
using vb = vec<bool>;
using pii = pair<ll, ll>;
using vp = vec<pii>;
/* const */
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
/* function */
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
bool isPrime(ll n) {
if (n < 2)
return false;
rep(i, 2, (sqrt(n) + 1)) {
if (n % i == 0)
return false;
}
return true;
}
void eratosthenes(vb &primes) {
rep(i, len(primes)) primes[i] = true;
primes[0] = primes[1] = false;
rep(i, len(primes) / 2 + 1) {
if (primes[i]) {
rep(j, i + i, len(primes), i) primes[j] = false;
}
}
}
inline ll minMultiple(ll a, ll n) { return n * (a / n + (a % n == 0 ? 0 : 1)); }
vi listDivisors(ll n) {
vi divs;
rep(i, 1, sqrt(n) + 1) {
if (n % i == 0) {
divs.pb(i);
divs.pb(n / i);
}
}
sort(all(divs));
return divs;
}
map<ll, ll> primeFactorize(ll n) {
map<ll, ll> prime_factors;
ll m = n;
rep(i, 2, sqrt(n) + 1) {
if (m < 1)
break;
while (m % i == 0) {
++prime_factors[i];
m /= i;
}
}
if (m != 1)
++prime_factors[m];
return prime_factors;
}
inline ll mod_add(ll a, ll b) { return (a + b) % MOD; }
inline ll mod_sub(ll a, ll b) { return (a + MOD - b) % MOD; }
inline ll mod_mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll mod_pow(ll x, ll y) {
if (y == 0)
return 1;
else if (y == 1)
return x % MOD;
else if (y % 2 == 0) {
ll val = mod_pow(x, (ll)(y / 2));
return mod_mul(val, val);
} else {
ll val = mod_pow(x, (ll)(y / 2));
return mod_mul(mod_mul(val, val), x);
}
}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }
ll mod_div(ll a, ll b) { return mod_mul(a, mod_inv(b)); }
ll fact(ll n) { return n == 0 ? 1 : mod_mul(n, fact(n - 1)); }
ll comb(ll n, ll r) { return fact(n) / fact(n - r) / fact(r); }
temp_T inline bool chmax(T &a, const T b) {
if (a < b)
a = b;
return a < b;
}
temp_T inline bool chmin(T &a, const T b) {
if (a > b)
a = b;
return a > b;
}
template <typename T = ll> inline T in() {
T x;
cin >> x;
return x;
}
temp_T inline void print(const T &x) { cout << x << "\n"; }
temp_T inline void print(const vector<T> &v) {
rep(i, len(v)) cout << v[i] << (i != len(v) - 1 ? " " : "\n");
}
temp_T inline void print(const vector<vector<T>> &vv) {
rep(j, len(vv)) print(vv[j]);
}
temp_TU inline void print(const pair<T, U> &p) {
cout << p.fi << " " << p.se << "\n";
}
temp_TU inline void print(const vector<pair<T, U>> &vp) {
rep(i, len(vp)) print(vp[i]);
}
temp_TU inline void print(const map<T, U> &d) { each(x, d) print(x); }
/* init */
struct Init {
Init() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} init;
/* }}} */
//-----------------------------------------------------------------------------
int main() {
ll N = in();
vi P(N);
rep(i, N) P[i] = in();
print(accumulate(all(P), 0) - *max_element(all(P)) / 2);
} | replace | 168 | 169 | 168 | 169 | -11 | |
p03207 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
cin >> p.at(i);
}
sort(p.begin(), p.end());
reverse(p.begin(), p.end());
p.at(0) /= 2;
int sum = 0;
for (int i = 0; i < N; i++) {
sum += p.at(i);
}
cout << sum;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
cin >> p.at(i);
}
sort(p.begin(), p.end());
reverse(p.begin(), p.end());
p.at(0) /= 2;
int sum = 0;
for (int i = 0; i < N; i++) {
sum += p.at(i);
}
cout << sum;
}
| insert | 5 | 5 | 5 | 6 | 0 | |
p03207 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> K;
for (int i = 0; i < N; i++) {
cin >> K.at(i);
}
sort(K.begin(), K.end());
K.at(N - 1) /= 2;
int H = 0;
for (int i = 0; i < N; i++) {
H += K.at(i);
}
cout << H << endl;
}
| #include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> K(N);
for (int i = 0; i < N; i++) {
cin >> K.at(i);
}
sort(K.begin(), K.end());
K.at(N - 1) /= 2;
int H = 0;
for (int i = 0; i < N; i++) {
H += K.at(i);
}
cout << H << endl;
}
| replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p03207 | C++ | Runtime Error | // AUTHOR:BlackBox Inc.//
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int, int>>
#define vs vector<string>
#define lin1(x) \
ll int x; \
x = scan();
#define lin2(x, y) \
ll int x, y; \
x = scan(), y = scan();
#define lin3(x, y, z) \
ll int x, y, z; \
x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x, y) make_pair(x, y)
#define mx(a, b) (a) > (b) ? (a) : (b)
#define mn(a, b) (a) < (b) ? (a) : (b)
#define fori(s, e) for (i = s; i <= e; i++)
#define forj(s, e) for (j = s; j <= e; j++)
#define fork(s, e) for (k = s; k <= e; k++)
#define rep(i, s, e) for (int i = s; i <= e; i++)
#define brep(i, s, e) for (int i = s; i >= e; i--)
#define all(x) x.begin(), x.end()
#define mem(x, y) memset(x, y, sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin >>
#define co cout <<
#define fast \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
using namespace std::tr1;
int main() {
#ifndef RAHUL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
long long x;
cin >> x;
std::vector<int> v(x);
for (int i = 0; i < x; ++i) {
/* code */
cin >> v[i];
}
sort(v.begin(), v.end());
int raj = v[x - 1] / 2;
int sum = 0;
for (int i = 0; i < x - 1; ++i) {
/* code */
sum += v[i];
}
cout << sum + raj << endl;
return 0;
}
| // AUTHOR:BlackBox Inc.//
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int, int>>
#define vs vector<string>
#define lin1(x) \
ll int x; \
x = scan();
#define lin2(x, y) \
ll int x, y; \
x = scan(), y = scan();
#define lin3(x, y, z) \
ll int x, y, z; \
x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x, y) make_pair(x, y)
#define mx(a, b) (a) > (b) ? (a) : (b)
#define mn(a, b) (a) < (b) ? (a) : (b)
#define fori(s, e) for (i = s; i <= e; i++)
#define forj(s, e) for (j = s; j <= e; j++)
#define fork(s, e) for (k = s; k <= e; k++)
#define rep(i, s, e) for (int i = s; i <= e; i++)
#define brep(i, s, e) for (int i = s; i >= e; i--)
#define all(x) x.begin(), x.end()
#define mem(x, y) memset(x, y, sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin >>
#define co cout <<
#define fast \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
using namespace std::tr1;
int main() {
long long x;
cin >> x;
std::vector<int> v(x);
for (int i = 0; i < x; ++i) {
/* code */
cin >> v[i];
}
sort(v.begin(), v.end());
int raj = v[x - 1] / 2;
int sum = 0;
for (int i = 0; i < x - 1; ++i) {
/* code */
sum += v[i];
}
cout << sum + raj << endl;
return 0;
}
| delete | 46 | 50 | 46 | 46 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03208 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define loop(i, N, M) for (int i = N; i < M; i++)
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define SORTL2S(type, v) sort(v.begin(), v.end(), greater<type>())
#define SORTS2L(type, v) sort(v.begin(), v.end())
#define SORTMF(v, func) sort(v.begin(), v.end(), func)
// 変数
ll N, K;
vector<ll> vec;
// 解法
void solve() {
SORTS2L(ll, vec);
ll ans = vec[N - 1] - vec[0];
for (ll i = 0; i <= N - K; ++i) {
ll maxx = *max_element(vec.begin() + i, vec.begin() + i + K);
ll minn = *min_element(vec.begin() + i, vec.begin() + i + K);
ans = min(ans, maxx - minn);
}
cout << ans;
return;
}
int main() {
// 入力
cin >> N >> K;
vec.resize(N);
rep(i, N) cin >> vec[i];
solve();
cout << endl;
return 0;
} |
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define loop(i, N, M) for (int i = N; i < M; i++)
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define SORTL2S(type, v) sort(v.begin(), v.end(), greater<type>())
#define SORTS2L(type, v) sort(v.begin(), v.end())
#define SORTMF(v, func) sort(v.begin(), v.end(), func)
// 変数
ll N, K;
vector<ll> vec;
// 解法
void solve() {
SORTS2L(ll, vec);
ll ans = vec[N - 1] - vec[0];
for (ll i = 0; i <= N - K; ++i) {
ans = min(ans, vec[i + K - 1] - vec[i]);
}
cout << ans;
return;
}
int main() {
// 入力
cin >> N >> K;
vec.resize(N);
rep(i, N) cin >> vec[i];
solve();
cout << endl;
return 0;
} | replace | 37 | 40 | 37 | 38 | TLE | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<long long> h;
long long l;
for (int i = 0; i < n; i++) {
cin >> l;
h.push_back(l);
}
sort(h.begin(), h.end());
long long ans = 1000000001;
for (int i = 0; i < k; i++) {
ans = min(ans, h[k - 1 + i] - h[i]);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<long long> h;
long long l;
for (int i = 0; i < n; i++) {
cin >> l;
h.push_back(l);
}
sort(h.begin(), h.end());
long long ans = 1000000001;
for (int i = 0; i <= n - k; i++) {
ans = min(ans, h[k - 1 + i] - h[i]);
}
cout << ans << endl;
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mkp make_pair
#define pb push_back
#define inf INT_MAX
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
IOS int n, k;
cin >> n >> k;
// max-min of k-th size window in the sorted array!
std::vector<int> v(n, 0);
for (int i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end());
int ans = v[k - 1] - v[0];
for (int i = k; i < n; i++) {
int diff = v[i] - v[i - k + 1];
ans = min(ans, diff);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define mkp make_pair
#define pb push_back
#define inf INT_MAX
int32_t main() {
IOS int n, k;
cin >> n >> k;
// max-min of k-th size window in the sorted array!
std::vector<int> v(n, 0);
for (int i = 0; i < n; i++)
cin >> v[i];
sort(v.begin(), v.end());
int ans = v[k - 1] - v[0];
for (int i = k; i < n; i++) {
int diff = v[i] - v[i - k + 1];
ans = min(ans, diff);
}
cout << ans;
return 0;
}
| delete | 17 | 21 | 17 | 17 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 15;
int n, k, a[N], ans;
int main() {
ios::sync_with_stdio(false);
ans = 0x3f3f3f3f;
cin >> n >> k;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n - k + 1; ++i)
ans = min(ans, a[i + k - 1] - a[i]);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, a[N], ans;
int main() {
ios::sync_with_stdio(false);
ans = 0x3f3f3f3f;
cin >> n >> k;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n - k + 1; ++i)
ans = min(ans, a[i + k - 1] - a[i]);
cout << ans << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03208 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> h(n);
for (auto &&e : h)
cin >> e;
sort(h.begin(), h.end());
vector<int> c(n - (k - 1));
for (int i = 0; i + k <= n; ++i) {
for (int j = 1; j < k; ++j) {
c[i] += h[i + j] - h[i + j - 1];
}
}
sort(c.begin(), c.end());
cout << c[0] << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> h(n);
for (auto &&e : h)
cin >> e;
sort(h.begin(), h.end());
vector<int> c(n - (k - 1));
for (int i = 0; i + k <= n; ++i)
c[i] = h[i + (k - 1)] - h[i];
sort(c.begin(), c.end());
cout << c[0] << endl;
} | replace | 18 | 23 | 18 | 20 | TLE | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define ll long long
#define ii pair<string, int> ii;
string IntToStr(int tmp) {
ostringstream out;
out << tmp;
return out.str();
}
int main() {
int n, k;
cin >> n >> k;
vector<ll> v;
while (n--) {
ll x;
cin >> x;
v.pb(x);
}
sort(v.begin(), v.end());
int len = v.size();
ll min = 100000000000000;
for (int i = 0; i < len; i++) {
ll kk = abs(v[i] - v[i + k - 1]);
if (min > kk)
min = kk;
}
cout << min << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define ll long long
#define ii pair<string, int> ii;
string IntToStr(int tmp) {
ostringstream out;
out << tmp;
return out.str();
}
int main() {
int n, k;
cin >> n >> k;
vector<ll> v;
while (n--) {
ll x;
cin >> x;
v.pb(x);
}
sort(v.begin(), v.end());
int len = v.size();
ll min = 100000000000000;
for (int i = 0; i < len - k + 1; i++) {
ll kk = abs(v[i] - v[i + k - 1]);
if (min > kk)
min = kk;
}
cout << min << endl;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p03208 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
const int max_n = 1e6;
ll h[max_n];
void solve() {
ll mi = 1e10;
for (int i = 0; i < n; i++) {
ll mmi = 1e10;
ll mma = -1;
for (int j = i; j < i + k; j++) {
mmi = min(mmi, h[j]);
mma = max(mma, h[j]);
}
mi = min(mi, mma - mmi);
}
cout << mi << endl;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
sort(h, h + n);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
const int max_n = 1e6;
ll h[max_n];
void solve() {
ll mi = 1e10;
for (int i = 0; i <= n - k; i++) {
ll mma = h[i + k - 1];
ll mmi = h[i];
mi = min(mi, mma - mmi);
}
cout << mi << endl;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
sort(h, h + n);
solve();
return 0;
}
| replace | 8 | 15 | 8 | 11 | TLE | |
p03208 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void) {
int N, K;
cin >> N >> K;
vector<lli> h;
lli x;
for (int i = 0; i < N; i++) {
cin >> x;
h.push_back(x);
}
vector<lli> hcopy;
hcopy = h;
sort(h.begin(), h.end());
sort(hcopy.begin(), hcopy.end());
hcopy.erase(unique(hcopy.begin(), hcopy.end()), hcopy.end());
if (hcopy.size() == N - K) {
cout << "0" << endl;
return 0;
} else {
lli minx = h[K - 1] - h[0];
vector<lli> hd;
for (int i = 0; i < N - K + 1; i++) {
for (int j = i; j <= i + K - 1; j++) {
hd.push_back(h[j]);
}
minx = min(hd[hd.size() - 1] - hd[0], minx);
hd.erase(hd.begin(), hd.end());
}
cout << minx << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void) {
int N, K;
cin >> N >> K;
vector<lli> h;
lli x;
for (int i = 0; i < N; i++) {
cin >> x;
h.push_back(x);
}
vector<lli> hcopy;
hcopy = h;
sort(h.begin(), h.end());
sort(hcopy.begin(), hcopy.end());
hcopy.erase(unique(hcopy.begin(), hcopy.end()), hcopy.end());
if (hcopy.size() == N - K) {
cout << "0" << endl;
return 0;
} else {
lli minx = h[K - 1] - h[0];
vector<lli> hd;
for (int i = 0; i < N - K + 1; i++) {
/*for (int j = i; j <= i + K - 1; j++)
{
hd.push_back(h[j]);
}*/
lli max = h[i + K - 1];
lli tmp = h[i];
minx = min(max - tmp, minx);
// hd.erase(hd.begin(), hd.end());
}
cout << minx << endl;
}
return 0;
} | replace | 31 | 36 | 31 | 39 | TLE | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a[10000], ans = 2000000000;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n - k + 1; i++) {
ans = min(ans, a[i + k - 1] - a[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a[100000], ans = 2000000000;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n - k + 1; i++) {
ans = min(ans, a[i + k - 1] - a[i]);
}
cout << ans << endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second
typedef long long ll;
using namespace std;
const int N = 1e5;
int a[N + 5];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, ans = INT_MAX;
cin >> n >> k;
k--;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
ans = min(ans, arr[i + k] - arr[i]);
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second
typedef long long ll;
using namespace std;
const int N = 1e5;
int a[N + 5];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, ans = INT_MAX;
cin >> n >> k;
k--;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
sort(arr, arr + n);
for (int i = 0; i < n - k; i++) {
ans = min(ans, arr[i + k] - arr[i]);
}
cout << ans;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03208 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long inf = numeric_limits<long long>::max();
int main() {
int n, k;
cin >> n >> k;
vector<int> seq(n);
rep(i, n) { cin >> seq[i]; }
sort(seq.begin(), seq.end());
int ans = 100000;
rep(i, n - k + 1) { ans = min(ans, abs(seq[i] - seq[i + 2])); }
cout << ans << endl;
return 0;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long inf = numeric_limits<long long>::max();
int main() {
int n, k;
cin >> n >> k;
vector<int> seq(n);
rep(i, n) { cin >> seq[i]; }
sort(seq.begin(), seq.end());
long long ans = inf;
rep(i, n - k + 1) { ans = min(ans, (long long)abs(seq[i] - seq[i + k - 1])); }
cout << ans << endl;
return 0;
} | replace | 19 | 21 | 19 | 21 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int N, K;
ll h[100000];
void _main() {
cin >> N >> K;
rep(i, 0, N) cin >> h[i];
sort(h, h + N);
ll ans = infl;
for (int a = 0, b = K - 1; a < K; a++, b++)
chmin(ans, h[b] - h[a]);
cout << ans << "\n";
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int N, K;
ll h[100000];
void _main() {
cin >> N >> K;
rep(i, 0, N) cin >> h[i];
sort(h, h + N);
ll ans = infl;
rep(i, 0, N - K + 1) chmin(ans, h[i + K - 1] - h[i]);
cout << ans << "\n";
} | replace | 40 | 42 | 40 | 41 | 0 | |
p03208 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
typedef long long ll;
typedef pair<int, int> pii;
int ans = 0;
vector<int> ps = {3, 5, 7};
ll N;
void dfs(ll n, ll b) {
if (n <= N && b == 7) {
ans++;
}
if (n > N) {
return;
}
rep(i, ps.size()) {
ll nb = b | (1 << i);
ll nn = 10 * n + 1L * ps[i];
dfs(nn, nb);
}
return;
}
int main() {
int N, K;
cin >> N >> K;
vector<int> hs(N);
rep(i, N) { cin >> hs[i]; }
sort(hs.begin(), hs.end());
int ans = 1e9;
for (int i = 0; i < N; i++) {
for (int j = i + K - 1; j < N; j++) {
int tmp = hs[j] - hs[i];
ans = min(tmp, ans);
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
typedef long long ll;
typedef pair<int, int> pii;
int ans = 0;
vector<int> ps = {3, 5, 7};
ll N;
void dfs(ll n, ll b) {
if (n <= N && b == 7) {
ans++;
}
if (n > N) {
return;
}
rep(i, ps.size()) {
ll nb = b | (1 << i);
ll nn = 10 * n + 1L * ps[i];
dfs(nn, nb);
}
return;
}
int main() {
int N, K;
cin >> N >> K;
vector<int> hs(N);
rep(i, N) { cin >> hs[i]; }
sort(hs.begin(), hs.end());
int ans = 1e9;
for (int i = 0; i + K - 1 < N; i++) {
int tmp = hs[i + K - 1] - hs[i];
ans = min(tmp, ans);
}
cout << ans << endl;
return 0;
}
| replace | 41 | 46 | 41 | 44 | TLE | |
p03208 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << endl;
int main() {
int N, K;
CIN(N >> K);
int h[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h, h + N);
int result = INT_MAX;
for (int i = 0; i < N; i++) {
int maxV = 0;
int minV = INT_MAX;
if (N < i + K) {
// COUT("break " << i << " " << K)
break;
}
for (int j = i; j < i + K; j++) {
maxV = max(maxV, h[j]);
minV = min(minV, h[j]);
// COUT("h[j]" << h[j] << "max " << maxV << " minv " << minV);
}
result = min(result, maxV - minV);
}
COUT(result);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << endl;
int main() {
int N, K;
CIN(N >> K);
int h[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h, h + N);
int result = INT_MAX;
for (int i = 0; i < N; i++) {
int maxV = 0;
int minV = INT_MAX;
if (N < i + K) {
// COUT("break " << i << " " << K)
break;
}
result = min(result, h[i + K - 1] - h[i]);
}
COUT(result);
return 0;
}
| replace | 39 | 45 | 39 | 40 | TLE | |
p03208 | C++ | Runtime Error |
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <algorithm>
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
int main() {
int i, j;
int N, K;
long long diff = 9223372036854775807;
long long temp;
cin >> N >> K;
vector<long long> H(N);
for (i = 0; i < N; i++) {
cin >> H.at(i);
}
/* 数値を降順にソート */
sort(H.begin(), H.end(), greater<long long>());
for (i = 0; i < N + K - 1; i++) {
temp = H.at(i) - H.at(i + K - 1);
if (temp < diff) {
diff = temp;
}
}
cout << diff << endl;
return 0;
} |
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <algorithm>
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
int main() {
int i, j;
int N, K;
long long diff = 9223372036854775807;
long long temp;
cin >> N >> K;
vector<long long> H(N);
for (i = 0; i < N; i++) {
cin >> H.at(i);
}
/* 数値を降順にソート */
sort(H.begin(), H.end(), greater<long long>());
for (i = 0; i < N - K + 1; i++) {
temp = H.at(i) - H.at(i + K - 1);
if (temp < diff) {
diff = temp;
}
}
cout << diff << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
|
p03208 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int K, N;
vector<ll> min_list;
int main() {
scanf("%d%d", &N, &K);
ll h[N];
rep(i, N) { scanf("%lld", &h[i]); }
sort(h, h + N);
for (int i = 0; i < N - K + 1; i++) {
vector<ll> temp;
rep(j, K) temp.push_back(h[i + j]);
ll min = temp.front();
ll max = temp.back();
min_list.push_back(max - min);
}
ll min = *min_element(min_list.begin(), min_list.end());
printf("%lld\n", min);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int K, N;
vector<ll> min_list;
int main() {
scanf("%d%d", &N, &K);
ll h[N];
rep(i, N) { scanf("%lld", &h[i]); }
sort(h, h + N);
for (int i = 0; i < N - K + 1; i++) {
ll min = h[i];
ll max = h[i + K - 1];
min_list.push_back(max - min);
}
ll min = *min_element(min_list.begin(), min_list.end());
printf("%lld\n", min);
return 0;
} | replace | 17 | 22 | 17 | 19 | TLE | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h.begin(), h.end());
vector<int> j(N - K + 1);
for (int i = 0; i < N - K + 1; i++) {
j[i] = j[i + K - 1] - j[i];
}
sort(j.begin(), j.end());
cout << j[0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h.begin(), h.end());
vector<int> j(N - K + 1);
for (int i = 0; i < N - K + 2; i++) {
j[i] = h[i + K - 1] - h[i];
}
sort(j.begin(), j.end());
cout << j[0] << endl;
}
| replace | 12 | 14 | 12 | 14 | 0 | |
p03208 | C++ | Time Limit Exceeded | #include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int h[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
// sort
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
if (h[j] > h[i]) {
int temp = h[i];
h[i] = h[j];
h[j] = temp;
}
}
}
int result = h[0] - h[K - 1];
for (int i = K; i < N; i++) {
int local = h[i - K + 1] - h[i];
if (local < result)
result = local;
}
cout << result << endl;
} | #include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int h[N];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
// sort
sort(h, h + N);
int result = 1000000000;
for (int i = K - 1; i < N; i++) {
int local = h[i] - h[i - K + 1];
if (local < result)
result = local;
}
cout << result << endl;
} | replace | 26 | 38 | 26 | 31 | TLE | |
p03208 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout << setprecision(15) << fixed << p;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define fio() \
cin.tie(0); \
ios::sync_with_stdio(false);
// #define mp make_pair
int main() {
int n, k;
cin >> n >> k;
vl h(n);
rep(i, n) { cin >> h[i]; }
sort(all(h));
int i = 0, j = k - 1;
ll ans = INF;
while (j < n) {
ans = min(ans, h[j] - h[i]);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout << setprecision(15) << fixed << p;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define fio() \
cin.tie(0); \
ios::sync_with_stdio(false);
// #define mp make_pair
int main() {
int n, k;
cin >> n >> k;
vl h(n);
rep(i, n) { cin >> h[i]; }
sort(all(h));
int i = 0, j = k - 1;
ll ans = INF;
while (j < n) {
ans = min(ans, h[j] - h[i]);
i++;
j++;
}
cout << ans << endl;
}
| insert | 80 | 80 | 80 | 82 | TLE | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int K, N;
cin >> N >> K;
long long h[11000];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h, h + N);
long long min = 1000000000;
for (int i = 0; i + K - 1 < N; i++) {
if (h[i + K - 1] - h[i] < min)
min = h[i + K - 1] - h[i];
}
cout << min << endl;
}
| #include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int K, N;
cin >> N >> K;
long long h[110000];
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h, h + N);
long long min = 1000000000;
for (int i = 0; i + K - 1 < N; i++) {
if (h[i + K - 1] - h[i] < min)
min = h[i + K - 1] - h[i];
}
cout << min << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
ll a[1005];
int Min = 0x3f3f3f3f;
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
for (int i = k - 1; i < n; i++) {
int temp = a[i] - a[i - k + 1];
Min = min(Min, temp);
}
printf("%d\n", Min);
return 0;
}
| #include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
int a[100005];
int Min = 0x3f3f3f3f;
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
for (int i = k - 1; i < n; i++) {
int temp = a[i] - a[i - k + 1];
Min = min(Min, temp);
}
printf("%d\n", Min);
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
int main() {
int n, k;
cin >> n >> k;
vl h(n);
rep(i, n) cin >> h[i];
sort(all(h));
set<int> g;
rep(i, n - 2) { g.insert(h[i + k - 1] - h[i]); }
cout << *begin(g) << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
int main() {
int n, k;
cin >> n >> k;
vl h(n);
rep(i, n) cin >> h[i];
sort(all(h));
set<int> g;
rep(i, n - k + 1) { g.insert(h[i + k - 1] - h[i]); }
cout << *begin(g) << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, K;
long min = 10000000000000;
cin >> N;
cin >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h.begin(), h.end());
for (int i = 0; i < N; i++) {
if (min > abs(h[K - 1 + i] - h[i])) {
min = abs(h[K - 1 + i] - h[i]);
}
}
cout << min << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, K;
long min = 10000000000000;
cin >> N;
cin >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h.begin(), h.end());
for (int i = 0; N - K + 1 != i; i++) {
if (min > abs(h[K - 1 + i] - h[i])) {
min = abs(h[K - 1 + i] - h[i]);
}
}
cout << min << endl;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
const int INF = 1 << 30;
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> h(n);
rep(i, n) cin >> h[i];
sort(h.begin(), h.end());
int ans = INF;
rep(i, n - 2) { ans = min(ans, h[i + k - 1] - h[i]); }
cout << ans << '\n';
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
const int INF = 1 << 30;
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> h(n);
rep(i, n) cin >> h[i];
sort(h.begin(), h.end());
int ans = INF;
rep(i, n - k + 1) { ans = min(ans, h[i + k - 1] - h[i]); }
cout << ans << '\n';
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
std::vector<int> h;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
h.push_back(tmp);
}
std::sort(h.begin(), h.end());
int min = h.at(n - 1);
for (int i = 0; i < n - (k - 1); ++i) {
int tmp = h.at(n + k - 1) - h.at(n);
if (min > tmp)
min = tmp;
}
// 出力
cout << min << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
std::vector<int> h;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
h.push_back(tmp);
}
std::sort(h.begin(), h.end());
int min = h.at(n - 1);
for (int i = 0; i < n - (k - 1); ++i) {
int tmp = h.at(i + k - 1) - h.at(i);
if (min > tmp)
min = tmp;
}
// 出力
cout << min << endl;
return 0;
} | replace | 16 | 17 | 16 | 17 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 7) >= this->size() (which is 5)
|
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
int main(int argc, char *argv[]) {
unsigned long n, k;
cin >> n >> k;
vector<unsigned long> h(n);
rep(i, n) cin >> h[i];
sort(ALL(h));
unsigned long min = pow(10, 9);
rep(i, n) {
unsigned long t = h[i + k - 1] - h[i];
if (min > t)
min = t;
}
cout << min << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
int main(int argc, char *argv[]) {
unsigned long n, k;
cin >> n >> k;
vector<unsigned long> h(n);
rep(i, n) cin >> h[i];
sort(ALL(h));
unsigned long min = pow(10, 9);
rep(i, n - k + 1) {
unsigned long t = h[i + k - 1] - h[i];
if (min > t)
min = t;
}
cout << min << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03208 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<int> h(N);
for (auto &i : h)
cin >> i;
sort(h.begin(), h.end());
int res = INT_MAX;
for (int i = 0; i < N - K + 1; i++) {
int foo = h[K + i - 1] - h[i];
if (foo < res)
res = foo;
}
cout << res;
return 0;
} | #pragma GCC optimize("Ofast")
#pragma GCC target("tune=native")
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<int> h(N);
for (auto &i : h)
cin >> i;
sort(h.begin(), h.end());
int res = INT_MAX;
for (int i = 0; i < N - K + 1; i++) {
int foo = h[K + i - 1] - h[i];
if (foo < res)
res = foo;
}
cout << res;
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
int N, K;
cin >> N >> K;
vector<long long> h(N);
for (int i = 0; i < N; i++)
cin >> h[i];
sort(h.begin(), h.end());
long long ans = INF;
for (int i = 0; i <= N - K; i++) {
ans = min(ans, h[i - K + 1] - h[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
int N, K;
cin >> N >> K;
vector<long long> h(N);
for (int i = 0; i < N; i++)
cin >> h[i];
sort(h.begin(), h.end());
long long ans = INF;
for (int i = 0; i <= N - K; i++) {
ans = min(ans, h[i + K - 1] - h[i]);
}
cout << ans << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03208 | C++ | Runtime Error | /*
Templatka c++ Kacper Fis
//
*/
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
const int INF = 1000000001;
const float PI = 3.14;
typedef long long LL;
typedef vector<int> vi;
typedef list<int> li;
typedef queue<int> qi;
typedef pair<int, int> ii;
typedef map<string, int> msi; // np msi['nazwa'] = 'liczba'
typedef vector<ii> vii; // vector par<int>, do tworzenia tablicy dla grafĂłw
// wagowych #dijkstra #Bellman_Ford
typedef priority_queue<ii, vector<ii>, greater<ii>>
pq; // kolejka priorytetowa vectorĂłw par(top()=min) #dijkstra
// list<int>::iterator it;
list<int>::iterator it1;
vector<int>::iterator it2;
vector<int>::iterator it3;
set<int>::iterator it4;
map<string, int>::iterator it5;
vector<ii>::iterator iter;
#define print_list(x) \
for (it = (x).begin(); it != (x).end(); it++) { \
cout << *it << " "; \
}
#define print_vector(x) \
for (it2 = (x).begin(); it2 != (x).end(); it2++) { \
cout << *it2 << " "; \
}
#define search_list(x) for (it = (x).begin(); it != (x).end(); it++)
#define search_vector(x) \
for (it2 = (x).begin(); it2 != (x).end(); it2++) \
;
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////GLOBAL
///DEFINITIONS////////////////////////////////////////////////////////
///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vi V;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
V.pb(x);
}
sort(V.begin(), V.end());
// cout << "Vector V: " << endl;
// for(auto it : V){
// cout << it << " ";
//}
vi ans;
for (int i = 2; i < n; i++) {
ans.pb(V[i] - V[i - k + 1]);
}
sort(ans.begin(), ans.end());
cout << *ans.begin();
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| /*
Templatka c++ Kacper Fis
//
*/
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
const int INF = 1000000001;
const float PI = 3.14;
typedef long long LL;
typedef vector<int> vi;
typedef list<int> li;
typedef queue<int> qi;
typedef pair<int, int> ii;
typedef map<string, int> msi; // np msi['nazwa'] = 'liczba'
typedef vector<ii> vii; // vector par<int>, do tworzenia tablicy dla grafĂłw
// wagowych #dijkstra #Bellman_Ford
typedef priority_queue<ii, vector<ii>, greater<ii>>
pq; // kolejka priorytetowa vectorĂłw par(top()=min) #dijkstra
// list<int>::iterator it;
list<int>::iterator it1;
vector<int>::iterator it2;
vector<int>::iterator it3;
set<int>::iterator it4;
map<string, int>::iterator it5;
vector<ii>::iterator iter;
#define print_list(x) \
for (it = (x).begin(); it != (x).end(); it++) { \
cout << *it << " "; \
}
#define print_vector(x) \
for (it2 = (x).begin(); it2 != (x).end(); it2++) { \
cout << *it2 << " "; \
}
#define search_list(x) for (it = (x).begin(); it != (x).end(); it++)
#define search_vector(x) \
for (it2 = (x).begin(); it2 != (x).end(); it2++) \
;
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////GLOBAL
///DEFINITIONS////////////////////////////////////////////////////////
///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vi V;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
V.pb(x);
}
sort(V.begin(), V.end());
// cout << "Vector V: " << endl;
// for(auto it : V){
// cout << it << " ";
//}
vi ans;
for (int i = k - 1; i < n; i++) {
ans.pb(V[i] - V[i - k + 1]);
}
sort(ans.begin(), ans.end());
cout << *ans.begin();
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| replace | 94 | 95 | 94 | 95 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
vector<ll> h;
int main() {
int n, k;
cin >> n >> k;
rep(i, n) {
ll t;
cin >> t;
h.push_back(t);
}
sort(h.begin(), h.end());
ll ans = LINF;
rep(i, k) { ans = min(ans, h[k + i - 1] - h[i]); }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
vector<ll> h;
int main() {
int n, k;
cin >> n >> k;
rep(i, n) {
ll t;
cin >> t;
h.push_back(t);
}
sort(h.begin(), h.end());
ll ans = LINF;
rep(i, n - k + 1) { ans = min(ans, h[k + i - 1] - h[i]); }
cout << ans << endl;
return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p03208 | C++ | Runtime Error | // #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, K;
cin >> N >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h.begin(), h.end());
int min_hight = 1e9;
for (int i = 0; i < N; i++) {
min_hight = min(min_hight, h[i + K - 1] - h[i]);
}
cout << min_hight << endl;
return 0;
}
| // #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, K;
cin >> N >> K;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
sort(h.begin(), h.end());
int min_hight = 1e9;
for (int i = 0; i < N - K + 1; i++) {
min_hight = min(min_hight, h[i + K - 1] - h[i]);
}
cout << min_hight << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll 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 rep11(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 pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
typedef pair<int, int> P;
int main() {
long long n, k;
cin >> n >> k;
vector<int> v;
vector<int> w;
rep(i, n) {
long long h;
cin >> h;
v.push_back(h);
}
sort(v.begin(), v.end());
rep(i, n - (k - 1)) { w[i] = v[i + (k - 1)] - v[i]; }
sort(w.begin(), w.end());
cout << w[0] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll 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 rep11(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 pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
typedef pair<int, int> P;
int main() {
long long n, k;
cin >> n >> k;
vector<int> v;
vector<int> w(n - (k - 1));
rep(i, n) {
long long h;
cin >> h;
v.push_back(h);
}
sort(v.begin(), v.end());
rep(i, n - (k - 1)) { w[i] = v[i + (k - 1)] - v[i]; }
sort(w.begin(), w.end());
cout << w[0] << endl;
}
| replace | 23 | 24 | 23 | 24 | -11 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void) {
int n, k;
cin >> n >> k;
ll h[n];
rep(i, n) { cin >> h[i]; }
sort(h, h + n);
ll diff = 10000000;
rep(i, n) { diff = min(h[i + k - 1] - h[i], diff); }
cout << diff << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void) {
int n, k;
cin >> n >> k;
ll h[n];
rep(i, n) { cin >> h[i]; }
sort(h, h + n);
ll diff = 10000000000;
rep(i, n) {
if (i + k - 1 == n)
break;
diff = min(h[i + k - 1] - h[i], diff);
}
cout << diff << endl;
return 0;
}
| replace | 14 | 16 | 14 | 20 | 0 | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
int main() {
int N, K;
std::cin >> N >> K;
std::vector<int> h(N);
for (int i = 0; i < N; i++) {
std::cin >> h.at(i);
}
std::sort(h.begin(), h.end());
int min = 1000000000;
for (int i = 0; i < N + K - 1; i++) {
int temp = h.at(i + K - 1) - h.at(i);
if (temp < min) {
min = temp;
}
}
std::cout << min << std::endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
int main() {
int N, K;
std::cin >> N >> K;
std::vector<int> h(N);
for (int i = 0; i < N; i++) {
std::cin >> h.at(i);
}
std::sort(h.begin(), h.end());
int min = 1000000000;
for (int i = 0; i < N - K + 1; i++) {
int temp = h.at(i + K - 1) - h.at(i);
if (temp < min) {
min = temp;
}
}
std::cout << min << std::endl;
}
| replace | 13 | 14 | 13 | 14 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
|
p03208 | C++ | Runtime Error | #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
int main() {
int n, k;
cin >> n >> k;
vector<int> c(n);
rep(i, 0, n) { cin >> c[i]; }
sort(c.begin(), c.end());
int ans = c[n - k] - c[0];
rep(i, 1, n - k + 1) { ans = min(c[i + n - k] - c[i], ans); }
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
int main() {
int n, k;
cin >> n >> k;
vector<int> c(n);
rep(i, 0, n) { cin >> c[i]; }
sort(c.begin(), c.end());
int ans = 1000000001;
rep(i, 0, n - k + 1) { ans = min(c[i + k - 1] - c[i], ans); }
cout << ans << endl;
return 0;
} | replace | 17 | 19 | 17 | 19 | 0 | |
p03208 | C++ | Runtime Error | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare_lld(const void *a, const void *b) {
long long int *A = (long long int *)a;
long long int *B = (long long int *)b;
if (*A > *B)
return 1;
if (*A < *B)
return -1;
return 0;
}
int main() {
long long int n, k, i;
scanf("%lld", &n);
scanf("%lld", &k);
long long int h[n];
for (i = 0; i < n; i++) {
scanf("%lld", &h[i]);
}
qsort(h, n, sizeof(long long int), compare_lld);
long long int ans = h[n - 1] - h[0];
long long int temp = 0;
for (i = 0; i < n; i++) {
temp = h[i + k - 1] - h[i];
if (temp < ans) {
ans = temp;
}
}
printf("%lld\n", ans);
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare_lld(const void *a, const void *b) {
long long int *A = (long long int *)a;
long long int *B = (long long int *)b;
if (*A > *B)
return 1;
if (*A < *B)
return -1;
return 0;
}
int main() {
long long int n, k, i;
scanf("%lld", &n);
scanf("%lld", &k);
long long int h[n];
for (i = 0; i < n; i++) {
scanf("%lld", &h[i]);
}
qsort(h, n, sizeof(long long int), compare_lld);
long long int ans = h[n - 1] - h[0];
long long int temp = 0;
for (i = 0; i + k - 1 < n; i++) {
temp = h[i + k - 1] - h[i];
if (temp < ans) {
ans = temp;
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p03208 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_LARGE = 1000000100;
// debug func
template <typename T> void vecprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vecvecprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename T> void pqprint(priority_queue<T> q) {
while (!q.empty()) {
cerr << q.top() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void qprint(queue<T> q) {
while (!q.empty()) {
cerr << q.front() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void vecqprint(vector<queue<T>> v) {
for (int i = 0; i < v.size(); i++) {
qprint(v[i]);
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
int main(void) {
int n, k;
cin >> n >> k;
VI v(n, 0);
REP(i, n) cin >> v[i];
sort(v.begin(), v.end());
int ans = INT_MAX;
REP(i, n - k + 1) { ans = min(ans, v[i + n - k] - v[i]); }
cout << ans << endl;
} | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SIZE(a) int((a).size())
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_LARGE = 1000000100;
// debug func
template <typename T> void vecprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vecvecprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename T> void pqprint(priority_queue<T> q) {
while (!q.empty()) {
cerr << q.top() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void qprint(queue<T> q) {
while (!q.empty()) {
cerr << q.front() << " ";
q.pop();
}
cerr << endl;
}
template <typename T> void vecqprint(vector<queue<T>> v) {
for (int i = 0; i < v.size(); i++) {
qprint(v[i]);
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
int main(void) {
int n, k;
cin >> n >> k;
VI v(n, 0);
REP(i, n) cin >> v[i];
sort(v.begin(), v.end());
int ans = INT_MAX;
// vecprint(v);
REP(i, n - k + 1) {
// cerr << i << endl;
// cerr << v[i] << " " << v[i+n-k] << endl;
ans = min(ans, v[i + k - 1] - v[i]);
}
cout << ans << endl;
} | replace | 143 | 144 | 143 | 149 | 0 | |
p03208 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using ll = long long;
using namespace std;
ll x, y, z, l, m, n, r, q, k;
// 0 1 2 3 4 5 6 n = 7;
void solve() {
cin >> n >> k;
ll a[1000];
for (int i = 0; i < n; i++)
cin >> a[i];
ll md = INT_MAX;
sort(a, a + n);
for (int i = 0; i <= n - k; i++) {
md = min(md, a[i + k - 1] - a[i]);
}
cout << md << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int test;
test = 1;
while (test--) {
solve();
}
return 0;
} | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using ll = long long;
using namespace std;
ll x, y, z, l, m, n, r, q, k;
// 0 1 2 3 4 5 6 n = 7;
void solve() {
cin >> n >> k;
ll a[100000];
for (int i = 0; i < n; i++)
cin >> a[i];
ll md = INT_MAX;
sort(a, a + n);
for (int i = 0; i <= n - k; i++) {
md = min(md, a[i + k - 1] - a[i]);
}
cout << md << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int test;
test = 1;
while (test--) {
solve();
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a;
cin >> n >> k;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
int diff = INT_MAX;
for (int i = 0; i < n; i++) {
diff = min(diff, v[i + k - 1] - v[i]);
}
cout << diff << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a;
cin >> n >> k;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
int diff = INT_MAX;
for (int i = 0; i <= n - k; i++) {
diff = min(diff, v[i + k - 1] - v[i]);
}
cout << diff << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03208 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) \
for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v) \
for (size_t I = 0; I < v.size(); ++I) { \
cout << " " << #v << "[" << I << "]=" << v[I]; \
} \
cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
int main(void) {
int n, k;
cin >> n >> k;
vector<int> h(n);
repeat(i, n) cin >> h[i];
sort(h.begin(), h.end());
int ans = 1e9 + 1;
repeat(i, n - k + 1) {
// cout << "h[" << n-k+i << "]-h[" << i << "]" << endl;
ans = min(ans, h[n - k + i] - h[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) \
for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v) \
for (size_t I = 0; I < v.size(); ++I) { \
cout << " " << #v << "[" << I << "]=" << v[I]; \
} \
cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
int main(void) {
int n, k;
cin >> n >> k;
vector<int> h(n);
repeat(i, n) cin >> h[i];
sort(h.begin(), h.end());
int ans = 1e9 + 1;
repeat(i, n - k + 1) {
// cout << "h[" << i+k-1 << "]-h[" << i << "]=" << h[i+k-1] - h[i] << endl;
ans = min(ans, h[i + k - 1] - h[i]);
}
cout << ans << endl;
} | replace | 33 | 35 | 33 | 35 | 0 | |
p03208 | C++ | Time Limit Exceeded | // lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define double long double
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n + 1)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, c, d, m, n, maxi = 0, f = 0, mini = INF, sum = 0;
string str;
cin >> n >> m;
// vector<vector<ll>> v(tate,vector<ll> (yoko));
vector<ll> v(n);
rep(i, n) cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
vector<ll> w(n - 1);
rep(i, n - 1) { w[i] = v[i] - v[i + 1]; }
vector<ll> x(n - m + 1);
rep(i, n - m + 1) {
for (ll j = i; j < i + m - 1; j++) {
x[i] += w[j];
}
// cout<<x[i]<<endl;
}
sort(x.begin(), x.end());
cout << x[0] << endl;
return 0;
}
| // lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define double long double
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n + 1)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, c, d, m, n, maxi = 0, f = 0, mini = INF, sum = 0;
string str;
cin >> n >> m;
// vector<vector<ll>> v(tate,vector<ll> (yoko));
vector<ll> v(n);
rep(i, n) cin >> v[i];
sort(v.begin(), v.end(), greater<ll>());
vector<ll> w(n - 1);
rep(i, n - 1) { w[i] = v[i] - v[i + 1]; }
vector<ll> x(n - m + 1);
rep(i, n - m + 1) { x[i] = v[i] - v[i + m - 1]; }
sort(x.begin(), x.end());
cout << x[0] << endl;
return 0;
}
| replace | 30 | 36 | 30 | 31 | TLE | |
p03208 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
using namespace std;
int abs(int n) { return n >= 0 ? n : -n; }
int main() {
int n, k;
int h[10000];
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &h[i]);
sort(h, h + n);
int min = 1000000000;
for (int i = 0; i < n - k + 1; i++) {
if (min > abs(h[i] - h[i + k - 1]))
min = abs(h[i] - h[i + k - 1]);
}
printf("%d\n", min);
}
| #include <algorithm>
#include <stdio.h>
using namespace std;
int abs(int n) { return n >= 0 ? n : -n; }
int main() {
int n, k;
int h[100000];
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%d", &h[i]);
sort(h, h + n);
int min = 1000000000;
for (int i = 0; i < n - k + 1; i++) {
if (min > abs(h[i] - h[i + k - 1]))
min = abs(h[i] - h[i + k - 1]);
}
printf("%d\n", min);
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03208 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int n, k;
cin >> n >> k;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
sort(h, h + n);
ll ans = 1e9 + 1;
for (int i = 0; i < n - k + 1; i++) {
ll hmin = 1e9 + 1;
ll hmax = -1;
for (int j = i; j < i + k; j++) {
hmin = min(hmin, h[j]);
hmax = max(hmax, h[j]);
}
ans = min(ans, hmax - hmin);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int n, k;
cin >> n >> k;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
sort(h, h + n);
ll ans = 1e9 + 1;
for (int i = 0; i < n; i++) {
if (i + k - 1 > n - 1)
continue;
ll tmp = h[i + k - 1] - h[i];
ans = min(ans, tmp);
}
cout << ans << endl;
return 0;
}
| replace | 12 | 20 | 12 | 17 | TLE | |
p03208 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define ALL(x) x.begin(), x.end()
#define REVERSE(x) reverse(x.begin(), x.end())
#define SORT(x, n) sort(x, x)
#define P pair<int, int>
typedef long long LL;
const int INF = 1000000007;
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
int main() {
int N, K;
cin >> N >> K;
vector<int> h(N);
REP(i, N) { cin >> h[i]; }
sort(ALL(h));
int ans = INF;
REP(i, N - K + 1) {
int maxh = 0;
int minh = INF;
for (int j = i; j < i + K; j++) {
maxh = max(maxh, h[j]);
minh = min(minh, h[j]);
}
ans = min(ans, (maxh - minh));
}
cout << ans;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define ALL(x) x.begin(), x.end()
#define REVERSE(x) reverse(x.begin(), x.end())
#define SORT(x, n) sort(x, x)
#define P pair<int, int>
typedef long long LL;
const int INF = 1000000007;
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
int main() {
int N, K;
cin >> N >> K;
vector<int> h(N);
REP(i, N) { cin >> h[i]; }
sort(ALL(h));
int ans = INF;
REP(i, N - K + 1) { ans = min(ans, h[i + K - 1] - h[i]); }
cout << ans;
} | replace | 25 | 34 | 25 | 26 | TLE |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.