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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03143
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define ll long long
using namespace std;
const int N = 2e5;
struct edge {
int fr, to, w;
} a[N], sta[N];
int n, m, val[N], fa[N];
int siz[N], cnt, top, ans;
ll sum[N];
int cmp(const edge &A, const edge &B) { return A.w < B.w; }
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%d", &val[i]);
fa[i] = i, siz[i] = 1, sum[i] = val[i];
}
for (int i = 1, x, y, w; i <= m; i++) {
scanf("%d%d%d", &x, &y, &w);
a[++cnt] = (edge){x, y, w};
}
sort(a + 1, a + cnt + 1, cmp);
for (int i = 1; i <= cnt; i++) {
int x = a[i].fr, y = a[i].to;
x = find(x);
y = find(y);
if (x == y)
continue;
if (siz[x] < siz[y])
swap(x, y);
sta[++top] = (edge){x, y, a[i].w};
fa[x] = y;
siz[y] += siz[x];
sum[y] += sum[x];
}
for (int i = top; i >= 1; i--) {
int x = sta[i].fr, y = sta[i].to;
ll v = sum[find(y)], val = sta[i].w;
if (v < val)
fa[x] = x, siz[y] -= siz[x], sum[y] -= sum[x];
}
for (int i = 1; i <= m; i++) {
int x = a[i].fr, y = a[i].to;
if (find(x) != find(y))
ans++;
else if (a[i].w > sum[find(x)])
ans++;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define ll long long
using namespace std;
const int N = 2e5;
struct edge {
int fr, to, w;
} a[N], sta[N];
int n, m, val[N], fa[N];
int siz[N], cnt, top, ans;
ll sum[N];
int cmp(const edge &A, const edge &B) { return A.w < B.w; }
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%d", &val[i]);
fa[i] = i, siz[i] = 1, sum[i] = val[i];
}
for (int i = 1, x, y, w; i <= m; i++) {
scanf("%d%d%d", &x, &y, &w);
a[++cnt] = (edge){x, y, w};
}
sort(a + 1, a + cnt + 1, cmp);
for (int i = 1; i <= cnt; i++) {
int x = a[i].fr, y = a[i].to;
x = find(x);
y = find(y);
if (x == y)
continue;
if (siz[x] > siz[y])
swap(x, y);
sta[++top] = (edge){x, y, a[i].w};
fa[x] = y;
siz[y] += siz[x];
sum[y] += sum[x];
}
for (int i = top; i >= 1; i--) {
int x = sta[i].fr, y = sta[i].to;
ll v = sum[find(y)], val = sta[i].w;
if (v < val)
fa[x] = x, siz[y] -= siz[x], sum[y] -= sum[x];
}
for (int i = 1; i <= m; i++) {
int x = a[i].fr, y = a[i].to;
if (find(x) != find(y))
ans++;
else if (a[i].w > sum[find(x)])
ans++;
}
cout << ans << endl;
}
|
replace
| 33 | 34 | 33 | 34 |
TLE
| |
p03143
|
C++
|
Time Limit Exceeded
|
/*input
6 10
4 4 1 1 1 7
3 5 19
2 5 20
4 5 8
1 6 16
2 3 9
3 6 16
3 4 1
2 6 20
2 4 19
1 2 9
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, j, k) for (int i = j; i < k; ++i)
#define RREP(i, j, k) for (int i = j; i >= k; --i)
#define F first
#define S second
#define mp make_pair
#define pb emplace_back
#define PII pair<int, int>
#define DBGG(i, j) cout << i << " " << j << endl
#define DB4(i, j, k, l) cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0), cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100009
#define INF 0x3f3f3f3f
struct djs {
int x[MAX], v[MAX], siz[];
void init() { REP(i, 0, MAX) x[i] = i; }
int Find(int now) { return x[now] == now ? now : Find(x[now]); }
void Union(int a, int b) {
a = Find(a), b = Find(b);
if (v[a] < v[b])
swap(a, b);
x[a] = b;
v[b] += v[a];
}
int operator[](int now) { return Find(now); }
} ds;
int n, m, e[MAX][3], x[MAX], in[MAX], s[MAX];
int cut[MAX][2], rrr[MAX][2], is[MAX];
int cmp(int a, int b) { return e[a][2] < e[b][2]; }
int32_t main() {
IOS;
cin >> n >> m;
REP(i, 1, n + 1) cin >> x[i];
REP(i, 1, m + 1) REP(j, 0, 3) cin >> e[i][j];
REP(i, 1, m + 1) s[i] = i;
sort(s + 1, s + 1 + m, cmp);
ds.init();
REP(i, 1, n + 1) ds.v[i] = x[i];
REP(idx, 1, m + 1) {
int i = s[idx];
int v1 = e[i][0], v2 = e[i][1];
if (ds[v1] != ds[v2]) {
is[i] = 1;
rrr[i][0] = ds[v1];
cut[i][0] = ds.v[ds[v1]];
rrr[i][1] = ds[v2];
cut[i][1] = ds.v[ds[v2]];
ds.Union(v1, v2);
}
// cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.x[i] << " "; cout <<
// endl; cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.v[i] << " "; cout
// << endl;
}
int ans = 0;
RREP(idx, m, 1) {
int i = s[idx];
int v1 = e[i][0], v2 = e[i][1];
// DB4("edge " , e[i][2] , "vs = " , ds.v[ds[v1]]);
// DB4(rrr[i][0] , cut[i][0] , rrr[i][1] , cut[i][1]);
if (ds[v1] != ds[v2])
ans++; // , DBGG("HERE" , "");
else if (ds.v[ds[v1]] < e[i][2]) {
ans++;
if (is[i]) {
ds.x[rrr[i][0]] = rrr[i][0], ds.v[rrr[i][0]] = cut[i][0];
ds.x[rrr[i][1]] = rrr[i][1], ds.v[rrr[i][1]] = cut[i][1];
// cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.x[i] << " "; cout <<
// endl;
}
}
}
cout << ans << endl;
return 0;
}
|
/*input
6 10
4 4 1 1 1 7
3 5 19
2 5 20
4 5 8
1 6 16
2 3 9
3 6 16
3 4 1
2 6 20
2 4 19
1 2 9
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, j, k) for (int i = j; i < k; ++i)
#define RREP(i, j, k) for (int i = j; i >= k; --i)
#define F first
#define S second
#define mp make_pair
#define pb emplace_back
#define PII pair<int, int>
#define DBGG(i, j) cout << i << " " << j << endl
#define DB4(i, j, k, l) cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0), cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100009
#define INF 0x3f3f3f3f
struct djs {
int x[MAX], v[MAX], siz[];
void init() { REP(i, 0, MAX) x[i] = i; }
int Find(int now) { return x[now] == now ? now : Find(x[now]); }
void Union(int a, int b) {
a = Find(a), b = Find(b);
if (v[a] > v[b])
swap(a, b);
x[a] = b;
v[b] += v[a];
}
int operator[](int now) { return Find(now); }
} ds;
int n, m, e[MAX][3], x[MAX], in[MAX], s[MAX];
int cut[MAX][2], rrr[MAX][2], is[MAX];
int cmp(int a, int b) { return e[a][2] < e[b][2]; }
int32_t main() {
IOS;
cin >> n >> m;
REP(i, 1, n + 1) cin >> x[i];
REP(i, 1, m + 1) REP(j, 0, 3) cin >> e[i][j];
REP(i, 1, m + 1) s[i] = i;
sort(s + 1, s + 1 + m, cmp);
ds.init();
REP(i, 1, n + 1) ds.v[i] = x[i];
REP(idx, 1, m + 1) {
int i = s[idx];
int v1 = e[i][0], v2 = e[i][1];
if (ds[v1] != ds[v2]) {
is[i] = 1;
rrr[i][0] = ds[v1];
cut[i][0] = ds.v[ds[v1]];
rrr[i][1] = ds[v2];
cut[i][1] = ds.v[ds[v2]];
ds.Union(v1, v2);
}
// cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.x[i] << " "; cout <<
// endl; cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.v[i] << " "; cout
// << endl;
}
int ans = 0;
RREP(idx, m, 1) {
int i = s[idx];
int v1 = e[i][0], v2 = e[i][1];
// DB4("edge " , e[i][2] , "vs = " , ds.v[ds[v1]]);
// DB4(rrr[i][0] , cut[i][0] , rrr[i][1] , cut[i][1]);
if (ds[v1] != ds[v2])
ans++; // , DBGG("HERE" , "");
else if (ds.v[ds[v1]] < e[i][2]) {
ans++;
if (is[i]) {
ds.x[rrr[i][0]] = rrr[i][0], ds.v[rrr[i][0]] = cut[i][0];
ds.x[rrr[i][1]] = rrr[i][1], ds.v[rrr[i][1]] = cut[i][1];
// cout << "\t\t\t"; REP(i , 1 , n + 1) cout << ds.x[i] << " "; cout <<
// endl;
}
}
}
cout << ans << endl;
return 0;
}
|
replace
| 40 | 41 | 40 | 41 |
TLE
| |
p03143
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <ext/algorithm>
#include <ext/numeric>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ffor(_a, _f, _t) for (int _a = (_f), __t = (_t); _a < __t; _a++)
#define all(_v) (_v).begin(), (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor(__i, 0, __n)
typedef long long LL;
using namespace std;
const int MAXN = 400000;
const int UNION_FIND_N = MAXN;
int parent[UNION_FIND_N];
LL sum[UNION_FIND_N];
int lastEdge[UNION_FIND_N];
int vWeight[MAXN];
vector<pair<int, pair<int, int>>> edges;
bool goodEdge[MAXN];
LL sumAtGood[MAXN];
vector<int> G[MAXN];
// assumes that if vertex v does not have parent,
// i.e. if v is root, then parent[v] = v
int root(int v) {
if (parent[v] == v)
return v;
return parent[v] = root(parent[v]);
}
void merge(int u, int v, int edge) {
int rv = root(v);
int ru = root(u);
if (rv == ru)
return;
parent[rv] = ru;
sum[ru] += sum[rv];
G[edge].pb(lastEdge[rv]);
G[edge].pb(lastEdge[ru]);
lastEdge[ru] = edge;
if (edges[edge].first <= sum[ru]) {
goodEdge[edge] = true;
sumAtGood[edge] = sum[ru];
}
}
void init_union_find(int n) {
for (int i = 0; i < n; i++) {
parent[i] = i;
sum[i] = vWeight[i];
lastEdge[i] = -i - 1;
}
}
int n, m;
int label[MAXN];
void dfs(int edge, bool good, int l) {
bool nextGood = good;
int nextLabel = l;
if (!good && goodEdge[edge]) {
nextGood = true;
nextLabel = edge;
}
int e0 = G[edge][0], e1 = G[edge][1];
if (e0 < 0) {
e0 = -e0 - 1;
label[e0] = nextLabel;
} else {
dfs(e0, nextGood, nextLabel);
}
if (e1 < 0) {
e1 = -e1 - 1;
label[e1] = nextLabel;
} else {
dfs(e1, nextGood, nextLabel);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
FOR(i, MAXN)
G[i].clear();
edges.clear();
cin >> n >> m;
FOR(i, n)
cin >> vWeight[i];
int x, y, c;
FOR(i, m) {
cin >> x >> y >> c;
x--;
y--;
edges.pb(make_pair(c, make_pair(x, y)));
}
sort(all(edges));
init_union_find(n);
SET(goodEdge, 0);
int lastAdded = -1;
FOR(i, edges.sz) {
int a = edges[i].second.first;
int b = edges[i].second.second;
if (root(a) == root(b))
continue;
merge(a, b, i);
lastAdded = i;
}
dfs(lastAdded, false, -1);
int ret = 0;
FOR(i, edges.sz) {
int a = edges[i].second.first;
int b = edges[i].second.second;
if (label[a] < 0 || label[b] < 0) {
ret++;
continue;
}
if (label[a] != label[b]) {
ret++;
continue;
}
if (sumAtGood[label[a]] < edges[i].first)
ret++;
}
cout << ret << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <ext/algorithm>
#include <ext/numeric>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ffor(_a, _f, _t) for (int _a = (_f), __t = (_t); _a < __t; _a++)
#define all(_v) (_v).begin(), (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor(__i, 0, __n)
typedef long long LL;
using namespace std;
const int MAXN = 400000;
const int UNION_FIND_N = MAXN;
int parent[UNION_FIND_N];
LL sum[UNION_FIND_N];
int lastEdge[UNION_FIND_N];
int vWeight[MAXN];
vector<pair<int, pair<int, int>>> edges;
bool goodEdge[MAXN];
LL sumAtGood[MAXN];
vector<int> G[MAXN];
// assumes that if vertex v does not have parent,
// i.e. if v is root, then parent[v] = v
int root(int v) {
if (parent[v] == v)
return v;
return parent[v] = root(parent[v]);
}
void merge(int u, int v, int edge) {
int rv = root(v);
int ru = root(u);
if (rv == ru)
return;
parent[rv] = ru;
sum[ru] += sum[rv];
G[edge].pb(lastEdge[rv]);
G[edge].pb(lastEdge[ru]);
lastEdge[ru] = edge;
if (edges[edge].first <= sum[ru]) {
goodEdge[edge] = true;
sumAtGood[edge] = sum[ru];
}
}
void init_union_find(int n) {
for (int i = 0; i < n; i++) {
parent[i] = i;
sum[i] = vWeight[i];
lastEdge[i] = -i - 1;
}
}
int n, m;
int label[MAXN];
void dfs(int edge, bool good, int l) {
bool nextGood = good;
int nextLabel = l;
if (!good && goodEdge[edge]) {
nextGood = true;
nextLabel = edge;
}
int e0 = G[edge][0], e1 = G[edge][1];
if (e0 < 0) {
e0 = -e0 - 1;
label[e0] = nextLabel;
} else {
dfs(e0, nextGood, nextLabel);
}
if (e1 < 0) {
e1 = -e1 - 1;
label[e1] = nextLabel;
} else {
dfs(e1, nextGood, nextLabel);
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
FOR(i, MAXN)
G[i].clear();
edges.clear();
cin >> n >> m;
FOR(i, n)
cin >> vWeight[i];
if (!m) {
cout << 0 << endl;
return 0;
}
int x, y, c;
FOR(i, m) {
cin >> x >> y >> c;
x--;
y--;
edges.pb(make_pair(c, make_pair(x, y)));
}
sort(all(edges));
init_union_find(n);
SET(goodEdge, 0);
int lastAdded = -1;
FOR(i, edges.sz) {
int a = edges[i].second.first;
int b = edges[i].second.second;
if (root(a) == root(b))
continue;
merge(a, b, i);
lastAdded = i;
}
dfs(lastAdded, false, -1);
int ret = 0;
FOR(i, edges.sz) {
int a = edges[i].second.first;
int b = edges[i].second.second;
if (label[a] < 0 || label[b] < 0) {
ret++;
continue;
}
if (label[a] != label[b]) {
ret++;
continue;
}
if (sumAtGood[label[a]] < edges[i].first)
ret++;
}
cout << ret << endl;
return 0;
}
|
insert
| 113 | 113 | 113 | 118 |
0
| |
p03143
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct GroupState {
int maxei;
long long vwsum;
};
struct UnionFind {
vector<int> par;
vector<long long> sum;
vector<int> last_e;
UnionFind(int n, vector<int> &vw) {
par.resize(n);
sum.resize(n);
last_e.resize(n, -1);
for (int i = 0; i < n; ++i) {
par[i] = i;
sum[i] = vw[i];
}
}
int find(int x) {
if (x == par[x])
return x;
return par[x] = find(par[x]);
}
pair<GroupState, GroupState> unite(int x, int y, int ei) {
int xr = find(x), yr = find(y);
auto ret = make_pair(GroupState{last_e[xr], sum[xr]},
GroupState{last_e[yr], sum[yr]});
long long xsum = sum[xr];
par[find(x)] = yr;
sum[yr] += xsum;
last_e[yr] = ei;
return ret;
}
bool same(int x, int y) { return find(x) == find(y); }
};
struct Edge {
int src, dst, cost, index;
};
bool operator<(const Edge &e, const Edge &f) { return e.cost < f.cost; }
int main() {
int n, m;
cin >> n >> m;
vector<int> vw(n);
vector<Edge> edge(m);
vector<pair<GroupState, GroupState>> to_check(m);
for (int i = 0; i < n; ++i)
cin >> vw[i];
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
edge[i] = {a - 1, b - 1, c, i};
}
auto sorted_edge = edge;
sort(sorted_edge.begin(), sorted_edge.end());
vector<long long> prev_vw(m), prev_e(m);
UnionFind uf(n, vw);
vector<int> uf_edge(m);
for (auto &e : sorted_edge) {
int x = e.src, y = e.dst;
if (uf.same(x, y))
continue;
auto res = uf.unite(x, y, e.index);
to_check[e.index] = res;
uf_edge[e.index] = 1;
//
// cerr << "new e" << ' ' << e.index << endl;
// cerr << "new e cost" << ' ' << e.cost << endl;
// cerr << "new sum" << ' ' << uf.sum[uf.find(x)] << endl;
// cerr << "prev e1: " << to_check[e.index].first.maxei << endl;
// cerr << "prev sum1: " << to_check[e.index].first.vwsum << endl;
// cerr << "prev e2: " << to_check[e.index].second.maxei << endl;
// cerr << "prev sum2: " << to_check[e.index].second.vwsum << endl;
// cerr << "---" << endl;
}
int root = uf.find(0);
cerr << root << endl;
int ei = uf.last_e[root];
long long sum = uf.sum[root];
vector<int> can_use(m, 1);
queue<GroupState> q;
q.push(GroupState{ei, sum});
while (!q.empty()) {
auto gs = q.front();
q.pop();
int idx = gs.maxei;
// cerr << "Edge index: " << idx << endl;
// cerr << "Edge cost: " << edge[idx].cost<< endl;
// cerr << "Group weight: " << gs.vwsum << endl;
if (edge[idx].cost <= gs.vwsum) {
continue;
}
auto pgs = to_check[idx];
if (pgs.first.maxei >= 0) {
q.push(pgs.first);
// cerr << "push " << pgs.first.maxei << endl;
}
if (pgs.second.maxei >= 0) {
// cerr << "push " << pgs.second.maxei << endl;
q.push(pgs.second);
}
can_use[idx] = 0;
}
int edgecnt = 0;
UnionFind uf2(n, vw);
for (auto &e : sorted_edge) {
if (!uf_edge[e.index] || !can_use[e.index])
continue;
int x = e.src, y = e.dst;
if (uf2.same(x, y))
continue;
auto res = uf2.unite(x, y, e.index);
to_check[e.index] = res;
uf_edge[e.index] = 1;
++edgecnt;
}
cerr << "rest edge" << endl;
for (int i = 0; i < m; ++i) {
if (uf_edge[i])
continue;
if (!uf2.same(edge[i].src, edge[i].dst))
continue;
int root = uf2.find(edge[i].src);
if (uf2.sum[root] >= edge[i].cost) {
cerr << i << endl;
++edgecnt;
}
}
cout << m - edgecnt << endl;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct GroupState {
int maxei;
long long vwsum;
};
struct UnionFind {
vector<int> par;
vector<long long> sum;
vector<int> last_e;
UnionFind(int n, vector<int> &vw) {
par.resize(n);
sum.resize(n);
last_e.resize(n, -1);
for (int i = 0; i < n; ++i) {
par[i] = i;
sum[i] = vw[i];
}
}
int find(int x) {
if (x == par[x])
return x;
return par[x] = find(par[x]);
}
pair<GroupState, GroupState> unite(int x, int y, int ei) {
int xr = find(x), yr = find(y);
auto ret = make_pair(GroupState{last_e[xr], sum[xr]},
GroupState{last_e[yr], sum[yr]});
long long xsum = sum[xr];
par[find(x)] = yr;
sum[yr] += xsum;
last_e[yr] = ei;
return ret;
}
bool same(int x, int y) { return find(x) == find(y); }
};
struct Edge {
int src, dst, cost, index;
};
bool operator<(const Edge &e, const Edge &f) { return e.cost < f.cost; }
int main() {
int n, m;
cin >> n >> m;
vector<int> vw(n);
vector<Edge> edge(m);
vector<pair<GroupState, GroupState>> to_check(m);
for (int i = 0; i < n; ++i)
cin >> vw[i];
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
edge[i] = {a - 1, b - 1, c, i};
}
auto sorted_edge = edge;
sort(sorted_edge.begin(), sorted_edge.end());
vector<long long> prev_vw(m), prev_e(m);
UnionFind uf(n, vw);
vector<int> uf_edge(m);
for (auto &e : sorted_edge) {
int x = e.src, y = e.dst;
if (uf.same(x, y))
continue;
auto res = uf.unite(x, y, e.index);
to_check[e.index] = res;
uf_edge[e.index] = 1;
//
// cerr << "new e" << ' ' << e.index << endl;
// cerr << "new e cost" << ' ' << e.cost << endl;
// cerr << "new sum" << ' ' << uf.sum[uf.find(x)] << endl;
// cerr << "prev e1: " << to_check[e.index].first.maxei << endl;
// cerr << "prev sum1: " << to_check[e.index].first.vwsum << endl;
// cerr << "prev e2: " << to_check[e.index].second.maxei << endl;
// cerr << "prev sum2: " << to_check[e.index].second.vwsum << endl;
// cerr << "---" << endl;
}
int root = uf.find(0);
cerr << root << endl;
int ei = uf.last_e[root];
long long sum = uf.sum[root];
vector<int> can_use(m, 1);
queue<GroupState> q;
if (ei >= 0)
q.push(GroupState{ei, sum});
while (!q.empty()) {
auto gs = q.front();
q.pop();
int idx = gs.maxei;
// cerr << "Edge index: " << idx << endl;
// cerr << "Edge cost: " << edge[idx].cost<< endl;
// cerr << "Group weight: " << gs.vwsum << endl;
if (edge[idx].cost <= gs.vwsum) {
continue;
}
auto pgs = to_check[idx];
if (pgs.first.maxei >= 0) {
q.push(pgs.first);
// cerr << "push " << pgs.first.maxei << endl;
}
if (pgs.second.maxei >= 0) {
// cerr << "push " << pgs.second.maxei << endl;
q.push(pgs.second);
}
can_use[idx] = 0;
}
int edgecnt = 0;
UnionFind uf2(n, vw);
for (auto &e : sorted_edge) {
if (!uf_edge[e.index] || !can_use[e.index])
continue;
int x = e.src, y = e.dst;
if (uf2.same(x, y))
continue;
auto res = uf2.unite(x, y, e.index);
to_check[e.index] = res;
uf_edge[e.index] = 1;
++edgecnt;
}
cerr << "rest edge" << endl;
for (int i = 0; i < m; ++i) {
if (uf_edge[i])
continue;
if (!uf2.same(edge[i].src, edge[i].dst))
continue;
int root = uf2.find(edge[i].src);
if (uf2.sum[root] >= edge[i].cost) {
cerr << i << endl;
++edgecnt;
}
}
cout << m - edgecnt << endl;
}
|
replace
| 102 | 103 | 102 | 104 |
0
|
3
rest edge
|
p03143
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
struct edge {
int a, b, y;
bool operator<(const struct edge &rhs) const { return y < rhs.y; }
};
struct union_find {
vector<long long> data;
union_find(vector<int> &X) : data(X.size()) {
for (int i = 0; i < X.size(); i++)
data[i] = -X[i];
}
void unite(int x, int y) {
if (root(x) == root(y))
return;
if (size(x) < size(y))
swap(x, y);
data[root(x)] += data[root(y)];
data[y] = root(x);
}
int root(int x) {
if (data[x] < 0)
return x;
return data[x] = root(data[x]);
}
long long size(int x) { return -data[root(x)]; }
};
int main() {
int N, M;
cin >> N >> M;
vector<int> X(N);
for (int &x : X)
cin >> x;
vector<vector<pair<int, int>>> G(N);
vector<edge> E(M);
for (auto &e : E) {
cin >> e.a >> e.b >> e.y, e.a--, e.b--;
G[e.a].emplace_back(e.b, e.y);
G[e.b].emplace_back(e.a, e.y);
}
sort(begin(E), end(E));
union_find uf(X);
vector<int> candidate(M);
for (int i = 0; i < E.size(); i++) {
uf.unite(E[i].a, E[i].b);
if (uf.size(E[i].a) >= E[i].y) {
candidate[i] = 1;
}
}
vector<int> visited(N);
int cnt = 0;
function<void(int, int)> recur;
recur = [&](int x, int cost) {
if (visited[x])
return;
visited[x] = 1;
for (auto p : G[x]) {
if (p.second <= cost) {
cnt++;
recur(p.first, cost);
}
}
};
for (int i = E.size() - 1; i >= 0; i--) {
if (candidate[i]) {
recur(E[i].a, E[i].y);
}
}
cout << M - cnt / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct edge {
int a, b, y;
bool operator<(const struct edge &rhs) const { return y < rhs.y; }
};
struct union_find {
vector<long long> data;
union_find(vector<int> &X) : data(X.size()) {
for (int i = 0; i < X.size(); i++)
data[i] = -X[i];
}
void unite(int x, int y) {
if (root(x) == root(y))
return;
if (size(x) < size(y))
swap(x, y);
data[root(x)] += data[root(y)];
data[root(y)] = root(x);
}
int root(int x) {
if (data[x] < 0)
return x;
return data[x] = root(data[x]);
}
long long size(int x) { return -data[root(x)]; }
};
int main() {
int N, M;
cin >> N >> M;
vector<int> X(N);
for (int &x : X)
cin >> x;
vector<vector<pair<int, int>>> G(N);
vector<edge> E(M);
for (auto &e : E) {
cin >> e.a >> e.b >> e.y, e.a--, e.b--;
G[e.a].emplace_back(e.b, e.y);
G[e.b].emplace_back(e.a, e.y);
}
sort(begin(E), end(E));
union_find uf(X);
vector<int> candidate(M);
for (int i = 0; i < E.size(); i++) {
uf.unite(E[i].a, E[i].b);
if (uf.size(E[i].a) >= E[i].y) {
candidate[i] = 1;
}
}
vector<int> visited(N);
int cnt = 0;
function<void(int, int)> recur;
recur = [&](int x, int cost) {
if (visited[x])
return;
visited[x] = 1;
for (auto p : G[x]) {
if (p.second <= cost) {
cnt++;
recur(p.first, cost);
}
}
};
for (int i = E.size() - 1; i >= 0; i--) {
if (candidate[i]) {
recur(E[i].a, E[i].y);
}
}
cout << M - cnt / 2 << endl;
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03143
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
/*
計算量気にしなければ貪欲に消せばいい
はみ出しているのがあったら消去
非連結になったらはみ出し確認
明らかに計算量が死ぬ
*/
// BEGIN CUT HERE
struct UnionFind {
int num; // 連結成分の数
vector<int> r, p, w; // そのグループのサイズ,自分の親っぽいやつ
UnionFind() {}
UnionFind(int n) : num(n), r(n, 1), w(n), p(n, 0) {
iota(p.begin(), p.end(), 0);
}
int find(int x) { // どのグループに所属するか
return (x == p[x]
? x
: p[x] =
find(p[x])); // xがグループの名前と一致するまでxを親にする
}
void init(vector<int> v) { w = v; }
bool same(int x, int y) { // 同じグループかどうか
return find(x) == find(y);
}
void unite(int x, int y) { // xとyを同じグループにする
x = find(x);
y = find(y); // xとyのグループの名前をどっちかが変える
if (x == y)
return;
if (r[x] < r[y])
swap(x, y); // サイズが大きい方をxとする
r[x] += r[y]; // yの親をxにする(今までyだったグループ名がxになる)
p[y] = x;
w[x] += w[y];
num--;
}
int size(int x) { // グループの大きさ
return r[find(x)];
}
int weight(int x) { return w[find(x)]; }
int count() const { // グループの数
return num;
}
};
typedef pair<int, int> P;
typedef pair<P, P> PP;
signed main() {
int N, M;
cin >> N >> M;
vector<int> w(N);
for (int i = 0; i < N; i++)
cin >> w[i];
vector<PP> e(M);
vector<P> edge[N];
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
e[i] = PP(P(c, 0), P(a, b));
edge[a].push_back(P(b, c));
edge[b].push_back(P(a, c));
}
sort(e.begin(), e.end());
UnionFind uf(N);
uf.init(w);
for (int i = 0; i < N; i++) {
int W = e[i].first.first, U = e[i].second.first, V = e[i].second.second;
uf.unite(U, V);
if (W <= uf.weight(U))
e[i].first.second = 1;
}
sort(e.rbegin(), e.rend());
set<P> s;
for (int i = 0; i < M; i++) {
int W = e[i].first.first, A = e[i].first.second, U = e[i].second.first,
V = e[i].second.second;
if (s.count(P(U, V)))
continue;
if (A == 0)
continue;
s.count(P(U, V));
queue<int> que;
que.push(U);
que.push(V);
while (que.size()) {
int p = que.front();
que.pop();
for (auto q : edge[p]) {
int t = q.first, WE = q.second;
if (s.count(P(min(p, t), max(p, t))))
continue;
if (WE > W)
continue;
s.insert(P(min(p, t), max(p, t)));
que.push(t);
}
}
}
cout << M - s.size() << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
/*
計算量気にしなければ貪欲に消せばいい
はみ出しているのがあったら消去
非連結になったらはみ出し確認
明らかに計算量が死ぬ
*/
// BEGIN CUT HERE
struct UnionFind {
int num; // 連結成分の数
vector<int> r, p, w; // そのグループのサイズ,自分の親っぽいやつ
UnionFind() {}
UnionFind(int n) : num(n), r(n, 1), w(n), p(n, 0) {
iota(p.begin(), p.end(), 0);
}
int find(int x) { // どのグループに所属するか
return (x == p[x]
? x
: p[x] =
find(p[x])); // xがグループの名前と一致するまでxを親にする
}
void init(vector<int> v) { w = v; }
bool same(int x, int y) { // 同じグループかどうか
return find(x) == find(y);
}
void unite(int x, int y) { // xとyを同じグループにする
x = find(x);
y = find(y); // xとyのグループの名前をどっちかが変える
if (x == y)
return;
if (r[x] < r[y])
swap(x, y); // サイズが大きい方をxとする
r[x] += r[y]; // yの親をxにする(今までyだったグループ名がxになる)
p[y] = x;
w[x] += w[y];
num--;
}
int size(int x) { // グループの大きさ
return r[find(x)];
}
int weight(int x) { return w[find(x)]; }
int count() const { // グループの数
return num;
}
};
typedef pair<int, int> P;
typedef pair<P, P> PP;
signed main() {
int N, M;
cin >> N >> M;
vector<int> w(N);
for (int i = 0; i < N; i++)
cin >> w[i];
vector<PP> e(M);
vector<P> edge[N];
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
e[i] = PP(P(c, 0), P(a, b));
edge[a].push_back(P(b, c));
edge[b].push_back(P(a, c));
}
sort(e.begin(), e.end());
UnionFind uf(N);
uf.init(w);
for (int i = 0; i < M; i++) {
int W = e[i].first.first, U = e[i].second.first, V = e[i].second.second;
uf.unite(U, V);
if (W <= uf.weight(U))
e[i].first.second = 1;
}
sort(e.rbegin(), e.rend());
set<P> s;
for (int i = 0; i < M; i++) {
int W = e[i].first.first, A = e[i].first.second, U = e[i].second.first,
V = e[i].second.second;
if (s.count(P(U, V)))
continue;
if (A == 0)
continue;
s.count(P(U, V));
queue<int> que;
que.push(U);
que.push(V);
while (que.size()) {
int p = que.front();
que.pop();
for (auto q : edge[p]) {
int t = q.first, WE = q.second;
if (s.count(P(min(p, t), max(p, t))))
continue;
if (WE > W)
continue;
s.insert(P(min(p, t), max(p, t)));
que.push(t);
}
}
}
cout << M - s.size() << endl;
}
|
replace
| 78 | 79 | 78 | 79 |
0
| |
p03143
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define lscan(x) scanf("%I64d", &x)
#define lprint(x) printf("%I64d", x)
ll gcd(ll a, ll b) {
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll x[111111];
struct UnionFind {
vector<ll> data;
UnionFind(int sz) {
// data.assign(sz, -1);
for (int i = 0; i < sz; i++)
data.pb(-x[i]);
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
ll size(int k) { return (-data[find(k)]); }
};
ll M = 1000000007;
vector<ll> fac(2000011); // n!(mod M)
vector<ll> ifac(2000011); // k!^{M-2} (mod M)
ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
ll mpow2(ll x, ll n, ll mod) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % mod;
x = x * x % mod;
n = n >> 1;
}
return ans;
}
void setcomb() {
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 2000010; i++) {
fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
}
ifac[2000010] = mpow(fac[2000010], M - 2);
for (ll i = 2000010; i > 0; i--) {
ifac[i - 1] = ifac[i] * i % M;
}
}
ll comb(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % M;
return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
return fac[a] * ifac[a - b] % M;
}
long long modinv(long long a) {
long long b = M, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= M;
if (u < 0)
u += M;
return u;
}
ll modinv2(ll a, ll mod) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= mod;
if (u < 0)
u += mod;
return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
int i, j, k, t;
vector<vector<ll>> c(n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
t = 0;
for (k = 0; k < n; k++)
t = (t + a[i][k] * b[k][j] % M) % M;
c[i].push_back(t);
}
}
return c;
}
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <unsigned mod> struct RollingHash {
vector<unsigned> hashed, power;
inline unsigned mul(unsigned a, unsigned b) const {
unsigned long long x = (unsigned long long)a * b;
unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod));
return m;
}
RollingHash(const string &s, unsigned base = 10007) {
int sz = (int)s.size();
hashed.assign(sz + 1, 0);
power.assign(sz + 1, 0);
power[0] = 1;
for (int i = 0; i < sz; i++) {
power[i + 1] = mul(power[i], base);
hashed[i + 1] = mul(hashed[i], base) + s[i];
if (hashed[i + 1] >= mod)
hashed[i + 1] -= mod;
}
}
unsigned get(int l, int r) const {
unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
if (ret >= mod)
ret -= mod;
return ret;
}
unsigned connect(unsigned h1, int h2, int h2len) const {
unsigned ret = mul(h1, power[h2len]) + h2;
if (ret >= mod)
ret -= mod;
return ret;
}
int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) {
int len = min(r1 - l1, r2 - l2);
int low = -1, high = len + 1;
while (high - low > 1) {
int mid = (low + high) / 2;
if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
low = mid;
else
high = mid;
}
return (low);
}
};
using RH = RollingHash<1000000007>;
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
template <typename G> struct DoublingLowestCommonAncestor {
const int LOG;
vector<int> dep;
const G &g;
vector<vector<int>> table;
DoublingLowestCommonAncestor(const G &g)
: g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) {
table.assign(LOG, vector<int>(g.size(), -1));
}
void dfs(int idx, int par, int d) {
table[0][idx] = par;
dep[idx] = d;
for (auto &to : g[idx]) {
if (to != par)
dfs(to, idx, d + 1);
}
}
void build() {
dfs(0, -1, 0);
for (int k = 0; k + 1 < LOG; k++) {
for (int i = 0; i < table[k].size(); i++) {
if (table[k][i] == -1)
table[k + 1][i] = -1;
else
table[k + 1][i] = table[k][table[k][i]];
}
}
}
int query(int u, int v) {
if (dep[u] > dep[v])
swap(u, v);
for (int i = LOG - 1; i >= 0; i--) {
if (((dep[v] - dep[u]) >> i) & 1)
v = table[i][v];
}
if (u == v)
return u;
for (int i = LOG - 1; i >= 0; i--) {
if (table[i][u] != table[i][v]) {
u = table[i][u];
v = table[i][v];
}
}
return table[0][u];
}
};
ll p[111111], ans = 0;
vector<ll> li[111111];
void dfs(ll now, ll flag) {
if (p[now])
flag = 1;
if (!flag)
ans++;
for (auto &e : li[now]) {
dfs(e, flag);
}
}
int main() {
ll n, m, i, a, b, y;
cin >> n >> m;
for (i = 0; i < n; i++)
cin >> x[i];
vector<pair<ll, pair<ll, ll>>> v;
for (i = 0; i < m; i++) {
cin >> a >> b >> y;
a--;
b--;
v.pb(mp(y, mp(a, b)));
}
sort(all(v));
UnionFind uf(n + 1);
ll ma[111111];
for (i = 0; i < n; i++)
ma[i] = -1;
for (i = 0; i < m; i++)
p[i] = 0;
for (i = 0; i < m; i++) {
auto q = v[i];
ll w = q.first, l = q.second.first, r = q.second.second;
if (uf.find(l) == uf.find(r)) {
if (ma[uf.find(l)] != -1) {
li[i].pb(ma[uf.find(l)]);
ma[uf.find(l)] = i;
}
} else {
if (ma[uf.find(l)] != -1)
li[i].pb(ma[uf.find(l)]);
if (ma[uf.find(r)] != -1)
li[i].pb(ma[uf.find(r)]);
uf.unite(l, r);
ma[uf.find(l)] = i;
}
if (w <= uf.size(l))
p[i]++;
}
dfs(m - 1, 0);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define lscan(x) scanf("%I64d", &x)
#define lprint(x) printf("%I64d", x)
ll gcd(ll a, ll b) {
int c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll x[111111];
struct UnionFind {
vector<ll> data;
UnionFind(int sz) {
// data.assign(sz, -1);
for (int i = 0; i < sz; i++)
data.pb(-x[i]);
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
ll size(int k) { return (-data[find(k)]); }
};
ll M = 1000000007;
vector<ll> fac(2000011); // n!(mod M)
vector<ll> ifac(2000011); // k!^{M-2} (mod M)
ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % M;
x = x * x % M;
n = n >> 1;
}
return ans;
}
ll mpow2(ll x, ll n, ll mod) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % mod;
x = x * x % mod;
n = n >> 1;
}
return ans;
}
void setcomb() {
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 2000010; i++) {
fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
}
ifac[2000010] = mpow(fac[2000010], M - 2);
for (ll i = 2000010; i > 0; i--) {
ifac[i - 1] = ifac[i] * i % M;
}
}
ll comb(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % M;
return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
return fac[a] * ifac[a - b] % M;
}
long long modinv(long long a) {
long long b = M, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= M;
if (u < 0)
u += M;
return u;
}
ll modinv2(ll a, ll mod) {
ll b = mod, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= mod;
if (u < 0)
u += mod;
return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
int i, j, k, t;
vector<vector<ll>> c(n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
t = 0;
for (k = 0; k < n; k++)
t = (t + a[i][k] * b[k][j] % M) % M;
c[i].push_back(t);
}
}
return c;
}
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <unsigned mod> struct RollingHash {
vector<unsigned> hashed, power;
inline unsigned mul(unsigned a, unsigned b) const {
unsigned long long x = (unsigned long long)a * b;
unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod));
return m;
}
RollingHash(const string &s, unsigned base = 10007) {
int sz = (int)s.size();
hashed.assign(sz + 1, 0);
power.assign(sz + 1, 0);
power[0] = 1;
for (int i = 0; i < sz; i++) {
power[i + 1] = mul(power[i], base);
hashed[i + 1] = mul(hashed[i], base) + s[i];
if (hashed[i + 1] >= mod)
hashed[i + 1] -= mod;
}
}
unsigned get(int l, int r) const {
unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
if (ret >= mod)
ret -= mod;
return ret;
}
unsigned connect(unsigned h1, int h2, int h2len) const {
unsigned ret = mul(h1, power[h2len]) + h2;
if (ret >= mod)
ret -= mod;
return ret;
}
int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) {
int len = min(r1 - l1, r2 - l2);
int low = -1, high = len + 1;
while (high - low > 1) {
int mid = (low + high) / 2;
if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
low = mid;
else
high = mid;
}
return (low);
}
};
using RH = RollingHash<1000000007>;
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
template <typename G> struct DoublingLowestCommonAncestor {
const int LOG;
vector<int> dep;
const G &g;
vector<vector<int>> table;
DoublingLowestCommonAncestor(const G &g)
: g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) {
table.assign(LOG, vector<int>(g.size(), -1));
}
void dfs(int idx, int par, int d) {
table[0][idx] = par;
dep[idx] = d;
for (auto &to : g[idx]) {
if (to != par)
dfs(to, idx, d + 1);
}
}
void build() {
dfs(0, -1, 0);
for (int k = 0; k + 1 < LOG; k++) {
for (int i = 0; i < table[k].size(); i++) {
if (table[k][i] == -1)
table[k + 1][i] = -1;
else
table[k + 1][i] = table[k][table[k][i]];
}
}
}
int query(int u, int v) {
if (dep[u] > dep[v])
swap(u, v);
for (int i = LOG - 1; i >= 0; i--) {
if (((dep[v] - dep[u]) >> i) & 1)
v = table[i][v];
}
if (u == v)
return u;
for (int i = LOG - 1; i >= 0; i--) {
if (table[i][u] != table[i][v]) {
u = table[i][u];
v = table[i][v];
}
}
return table[0][u];
}
};
ll p[111111], ans = 0;
vector<ll> li[111111];
void dfs(ll now, ll flag) {
if (p[now])
flag = 1;
if (!flag)
ans++;
for (auto &e : li[now]) {
dfs(e, flag);
}
}
int main() {
ll n, m, i, a, b, y;
cin >> n >> m;
for (i = 0; i < n; i++)
cin >> x[i];
vector<pair<ll, pair<ll, ll>>> v;
for (i = 0; i < m; i++) {
cin >> a >> b >> y;
a--;
b--;
v.pb(mp(y, mp(a, b)));
}
sort(all(v));
UnionFind uf(n + 1);
ll ma[111111];
for (i = 0; i < n; i++)
ma[i] = -1;
for (i = 0; i < m; i++)
p[i] = 0;
for (i = 0; i < m; i++) {
auto q = v[i];
ll w = q.first, l = q.second.first, r = q.second.second;
if (uf.find(l) == uf.find(r)) {
if (ma[uf.find(l)] != -1) {
li[i].pb(ma[uf.find(l)]);
ma[uf.find(l)] = i;
}
} else {
if (ma[uf.find(l)] != -1)
li[i].pb(ma[uf.find(l)]);
if (ma[uf.find(r)] != -1)
li[i].pb(ma[uf.find(r)]);
uf.unite(l, r);
ma[uf.find(l)] = i;
}
if (w <= uf.size(l))
p[i]++;
}
if (m > 0)
dfs(m - 1, 0);
cout << ans << endl;
}
|
replace
| 423 | 424 | 423 | 425 |
0
| |
p03144
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define poly vector<ll>
#define sqr(x) ((x) * (x))
#define mp make_pair
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
inline void writeln(ll a) {
write(a);
puts("");
}
const int N = 200005;
const ll inf = 1e18;
vector<int> v[N];
poly me(poly a, poly b) {
int n = a.size(), m = b.size(), i = 0, j = 0;
poly c(n + m - 1);
while (i < n && j < m) {
c[i + j] = a[i] + b[j];
if ((i + 1 < n && (j + 1 == m || a[i + 1] + b[j] > a[i] + b[j + 1])))
i++;
else
j++;
}
return c;
}
poly operator+(poly a, poly b) {
poly A[2], B[2];
for (int i = 0; i < 2; i++) {
for (unsigned j = i; j < a.size(); j += 2)
A[i].push_back(a[j]);
for (unsigned j = i; j < b.size(); j += 2)
B[i].push_back(b[j]);
}
poly ans(a.size() + b.size() - 1);
for (auto &i : ans)
i = -inf;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
poly c = me(A[i], B[j]);
for (unsigned k = 0; k < c.size(); k++) {
ans[k * 2 + i + j] = max(ans[k * 2 + i + j], c[k]);
}
}
}
return ans;
}
poly solve(int l, int r) {
if (l == r) {
sort(v[l].begin(), v[l].end());
int m = v[l].size();
poly ans(m + 1);
for (int i = 1; i <= m; i++)
ans[i] = ans[i - 1] + v[l][m - i];
ans[1] = -inf; // cout<<l<<" fjzzq "<<ans.size()<<endl;
return ans;
}
int mid = (l + r) >> 1;
return solve(l, mid) + solve(mid + 1, r);
}
signed main() {
int n = read(), k = read();
for (int i = 1; i <= n; i++) {
int c = read(), w = read();
v[c].push_back(w);
}
poly ans(n + 1);
for (auto &i : ans)
i = -inf;
for (int i = 1; i <= 3; i++) {
for (int i = 1; i <= k; i++)
swap(v[i], v[(rand() << 15 ^ rand()) % i + 1]);
poly zs = solve(1, k);
for (int i = 1; i <= n; i++)
ans[i] = max(ans[i], zs[i]);
}
for (int i = 1; i <= n; i++) {
if (ans[i] < 0)
puts("-1");
else
writeln(ans[i]);
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define poly vector<ll>
#define sqr(x) ((x) * (x))
#define mp make_pair
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
inline void writeln(ll a) {
write(a);
puts("");
}
const int N = 200005;
const ll inf = 1e18;
vector<int> v[N];
poly me(poly a, poly b) {
int n = a.size(), m = b.size(), i = 0, j = 0;
poly c(n + m - 1);
while (i < n && j < m) {
c[i + j] = a[i] + b[j];
if ((i + 1 < n && (j + 1 == m || a[i + 1] + b[j] > a[i] + b[j + 1])))
i++;
else
j++;
}
return c;
}
poly operator+(poly a, poly b) {
poly A[2], B[2];
for (int i = 0; i < 2; i++) {
for (unsigned j = i; j < a.size(); j += 2)
A[i].push_back(a[j]);
for (unsigned j = i; j < b.size(); j += 2)
B[i].push_back(b[j]);
}
poly ans(a.size() + b.size() - 1);
for (auto &i : ans)
i = -inf;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
poly c = me(A[i], B[j]);
for (unsigned k = 0; k < c.size(); k++) {
ans[k * 2 + i + j] = max(ans[k * 2 + i + j], c[k]);
}
}
}
return ans;
}
poly solve(int l, int r) {
if (l == r) {
sort(v[l].begin(), v[l].end());
int m = v[l].size();
poly ans(m + 1);
for (int i = 1; i <= m; i++)
ans[i] = ans[i - 1] + v[l][m - i];
ans[1] = -inf; // cout<<l<<" fjzzq "<<ans.size()<<endl;
return ans;
}
int mid = (l + r) >> 1;
return solve(l, mid) + solve(mid + 1, r);
}
signed main() {
int n = read(), k = read();
for (int i = 1; i <= n; i++) {
int c = read(), w = read();
v[c].push_back(w);
}
poly ans(n + 1);
for (auto &i : ans)
i = -inf;
for (int i = 1; i <= 3; i++) {
for (int i = 1; i <= k; i++)
swap(v[i], v[((ll)rand() << 15 ^ rand()) % i + 1]);
poly zs = solve(1, k);
for (int i = 1; i <= n; i++)
ans[i] = max(ans[i], zs[i]);
}
for (int i = 1; i <= n; i++) {
if (ans[i] < 0)
puts("-1");
else
writeln(ans[i]);
}
}
|
replace
| 101 | 102 | 101 | 102 |
0
| |
p03144
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
using int64 = long long;
const int64 inf = 1000000000000ll;
struct Color {
std::vector<int> costs;
size_t pos{0};
int id;
int64 cost_n(int n) {
if (n == 0) {
if (pos < 3) {
return -inf;
}
return -costs[pos - 1];
}
if (pos == 0 && n < 2) {
return -1;
}
if (pos + n > costs.size()) {
return -1;
}
int64 res = 0;
for (int i = 0; i < n; i++) {
res += costs[pos + i];
}
return res;
}
auto key(int d) { return std::make_pair(-cost_n(d), id); }
};
void relax(int64 &x, int64 v) {
if (x < v) {
x = v;
}
}
std::vector<int64> solve(int n, int k, std::vector<Color> colors) {
for (auto &c : colors) {
std::sort(c.costs.begin(), c.costs.end(), std::greater<>());
}
std::vector<int64> res(n + 1, -1);
const int maxd = 3;
std::set<std::pair<int64, int>> best[maxd + 1];
auto add = [&](int id) {
for (int d = 0; d <= maxd; d++) {
best[d].insert(colors[id].key(d));
}
};
auto remove = [&](int id) {
for (int d = 0; d <= maxd; d++) {
best[d].erase(colors[id].key(d));
}
};
for (int i = 0; i < k; i++) {
add(i);
}
int cnt = 0;
int64 cost = 0;
while (cnt < n) {
for (int d = 1; d <= maxd; d++) {
auto x = *best[d].begin();
if (x.first > 0) {
continue;
}
relax(res[cnt + d], cost - x.first);
}
auto one = *best[1].begin();
auto two = *best[2].begin();
if (one.first > 0 || one.first * 2 >= two.first) {
cnt += 2;
cost -= two.first;
remove(two.second);
colors[two.second].pos += 2;
add(two.second);
// printf("two");
} else {
cnt += 1;
cost -= one.first;
remove(one.second);
colors[one.second].pos += 1;
add(one.second);
// printf("one");
}
// printf("?%d %lld\n", cnt, cost);
relax(res[cnt], cost);
{
auto x = *best[0].begin();
if (x.first != inf) {
relax(res[cnt - 1], cost - x.first);
}
}
}
res[0] = 0;
return res;
}
void dfs(int i, int cnt, int64 cost, std::vector<int64> &res,
std::vector<Color> &colors, int k) {
if (i == k) {
relax(res[cnt], cost);
return;
}
int add_cnt = 0;
int64 add_cost = 0;
dfs(i + 1, cnt, cost, res, colors, k);
for (int x : colors[i].costs) {
add_cnt++;
add_cost += x;
if (add_cnt >= 2) {
dfs(i + 1, cnt + add_cnt, cost + add_cost, res, colors, k);
}
}
}
std::vector<int64> solve_slow(int n, int k, std::vector<Color> colors) {
for (auto &c : colors) {
std::sort(c.costs.begin(), c.costs.end(), std::greater<>());
}
std::vector<int64> res(n + 1, -1);
dfs(0, 0, 0, res, colors, k);
return res;
}
void stress() {
int test_i = 0;
while (true) {
printf("test %d\n", test_i++);
int n = 0;
int k = rand() % 2 + 5;
std::vector<Color> colors(k);
for (int i = 0; i < k; i++) {
int cnt = rand() % 4 + 2;
colors[i].id = i;
for (int j = 0; j < cnt; j++) {
colors[i].costs.push_back(rand() % 5 + 1);
n++;
}
}
for (auto &c : colors) {
std::sort(c.costs.begin(), c.costs.end(), std::greater<>());
}
auto res = solve(n, k, colors);
auto res2 = solve_slow(n, k, colors);
if (res != res2) {
printf("mismatch\n");
printf("k = %d\n", k);
for (int i = 0; i < k; i++) {
for (int c : colors[i].costs) {
printf("%d ", c);
}
printf("\n");
}
for (size_t i = 2; i < res.size(); i++) {
printf("%d: %lld vs %lld\n", (int)i, res[i], res2[i]);
}
std::exit(1);
}
}
}
int main(void) {
int n, k;
// stress();
while (scanf("%d%d", &n, &k) == 2) {
std::vector<Color> colors(k);
for (int i = 0; i < n; i++) {
int c, v;
scanf("%d%d", &c, &v);
colors[c - 1].costs.push_back(v);
}
for (int i = 0; i < k; i++) {
colors[i].id = i;
}
auto res = solve(n, k, colors);
auto res2 = solve_slow(n, k, colors);
if (res != res2) {
printf("mismatch\n");
}
for (int i = 1; i <= n; i++) {
printf("%lld\n", res[i]);
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
using int64 = long long;
const int64 inf = 1000000000000ll;
struct Color {
std::vector<int> costs;
size_t pos{0};
int id;
int64 cost_n(int n) {
if (n == 0) {
if (pos < 3) {
return -inf;
}
return -costs[pos - 1];
}
if (pos == 0 && n < 2) {
return -1;
}
if (pos + n > costs.size()) {
return -1;
}
int64 res = 0;
for (int i = 0; i < n; i++) {
res += costs[pos + i];
}
return res;
}
auto key(int d) { return std::make_pair(-cost_n(d), id); }
};
void relax(int64 &x, int64 v) {
if (x < v) {
x = v;
}
}
std::vector<int64> solve(int n, int k, std::vector<Color> colors) {
for (auto &c : colors) {
std::sort(c.costs.begin(), c.costs.end(), std::greater<>());
}
std::vector<int64> res(n + 1, -1);
const int maxd = 3;
std::set<std::pair<int64, int>> best[maxd + 1];
auto add = [&](int id) {
for (int d = 0; d <= maxd; d++) {
best[d].insert(colors[id].key(d));
}
};
auto remove = [&](int id) {
for (int d = 0; d <= maxd; d++) {
best[d].erase(colors[id].key(d));
}
};
for (int i = 0; i < k; i++) {
add(i);
}
int cnt = 0;
int64 cost = 0;
while (cnt < n) {
for (int d = 1; d <= maxd; d++) {
auto x = *best[d].begin();
if (x.first > 0) {
continue;
}
relax(res[cnt + d], cost - x.first);
}
auto one = *best[1].begin();
auto two = *best[2].begin();
if (one.first > 0 || one.first * 2 >= two.first) {
cnt += 2;
cost -= two.first;
remove(two.second);
colors[two.second].pos += 2;
add(two.second);
// printf("two");
} else {
cnt += 1;
cost -= one.first;
remove(one.second);
colors[one.second].pos += 1;
add(one.second);
// printf("one");
}
// printf("?%d %lld\n", cnt, cost);
relax(res[cnt], cost);
{
auto x = *best[0].begin();
if (x.first != inf) {
relax(res[cnt - 1], cost - x.first);
}
}
}
res[0] = 0;
return res;
}
void dfs(int i, int cnt, int64 cost, std::vector<int64> &res,
std::vector<Color> &colors, int k) {
if (i == k) {
relax(res[cnt], cost);
return;
}
int add_cnt = 0;
int64 add_cost = 0;
dfs(i + 1, cnt, cost, res, colors, k);
for (int x : colors[i].costs) {
add_cnt++;
add_cost += x;
if (add_cnt >= 2) {
dfs(i + 1, cnt + add_cnt, cost + add_cost, res, colors, k);
}
}
}
std::vector<int64> solve_slow(int n, int k, std::vector<Color> colors) {
for (auto &c : colors) {
std::sort(c.costs.begin(), c.costs.end(), std::greater<>());
}
std::vector<int64> res(n + 1, -1);
dfs(0, 0, 0, res, colors, k);
return res;
}
void stress() {
int test_i = 0;
while (true) {
printf("test %d\n", test_i++);
int n = 0;
int k = rand() % 2 + 5;
std::vector<Color> colors(k);
for (int i = 0; i < k; i++) {
int cnt = rand() % 4 + 2;
colors[i].id = i;
for (int j = 0; j < cnt; j++) {
colors[i].costs.push_back(rand() % 5 + 1);
n++;
}
}
for (auto &c : colors) {
std::sort(c.costs.begin(), c.costs.end(), std::greater<>());
}
auto res = solve(n, k, colors);
auto res2 = solve_slow(n, k, colors);
if (res != res2) {
printf("mismatch\n");
printf("k = %d\n", k);
for (int i = 0; i < k; i++) {
for (int c : colors[i].costs) {
printf("%d ", c);
}
printf("\n");
}
for (size_t i = 2; i < res.size(); i++) {
printf("%d: %lld vs %lld\n", (int)i, res[i], res2[i]);
}
std::exit(1);
}
}
}
int main(void) {
int n, k;
// stress();
while (scanf("%d%d", &n, &k) == 2) {
std::vector<Color> colors(k);
for (int i = 0; i < n; i++) {
int c, v;
scanf("%d%d", &c, &v);
colors[c - 1].costs.push_back(v);
}
for (int i = 0; i < k; i++) {
colors[i].id = i;
}
auto res = solve(n, k, colors);
// auto res2 = solve_slow(n, k, colors);
// if (res != res2) {
// printf("mismatch\n");
// }
for (int i = 1; i <= n; i++) {
printf("%lld\n", res[i]);
}
}
return 0;
}
|
replace
| 179 | 183 | 179 | 183 |
TLE
| |
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge {
ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
vi ABC;
signed main() {
ABC.resize(3);
REP(i, 3)
cin >> ABC[3];
sort(ALL(ABC));
cout << ABC[0] * ABC[1] / 2 << endl;
// system("pause");
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge {
ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
vi ABC;
signed main() {
ABC.resize(3);
REP(i, 3)
cin >> ABC[i];
sort(ALL(ABC));
cout << ABC[0] * ABC[1] / 2 << endl;
// system("pause");
}
|
replace
| 36 | 37 | 36 | 37 |
0
| |
p03145
|
Python
|
Runtime Error
|
LL = list(map(int, input().split())).sort()
R = LL[0] * LL[1] // 2
print(R)
|
LL = list(map(int, input().split()))
LL.sort()
R = LL[0] * LL[1] // 2
print(R)
|
replace
| 0 | 1 | 0 | 2 |
TypeError: 'NoneType' object is not subscriptable
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s826877996.py", line 2, in <module>
R = LL[0] * LL[1] // 2
TypeError: 'NoneType' object is not subscriptable
|
p03145
|
Python
|
Runtime Error
|
h, w, _ = [int(i) for i in input()]
ans = h * w // 2
print(ans)
|
h, w, _ = [int(i) for i in input().split()]
ans = h * w // 2
print(ans)
|
replace
| 0 | 1 | 0 | 1 |
ValueError: invalid literal for int() with base 10: ' '
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s129162499.py", line 1, in <module>
h, w, _ = [int(i) for i in input()]
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s129162499.py", line 1, in <listcomp>
h, w, _ = [int(i) for i in input()]
ValueError: invalid literal for int() with base 10: ' '
|
p03145
|
Python
|
Runtime Error
|
def main() -> None:
ab, bc, ca = map(int, input())
print(ab * bc // 2)
if __name__ == "__main__":
main()
|
def main() -> None:
ab, bc, ca = map(int, input().split())
print(ab * bc // 2)
if __name__ == "__main__":
main()
|
replace
| 1 | 2 | 1 | 2 |
ValueError: invalid literal for int() with base 10: ' '
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s388138041.py", line 7, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s388138041.py", line 2, in main
ab, bc, ca = map(int, input())
ValueError: invalid literal for int() with base 10: ' '
|
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll>;
using vs = vector<string>;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) range(i, 0, n)
#define range(i, a, n) for (ll i = (a); i < (n); i++)
#define LINF ((ll)1ll << 60)
#define INF ((int)1 << 30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout << setprecision(a) << fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "[" << p.first << ", " << p.second << "]";
return os;
};
template <class S> auto &operator<<(ostream &os, vector<S> t) {
bool a = 1;
for (auto s : t) {
os << (a ? "" : " ") << s;
a = 0;
}
return os;
}
template <class S> void tf(bool b, S t, S f) { cout << (b ? t : f) << endl; }
void OUT(bool b) { tf(b, "YES", "NO"); }
void Out(bool b) { tf(b, "Yes", "No"); }
void out(bool b) { tf(b, "yes", "no"); }
template <class T> void puta(T &&t) { cout << t << endl; }
template <class H, class... T> void puta(H &&h, T &&...t) {
cout << h << ' ';
puta(t...);
}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int bsr(int x) { return 31 - __builtin_clz(x); }
int bsr(ll x) { return 63 - __builtin_clzll(x); }
int bsf(int x) { return __builtin_ctz(x); }
int bsf(ll x) { return __builtin_ctzll(x); }
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/*他のライブラリを入れる場所*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vi a;
rep(i, 3) cin >> a[i];
sort(all(a));
cout << a[0] * a[1] / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll>;
using vs = vector<string>;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) range(i, 0, n)
#define range(i, a, n) for (ll i = (a); i < (n); i++)
#define LINF ((ll)1ll << 60)
#define INF ((int)1 << 30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout << setprecision(a) << fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "[" << p.first << ", " << p.second << "]";
return os;
};
template <class S> auto &operator<<(ostream &os, vector<S> t) {
bool a = 1;
for (auto s : t) {
os << (a ? "" : " ") << s;
a = 0;
}
return os;
}
template <class S> void tf(bool b, S t, S f) { cout << (b ? t : f) << endl; }
void OUT(bool b) { tf(b, "YES", "NO"); }
void Out(bool b) { tf(b, "Yes", "No"); }
void out(bool b) { tf(b, "yes", "no"); }
template <class T> void puta(T &&t) { cout << t << endl; }
template <class H, class... T> void puta(H &&h, T &&...t) {
cout << h << ' ';
puta(t...);
}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int bsr(int x) { return 31 - __builtin_clz(x); }
int bsr(ll x) { return 63 - __builtin_clzll(x); }
int bsf(int x) { return __builtin_ctz(x); }
int bsf(ll x) { return __builtin_ctzll(x); }
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/*他のライブラリを入れる場所*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vi a(3);
rep(i, 3) cin >> a[i];
sort(all(a));
cout << a[0] * a[1] / 2 << endl;
return 0;
}
|
replace
| 76 | 77 | 76 | 77 |
-11
| |
p03145
|
C++
|
Runtime Error
|
#include <stdio.h>
int main() {
int a, b, Area;
printf("Enter the values of a and b : \n");
scanf("%d %d %d", &a, &b);
Area = (a + b) / 2;
printf("Area of a triangle = %d \n", Area);
return 0;
}
|
#include <stdio.h>
int main() {
int a, b, c;
int answer;
scanf("%d %d %d", &a, &b, &c);
answer = a * b / 2;
printf("%d", answer);
return 0;
}
|
replace
| 4 | 10 | 4 | 9 |
-11
| |
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
printf("%d", a * b * c / 2 / max({a, b, c}));
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%d", a * b * c / 2 / max({a, b, c}));
}
|
insert
| 6 | 6 | 6 | 7 |
0
| |
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
ll mod = 1e9 + 7;
int main() {
int a, b;
scanf("%d%d%d", &a, &b);
int ans = a * b / 2;
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
ll mod = 1e9 + 7;
int main() {
int a, b;
scanf("%d%d", &a, &b);
int ans = a * b / 2;
printf("%d\n", ans);
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
-11
| |
p03145
|
Python
|
Runtime Error
|
def run(a):
return a[0] * a[1] // 2
def main():
a = map(int, input().split())
print(run(a))
if __name__ == "__main__":
main()
|
def run(a):
return a[0] * a[1] // 2
def main():
a = list(map(int, input().split()))
print(run(a))
if __name__ == "__main__":
main()
|
replace
| 5 | 6 | 5 | 6 |
TypeError: 'map' object is not subscriptable
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s623921707.py", line 11, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s623921707.py", line 7, in main
print(run(a))
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s623921707.py", line 2, in run
return a[0] * a[1] // 2
TypeError: 'map' object is not subscriptable
|
p03145
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
return (a * b) / 2;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << (a * b) / 2 << endl;
return 0;
return 0;
}
|
replace
| 9 | 10 | 9 | 11 |
6
| |
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
return a * b * c / max(a, max(b, c)) / 2;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << (a * b * c / 2 / max(a, max(b, c))) << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 8 |
6
| |
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define fast_io() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x, y) fixed << setprecision(y) << x
#define ll long long
#define ld long double
#define lop(i, a, b) for (ll i = a; i < b; i++)
#define lopr(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast_io()
int a,
b, c;
cin >> a >> b >> c;
cout << (b * a) / 2;
return 0;
}
|
#include <bits/stdc++.h>
#define fast_io() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x, y) fixed << setprecision(y) << x
#define ll long long
#define ld long double
#define lop(i, a, b) for (ll i = a; i < b; i++)
#define lopr(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
using namespace std;
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
fast_io()
int a,
b, c;
cin >> a >> b >> c;
cout << (b * a) / 2;
return 0;
}
|
replace
| 21 | 25 | 21 | 25 |
0
| |
p03145
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
return (a * b / 2);
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a * b / 2);
return 0;
}
|
replace
| 9 | 10 | 9 | 11 |
6
| |
p03145
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
const int maxa = 3;
int a[maxa];
int main() {
int mini1 = 0, mini2 = 0, num1, num2, area;
for (int i = 0; i < 3; i++) {
cin >> a[i];
if (mini1 <= a[i]) {
mini1 = a[i];
num1 = i;
}
}
a[num1] = 0;
for (int j = 0; j < 3; j--) {
if (mini1 >= a[j]) {
mini1 = a[j];
}
}
for (int k = 0; k < 3; k++) {
if (mini2 <= a[k]) {
mini2 = a[k];
num2 = k;
}
}
a[num2] = 0;
for (int l = 3; l != 0; l--) {
if (mini2 >= a[l]) {
mini2 = a[l];
}
}
area = (mini1 * mini2) / 2;
cout << area;
return 0;
}
|
#include <iostream>
using namespace std;
const int maxa = 3;
int a[maxa];
int main() {
int a, b, c, area;
cin >> a >> b >> c;
area = (a * b) / 2;
cout << area;
return 0;
}
|
replace
| 8 | 35 | 8 | 11 |
TLE
| |
p03145
|
Python
|
Runtime Error
|
s = int(input())
an = []
an.append(s)
n = s
while an.count(4) != 2:
if n % 2 == 0:
n /= 2
an.append(int(n))
else:
n = 3 * n + 1
an.append(int(n))
if an.index(1 or 2) == 0:
print(4)
else:
print(an.index(4) + 4)
|
x, y, z = map(int, input().split())
print(int(x * y / 2))
|
replace
| 0 | 15 | 0 | 2 |
ValueError: invalid literal for int() with base 10: '3 4 5'
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s174683495.py", line 1, in <module>
s = int(input())
ValueError: invalid literal for int() with base 10: '3 4 5'
|
p03145
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// start
vector<int> x;
cin >> x.at(0);
cin >> x.at(1);
cin >> x.at(2);
sort(all(x));
cout << x.at(0) * x.at(1) / 2 << endl;
// end
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// start
vector<int> x(3);
cin >> x.at(0);
cin >> x.at(1);
cin >> x.at(2);
sort(all(x));
cout << x.at(0) * x.at(1) / 2 << endl;
// end
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
-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)
|
p03145
|
Python
|
Runtime Error
|
AB, BC, CA = int(input())
print((AB * BC) // 2)
|
AB, BC, CA = map(int, input().split())
print((AB * BC) // 2)
|
replace
| 0 | 1 | 0 | 1 |
ValueError: invalid literal for int() with base 10: '3 4 5'
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03145/Python/s114139853.py", line 1, in <module>
AB, BC, CA = int(input())
ValueError: invalid literal for int() with base 10: '3 4 5'
|
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int s;
cin >> s;
vector<int> f(1000000);
f.at(0) = s;
rep(i, 1000000) {
if (f.at(i) % 2 == 0)
f.at(i + 1) = f.at(i) / 2;
else
f.at(i + 1) = 3 * f.at(i) + 1;
}
for (int i = 0; i < 1000000 - 1; i++) {
for (int j = i + 1; j < 1000000; j++) {
if (f.at(i) == f.at(j)) {
cout << j + 1 << endl;
return 0;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int s;
cin >> s;
vector<int> f(1000000);
f.at(0) = s;
rep(i, 1000000 - 1) {
if (f.at(i) % 2 == 0)
f.at(i + 1) = f.at(i) / 2;
else
f.at(i + 1) = 3 * f.at(i) + 1;
}
for (int i = 0; i < 1000000 - 1; i++) {
for (int j = i + 1; j < 1000000; j++) {
if (f.at(i) == f.at(j)) {
cout << j + 1 << endl;
return 0;
}
}
}
}
|
replace
| 8 | 9 | 8 | 9 |
-6
|
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 1000000) >= this->size() (which is 1000000)
|
p03146
|
C++
|
Runtime Error
|
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int a[100010];
int main(int argc, char const *argv[]) {
int s;
cin >> s;
a[0] = s;
for (int i = 0; i < 100009; i++) {
if (a[i] % 2 == 0) {
a[i + 1] = a[i] / 2;
} else {
a[i + 1] = a[i] * 3 + 1;
}
}
int b[1000];
for (int i = 0; i < 1000; i++) {
b[i] = 0;
}
int ans = 0;
for (int i = 0; i < 100010; i++) {
b[a[i]]++;
if (b[a[i]] == 2) {
ans = i + 1;
break;
}
}
cout << ans << endl;
return 0;
}
|
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int a[100010];
int main(int argc, char const *argv[]) {
int s;
cin >> s;
a[0] = s;
for (int i = 0; i < 100009; i++) {
if (a[i] % 2 == 0) {
a[i + 1] = a[i] / 2;
} else {
a[i + 1] = a[i] * 3 + 1;
}
}
int b[10000];
for (int i = 0; i < 10000; i++) {
b[i] = 0;
}
int ans = 0;
for (int i = 0; i < 100010; i++) {
b[a[i]]++;
if (b[a[i]] == 2) {
ans = i + 1;
break;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 21 | 23 | 21 | 23 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_SIZE = 1000000;
vector<long long> a(100);
int s;
void solve() {
cin >> s;
a[1] = s;
for (long long i = 2; i < MAX_SIZE; i++) {
if (a[i - 1] % 2 == 0) {
a[i] = a[i - 1] / 2;
} else {
a[i] = (3 * a[i - 1]) + 1;
}
for (long long j = 1; j < i; j++) {
if (a[i] == a[j]) {
cout << i << endl;
return;
}
}
}
return;
}
// 逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 組み合わせ
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(int args, char *argv[]) { solve(); }
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_SIZE = 1000000;
vector<long long> a(1000000);
int s;
void solve() {
cin >> s;
a[1] = s;
for (long long i = 2; i < MAX_SIZE; i++) {
if (a[i - 1] % 2 == 0) {
a[i] = a[i - 1] / 2;
} else {
a[i] = (3 * a[i - 1]) + 1;
}
for (long long j = 1; j < i; j++) {
if (a[i] == a[j]) {
cout << i << endl;
return;
}
}
}
return;
}
// 逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 組み合わせ
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(int args, char *argv[]) { solve(); }
|
replace
| 28 | 29 | 28 | 29 |
0
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
set<int> st;
int x = s;
while (st.count(x) == 0) {
st.insert(x);
if (x % 2 == 0) {
x /= 2;
} else {
x *= 3;
x + 1;
}
}
cout << st.size() + 1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
set<int> st;
int x = s;
while (st.count(x) == 0) {
st.insert(x);
if (x % 2 == 0) {
x /= 2;
} else {
x = x * 3 + 1;
}
}
cout << st.size() + 1 << endl;
}
|
replace
| 13 | 15 | 13 | 14 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll a;
cin >> a;
vector<ll> vec(100, -1);
vec.at(a) = 1;
for (ll i = 0;; i++) {
if (a % 2 == 0) {
a = a / 2;
} else {
a = 3 * a + 1;
}
if (a <= 100) {
if (vec.at(a) == -1) {
vec.at(a) = 1;
} else {
cout << i + 2 << endl;
return 0;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll a;
cin >> a;
vector<ll> vec(101, -1);
vec.at(a) = 1;
for (ll i = 0;; i++) {
if (a % 2 == 0) {
a = a / 2;
} else {
a = 3 * a + 1;
}
if (a <= 100) {
if (vec.at(a) == -1) {
vec.at(a) = 1;
} else {
cout << i + 2 << endl;
return 0;
}
}
}
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
#define MAX_N 1000010
/* ACはうれCすぎてうれD */
int main(void) {
int s;
cin >> s;
ll ans = 1;
while (s != 4 || s != 2 || s != 1) {
ans += 1;
if (s % 2 == 0) {
s = s / 2;
} else {
s = 3 * s + 1;
}
}
cout << ans + 3;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF (1 << 29)
#define MAX_N 1000010
/* ACはうれCすぎてうれD */
int main(void) {
int s;
cin >> s;
ll ans = 1;
while (s != 4 && s != 2 &&
s != 1) { // 2 1 4 2 なら、4 より先に 2が重複するじゃん
// ずっと 4 しか考えてなかった。
ans += 1;
if (s % 2 == 0) {
s = s / 2;
} else {
s = 3 * s + 1;
}
}
cout << ans + 3;
return 0;
}
|
replace
| 12 | 13 | 12 | 15 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
vector<int> ans(1000000000, 0);
for (int i = 0; i < 1000000; i++) {
if (s % 2 == 0) {
s /= 2;
ans[s]++;
} else {
s = 3 * s + 1;
ans[s]++;
}
if (ans[s] == 2) {
cout << i + 2 << endl;
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
vector<int> ans(100000000, 0);
ans[s]++;
for (int i = 0; i < 1000000; i++) {
if (s % 2 == 0) {
s /= 2;
ans[s]++;
} else {
s = 3 * s + 1;
ans[s]++;
}
if (ans[s] == 2) {
cout << i + 2 << endl;
return 0;
}
}
}
|
replace
| 5 | 6 | 5 | 7 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int round(int a, int b) {
if ((a % b) * 2 >= b) {
return (a / b) + 1;
}
return a / b;
}
int gcd(int a, int b) {
int c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
} // 最大公約数
int lcm(int a, int b) {
int c = gcd(a, b);
a /= c;
return a * b;
} // 最小公倍数
int nCr(int a, int b) {
int i, r = 1;
for (i = 1; i <= b; i++) {
r *= (a + 1 - i);
r /= i;
}
return r;
} // コンビネーション
int nHr(int a, int b) { return nCr(a + b - 1, b); } // 重複組み合わせ
int fact(int a) {
int i, r = 1;
for (i = 1; i <= a; i++) {
r *= i;
}
return r;
} // 階乗
int pow(int a, int b) {
int i, r = 1;
for (i = 1; i <= b; i++) {
r *= a;
}
return r;
} // a~bまでの階乗
int dsum(int x) {
int r = 0;
while (x) {
r += (x % 10);
x /= 10;
}
return r;
} // 数字の各位の和
int dsumb(int x, int b) {
int r = 0;
while (x) {
r += (x % b);
x /= b;
}
return r;
} // b進数の各位の和?
int sankaku(int x) { return ((1 + x) * x) / 2; } // 三角数 xまでの和
// 以下long long ver
long long llmax(long long a, long long b) {
if (a > b) {
return a;
}
return b;
}
long long llmin(long long a, long long b) {
if (a < b) {
return a;
}
return b;
}
long long llzt(long long a, long long b) { return llmax(a, b) - llmin(a, b); }
long long llround(long long a, long long b) {
if ((a % b) * 2 >= b) {
return (a / b) + 1;
}
return a / b;
}
long long llceil(long long a, long long b) {
if (a % b == 0) {
return a / b;
}
return (a / b) + 1;
}
long long llgcd(long long a, long long b) {
long long c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
long long lllcm(long long a, long long b) {
long long c = llgcd(a, b);
a /= c;
return a * b;
}
long long llnCr(long long a, long long b) {
long long i, r = 1;
for (i = 1; i <= b; i++) {
r *= (a + 1 - i);
r /= i;
}
return r;
}
long long llnHr(long long a, long long b) { return llnCr(a + b - 1, b); }
long long llfact(long long a) {
long long i, r = 1;
for (i = 1; i <= a; i++) {
r *= i;
}
return r;
}
long long llpow(long long a, long long b) {
long long i, r = 1;
for (i = 1; i <= b; i++) {
r *= a;
}
return r;
}
long long lldsum(long long x) {
long long r = 0;
while (x) {
r += (x % 10);
x /= 10;
}
return r;
}
long long lldsumb(long long x, long long b) {
long long r = 0;
while (x) {
r += (x % b);
x /= b;
}
return r;
}
long long llsankaku(long long x) { return ((1 + x) * x) / 2; }
// double
double dbmax(double a, double b) {
if (a > b) {
return a;
}
return b;
}
double dbmin(double a, double b) {
if (a < b) {
return a;
}
return b;
}
double dbzt(double a, double b) { return dbmax(a, b) - dbmin(a, b); }
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define forr(i, a, b) \
; \
for (int i = (a); i < (b); i++)
#define clean(arr, val) memset(arr, val, sizeof(arr))
#define forn(i, n) forr(i, 0, n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
/*CODE START HERE*/
int main() {
int s;
cin >> s;
int a_n = s;
int n = 1;
while (a_n != 1 || a_n != 2 || a_n != 4) {
if (a_n % 2 == 1) {
a_n = 3 * a_n + 1;
} else if (a_n % 2 == 0) {
a_n /= 2;
}
n++;
}
cout << n + 3 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int round(int a, int b) {
if ((a % b) * 2 >= b) {
return (a / b) + 1;
}
return a / b;
}
int gcd(int a, int b) {
int c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
} // 最大公約数
int lcm(int a, int b) {
int c = gcd(a, b);
a /= c;
return a * b;
} // 最小公倍数
int nCr(int a, int b) {
int i, r = 1;
for (i = 1; i <= b; i++) {
r *= (a + 1 - i);
r /= i;
}
return r;
} // コンビネーション
int nHr(int a, int b) { return nCr(a + b - 1, b); } // 重複組み合わせ
int fact(int a) {
int i, r = 1;
for (i = 1; i <= a; i++) {
r *= i;
}
return r;
} // 階乗
int pow(int a, int b) {
int i, r = 1;
for (i = 1; i <= b; i++) {
r *= a;
}
return r;
} // a~bまでの階乗
int dsum(int x) {
int r = 0;
while (x) {
r += (x % 10);
x /= 10;
}
return r;
} // 数字の各位の和
int dsumb(int x, int b) {
int r = 0;
while (x) {
r += (x % b);
x /= b;
}
return r;
} // b進数の各位の和?
int sankaku(int x) { return ((1 + x) * x) / 2; } // 三角数 xまでの和
// 以下long long ver
long long llmax(long long a, long long b) {
if (a > b) {
return a;
}
return b;
}
long long llmin(long long a, long long b) {
if (a < b) {
return a;
}
return b;
}
long long llzt(long long a, long long b) { return llmax(a, b) - llmin(a, b); }
long long llround(long long a, long long b) {
if ((a % b) * 2 >= b) {
return (a / b) + 1;
}
return a / b;
}
long long llceil(long long a, long long b) {
if (a % b == 0) {
return a / b;
}
return (a / b) + 1;
}
long long llgcd(long long a, long long b) {
long long c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
long long lllcm(long long a, long long b) {
long long c = llgcd(a, b);
a /= c;
return a * b;
}
long long llnCr(long long a, long long b) {
long long i, r = 1;
for (i = 1; i <= b; i++) {
r *= (a + 1 - i);
r /= i;
}
return r;
}
long long llnHr(long long a, long long b) { return llnCr(a + b - 1, b); }
long long llfact(long long a) {
long long i, r = 1;
for (i = 1; i <= a; i++) {
r *= i;
}
return r;
}
long long llpow(long long a, long long b) {
long long i, r = 1;
for (i = 1; i <= b; i++) {
r *= a;
}
return r;
}
long long lldsum(long long x) {
long long r = 0;
while (x) {
r += (x % 10);
x /= 10;
}
return r;
}
long long lldsumb(long long x, long long b) {
long long r = 0;
while (x) {
r += (x % b);
x /= b;
}
return r;
}
long long llsankaku(long long x) { return ((1 + x) * x) / 2; }
// double
double dbmax(double a, double b) {
if (a > b) {
return a;
}
return b;
}
double dbmin(double a, double b) {
if (a < b) {
return a;
}
return b;
}
double dbzt(double a, double b) { return dbmax(a, b) - dbmin(a, b); }
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define forr(i, a, b) \
; \
for (int i = (a); i < (b); i++)
#define clean(arr, val) memset(arr, val, sizeof(arr))
#define forn(i, n) forr(i, 0, n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
/*CODE START HERE*/
int main() {
int s;
cin >> s;
int a_n = s;
int n = 1;
forn(i, 1000000) {
if (a_n == 1 || a_n == 2 || a_n == 4) {
break;
}
if (a_n % 2 == 1) {
a_n = 3 * a_n + 1;
} else if (a_n % 2 == 0) {
a_n /= 2;
}
n++;
}
cout << n + 3 << endl;
}
|
replace
| 187 | 188 | 187 | 191 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int main() {
int s;
cin >> s;
int n[1000000], i = 0;
while (true) {
n[i] = s;
i++;
if (s % 2 == 0)
s = s / 2;
else
s = 3 * s + 1;
for (int j = 0; j < i; j++) {
if (n[j] == s) {
cout << i + 1 << endl;
return 1;
}
}
}
}
|
#include <iostream>
using namespace std;
int main() {
int s;
cin >> s;
int n[1000000], i = 0;
while (true) {
n[i] = s;
i++;
if (s % 2 == 0)
s = s / 2;
else
s = 3 * s + 1;
for (int j = 0; j < i; j++) {
if (n[j] == s) {
cout << i + 1 << endl;
return 0;
}
}
}
}
|
replace
| 17 | 18 | 17 | 18 |
1
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define _FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define MAXX 1005
int s, t;
bool used[MAXX];
int main() {
_FastIO;
cin >> s;
int ans = 0;
used[s] = true;
t = 1;
while (true) {
t++;
if (s % 2 == 0)
s /= 2;
else
s = s * 3 + 1;
if (used[s]) {
ans = t;
break;
}
used[s] = true;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define _FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define MAXX 100005
int s, t;
bool used[MAXX];
int main() {
_FastIO;
cin >> s;
int ans = 0;
used[s] = true;
t = 1;
while (true) {
t++;
if (s % 2 == 0)
s /= 2;
else
s = s * 3 + 1;
if (used[s]) {
ans = t;
break;
}
used[s] = true;
}
cout << ans << endl;
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
int n;
cin >> n;
int cnt = 4;
while (n != 4 || n != 2 || n != 1) {
if (n % 2 == 1)
n = 3 * n + 1;
else
n /= 2;
cnt++;
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
int n;
cin >> n;
int cnt = 4;
while (1) {
if (n == 4 || n == 2 || n == 1)
break;
if (n % 2 == 1)
n = 3 * n + 1;
else
n /= 2;
cnt++;
}
cout << cnt << endl;
}
|
replace
| 10 | 11 | 10 | 13 |
TLE
| |
p03146
|
Python
|
Runtime Error
|
s = int(input())
a = [s]
z = set(s)
idx = 1
for i in range(10**8):
idx += 1
if a[i] % 2 == 0:
ai = a[i] // 2
else:
ai = 3 * a[i] + 1
if ai in z:
print(idx)
exit()
a.append(ai)
z.add(ai)
|
s = int(input())
a = [s]
z = set([s])
idx = 1
for i in range(10**8):
idx += 1
if a[i] % 2 == 0:
ai = a[i] // 2
else:
ai = 3 * a[i] + 1
if ai in z:
print(idx)
exit()
a.append(ai)
z.add(ai)
|
replace
| 2 | 3 | 2 | 3 |
TypeError: 'int' object is not iterable
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03146/Python/s047431119.py", line 3, in <module>
z = set(s)
TypeError: 'int' object is not iterable
|
p03146
|
C++
|
Runtime Error
|
#define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
bool used[85];
int main() {
int n;
cin >> n;
int ans = 1;
while (!used[n]) {
used[n] = true;
if (n % 2 == 0)
n /= 2;
else
n = 3 * n + 1;
++ans;
}
cout << ans << endl;
return 0;
}
|
#define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
bool used[1010101];
int main() {
int n;
cin >> n;
int ans = 1;
while (!used[n]) {
used[n] = true;
if (n % 2 == 0)
n /= 2;
else
n = 3 * n + 1;
++ans;
}
cout << ans << endl;
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
bool in_judge(std::vector<int> &a) {
int n = a.size();
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[n - 1]) {
return true;
}
}
return false;
}
int main() {
int s;
std::cin >> s;
std::vector<int> a(1, s);
for (int i = 1;; i++) {
if (a[i - 1] % 2 == 0) {
a.push_back(a[i - 1] / 2);
} else {
a.push_back(3 * a[i - 1] + 1);
}
if (in_judge(a)) {
std::cout << i + 1 << std::endl;
return 9;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
bool in_judge(std::vector<int> &a) {
int n = a.size();
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[n - 1]) {
return true;
}
}
return false;
}
int main() {
int s;
std::cin >> s;
std::vector<int> a(1, s);
for (int i = 1;; i++) {
if (a[i - 1] % 2 == 0) {
a.push_back(a[i - 1] / 2);
} else {
a.push_back(3 * a[i - 1] + 1);
}
if (in_judge(a)) {
std::cout << i + 1 << std::endl;
return 0;
}
}
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
9
| |
p03146
|
C++
|
Runtime Error
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
int a[1000005], n;
for (int i = 0; i < 10000005; i++) {
a[i] = 0;
}
scanf("%d", &n);
for (int i = 1; i < 1000005; i++) {
a[n]++;
if (a[n] == 2) {
printf("%d\n", i);
break;
}
if (n % 2 == 0) {
n = n / 2;
} else {
n = n * 3 + 1;
}
}
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
int a[1000005], n;
for (int i = 0; i < 1000005; i++) {
a[i] = 0;
}
scanf("%d", &n);
for (int i = 1; i < 1000005; i++) {
a[n]++;
if (a[n] == 2) {
printf("%d\n", i);
break;
}
if (n % 2 == 0) {
n = n / 2;
} else {
n = n * 3 + 1;
}
}
}
|
replace
| 6 | 7 | 6 | 7 |
-11
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define tii tuple<int, int, int>
signed main() {
int S;
cin >> S;
int ans = 1;
bitset<1000> A;
A.set(S);
while (1) {
ans++;
if (S % 2 == 0) {
S /= 2;
} else {
S = 3 * S + 1;
}
if (A.test(S)) {
cout << ans << endl;
break;
}
A.set(S);
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define tii tuple<int, int, int>
signed main() {
int S;
cin >> S;
int ans = 1;
bitset<100000> A;
A.set(S);
while (1) {
ans++;
if (S % 2 == 0) {
S /= 2;
} else {
S = 3 * S + 1;
}
if (A.test(S)) {
cout << ans << endl;
break;
}
A.set(S);
}
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int main() {
int a[100000], i, j;
cin >> a[0];
for (i = 0;; i++) {
if (a[i] % 2 == 0)
a[i + 1] = a[i] / 2;
else
a[i + 1] = 3 * a[i] + 1;
for (j = 0; j < i + 1; j++) {
if (a[i + 1] == a[j]) {
cout << i + 1;
break;
}
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a[100000], i, j;
cin >> a[0];
for (i = 0;; i++) {
if (a[i] % 2 == 0)
a[i + 1] = a[i] / 2;
else
a[i + 1] = 3 * a[i] + 1;
for (j = 0; j < i + 1; j++) {
if (a[i + 1] == a[j]) {
cout << i + 2;
return 0;
}
}
}
return 0;
}
|
replace
| 12 | 14 | 12 | 14 |
-11
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int memo[350];
int collaz(int x) {
if (x % 2 == 0) {
return x / 2;
}
return (x * 3) + 1;
}
int main() {
int n, i = 1;
cin >> n;
while (memo[n] == 0) {
memo[n] = i++;
n = collaz(n);
}
cout << i;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> memo;
int collaz(int x) {
if (x % 2 == 0) {
return x / 2;
}
return (x * 3) + 1;
}
int main() {
int n, i = 1;
cin >> n;
while (memo[n] == 0) {
memo[n] = i++;
n = collaz(n);
}
cout << i;
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);
int main(void) {
ll N = 0;
ll A = 0;
ll B = 0;
ll C = 0;
ll D = 0;
ll H = 0;
ll W = 0;
// ll T = 0;
// ll M = 0;
ll h[400][400] = {};
// ll b[100] = {};
// ll c[100] = {};
// ll d[100] = {};
// ll v[3] = {};
// ll *c, *s, *n;
string S, T[50], U[52];
char fi[50], fv[50];
ll count = 0;
ll count2 = 0;
float sum = 0;
ll min = 1000000000000;
ll max = 1;
ll dist1 = 0;
ll dist2 = 0;
ll dist3 = 0;
ll now = 0;
int tmax = 0;
int tmax2 = 0;
// int flag = 0;
char temp, head;
// int is = 0;
bool flag = false;
// char p;
ll all = 0;
ll niku = 0;
ll state = 2;
bool down = true;
cin >> N;
vector<int> ov(105);
// sort(ov.begin(),ov.end());
ov[0] = N;
now++;
A = N;
while (true) {
// cout << A << endl;
if (A % 2 == 0) {
A /= 2;
} else {
A = 3 * A + 1;
}
ov[now] = A;
rep(i, 0, now) {
if (A == ov[i]) {
flag = true;
}
}
if (flag == true)
break;
now++;
}
cout << now + 1 << endl;
/*vector<pair<int,int>> tr(N);
rep(i, 0, N) {
cin >> tr[i].first;
count += tr[i].first;
}
rep(i, 0, N) {
cin >> tr[i].second;
count2 += tr[i].second;
}
if (count < count2) {
cout << -1 << endl;
return 0;
}
rep(i, 0, N) {
if (tr[i].first < tr[i].second) {
sum += tr[i].second - tr[i].first;
niku++;
}
else {
ov[all] += tr[i].first - tr[i].second;
all++;
}
}
sort(ov.begin(), ov.end(), greater<>());
int xx = 0;
while (sum > 0) {
sum -= ov[xx];
xx++;
niku++;
}*/
// cout << niku << endl;
// x = (ll *)malloc((N+1) * sizeof(ll));
// c = (ll *)malloc((N) * sizeof(ll));
// cin >> D >> G;
// vector<pair<int,int>> tr(M);
// vector<pair<int,int>> qes(Q);
// sort(c.begin(), c.end());
// cout << c[2] - c[1] << endl;
/*A = N / 1000;
N %= 1000;
B = N / 100;
N %= 100;
C = N / 10;
N %= 10;
D = N;*/
// cin >> N >> M;
// vector<pair<int,int>> c(M);
////vector<pair<int, int>> e(M);
// vector<ll> d(M);
// rep(i, 0, M) {
// cin >> c[i].first >> c[i].second;
// //e[i].first = c[i].first;
// //e[i].second = c[i].second;
//}
////sort(c.begin(), c.end());
//
// rep(i, 0, M) {
//
//
// rep(j, 0, M) {
// if (c[i].first == c[j].first && c[j].second < c[i].second) {
// d[i]++;
// //cout << j << endl;
// }
// }
// cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
// cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 <<
//endl;
//}
return 0;
}
ll bur(ll N, ll X) {
ll pan = 1;
ll pat = 1;
ll burg = 0;
if (X > burg) {
if (N == 0)
return pat;
burg += pan;
burg += bur(N - 1, X);
burg += pat;
burg += bur(N - 1, X);
burg += pan;
}
return burg;
}
ll gcd(ll a, ll b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll x = b;
ll y = a;
/* ユークリッドの互除法 */
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return y / b * x;
}
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);
int main(void) {
ll N = 0;
ll A = 0;
ll B = 0;
ll C = 0;
ll D = 0;
ll H = 0;
ll W = 0;
// ll T = 0;
// ll M = 0;
ll h[400][400] = {};
// ll b[100] = {};
// ll c[100] = {};
// ll d[100] = {};
// ll v[3] = {};
// ll *c, *s, *n;
string S, T[50], U[52];
char fi[50], fv[50];
ll count = 0;
ll count2 = 0;
float sum = 0;
ll min = 1000000000000;
ll max = 1;
ll dist1 = 0;
ll dist2 = 0;
ll dist3 = 0;
ll now = 0;
int tmax = 0;
int tmax2 = 0;
// int flag = 0;
char temp, head;
// int is = 0;
bool flag = false;
// char p;
ll all = 0;
ll niku = 0;
ll state = 2;
bool down = true;
cin >> N;
vector<int> ov(1000000);
// sort(ov.begin(),ov.end());
ov[0] = N;
now++;
A = N;
while (true) {
// cout << A << endl;
if (A % 2 == 0) {
A /= 2;
} else {
A = 3 * A + 1;
}
ov[now] = A;
rep(i, 0, now) {
if (A == ov[i]) {
flag = true;
}
}
if (flag == true)
break;
now++;
}
cout << now + 1 << endl;
/*vector<pair<int,int>> tr(N);
rep(i, 0, N) {
cin >> tr[i].first;
count += tr[i].first;
}
rep(i, 0, N) {
cin >> tr[i].second;
count2 += tr[i].second;
}
if (count < count2) {
cout << -1 << endl;
return 0;
}
rep(i, 0, N) {
if (tr[i].first < tr[i].second) {
sum += tr[i].second - tr[i].first;
niku++;
}
else {
ov[all] += tr[i].first - tr[i].second;
all++;
}
}
sort(ov.begin(), ov.end(), greater<>());
int xx = 0;
while (sum > 0) {
sum -= ov[xx];
xx++;
niku++;
}*/
// cout << niku << endl;
// x = (ll *)malloc((N+1) * sizeof(ll));
// c = (ll *)malloc((N) * sizeof(ll));
// cin >> D >> G;
// vector<pair<int,int>> tr(M);
// vector<pair<int,int>> qes(Q);
// sort(c.begin(), c.end());
// cout << c[2] - c[1] << endl;
/*A = N / 1000;
N %= 1000;
B = N / 100;
N %= 100;
C = N / 10;
N %= 10;
D = N;*/
// cin >> N >> M;
// vector<pair<int,int>> c(M);
////vector<pair<int, int>> e(M);
// vector<ll> d(M);
// rep(i, 0, M) {
// cin >> c[i].first >> c[i].second;
// //e[i].first = c[i].first;
// //e[i].second = c[i].second;
//}
////sort(c.begin(), c.end());
//
// rep(i, 0, M) {
//
//
// rep(j, 0, M) {
// if (c[i].first == c[j].first && c[j].second < c[i].second) {
// d[i]++;
// //cout << j << endl;
// }
// }
// cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
// cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 <<
//endl;
//}
return 0;
}
ll bur(ll N, ll X) {
ll pan = 1;
ll pat = 1;
ll burg = 0;
if (X > burg) {
if (N == 0)
return pat;
burg += pan;
burg += bur(N - 1, X);
burg += pat;
burg += bur(N - 1, X);
burg += pan;
}
return burg;
}
ll gcd(ll a, ll b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll x = b;
ll y = a;
/* ユークリッドの互除法 */
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return y / b * x;
}
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
|
replace
| 69 | 70 | 69 | 70 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <iostream>
#include <set>
using namespace std;
int main() {
int s;
cin >> s;
int a;
int i = 1;
set<int> ss;
while (a <= 1000000) {
if (i == 1) {
a = s;
} else if (a % 2 == 0) {
a = a / 2;
} else {
a = 3 * a + 1;
}
if (ss.find(a) == ss.end()) {
ss.insert(a);
} else {
cout << i << endl;
return i;
}
i++;
}
return 0;
}
|
#include <iostream>
#include <set>
using namespace std;
int main() {
int s;
cin >> s;
int a;
int i = 1;
set<int> ss;
while (a <= 1000000) {
if (i == 1) {
a = s;
} else if (a % 2 == 0) {
a = a / 2;
} else {
a = 3 * a + 1;
}
if (ss.find(a) == ss.end()) {
ss.insert(a);
} else {
cout << i << endl;
return 0;
}
i++;
}
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
vector<bool> done(10000000, false);
int cnt = 0;
while (true) {
cnt++;
if (done.at(s)) {
cout << cnt << endl;
break;
} else {
if (s % 2 == 0) {
s /= 2;
} else {
s = 3 * s + 1;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
vector<bool> done(10000000, false);
int cnt = 0;
while (true) {
cnt++;
if (done.at(s)) {
cout << cnt << endl;
break;
} else {
done.at(s) = true;
if (s % 2 == 0) {
s /= 2;
} else {
s = 3 * s + 1;
}
}
}
}
|
insert
| 14 | 14 | 14 | 15 |
TLE
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int main() {
int s;
cin >> s;
int i = 1;
do {
if (s == 4 || s == 2 || s == 1) {
cout << i + 3 << endl;
break;
}
i++;
} while (1);
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int s;
cin >> s;
int i = 1;
do {
if (s == 4 || s == 2 || s == 1) {
cout << i + 3 << endl;
break;
}
i++;
if (s % 2 == 0) {
s = s / 2;
} else {
s = 3 * s + 1;
}
} while (1);
return 0;
}
|
insert
| 14 | 14 | 14 | 19 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int s;
cin >> s;
const int p = 2147483647;
vector<int> num(p, 0);
int ans;
int a_prev;
int a_now = s;
int i = 1;
while (true) {
if (i == 1) {
a_now = s;
} else {
a_prev = a_now;
if (a_prev % 2 == 0) {
a_now = a_prev / 2;
} else {
a_now = a_prev * 3 + 1;
}
}
if (num[a_now] == 1)
break;
else
num[a_now]++;
i++;
}
cout << i << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int s;
cin >> s;
const int p = 147483647;
vector<int> num(p, 0);
int ans;
int a_prev;
int a_now = s;
int i = 1;
while (true) {
if (i == 1) {
a_now = s;
} else {
a_prev = a_now;
if (a_prev % 2 == 0) {
a_now = a_prev / 2;
} else {
a_now = a_prev * 3 + 1;
}
}
if (num[a_now] == 1)
break;
else
num[a_now]++;
i++;
}
cout << i << endl;
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03146
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <vector>
int main() {
int s;
scanf("%d", &s);
std::vector<int> vec;
vec.push_back(s);
int i;
for (i = 1; i < 1000000; i++) {
int tmp = vec.at(i - 1);
int push;
if (tmp % 2 == 0) {
push = tmp / 2;
} else {
push = tmp * 3 + 1;
}
if (std::find(vec.begin(), vec.end(), push) != vec.end()) {
break;
} else {
vec.push_back(push);
}
}
printf("%d\n", i + 1);
return i + 1;
}
|
#include <algorithm>
#include <cstdio>
#include <vector>
int main() {
int s;
scanf("%d", &s);
std::vector<int> vec;
vec.push_back(s);
int i;
for (i = 1; i < 1000000; i++) {
int tmp = vec.at(i - 1);
int push;
if (tmp % 2 == 0) {
push = tmp / 2;
} else {
push = tmp * 3 + 1;
}
if (std::find(vec.begin(), vec.end(), push) != vec.end()) {
break;
} else {
vec.push_back(push);
}
}
printf("%d\n", i + 1);
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
5
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int s;
cin >> s;
int ans = 1;
int a = (s <= 4 ? 1 : 0);
int b = (s >= 4 ? 4 : s);
while (a < 2) {
if (s % 2 == 0)
s = s / 2;
else
s = 3 * s + 1;
if (s == b)
a += 1;
ans++;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int s;
cin >> s;
int ans = 1;
int a = 0;
if (s == 4 || s == 2 || s == 1)
a += 1;
int b = (s == 4 || s == 2 || s == 1 ? s : 4);
while (a < 2) {
if (s % 2 == 0)
s = s / 2;
else
s = 3 * s + 1;
if (s == b)
a += 1;
ans++;
}
cout << ans << endl;
return 0;
}
|
replace
| 15 | 17 | 15 | 19 |
TLE
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define rev_rep(i, n) for (int i = n - 1; i >= 0; --i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::map<T1, T2> &mp);
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> &pair);
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &vec);
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> &pair) {
os << '(' << pair.first << ',' << pair.second << ')';
return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &vec) {
std::size_t n = vec.size();
if (n == 0) {
return os;
}
os << " ";
for (int i = 0; i < n - 1; ++i) {
os << vec[i] << " ";
}
os << vec[n - 1];
os << std::endl;
return os;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::map<T1, T2> &mp) {
std::size_t n = mp.size();
if (n == 0) {
return os;
}
os << " ";
for (auto &&x : mp) {
os << x << " ";
}
os << std::endl;
return os;
}
template <class T> std::ostream &operator<<(std::ostream &os, std::set<T> &mp) {
std::size_t n = mp.size();
if (n == 0) {
return os;
}
os << " ";
for (auto &&x : mp) {
os << x << " ";
}
os << std::endl;
return os;
}
ll f(ll x) {
if (x % 2 == 0) {
return x / 2;
} else {
return x * 3 + 1;
}
}
#ifndef BOOST_TEST_MAIN
int main(int const argc, char const **argv) {
ll s;
cin >> s;
set<ll> memory;
int res = 0;
memory.insert(s);
while (memory.find(s) == memory.end() || res == 0) {
// dump(memory);
// dump(s);
// memory.insert(s);
s = f(s);
res++;
};
cout << res + 1;
}
#endif
|
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define rev_rep(i, n) for (int i = n - 1; i >= 0; --i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::map<T1, T2> &mp);
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> &pair);
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &vec);
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> &pair) {
os << '(' << pair.first << ',' << pair.second << ')';
return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> &vec) {
std::size_t n = vec.size();
if (n == 0) {
return os;
}
os << " ";
for (int i = 0; i < n - 1; ++i) {
os << vec[i] << " ";
}
os << vec[n - 1];
os << std::endl;
return os;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, std::map<T1, T2> &mp) {
std::size_t n = mp.size();
if (n == 0) {
return os;
}
os << " ";
for (auto &&x : mp) {
os << x << " ";
}
os << std::endl;
return os;
}
template <class T> std::ostream &operator<<(std::ostream &os, std::set<T> &mp) {
std::size_t n = mp.size();
if (n == 0) {
return os;
}
os << " ";
for (auto &&x : mp) {
os << x << " ";
}
os << std::endl;
return os;
}
ll f(ll x) {
if (x % 2 == 0) {
return x / 2;
} else {
return x * 3 + 1;
}
}
#ifndef BOOST_TEST_MAIN
int main(int const argc, char const **argv) {
ll s;
cin >> s;
set<ll> memory;
int res = 0;
memory.insert(s);
while (memory.find(s) == memory.end() || res == 0) {
// dump(memory);
// dump(s);
memory.insert(s);
s = f(s);
res++;
};
cout << res + 1;
}
#endif
|
replace
| 96 | 97 | 96 | 97 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
int c[10 * a];
c[a] = 1;
int t;
for (int i = 0;; i++) {
t = i;
if (a % 2 == 1)
a = 3 * a + 1;
else
a = a / 2;
if (c[a] == 1)
goto end;
else
c[a] = 1;
}
end:
cout << t + 2;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
int c[1000000];
c[a] = 1;
int t;
for (int i = 0;; i++) {
t = i;
if (a % 2 == 1)
a = 3 * a + 1;
else
a = a / 2;
if (c[a] == 1)
goto end;
else
c[a] = 1;
}
end:
cout << t + 2;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03146
|
C++
|
Time Limit Exceeded
|
#pragma GCC optimize "-O3"
#pragma GCC target("avx")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define inf (1ll << 60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
signed gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed lcm(int a, int b) { return a * b / gcd(a, b); }
using namespace std;
const int mod = 1e9 + 7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
}
signed main() {
init();
run();
return 0;
}
signed f(int num) {
if (num % 2 == 0)
return num / 2;
else
return num * 3 + 1;
}
void run() {
int s;
cin >> s;
int num = 4;
while (s != 4 || s != 2 || s != 1) {
++num;
s = f(s);
}
cout << num << endl;
}
|
#pragma GCC optimize "-O3"
#pragma GCC target("avx")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define inf (1ll << 60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
signed gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed lcm(int a, int b) { return a * b / gcd(a, b); }
using namespace std;
const int mod = 1e9 + 7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
}
signed main() {
init();
run();
return 0;
}
signed f(int num) {
if (num % 2 == 0)
return num / 2;
else
return num * 3 + 1;
}
void run() {
int s;
cin >> s;
int num = 4;
if (s == 2) {
cout << 4 << endl;
return;
}
if (s == 1) {
cout << 4 << endl;
return;
}
while (s != 4) {
++num;
s = f(s);
}
cout << num << endl;
}
|
replace
| 50 | 51 | 50 | 59 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long fn(long n);
#define N 1000000
int main() {
long str[N] = {};
long s, tmp;
cin >> s;
str[s] = 1;
for (int i = 2; i < N + 1; i++) {
tmp = fn(s);
// cout << tmp << endl;
if (str[tmp] != 0) {
return i;
} else {
str[tmp] = 1;
}
s = tmp;
}
return 0;
}
long fn(long n) {
if (n % 2 == 0) {
return n / 2;
} else {
return 3 * n + 1;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long fn(long n);
#define N 1000000
int main() {
long str[N] = {};
long s, tmp;
cin >> s;
str[s] = 1;
for (int i = 2; i < N + 1; i++) {
tmp = fn(s);
// cout << tmp << endl;
if (str[tmp] != 0) {
cout << i << endl;
return 0;
} else {
str[tmp] = 1;
}
s = tmp;
}
return 0;
}
long fn(long n) {
if (n % 2 == 0) {
return n / 2;
} else {
return 3 * n + 1;
}
}
|
replace
| 18 | 19 | 18 | 20 |
5
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <iostream>
int main() {
int s;
std::cin >> s;
int list[1000000];
int index = 0;
int a_i;
int a_pre = s;
list[0] = s;
index = index + 1;
bool search_flag = false;
while (true) {
if (a_pre % 2 == 0) {
a_i = a_pre / 2;
} else {
a_i = 3 * a_pre + 1;
}
list[index] = a_i;
index = index + 1;
for (int i = 0; i < index - 1; ++i) {
if (list[i] == a_i) {
search_flag = false;
break;
}
}
if (search_flag == true) {
break;
}
a_pre = a_i;
}
std::cout << index << std::endl;
return 0;
}
|
#include <iostream>
int main() {
int s;
std::cin >> s;
int list[1000000];
int index = 0;
int a_i;
int a_pre = s;
list[0] = s;
index = index + 1;
bool search_flag = false;
while (true) {
if (a_pre % 2 == 0) {
a_i = a_pre / 2;
} else {
a_i = 3 * a_pre + 1;
}
list[index] = a_i;
index = index + 1;
for (int i = 0; i < index - 1; ++i) {
if (list[i] == a_i) {
search_flag = true;
break;
}
}
if (search_flag == true) {
break;
}
a_pre = a_i;
}
std::cout << index << std::endl;
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int s, i = 0, j;
vector<int> a;
cin >> s;
a.push_back(s);
i++;
while (true) {
if (a[i - 1] % 2) {
a.push_back(a[i - 1] * 3 + 1);
} else {
a.push_back(a[i - 1] / 2);
}
for (j = 0; j < i; j++) {
if (a[i] == a[j]) {
cout << i + 1 << endl;
return (1);
}
}
i++;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
int s, i = 0, j;
vector<int> a;
cin >> s;
a.push_back(s);
i++;
while (true) {
if (a[i - 1] % 2) {
a.push_back(a[i - 1] * 3 + 1);
} else {
a.push_back(a[i - 1] / 2);
}
for (j = 0; j < i; j++) {
if (a[i] == a[j]) {
cout << i + 1 << endl;
return (0);
}
}
i++;
}
}
|
replace
| 19 | 20 | 19 | 20 |
1
| |
p03146
|
C++
|
Runtime Error
|
// in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define rfr(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
int rec(int ind, int n) {
if (n == 1)
return ind;
if (n % 2 == 0)
return rec(ind + 1, n / 2);
else
return rec(ind + 1, 3 * n + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
int n;
cin >> n;
if (n <= 2)
cout << 4 << "\n";
else
cout << rec(0, n) + 2 << "\n";
return 0;
}
|
// in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define rfr(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
int rec(int ind, int n) {
if (n == 1)
return ind;
if (n % 2 == 0)
return rec(ind + 1, n / 2);
else
return rec(ind + 1, 3 * n + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
int n;
cin >> n;
if (n <= 2)
cout << 4 << "\n";
else
cout << rec(0, n) + 2 << "\n";
return 0;
}
|
replace
| 20 | 22 | 20 | 22 |
0
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(1);
cin >> a.at(0);
int i;
int ans = 0;
while (true) {
for (int j = 0; j < i; j++) {
if (a.at(i) == a.at(j)) {
ans = i + 1;
}
}
if (a.at(i) % 2 == 0) {
a.push_back(a.at(i) / 2);
} else {
a.push_back(a.at(i) * 3 + 1);
}
if (ans != 0) {
break;
}
i++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(1);
cin >> a.at(0);
int i = 0;
int ans = 0;
while (true) {
for (int j = 0; j < i; j++) {
if (a.at(i) == a.at(j)) {
ans = i + 1;
}
}
if (a.at(i) % 2 == 0) {
a.push_back(a.at(i) / 2);
} else {
a.push_back(a.at(i) * 3 + 1);
}
if (ans != 0) {
break;
}
i++;
}
cout << ans << endl;
}
|
replace
| 6 | 7 | 6 | 7 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
int S, ans = 2;
vector<bool> num(300, 1);
cin >> S;
num.at(S - 1) = 0;
while (true) {
if (S % 2 == 0) {
S /= 2;
} else {
S = 3 * S + 1;
}
if (num.at(S - 1)) {
num.at(S - 1) = 0;
} else {
break;
}
ans++;
}
cout << ans;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
int S, ans = 2;
vector<bool> num(10000, 1);
cin >> S;
num.at(S - 1) = 0;
while (true) {
if (S % 2 == 0) {
S /= 2;
} else {
S = 3 * S + 1;
}
if (num.at(S - 1)) {
num.at(S - 1) = 0;
} else {
break;
}
ans++;
}
cout << ans;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
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; }
const int mod = 1e9 + 7;
struct mint {
ll x;
mint(ll x = 0) : x(x % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
};
mint c[4005][4005];
void init() {
c[0][0] = 1;
for (int i = 0; i <= 4000; i++) {
for (int j = 0; j <= i; j++) {
c[i + 1][j] += c[i][j];
c[i + 1][j + 1] += c[i][j];
}
}
}
mint comb(int n, int k) { return c[n][k]; }
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
map<ll, ll> primeFact(ll n) {
map<ll, ll> res;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1)
res[n]++;
return res;
}
void printv(vi &v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
void printv(vll &v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
int vtotal(vi &v) {
int total = 0;
rep(i, v.size()) total += v[i];
return total;
}
int main() {
// init(); // mint初期化
cin.tie(0);
ios::sync_with_stdio(false);
int s;
cin >> s;
vi v(500, 0);
v[s] = 1;
int ans = 0;
int before = s;
for (int i = 2;; i++) {
int a;
if (before % 2 == 0)
a = before / 2;
else
a = 3 * before + 1;
if (v[a] == 1) {
ans = i;
break;
}
v[a] = 1;
before = a;
}
cout(ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
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; }
const int mod = 1e9 + 7;
struct mint {
ll x;
mint(ll x = 0) : x(x % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
};
mint c[4005][4005];
void init() {
c[0][0] = 1;
for (int i = 0; i <= 4000; i++) {
for (int j = 0; j <= i; j++) {
c[i + 1][j] += c[i][j];
c[i + 1][j + 1] += c[i][j];
}
}
}
mint comb(int n, int k) { return c[n][k]; }
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
map<ll, ll> primeFact(ll n) {
map<ll, ll> res;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1)
res[n]++;
return res;
}
void printv(vi &v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
void printv(vll &v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
int vtotal(vi &v) {
int total = 0;
rep(i, v.size()) total += v[i];
return total;
}
int main() {
// init(); // mint初期化
cin.tie(0);
ios::sync_with_stdio(false);
int s;
cin >> s;
vi v(100000, 0);
v[s] = 1;
int ans = 0;
int before = s;
for (int i = 2;; i++) {
int a;
if (before % 2 == 0)
a = before / 2;
else
a = 3 * before + 1;
if (v[a] == 1) {
ans = i;
break;
}
v[a] = 1;
before = a;
}
cout(ans);
return 0;
}
|
replace
| 130 | 131 | 130 | 131 |
-11
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> k(1000001, 0);
k[n] = 1;
int cnt = 2;
while (1) {
if (n % 2 == 0) {
n /= 2;
} else {
n = n * 3 + 1;
}
if (k[n] == 1) {
cout << cnt << endl;
return 0;
} else {
k[n] == 1;
}
cnt++;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> k(1000001, 0);
k[n] = 1;
int cnt = 2;
while (1) {
if (n % 2 == 0) {
n /= 2;
} else {
n = n * 3 + 1;
}
if (k[n] == 1) {
cout << cnt << endl;
return 0;
} else {
k[n] = 1;
}
cnt++;
}
}
|
replace
| 19 | 20 | 19 | 20 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int s;
cin >> s;
int ans;
int v[100] = {0};
v[s]++;
for (int i = 1;; i++) {
if (s % 2 == 0) {
s /= 2;
} else {
s = 3 * s + 1;
}
if (v[s] == 0)
v[s]++;
else {
ans = i + 1;
break;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int s;
cin >> s;
int ans;
int v[1000000] = {0};
v[s]++;
for (int i = 1;; i++) {
if (s % 2 == 0) {
s /= 2;
} else {
s = 3 * s + 1;
}
if (v[s] == 0)
v[s]++;
else {
ans = i + 1;
break;
}
}
cout << ans;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
vector<int> a;
a[1] = s;
int an;
bool loop = true;
for (int i = 2; loop; i++) {
if (a[i - 1] % 2 == 0)
a.push_back(a[i - 1] / 2);
else
a.push_back(3 * a[i - 1] + 1);
for (int j = 1; j < i; j++) {
if (a[i] == a[j]) {
loop = false;
an = i;
break;
}
}
}
cout << an << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s;
cin >> s;
vector<int> a(2);
a[0] = -1;
a[1] = s;
int an;
bool loop = true;
for (int i = 2; loop; i++) {
if (a[i - 1] % 2 == 0)
a.push_back(a[i - 1] / 2);
else
a.push_back(3 * a[i - 1] + 1);
for (int j = 1; j < i; j++) {
if (a[i] == a[j]) {
loop = false;
an = i;
break;
}
}
}
cout << an << endl;
}
|
replace
| 6 | 7 | 6 | 8 |
-11
| |
p03146
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, i = 1, m;
cin >> s;
m = s;
while (s != 4 || m != 2 || m != 1) {
if (s % 2 == 0) {
s /= 2;
} else
s = 3 * s + 1;
i++;
}
cout << i + 3 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, i = 1, m;
cin >> s;
m = s;
while (s != 4) {
if (m == 2 || m == 1)
break;
if (s % 2 == 0) {
s /= 2;
} else
s = 3 * s + 1;
i++;
}
cout << i + 3 << endl;
return 0;
}
|
replace
| 7 | 8 | 7 | 10 |
TLE
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, num;
cin >> s;
vector<int> a(101);
int tmp = s;
a[tmp]++;
for (int i = 1;; i++) {
if (tmp % 2 == 0)
tmp /= 2;
else
tmp = 3 * tmp + 1;
a[tmp]++;
if (a[tmp] == 2) {
cout << i + 1;
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, num;
cin >> s;
vector<int> a(1000001);
int tmp = s;
a[tmp]++;
for (int i = 1;; i++) {
if (tmp % 2 == 0)
tmp /= 2;
else
tmp = 3 * tmp + 1;
a[tmp]++;
if (a[tmp] == 2) {
cout << i + 1;
return 0;
}
}
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03146
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
int s;
cin >> s;
int ok[1100];
bool fin = false;
int ans = 0;
while (!fin) {
ans++;
// cout<<s<<endl;
if (ok[s] == 1) {
// cout<<" "<<s<<endl;
fin = true;
} else {
ok[s] = 1;
if (s % 2 == 0)
s /= 2;
else
s = 3 * s + 1;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
int s;
cin >> s;
int ok[11000];
bool fin = false;
int ans = 0;
while (!fin) {
ans++;
// cout<<s<<endl;
if (ok[s] == 1) {
// cout<<" "<<s<<endl;
fin = true;
} else {
ok[s] = 1;
if (s % 2 == 0)
s /= 2;
else
s = 3 * s + 1;
}
}
cout << ans << endl;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
vector<int> data(n);
data[0] = 0;
rep(i, 0, n) { cin >> data[i + 1]; }
int ans = 0;
rep(i, 0, n) {
if (data[i + 1] > data[i]) {
ans += data[i + 1] - data[i];
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
vector<int> data(n + 1);
data[0] = 0;
rep(i, 0, n) { cin >> data[i + 1]; }
int ans = 0;
rep(i, 0, n) {
if (data[i + 1] > data[i]) {
ans += data[i + 1] - data[i];
}
}
cout << ans << endl;
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03147
|
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;
int main() {
int N;
cin >> N;
vector<int> h(N);
REP(i, N) cin >> h[i];
int ans = 0;
for (int l = 0; l < N; ++l) {
while (h[l] > 0) {
int r = l;
while (h[++r] != 0)
;
for (int i = l; i < r; ++i)
h[i]--;
ans++;
}
}
cout << ans << 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;
int main() {
int N;
cin >> N;
vector<int> h(N);
REP(i, N) cin >> h[i];
int ans = 0;
for (int l = 0; l < N; ++l) {
while (h[l] > 0) {
int r;
for (r = l; r < N; ++r) {
if (h[r] == 0)
break;
}
for (int i = l; i < r; ++i)
h[i]--;
ans++;
}
}
cout << ans << endl;
}
|
replace
| 16 | 19 | 16 | 21 |
0
| |
p03147
|
C++
|
Runtime Error
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
int res = 0;
while (true) {
if (*max_element(h.begin(), h.end()) == 0)
break;
int it = 0;
while (it < N) {
if (h[it] == 0)
it++;
else {
res++;
while (h[it] > 0 && it < N) {
h[it]--;
it++;
}
}
}
}
cout << res << endl;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
int res = 0;
while (true) {
if (*max_element(h.begin(), h.end()) == 0)
break;
int it = 0;
while (it < N) {
if (h[it] == 0)
it++;
else {
res++;
while (it < N && h[it] > 0) {
h[it]--;
it++;
}
}
}
}
cout << res << endl;
}
|
replace
| 22 | 23 | 22 | 23 |
-6
|
/usr/include/c++/12/debug/vector:442:
In function:
std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp,
_Allocator>::operator[](size_type) [with _Tp = int; _Allocator =
std::allocator<int>; reference = int&; size_type = long unsigned int]
Error: attempt to subscript container with out-of-bounds index 4, but
container only holds 4 elements.
Objects involved in the operation:
sequence "this" @ 0x7fff7871fb20 {
type = std::debug::vector<int, std::allocator<int> >;
}
|
p03147
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h[101] = {0};
int Min = 100;
for (int i = 0; i < n; ++i) {
cin >> h[i];
if (Min > h[i]) {
Min = h[i];
}
}
for (int i = 0; i < n; ++i) {
h[i] -= Min;
}
int Sum = Min;
int st, end;
int flg = 0;
while (1) {
for (int i = 0; i < n; ++i) { // all 0 ?
if (h[i] != 0) {
break;
}
if (i == n - 1) {
cout << Sum << endl;
return 0;
}
}
for (int i = 0; i < n; ++i) {
if (h[i] != 0 && flg == 0) {
flg = 1;
st = i;
}
}
for (int i = st + 1; i < n; ++i) {
if (h[i] != 0 && h[i + 1] == 0) {
end = i;
flg = 0;
Min = 100;
for (int j = st; j <= end; ++j) {
if (Min > h[j]) {
Min = h[j];
}
}
for (int j = st; j <= end; ++j) {
h[j] -= Min;
}
Sum += Min;
break;
}
}
}
}
|
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h[101] = {0};
int Min = 100;
for (int i = 0; i < n; ++i) {
cin >> h[i];
if (Min > h[i]) {
Min = h[i];
}
}
for (int i = 0; i < n; ++i) {
h[i] -= Min;
}
int Sum = Min;
int st, end;
int flg = 0;
while (1) {
for (int i = 0; i < n; ++i) { // all 0 ?
if (h[i] != 0) {
break;
}
if (i == n - 1) {
cout << Sum << endl;
return 0;
}
}
for (int i = 0; i < n; ++i) {
if (h[i] != 0 && flg == 0) {
flg = 1;
st = i;
}
if (h[i] != 0 && h[i + 1] == 0) {
end = i;
flg = 0;
Min = 100;
for (int j = st; j <= end; ++j) {
if (Min > h[j]) {
Min = h[j];
}
}
for (int j = st; j <= end; ++j) {
h[j] -= Min;
}
Sum += Min;
break;
}
}
}
}
|
delete
| 34 | 36 | 34 | 34 |
TLE
| |
p03147
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
const vector<vector<int>> DivideGroup(const vector<int> origGroup) {
vector<vector<int>> divideds;
vector<int> divided;
for (const int member : origGroup) {
if (member == 0) {
if (!divided.empty()) {
divideds.push_back(divided);
divided.clear();
}
} else {
divided.push_back(member);
}
}
if (!divided.empty()) {
divideds.push_back(divided);
}
return divideds;
}
int main() {
int N;
cin >> N;
vector<int> heights(N);
for (int i = 0; i < N; ++i) {
cin >> heights[i];
}
vector<vector<int>> groups{heights};
int num = 0;
for (;;) {
if (groups.empty()) {
break;
}
// 0で各グループを分割
vector<vector<int>> dividedGroups;
for (auto itr = groups.begin(); itr != groups.end();) {
const auto divideds = DivideGroup(*itr);
if (!divideds.empty()) {
dividedGroups.insert(dividedGroups.end(), divideds.begin(),
divideds.end());
itr = groups.erase(itr);
} else {
++itr;
}
}
groups.insert(groups.end(), dividedGroups.begin(), dividedGroups.end());
// 各グループごとに1ずつ減らす
for (auto &group : groups) {
for (int &member : group) {
--member;
}
++num;
}
// グループ内がゼロのグループは削除
for (auto itr = groups.begin(); itr != groups.end();) {
if (accumulate(itr->begin(), itr->end(), 0) == 0) {
itr = groups.erase(itr);
} else {
++itr;
}
}
}
cout << num << endl;
}
|
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
const vector<vector<int>> DivideGroup(const vector<int> origGroup) {
vector<vector<int>> divideds;
vector<int> divided;
for (const int member : origGroup) {
if (member == 0) {
if (!divided.empty()) {
divideds.push_back(divided);
divided.clear();
}
} else {
divided.push_back(member);
}
}
if (!divided.empty()) {
divideds.push_back(divided);
}
return divideds;
}
int main() {
int N;
cin >> N;
vector<int> heights(N);
for (int i = 0; i < N; ++i) {
cin >> heights[i];
}
if (accumulate(heights.begin(), heights.end(), 0) == 0) {
cout << 0 << endl;
return 0;
}
vector<vector<int>> groups{heights};
int num = 0;
for (;;) {
if (groups.empty()) {
break;
}
// 0で各グループを分割
vector<vector<int>> dividedGroups;
for (auto itr = groups.begin(); itr != groups.end();) {
const auto divideds = DivideGroup(*itr);
if (!divideds.empty()) {
dividedGroups.insert(dividedGroups.end(), divideds.begin(),
divideds.end());
itr = groups.erase(itr);
} else {
++itr;
}
}
groups.insert(groups.end(), dividedGroups.begin(), dividedGroups.end());
// 各グループごとに1ずつ減らす
for (auto &group : groups) {
for (int &member : group) {
--member;
}
++num;
}
// グループ内がゼロのグループは削除
for (auto itr = groups.begin(); itr != groups.end();) {
if (accumulate(itr->begin(), itr->end(), 0) == 0) {
itr = groups.erase(itr);
} else {
++itr;
}
}
}
cout << num << endl;
}
|
insert
| 32 | 32 | 32 | 36 |
TLE
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> buf;
int main() {
int N, h[100], c = 0;
vector<vector<int>> T(100, vector<int>(N + 1, 0));
int ans = 0;
cin >> N;
for (int i = 0; i < 100; i++) {
h[i] = 0;
}
for (int i = 0; i < N; i++) {
cin >> h[i];
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
if (h[j] > i) {
T[i][j] = 1;
}
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
c = 0;
while (T[i][j] == 1) {
j++;
c++;
}
if (c != 0) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> buf;
int main() {
int N, h[100], c = 0;
vector<vector<int>> T(100, vector<int>(100, 0));
int ans = 0;
cin >> N;
for (int i = 0; i < 100; i++) {
h[i] = 0;
}
for (int i = 0; i < N; i++) {
cin >> h[i];
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
if (h[j] > i) {
T[i][j] = 1;
}
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
c = 0;
while (T[i][j] == 1) {
j++;
c++;
}
if (c != 0) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> buf;
int main() {
int N, h[100], c = 0;
vector<vector<int>> T(100, vector<int>(N, 0));
int ans = 0;
cin >> N;
for (int i = 0; i < 100; i++) {
h[i] = 0;
}
for (int i = 0; i < N; i++) {
cin >> h[i];
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
if (h[j] > i) {
T[i][j] = 1;
}
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
c = 0;
while (T[i][j] == 1) {
j++;
c++;
}
if (c != 0) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> buf;
int main() {
int N, h[100], c = 0;
vector<vector<int>> T(1000, vector<int>(100, 0));
int ans = 0;
cin >> N;
for (int i = 0; i < 100; i++) {
h[i] = 0;
}
for (int i = 0; i < N; i++) {
cin >> h[i];
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
if (h[j] > i) {
T[i][j] = 1;
}
}
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < N; j++) {
c = 0;
while (T[i][j] == 1) {
j++;
c++;
}
if (c != 0) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
-6
|
terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; ++i)
cin >> h[i];
int j = 0, cnt = 0;
for (int i = 0; i < N; ++i) {
while (h[i] > 0) {
int j = i;
while (h[j] > 0) {
++j;
}
int k = i;
while (k < j) {
--h[k];
++k;
}
++cnt;
}
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; ++i)
cin >> h[i];
int j = 0, cnt = 0;
for (int i = 0; i < N; ++i) {
while (h[i] > 0) {
for (int j = i; j < N && h[j] > 0; ++j) {
--h[j];
}
++cnt;
}
}
cout << cnt << endl;
}
|
replace
| 12 | 20 | 12 | 14 |
0
| |
p03147
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ct(string) cout << string << endl
int main() {
int n, minn, ans = 0, check, startt;
cin >> n;
vector<int> data(n);
rep(i, n) cin >> data.at(i);
while (true) {
minn = 101;
check = 0;
startt = 0;
rep(i, n) {
if (data.at(i) == 0 || i == n - 1) {
minn = (i == n - 1 ? min(minn, data.at(i)) : minn);
for (int j = startt; i + 1 > j; j++) {
data.at(j) = ((data.at(j) - minn < 1) ? 0 : data.at(j) - minn);
}
ans += (minn == 101 ? 0 : minn);
startt = i;
minn = 101;
check += data.at(i);
continue;
}
check += data.at(i);
minn = min(minn, data.at(i));
}
if (check == 0)
break;
}
ct(ans);
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ct(string) cout << string << endl
int main() {
int n, minn, ans = 0, check, startt;
cin >> n;
vector<int> data(n);
rep(i, n) cin >> data.at(i);
while (true) {
minn = 101;
check = 0;
startt = 0;
rep(i, n) {
if (data.at(i) == 0 || i == n - 1) {
minn = (data.at(i) != 0 ? min(minn, data.at(i)) : minn);
for (int j = startt; i + 1 > j; j++) {
data.at(j) = ((data.at(j) - minn < 1) ? 0 : data.at(j) - minn);
}
ans += (minn == 101 ? 0 : minn);
startt = i;
minn = 101;
check += data.at(i);
continue;
}
check += data.at(i);
minn = min(minn, data.at(i));
}
if (check == 0)
break;
}
ct(ans);
}
|
replace
| 20 | 21 | 20 | 21 |
TLE
| |
p03147
|
C++
|
Runtime Error
|
#include <cstdio>
#include <iostream>
#include <vector>
int main() {
using namespace std;
int n;
scanf("%d", &n);
vector<int> h(n);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
}
int watering_times = 0;
for (int i = 0; i < n; i++) {
while (h[i]) {
watering_times++;
h[i]--;
int j = i + 1;
if (j == n)
continue;
while (h[j]) {
h[j++]--;
}
}
}
cout << watering_times << endl;
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <vector>
int main() {
using namespace std;
int n;
scanf("%d", &n);
vector<int> h(n);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
}
int watering_times = 0;
for (int i = 0; i < n; i++) {
while (h[i]) {
watering_times++;
h[i]--;
int j = i + 1;
if (j == n)
continue;
while (h[j]) {
h[j]--;
j++;
if (j == n)
break;
}
}
}
cout << watering_times << endl;
return 0;
}
|
replace
| 24 | 25 | 24 | 28 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h.at(i);
}
int cnt;
while (true) {
bool allzero = true;
for (int i = 0; i < N; i++) {
if (h.at(i) != 0) {
allzero = false;
}
}
if (allzero)
break;
// ゼロでない一番左の値をほしい
int l;
while (h.at(l) == 0)
l++;
int r = l;
while (r < N && h.at(r + 1) != 0)
r++;
cnt++;
for (int i = l; i <= r; i++)
h.at(i)--;
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h.at(i);
}
int cnt;
while (true) {
bool allzero = true;
for (int i = 0; i < N; i++) {
if (h.at(i) != 0) {
allzero = false;
}
}
if (allzero)
break;
// ゼロでない一番左の値をほしい
int l;
while (h.at(l) == 0)
l++;
int r = l;
while (r < N - 1 && h.at(r + 1) != 0)
r++;
cnt++;
for (int i = l; i <= r; i++)
h.at(i)--;
}
cout << cnt << endl;
}
|
replace
| 30 | 31 | 30 | 31 |
-6
|
terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 32559) >= this->size() (which is 4)
|
p03147
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, ans, r, j, i, l;
cin >> N;
int h[1100] = {0};
for (int i = 0; i < N; ++i)
cin >> h[i];
ans = 0;
for (int l = 0; l < N; l++) {
while (h[l] > 0) {
for (int r = l + 1; r < N; r++) {
if (h[r] == 0)
break;
}
for (int i = l; i < r; i++)
--h[i];
ans++;
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, ans, r, j, i, l;
cin >> N;
int h[1100] = {0};
for (int i = 0; i < N; ++i)
cin >> h[i];
ans = 0;
for (int l = 0; l < N; l++) {
while (h[l] > 0) {
int r;
for (r = l + 1; r < N; r++) {
if (h[r] == 0)
break;
}
for (int i = l; i < r; i++)
--h[i];
ans++;
}
}
cout << ans << endl;
}
|
replace
| 13 | 14 | 13 | 15 |
TLE
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
ll N;
ll h[111];
ll rec(ll l, ll r) {
if (l >= r)
return 0;
ll res = 0;
ll i;
ll min = INF;
for (i = l; i < r; i++)
chmin(min, h[i]);
res += min;
vector<ll> ze;
ze.pb(-1);
for (i = l; i < r; i++) {
h[i] -= min;
if (h[i] == 0)
ze.pb(i);
}
ze.pb(N);
for (i = 0; i < ze.size() - 1; i++)
res += rec(ze[i] + 1, ze[i + 1]);
return res;
}
int main(void) {
cin >> N;
ll i;
for (i = 0; i < N; i++)
cin >> h[i];
pt(rec(0, N));
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
ll N;
ll h[111];
ll rec(ll l, ll r) {
if (l >= r)
return 0;
ll res = 0;
ll i;
ll min = INF;
for (i = l; i < r; i++)
chmin(min, h[i]);
res += min;
vector<ll> ze;
ze.pb(l - 1);
for (i = l; i < r; i++) {
h[i] -= min;
if (h[i] == 0)
ze.pb(i);
}
ze.pb(N);
for (i = 0; i < ze.size() - 1; i++)
res += rec(ze[i] + 1, ze[i + 1]);
return res;
}
int main(void) {
cin >> N;
ll i;
for (i = 0; i < N; i++)
cin >> h[i];
pt(rec(0, N));
}
|
replace
| 46 | 47 | 46 | 47 |
-11
| |
p03147
|
C++
|
Runtime Error
|
#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 N;
int h[100] = {};
int count(int height, int i) {
if (i == 0 && h[i] >= height) {
return count(height, i + 1) + 1;
}
if (i == N - 1) {
return 0;
} else {
if (h[i] < height && h[i + 1] >= height) {
return count(height, i + 1) + 1;
} else {
return count(height, i + 1);
}
}
}
int main() {
cin >> N;
REP(i, N) { cin >> h[i]; }
int ans = 0;
FOR(x, 1, 101) { ans += count(x, 0); }
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 N;
int h[100] = {};
int count(int height, int i) {
if (i == 0 && h[i] >= height) {
return count(height, i + 1) + 1;
}
if (i == N - 1) {
return 0;
} else {
if (h[i] < height && h[i + 1] >= height) {
return count(height, i + 1) + 1;
} else {
return count(height, i + 1);
}
}
}
int main() {
cin >> N;
REP(i, N) { cin >> h[i]; }
if (N == 1) {
cout << h[0];
} else {
int ans = 0;
FOR(x, 1, 101) { ans += count(x, 0); }
cout << ans;
}
}
|
replace
| 37 | 40 | 37 | 44 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// 最大公約数
template <class T> inline T GCD(T m, T n) {
T temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
}
// 最小公倍数
template <class T> inline T LCM(T m, T n) { return m * n / GCD(m, n); }
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
int ans = 0;
while (true) {
auto mid = find(h.begin(), h.end(), 0);
int m = *min_element(h.begin(), mid - 1);
for (auto it = h.begin(); it < mid; ++it) {
*it = *it - m > 0 ? *it - m : 0;
}
ans += m;
auto iter = h.begin();
for (auto it : h) {
if (it != 0) {
break;
}
iter++;
}
h.erase(h.begin(), iter);
if (h.size() == 0) {
break;
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// 最大公約数
template <class T> inline T GCD(T m, T n) {
T temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
}
// 最小公倍数
template <class T> inline T LCM(T m, T n) { return m * n / GCD(m, n); }
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
int ans = 0;
while (true) {
auto mid = find(h.begin(), h.end(), 0);
int m = *min_element(h.begin(), distance(h.begin(), mid) ? mid - 1 : mid);
for (auto it = h.begin(); it < mid; ++it) {
*it = *it - m > 0 ? *it - m : 0;
}
ans += m;
auto iter = h.begin();
for (auto it : h) {
if (it != 0) {
break;
}
iter++;
}
h.erase(h.begin(), iter);
if (h.size() == 0) {
break;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 52 | 53 | 52 | 53 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
int n;
std::cin >> n;
std::vector<int> h(n);
for (int i = 0; i < n; i++) {
std::cin >> h[i];
}
int tmp = *std::max_element(h.begin(), h.end());
std::vector<int> flag(0);
for (int i = 0; i < tmp; i++) {
for (int j = 0; j < n; j++) {
if (h[j] > 0) {
flag.push_back(1);
} else {
flag.push_back(0);
}
h[j]--;
}
flag.push_back(0);
}
int count = 0;
for (int i = 0; i < flag.size() - 1; i++) {
if (flag[i] == 1 && flag[i + 1] == 0) {
count++;
}
}
std::cout << count << std::endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
int n;
std::cin >> n;
std::vector<int> h(n);
for (int i = 0; i < n; i++) {
std::cin >> h[i];
}
int tmp = *std::max_element(h.begin(), h.end());
std::vector<int> flag(0);
for (int i = 0; i < tmp; i++) {
for (int j = 0; j < n; j++) {
if (h[j] > 0) {
flag.push_back(1);
} else {
flag.push_back(0);
}
h[j]--;
}
flag.push_back(0);
}
int count = 0;
for (int i = 0; i < (int)flag.size() - 1; i++) {
if (flag[i] == 1 && flag[i + 1] == 0) {
count++;
}
}
std::cout << count << std::endl;
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <iostream>
#include <utility>
using namespace std;
unsigned int *h;
unsigned int N;
unsigned int findMax() {
unsigned max = 0;
unsigned int found = N;
for (unsigned int i = 0; i < N; i++) {
if (max < h[i]) {
max = h[i];
found = i;
}
}
return found;
}
std::pair<unsigned int, unsigned int> searchRound(unsigned int orig) {
std::pair<unsigned int, unsigned int> ret = {orig, orig};
unsigned int i;
for (i = orig; 0 < i; i--) {
if (h[i - 1] > 0) {
if (i == 1) {
ret.first = 0;
break;
}
continue;
}
ret.first = i;
break;
}
for (i = orig; i < (N - 1); i++) {
if (h[i + 1] > 0) {
if (i == (N - 2)) {
ret.second = N - 1;
break;
}
continue;
}
ret.second = i;
break;
}
return ret;
}
void give(std::pair<unsigned int, unsigned int> targets) {
for (unsigned int i = targets.first; i <= targets.second; i++) {
h[i]--;
}
}
void show() {
for (unsigned int i = 0; i < N; i++) {
cout << h[i] << ' ';
}
cout << endl;
}
int main() {
cin >> N;
h = new unsigned int(N);
for (unsigned int i = 0; i < N; i++) {
cin >> h[i];
}
unsigned int count = 0;
do {
unsigned int target = findMax();
if (target == N)
break;
count++;
std::pair<unsigned int, unsigned int> targets = searchRound(target);
give(targets);
// show();
} while (1);
cout << count << endl;
delete[] h;
return 0;
}
|
#include <iostream>
#include <utility>
using namespace std;
unsigned int *h;
unsigned int N;
unsigned int findMax() {
unsigned max = 0;
unsigned int found = N;
for (unsigned int i = 0; i < N; i++) {
if (max < h[i]) {
max = h[i];
found = i;
}
}
return found;
}
std::pair<unsigned int, unsigned int> searchRound(unsigned int orig) {
std::pair<unsigned int, unsigned int> ret = {orig, orig};
unsigned int i;
for (i = orig; 0 < i; i--) {
if (h[i - 1] > 0) {
if (i == 1) {
ret.first = 0;
break;
}
continue;
}
ret.first = i;
break;
}
for (i = orig; i < (N - 1); i++) {
if (h[i + 1] > 0) {
if (i == (N - 2)) {
ret.second = N - 1;
break;
}
continue;
}
ret.second = i;
break;
}
return ret;
}
void give(std::pair<unsigned int, unsigned int> targets) {
for (unsigned int i = targets.first; i <= targets.second; i++) {
h[i]--;
}
}
void show() {
for (unsigned int i = 0; i < N; i++) {
cout << h[i] << ' ';
}
cout << endl;
}
int main() {
cin >> N;
h = new unsigned int(N);
for (unsigned int i = 0; i < N; i++) {
cin >> h[i];
}
unsigned int count = 0;
do {
unsigned int target = findMax();
if (target == N)
break;
count++;
std::pair<unsigned int, unsigned int> targets = searchRound(target);
give(targets);
// show();
} while (1);
cout << count << endl;
// delete [] h;
return 0;
}
|
replace
| 77 | 78 | 77 | 78 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
// #define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// std::cout << std::fixed << std::setprecision(15); //"for float-base
// problem"
int N, ans = 0;
vi max, min;
bool flag = true; // true なら↑ falseなら↓
cin >> N;
vi h(N);
REP(i, N) cin >> h.at(i);
min.push_back(0);
if (h.at(0) > h.at(1)) {
max.push_back(h[0]);
flag = false;
} else {
flag = true;
}
for (int i = 1; i < N - 1; i++) {
if (h.at(i) < h.at(i + 1) && !flag) {
min.push_back(h.at(i));
flag = true;
} else if (h.at(i) > h.at(i + 1) && flag) {
max.push_back(h.at(i));
flag = false;
}
}
if (flag == true)
max.push_back(h.at(N - 1));
for (int j = 0; j < max.size(); j++) {
ans += max.at(j) - min.at(j);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
// #define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// std::cout << std::fixed << std::setprecision(15); //"for float-base
// problem"
int N, ans = 0;
vi max, min;
bool flag = true; // true なら↑ falseなら↓
cin >> N;
vi h(N);
REP(i, N) cin >> h.at(i);
min.push_back(0);
if (N == 1) {
cout << h.at(0) << endl;
return 0;
}
if (h.at(0) > h.at(1)) {
max.push_back(h[0]);
flag = false;
} else {
flag = true;
}
for (int i = 1; i < N - 1; i++) {
if (h.at(i) < h.at(i + 1) && !flag) {
min.push_back(h.at(i));
flag = true;
} else if (h.at(i) > h.at(i + 1) && flag) {
max.push_back(h.at(i));
flag = false;
}
}
if (flag == true)
max.push_back(h.at(N - 1));
for (int j = 0; j < max.size(); j++) {
ans += max.at(j) - min.at(j);
}
cout << ans << endl;
}
|
insert
| 23 | 23 | 23 | 27 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> v(n);
vector<int> u(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
v.push_back(0);
u[0] = v[0];
for (int i = 0; i < n + 1; i++) {
if (0 < i)
u[i] = v[i] - v[i - 1];
}
int ans = 0;
for (int i = 0; i < n + 1; i++) {
if (u[i] > 0)
ans += u[i];
}
// for (int i = 0; i < n;i++){
// cout << u[i] << " ";
// }
// cout << endl;
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> v(n);
vector<int> u(n + 1);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
v.push_back(0);
u[0] = v[0];
for (int i = 0; i < n + 1; i++) {
if (0 < i)
u[i] = v[i] - v[i - 1];
}
int ans = 0;
for (int i = 0; i < n + 1; i++) {
if (u[i] > 0)
ans += u[i];
}
// for (int i = 0; i < n;i++){
// cout << u[i] << " ";
// }
// cout << endl;
cout << ans << endl;
return 0;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define N 100009
int main() {
int n;
cin >> n;
int data[n];
for (int i = 0; i < n; i++)
cin >> data[i];
bool color[n + 1];
for (int i = 0; i < n; i++)
color[i] = false;
color[n] = true;
int high[n + 1];
for (int i = 0; i < n; i++) {
high[i] = 0;
if (data[i] == 0)
color[i] = true;
}
int count = 0;
bool ans = true;
while (ans) {
ans = false;
int p, q;
for (int i = 0; i < n; i++) {
if (color[i] == false) {
p = i;
break;
}
}
for (int j = p + 1; j <= n; j++) {
if (color[j] == true) {
q = j - 1;
break;
}
}
for (int i = p; i <= q; i++) {
high[i]++;
if (high[i] == data[i])
color[i] = true;
}
// for(int i=0; i<n; i++) cout<<color[i];
// cout<<endl;
count++;
for (int i = 0; i < n; i++) {
if (color[i] == false) {
ans = true;
}
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define N 100009
int main() {
int n;
cin >> n;
int data[n];
for (int i = 0; i < n; i++)
cin >> data[i];
bool color[n + 1];
for (int i = 0; i < n; i++)
color[i] = false;
color[n] = true;
int high[n + 1];
for (int i = 0; i < n; i++) {
high[i] = 0;
if (data[i] == 0)
color[i] = true;
}
int count = 0;
bool ans = false;
for (int i = 0; i < n; i++) {
if (data[i] != 0) {
ans = true;
break;
}
}
while (ans) {
ans = false;
int p, q;
for (int i = 0; i < n; i++) {
if (color[i] == false) {
p = i;
break;
}
}
for (int j = p + 1; j <= n; j++) {
if (color[j] == true) {
q = j - 1;
break;
}
}
for (int i = p; i <= q; i++) {
high[i]++;
if (high[i] == data[i])
color[i] = true;
}
// for(int i=0; i<n; i++) cout<<color[i];
// cout<<endl;
count++;
for (int i = 0; i < n; i++) {
if (color[i] == false) {
ans = true;
}
}
}
cout << count << endl;
}
|
replace
| 28 | 29 | 28 | 35 |
0
| |
p03147
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int main() {
int i = 0, n, m = 0, j = 0, a[114];
for (cin >> n; i < n; cin >> a[i++])
;
for (a[i] = 0; j++ < 114;)
for (i = 0; i<n; m += a[i]--> 0 && a[++i] <= 0)
;
cout << m << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int i = 0, n, m = 0, j = 0, a[114];
for (cin >> n; i < n; cin >> a[i++])
;
for (a[i] = 0; j++ < 114;)
for (i = 0; i<n; m += a[i++]--> 0 && a[i] <= 0)
;
cout << m << endl;
}
|
replace
| 7 | 8 | 7 | 8 |
TLE
| |
p03147
|
C++
|
Time Limit Exceeded
|
#include <stdio.h>
int main() {
int n, h[111], flag1 = 1, flag2, ans = 0, i, j, k, min;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &h[i]);
if (h[i] != 0)
flag1 = 0;
}
while (flag1 == 0) {
k = 0;
flag2 = 1;
min = 111;
for (i = 0; i < n; i++) {
if (h[i] == 0) {
for (j = k + 1; j < i; j++)
h[j] -= min;
if (min < 111)
ans += min;
k = i;
min = 111;
} else if (h[i] < min) {
min = h[i];
flag2 = 0;
}
}
for (j = k + 1; j < i; j++)
h[j] -= min;
if (min < 111)
ans += min;
if (flag2 == 1)
flag1 = 1;
}
printf("%d\n", ans);
return 0;
}
|
#include <stdio.h>
int main() {
int n, h[111], flag1 = 1, flag2, ans = 0, i, j, k, min;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &h[i]);
if (h[i] != 0)
flag1 = 0;
}
while (flag1 == 0) {
k = -1;
flag2 = 1;
min = 111;
for (i = 0; i < n; i++) {
if (h[i] == 0) {
for (j = k + 1; j < i; j++)
h[j] -= min;
if (min < 111)
ans += min;
k = i;
min = 111;
} else if (h[i] < min) {
min = h[i];
flag2 = 0;
}
}
for (j = k + 1; j < i; j++)
h[j] -= min;
if (min < 111)
ans += min;
if (flag2 == 1)
flag1 = 1;
}
printf("%d\n", ans);
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
TLE
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
int ans = 0;
bool st = true;
while (st) {
int i = 0;
if (h[i] == 0) {
while (h[i] == 0 && i < n) {
i++;
}
if (i == n) {
st = false;
break;
}
}
while (h[i] > 0) {
h[i]--;
i++;
}
ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n + 1);
for (int i = 0; i < n; i++)
cin >> h[i];
int ans = 0;
bool st = true;
while (st) {
int i = 0;
if (h[i] == 0) {
while (h[i] == 0 && i < n) {
i++;
}
if (i == n) {
st = false;
break;
}
}
while (h[i] > 0) {
h[i]--;
i++;
}
ans++;
}
cout << ans << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> H(N);
vector<vector<int>> table(1);
int index = 0;
for (int i = 0; i < N; i++) {
cin >> H[i];
if (H[i] == 0) {
index++;
table.push_back(vector<int>());
continue;
}
table[index].push_back(H[i]);
}
int ans = 0;
for (int i = 0; i < table.size(); i++) {
if (table[i].size() == 1) {
ans += table[i][0];
continue;
}
int min = *min_element(table[i].begin(), table[i].end());
index++;
table.push_back(vector<int>());
if (table[i][0] != min) {
table[index].push_back(table[i][0] - min);
}
for (int k = 1; k < table[i].size() - 1; k++) {
if (table[i][k] == min && table[index].size() > 0) {
index++;
table.push_back(vector<int>());
} else {
table[index].push_back(table[i][k] - min);
}
}
if (table[i][table[i].size() - 1] != min) {
table[index].push_back(table[i][table[i].size() - 1] - min);
}
if (table[index].size() == 0) {
table.erase(table.begin() + index);
index--;
}
ans += min;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> H(N);
vector<vector<int>> table(1);
int index = 0;
for (int i = 0; i < N; i++) {
cin >> H[i];
if (H[i] == 0) {
index++;
table.push_back(vector<int>());
continue;
}
table[index].push_back(H[i]);
}
int ans = 0;
for (int i = 0; i < table.size(); i++) {
if (table[i].size() == 0) {
continue;
}
if (table[i].size() == 1) {
ans += table[i][0];
continue;
}
int min = *min_element(table[i].begin(), table[i].end());
index++;
table.push_back(vector<int>());
if (table[i][0] != min) {
table[index].push_back(table[i][0] - min);
}
for (int k = 1; k < table[i].size() - 1; k++) {
if (table[i][k] == min && table[index].size() > 0) {
index++;
table.push_back(vector<int>());
} else {
table[index].push_back(table[i][k] - min);
}
}
if (table[i][table[i].size() - 1] != min) {
table[index].push_back(table[i][table[i].size() - 1] - min);
}
if (table[index].size() == 0) {
table.erase(table.begin() + index);
index--;
}
ans += min;
}
cout << ans << endl;
return 0;
}
|
insert
| 29 | 29 | 29 | 33 |
0
| |
p03147
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
// const int N = 1000000;
const ll mod = 1000000007;
// using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
ll gcd(ll A, ll B) {
if (B == 0)
return A;
return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * (B / gcd(A, B)); }
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
Graph G;
/*------------------------------------------------------------------*/
int main() {
int n;
cin >> n;
vector<int> h(n);
rep(i, n) cin >> h[i];
int MAX = *max_element(h.begin(), h.end());
int ans = 0;
while (true) {
int mi = 101;
MAX = *max_element(h.begin(), h.end());
if (MAX <= 0)
break;
rep(i, n) {
if (h[i] <= 0 and mi == 101)
continue;
if (i == n - 1) {
mi = min(h[i], mi);
ans += mi;
rep(j, n) { h[j] -= mi; }
break;
}
if (h[i] > 0) {
mi = min(h[i], mi);
}
if (h[i] <= 0) {
ans += mi;
rep(j, i) { h[j] -= mi; }
break;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
// const int N = 1000000;
const ll mod = 1000000007;
// using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
ll gcd(ll A, ll B) {
if (B == 0)
return A;
return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * (B / gcd(A, B)); }
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
Graph G;
/*------------------------------------------------------------------*/
int main() {
int n;
cin >> n;
vector<int> h(n);
rep(i, n) cin >> h[i];
int MAX = *max_element(h.begin(), h.end());
int ans = 0;
while (true) {
int mi = 101;
MAX = *max_element(h.begin(), h.end());
if (MAX <= 0)
break;
rep(i, n) {
if (h[i] <= 0 and mi == 101)
continue;
if (i == n - 1 and h[i] > 0) {
mi = min(h[i], mi);
ans += mi;
rep(j, n) { h[j] -= mi; }
break;
}
if (h[i] > 0) {
mi = min(h[i], mi);
}
if (h[i] <= 0) {
ans += mi;
rep(j, i) { h[j] -= mi; }
break;
}
}
}
cout << ans << endl;
}
|
replace
| 43 | 44 | 43 | 44 |
TLE
| |
p03147
|
Python
|
Runtime Error
|
N = int(input())
H = list(map(int, input().split()))
ans = 0
while max(H) > 0:
grp = [[]]
for i, h in enumerate(H):
if h == 0:
if len(grp[-1]) > 0:
grp.append([])
else:
grp[-1].append((i, h))
for g in grp:
mi = min([h for _, h in g])
ans += mi
for i, _ in g:
H[i] -= mi
print(ans)
|
N = int(input())
H = list(map(int, input().split()))
ans = 0
while max(H) > 0:
grp = [[]]
for i, h in enumerate(H):
if h == 0:
if len(grp[-1]) > 0:
grp.append([])
else:
grp[-1].append((i, h))
for g in grp:
if len(g) == 0:
continue
mi = min([h for _, h in g])
ans += mi
for i, _ in g:
H[i] -= mi
print(ans)
|
insert
| 13 | 13 | 13 | 15 |
ValueError: min() arg is an empty sequence
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03147/Python/s431171639.py", line 14, in <module>
mi = min([h for _, h in g])
ValueError: min() arg is an empty sequence
|
p03147
|
Python
|
Runtime Error
|
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
h = list(map(int, input().split()))
dflag = 0
cmin = 0
cmax = h[0]
count = 0
for i in range(1, N):
if h[i - 1] < h[i] and dflag == 1:
count += cmax - cmin
cmax = h[i]
dflag = 0
cmin = h[i - 1]
elif h[i - 1] > h[i]:
dflag = 1
elif h[i - 1] < h[i]:
cmax = h[i]
if dflag == 1:
count += cmax - cmin
else:
count += max(cmax, h[i]) - cmin
print(count)
if __name__ == "__main__":
main()
|
import sys
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
if N == 1:
print(input())
exit()
h = list(map(int, input().split()))
dflag = 0
cmin = 0
cmax = h[0]
count = 0
for i in range(1, N):
if h[i - 1] < h[i] and dflag == 1:
count += cmax - cmin
cmax = h[i]
dflag = 0
cmin = h[i - 1]
elif h[i - 1] > h[i]:
dflag = 1
elif h[i - 1] < h[i]:
cmax = h[i]
if dflag == 1:
count += cmax - cmin
else:
count += max(cmax, h[i]) - cmin
print(count)
if __name__ == "__main__":
main()
|
insert
| 9 | 9 | 9 | 12 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) \
Type __VA_ARGS__; \
IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
// IN
void IN() {}
template <class Head, class... Tail> void IN(Head &&head, Tail &&...tail) {
cin >> head;
IN(forward<Tail>(tail)...);
}
// OUTS
void OUTS() {}
template <class Head, class... Tail> void OUTS(Head &&head, Tail &&...tail) {
cout << head << " \n"[sizeof...(tail) == 0];
OUTS(forward<Tail>(tail)...);
}
template <class T> void OUTS(vector<T> &vec) {
for (auto &e : vec)
cout << e << " \n"[&e == &vec.back()];
}
template <class T> void OUTS(vector<vector<T>> &df) {
for (auto &vec : df)
OUTS(vec);
}
// OUTL
void OUTL() {}
template <class Head, class... Tail> void OUTL(Head &&head, Tail &&...tail) {
cout << head << "\n";
OUTL(forward<Tail>(tail)...);
}
template <class T> void OUTL(vector<T> &vec) {
for (auto &e : vec)
cout << e << "\n";
}
// OUTN
void OUTN() {}
template <class Head, class... Tail> void OUTN(Head &&head, Tail &&...tail) {
cout << head;
OUTN(forward<Tail>(tail)...);
}
// }}} End
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
VAR(int, N);
vector<int> h(N);
rep(i, N) { IN(h[i]); }
h[N] = 0;
int res = 0;
while (true) {
bool all_of_zero = true;
reps(i, 1, N) {
if (!h[i] && h[i - 1])
++res;
if (h[i - 1]) {
--h[i - 1];
all_of_zero = false;
}
}
if (all_of_zero)
break;
}
OUTL(res);
return 0;
}
|
#include <bits/stdc++.h>
// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) \
Type __VA_ARGS__; \
IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
// IN
void IN() {}
template <class Head, class... Tail> void IN(Head &&head, Tail &&...tail) {
cin >> head;
IN(forward<Tail>(tail)...);
}
// OUTS
void OUTS() {}
template <class Head, class... Tail> void OUTS(Head &&head, Tail &&...tail) {
cout << head << " \n"[sizeof...(tail) == 0];
OUTS(forward<Tail>(tail)...);
}
template <class T> void OUTS(vector<T> &vec) {
for (auto &e : vec)
cout << e << " \n"[&e == &vec.back()];
}
template <class T> void OUTS(vector<vector<T>> &df) {
for (auto &vec : df)
OUTS(vec);
}
// OUTL
void OUTL() {}
template <class Head, class... Tail> void OUTL(Head &&head, Tail &&...tail) {
cout << head << "\n";
OUTL(forward<Tail>(tail)...);
}
template <class T> void OUTL(vector<T> &vec) {
for (auto &e : vec)
cout << e << "\n";
}
// OUTN
void OUTN() {}
template <class Head, class... Tail> void OUTN(Head &&head, Tail &&...tail) {
cout << head;
OUTN(forward<Tail>(tail)...);
}
// }}} End
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
VAR(int, N);
vector<int> h(N + 10);
rep(i, N) { IN(h[i]); }
h[N] = 0;
int res = 0;
while (true) {
bool all_of_zero = true;
reps(i, 1, N) {
if (!h[i] && h[i - 1])
++res;
if (h[i - 1]) {
--h[i - 1];
all_of_zero = false;
}
}
if (all_of_zero)
break;
}
OUTL(res);
return 0;
}
|
replace
| 78 | 79 | 78 | 79 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <stdio.h>
int nibun(int *, int, int, int);
int main(void) {
int n, h[200];
int ans;
ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
}
ans = nibun(h, 0, n, ans);
printf("%d\n", ans);
return 0;
}
int nibun(int *h, int start, int end, int ans) {
int i, j, k;
int min, mini;
min = 999;
mini = -1;
for (i = start; i < end; i++) {
if (min > h[i]) {
min = h[i];
mini = i;
}
}
if (min != 0 && min != 99) {
ans += min;
for (i = start; i < end; i++) {
h[i] -= min;
}
}
if (mini != 0) {
ans = nibun(h, start, mini, ans);
}
if (mini + 1 != end) {
ans = nibun(h, mini + 1, end, ans);
}
return ans;
}
|
#include <stdio.h>
int nibun(int *, int, int, int);
int main(void) {
int n, h[200];
int ans;
ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &h[i]);
}
ans = nibun(h, 0, n, ans);
printf("%d\n", ans);
return 0;
}
int nibun(int *h, int start, int end, int ans) {
int i, j, k;
int min, mini;
min = 999;
mini = -1;
for (i = start; i < end; i++) {
if (min > h[i]) {
min = h[i];
mini = i;
}
}
if (min != 0 && min != 99) {
ans += min;
for (i = start; i < end; i++) {
h[i] -= min;
}
}
if (mini != start) {
ans = nibun(h, start, mini, ans);
}
if (mini + 1 != end) {
ans = nibun(h, mini + 1, end, ans);
}
return ans;
}
|
replace
| 39 | 40 | 39 | 40 |
-11
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; ++i)
cin >> h[i];
// 高さが全部 0 になるまでやる
int res = 0;
while (true) {
// 最高高さが 0 だったらおしまい
if (*max_element(h.begin(), h.end()) == 0)
break;
// 区間分割する
int i = 0;
while (i < N) {
if (h[i] == 0)
++i; // 0 なら何もせずに次に進む
else {
++res; // 区間の始まり
while (h[i] > 0) {
--h[i]; // ついでに引いとく
++i; // 区間の終わりまで一気に
}
}
}
}
cout << res << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; ++i)
cin >> h[i];
// 高さが全部 0 になるまでやる
int res = 0;
while (true) {
// 最高高さが 0 だったらおしまい
if (*max_element(h.begin(), h.end()) == 0)
break;
// 区間分割する
int i = 0;
while (i < N) {
if (h[i] == 0)
++i; // 0 なら何もせずに次に進む
else {
++res; // 区間の始まり
while (i < N && h[i] > 0) {
--h[i]; // ついでに引いとく
++i; // 区間の終わりまで一気に
}
}
}
}
cout << res << endl;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
int left, right;
int water = 0;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
left = 0;
while (1) {
while (h[left] == 0) {
left++;
if (left == N)
break;
}
right = left;
while (h[right]) {
right++;
}
if (right > left)
water++;
for (int i = left; i < right; i++) {
h[i]--;
}
if (left == N)
break;
}
cout << water << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
int left, right;
int water = 0;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
left = 0;
while (1) {
while (h[left] == 0) {
left++;
if (left == N)
break;
}
if (left == N)
break;
right = left + 1;
if (right != N) {
while (h[right]) {
right++;
if (right == N)
break;
}
}
if (right > left)
water++;
for (int i = left; i < right; i++) {
h[i]--;
}
if (left == N)
break;
}
cout << water << endl;
return 0;
}
|
replace
| 21 | 24 | 21 | 30 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 1; i <= N; i++)
cin >> h[i];
long long int ans = 0, active = 0;
for (int i = 1; i <= N; i++) {
if (active < h[i]) {
ans += h[i] - active;
active = h[i];
} else
active = h[i];
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(1000);
for (int i = 1; i <= N; i++)
cin >> h[i];
long long int ans = 0, active = 0;
for (int i = 1; i <= N; i++) {
if (active < h[i]) {
ans += h[i] - active;
active = h[i];
} else
active = h[i];
}
cout << ans << endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03147
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
int c = 0;
int p = 0;
while (p < N) {
if (h[p] > 0) {
c++;
int s = p;
while (h[s] != 0) {
h[s]--;
s++;
}
} else {
p++;
}
}
cout << c << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++) {
cin >> h[i];
}
int c = 0;
int p = 0;
while (p < N) {
if (h[p] > 0) {
c++;
int s = p;
while (h[s] > 0 && s < N) {
h[s]--;
s++;
}
} else {
p++;
}
}
cout << c << endl;
}
|
replace
| 34 | 35 | 34 | 35 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.