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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03244 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define P pair<ll, ll>
#define INF 1000000000000000000
using namespace std;
int main(void) {
ll n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
map<ll, ll> b, c;
for (int i = 0; i < n; i++) {
if (i % 2) {
c[a[i]]++;
} else
b[a[i]]++;
}
vector<P> bs(0), cs(0);
for (auto p : b) {
bs.emplace_back(P(p.second, p.first));
}
for (auto p : c) {
cs.emplace_back(P(p.second, p.first));
}
sort(bs.begin(), bs.end());
sort(cs.begin(), cs.end());
if (bs[bs.size() - 1].second == cs[bs.size() - 1].second) {
if (bs.size() == 1) {
if (cs.size() == 1) {
cout << n / 2 << endl;
} else {
cout << n / 2 - cs[cs.size() - 2].first << endl;
}
} else {
if (cs.size() == 1)
cout << n / 2 - bs[bs.size() - 2].first << endl;
else {
ll s = bs[bs.size() - 1].first + cs[cs.size() - 2].first;
ll t = bs[bs.size() - 2].first + cs[cs.size() - 1].first;
cout << n - max(s, t) << endl;
}
}
} else
cout << n - bs[bs.size() - 1].first - cs[cs.size() - 1].first << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define P pair<ll, ll>
#define INF 1000000000000000000
using namespace std;
int main(void) {
ll n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
map<ll, ll> b, c;
for (int i = 0; i < n; i++) {
if (i % 2) {
c[a[i]]++;
} else
b[a[i]]++;
}
vector<P> bs(0), cs(0);
for (auto p : b) {
bs.emplace_back(P(p.second, p.first));
}
for (auto p : c) {
cs.emplace_back(P(p.second, p.first));
}
sort(bs.begin(), bs.end());
sort(cs.begin(), cs.end());
if (bs[bs.size() - 1].second == cs[cs.size() - 1].second) {
if (bs.size() == 1) {
if (cs.size() == 1) {
cout << n / 2 << endl;
} else {
cout << n / 2 - cs[cs.size() - 2].first << endl;
}
} else {
if (cs.size() == 1)
cout << n / 2 - bs[bs.size() - 2].first << endl;
else {
ll s = bs[bs.size() - 1].first + cs[cs.size() - 2].first;
ll t = bs[bs.size() - 2].first + cs[cs.size() - 1].first;
cout << n - max(s, t) << endl;
}
}
} else
cout << n - bs[bs.size() - 1].first - cs[cs.size() - 1].first << endl;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03244 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
#define INF 1e16
typedef pair<int, int> P;
typedef long long ll;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first > b.first)
return a.first > b.first;
else {
return a.second > b.second;
}
}
int main(void) {
int n;
cin >> n;
vector<int> odd, even, v(n);
vector<pair<int, int>> oddnum, evennum;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (i % 2 == 0)
even.push_back(v[i]);
else
odd.push_back(v[i]);
}
sort(even.begin(), even.end());
sort(odd.begin(), odd.end());
int i = 0;
for (i = 0; i < (int)even.size();) {
int j = i;
while (true) {
if (i == (int)even.size()) {
pair<int, int> p = make_pair(i - j, even[j]);
evennum.push_back(p);
break;
}
if (even[j] == even[i])
i++;
else {
pair<int, int> p = make_pair(i - j, even[j]);
evennum.push_back(p);
break;
}
}
}
for (i = 0; i < (int)odd.size();) {
int j = i;
while (true) {
if (i == (int)odd.size()) {
pair<int, int> p = make_pair(i - j, odd[j]);
oddnum.push_back(p);
break;
}
if (odd[j] == odd[i])
i++;
else {
pair<int, int> p = make_pair(i - j, odd[j]);
oddnum.push_back(p);
break;
}
}
}
int ans = 10000000;
sort(oddnum.begin(), oddnum.end(), cmp);
sort(evennum.begin(), evennum.end(), cmp);
int v1 = ((int)oddnum.size() == 1) ? 0 : oddnum[1].second;
int v2 = ((int)oddnum.size() == 1) ? 0 : oddnum[1].first;
int u1 = ((int)evennum.size() == 1) ? 0 : evennum[1].second;
int u2 = ((int)evennum.size() == 1) ? 0 : evennum[1].first;
if (oddnum[0].second != evennum[0].second)
ans = n - oddnum[0].first - evennum[0].first;
else {
if (v1 == v2) {
ans = min(ans, min(n / 2 - oddnum[0].first + n / 2 - u2,
n / 2 - v2 + n / 2 - evennum[0].first));
} else {
ans = min(ans, min(n / 2 - oddnum[0].first + n / 2 - u2,
n / 2 - v2 + n / 2 - evennum[0].first));
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
#define INF 1e16
typedef pair<int, int> P;
typedef long long ll;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first != b.first)
return a.first > b.first;
else {
return a.second > b.second;
}
}
int main(void) {
int n;
cin >> n;
vector<int> odd, even, v(n);
vector<pair<int, int>> oddnum, evennum;
for (int i = 0; i < n; i++) {
cin >> v[i];
if (i % 2 == 0)
even.push_back(v[i]);
else
odd.push_back(v[i]);
}
sort(even.begin(), even.end());
sort(odd.begin(), odd.end());
int i = 0;
for (i = 0; i < (int)even.size();) {
int j = i;
while (true) {
if (i == (int)even.size()) {
pair<int, int> p = make_pair(i - j, even[j]);
evennum.push_back(p);
break;
}
if (even[j] == even[i])
i++;
else {
pair<int, int> p = make_pair(i - j, even[j]);
evennum.push_back(p);
break;
}
}
}
for (i = 0; i < (int)odd.size();) {
int j = i;
while (true) {
if (i == (int)odd.size()) {
pair<int, int> p = make_pair(i - j, odd[j]);
oddnum.push_back(p);
break;
}
if (odd[j] == odd[i])
i++;
else {
pair<int, int> p = make_pair(i - j, odd[j]);
oddnum.push_back(p);
break;
}
}
}
int ans = 10000000;
sort(oddnum.begin(), oddnum.end(), cmp);
sort(evennum.begin(), evennum.end(), cmp);
int v1 = ((int)oddnum.size() == 1) ? 0 : oddnum[1].second;
int v2 = ((int)oddnum.size() == 1) ? 0 : oddnum[1].first;
int u1 = ((int)evennum.size() == 1) ? 0 : evennum[1].second;
int u2 = ((int)evennum.size() == 1) ? 0 : evennum[1].first;
if (oddnum[0].second != evennum[0].second)
ans = n - oddnum[0].first - evennum[0].first;
else {
if (v1 == v2) {
ans = min(ans, min(n / 2 - oddnum[0].first + n / 2 - u2,
n / 2 - v2 + n / 2 - evennum[0].first));
} else {
ans = min(ans, min(n / 2 - oddnum[0].first + n / 2 - u2,
n / 2 - v2 + n / 2 - evennum[0].first));
}
}
cout << ans << endl;
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03244 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()
typedef int64_t ll;
typedef vector<int> VI;
typedef pair<ll, ll> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
cerr << fst << ": ";
dbg(rst...);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
VI v(n);
rep(i, n) cin >> v[i];
map<int, int> me, mo;
rep(i, n) {
if (i % 2)
mo[v[i]]++;
else
me[v[i]]++;
}
vector<pii> ve, vo;
for (auto q : me)
ve.emplace_back(q.second, q.first);
for (auto q : mo)
vo.emplace_back(q.second, q.first);
sort(rbegin(ve), rend(ve));
sort(rbegin(vo), rend(vo));
int ans = min(n - ve[0].first, n - vo[0].first);
rep(i, min(sz(ve), 4)) rep(j, min(sz(vo), 4)) {
if (ve[i].second == vo[j].second)
continue;
int ct = 0;
rep(k, n) {
dbg(k, v[k], ve[i].second, vo[j].second);
if (k % 2 && v[k] != vo[i].second)
ct++;
else if (k % 2 == 0 && v[k] != ve[j].second)
ct++;
}
// dbg(i,j,ct);
ans = min(ans, ct);
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()
typedef int64_t ll;
typedef vector<int> VI;
typedef pair<ll, ll> pii;
const int MD = 1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
cerr << fst << ": ";
dbg(rst...);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
VI v(n);
rep(i, n) cin >> v[i];
map<int, int> me, mo;
rep(i, n) {
if (i % 2)
mo[v[i]]++;
else
me[v[i]]++;
}
vector<pii> ve, vo;
for (auto q : me)
ve.emplace_back(q.second, q.first);
for (auto q : mo)
vo.emplace_back(q.second, q.first);
sort(rbegin(ve), rend(ve));
sort(rbegin(vo), rend(vo));
int ans = min(n - ve[0].first, n - vo[0].first);
rep(i, min(sz(ve), 4)) rep(j, min(sz(vo), 4)) {
if (ve[i].second == vo[j].second)
continue;
int ct = n - ve[i].first - vo[j].first;
// dbg(i,j,ct);
ans = min(ans, ct);
}
cout << ans << "\n";
return 0;
}
| replace | 49 | 57 | 49 | 51 | TLE | |
p03244 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n / 2), b(n / 2);
int init_a = 0;
int init_b = 0;
int mx_a, mx_b;
rep(i, n) {
if (i % 2 == 0) {
int x;
cin >> x;
a[x]++;
if (a[x] > init_a) {
init_a = a[x];
mx_a = x;
}
} else {
int x;
cin >> x;
b[x]++;
if (b[x] > init_b) {
init_b = b[x];
mx_b = x;
}
}
}
if (mx_a != mx_b)
cout << n - a[mx_a] - b[mx_b] << endl;
else {
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
int ans = 1e9;
ans = min(ans, n - a[1] - b[0]);
ans = min(ans, n - a[0] - b[1]);
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(100005), b(100005);
int init_a = 0;
int init_b = 0;
int mx_a, mx_b;
rep(i, n) {
if (i % 2 == 0) {
int x;
cin >> x;
a[x]++;
if (a[x] > init_a) {
init_a = a[x];
mx_a = x;
}
} else {
int x;
cin >> x;
b[x]++;
if (b[x] > init_b) {
init_b = b[x];
mx_b = x;
}
}
}
if (mx_a != mx_b)
cout << n - a[mx_a] - b[mx_b] << endl;
else {
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
int ans = 1e9;
ans = min(ans, n - a[1] - b[0]);
ans = min(ans, n - a[0] - b[1]);
cout << ans << endl;
}
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03244 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
// O(N log N)
int solve2(vector<int> v) {
int N = (int)v.size();
map<int, int> cnt;
cnt.clear();
rep(i, N) { ++cnt[v[i]]; } // end rep
vector<P> rank;
rank.clear();
map<int, int>::iterator it = cnt.begin();
for (; it != cnt.end(); ++it) {
int n = (*it).first;
int c = (*it).second;
rank.push_back(P(-c, n));
} // end for
sort(ALL(rank));
int res = N;
if (rank.size() == 1) {
res = min(res, N / 2);
} else if (rank.size() >= 2) {
vector<int> n((int)min(10, N), 0);
rep(i, (int)min(10, N)) n[i] = rank[i].second;
sort(ALL(n));
do {
int curr = 0;
rep(i, N) {
if (i % 2 == 0) {
curr += (int)(v[i] != n[0]);
} else { // if (i % 2 == 1)
curr += (int)(v[i] != n[1]);
} // end if
} // end rep
res = min(res, curr);
} while (next_permutation(ALL(n)));
} // end if
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> v(N, 0);
rep(i, N) { cin >> v[i]; } // end rep
int res = solve2(v);
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
// O(N log N)
int solve2(vector<int> v) {
int N = (int)v.size();
map<int, int> cnt;
cnt.clear();
rep(i, N) { ++cnt[v[i]]; } // end rep
vector<P> rank;
rank.clear();
map<int, int>::iterator it = cnt.begin();
for (; it != cnt.end(); ++it) {
int n = (*it).first;
int c = (*it).second;
rank.push_back(P(-c, n));
} // end for
sort(ALL(rank));
int res = N;
if (rank.size() == 1) {
res = min(res, N / 2);
} else if (rank.size() >= 2) {
vector<int> n((int)min(7, N), 0);
rep(i, (int)min(7, N)) n[i] = rank[i].second;
sort(ALL(n));
do {
int curr = 0;
rep(i, N) {
if (i % 2 == 0) {
curr += (int)(v[i] != n[0]);
} else { // if (i % 2 == 1)
curr += (int)(v[i] != n[1]);
} // end if
} // end rep
res = min(res, curr);
} while (next_permutation(ALL(n)));
} // end if
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<int> v(N, 0);
rep(i, N) { cin >> v[i]; } // end rep
int res = solve2(v);
cout << res << endl;
return 0;
} | replace | 32 | 34 | 32 | 34 | TLE | |
p03244 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> odd(100000, 0);
vector<int> even(100000, 0);
int od = 0, ev = 0;
rep(i, N) {
int t;
cin >> t;
if (i % 2 == 0) {
odd[t]++;
if (odd[t] > odd[od])
od = t;
} else {
even[t]++;
if (even[t] > even[ev])
ev = t;
}
}
sort(odd.begin(), odd.end());
reverse(odd.begin(), odd.end());
sort(even.begin(), even.end());
reverse(even.begin(), even.end());
if (od == ev) {
cout << N - max(even[0] + odd[1], even[1] + odd[0]) << endl;
} else
cout << N - even[0] - odd[0] << endl;
} | #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> odd(100010, 0);
vector<int> even(100010, 0);
int od = 0, ev = 0;
rep(i, N) {
int t;
cin >> t;
if (i % 2 == 0) {
odd[t]++;
if (odd[t] > odd[od])
od = t;
} else {
even[t]++;
if (even[t] > even[ev])
ev = t;
}
}
sort(odd.begin(), odd.end());
reverse(odd.begin(), odd.end());
sort(even.begin(), even.end());
reverse(even.begin(), even.end());
if (od == ev) {
cout << N - max(even[0] + odd[1], even[1] + odd[0]) << endl;
} else
cout << N - even[0] - odd[0] << endl;
} | replace | 10 | 12 | 10 | 12 | TLE | |
p03244 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int v[n];
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> cnt1, cnt2;
for (int i = 0; i < n; i++) {
if (i % 2)
cnt2.push_back(v[i]);
else
cnt1.push_back(v[i]);
}
map<int, int> CNT1, CNT2;
for (int i = 0; i < cnt1.size(); i++) {
CNT1[cnt1[i]]++;
}
for (int i = 0; i < cnt2.size(); i++) {
CNT2[cnt2[i]]++;
}
int ans = 0;
int ma = -1;
vector<int> ANS;
for (auto e : CNT1) {
if (ma < e.second) {
ANS.resize(1);
ANS[0] = e.first;
} else if (ma == e.second)
ANS.push_back(e.first);
ma = max(ma, e.second);
}
ans += cnt1.size() - ma;
ma = 0;
for (auto e : CNT2)
for (auto E : ANS)
if (E != e.first)
ma = max(ma, e.second);
int ans1 = ans + cnt2.size() - ma;
ans = 0;
ma = -1;
ANS.resize(0);
for (auto e : CNT2) {
if (ma < e.second) {
ANS.resize(1);
ANS[0] = e.first;
} else if (ma == e.second && ANS.size() == 1)
ANS.push_back(e.first);
ma = max(ma, e.second);
}
ans += cnt2.size() - ma;
ma = 0;
for (auto e : CNT1)
for (auto E : ANS)
if (E != e.first)
ma = max(ma, e.second);
int ans2 = ans + cnt1.size() - ma;
cout << min(ans1, ans2) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int v[n];
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> cnt1, cnt2;
for (int i = 0; i < n; i++) {
if (i % 2)
cnt2.push_back(v[i]);
else
cnt1.push_back(v[i]);
}
map<int, int> CNT1, CNT2;
for (int i = 0; i < cnt1.size(); i++) {
CNT1[cnt1[i]]++;
}
for (int i = 0; i < cnt2.size(); i++) {
CNT2[cnt2[i]]++;
}
int ans = 0;
int ma = -1;
vector<int> ANS;
for (auto e : CNT1) {
if (ma < e.second) {
ANS.resize(1);
ANS[0] = e.first;
} else if (ma == e.second && ANS.size() == 1)
ANS.push_back(e.first);
ma = max(ma, e.second);
}
ans += cnt1.size() - ma;
ma = 0;
for (auto e : CNT2)
for (auto E : ANS)
if (E != e.first)
ma = max(ma, e.second);
int ans1 = ans + cnt2.size() - ma;
ans = 0;
ma = -1;
ANS.resize(0);
for (auto e : CNT2) {
if (ma < e.second) {
ANS.resize(1);
ANS[0] = e.first;
} else if (ma == e.second && ANS.size() == 1)
ANS.push_back(e.first);
ma = max(ma, e.second);
}
ans += cnt2.size() - ma;
ma = 0;
for (auto e : CNT1)
for (auto E : ANS)
if (E != e.first)
ma = max(ma, e.second);
int ans2 = ans + cnt1.size() - ma;
cout << min(ans1, ans2) << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p03244 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(), a.end()
#define mod 1000000007
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
using namespace std;
using graph = vector<vector<ll>>;
const ll MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void cominit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll 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;
}
}
// 二項係数計算nCk
ll com(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 二項係数計算nPk
ll per(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[n - k] % MOD) % MOD;
}
// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll 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 gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
/*最小公倍数*/
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
/*二点間の距離*/
double dist(pair<double, double> a, pair<double, double> b) {
return sqrt(pow((a.first - b.first), 2) + pow((a.second - b.second), 2));
}
// 繰り返し自乗法
double ism(double aa, ll p) {
double ap = aa;
double ans = 1;
while (p > 0) {
// cout<<"p="<<p<<",ap="<<ap<<endl;
if (p & 1) { // 奇数が真
ans *= ap;
}
p /= 2;
ap = ap * ap;
}
return ans;
}
// 繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa, ll p, ll m) {
ll ap = aa;
ll ans = 1;
while (p > 0) {
// cout<<"p="<<p<<",ap="<<ap<<endl;
if (p & 1) { // 奇数が真
ans = (ans * ap) % m;
}
p /= 2;
ap = (ap * ap) % m;
}
return ans;
}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
if(m==0){
return 1;
}
if(i>=n){
return 0;
}
cout<<i+1<<" "<<m<<endl;
cout<<i+1<<" "<<m-t[i]<<endl;
ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
return res;
}
*/
struct UnionFind {
vector<ll> par;
UnionFind(ll n) : par(n, -1) {}
ll root(ll x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(ll x, ll y) { return root(x) == root(y); }
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) { return -par[root(x)]; }
};
using pint = pair<ll, ll>;
// 小数点12桁
struct all_init {
all_init() { cout << fixed << setprecision(12); }
} All_init;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
map<ll, ll> mx, my;
rep(i, 0, n) {
cin >> a[i];
if (i % 2 == 0) {
mx[a[i]]++;
} else {
my[a[i]]++;
}
}
vector<P> px, py;
for (auto x : mx) {
px.push_back({x.second, x.first});
}
for (auto y : my) {
py.push_back({y.second, y.first});
}
sort(all(px), greater<P>());
sort(all(py), greater<P>());
px.push_back({0, 0});
py.push_back({0, 0});
rep(i, 0, px.size()) {
// cout<<px[i].first<<" "<<px[i].second<<endl;
}
ll i = 0, j = 0, ans = a.size();
while (i < px.size() - 2) {
if (px[i].second != py[j].second) {
ans = min(ans, (ll)(a.size() - px[i].first - py[j].first));
}
if (px[i].second != py[j + 1].second) {
ans = min(ans, (ll)(a.size() - px[i].first - py[j + 1].first));
}
if (px[i + 1].second != py[j].second) {
ans = min(ans, (ll)(a.size() - px[i + 1].first - py[j].first));
}
i++;
j++;
}
cout << ans << endl;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(), a.end()
#define mod 1000000007
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
using namespace std;
using graph = vector<vector<ll>>;
const ll MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void cominit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll 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;
}
}
// 二項係数計算nCk
ll com(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 二項係数計算nPk
ll per(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[n - k] % MOD) % MOD;
}
// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll 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 gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
/*最小公倍数*/
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
/*二点間の距離*/
double dist(pair<double, double> a, pair<double, double> b) {
return sqrt(pow((a.first - b.first), 2) + pow((a.second - b.second), 2));
}
// 繰り返し自乗法
double ism(double aa, ll p) {
double ap = aa;
double ans = 1;
while (p > 0) {
// cout<<"p="<<p<<",ap="<<ap<<endl;
if (p & 1) { // 奇数が真
ans *= ap;
}
p /= 2;
ap = ap * ap;
}
return ans;
}
// 繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa, ll p, ll m) {
ll ap = aa;
ll ans = 1;
while (p > 0) {
// cout<<"p="<<p<<",ap="<<ap<<endl;
if (p & 1) { // 奇数が真
ans = (ans * ap) % m;
}
p /= 2;
ap = (ap * ap) % m;
}
return ans;
}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
if(m==0){
return 1;
}
if(i>=n){
return 0;
}
cout<<i+1<<" "<<m<<endl;
cout<<i+1<<" "<<m-t[i]<<endl;
ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
return res;
}
*/
struct UnionFind {
vector<ll> par;
UnionFind(ll n) : par(n, -1) {}
ll root(ll x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(ll x, ll y) { return root(x) == root(y); }
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) { return -par[root(x)]; }
};
using pint = pair<ll, ll>;
// 小数点12桁
struct all_init {
all_init() { cout << fixed << setprecision(12); }
} All_init;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
map<ll, ll> mx, my;
rep(i, 0, n) {
cin >> a[i];
if (i % 2 == 0) {
mx[a[i]]++;
} else {
my[a[i]]++;
}
}
vector<P> px, py;
for (auto x : mx) {
px.push_back({x.second, x.first});
}
for (auto y : my) {
py.push_back({y.second, y.first});
}
sort(all(px), greater<P>());
sort(all(py), greater<P>());
px.push_back({0, 0});
py.push_back({0, 0});
rep(i, 0, px.size()) {
// cout<<px[i].first<<" "<<px[i].second<<endl;
}
ll ans = a.size();
if (px[0].second != py[0].second) {
ans = min(ans, (ll)(a.size() - px[0].first - py[0].first));
}
if (px[0].second != py[1].second) {
ans = min(ans, (ll)(a.size() - px[0].first - py[1].first));
}
if (px[1].second != py[0].second) {
ans = min(ans, (ll)(a.size() - px[1].first - py[0].first));
}
cout << ans << endl;
}
| replace | 191 | 206 | 191 | 202 | 0 | |
p03244 | C++ | Runtime Error | //
// AtCoder Beginner Contest 111
// C
// https://atcoder.jp/contests/abc111/tasks/arc103_a
//
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } // 最小公倍数
int main() {
int n;
cin >> n;
vector<pair<int, int>> vOddCnt(10010);
vector<pair<int, int>> vEvenCnt(10010);
REP(i, n) {
int v;
cin >> v;
if (i % 2 == 0) {
vOddCnt[v].first++;
vOddCnt[v].second = v;
} else {
vEvenCnt[v].first++;
vEvenCnt[v].second = v;
}
}
sort(RALL(vOddCnt));
sort(RALL(vEvenCnt));
int ans = 0;
if (vOddCnt[0].second == vEvenCnt[0].second) {
int a1 = (n / 2 - vOddCnt[0].first) + (n / 2 - vEvenCnt[1].first);
int a2 = (n / 2 - vOddCnt[1].first) + (n / 2 - vEvenCnt[0].first);
ans = min(a1, a2);
} else {
ans += n / 2 - vOddCnt[0].first;
ans += n / 2 - vEvenCnt[0].first;
}
cout << ans << endl;
return 0;
}
| //
// AtCoder Beginner Contest 111
// C
// https://atcoder.jp/contests/abc111/tasks/arc103_a
//
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } // 最小公倍数
int main() {
int n;
cin >> n;
vector<pair<int, int>> vOddCnt(100010);
vector<pair<int, int>> vEvenCnt(100010);
REP(i, n) {
int v;
cin >> v;
if (i % 2 == 0) {
vOddCnt[v].first++;
vOddCnt[v].second = v;
} else {
vEvenCnt[v].first++;
vEvenCnt[v].second = v;
}
}
sort(RALL(vOddCnt));
sort(RALL(vEvenCnt));
int ans = 0;
if (vOddCnt[0].second == vEvenCnt[0].second) {
int a1 = (n / 2 - vOddCnt[0].first) + (n / 2 - vEvenCnt[1].first);
int a2 = (n / 2 - vOddCnt[1].first) + (n / 2 - vEvenCnt[0].first);
ans = min(a1, a2);
} else {
ans += n / 2 - vOddCnt[0].first;
ans += n / 2 - vEvenCnt[0].first;
}
cout << ans << endl;
return 0;
}
| replace | 48 | 50 | 48 | 50 | 0 | |
p03244 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> mode2(vector<int> a) {
sort(a.begin(), a.end());
int temp1, temp1n;
int temp2, temp2n;
int p = 0;
temp1n = 0;
temp2n = 0;
for (int i = 0; i < a.size() - 1; i++) {
if (a[i] == a[i + 1]) {
p++;
} else {
if (temp1n < p + 1) {
temp2 = temp1;
temp2n = temp1n;
temp1n = p + 1;
temp1 = a[i];
} else if (temp2n < p + 1) {
temp2n = p + 1;
temp2 = a[i];
}
p = 0;
}
}
if (a[a.size() - 2] == a[a.size() - 1]) {
if (temp1n < p + 1) {
temp2 = temp1;
temp2n = temp1n;
temp1n = p + 1;
temp1 = a[a[a.size() - 1]];
} else if (temp2n < p + 1) {
temp2n = p + 1;
temp2 = a[a.size() - 1];
}
}
vector<int> mode = {temp1, temp1n, temp2, temp2n};
return mode;
}
int main() {
int n;
cin >> n;
vector<int> a;
vector<int> b;
int p;
for (int i = 0; i < (n / 2); i++) {
cin >> p;
a.push_back(p);
cin >> p;
b.push_back(p);
}
vector<int> amode = mode2(a);
vector<int> bmode = mode2(b);
int ans;
if (amode[0] != bmode[0]) {
ans = n - amode[1] - bmode[1];
} else {
ans = min(n - amode[3] - bmode[1], n - amode[1] - bmode[3]);
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> mode2(vector<int> a) {
sort(a.begin(), a.end());
int temp1, temp1n;
int temp2, temp2n;
int p = 0;
temp1n = 0;
temp2n = 0;
for (int i = 0; i < a.size() - 1; i++) {
if (a[i] == a[i + 1]) {
p++;
} else {
if (temp1n < p + 1) {
temp2 = temp1;
temp2n = temp1n;
temp1n = p + 1;
temp1 = a[i];
} else if (temp2n < p + 1) {
temp2n = p + 1;
temp2 = a[i];
}
p = 0;
}
}
if (a[a.size() - 2] == a[a.size() - 1]) {
if (temp1n < p + 1) {
temp2 = temp1;
temp2n = temp1n;
temp1n = p + 1;
temp1 = a[a.size() - 1];
} else if (temp2n < p + 1) {
temp2n = p + 1;
temp2 = a[a.size() - 1];
}
}
vector<int> mode = {temp1, temp1n, temp2, temp2n};
return mode;
}
int main() {
int n;
cin >> n;
vector<int> a;
vector<int> b;
int p;
for (int i = 0; i < (n / 2); i++) {
cin >> p;
a.push_back(p);
cin >> p;
b.push_back(p);
}
vector<int> amode = mode2(a);
vector<int> bmode = mode2(b);
int ans;
if (amode[0] != bmode[0]) {
ans = n - amode[1] - bmode[1];
} else {
ans = min(n - amode[3] - bmode[1], n - amode[1] - bmode[3]);
}
cout << ans << endl;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p03244 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll n;
cin >> n;
ll e[n], o[n], k = 0, l = 0;
for (ll i = 0; i < n; i++) {
if (i % 2 == 0) {
cin >> e[k];
k++;
} else {
cin >> o[l];
l++;
}
}
vector<pair<ll, ll>> ee, oo;
k = n / 2;
sort(e, e + k);
ll c = 1;
for (ll i = 0; i < k; i++) { // 配列の中身がそれぞれ何個あるかのカウント
if (e[i] == e[i + 1]) {
c++;
if (i == k - 2) { // 122333みたいなときは3のところがansに入らないので
ee.push_back(make_pair(c, e[i]));
break;
}
} else {
ee.push_back(make_pair(c, e[i]));
if (i == k - 2) {
ee.push_back(
make_pair(1, e[i + 1])); // 112223とかのときにansに3の分を足すため
break;
}
c = 1;
}
}
sort(o, o + k);
c = 1;
for (ll i = 0; i < k; i++) { // 配列の中身がそれぞれ何個あるかのカウント
if (o[i] == o[i + 1]) {
c++;
if (i == k - 2) { // 122333みたいなときは3のところがansに入らないので
oo.push_back(make_pair(c, o[i]));
break;
}
} else {
oo.push_back(make_pair(c, o[i]));
if (i == k - 2) {
oo.push_back(
make_pair(1, o[i + 1])); // 112223とかのときにansに3の分を足すため
break;
}
c = 1;
}
}
sort(ee.begin(), ee.end());
sort(oo.begin(), oo.end());
ll es = ee.size();
ll os = oo.size();
if (es == 1 && os == 1) {
if (ee[0].second == oo[0].second) {
cout << k << endl;
return 0;
} else {
cout << 0 << endl;
return 0;
}
}
if (ee[es - 1].second != oo[os - 1].second) {
cout << (k - ee[es - 1].first) + (k - oo[es - 1].first) << endl;
return 0;
} else {
if (es == 1) {
cout << (k - ee[es - 1].first) + (k - oo[os - 2].first) << endl;
return 0;
}
if (os == 1) {
cout << (k - ee[es - 2].first) + (k - oo[os - 1].first) << endl;
return 0;
}
ll p = (k - ee[es - 1].first) + (k - oo[os - 2].first);
ll q = (k - ee[es - 2].first) + (k - oo[os - 1].first);
cout << min(p, q) << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll n;
cin >> n;
ll e[n], o[n], k = 0, l = 0;
for (ll i = 0; i < n; i++) {
if (i % 2 == 0) {
cin >> e[k];
k++;
} else {
cin >> o[l];
l++;
}
}
vector<pair<ll, ll>> ee, oo;
k = n / 2;
sort(e, e + k);
ll c = 1;
for (ll i = 0; i < k; i++) { // 配列の中身がそれぞれ何個あるかのカウント
if (e[i] == e[i + 1]) {
c++;
if (i == k - 2) { // 122333みたいなときは3のところがansに入らないので
ee.push_back(make_pair(c, e[i]));
break;
}
} else {
ee.push_back(make_pair(c, e[i]));
if (i == k - 2) {
ee.push_back(
make_pair(1, e[i + 1])); // 112223とかのときにansに3の分を足すため
break;
}
c = 1;
}
}
sort(o, o + k);
c = 1;
for (ll i = 0; i < k; i++) { // 配列の中身がそれぞれ何個あるかのカウント
if (o[i] == o[i + 1]) {
c++;
if (i == k - 2) { // 122333みたいなときは3のところがansに入らないので
oo.push_back(make_pair(c, o[i]));
break;
}
} else {
oo.push_back(make_pair(c, o[i]));
if (i == k - 2) {
oo.push_back(
make_pair(1, o[i + 1])); // 112223とかのときにansに3の分を足すため
break;
}
c = 1;
}
}
sort(ee.begin(), ee.end());
sort(oo.begin(), oo.end());
ll es = ee.size();
ll os = oo.size();
if (es == 1 && os == 1) {
if (ee[0].second == oo[0].second) {
cout << k << endl;
return 0;
} else {
cout << 0 << endl;
return 0;
}
}
if (ee[es - 1].second != oo[os - 1].second) {
cout << (k - ee[es - 1].first) + (k - oo[os - 1].first) << endl;
return 0;
} else {
if (es == 1) {
cout << (k - ee[es - 1].first) + (k - oo[os - 2].first) << endl;
return 0;
}
if (os == 1) {
cout << (k - ee[es - 2].first) + (k - oo[os - 1].first) << endl;
return 0;
}
ll p = (k - ee[es - 1].first) + (k - oo[os - 2].first);
ll q = (k - ee[es - 2].first) + (k - oo[os - 1].first);
cout << min(p, q) << endl;
}
}
| replace | 70 | 71 | 70 | 71 | 0 | |
p03244 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int N;
vector<int> V;
cin >> N;
V.resize(N);
REP(i, N) { cin >> V[i]; }
// key: 数, val: 出現数
map<int, int> even, odd;
REP(i, N) {
if (i % 2 == 0) {
even[V[i]]++;
} else {
odd[V[i]]++;
}
}
vector<pair<int, int>> v_even, v_odd;
for (auto &tmp : even) {
v_even.push_back(make_pair(tmp.second, tmp.first));
}
v_even.push_back(make_pair(0, -1));
for (auto &tmp : odd) {
v_odd.push_back(make_pair(tmp.second, tmp.first));
}
v_odd.push_back(make_pair(0, -1));
SORT(v_even);
reverse(v_even.begin(), v_even.end());
SORT(v_odd);
reverse(v_odd.begin(), v_odd.end());
int ans = N;
REP(i, v_even.size()) {
REP(j, v_odd.size()) {
if (v_even[i].second != v_odd[j].second) {
ans = min(ans, N - v_even[i].first - v_odd[j].first);
}
}
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int N;
vector<int> V;
cin >> N;
V.resize(N);
REP(i, N) { cin >> V[i]; }
// key: 数, val: 出現数
map<int, int> even, odd;
REP(i, N) {
if (i % 2 == 0) {
even[V[i]]++;
} else {
odd[V[i]]++;
}
}
vector<pair<int, int>> v_even, v_odd;
for (auto &tmp : even) {
v_even.push_back(make_pair(tmp.second, tmp.first));
}
v_even.push_back(make_pair(0, -1));
for (auto &tmp : odd) {
v_odd.push_back(make_pair(tmp.second, tmp.first));
}
v_odd.push_back(make_pair(0, -1));
SORT(v_even);
reverse(v_even.begin(), v_even.end());
SORT(v_odd);
reverse(v_odd.begin(), v_odd.end());
int ans = N;
int i_n = v_even.size();
if (i_n > 10) {
i_n = 10;
}
int j_n = v_odd.size();
if (j_n > 10) {
j_n = 10;
}
for (int i = 0; i < i_n; ++i) {
for (int j = 0; j < j_n; ++j) {
if (v_even[i].second != v_odd[j].second) {
ans = min(ans, N - v_even[i].first - v_odd[j].first);
}
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 61 | 63 | 61 | 71 | TLE | |
p03244 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX 3005
#define mp make_pair
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
int cnt1[MAX], cnt2[MAX], arr[MAX], vis1[MAX], vis2[MAX];
priority_queue<ii> pq1, pq2;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
(i % 2) ? cnt2[arr[i]]++ : cnt1[arr[i]]++;
}
for (int i = 0; i < n; i++) {
if (i % 2 && !vis2[arr[i]]) {
vis2[arr[i]] = 1;
pq2.push(mp(cnt2[arr[i]], arr[i]));
} else if (i % 2 == 0 && !vis1[arr[i]]) {
vis1[arr[i]] = 1;
pq1.push(mp(cnt1[arr[i]], arr[i]));
}
}
ii u = pq1.top(), v = pq2.top();
int ans;
if (u.second != v.second) {
ans = (n / 2) - u.first + (n / 2) - v.first;
cout << ans << endl;
return 0;
}
int p = 0, q = 0, r = 0, s = 0;
p = u.first;
pq1.pop();
q = v.first;
pq2.pop();
if (!pq1.empty())
r = pq1.top().first;
if (!pq2.empty())
s = pq2.top().first;
ans = (n / 2) - p + (n / 2) - s;
ans = min(ans, (n / 2) - q + (n / 2) - r);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define MAX 100005
#define mp make_pair
using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
int cnt1[MAX], cnt2[MAX], arr[MAX], vis1[MAX], vis2[MAX];
priority_queue<ii> pq1, pq2;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
(i % 2) ? cnt2[arr[i]]++ : cnt1[arr[i]]++;
}
for (int i = 0; i < n; i++) {
if (i % 2 && !vis2[arr[i]]) {
vis2[arr[i]] = 1;
pq2.push(mp(cnt2[arr[i]], arr[i]));
} else if (i % 2 == 0 && !vis1[arr[i]]) {
vis1[arr[i]] = 1;
pq1.push(mp(cnt1[arr[i]], arr[i]));
}
}
ii u = pq1.top(), v = pq2.top();
int ans;
if (u.second != v.second) {
ans = (n / 2) - u.first + (n / 2) - v.first;
cout << ans << endl;
return 0;
}
int p = 0, q = 0, r = 0, s = 0;
p = u.first;
pq1.pop();
q = v.first;
pq2.pop();
if (!pq1.empty())
r = pq1.top().first;
if (!pq2.empty())
s = pq2.top().first;
ans = (n / 2) - p + (n / 2) - s;
ans = min(ans, (n / 2) - q + (n / 2) - r);
cout << ans << endl;
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p03244 | Python | Runtime Error | import collections
n = int(input())
v = list(map(int, input().split()))
odd = collections.defaultdict(int)
even = collections.defaultdict(int)
for i in range(n):
if i % 2 == 0:
even[v[i]] += 1
else:
odd[v[i]] += 1
even = list(even.items())
odd = list(odd.items())
even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)
if even[0][0] == odd[0][0]:
if len(even) == 1 and len(odd) == 1:
print(n // 2)
elif len(even) == 1:
print(n - (even[0][1] + odd[1][1]))
elif len(odd) == 1:
print(n - (even[1][1] + odd[0][1]))
else:
print(min(n - (even[1][1] + odd[0][1])), (n - (even[0][1] + odd[1][1])))
else:
print(n - (even[0][1] + odd[0][1]))
| import collections
n = int(input())
v = list(map(int, input().split()))
odd = collections.defaultdict(int)
even = collections.defaultdict(int)
for i in range(n):
if i % 2 == 0:
even[v[i]] += 1
else:
odd[v[i]] += 1
even = list(even.items())
odd = list(odd.items())
even.sort(key=lambda x: x[1], reverse=True)
odd.sort(key=lambda x: x[1], reverse=True)
if even[0][0] == odd[0][0]:
if len(even) == 1 and len(odd) == 1:
print(n // 2)
elif len(even) == 1:
print(n - (even[0][1] + odd[1][1]))
elif len(odd) == 1:
print(n - (even[1][1] + odd[0][1]))
else:
print(min(n - (even[1][1] + odd[0][1]), n - (even[0][1] + odd[1][1])))
else:
print(n - (even[0][1] + odd[0][1]))
| replace | 30 | 31 | 30 | 31 | 0 | |
p03244 | Python | Runtime Error | from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
print(n // 2)
else:
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[i + 1] for i in range(0, n, 2)]
kw1 = Counter(v1)
kw2 = Counter(v2)
x1 = kw1.most_common()[0][0]
x2 = kw2.most_common()[0][0]
if x1 != x2:
ans = 0
for i in v1:
if i != x1:
ans += 1
for i in v2:
if i != x2:
ans += 1
else:
y1 = kw1.most_common()[1][0]
y2 = kw2.most_common()[1][0]
ans1 = 0
ans2 = 0
for i in v1:
if i != y1:
ans1 += 1
for i in v2:
if i != x2:
ans1 += 1
for i in v1:
if i != x1:
ans2 += 1
for i in v2:
if i != y2:
ans2 += 1
ans = min(ans1, ans2)
print(ans)
| from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
print(n // 2)
else:
v1 = [v[i] for i in range(0, n, 2)]
v2 = [v[i + 1] for i in range(0, n, 2)]
kw1 = Counter(v1)
kw2 = Counter(v2)
x1 = kw1.most_common()[0][0]
x2 = kw2.most_common()[0][0]
if x1 != x2:
ans = 0
for i in v1:
if i != x1:
ans += 1
for i in v2:
if i != x2:
ans += 1
else:
y1 = kw1.most_common()[1][0]
y2 = kw2.most_common()[1][0]
ans1 = 0
ans2 = 0
for i in v1:
if i != y1:
ans1 += 1
for i in v2:
if i != x2:
ans1 += 1
for i in v1:
if i != x1:
ans2 += 1
for i in v2:
if i != y2:
ans2 += 1
ans = min(ans1, ans2)
print(ans)
| replace | 48 | 49 | 48 | 49 | 0 | |
p03244 | Python | Runtime Error | from collections import Counter
N = int(input())
index = 0
even_numbers = []
odd_numbers = []
for i in input().split():
if index % 2 == 0:
even_numbers.append(int(i))
else:
odd_numbers.append(int(i))
index += 1
even = Counter(even_numbers).most_common(2)
odd = Counter(odd_numbers).most_common(2)
if even[0][1] == odd[0][1]:
print(min(N - even[0][1] - odd[1][1], N - even[1][1] - odd[0][1]))
else:
print(N - even[0][1] - odd[0][1])
| from collections import Counter
N = int(input())
index = 0
even_numbers = []
odd_numbers = []
for i in input().split():
if index % 2 == 0:
even_numbers.append(int(i))
else:
odd_numbers.append(int(i))
index += 1
even = Counter(even_numbers).most_common(2)
odd = Counter(odd_numbers).most_common(2)
if even[0][0] == odd[0][0]:
if len(even) == 1:
print(N // 2)
else:
print(N - even[0][1] - max(even[1][1], odd[1][1]))
else:
print(N - even[0][1] - odd[0][1])
| replace | 18 | 20 | 18 | 23 | 0 | |
p03244 | Python | Runtime Error | n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (n + 1)
odd_list = [0] * (n + 1)
for i in range(n):
if i % 2 == 0:
even_list[v[i]] += 1
else:
odd_list[v[i]] += 1
if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
print(
min(n - even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1])
)
else:
print(n - max(even_list) - max(odd_list))
| n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (100000 + 1)
odd_list = [0] * (100000 + 1)
for i in range(n):
if i % 2 == 0:
even_list[v[i]] += 1
else:
odd_list[v[i]] += 1
if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
print(
min(n - even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1])
)
else:
print(n - max(even_list) - max(odd_list))
| replace | 2 | 4 | 2 | 4 | 0 | |
p03244 | Python | Runtime Error | from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
print(n // 2)
else:
c1m = c1.most_common(1)
c2m = c2.most_common(1)
if c1m[0][0] == c2m[0][0]:
print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
else:
print(n - c1m[0][1] - c2m[0][1])
| from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
print(n // 2)
else:
c1m = c1.most_common(2)
c2m = c2.most_common(2)
if c1m[0][0] == c2m[0][0]:
print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
else:
print(n - c1m[0][1] - c2m[0][1])
| replace | 9 | 11 | 9 | 11 | 0 | |
p03244 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
const int Vmax = 100000;
using pii = pair<int, int>;
int N, buf;
cin >> N;
int Nhalf = N / 2;
vector<pii> odd;
vector<pii> even;
for (int i = 1; i <= Vmax; i++) {
odd.emplace_back(make_pair(i, 0));
even.emplace_back(make_pair(i, 0));
}
for (int i = 0; i < N; i += 2) {
cin >> buf;
odd.at(buf).second++;
cin >> buf;
even.at(buf).second++;
}
auto comp = [](pii a, pii b) {
bool ans =
(a.second != b.second) ? (a.second > b.second) : (a.first > b.first);
return ans;
};
sort(odd.begin(), odd.end(), comp);
sort(even.begin(), even.end(), comp);
int ans = (odd.at(0).first != even.at(0).first)
? (Nhalf - odd.at(0).second) + (Nhalf - even.at(0).second)
: (odd.at(1).second > even.at(1).second)
? (Nhalf - odd.at(1).second) + (Nhalf - even.at(0).second)
: (Nhalf - odd.at(0).second) + (Nhalf - even.at(1).second);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
const int Vmax = 100000;
using pii = pair<int, int>;
int N, buf;
cin >> N;
int Nhalf = N / 2;
vector<pii> odd;
vector<pii> even;
for (int i = 0; i <= Vmax;
i++) { // 頻度をとるとき1-indexedのままにするため,ダミーを入れる
odd.emplace_back(make_pair(i, 0));
even.emplace_back(make_pair(i, 0));
}
for (int i = 0; i < N; i += 2) {
cin >> buf;
odd.at(buf).second++;
cin >> buf;
even.at(buf).second++;
}
auto comp = [](pii a, pii b) {
bool ans =
(a.second != b.second) ? (a.second > b.second) : (a.first > b.first);
return ans;
};
sort(odd.begin(), odd.end(), comp);
sort(even.begin(), even.end(), comp);
int ans = (odd.at(0).first != even.at(0).first)
? (Nhalf - odd.at(0).second) + (Nhalf - even.at(0).second)
: (odd.at(1).second > even.at(1).second)
? (Nhalf - odd.at(1).second) + (Nhalf - even.at(0).second)
: (Nhalf - odd.at(0).second) + (Nhalf - even.at(1).second);
cout << ans << endl;
} | replace | 13 | 14 | 13 | 15 | 0 | |
p03244 | Python | Runtime Error | from collections import Counter
n = int(input())
v = input().split()
v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)
if c1[0][0] != c2[0][0]:
print(n - c1[0][1] - c2[0][1])
else:
print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))
| from collections import Counter
n = int(input())
v = input().split()
v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)
if len(set(v)) == 1:
print(len(v) // 2)
elif c1[0][0] != c2[0][0]:
print(n - c1[0][1] - c2[0][1])
else:
print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))
| replace | 10 | 11 | 10 | 13 | 0 | |
p03244 | Python | Time Limit Exceeded | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import defaultdict
def solve():
n = int(input())
v = [int(i) for i in input().split()]
d1 = defaultdict(int)
d2 = defaultdict(int)
for i in range(n):
if i % 2 == 0:
d1[v[i]] += 1
else:
d2[v[i]] += 1
rd1 = defaultdict(list)
rd2 = defaultdict(list)
for k, v in d1.items():
rd1[v].append(k)
for k, v in d2.items():
rd2[v].append(k)
a1 = [i for i in sorted(rd1.keys(), reverse=True)]
a2 = [i for i in sorted(rd2.keys(), reverse=True)]
ans = n
la1 = len(a1) - 1
la2 = len(a2) - 1
for h in range(3):
for i in range(3):
aa1 = rd1[a1[min(h, la1)]]
aa2 = rd2[a2[min(i, la2)]]
for j in aa1:
for k in aa2:
if j != k:
ans = min(
ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
)
else:
ans = min(
ans,
(n // 2)
- a1[min(h, la1)]
+ (n // 2)
- a2[min(i, la2)]
+ min(a1[min(h, la1)], a2[min(i, la2)]),
)
print(ans)
if __name__ == "__main__":
solve()
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import defaultdict
def solve():
n = int(input())
v = [int(i) for i in input().split()]
d1 = defaultdict(int)
d2 = defaultdict(int)
for i in range(n):
if i % 2 == 0:
d1[v[i]] += 1
else:
d2[v[i]] += 1
rd1 = defaultdict(list)
rd2 = defaultdict(list)
for k, v in d1.items():
rd1[v].append(k)
for k, v in d2.items():
rd2[v].append(k)
a1 = [i for i in sorted(rd1.keys(), reverse=True)]
a2 = [i for i in sorted(rd2.keys(), reverse=True)]
ans = n
la1 = len(a1) - 1
la2 = len(a2) - 1
for h in range(3):
for i in range(3):
aa1 = rd1[a1[min(h, la1)]]
aa2 = rd2[a2[min(i, la2)]]
s1 = set(aa1)
s2 = set(aa2)
if len(s1) > 1 or len(s2) > 1 or (s1 - s2) or (s2 - s1):
ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
else:
ans = min(
ans,
(n // 2)
- a1[min(h, la1)]
+ (n // 2)
- a2[min(i, la2)]
+ min(a1[min(h, la1)], a2[min(i, la2)]),
)
print(ans)
if __name__ == "__main__":
solve()
| replace | 31 | 46 | 31 | 44 | TLE | |
p03244 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
vector<pair<int, int>> K;
vector<pair<int, int>> G;
vector<int> KI(n / 2);
vector<int> GU(n / 2);
for (int i = 0; i < n / 2; i++) {
cin >> KI.at(i) >> GU.at(i);
}
sort(KI.begin(), KI.end());
sort(GU.begin(), GU.end());
K.push_back(make_pair(1, KI.at(0)));
G.push_back(make_pair(1, GU.at(0)));
for (int i = 1; i < n / 2; i++) {
if (K.at(K.size() - 1).second == KI.at(i)) {
K.at(K.size() - 1).first = K.at(K.size() - 1).first + 1;
} else {
K.push_back(make_pair(1, KI.at(i)));
}
}
for (int i = 1; i < n / 2; i++) {
if (G.at(K.size() - 1).second == GU.at(i)) {
G.at(K.size() - 1).first = G.at(K.size() - 1).first + 1;
} else {
G.push_back(make_pair(1, GU.at(i)));
}
}
K.push_back(make_pair(0, -1));
G.push_back(make_pair(0, -1));
sort(K.begin(), K.end());
reverse(K.begin(), K.end());
sort(G.begin(), G.end());
reverse(G.begin(), G.end());
if (K.at(0).second == G.at(0).second) {
cout << n - max(K.at(0).first + G.at(1).first,
K.at(1).first + G.at(0).first)
<< endl;
} else {
cout << n - K.at(0).first - G.at(0).first << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
vector<pair<int, int>> K;
vector<pair<int, int>> G;
vector<int> KI(n / 2);
vector<int> GU(n / 2);
for (int i = 0; i < n / 2; i++) {
cin >> KI.at(i) >> GU.at(i);
}
sort(KI.begin(), KI.end());
sort(GU.begin(), GU.end());
K.push_back(make_pair(1, KI.at(0)));
G.push_back(make_pair(1, GU.at(0)));
for (int i = 1; i < n / 2; i++) {
if (K.at(K.size() - 1).second == KI.at(i)) {
K.at(K.size() - 1).first = K.at(K.size() - 1).first + 1;
} else {
K.push_back(make_pair(1, KI.at(i)));
}
}
for (int i = 1; i < n / 2; i++) {
if (G.at(G.size() - 1).second == GU.at(i)) {
G.at(G.size() - 1).first = G.at(G.size() - 1).first + 1;
} else {
G.push_back(make_pair(1, GU.at(i)));
}
}
K.push_back(make_pair(0, -1));
G.push_back(make_pair(0, -1));
sort(K.begin(), K.end());
reverse(K.begin(), K.end());
sort(G.begin(), G.end());
reverse(G.begin(), G.end());
if (K.at(0).second == G.at(0).second) {
cout << n - max(K.at(0).first + G.at(1).first,
K.at(1).first + G.at(0).first)
<< endl;
} else {
cout << n - K.at(0).first - G.at(0).first << endl;
}
} | replace | 29 | 31 | 29 | 31 | 0 | |
p03244 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) { \
cout << "yes" << endl; \
} else { \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) { \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) { \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) { \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) { \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) { \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
const long long int mod = 1000000007;
const long long int INF = 99999999999999999;
long long int N, M, A[6], B, C, D, E, tmp[100500] = {}, tmp2[100500] = {},
cou = 0;
long long int first, firstid, second, secondid;
long long int first2, firstid2, second2, secondid2;
int main() {
cout << fixed << setprecision(18);
cin >> N;
for (long long int i = 0; i < N; i++) {
cin >> A[i];
}
for (long long int i = 0; i < N; i += 2) {
tmp[A[i]]++;
}
for (long long int i = 1; i < N; i += 2) {
tmp2[A[i]]++;
}
first = 0;
for (long long int i = 1; i < 100010; i++) {
if (first <= tmp[i]) {
second = first;
secondid = firstid;
first = tmp[i];
firstid = i;
} else if (second <= tmp[i]) {
second = tmp[i];
secondid = i;
}
}
first2 = 0;
for (long long int i = 1; i < 100010; i++) {
if (first2 <= tmp2[i]) {
second2 = first2;
secondid2 = firstid2;
first2 = tmp2[i];
firstid2 = i;
} else if (second2 <= tmp2[i]) {
second2 = tmp2[i];
secondid2 = i;
}
}
if (firstid != firstid2) {
cout << N - first - first2 << endl;
} else {
cout << N - max(first + second2, second + first2) << endl;
}
}
| #include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) { \
cout << "yes" << endl; \
} else { \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) { \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) { \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) { \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) { \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) { \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
const long long int mod = 1000000007;
const long long int INF = 99999999999999999;
long long int N, M, A[200000], B, C, D, E, tmp[100500] = {}, tmp2[100500] = {},
cou = 0;
long long int first, firstid, second, secondid;
long long int first2, firstid2, second2, secondid2;
int main() {
cout << fixed << setprecision(18);
cin >> N;
for (long long int i = 0; i < N; i++) {
cin >> A[i];
}
for (long long int i = 0; i < N; i += 2) {
tmp[A[i]]++;
}
for (long long int i = 1; i < N; i += 2) {
tmp2[A[i]]++;
}
first = 0;
for (long long int i = 1; i < 100010; i++) {
if (first <= tmp[i]) {
second = first;
secondid = firstid;
first = tmp[i];
firstid = i;
} else if (second <= tmp[i]) {
second = tmp[i];
secondid = i;
}
}
first2 = 0;
for (long long int i = 1; i < 100010; i++) {
if (first2 <= tmp2[i]) {
second2 = first2;
secondid2 = firstid2;
first2 = tmp2[i];
firstid2 = i;
} else if (second2 <= tmp2[i]) {
second2 = tmp2[i];
secondid2 = i;
}
}
if (firstid != firstid2) {
cout << N - first - first2 << endl;
} else {
cout << N - max(first + second2, second + first2) << endl;
}
}
| replace | 65 | 67 | 65 | 67 | 0 | |
p03244 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fore(i, a, b) for (int i = a; i >= b; i--)
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a, b) memset(a, b, sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int, int> pii;
const long long linf = 1LL << 62;
const int iinf = 1000000009;
const double dinf = 1e17;
const int Mod = 1e9 + 9;
typedef long long ll;
typedef long double ld;
const int maxn = 1000005;
int n, ans;
int a[maxn];
int b[maxn];
int r1[maxn], r2[maxn];
int vs1[100005], vs2[100005];
int rt1, rt2;
bool cmp1(int a, int b) { return vs1[a] > vs1[b]; }
bool cmp2(int a, int b) { return vs2[a] > vs2[b]; }
int chk() {
int cnt = 0;
For(i, 3, n) b[i] = b[i - 2];
For(i, 1, n) if (a[i] != b[i]) cnt++;
return cnt;
}
void solve() {
iossy;
cin >> n;
ans = iinf;
met(vs1, 0);
met(vs2, 0);
rt1 = 0;
rt2 = 0;
For(i, 1, n) {
cin >> a[i];
if (i % 2) {
vs1[a[i]]++;
if (vs1[a[i]] == 1)
r1[rt1++] = a[i];
} else {
vs2[a[i]]++;
if (vs2[a[i]] == 1)
r2[rt2++] = a[i];
}
}
sort(r1, r1 + rt1, cmp1);
sort(r2, r2 + rt2, cmp2);
For(i, 0, min(200, rt1 - 1)) {
For(j, 0, min(200, rt2 - 1)) {
b[1] = r1[i];
b[2] = r2[j];
if (b[1] == b[2]) {
if (vs1[b[1]] >= vs2[b[2]])
b[2]++;
else
b[1]++;
}
ans = min(ans, chk());
}
}
cout << ans << endl;
}
int main() {
int t = 1;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fore(i, a, b) for (int i = a; i >= b; i--)
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define mkp make_pair
#define pb push_back
#define sz size()
#define met(a, b) memset(a, b, sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fr freopen
#define pi acos(-1.0)
#define Vector Point
typedef pair<int, int> pii;
const long long linf = 1LL << 62;
const int iinf = 1000000009;
const double dinf = 1e17;
const int Mod = 1e9 + 9;
typedef long long ll;
typedef long double ld;
const int maxn = 1000005;
int n, ans;
int a[maxn];
int b[maxn];
int r1[maxn], r2[maxn];
int vs1[100005], vs2[100005];
int rt1, rt2;
bool cmp1(int a, int b) { return vs1[a] > vs1[b]; }
bool cmp2(int a, int b) { return vs2[a] > vs2[b]; }
int chk() {
int cnt = 0;
For(i, 3, n) b[i] = b[i - 2];
For(i, 1, n) if (a[i] != b[i]) cnt++;
return cnt;
}
void solve() {
iossy;
cin >> n;
ans = iinf;
met(vs1, 0);
met(vs2, 0);
rt1 = 0;
rt2 = 0;
For(i, 1, n) {
cin >> a[i];
if (i % 2) {
vs1[a[i]]++;
if (vs1[a[i]] == 1)
r1[rt1++] = a[i];
} else {
vs2[a[i]]++;
if (vs2[a[i]] == 1)
r2[rt2++] = a[i];
}
}
sort(r1, r1 + rt1, cmp1);
sort(r2, r2 + rt2, cmp2);
For(i, 0, min(100, rt1 - 1)) {
For(j, 0, min(100, rt2 - 1)) {
b[1] = r1[i];
b[2] = r2[j];
if (b[1] == b[2]) {
if (vs1[b[1]] >= vs2[b[2]])
b[2]++;
else
b[1]++;
}
ans = min(ans, chk());
}
}
cout << ans << endl;
}
int main() {
int t = 1;
while (t--)
solve();
return 0;
}
| replace | 59 | 61 | 59 | 61 | TLE | |
p03245 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
ll x[n], y[n];
int f[2] = {0, 0};
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
f[(x[i] + y[i] + 2) % 2]++;
}
if (f[0] * f[1] > 0) {
cout << -1 << endl;
return 0;
}
vector<ll> d;
for (int i = 0; i < 35; i++)
d.push_back((ll)pow(2, i));
if (f[0] > 0)
d.push_back(1);
cout << d.size() << endl;
for (int i = 0; i < d.size() - 1; i++)
cout << d[i] << " ";
cout << d.back() << endl;
for (int i = 0; i < n; i++) {
ll u = x[i] + y[i];
ll v = x[i] - y[i];
if (f[0] > 0) {
u--;
v--;
}
for (int j = 0; j < 35; j++) {
u += d[j];
v += d[j];
}
u /= 2;
v /= 2;
for (int j = 0; j < 35; j++) {
ll s = u / ((ll)pow(2, j)) & 1;
ll t = v / ((ll)pow(2, j)) & 1;
if (s) {
if (t)
cout << "R";
else
cout << "U";
} else {
if (t)
cout << "D";
else
cout << "L";
}
}
if (f[0] > 0)
cout << "R";
cout << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
ll x[n], y[n];
int f[2] = {0, 0};
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
f[(x[i] + y[i] + 1000000000000) % 2]++;
}
if (f[0] * f[1] > 0) {
cout << -1 << endl;
return 0;
}
vector<ll> d;
for (int i = 0; i < 35; i++)
d.push_back((ll)pow(2, i));
if (f[0] > 0)
d.push_back(1);
cout << d.size() << endl;
for (int i = 0; i < d.size() - 1; i++)
cout << d[i] << " ";
cout << d.back() << endl;
for (int i = 0; i < n; i++) {
ll u = x[i] + y[i];
ll v = x[i] - y[i];
if (f[0] > 0) {
u--;
v--;
}
for (int j = 0; j < 35; j++) {
u += d[j];
v += d[j];
}
u /= 2;
v /= 2;
for (int j = 0; j < 35; j++) {
ll s = u / ((ll)pow(2, j)) & 1;
ll t = v / ((ll)pow(2, j)) & 1;
if (s) {
if (t)
cout << "R";
else
cout << "U";
} else {
if (t)
cout << "D";
else
cout << "L";
}
}
if (f[0] > 0)
cout << "R";
cout << endl;
}
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03245 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
using namespace std;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const string dir = "URDL";
string solve(long long x, long long y, const vector<long long> &arm) {
string ret;
int id;
long long d, dd, xx, yy;
for (auto it = arm.rbegin(); it != arm.rend(); it++) {
d = LLONG_MAX;
for (int i = 0; i < 4; i++) {
xx = x + dx[i] * *it;
yy = y + dy[i] * *it;
dd = abs(xx) + abs(yy);
if (dd < d) {
id = i;
d = dd;
}
}
ret += dir[(id + 2) % 4];
x += dx[id] * *it;
y += dy[id] * *it;
}
reverse(ret.begin(), ret.end());
return ret;
}
int main(void) {
int n;
cin >> n;
vector<long long> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
bool b = (abs(x[0]) + abs(y[0])) % 2;
for (int i = 0; i < n; i++) {
if ((abs(x[i]) + abs(y[i])) % 2 != b) {
cout << -1 << endl;
return -1;
}
}
long long md = 0;
for (int i = 0; i < n; i++)
md = max(md, abs(x[i]) + abs(y[i]));
vector<long long> arm;
if (b == 0)
arm.push_back(1);
for (long long i = 1, sum = (b == 0 ? 1 : 0); sum < md; i *= 2) {
arm.push_back(i);
sum += i;
}
cout << arm.size() << endl;
for (int i = 0; i < arm.size(); i++)
cout << arm[i] << (i + 1 == arm.size() ? '\n' : ' ');
for (int i = 0; i < n; i++)
cout << solve(x[i], y[i], arm) << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
using namespace std;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const string dir = "URDL";
string solve(long long x, long long y, const vector<long long> &arm) {
string ret;
int id;
long long d, dd, xx, yy;
for (auto it = arm.rbegin(); it != arm.rend(); it++) {
d = LLONG_MAX;
for (int i = 0; i < 4; i++) {
xx = x + dx[i] * *it;
yy = y + dy[i] * *it;
dd = abs(xx) + abs(yy);
if (dd < d) {
id = i;
d = dd;
}
}
ret += dir[(id + 2) % 4];
x += dx[id] * *it;
y += dy[id] * *it;
}
reverse(ret.begin(), ret.end());
return ret;
}
int main(void) {
int n;
cin >> n;
vector<long long> x(n), y(n);
for (int i = 0; i < n; i++)
cin >> x[i] >> y[i];
bool b = (abs(x[0]) + abs(y[0])) % 2;
for (int i = 0; i < n; i++) {
if ((abs(x[i]) + abs(y[i])) % 2 != b) {
cout << -1 << endl;
return 0;
}
}
long long md = 0;
for (int i = 0; i < n; i++)
md = max(md, abs(x[i]) + abs(y[i]));
vector<long long> arm;
if (b == 0)
arm.push_back(1);
for (long long i = 1, sum = (b == 0 ? 1 : 0); sum < md; i *= 2) {
arm.push_back(i);
sum += i;
}
cout << arm.size() << endl;
for (int i = 0; i < arm.size(); i++)
cout << arm[i] << (i + 1 == arm.size() ? '\n' : ' ');
for (int i = 0; i < n; i++)
cout << solve(x[i], y[i], arm) << endl;
return 0;
}
| replace | 51 | 52 | 51 | 52 | 0 | |
p03245 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ') {
while (!isdigit(ch = getchar()))
if (ch == '-')
f = -1;
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
const int N = 4e1 + 5;
int n, m, a[N], b[N], c[N];
char s[N];
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read(), b[i] = read();
c[1] = 1, m = ~abs(a[1] + b[1]) & 1;
for (int i = 2; i <= n; ++i)
if (m != (~abs(a[i] + b[i]) & 1))
return puts("-1"), 0;
c[++m] = 1;
for (int i = 1; i <= 30; ++i)
c[++m] = 1 << i;
printf("%d\n", m);
for (int i = 1; i <= m; ++i)
printf("%d ", c[i]);
puts("");
for (int i = 1; i <= n; ++i) {
int nx = 0, ny = 0;
for (int j = m; j; --j) {
int dx = a[i] - nx, dy = b[i] - ny;
if (abs(dx) > abs(dy))
dx > 0 ? (nx += c[j], s[j] = 'R') : (nx -= c[j], s[j] = 'L');
else
dy > 0 ? (ny += c[j], s[j] = 'U') : (ny -= c[j], s[j] = 'D');
}
puts(s + 1);
}
return 0;
} | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ') {
while (!isdigit(ch = getchar()))
if (ch == '-')
f = -1;
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
const int N = 1e3 + 5, M = 4e1 + 5;
int n, m, a[N], b[N], c[M];
char s[M];
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read(), b[i] = read();
c[1] = 1, m = ~abs(a[1] + b[1]) & 1;
for (int i = 2; i <= n; ++i)
if (m != (~abs(a[i] + b[i]) & 1))
return puts("-1"), 0;
c[++m] = 1;
for (int i = 1; i <= 30; ++i)
c[++m] = 1 << i;
printf("%d\n", m);
for (int i = 1; i <= m; ++i)
printf("%d ", c[i]);
puts("");
for (int i = 1; i <= n; ++i) {
int nx = 0, ny = 0;
for (int j = m; j; --j) {
int dx = a[i] - nx, dy = b[i] - ny;
if (abs(dx) > abs(dy))
dx > 0 ? (nx += c[j], s[j] = 'R') : (nx -= c[j], s[j] = 'L');
else
dy > 0 ? (ny += c[j], s[j] = 'U') : (ny -= c[j], s[j] = 'D');
}
puts(s + 1);
}
return 0;
} | replace | 13 | 16 | 13 | 16 | 0 | |
p03245 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int x[2010], y[2010], pow[2010], sum[2010], n;
int main() {
scanf("%d", &n);
int i, j;
for (i = 1; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
sum[i] = abs(x[i] + y[i]);
}
for (i = 1; i < n; i++)
if (sum[i] % 2 != sum[i + 1] % 2) {
printf("%d", -1);
return 0;
}
int maxd = 0, cnt = 0;
for (i = 1; i <= n; i++)
maxd = max(maxd, sum[i]);
if (!(sum[1] % 2)) {
pow[++cnt] = 1;
maxd--;
}
int tmp = 1;
while (tmp <= maxd + 1) {
pow[++cnt] = tmp;
tmp *= 2;
}
printf("%d\n", cnt);
for (i = 1; i <= cnt; i++)
printf("%d ", pow[cnt - i + 1]);
printf("\n");
for (i = 1; i <= n; i++) {
int fx = x[i], fy = y[i], nx = 0, ny = 0;
for (j = cnt; j >= 1; j--) {
int chax = fx - nx, chay = fy - ny;
if (abs(chax) > abs(chay)) {
if (chax > 0) {
printf("R");
nx += pow[j];
} else {
printf("L");
nx -= pow[j];
}
} else {
if (chay > 0) {
printf("U");
ny += pow[j];
} else {
printf("D");
ny -= pow[j];
}
}
}
printf("\n");
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int x[2010], y[2010], pow[2010], sum[2010], n;
int main() {
scanf("%d", &n);
int i, j;
for (i = 1; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
sum[i] = abs(x[i] + y[i]);
}
for (i = 1; i < n; i++)
if (sum[i] % 2 != sum[i + 1] % 2) {
printf("%d", -1);
return 0;
}
int maxd = 0, cnt = 0;
for (i = 1; i <= n; i++)
maxd = max(maxd, sum[i]);
if (!(sum[1] % 2)) {
pow[++cnt] = 1;
maxd--;
}
int tmp = 1;
while (tmp - 1 <= maxd) {
pow[++cnt] = tmp;
tmp *= 2;
}
printf("%d\n", cnt);
for (i = 1; i <= cnt; i++)
printf("%d ", pow[cnt - i + 1]);
printf("\n");
for (i = 1; i <= n; i++) {
int fx = x[i], fy = y[i], nx = 0, ny = 0;
for (j = cnt; j >= 1; j--) {
int chax = fx - nx, chay = fy - ny;
if (abs(chax) > abs(chay)) {
if (chax > 0) {
printf("R");
nx += pow[j];
} else {
printf("L");
nx -= pow[j];
}
} else {
if (chay > 0) {
printf("U");
ny += pow[j];
} else {
printf("D");
ny -= pow[j];
}
}
}
printf("\n");
}
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p03245 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) \
for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v) \
for (size_t I = 0; I < v.size(); ++I) { \
cout << " " << #v << "[" << I << "]=" << v[I]; \
} \
cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pll = pair<lint, lint>;
int main(void) {
lint n;
cin >> n;
vector<lint> x(n), y(n);
repeat(i, n) cin >> x[i] >> y[i];
lint parity = abs(x[0]) + abs(y[0]);
parity %= 2;
repeat(i, n) {
lint cand = abs(x[i]) + abs(y[i]);
cand %= 2;
if (parity != cand) {
cout << -1 << endl;
return 0;
}
}
const lint m = 4;
cout << (parity == 1 ? m : (m + 1)) << endl;
vector<lint> d(m);
repeat_reverse_from_to(i, m - 1, 0) { d[m - 1 - i] = (1 << i); }
if (parity == 0) {
d.push_back(1);
}
repeat_reverse_from_to(i, d.size() - 1, 0) { cout << d[i] << " "; }
cout << endl;
auto dist = [](pll p) -> lint { return abs(p.fst) + abs(p.snd); };
auto f = [&dist](pll p, lint d, char &c) -> pll {
pll res = make_pair(1e10, 1e10);
vector<lint> dx{1, 0, -1, 0};
vector<lint> dy{0, 1, 0, -1};
repeat(i, 4) {
pll cand = make_pair(p.fst + dx[i] * d, p.snd + dy[i] * d);
if (dist(cand) < dist(res)) {
res = cand;
if (i == 0)
c = 'L';
if (i == 1)
c = 'D';
if (i == 2)
c = 'R';
if (i == 3)
c = 'U';
}
}
return res;
};
repeat(i, n) {
pll p = make_pair(x[i], y[i]);
string str;
repeat(j, d.size()) {
// pdump(p); dump(j); dump(d[j]); el;
char c;
p = f(p, d[j], c);
str += c;
}
reverse(str.begin(), str.end());
cout << str << endl;
assert(p.fst == 0 and p.snd == 0);
}
} | #include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) \
for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v) \
for (size_t I = 0; I < v.size(); ++I) { \
cout << " " << #v << "[" << I << "]=" << v[I]; \
} \
cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pll = pair<lint, lint>;
int main(void) {
lint n;
cin >> n;
vector<lint> x(n), y(n);
repeat(i, n) cin >> x[i] >> y[i];
lint parity = abs(x[0]) + abs(y[0]);
parity %= 2;
repeat(i, n) {
lint cand = abs(x[i]) + abs(y[i]);
cand %= 2;
if (parity != cand) {
cout << -1 << endl;
return 0;
}
}
const lint m = 31;
cout << (parity == 1 ? m : (m + 1)) << endl;
vector<lint> d(m);
repeat_reverse_from_to(i, m - 1, 0) { d[m - 1 - i] = (1 << i); }
if (parity == 0) {
d.push_back(1);
}
repeat_reverse_from_to(i, d.size() - 1, 0) { cout << d[i] << " "; }
cout << endl;
auto dist = [](pll p) -> lint { return abs(p.fst) + abs(p.snd); };
auto f = [&dist](pll p, lint d, char &c) -> pll {
pll res = make_pair(1e10, 1e10);
vector<lint> dx{1, 0, -1, 0};
vector<lint> dy{0, 1, 0, -1};
repeat(i, 4) {
pll cand = make_pair(p.fst + dx[i] * d, p.snd + dy[i] * d);
if (dist(cand) < dist(res)) {
res = cand;
if (i == 0)
c = 'L';
if (i == 1)
c = 'D';
if (i == 2)
c = 'R';
if (i == 3)
c = 'U';
}
}
return res;
};
repeat(i, n) {
pll p = make_pair(x[i], y[i]);
string str;
repeat(j, d.size()) {
// pdump(p); dump(j); dump(d[j]); el;
char c;
p = f(p, d[j], c);
str += c;
}
reverse(str.begin(), str.end());
cout << str << endl;
assert(p.fst == 0 and p.snd == 0);
}
} | replace | 41 | 42 | 41 | 42 | 0 | |
p03245 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
// hamko utils
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) \
for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template <class T1, class T2> bool chmin(T1 &a, T2 b) {
return b < a && (a = b, true);
}
template <class T1, class T2> bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using ld = long double;
using vld = vector<ld>;
using vi = vector<int>;
using vvi = vector<vi>;
vll conv(vi &v) {
vll r(v.size());
rep(i, v.size()) r[i] = v[i];
return r;
}
inline void input(int &v) {
v = 0;
char c = 0;
int p = 1;
while (c < '0' || c > '9') {
if (c == '-')
p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
v = (v << 3) + (v << 1) + c - '0';
c = getchar();
}
v *= p;
} // これを使うならば、tieとかを消して!!
template <typename T, typename U>
ostream &operator<<(ostream &o, const pair<T, U> &v) {
o << "(" << v.first << ", " << v.second << ")";
return o;
}
template <size_t...> struct seq {};
template <size_t N, size_t... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template <class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) {
using s = int[];
(void)s{0, (void(os << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...};
}
template <class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr> &os, tuple<Args...> const &t)
-> basic_ostream<Ch, Tr> & {
os << "(";
print_tuple(os, t, gen_seq<sizeof...(Args)>());
return os << ")";
}
ostream &operator<<(ostream &o, const vvll &v) {
rep(i, v.size()) {
rep(j, v[i].size()) o << v[i][j] << " ";
o << endl;
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T>
ostream &operator<<(ostream &o, const unordered_set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &o, const map<T, U> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it;
o << "]";
return o;
}
vector<int> range(const int x, const int y) {
vector<int> v(y - x + 1);
iota(v.begin(), v.end(), x);
return v;
}
template <typename T> istream &operator>>(istream &i, vector<T> &o) {
rep(j, o.size()) i >> o[j];
return i;
}
template <typename T, typename S, typename U>
ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.front();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> unordered_map<T, ll> counter(vector<T> vec) {
unordered_map<T, ll> ret;
for (auto &&x : vec)
ret[x]++;
return ret;
};
string substr(string s, P x) { return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll &g, int mode = 0, string filename = "out.png") {
ofstream ofs("./out.dot");
ofs << "digraph graph_name {" << endl;
set<P> memo;
rep(i, g.size()) rep(j, g[i].size()) {
if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i))))
continue;
memo.insert(P(i, g[i][j]));
ofs << " " << i << " -> " << g[i][j]
<< (mode ? " [arrowhead = none]" : "") << endl;
}
ofs << "}" << endl;
ofs.close();
system(((string) "dot -T png out.dot >" + filename).c_str());
}
class ScopedTime {
public:
ScopedTime(const std::string &msg = "") : msg_(msg) {
start_ = std::chrono::system_clock::now();
}
void lap(const std::string &msg) {
const auto duration_time = std::chrono::system_clock::now() - start_;
const auto duration_ms =
std::chrono::duration_cast<std::chrono::milliseconds>(duration_time);
std::cerr << "[" << duration_ms.count() << " ms] " << msg << std::endl;
}
virtual ~ScopedTime() { this->lap(msg_); }
private:
std::chrono::system_clock::time_point start_;
std::string msg_;
};
size_t g_random_seed;
struct init_ {
init_() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
srand(static_cast<unsigned int>(time(NULL)));
g_random_seed = RAND_MAX / 2 + rand() / 2;
}
} init__;
namespace std {
using argument_type = P;
template <> struct hash<argument_type> {
size_t operator()(argument_type const &x) const {
size_t seed = g_random_seed;
seed ^= hash<ll>{}(x.fi);
seed ^= (hash<ll>{}(x.se) << 1);
return seed;
}
};
}; // namespace std
#define ldout fixed << setprecision(40)
#define EPS (double)1e-14
#define INF (ll)1e18
#define mo (ll)(1e9 + 7)
// end of hamko utils
// void out(std::stringstream& ss, char c, int count) {
// for (int i = 0; i < count; i++) {
// ss << c;
// }
// }
//
int N;
int main(void) {
std::ios::sync_with_stdio(false);
cin >> N;
vector<ll> x(N), y(N);
int odd_or_even = 0;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < N; i++) {
if (i == 0) {
odd_or_even = (x[i] + y[i]) & 1;
} else {
if (odd_or_even != ((x[i] + y[i]) & 1)) {
std::cout << -1 << std::endl;
return -1;
}
}
}
std::stringstream ss;
vector<ll> d;
for (int i = 0; i < 31; i++) {
d.push_back(1ll << i);
}
// もしx+yが奇数なら余分に1の長さの腕が必要
if (odd_or_even == 0) {
d.push_back(1);
}
std::sort(d.rbegin(), d.rend());
std::cout << d.size() << std::endl;
// 腕はreverse(1, 1, 2, 4, 8, 16...) とする
for (auto &&r : d) {
std::cout << r << " ";
}
std::cout << std::endl;
for (int i = 0; i < N; i++) {
// それぞれの目標位置について、
// 原点からスタートして長い腕(原点側)から順番に
ll xx = 0, yy = 0;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
string dir = "LRDU";
for (auto l : d) {
// 目標位置に近づくような方向に腕を定める
int q = 0;
ll best = INF; // std::numeric_limits<ll>::max();
for (int j = 0; j < 4; j++) {
ll xxx = xx + l * dx[j];
ll yyy = yy + l * dy[j];
ll dd = std::abs(xxx - x[i]) + std::abs(yyy - y[i]);
if (dd < best) {
best = dd;
q = j;
}
}
std::cout << dir[q];
xx += l * dx[q];
yy += l * dy[q];
}
std::cout << std::endl;
}
return 0;
}
| #include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
// hamko utils
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) \
for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template <class T1, class T2> bool chmin(T1 &a, T2 b) {
return b < a && (a = b, true);
}
template <class T1, class T2> bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using ld = long double;
using vld = vector<ld>;
using vi = vector<int>;
using vvi = vector<vi>;
vll conv(vi &v) {
vll r(v.size());
rep(i, v.size()) r[i] = v[i];
return r;
}
inline void input(int &v) {
v = 0;
char c = 0;
int p = 1;
while (c < '0' || c > '9') {
if (c == '-')
p = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
v = (v << 3) + (v << 1) + c - '0';
c = getchar();
}
v *= p;
} // これを使うならば、tieとかを消して!!
template <typename T, typename U>
ostream &operator<<(ostream &o, const pair<T, U> &v) {
o << "(" << v.first << ", " << v.second << ")";
return o;
}
template <size_t...> struct seq {};
template <size_t N, size_t... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {};
template <class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) {
using s = int[];
(void)s{0, (void(os << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...};
}
template <class Ch, class Tr, class... Args>
auto operator<<(basic_ostream<Ch, Tr> &os, tuple<Args...> const &t)
-> basic_ostream<Ch, Tr> & {
os << "(";
print_tuple(os, t, gen_seq<sizeof...(Args)>());
return os << ")";
}
ostream &operator<<(ostream &o, const vvll &v) {
rep(i, v.size()) {
rep(j, v[i].size()) o << v[i][j] << " ";
o << endl;
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << '[';
rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : "");
o << "]";
return o;
}
template <typename T> ostream &operator<<(ostream &o, const set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T>
ostream &operator<<(ostream &o, const unordered_set<T> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U>
ostream &operator<<(ostream &o, const map<T, U> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it << (next(it) != m.end() ? ", " : "");
o << "]";
return o;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) {
o << '[';
for (auto it = m.begin(); it != m.end(); it++)
o << *it;
o << "]";
return o;
}
vector<int> range(const int x, const int y) {
vector<int> v(y - x + 1);
iota(v.begin(), v.end(), x);
return v;
}
template <typename T> istream &operator>>(istream &i, vector<T> &o) {
rep(j, o.size()) i >> o[j];
return i;
}
template <typename T, typename S, typename U>
ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.front();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) {
auto tmp = v;
while (tmp.size()) {
auto x = tmp.top();
tmp.pop();
o << x << " ";
}
return o;
}
template <typename T> unordered_map<T, ll> counter(vector<T> vec) {
unordered_map<T, ll> ret;
for (auto &&x : vec)
ret[x]++;
return ret;
};
string substr(string s, P x) { return s.substr(x.fi, x.se - x.fi); }
void vizGraph(vvll &g, int mode = 0, string filename = "out.png") {
ofstream ofs("./out.dot");
ofs << "digraph graph_name {" << endl;
set<P> memo;
rep(i, g.size()) rep(j, g[i].size()) {
if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i))))
continue;
memo.insert(P(i, g[i][j]));
ofs << " " << i << " -> " << g[i][j]
<< (mode ? " [arrowhead = none]" : "") << endl;
}
ofs << "}" << endl;
ofs.close();
system(((string) "dot -T png out.dot >" + filename).c_str());
}
class ScopedTime {
public:
ScopedTime(const std::string &msg = "") : msg_(msg) {
start_ = std::chrono::system_clock::now();
}
void lap(const std::string &msg) {
const auto duration_time = std::chrono::system_clock::now() - start_;
const auto duration_ms =
std::chrono::duration_cast<std::chrono::milliseconds>(duration_time);
std::cerr << "[" << duration_ms.count() << " ms] " << msg << std::endl;
}
virtual ~ScopedTime() { this->lap(msg_); }
private:
std::chrono::system_clock::time_point start_;
std::string msg_;
};
size_t g_random_seed;
struct init_ {
init_() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
srand(static_cast<unsigned int>(time(NULL)));
g_random_seed = RAND_MAX / 2 + rand() / 2;
}
} init__;
namespace std {
using argument_type = P;
template <> struct hash<argument_type> {
size_t operator()(argument_type const &x) const {
size_t seed = g_random_seed;
seed ^= hash<ll>{}(x.fi);
seed ^= (hash<ll>{}(x.se) << 1);
return seed;
}
};
}; // namespace std
#define ldout fixed << setprecision(40)
#define EPS (double)1e-14
#define INF (ll)1e18
#define mo (ll)(1e9 + 7)
// end of hamko utils
// void out(std::stringstream& ss, char c, int count) {
// for (int i = 0; i < count; i++) {
// ss << c;
// }
// }
//
int N;
int main(void) {
std::ios::sync_with_stdio(false);
cin >> N;
vector<ll> x(N), y(N);
int odd_or_even = 0;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < N; i++) {
if (i == 0) {
odd_or_even = (x[i] + y[i]) & 1;
} else {
if (odd_or_even != ((x[i] + y[i]) & 1)) {
std::cout << -1 << std::endl;
return 0;
}
}
}
std::stringstream ss;
vector<ll> d;
for (int i = 0; i < 31; i++) {
d.push_back(1ll << i);
}
// もしx+yが奇数なら余分に1の長さの腕が必要
if (odd_or_even == 0) {
d.push_back(1);
}
std::sort(d.rbegin(), d.rend());
std::cout << d.size() << std::endl;
// 腕はreverse(1, 1, 2, 4, 8, 16...) とする
for (auto &&r : d) {
std::cout << r << " ";
}
std::cout << std::endl;
for (int i = 0; i < N; i++) {
// それぞれの目標位置について、
// 原点からスタートして長い腕(原点側)から順番に
ll xx = 0, yy = 0;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
string dir = "LRDU";
for (auto l : d) {
// 目標位置に近づくような方向に腕を定める
int q = 0;
ll best = INF; // std::numeric_limits<ll>::max();
for (int j = 0; j < 4; j++) {
ll xxx = xx + l * dx[j];
ll yyy = yy + l * dy[j];
ll dd = std::abs(xxx - x[i]) + std::abs(yyy - y[i]);
if (dd < best) {
best = dd;
q = j;
}
}
std::cout << dir[q];
xx += l * dx[q];
yy += l * dy[q];
}
std::cout << std::endl;
}
return 0;
}
| replace | 246 | 247 | 246 | 247 | 0 | |
p03246 | C++ | Runtime Error |
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define EXISTch(s, c) \
((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1)
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define loop(n) FOR(i, 0, n)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007; // 10^9+7
const LL INF2 = (LL)100000000000000000; // 10^18
// 写経して、レッドコーダーを感じる儀式
int main() {
int ki[10001] = {0};
int gu[10001] = {0};
int n;
cin >> n;
// 0,…n-1を偶奇で二分割
for (int i = 0; i < n / 2; i++) {
int u, v;
cin >> u >> v;
ki[u]++;
gu[v]++;
}
// 奇数の1,2番目と
// 偶数の1,2番目を管理したい。
// 1,2番目を知りたいだけなので、いちいちマップを使わなくても4つ変数使うことで
// 対処できたらものすごい楽。
int ka = 0, kb = 0, ga = 0, gb = 0;
// 11b2222a33333
// iはソートされていないので、
// 上の1,2,3のどこにくるかはわからない。
// bより大きければ更新が発生するが、3だった場合aとbが逆転しているので
// 元に戻してやる必要がある
for (int i = 0; i <= 100000; i++) {
// ki[kb]より大きい要素があったら添字を更新する。
if (ki[kb] < ki[i]) {
kb = i;
}
// 2番目が1番を追い越していたら、交換して正しい順位に戻す。
if (ki[ka] < ki[kb]) {
swap(ka, kb);
}
// 偶数も同様
if (gu[gb] < gu[i]) {
gb = i;
}
if (gu[ga] < gu[gb]) {
swap(ga, gb);
}
}
// 考察の通り、偶数と奇数で衝突が起きているかいないかで、変わる。
// 最頻値に衝突が起きていないなら
// n/2-最頻値で最頻値以外を書き換えるのを偶奇でそれそれやればよい。
// 衝突が起きているならa1-b2,a2-b1の組合せを全部試す。
if (ka != ga) {
cout << n - (ki[ka] + gu[ga]) << endl;
} else {
cout << n - max(ki[ka] + gu[gb], ki[kb] + gu[ga]) << endl;
}
return 0;
} |
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define EXISTch(s, c) \
((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1)
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define loop(n) FOR(i, 0, n)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007; // 10^9+7
const LL INF2 = (LL)100000000000000000; // 10^18
// 写経して、レッドコーダーを感じる儀式
int main() {
int ki[100001] = {0};
int gu[100001] = {0};
int n;
cin >> n;
// 0,…n-1を偶奇で二分割
for (int i = 0; i < n / 2; i++) {
int u, v;
cin >> u >> v;
ki[u]++;
gu[v]++;
}
// 奇数の1,2番目と
// 偶数の1,2番目を管理したい。
// 1,2番目を知りたいだけなので、いちいちマップを使わなくても4つ変数使うことで
// 対処できたらものすごい楽。
int ka = 0, kb = 0, ga = 0, gb = 0;
// 11b2222a33333
// iはソートされていないので、
// 上の1,2,3のどこにくるかはわからない。
// bより大きければ更新が発生するが、3だった場合aとbが逆転しているので
// 元に戻してやる必要がある
for (int i = 0; i <= 100000; i++) {
// ki[kb]より大きい要素があったら添字を更新する。
if (ki[kb] < ki[i]) {
kb = i;
}
// 2番目が1番を追い越していたら、交換して正しい順位に戻す。
if (ki[ka] < ki[kb]) {
swap(ka, kb);
}
// 偶数も同様
if (gu[gb] < gu[i]) {
gb = i;
}
if (gu[ga] < gu[gb]) {
swap(ga, gb);
}
}
// 考察の通り、偶数と奇数で衝突が起きているかいないかで、変わる。
// 最頻値に衝突が起きていないなら
// n/2-最頻値で最頻値以外を書き換えるのを偶奇でそれそれやればよい。
// 衝突が起きているならa1-b2,a2-b1の組合せを全部試す。
if (ka != ga) {
cout << n - (ki[ka] + gu[ga]) << endl;
} else {
cout << n - max(ki[ka] + gu[gb], ki[kb] + gu[ga]) << endl;
}
return 0;
} | replace | 84 | 86 | 84 | 86 | -11 | |
p03246 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
using namespace std;
int n, mx[2], mi[2], my[2], ans, a[2][100005];
int main() {
int i, j, t;
cin >> n;
for (i = 0; i < n; i++)
scanf("%d", &t), a[i % 2][t]++;
for (i = 0; i < 2; i++)
for (j = 1; j <= 100000; j++) {
if (a[i][j] > mx[i])
mx[i] = a[i][j], mi[i] = j;
}
if (mi[0] != mi[1])
ans = n - mx[0] - mx[1];
else {
for (i = 0; i < 2; i++)
for (j = 1; j <= 100000; j++) {
if (j == mi[0])
continue;
if (a[i][j] > my[j])
my[i] = a[i][j];
}
ans = n - max(mx[0] + my[1], mx[1] + my[0]);
}
cout << ans;
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
int n, mx[2], mi[2], my[2], ans, a[2][100005];
int main() {
int i, j, t;
cin >> n;
for (i = 0; i < n; i++)
scanf("%d", &t), a[i % 2][t]++;
for (i = 0; i < 2; i++)
for (j = 1; j <= 100000; j++) {
if (a[i][j] > mx[i])
mx[i] = a[i][j], mi[i] = j;
}
if (mi[0] != mi[1])
ans = n - mx[0] - mx[1];
else {
for (i = 0; i < 2; i++)
for (j = 1; j <= 100000; j++) {
if (j == mi[0])
continue;
if (a[i][j] > my[i])
my[i] = a[i][j];
}
ans = n - max(mx[0] + my[1], mx[1] + my[0]);
}
cout << ans;
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10000;
int a[N + 1], b[N + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (i % 2) {
b[x]++;
} else {
a[x]++;
}
}
int ma = 0, ai = 0;
int mb = 0, bi = 0;
for (int i = 0; i <= N; i++) {
if (a[i] > ma) {
ma = a[i];
ai = i;
}
if (b[i] > mb) {
mb = b[i];
bi = i;
}
}
int s = ma + mb;
if (ai == bi) {
int m = 0;
for (int i = 0; i <= N; i++) {
if (i == ai)
continue;
m = max(m, a[i]);
}
s = mb + m;
m = 0;
for (int i = 0; i <= N; i++) {
if (i == bi)
continue;
m = max(m, b[i]);
}
s = max(s, ma + m);
}
cout << n - s << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000;
int a[N + 1], b[N + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (i % 2) {
b[x]++;
} else {
a[x]++;
}
}
int ma = 0, ai = 0;
int mb = 0, bi = 0;
for (int i = 0; i <= N; i++) {
if (a[i] > ma) {
ma = a[i];
ai = i;
}
if (b[i] > mb) {
mb = b[i];
bi = i;
}
}
int s = ma + mb;
if (ai == bi) {
int m = 0;
for (int i = 0; i <= N; i++) {
if (i == ai)
continue;
m = max(m, a[i]);
}
s = mb + m;
m = 0;
for (int i = 0; i <= N; i++) {
if (i == bi)
continue;
m = max(m, b[i]);
}
s = max(s, ma + m);
}
cout << n - s << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read() {
LL x;
scanf("%lld", &x);
return x;
}
inline void read(char *s) { scanf("%s", s); }
inline void no() {
printf("no\n");
exit(0);
}
#define maxn 12000
int v[2][maxn], ans[2], pans[2];
int main() {
int n = read();
for (int i = 0; i < n; i += 1)
v[i & 1][read()] += 1;
ans[0] = ans[1] = 0;
v[0][0] = v[1][0] = -1;
for (int i = 0; i < maxn; i += 1)
for (int j = 0; j < 2; j += 1)
if (v[j][i] > v[j][ans[j]])
ans[j] = i;
if (ans[0] != ans[1])
printf("%d", n - v[0][ans[0]] - v[1][ans[1]]);
else {
for (int i = 0; i < maxn; i += 1)
for (int j = 0; j < 2; j += 1)
if (v[j][i] > v[j][pans[j]] && i != ans[j])
pans[j] = i;
printf("%d",
n - max(v[0][ans[0]] + v[1][pans[1]], v[0][pans[0]] + v[1][ans[1]]));
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read() {
LL x;
scanf("%lld", &x);
return x;
}
inline void read(char *s) { scanf("%s", s); }
inline void no() {
printf("no\n");
exit(0);
}
#define maxn 120000
int v[2][maxn], ans[2], pans[2];
int main() {
int n = read();
for (int i = 0; i < n; i += 1)
v[i & 1][read()] += 1;
ans[0] = ans[1] = 0;
v[0][0] = v[1][0] = -1;
for (int i = 0; i < maxn; i += 1)
for (int j = 0; j < 2; j += 1)
if (v[j][i] > v[j][ans[j]])
ans[j] = i;
if (ans[0] != ans[1])
printf("%d", n - v[0][ans[0]] - v[1][ans[1]]);
else {
for (int i = 0; i < maxn; i += 1)
for (int j = 0; j < 2; j += 1)
if (v[j][i] > v[j][pans[j]] && i != ans[j])
pans[j] = i;
printf("%d",
n - max(v[0][ans[0]] + v[1][pans[1]], v[0][pans[0]] + v[1][ans[1]]));
}
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N = 1e5 + 123;
int n;
int a[N], cnt1[N], cnt2[N], ans = N;
pii x, y, p;
set<pii> s, t;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i += 2) {
cnt1[a[i]]++;
cnt2[a[i + 1]]++;
}
for (int i = 1; i < n; i += 2) {
s.insert(mp(cnt1[a[i]], a[i]));
t.insert(mp(cnt2[a[i + 1]], a[i + 1]));
}
x = *s.rbegin();
y = *t.rbegin();
s.erase(s.end());
t.erase(t.end());
if (x.S == y.S) {
if (!t.empty()) {
p = *t.rbegin();
ans = min(n - (x.F + p.F), ans);
}
if (!s.empty()) {
p = *s.rbegin();
ans = min(ans, n - (y.F + p.F));
}
if (!t.empty() && !s.empty()) {
x = *s.rbegin();
y = *t.rbegin();
ans = min(ans, n - (x.F + y.F));
}
if (t.empty() && s.empty()) {
ans = n / 2;
}
} else {
ans = n - (x.F + y.F);
}
cout << ans;
}
| #include <bits/stdc++.h>
#define pii pair<int, int>
#define ll long long
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N = 1e5 + 123;
int n;
int a[N], cnt1[N], cnt2[N], ans = N;
pii x, y, p;
set<pii> s, t;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i += 2) {
cnt1[a[i]]++;
cnt2[a[i + 1]]++;
}
for (int i = 1; i < n; i += 2) {
s.insert(mp(cnt1[a[i]], a[i]));
t.insert(mp(cnt2[a[i + 1]], a[i + 1]));
}
x = *s.rbegin();
y = *t.rbegin();
s.erase(*s.rbegin());
t.erase(*t.rbegin());
if (x.S == y.S) {
if (!t.empty()) {
p = *t.rbegin();
ans = min(n - (x.F + p.F), ans);
}
if (!s.empty()) {
p = *s.rbegin();
ans = min(ans, n - (y.F + p.F));
}
if (!t.empty() && !s.empty()) {
x = *s.rbegin();
y = *t.rbegin();
ans = min(ans, n - (x.F + y.F));
}
if (t.empty() && s.empty()) {
ans = n / 2;
}
} else {
ans = n - (x.F + y.F);
}
cout << ans;
}
| replace | 35 | 37 | 35 | 37 | -6 | free(): invalid pointer
|
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(c, a, b) for (ll c = a; c < b; c++)
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define min_heap priority_queue<pll, vector<pll>, greater<pll>>
ll dx4[] = {-1, 1, 0, 0};
ll dy4[] = {0, 0, -1, 1};
ll dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool isvalid(ll x, ll y, ll n, ll m) {
return (x >= 0 and y >= 0 and x < n and y < m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n) {
mem(isprime, true);
for (ll p = 2; p * p <= n; p++) {
if (isprime[p] == true) {
for (ll i = p * p; i <= n; i += p)
isprime[i] = false;
}
}
}
ll lcm(ll a, ll b) { return (a / __gcd(a, b)) * b; }
bool cmp(pair<string, ll> a, pair<string, ll> b) {
if (a.first < b.first)
return 1;
else if (a.x == b.x) {
return a.y < b.y;
}
return 0;
}
bool cmp(ll a, ll b) { return a > b; }
void solve() {
ll n;
cin >> n;
unordered_map<ll, ll> a, b;
ll x;
rep(i, 0, n) {
cin >> x;
if (i % 2 == 0) {
a[x]++;
} else
b[x]++;
}
ll fma = 0, sma = -1, fmb = 0, smb = -1, p, q, ans = 0;
for (auto i : a) {
if (fma < i.second) {
sma = fma;
fma = i.second;
p = i.first;
} else if (i.second > sma) {
sma = i.second;
}
}
for (auto i : b) {
if (fmb < i.second) {
smb = fmb;
fmb = i.second;
q = i.first;
} else if (i.second > smb) {
smb = i.second;
}
}
ans = n;
if (p == q) {
cout << min(n - fma - smb, n - sma - fmb);
} else {
cout << n - fma - fmb;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS ll t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(c, a, b) for (ll c = a; c < b; c++)
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define min_heap priority_queue<pll, vector<pll>, greater<pll>>
ll dx4[] = {-1, 1, 0, 0};
ll dy4[] = {0, 0, -1, 1};
ll dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1};
bool isvalid(ll x, ll y, ll n, ll m) {
return (x >= 0 and y >= 0 and x < n and y < m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n) {
mem(isprime, true);
for (ll p = 2; p * p <= n; p++) {
if (isprime[p] == true) {
for (ll i = p * p; i <= n; i += p)
isprime[i] = false;
}
}
}
ll lcm(ll a, ll b) { return (a / __gcd(a, b)) * b; }
bool cmp(pair<string, ll> a, pair<string, ll> b) {
if (a.first < b.first)
return 1;
else if (a.x == b.x) {
return a.y < b.y;
}
return 0;
}
bool cmp(ll a, ll b) { return a > b; }
void solve() {
ll n;
cin >> n;
unordered_map<ll, ll> a, b;
ll x;
rep(i, 0, n) {
cin >> x;
if (i % 2 == 0) {
a[x]++;
} else
b[x]++;
}
ll fma = 0, sma = -1, fmb = 0, smb = -1, p, q, ans = 0;
for (auto i : a) {
if (fma < i.second) {
sma = fma;
fma = i.second;
p = i.first;
} else if (i.second > sma) {
sma = i.second;
}
}
for (auto i : b) {
if (fmb < i.second) {
smb = fmb;
fmb = i.second;
q = i.first;
} else if (i.second > smb) {
smb = i.second;
}
}
ans = n;
if (p == q) {
cout << min(n - fma - smb, n - sma - fmb);
} else {
cout << n - fma - fmb;
}
}
int main() {
IOS ll t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
} | delete | 86 | 90 | 86 | 86 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<P> s;
vector<P> t;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
scanf("%d", &n);
int v[n];
rep(i, 0, n) {
cin >> v[i];
v[i]--;
}
rep(j, 0, 100000) {
s.push_back(P(0, j));
t.push_back(P(0, j));
}
rep(i, 0, n) {
if (i % 2 == 0) {
s[v[i]].first++;
} else
t[v[i]].first++;
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
if (s[0].second != t[0].second) {
printf("%d\n", n - s[0].first - t[0].first);
} else {
int a = max(s[1].first, t[1].first);
printf("%d\n", n - s[0].first - a);
}
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<P> s;
vector<P> t;
int main() {
int n;
scanf("%d", &n);
int v[n];
rep(i, 0, n) {
cin >> v[i];
v[i]--;
}
rep(j, 0, 100000) {
s.push_back(P(0, j));
t.push_back(P(0, j));
}
rep(i, 0, n) {
if (i % 2 == 0) {
s[v[i]].first++;
} else
t[v[i]].first++;
}
sort(s.begin(), s.end());
sort(t.begin(), t.end());
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
if (s[0].second != t[0].second) {
printf("%d\n", n - s[0].first - t[0].first);
} else {
int a = max(s[1].first, t[1].first);
printf("%d\n", n - s[0].first - a);
}
}
| delete | 11 | 13 | 11 | 11 | -11 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("vvv_in.txt", "r", stdin);
#endif
int n;
cin >> n;
map<int, int> high[2];
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
++high[i % 2][k];
}
int mx[2] = {};
for (auto it = high[0].begin(); it != high[0].end(); ++it)
if (high[0][mx[0]] < high[0][it->first])
mx[0] = it->first;
for (auto it = high[1].begin(); it != high[1].end(); ++it)
if (high[1][mx[1]] < high[1][it->first])
mx[1] = it->first;
int md[2] = {};
for (auto it = high[0].begin(); it != high[0].end(); ++it)
if (high[0][md[0]] < high[0][it->first] && it->first != mx[0])
md[0] = it->first;
for (auto it = high[1].begin(); it != high[1].end(); ++it)
if (high[1][md[1]] < high[1][it->first] && it->first != mx[1])
md[1] = it->first;
if (mx[0] != mx[1])
cout << n - high[0][mx[0]] - high[1][mx[1]];
else
cout << n - max(high[0][mx[0]] + high[1][md[1]],
high[0][md[0]] + high[1][mx[1]]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
map<int, int> high[2];
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
++high[i % 2][k];
}
int mx[2] = {};
for (auto it = high[0].begin(); it != high[0].end(); ++it)
if (high[0][mx[0]] < high[0][it->first])
mx[0] = it->first;
for (auto it = high[1].begin(); it != high[1].end(); ++it)
if (high[1][mx[1]] < high[1][it->first])
mx[1] = it->first;
int md[2] = {};
for (auto it = high[0].begin(); it != high[0].end(); ++it)
if (high[0][md[0]] < high[0][it->first] && it->first != mx[0])
md[0] = it->first;
for (auto it = high[1].begin(); it != high[1].end(); ++it)
if (high[1][md[1]] < high[1][it->first] && it->first != mx[1])
md[1] = it->first;
if (mx[0] != mx[1])
cout << n - high[0][mx[0]] - high[1][mx[1]];
else
cout << n - max(high[0][mx[0]] + high[1][md[1]],
high[0][md[0]] + high[1][mx[1]]);
return 0;
}
| delete | 8 | 12 | 8 | 8 | TLE | |
p03246 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
mt19937 rnd(228);
map<int, int> mp[2];
int main() {
#ifdef ONPC
freopen("a.in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mp[i % 2][x]++;
}
int ans = 0;
vector<vector<pair<int, int>>> f;
for (int t = 0; t < 2; t++) {
vector<pair<int, int>> e;
for (auto c : mp[t])
e.push_back({c.second, c.first});
for (int i = 1; i <= 3; i++)
e.push_back({mp[t][i], i});
sort(e.rbegin(), e.rend());
e.resize(unique(e.begin(), e.end()) - e.begin());
f.push_back(e);
}
for (auto c : f[0]) {
for (auto d : f[1]) {
if (c.second != d.second) {
ans = max(ans, c.first + d.first);
}
}
}
cout << n - ans << '\n';
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
mt19937 rnd(228);
map<int, int> mp[2];
int main() {
#ifdef ONPC
freopen("a.in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
mp[i % 2][x]++;
}
int ans = 0;
vector<vector<pair<int, int>>> f;
for (int t = 0; t < 2; t++) {
vector<pair<int, int>> e;
for (auto c : mp[t])
e.push_back({c.second, c.first});
for (int i = 1; i <= 3; i++)
e.push_back({mp[t][i], i});
sort(e.rbegin(), e.rend());
e.resize(unique(e.begin(), e.end()) - e.begin());
e.resize(2);
f.push_back(e);
}
for (auto c : f[0]) {
for (auto d : f[1]) {
if (c.second != d.second) {
ans = max(ans, c.first + d.first);
}
}
}
cout << n - ans << '\n';
}
| insert | 51 | 51 | 51 | 52 | TLE | |
p03246 | C++ | Runtime Error | /*
Author : N_o_o_B
Created : June 15 2020 15:42:13
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) \
{ \
cerr << "[ "; \
__trace__(#__VA_ARGS__, __VA_ARGS__); \
}
#undef endl
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) {
return out << "(" << x.first << "," << x.second << ")";
}
template <typename Arg1>
ostream &operator<<(ostream &out, const vector<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> void __trace__(const string name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1 &&arg1, Args &&...args) {
const string name = names.substr(0, names.find(','));
cerr << name << " : " << arg1 << " | ";
__trace__(names.substr(1 + (int)name.size()), args...);
}
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vll;
typedef vector<vl> vvl;
// typedef tree<pii, null_type, less<pii>, rb_tree_tag,
// tree_order_statistics_node_update> oset;
#define fori(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p = clock();
void time_taken() {
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
// const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const int maxn = 1e5 + 5;
int cnt[2][maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(12);
cout << fixed;
int n;
cin >> n;
set<int> s;
fori(i, n) {
int x;
cin >> x;
cnt[i % 2][x]++;
if (i % 2) {
s.insert(x);
}
}
map<int, int> m;
for (auto x : s) {
m[cnt[1][x]]++;
}
int ans = n;
for (int i = 1; i <= maxn; i++) {
int cur = n / 2 - cnt[0][i];
if (m.rbegin()->first == cnt[1][i]) {
if (m.rbegin()->second == 1) {
m.erase(m.rbegin()->fi);
cur += n / 2 - (sz(m) ? m.rbegin()->fi : 0);
m[cnt[1][i]] = 1;
} else {
cur += n / 2 - m.rbegin()->fi;
}
} else {
cur += n / 2 - m.rbegin()->fi;
}
ans = min(ans, cur);
}
cout << ans << endl;
time_taken();
return 0;
} | /*
Author : N_o_o_B
Created : June 15 2020 15:42:13
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) \
{ \
cerr << "[ "; \
__trace__(#__VA_ARGS__, __VA_ARGS__); \
}
#undef endl
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) {
return out << "(" << x.first << "," << x.second << ")";
}
template <typename Arg1>
ostream &operator<<(ostream &out, const vector<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> void __trace__(const string name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1 &&arg1, Args &&...args) {
const string name = names.substr(0, names.find(','));
cerr << name << " : " << arg1 << " | ";
__trace__(names.substr(1 + (int)name.size()), args...);
}
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll, ll>> vll;
typedef vector<vl> vvl;
// typedef tree<pii, null_type, less<pii>, rb_tree_tag,
// tree_order_statistics_node_update> oset;
#define fori(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p = clock();
void time_taken() {
time_p = clock() - time_p;
cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
// const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const int maxn = 1e5 + 5;
int cnt[2][maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(12);
cout << fixed;
int n;
cin >> n;
set<int> s;
fori(i, n) {
int x;
cin >> x;
cnt[i % 2][x]++;
if (i % 2) {
s.insert(x);
}
}
map<int, int> m;
for (auto x : s) {
m[cnt[1][x]]++;
}
int ans = n;
for (int i = 1; i < maxn; i++) {
int cur = n / 2 - cnt[0][i];
if (m.rbegin()->first == cnt[1][i]) {
if (m.rbegin()->second == 1) {
m.erase(m.rbegin()->fi);
cur += n / 2 - (sz(m) ? m.rbegin()->fi : 0);
m[cnt[1][i]] = 1;
} else {
cur += n / 2 - m.rbegin()->fi;
}
} else {
cur += n / 2 - m.rbegin()->fi;
}
ans = min(ans, cur);
}
cout << ans << endl;
time_taken();
return 0;
} | replace | 118 | 119 | 118 | 119 | 0 | Time Taken : 0.012119
|
p03246 | C++ | Runtime Error | #include <stdio.h>
#define ARC(i, a, b) for (int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template <class T> T ath(const T &a, const T &b) { return a > b ? a : b; }
int n, v[2][12000], av[2], inav[2], aav[2], inaav[2];
int solve() {
scanf("%d", &n);
RC(i, n / 2) {
int in;
scanf("%d", &in);
++v[0][in];
if (av[0] < v[0][in]) {
if (inav[0] != in) {
aav[0] = av[0];
inaav[0] = inav[0];
}
av[0] = v[0][in];
inav[0] = in;
} else if (aav[0] < v[0][in]) {
aav[0] = v[0][in];
inaav[0] = in;
}
scanf("%d", &in);
++v[1][in];
if (av[1] < v[1][in]) {
if (inav[1] != in) {
aav[1] = av[1];
inaav[1] = inav[1];
}
av[1] = v[1][in];
inav[1] = in;
} else if (aav[1] < v[1][in]) {
aav[1] = v[1][in];
inaav[1] = in;
}
}
return n - (inav[0] != inav[1] ? av[0] + av[1]
: ath(av[0] + aav[1], av[1] + aav[0]));
}
int main() { printf("%d\n", solve()); }
| #include <stdio.h>
#define ARC(i, a, b) for (int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template <class T> T ath(const T &a, const T &b) { return a > b ? a : b; }
int n, v[2][120000], av[2], inav[2], aav[2], inaav[2];
int solve() {
scanf("%d", &n);
RC(i, n / 2) {
int in;
scanf("%d", &in);
++v[0][in];
if (av[0] < v[0][in]) {
if (inav[0] != in) {
aav[0] = av[0];
inaav[0] = inav[0];
}
av[0] = v[0][in];
inav[0] = in;
} else if (aav[0] < v[0][in]) {
aav[0] = v[0][in];
inaav[0] = in;
}
scanf("%d", &in);
++v[1][in];
if (av[1] < v[1][in]) {
if (inav[1] != in) {
aav[1] = av[1];
inaav[1] = inav[1];
}
av[1] = v[1][in];
inav[1] = in;
} else if (aav[1] < v[1][in]) {
aav[1] = v[1][in];
inaav[1] = in;
}
}
return n - (inav[0] != inav[1] ? av[0] + av[1]
: ath(av[0] + aav[1], av[1] + aav[0]));
}
int main() { printf("%d\n", solve()); }
| replace | 9 | 10 | 9 | 10 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 1e5 + 5;
int ct[2][N], a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ct[i & 1][a[i]]++;
}
set<pair<int, int>> v[2];
int ans = n;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < N; j++) {
if (ct[i][j]) {
v[i].insert({n / 2 - ct[i][j], j});
if (v[i].size() > 2)
v[i].erase(prev(v[i].begin()));
ans = min(ans, n - ct[i][j]);
}
}
}
for (auto p : v[0]) {
for (auto q : v[1]) {
if (p.second != q.second) {
ans = min(ans, p.first + q.first);
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 1e5 + 5;
int ct[2][N], a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ct[i & 1][a[i]]++;
}
set<pair<int, int>> v[2];
int ans = n;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < N; j++) {
if (ct[i][j]) {
v[i].insert({n / 2 - ct[i][j], j});
if (v[i].size() > 2)
v[i].erase(prev(v[i].end()));
ans = min(ans, n - ct[i][j]);
}
}
}
for (auto p : v[0]) {
for (auto q : v[1]) {
if (p.second != q.second) {
ans = min(ans, p.first + q.first);
}
}
}
cout << ans;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p03246 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i, n) for (int i = 0; i < n; i++)
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
// #define sort(v) sort((v).begin(),(v).end())
// #define rsort(v) sort((v).rbegin(),(v).rend())
#define gcd(a, b) __gcd((a), (b))
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout << (x) << endl;
#define sum(v) +x accumulate(v.begin(), v.end(), x);
typedef pair<int, int> pii;
typedef vector<int> vi;
// x.substr(start, length);
/*
// Create a vector containing n
//vectors of size m.
vector<vector<int> > vec( n , vector<int> (m, 0));
*/
struct type {
int k, i, j;
};
// to check if a no is prime or not?
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k) {
int window_sum = 0;
int min_window = INT_MAX;
int last = 0;
for (int i = 0; i < n; i++) {
window_sum += arr[i];
if (i + 1 >= k) {
if (min_window > window_sum) {
min_window = window_sum;
last = i;
}
window_sum -= arr[i + 1 - k];
}
}
int sum = 0;
for (int i = last - k + 1; i <= last; i++) {
sum += arr[i];
}
return sum;
}
// finds the next permutation to given sequence of nos
int nextpermutation(vi v) {
vi t = v;
// sort(t);
int x = 0;
while (true) {
x++;
if (t == v) {
return x;
}
next_permutation(all(t));
}
}
signed main() {
fastio;
// cout << fixed << setprecision(0);
int n;
cin >> n;
vi a(n);
f(i, n) cin >> a[i];
map<int, int> m1, m2;
f(i, n) {
if (i % 2 == 0) {
m1[a[i]] += 1;
} else {
m2[a[i]] += 1;
}
}
vector<pii> v[2];
for (auto x : m1)
v[0].pb({x.S, x.F});
for (auto x : m2)
v[1].pb({x.S, x.F});
for (int i = 0; i < 2; i++)
sort(v[i].rbegin(), v[i].rend());
if (v[0][0].S != v[1][0].S) {
cout << n / 2 - v[0][0].F + n / 2 - v[1][0].F << endl;
} else {
int ans = n;
for (int i = 0; i < (int)v[0].size(); i++) {
for (int j = 0; j < (int)v[1].size(); j++) {
int cur = n;
if (v[0][i].S == v[1][j].S)
cur -= max(v[0][i].F, v[1][j].F);
else
cur -= (v[0][i].F + v[1][j].F);
ans = min(ans, cur);
}
}
cout << ans << endl;
}
} |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i, n) for (int i = 0; i < n; i++)
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
// #define sort(v) sort((v).begin(),(v).end())
// #define rsort(v) sort((v).rbegin(),(v).rend())
#define gcd(a, b) __gcd((a), (b))
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout << (x) << endl;
#define sum(v) +x accumulate(v.begin(), v.end(), x);
typedef pair<int, int> pii;
typedef vector<int> vi;
// x.substr(start, length);
/*
// Create a vector containing n
//vectors of size m.
vector<vector<int> > vec( n , vector<int> (m, 0));
*/
struct type {
int k, i, j;
};
// to check if a no is prime or not?
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k) {
int window_sum = 0;
int min_window = INT_MAX;
int last = 0;
for (int i = 0; i < n; i++) {
window_sum += arr[i];
if (i + 1 >= k) {
if (min_window > window_sum) {
min_window = window_sum;
last = i;
}
window_sum -= arr[i + 1 - k];
}
}
int sum = 0;
for (int i = last - k + 1; i <= last; i++) {
sum += arr[i];
}
return sum;
}
// finds the next permutation to given sequence of nos
int nextpermutation(vi v) {
vi t = v;
// sort(t);
int x = 0;
while (true) {
x++;
if (t == v) {
return x;
}
next_permutation(all(t));
}
}
signed main() {
fastio;
// cout << fixed << setprecision(0);
int n;
cin >> n;
vi a(n);
f(i, n) cin >> a[i];
map<int, int> m1, m2;
f(i, n) {
if (i % 2 == 0) {
m1[a[i]] += 1;
} else {
m2[a[i]] += 1;
}
}
vector<pii> v[2];
for (auto x : m1)
v[0].pb({x.S, x.F});
for (auto x : m2)
v[1].pb({x.S, x.F});
for (int i = 0; i < 2; i++)
sort(v[i].rbegin(), v[i].rend());
if (v[0][0].S != v[1][0].S) {
cout << n / 2 - v[0][0].F + n / 2 - v[1][0].F << endl;
} else {
int ans = n;
for (int i = 0; i < min((int)v[0].size(), 5LL); i++) {
for (int j = 0; j < min((int)v[1].size(), 5LL); j++) {
int cur = n;
if (v[0][i].S == v[1][j].S)
cur -= max(v[0][i].F, v[1][j].F);
else
cur -= (v[0][i].F + v[1][j].F);
ans = min(ans, cur);
}
}
cout << ans << endl;
}
} | replace | 113 | 115 | 113 | 115 | TLE | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
int n;
cin >> n;
map<int, int> odd, even;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (i % 2) {
odd[temp]++;
} else {
even[temp]++;
}
}
vector<pair<int, int>> a, b;
for (auto it = odd.begin(); it != odd.end(); it++) {
a.push_back({it->second, it->first});
}
for (auto it = even.begin(); it != even.end(); it++) {
b.push_back({it->second, it->first});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
n /= 2;
int n1 = a.size();
int m1 = b.size();
if (a[n1 - 1].second != b[m1 - 1].second) {
cout << n - a[n1 - 1].first + n - b[m1 - 1].first << endl;
return 0;
}
int ans = n - max(b[m1 - 1].first, a[n - 1].first) + n;
if (n1 >= 2) {
ans = min(ans, n - a[n1 - 2].first + n - b[m1 - 1].first);
}
if (m1 >= 2) {
ans = min(ans, n - a[n1 - 1].first + n - b[m1 - 2].first);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
int n;
cin >> n;
map<int, int> odd, even;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (i % 2) {
odd[temp]++;
} else {
even[temp]++;
}
}
vector<pair<int, int>> a, b;
for (auto it = odd.begin(); it != odd.end(); it++) {
a.push_back({it->second, it->first});
}
for (auto it = even.begin(); it != even.end(); it++) {
b.push_back({it->second, it->first});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
n /= 2;
int n1 = a.size();
int m1 = b.size();
if (a[n1 - 1].second != b[m1 - 1].second) {
cout << n - a[n1 - 1].first + n - b[m1 - 1].first << endl;
return 0;
}
int ans = n - max(b[m1 - 1].first, a[n1 - 1].first) + n;
if (n1 >= 2) {
ans = min(ans, n - a[n1 - 2].first + n - b[m1 - 1].first);
}
if (m1 >= 2) {
ans = min(ans, n - a[n1 - 1].first + n - b[m1 - 2].first);
}
cout << ans << endl;
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p03246 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, ans = 1e9, amax = 0, bmax = 0, af, bf;
cin >> n;
map<int, int> a, b;
rep(i, n / 2) {
int x, y;
cin >> x >> y;
a[x]++;
b[y]++;
}
for (auto i = a.begin(); i != a.end(); ++i) {
if (amax < (i->second)) {
amax = i->second;
af = i->first;
}
}
for (auto i = b.begin(); i != b.end(); ++i) {
if (bmax < (i->second)) {
bmax = i->second;
bf = i->first;
}
}
if (bf != af) {
cout << n - amax - bmax << endl;
return 0;
}
for (auto i = a.begin(); i != a.end(); ++i) {
for (auto j = b.begin(); j != b.end(); ++j) {
if ((i->first) == (j->first))
ans = min(ans, n - max(i->second, j->second));
else
ans = min(ans, n - (i->second) - (j->second));
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, ans = 1e9, amax = 0, bmax = 0, af, bf;
cin >> n;
map<int, int> a, b;
rep(i, n / 2) {
int x, y;
cin >> x >> y;
a[x]++;
b[y]++;
}
for (auto i = a.begin(); i != a.end(); ++i) {
if (amax < (i->second)) {
amax = i->second;
af = i->first;
}
}
for (auto i = b.begin(); i != b.end(); ++i) {
if (bmax <= (i->second)) {
bmax = i->second;
bf = i->first;
}
}
if (bf != af) {
cout << n - amax - bmax << endl;
return 0;
}
for (auto i = a.begin(); i != a.end(); ++i) {
for (auto j = b.begin(); j != b.end(); ++j) {
if ((i->first) == (j->first))
ans = min(ans, n - max(i->second, j->second));
else
ans = min(ans, n - (i->second) - (j->second));
}
}
cout << ans << endl;
return 0;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p03246 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
vector<pii> a(10005, {0, 0}), b(10005, {0, 0});
rep(i, n) {
int k;
cin >> k;
if (i % 2) {
a[k].first++;
a[k].second = k;
} else {
b[k].first++;
b[k].second = k;
}
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
if (a[0].second != b[0].second) {
cout << n - a[0].first - b[0].first << endl;
} else {
cout << min(n - a[0].first - b[1].first, n - a[1].first - b[0].first)
<< endl;
}
}
| #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
int n;
cin >> n;
vector<pii> a(100005, {0, 0}), b(100005, {0, 0});
rep(i, n) {
int k;
cin >> k;
if (i % 2) {
a[k].first++;
a[k].second = k;
} else {
b[k].first++;
b[k].second = k;
}
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
if (a[0].second != b[0].second) {
cout << n - a[0].first - b[0].first << endl;
} else {
cout << min(n - a[0].first - b[1].first, n - a[1].first - b[0].first)
<< endl;
}
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main() {
int n, M, m, amax = 0, amaxi = 0, bmax = 0, bmaxi = 0;
cin >> n;
vector<int> v(n + 10), a(100000, 0), b(100000, 0);
for (int i = 0; i < n; i++) {
cin >> v.at(i);
}
for (int i = 0; i < n - 1; i += 2) {
a.at(v.at(i))++;
b.at(v.at(i + 1))++;
}
for (int i = 0; i < 100000; i++) {
if (a.at(i) > amax) {
amax = a.at(i);
amaxi = i;
}
if (b.at(i) > bmax) {
bmax = b.at(i);
bmaxi = i;
}
}
if (amaxi == bmaxi) {
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
int c = min(n - a.at(0) - b.at(1), n - a.at(1) - b.at(0));
cout << c << endl;
} else {
cout << n - amax - bmax << endl;
}
}
| #include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main() {
int n, M, m, amax = 0, amaxi = 0, bmax = 0, bmaxi = 0;
cin >> n;
vector<int> v(n + 10), a(100001, 0), b(100001, 0);
for (int i = 0; i < n; i++) {
cin >> v.at(i);
}
for (int i = 0; i < n - 1; i += 2) {
a.at(v.at(i))++;
b.at(v.at(i + 1))++;
}
for (int i = 0; i < 100000; i++) {
if (a.at(i) > amax) {
amax = a.at(i);
amaxi = i;
}
if (b.at(i) > bmax) {
bmax = b.at(i);
bmaxi = i;
}
}
if (amaxi == bmaxi) {
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
int c = min(n - a.at(0) - b.at(1), n - a.at(1) - b.at(0));
cout << c << endl;
} else {
cout << n - amax - bmax << endl;
}
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03246 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
const int N = 10010;
int n, s1[N], s2[N], mx, mx11, mx12, mx21, mx22, v11, v12, v21, v22;
int main() {
int t, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &t);
mx = max(mx, t);
if (i & 1)
s1[t]++;
else
s2[t]++;
}
for (int i = 1; i <= mx; i++) {
if (s1[i] >= mx11) {
mx12 = mx11, v12 = v11;
mx11 = s1[i], v11 = i;
} else if (s1[i] > mx12)
mx12 = s1[i], v12 = i;
if (s2[i] >= mx21) {
mx22 = mx21, v22 = v21;
mx21 = s2[i], v21 = i;
} else if (s2[i] > mx22)
mx22 = s2[i], v22 = i;
}
if (v11 == v21) {
if (v11 != v22)
ans = max(ans, mx11 + mx22);
if (v12 != v21)
ans = max(ans, mx12 + mx21);
} else
ans = mx11 + mx21;
ans = n - ans;
printf("%d", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
using namespace std;
const int N = 100010;
int n, s1[N], s2[N], mx, mx11, mx12, mx21, mx22, v11, v12, v21, v22;
int main() {
int t, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &t);
mx = max(mx, t);
if (i & 1)
s1[t]++;
else
s2[t]++;
}
for (int i = 1; i <= mx; i++) {
if (s1[i] >= mx11) {
mx12 = mx11, v12 = v11;
mx11 = s1[i], v11 = i;
} else if (s1[i] > mx12)
mx12 = s1[i], v12 = i;
if (s2[i] >= mx21) {
mx22 = mx21, v22 = v21;
mx21 = s2[i], v21 = i;
} else if (s2[i] > mx22)
mx22 = s2[i], v22 = i;
}
if (v11 == v21) {
if (v11 != v22)
ans = max(ans, mx11 + mx22);
if (v12 != v21)
ans = max(ans, mx12 + mx21);
} else
ans = mx11 + mx21;
ans = n - ans;
printf("%d", ans);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03246 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
if (*max_element(v.begin(), v.end()) == *min_element(v.begin(), v.end())) {
cout << n / 2 << endl;
return 0;
}
map<int, int> cnt[2];
for (int i = 0; i < n; i++) {
if (i & 1) {
cnt[1][v[i]]++;
} else {
cnt[0][v[i]]++;
}
}
int res = n;
for (auto p1 : cnt[0]) {
for (auto p2 : cnt[1]) {
if (p1.first != p2.first) {
res = min(res, ((n + 1) / 2 - p1.second) + (n / 2 - p2.second));
}
}
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
if (*max_element(v.begin(), v.end()) == *min_element(v.begin(), v.end())) {
cout << n / 2 << endl;
return 0;
}
map<int, int> cnt[2];
for (int i = 0; i < n; i++) {
if (i & 1) {
cnt[1][v[i]]++;
} else {
cnt[0][v[i]]++;
}
}
vector<pair<int, int>> p1, p2;
for (auto v1 : cnt[0]) {
p1.emplace_back((n + 1) / 2 - v1.second, v1.first);
}
for (auto v2 : cnt[1]) {
p2.emplace_back(n / 2 - v2.second, v2.first);
}
sort(p1.begin(), p1.end());
sort(p2.begin(), p2.end());
int res = 0;
if (p1.front().second == p2.front().second) {
res = min(p1.front().first + ((int)p2.size() >= 2 ? p2[1].first : n / 2),
((int)p1.size() >= 2 ? p1[1].first : (n + 1) / 2) +
p2.front().first);
} else {
res = p1.front().first + p2.front().first;
}
cout << res << endl;
return 0;
}
| replace | 22 | 29 | 22 | 38 | TLE | |
p03246 | C++ | Runtime Error | /*
TASK: C - /\/\/\/
LANG: C++
*/
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
//*/
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef map<int, int> mii;
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define X first
#define Y second
#define mset(a, x) memset(a, x, sizeof(a))
#define P(x) cout << #x << " = " << x << endl;
#define P2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl;
#define PV(a, n) \
for (int i = 0; i < n; i++) \
cout << #a << "[" << i << "] = " << a[i] << endl;
#define TM(a, b) \
cout << #a << "->" << #b << ": " << 1. * (b - a) / CLOCKS_PER_SEC << "s\n";
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define for_each(it, X) \
for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define scanf_v(n, v) \
{ \
int tt; \
F0R(i, n) cin >> tt, v.pb(tt); \
}
#define fastio \
{ \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
}
#define unique_v(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
bitset<10000010> chk_p;
vi primes;
ll _sieve_size;
void gen_prime(ll nn) {
_sieve_size = nn + 1;
chk_p.set();
chk_p[0] = chk_p[1] = 0;
primes.pb(2);
FOR(i, 4, _sieve_size) chk_p[i] = 0;
for (ll i = 3; i < _sieve_size; i += 2)
if (chk_p[i]) {
for (ll j = i * i; j <= _sieve_size; j += i)
chk_p[j] = 0;
primes.pb((int)i);
}
}
ll exp(ll x, ll y, ll mod) {
if (y < 0)
return 0;
ll ret = 1;
for (; y; y >>= 1, x = (x * x) % mod) {
if (y & 1)
ret = (ret * x) % mod;
}
return ret;
}
ll inv_mod(ll a, ll p) { return exp(a, p - 2, p); } // only p-prime
bool isprime(ll x) {
if (x <= 1)
return false;
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
ll phi(ll x) {
ll t = x, ret = x, i;
for (i = 2; i * i <= x; i++) {
if (t % i == 0) {
ret -= ret / i;
while (t % i == 0)
t /= i;
}
}
if (t != 1)
ret -= ret / t;
return ret;
}
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(ull x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(ull x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(ull x) { return __builtin_popcountll(x); }
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(ull x) { return 63 ^ clzll(x); }
int N, M, T;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("xxx.in","r",stdin);
// freopen("xxx.out","w",stdout);
int i, j, k;
int tt = 0;
vi v;
cin >> N;
scanf_v(N, v);
mii mm, xx;
for (i = 0; i < N; i += 2)
mm[v[i]]++;
for (i = 1; i < N; i += 2)
xx[v[i]]++;
vii v1, v2;
for (auto it = mm.begin(); it != mm.end(); it++)
v1.pb({(*it).Y, (*it).X});
v1.pb({0, 1000000});
for (auto it = xx.begin(); it != xx.end(); it++)
v2.pb({(*it).Y, (*it).X});
v2.pb({0, 1000000});
sort(allr(v1));
sort(allr(v2));
int Mc = 0;
for (i = 0; i < v1.size(); i++) {
for (j = 0; j < v2.size(); j++) {
if (v2[j].Y != v1[i].Y) {
Mc = max(Mc, v2[j].X + v1[i].X);
break;
}
}
}
for (j = 0; j < v1.size(); j++) {
for (i = 0; i < v2.size(); i++) {
if (v2[j].Y != v1[i].Y) {
Mc = max(Mc, v2[j].X + v1[i].X);
break;
}
}
}
cout << N - Mc << '\n';
return 0;
}
| /*
TASK: C - /\/\/\/
LANG: C++
*/
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
//*/
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef map<int, int> mii;
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define X first
#define Y second
#define mset(a, x) memset(a, x, sizeof(a))
#define P(x) cout << #x << " = " << x << endl;
#define P2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl;
#define PV(a, n) \
for (int i = 0; i < n; i++) \
cout << #a << "[" << i << "] = " << a[i] << endl;
#define TM(a, b) \
cout << #a << "->" << #b << ": " << 1. * (b - a) / CLOCKS_PER_SEC << "s\n";
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define for_each(it, X) \
for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define scanf_v(n, v) \
{ \
int tt; \
F0R(i, n) cin >> tt, v.pb(tt); \
}
#define fastio \
{ \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
}
#define unique_v(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
bitset<10000010> chk_p;
vi primes;
ll _sieve_size;
void gen_prime(ll nn) {
_sieve_size = nn + 1;
chk_p.set();
chk_p[0] = chk_p[1] = 0;
primes.pb(2);
FOR(i, 4, _sieve_size) chk_p[i] = 0;
for (ll i = 3; i < _sieve_size; i += 2)
if (chk_p[i]) {
for (ll j = i * i; j <= _sieve_size; j += i)
chk_p[j] = 0;
primes.pb((int)i);
}
}
ll exp(ll x, ll y, ll mod) {
if (y < 0)
return 0;
ll ret = 1;
for (; y; y >>= 1, x = (x * x) % mod) {
if (y & 1)
ret = (ret * x) % mod;
}
return ret;
}
ll inv_mod(ll a, ll p) { return exp(a, p - 2, p); } // only p-prime
bool isprime(ll x) {
if (x <= 1)
return false;
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
ll phi(ll x) {
ll t = x, ret = x, i;
for (i = 2; i * i <= x; i++) {
if (t % i == 0) {
ret -= ret / i;
while (t % i == 0)
t /= i;
}
}
if (t != 1)
ret -= ret / t;
return ret;
}
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(ull x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(ull x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(ull x) { return __builtin_popcountll(x); }
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(ull x) { return 63 ^ clzll(x); }
int N, M, T;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("xxx.in","r",stdin);
// freopen("xxx.out","w",stdout);
int i, j, k;
int tt = 0;
vi v;
cin >> N;
scanf_v(N, v);
mii mm, xx;
for (i = 0; i < N; i += 2)
mm[v[i]]++;
for (i = 1; i < N; i += 2)
xx[v[i]]++;
vii v1, v2;
for (auto it = mm.begin(); it != mm.end(); it++)
v1.pb({(*it).Y, (*it).X});
v1.pb({0, 1000000});
for (auto it = xx.begin(); it != xx.end(); it++)
v2.pb({(*it).Y, (*it).X});
v2.pb({0, 1000000});
sort(allr(v1));
sort(allr(v2));
int Mc = 0;
for (i = 0; i < v1.size(); i++) {
for (j = 0; j < v2.size(); j++) {
if (v2[j].Y != v1[i].Y) {
Mc = max(Mc, v2[j].X + v1[i].X);
break;
}
}
}
for (i = 0; i < v2.size(); i++) {
for (j = 0; j < v1.size(); j++) {
if (v2[i].Y != v1[j].Y) {
Mc = max(Mc, v2[i].X + v1[j].X);
break;
}
}
}
cout << N - Mc << '\n';
return 0;
}
| replace | 192 | 196 | 192 | 196 | 0 | |
p03246 | C++ | Runtime Error | /**
* Author: "Robin Singh" !!!
* BrainyIsTheNewSexy (CodeForces)
* rob_in_1 (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) \
sort(all((x))); \
(x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())
#define fr(i, j, k) for (int i = j; i < k; i++)
#define bk(i, j, k) for (int i = j - 1; i >= k; i--)
#define frit(it, a) \
for (__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr) memset(ptr, 0, sizeof ptr)
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long INF = (1LL << 61);
const int inf = (1 << 30);
const int nn = 1e5 + 5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg(args...) \
{ \
vector<string> _v = split(#args, ','); \
err(_v.begin(), args); \
cerr << '\n'; \
}
vector<string> split(const string &s, char c) {
vector<string> v;
stringstream ss(s);
string x;
while (getline(ss, x, c))
v.emplace_back(x);
return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\t';
err(++it, args...);
}
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends
//Here!*****************************************************]
int cnt[2][nn];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
int n;
cin >> n;
int a[n];
fr(i, 0, n) {
cin >> a[i];
cnt[i % 2][a[i]]++;
}
int mx1 = 0, mx11 = 0, mx2 = 0, mx22 = 0;
int n1, n2;
fr(i, 0, nn) {
if (cnt[0][i] > mx1) {
n1 = i;
mx11 = mx1;
mx1 = cnt[0][i];
} else if (cnt[0][i] > mx11) {
mx11 = cnt[0][i];
}
if (cnt[1][i] > mx2) {
n2 = i;
mx22 = mx2;
mx2 = cnt[1][i];
} else if (cnt[1][i] > mx22) {
mx22 = cnt[1][i];
}
}
if (n1 == n2) {
int mx = max({mx1 + mx22, mx2 + mx11});
cout << n - mx;
} else
cout << n / 2 - mx1 + n / 2 - mx2;
return 0;
}
//->INTUITIONS are not to be ignored. They represent data processed too fast for
//the conscious mind to comprehend !!
| /**
* Author: "Robin Singh" !!!
* BrainyIsTheNewSexy (CodeForces)
* rob_in_1 (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) \
sort(all((x))); \
(x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())
#define fr(i, j, k) for (int i = j; i < k; i++)
#define bk(i, j, k) for (int i = j - 1; i >= k; i--)
#define frit(it, a) \
for (__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr) memset(ptr, 0, sizeof ptr)
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long INF = (1LL << 61);
const int inf = (1 << 30);
const int nn = 1e5 + 5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg(args...) \
{ \
vector<string> _v = split(#args, ','); \
err(_v.begin(), args); \
cerr << '\n'; \
}
vector<string> split(const string &s, char c) {
vector<string> v;
stringstream ss(s);
string x;
while (getline(ss, x, c))
v.emplace_back(x);
return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\t';
err(++it, args...);
}
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends
//Here!*****************************************************]
int cnt[2][nn];
int main() {
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
IOS;
int n;
cin >> n;
int a[n];
fr(i, 0, n) {
cin >> a[i];
cnt[i % 2][a[i]]++;
}
int mx1 = 0, mx11 = 0, mx2 = 0, mx22 = 0;
int n1, n2;
fr(i, 0, nn) {
if (cnt[0][i] > mx1) {
n1 = i;
mx11 = mx1;
mx1 = cnt[0][i];
} else if (cnt[0][i] > mx11) {
mx11 = cnt[0][i];
}
if (cnt[1][i] > mx2) {
n2 = i;
mx22 = mx2;
mx2 = cnt[1][i];
} else if (cnt[1][i] > mx22) {
mx22 = cnt[1][i];
}
}
if (n1 == n2) {
int mx = max({mx1 + mx22, mx2 + mx11});
cout << n - mx;
} else
cout << n / 2 - mx1 + n / 2 - mx2;
return 0;
}
//->INTUITIONS are not to be ignored. They represent data processed too fast for
//the conscious mind to comprehend !!
| replace | 68 | 72 | 68 | 70 | -11 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define ld long double
using namespace std;
int n, a[20100], ct[20100], proh;
int maxa1, maxa2, num1, num2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
maxa1 = 0;
for (int i = 0; i < n; i += 2) {
ct[a[i]]++;
if (maxa1 < ct[a[i]]) {
maxa1 = ct[a[i]];
num1 = a[i];
}
}
memset(ct, 0, sizeof(ct));
for (int i = 1; i < n; i += 2) {
ct[a[i]]++;
if (maxa2 < ct[a[i]]) {
maxa2 = ct[a[i]];
num2 = a[i];
}
}
int ans;
if (num1 == num2) {
int proh1 = num1, proh2 = num2;
int large1 = maxa1, large2 = maxa2;
maxa1 = 0;
memset(ct, 0, sizeof(ct));
for (int i = 0; i < n; i += 2) {
ct[a[i]]++;
if (maxa1 < ct[a[i]] && a[i] != proh1) {
maxa1 = ct[a[i]];
num1 = a[i];
}
}
maxa2 = 0;
memset(ct, 0, sizeof(ct));
for (int i = 1; i < n; i += 2) {
ct[a[i]]++;
if (maxa2 < ct[a[i]] && a[i] != proh2) {
maxa2 = ct[a[i]];
num2 = a[i];
}
}
ans = max(large1 + maxa2, maxa1 + large2);
} else
ans = maxa1 + maxa2;
cout << n - ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define ld long double
using namespace std;
int n, a[200100], ct[200100], proh;
int maxa1, maxa2, num1, num2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
maxa1 = 0;
for (int i = 0; i < n; i += 2) {
ct[a[i]]++;
if (maxa1 < ct[a[i]]) {
maxa1 = ct[a[i]];
num1 = a[i];
}
}
memset(ct, 0, sizeof(ct));
for (int i = 1; i < n; i += 2) {
ct[a[i]]++;
if (maxa2 < ct[a[i]]) {
maxa2 = ct[a[i]];
num2 = a[i];
}
}
int ans;
if (num1 == num2) {
int proh1 = num1, proh2 = num2;
int large1 = maxa1, large2 = maxa2;
maxa1 = 0;
memset(ct, 0, sizeof(ct));
for (int i = 0; i < n; i += 2) {
ct[a[i]]++;
if (maxa1 < ct[a[i]] && a[i] != proh1) {
maxa1 = ct[a[i]];
num1 = a[i];
}
}
maxa2 = 0;
memset(ct, 0, sizeof(ct));
for (int i = 1; i < n; i += 2) {
ct[a[i]]++;
if (maxa2 < ct[a[i]] && a[i] != proh2) {
maxa2 = ct[a[i]];
num2 = a[i];
}
}
ans = max(large1 + maxa2, maxa1 + large2);
} else
ans = maxa1 + maxa2;
cout << n - ans << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03246 | C++ | Runtime Error | #include <bits/stdc++.h>
#define CEIL(a, b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;
constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
bool compy(pii a, pii b) { return a.second > b.second; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pii> b(100001), c(100001);
for (int i = 0; i < 100001; ++i) {
b[i].second = i;
c[i].second = i;
}
for (int i = 0; i < n; i += 2) {
b[a[i]].first++;
}
for (int i = 1; i < n; i += 2) {
c[a[i]].first++;
}
int m = 0, mm = 0;
sort(begin(b), end(b), greater<pii>());
sort(begin(c), end(c), greater<pii>());
int ans = INF;
if (b[0].second != c[0].second) {
cout << n - b[0].first - c[0].first << "\n";
return 0;
}
for (int i = 0; i < 100000; ++i) {
if (b[i].second != c[i].second) {
cout << n - b[i].first - c[i].first << "\n";
return i;
}
if (b[i + 1].second != c[i].second) {
ans = min(ans, n - b[i + 1].first - c[i].first);
}
if (b[i].second != c[i + 1].second) {
ans = min(ans, n - b[i].first - c[i + 1].first);
}
}
cout << ans << "\n";
/*
vector<int> q, r;
for(auto && i : b){
if(m < i.second){
q = vector<int>();
m = max(m, i.second);
q.push_back(i.first);
}
else if(m == i.second){
q.push_back(i.first);
}
}
for(auto && i : c){
if(mm < i.second){
r = vector<int>();
mm = max(mm, i.second);
r.push_back(i.first);
}
else if(mm == i.second){
r.push_back(i.first);
}
}
for(auto && i : q){
for(auto && j : r){
if(q != r){
cout << n - m - mm << "\n";
return 0;
}
}
}
int tm, tmm;
for(auto && i : b){
if(m < i.second && ){
q = vector<int>();
m = max(m, i.second);
q.push_back(i.first);
}
else if(m == i.second){
q.push_back(i.first);
}
}
for(auto && i : c){
if(mm < i.second){
r = vector<int>();
mm = max(mm, i.second);
r.push_back(i.first);
}
else if(mm == i.second){
r.push_back(i.first);
}
}
cout << n - m - mm << "\n";
*/
return 0;
}
| #include <bits/stdc++.h>
#define CEIL(a, b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;
constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
bool compy(pii a, pii b) { return a.second > b.second; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pii> b(100001), c(100001);
for (int i = 0; i < 100001; ++i) {
b[i].second = i;
c[i].second = i;
}
for (int i = 0; i < n; i += 2) {
b[a[i]].first++;
}
for (int i = 1; i < n; i += 2) {
c[a[i]].first++;
}
int m = 0, mm = 0;
sort(begin(b), end(b), greater<pii>());
sort(begin(c), end(c), greater<pii>());
int ans = INF;
if (b[0].second != c[0].second) {
cout << n - b[0].first - c[0].first << "\n";
return 0;
}
for (int i = 0; i < 100000; ++i) {
if (b[i].second != c[i].second) {
ans = min(ans, n - b[i].first - c[i].first);
}
if (b[i + 1].second != c[i].second) {
ans = min(ans, n - b[i + 1].first - c[i].first);
}
if (b[i].second != c[i + 1].second) {
ans = min(ans, n - b[i].first - c[i + 1].first);
}
}
cout << ans << "\n";
/*
vector<int> q, r;
for(auto && i : b){
if(m < i.second){
q = vector<int>();
m = max(m, i.second);
q.push_back(i.first);
}
else if(m == i.second){
q.push_back(i.first);
}
}
for(auto && i : c){
if(mm < i.second){
r = vector<int>();
mm = max(mm, i.second);
r.push_back(i.first);
}
else if(mm == i.second){
r.push_back(i.first);
}
}
for(auto && i : q){
for(auto && j : r){
if(q != r){
cout << n - m - mm << "\n";
return 0;
}
}
}
int tm, tmm;
for(auto && i : b){
if(m < i.second && ){
q = vector<int>();
m = max(m, i.second);
q.push_back(i.first);
}
else if(m == i.second){
q.push_back(i.first);
}
}
for(auto && i : c){
if(mm < i.second){
r = vector<int>();
mm = max(mm, i.second);
r.push_back(i.first);
}
else if(mm == i.second){
r.push_back(i.first);
}
}
cout << n - m - mm << "\n";
*/
return 0;
}
| replace | 56 | 58 | 56 | 57 | 0 | |
p03247 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define For(i, l, r) for (int i = (l), i##end = (r); i <= i##end; i++)
#define Fordown(i, r, l) for (int i = (r), i##end = (l); i >= i##end; i--)
#define debug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10, Bit = 35;
struct node {
int x, y;
} Pos[N];
char Opt[N][Bit];
int n, cnt, Val[Bit];
inline int read() {
int x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
flag = -1, ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
return x * flag;
}
inline void Work(int val) {
int id = ++cnt;
For(i, 1, n) {
if (abs(Pos[i].x) > abs(Pos[i].y)) {
if (Pos[i].x > 0) {
Pos[i].x -= val;
Opt[i][id] = 'R';
} else {
Pos[i].x += val;
Opt[i][id] = 'L';
}
} else {
if (Pos[i].y > 0) {
Pos[i].y -= val;
Opt[i][id] = 'U';
} else {
Pos[i].y += val;
Opt[i][id] = 'D';
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("ARC103D.in", "r", stdin);
freopen("ARC103D.out", "w", stdout);
#endif
n = read();
int val = -1, tot = 0;
For(i, 1, n) {
Pos[i].x = read(), Pos[i].y = read();
if (val < 0)
val = (Pos[i].x + Pos[i].y) & 1;
else if (((Pos[i].x + Pos[i].y) & 1) != val)
return puts("-1"), 0;
}
Fordown(i, 30, 0) Work(1 << i), Val[++tot] = 1 << i;
if (!val)
Work(1), Val[++tot] = 1;
printf("%d\n", tot);
For(i, 1, tot) printf("%d%c", Val[i], i == iend ? '\n' : ' ');
For(i, 1, n) {
For(j, 1, tot) printf("%c", Opt[i][j]);
puts("");
}
return 0;
} | #include <bits/stdc++.h>
#define For(i, l, r) for (int i = (l), i##end = (r); i <= i##end; i++)
#define Fordown(i, r, l) for (int i = (r), i##end = (l); i >= i##end; i--)
#define debug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10, Bit = 35;
struct node {
int x, y;
} Pos[N];
char Opt[N][Bit];
int n, cnt, Val[Bit];
inline int read() {
int x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
flag = -1, ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch - '0'), ch = getchar();
return x * flag;
}
inline void Work(int val) {
int id = ++cnt;
For(i, 1, n) {
if (abs(Pos[i].x) > abs(Pos[i].y)) {
if (Pos[i].x > 0) {
Pos[i].x -= val;
Opt[i][id] = 'R';
} else {
Pos[i].x += val;
Opt[i][id] = 'L';
}
} else {
if (Pos[i].y > 0) {
Pos[i].y -= val;
Opt[i][id] = 'U';
} else {
Pos[i].y += val;
Opt[i][id] = 'D';
}
}
}
}
int main() {
n = read();
int val = -1, tot = 0;
For(i, 1, n) {
Pos[i].x = read(), Pos[i].y = read();
if (val < 0)
val = (Pos[i].x + Pos[i].y) & 1;
else if (((Pos[i].x + Pos[i].y) & 1) != val)
return puts("-1"), 0;
}
Fordown(i, 30, 0) Work(1 << i), Val[++tot] = 1 << i;
if (!val)
Work(1), Val[++tot] = 1;
printf("%d\n", tot);
For(i, 1, tot) printf("%d%c", Val[i], i == iend ? '\n' : ' ');
For(i, 1, n) {
For(j, 1, tot) printf("%c", Opt[i][j]);
puts("");
}
return 0;
} | delete | 61 | 65 | 61 | 61 | TLE | |
p03247 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#define REP(i, a, n) for (int i = a; i <= n; ++i)
#define PER(i, a, n) for (int i = n; i >= a; --i)
#define hr putchar(10)
#define pb push_back
#define lc (o << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define ls lc, l, mid
#define rs rc, mid + 1, r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) \
({ \
REP(__i, 1, n) cout << a[__i] << ','; \
hr; \
})
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll qpow(ll a, ll n) {
ll r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1)
r = r * a % P;
return r;
}
ll inv(ll x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; }
inline int rd() {
int x = 0;
char p = getchar();
while (p < '0' || p > '9')
p = getchar();
while (p >= '0' && p <= '9')
x = x * 10 + p - '0', p = getchar();
return x;
}
// head
#ifdef ONLINE_JUDGE
const int N = 1e6 + 50;
#else
const int N = 1e2 + 10;
#endif
int n, a[N], b[N], d[N];
char s[N];
int main() {
scanf("%d", &n);
int c[2]{};
REP(i, 1, n) {
scanf("%d%d", a + i, b + i);
++c[a[i] + b[i] & 1];
}
if (c[0] != n && c[1] != n)
return puts("-1"), 0;
printf("%d\n", 31 + !!c[0]);
REP(i, 0, 30) printf("%d ", 1 << i);
if (c[0])
printf("%d ", 1);
hr;
REP(i, 1, n) {
int x = a[i], y = b[i];
if (c[0])
--x, s[31] = 'R';
int f = 0;
PER(i, 0, 30) {
if (abs(x) < abs(y))
swap(x, y), f ^= 1;
if (x > 0)
x -= 1 << i, s[i] = "RU"[f];
else
x += 1 << i, s[i] = "LD"[f];
}
puts(s);
}
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#define REP(i, a, n) for (int i = a; i <= n; ++i)
#define PER(i, a, n) for (int i = n; i >= a; --i)
#define hr putchar(10)
#define pb push_back
#define lc (o << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define ls lc, l, mid
#define rs rc, mid + 1, r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) \
({ \
REP(__i, 1, n) cout << a[__i] << ','; \
hr; \
})
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll qpow(ll a, ll n) {
ll r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1)
r = r * a % P;
return r;
}
ll inv(ll x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; }
inline int rd() {
int x = 0;
char p = getchar();
while (p < '0' || p > '9')
p = getchar();
while (p >= '0' && p <= '9')
x = x * 10 + p - '0', p = getchar();
return x;
}
// head
const int N = 1e5 + 10;
int n, a[N], b[N], d[N];
char s[N];
int main() {
scanf("%d", &n);
int c[2]{};
REP(i, 1, n) {
scanf("%d%d", a + i, b + i);
++c[a[i] + b[i] & 1];
}
if (c[0] != n && c[1] != n)
return puts("-1"), 0;
printf("%d\n", 31 + !!c[0]);
REP(i, 0, 30) printf("%d ", 1 << i);
if (c[0])
printf("%d ", 1);
hr;
REP(i, 1, n) {
int x = a[i], y = b[i];
if (c[0])
--x, s[31] = 'R';
int f = 0;
PER(i, 0, 30) {
if (abs(x) < abs(y))
swap(x, y), f ^= 1;
if (x > 0)
x -= 1 << i, s[i] = "RU"[f];
else
x += 1 << i, s[i] = "LD"[f];
}
puts(s);
}
}
| replace | 55 | 61 | 55 | 56 | 0 | |
p03247 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>/
// #include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define mod 1000000007LL
#define IN freopen("input.txt", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define DBG printf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x) * (x))
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define EPS 1e-7
// using namespace __gnu_pbds;
using namespace std;
// typedef tree< i64, null_type, less<i64>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;
#define maxn 1000005
#define mxPower 30
i64 x[45], y[45];
vector<int> f(i64 m, int p) {
if (p == -1) {
vector<int> res;
return res;
}
vector<int> res;
if ((1LL << p) > m) {
res = f((1LL << p) - m, p - 1);
for (int i = 0; i < res.size(); i++)
res[i] *= -1;
} else {
res = f(m - (1LL << p), p - 1);
}
res.pb(1);
return res;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld %lld", &x[i], &y[i]);
int parity = ((x[1] + y[1]) % 2 + 2) % 2;
for (int i = 2; i <= n; i++) {
if (((x[i] + y[i]) % 2 + 2) % 2 != parity) {
printf("-1\n");
return 0;
}
}
vector<i64> ansPowers;
for (int i = 0; i <= mxPower; i++)
ansPowers.pb((1LL << i));
if (parity == 0) {
for (int i = 1; i <= n; i++)
x[i]++;
ansPowers.pb(1);
}
printf("%d\n", (int)ansPowers.size());
for (int i = 0; i < ansPowers.size(); i++)
printf("%lld ", ansPowers[i]);
printf("\n");
for (int i = 1; i <= n; i++) {
vector<int> res = f(abs(x[i]) + abs(y[i]), mxPower);
i64 Y = abs(y[i]);
vector<int> forY;
for (int j = 0; j <= mxPower; j++) {
if (Y % 2) {
forY.pb(1);
if (res[j] == 1)
Y--;
else
Y++;
} else {
forY.pb(0);
}
Y /= 2;
}
string ans;
for (int j = 0; j <= mxPower; j++) {
if (forY[j] == 0) {
if (res[j] == 1)
ans += "R";
else
ans += "L";
} else {
if (res[j] == 1)
ans += "U";
else
ans += "D";
}
}
if (x[i] < 0) {
for (int j = 0; j < ans.size(); j++) {
if (ans[j] == 'L')
ans[j] = 'R';
else if (ans[j] == 'R')
ans[j] = 'L';
}
}
if (y[i] < 0) {
for (int j = 0; j < ans.size(); j++) {
if (ans[j] == 'U')
ans[j] = 'D';
else if (ans[j] == 'D')
ans[j] = 'U';
}
}
if (parity == 0)
ans += "L";
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>/
// #include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define mod 1000000007LL
#define IN freopen("input.txt", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define DBG printf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x) * (x))
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define EPS 1e-7
// using namespace __gnu_pbds;
using namespace std;
// typedef tree< i64, null_type, less<i64>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;
#define maxn 1000005
#define mxPower 30
i64 x[1005], y[1005];
vector<int> f(i64 m, int p) {
if (p == -1) {
vector<int> res;
return res;
}
vector<int> res;
if ((1LL << p) > m) {
res = f((1LL << p) - m, p - 1);
for (int i = 0; i < res.size(); i++)
res[i] *= -1;
} else {
res = f(m - (1LL << p), p - 1);
}
res.pb(1);
return res;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld %lld", &x[i], &y[i]);
int parity = ((x[1] + y[1]) % 2 + 2) % 2;
for (int i = 2; i <= n; i++) {
if (((x[i] + y[i]) % 2 + 2) % 2 != parity) {
printf("-1\n");
return 0;
}
}
vector<i64> ansPowers;
for (int i = 0; i <= mxPower; i++)
ansPowers.pb((1LL << i));
if (parity == 0) {
for (int i = 1; i <= n; i++)
x[i]++;
ansPowers.pb(1);
}
printf("%d\n", (int)ansPowers.size());
for (int i = 0; i < ansPowers.size(); i++)
printf("%lld ", ansPowers[i]);
printf("\n");
for (int i = 1; i <= n; i++) {
vector<int> res = f(abs(x[i]) + abs(y[i]), mxPower);
i64 Y = abs(y[i]);
vector<int> forY;
for (int j = 0; j <= mxPower; j++) {
if (Y % 2) {
forY.pb(1);
if (res[j] == 1)
Y--;
else
Y++;
} else {
forY.pb(0);
}
Y /= 2;
}
string ans;
for (int j = 0; j <= mxPower; j++) {
if (forY[j] == 0) {
if (res[j] == 1)
ans += "R";
else
ans += "L";
} else {
if (res[j] == 1)
ans += "U";
else
ans += "D";
}
}
if (x[i] < 0) {
for (int j = 0; j < ans.size(); j++) {
if (ans[j] == 'L')
ans[j] = 'R';
else if (ans[j] == 'R')
ans[j] = 'L';
}
}
if (y[i] < 0) {
for (int j = 0; j < ans.size(); j++) {
if (ans[j] == 'U')
ans[j] = 'D';
else if (ans[j] == 'D')
ans[j] = 'U';
}
}
if (parity == 0)
ans += "L";
cout << ans << endl;
}
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p03247 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define of(i, l, r) for (int i = l; i >= r; i--)
#define fe(i, u) for (int i = head[u]; i; i = e[i].next)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline void open(const char *s) {
#ifndef ONLINE_JUDGE
char str[20];
sprintf(str, "%s.in", s);
freopen(str, "r", stdin);
// sprintf(str,"%s.out",s);
// freopen(str,"w",stdout);
#endif
}
inline int rd() {
static int x, f;
x = 0;
f = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-')
f = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
return f > 0 ? x : -x;
}
const int N = 1010;
int n, a[N], b[N], B;
inline void gao(int x, int y, int k) {
if (k == -1)
return;
if (abs(x) >= (1 << k)) {
if (x > 0) {
cout << 'R';
x -= (1 << k);
return gao(x, y, k - 1);
} else {
cout << 'L';
x += (1 << k);
return gao(x, y, k - 1);
}
}
if (abs(y) >= (1 << k)) {
if (y > 0) {
cout << 'U';
y -= (1 << k);
return gao(x, y, k - 1);
} else {
cout << 'D';
y += (1 << k);
return gao(x, y, k - 1);
}
}
if (abs(x) > abs(y)) {
if (x > 0) {
cout << 'R';
x -= 1 << k;
return gao(x, y, k - 1);
} else {
cout << 'L';
x += 1 << k;
return gao(x, y, k - 1);
}
} else {
if (y > 0) {
cout << 'U';
y -= 1 << k;
return gao(x, y, k - 1);
} else {
cout << 'D';
y += 1 << k;
return gao(x, y, k - 1);
}
}
}
int main() {
open("hh");
n = rd();
fo(i, 1, n) a[i] = rd(), b[i] = rd();
fo(i, 1, n - 1) if ((abs(a[i]) ^ abs(b[i]) ^ abs(a[i + 1]) ^ abs(b[i + 1])) &
1) return puts("-1"),
0;
int f = ~(abs(a[1]) + abs(b[1])) & 1;
B = 30;
cout << B + f + 1 << '\n';
of(i, B, 0) cout << (1 << i) << ' ';
if (f) {
cout << 1;
fo(i, 1, n)++ a[i];
}
cout << '\n';
fo(i, 1, n) {
gao(a[i], b[i], B);
if (f)
cout << 'L';
cout << '\n';
}
return 0;
} | #include <bits/stdc++.h>
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define of(i, l, r) for (int i = l; i >= r; i--)
#define fe(i, u) for (int i = head[u]; i; i = e[i].next)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline void open(const char *s) {
#ifndef ONLINE_JUDGE
char str[20];
sprintf(str, "%s.in", s);
freopen(str, "r", stdin);
// sprintf(str,"%s.out",s);
// freopen(str,"w",stdout);
#endif
}
inline int rd() {
static int x, f;
x = 0;
f = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-')
f = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
return f > 0 ? x : -x;
}
const int N = 1010;
int n, a[N], b[N], B;
inline void gao(int x, int y, int k) {
if (k == -1)
return;
if (abs(x) >= (1 << k)) {
if (x > 0) {
cout << 'R';
x -= (1 << k);
return gao(x, y, k - 1);
} else {
cout << 'L';
x += (1 << k);
return gao(x, y, k - 1);
}
}
if (abs(y) >= (1 << k)) {
if (y > 0) {
cout << 'U';
y -= (1 << k);
return gao(x, y, k - 1);
} else {
cout << 'D';
y += (1 << k);
return gao(x, y, k - 1);
}
}
if (abs(x) > abs(y)) {
if (x > 0) {
cout << 'R';
x -= 1 << k;
return gao(x, y, k - 1);
} else {
cout << 'L';
x += 1 << k;
return gao(x, y, k - 1);
}
} else {
if (y > 0) {
cout << 'U';
y -= 1 << k;
return gao(x, y, k - 1);
} else {
cout << 'D';
y += 1 << k;
return gao(x, y, k - 1);
}
}
}
int main() {
n = rd();
fo(i, 1, n) a[i] = rd(), b[i] = rd();
fo(i, 1, n - 1) if ((abs(a[i]) ^ abs(b[i]) ^ abs(a[i + 1]) ^ abs(b[i + 1])) &
1) return puts("-1"),
0;
int f = ~(abs(a[1]) + abs(b[1])) & 1;
B = 30;
cout << B + f + 1 << '\n';
of(i, B, 0) cout << (1 << i) << ' ';
if (f) {
cout << 1;
fo(i, 1, n)++ a[i];
}
cout << '\n';
fo(i, 1, n) {
gao(a[i], b[i], B);
if (f)
cout << 'L';
cout << '\n';
}
return 0;
} | delete | 80 | 81 | 80 | 80 | TLE | |
p03247 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define f first
#define s second
using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(ld x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char *x) { cout << x; }
void pr(const string &x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T> void pr(const complex<T> &x) { cout << x; }
template <class T1, class T2> void pr(const pair<T1, T2> &x);
template <class T> void pr(const T &x);
template <class T, class... Ts> void pr(const T &t, const Ts &...ts) {
pr(t);
pr(ts...);
}
template <class T1, class T2> void pr(const pair<T1, T2> &x) {
pr("{", x.f, ", ", x.s, "}");
}
template <class T> void pr(const T &x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto &a : x)
pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void print() { pr("\n"); } // print w/ spaces
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
pr(t);
if (sizeof...(ts))
pr(" ");
print(ts...);
}
} // namespace output
using namespace output;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N;
cin >> N;
vector<pair<ll, ll>> points(N);
F0R(i, N) {
ll x, y;
cin >> x >> y;
points[i] = {x, y};
}
bool par = (points[0].first ^ points[0].second) & 1;
F0R(i, N) if (((points[i].first ^ points[i].second) & 1) != par) {
print(-1);
return 0;
}
vll sizes;
vector<string> ans(N);
if (!par) {
F0R(i, N) points[i].second++;
sizes.push_back(1);
F0R(i, N) ans[i] += "D";
}
R0F(d, 30) {
sizes.push_back(1ll << d);
F0R(i, N) {
ll x = points[i].first;
ll y = points[i].second;
if (y >= x && y >= -x) {
ans[i] += "U";
points[i].second -= 1ll << d;
} else if (y >= x && y < -x) {
ans[i] += "L";
points[i].first += 1ll << d;
} else if (y < x && y >= -x) {
ans[i] += "R";
points[i].first -= 1ll << d;
} else if (y < x && y < -x) {
ans[i] += "D";
points[i].second += 1ll << d;
}
}
}
F0R(i, N) { assert(points[i].first == 0 && points[i].second == 0); }
print(sizes.size());
for (ll x : sizes)
cout << x << " ";
cout << endl;
F0R(i, N) print(ans[i]);
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define f first
#define s second
using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(ld x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char *x) { cout << x; }
void pr(const string &x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template <class T> void pr(const complex<T> &x) { cout << x; }
template <class T1, class T2> void pr(const pair<T1, T2> &x);
template <class T> void pr(const T &x);
template <class T, class... Ts> void pr(const T &t, const Ts &...ts) {
pr(t);
pr(ts...);
}
template <class T1, class T2> void pr(const pair<T1, T2> &x) {
pr("{", x.f, ", ", x.s, "}");
}
template <class T> void pr(const T &x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto &a : x)
pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void print() { pr("\n"); } // print w/ spaces
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
pr(t);
if (sizeof...(ts))
pr(" ");
print(ts...);
}
} // namespace output
using namespace output;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N;
cin >> N;
vector<pair<ll, ll>> points(N);
F0R(i, N) {
ll x, y;
cin >> x >> y;
points[i] = {x, y};
}
bool par = (points[0].first ^ points[0].second) & 1;
F0R(i, N) if (((points[i].first ^ points[i].second) & 1) != par) {
print(-1);
return 0;
}
vll sizes;
vector<string> ans(N);
if (!par) {
F0R(i, N) points[i].second++;
sizes.push_back(1);
F0R(i, N) ans[i] += "D";
}
R0F(d, 32) {
sizes.push_back(1ll << d);
F0R(i, N) {
ll x = points[i].first;
ll y = points[i].second;
if (y >= x && y >= -x) {
ans[i] += "U";
points[i].second -= 1ll << d;
} else if (y >= x && y < -x) {
ans[i] += "L";
points[i].first += 1ll << d;
} else if (y < x && y >= -x) {
ans[i] += "R";
points[i].first -= 1ll << d;
} else if (y < x && y < -x) {
ans[i] += "D";
points[i].second += 1ll << d;
}
}
}
F0R(i, N) { assert(points[i].first == 0 && points[i].second == 0); }
print(sizes.size());
for (ll x : sizes)
cout << x << " ";
cout << endl;
F0R(i, N) print(ans[i]);
} | replace | 89 | 90 | 89 | 90 | 0 | |
p03247 | C++ | Runtime Error | #include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 1000 + 5;
int n;
int x[N], y[N];
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const char dir[4] = {'R', 'L', 'U', 'D'};
ll dist(ll x, ll y, ll tx, ll ty) { return abs(x - tx) + abs(y - ty); }
int main() {
scanf("%d", &n);
int sig = 0, par = 0;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x[i], &y[i]);
sig |= ((x[i] ^ y[i]) & 1);
par |= !((x[i] ^ y[i]) & 1);
}
if (sig && par) {
puts("-1");
return 0;
}
if (par) {
printf("32\n1 ");
} else {
printf("31\n");
}
for (int i = 30; i >= 0; i--) {
printf("%d ", (int)pow(2, i));
}
puts("");
for (int i = 1; i <= n; i++) {
ll sx = 0, sy = 0;
if (par) {
putchar('L');
sx--;
}
for (int j = 30; j >= 0; j--) {
for (int k = 0; k < 4; k++) {
ll nx = sx + dx[k] * pow(2, j);
ll ny = sy + dy[k] * pow(2, j);
int d = dist(nx, ny, x[i], y[i]);
if (d <= pow(2, j) - 1 && !((d ^ ((int)pow(2, j) - 1)) & 1)) {
sx = nx;
sy = ny;
putchar(dir[k]);
break;
}
}
}
assert(sx == x[i] && sy == y[i]);
puts("");
}
return 0;
}
| #include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 1000 + 5;
int n;
int x[N], y[N];
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const char dir[4] = {'R', 'L', 'U', 'D'};
ll dist(ll x, ll y, ll tx, ll ty) { return abs(x - tx) + abs(y - ty); }
int main() {
scanf("%d", &n);
int sig = 0, par = 0;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x[i], &y[i]);
sig |= ((x[i] ^ y[i]) & 1);
par |= !((x[i] ^ y[i]) & 1);
}
if (sig && par) {
puts("-1");
return 0;
}
if (par) {
printf("32\n1 ");
} else {
printf("31\n");
}
for (int i = 30; i >= 0; i--) {
printf("%d ", (int)pow(2, i));
}
puts("");
for (int i = 1; i <= n; i++) {
ll sx = 0, sy = 0;
if (par) {
putchar('L');
sx--;
}
for (int j = 30; j >= 0; j--) {
for (int k = 0; k < 4; k++) {
ll nx = sx + dx[k] * pow(2, j);
ll ny = sy + dy[k] * pow(2, j);
ll d = dist(nx, ny, x[i], y[i]);
if (d <= pow(2, j) - 1 && !((d ^ ((int)pow(2, j) - 1)) & 1)) {
sx = nx;
sy = ny;
putchar(dir[k]);
break;
}
}
}
assert(sx == x[i] && sy == y[i]);
puts("");
}
return 0;
}
| replace | 55 | 56 | 55 | 56 | 0 | |
p03247 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(), V.end()
#define MOD 1000000007
ll dat[1010][3];
ll arms[41];
short B[41];
string F[1010];
int main() {
arms[0] = arms[1] = 1;
for (int i = 2; i < 35; i++) {
arms[i] = arms[i - 1] * 2;
}
ll S = (1LL << 34);
int N;
cin >> N;
ll x, y;
short z = 2;
for (int i = 0; i < N; i++) {
cin >> x >> y;
dat[i][0] = x;
dat[i][1] = y;
if ((x + y) & 1) {
if (z == 0)
z = 5;
if (z == 2)
z = 1;
} else {
if (z == 1)
z = 5;
if (z == 2)
z = 0;
}
}
if (z == 5) {
cout << -1 << endl;
return 0;
}
if (z == 1)
arms[0] = 0, S--;
bool xc, yc;
string ans;
for (int i = 0; i < N; i++) {
x = dat[i][0];
if (x < 0)
xc = 1, x = -x;
else
xc = 0;
y = dat[i][1];
if (y < 0)
yc = 1, y = -y;
else
yc = 0;
ll bt = (S - x - y) / 2;
int bc = 1;
B[0] = 6;
for (int j = 1; j < 35; j++) {
if (bt & 1)
B[j] = 1;
else
B[j] = 0;
bt /= 2;
}
for (int j = 0; j < 35; j++) {
if (x & (1LL << j)) {
if (B[j + 1]) {
B[j + 1] = 5;
x += (1LL << j);
} else {
B[j + 1] = 4;
x -= (1LL << j);
}
} else {
B[j + 1] += 6;
}
}
ans = "";
for (int j = 0; j < 35; j++) {
if (arms[0] == 0)
continue;
if (B[j] == 4) {
if (xc)
ans += 'L';
else
ans += 'R';
} else if (B[j] == 5) {
if (xc)
ans += 'R';
else
ans += 'L';
} else if (B[j] == 6) {
if (yc)
ans += 'D';
else
ans += 'U';
} else if (B[j] == 7) {
if (yc)
ans += 'U';
else
ans += 'D';
} else
ans += 'X';
}
F[i] = ans;
}
if (arms[0] == 0) {
cout << 34 << endl;
for (int i = 1; i < 35; i++) {
cout << arms[i];
if (i == 34)
cout << endl;
else
cout << " ";
}
for (int j = 0; j < N; j++) {
cout << F[j] << endl;
}
// VERIFY
for (int i = 0; i < N; i++) {
ans = F[i];
x = 0, y = 0;
for (int j = 0; j < 34; j++) {
if (ans[j] == 'L')
x -= arms[j + 1];
if (ans[j] == 'R')
x += arms[j + 1];
if (ans[j] == 'U')
y += arms[j + 1];
if (ans[j] == 'D')
y -= arms[j + 1];
}
if (x != dat[i][0] || y != dat[i][1]) {
cout << "WA" << endl;
cout << x << " " << y << endl;
assert(0);
}
}
} else {
cout << 35 << endl;
for (int i = 0; i < 35; i++) {
cout << arms[i];
if (i == 34)
cout << endl;
else
cout << " ";
}
for (int j = 0; j < N; j++) {
cout << F[j] << endl;
}
for (int i = 0; i < N; i++) {
ans = F[i];
x = 0, y = 0;
for (int j = 0; j < 35; j++) {
if (ans[j] == 'L')
x -= arms[j];
if (ans[j] == 'R')
x += arms[j];
if (ans[j] == 'U')
y += arms[j];
if (ans[j] == 'D')
y -= arms[j];
}
if (x != dat[i][0] || y != dat[i][1]) {
cout << x << " " << y << endl;
cout << "WA" << endl;
assert(0);
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(), V.end()
#define MOD 1000000007
ll dat[1010][3];
ll arms[41];
short B[41];
string F[1010];
int main() {
arms[0] = arms[1] = 1;
for (int i = 2; i < 35; i++) {
arms[i] = arms[i - 1] * 2;
}
ll S = (1LL << 34);
int N;
cin >> N;
ll x, y;
short z = 2;
for (int i = 0; i < N; i++) {
cin >> x >> y;
dat[i][0] = x;
dat[i][1] = y;
if ((x + y) & 1) {
if (z == 0)
z = 5;
if (z == 2)
z = 1;
} else {
if (z == 1)
z = 5;
if (z == 2)
z = 0;
}
}
if (z == 5) {
cout << -1 << endl;
return 0;
}
if (z == 1)
arms[0] = 0, S--;
bool xc, yc;
string ans;
for (int i = 0; i < N; i++) {
x = dat[i][0];
if (x < 0)
xc = 1, x = -x;
else
xc = 0;
y = dat[i][1];
if (y < 0)
yc = 1, y = -y;
else
yc = 0;
ll bt = (S - x - y) / 2;
int bc = 1;
B[0] = 6;
for (int j = 1; j < 35; j++) {
if (bt & 1)
B[j] = 1;
else
B[j] = 0;
bt /= 2;
}
for (int j = 0; j < 35; j++) {
if (x & (1LL << j)) {
if (B[j + 1]) {
B[j + 1] = 5;
x += (1LL << j);
} else {
B[j + 1] = 4;
x -= (1LL << j);
}
} else {
B[j + 1] += 6;
}
}
ans = "";
for (int j = 0; j < 35; j++) {
if (arms[j] == 0)
continue;
if (B[j] == 4) {
if (xc)
ans += 'L';
else
ans += 'R';
} else if (B[j] == 5) {
if (xc)
ans += 'R';
else
ans += 'L';
} else if (B[j] == 6) {
if (yc)
ans += 'D';
else
ans += 'U';
} else if (B[j] == 7) {
if (yc)
ans += 'U';
else
ans += 'D';
} else
ans += 'X';
}
F[i] = ans;
}
if (arms[0] == 0) {
cout << 34 << endl;
for (int i = 1; i < 35; i++) {
cout << arms[i];
if (i == 34)
cout << endl;
else
cout << " ";
}
for (int j = 0; j < N; j++) {
cout << F[j] << endl;
}
// VERIFY
for (int i = 0; i < N; i++) {
ans = F[i];
x = 0, y = 0;
for (int j = 0; j < 34; j++) {
if (ans[j] == 'L')
x -= arms[j + 1];
if (ans[j] == 'R')
x += arms[j + 1];
if (ans[j] == 'U')
y += arms[j + 1];
if (ans[j] == 'D')
y -= arms[j + 1];
}
if (x != dat[i][0] || y != dat[i][1]) {
cout << "WA" << endl;
cout << x << " " << y << endl;
assert(0);
}
}
} else {
cout << 35 << endl;
for (int i = 0; i < 35; i++) {
cout << arms[i];
if (i == 34)
cout << endl;
else
cout << " ";
}
for (int j = 0; j < N; j++) {
cout << F[j] << endl;
}
for (int i = 0; i < N; i++) {
ans = F[i];
x = 0, y = 0;
for (int j = 0; j < 35; j++) {
if (ans[j] == 'L')
x -= arms[j];
if (ans[j] == 'R')
x += arms[j];
if (ans[j] == 'U')
y += arms[j];
if (ans[j] == 'D')
y -= arms[j];
}
if (x != dat[i][0] || y != dat[i][1]) {
cout << x << " " << y << endl;
cout << "WA" << endl;
assert(0);
}
}
}
} | replace | 88 | 89 | 88 | 89 | -6 | d099d00f-f465-4af8-8561-db082d70bb0b.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03247/C++/s798615135.cpp:134: int main(): Assertion `0' failed.
|
p03247 | C++ | Runtime Error | #include <cmath>
#include <iostream>
using namespace std;
long long a[45], b[45];
int n, m, cnt;
long long x, y;
char s[45];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
if ((a[i] + b[i]) & 1)
cnt++;
else
cnt--;
}
if (abs(cnt) != n) {
cout << -1;
return 0;
}
m = 31 + (cnt < 0);
cout << m << endl;
for (int i = 0; i <= 30; i++) {
cout << (1 << i) << " ";
}
if (cnt < 0)
cout << 1;
cout << endl;
for (int i = 1; i <= n; i++) {
int x = a[i], y = b[i];
if (cnt < 0)
s[31] = 'R', x--;
int flag = 0;
for (int j = 30; j >= 0; j--) {
if (abs(x) < abs(y))
swap(x, y), flag ^= 1;
if (x > 0)
x -= (1 << j), s[j] = flag ? 'U' : 'R';
else
x += (1 << j), s[j] = flag ? 'D' : 'L';
}
cout << s << endl;
}
} | #include <cmath>
#include <iostream>
using namespace std;
long long a[1005], b[1005];
int n, m, cnt;
long long x, y;
char s[45];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
if ((a[i] + b[i]) & 1)
cnt++;
else
cnt--;
}
if (abs(cnt) != n) {
cout << -1;
return 0;
}
m = 31 + (cnt < 0);
cout << m << endl;
for (int i = 0; i <= 30; i++) {
cout << (1 << i) << " ";
}
if (cnt < 0)
cout << 1;
cout << endl;
for (int i = 1; i <= n; i++) {
int x = a[i], y = b[i];
if (cnt < 0)
s[31] = 'R', x--;
int flag = 0;
for (int j = 30; j >= 0; j--) {
if (abs(x) < abs(y))
swap(x, y), flag ^= 1;
if (x > 0)
x -= (1 << j), s[j] = flag ? 'U' : 'R';
else
x += (1 << j), s[j] = flag ? 'D' : 'L';
}
cout << s << endl;
}
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03247 | C++ | Runtime Error | #include <cassert>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
LL Abs(LL x) { return x < 0 ? -x : x; }
int n, m;
int d[40];
int x[1005], y[1005];
bool judge(LL x, LL y, int t) { return Abs(x) + Abs(y) < d[t + 1]; }
void print(LL x, LL y, int step) {
if (step == -1) {
return;
}
if (judge(x + d[step], y, step - 1)) {
print(x + d[step], y, step - 1);
printf("L");
return;
}
if (judge(x - d[step], y, step - 1)) {
print(x - d[step], y, step - 1);
printf("R");
return;
}
if (judge(x, y + d[step], step - 1)) {
print(x, y + d[step], step - 1);
printf("D");
return;
}
if (judge(x, y - d[step], step - 1)) {
print(x, y - d[step], step - 1);
printf("U");
return;
}
assert(0);
}
bool solve() {
int r = (x[1] + y[1]) & 1;
for (int i = 2; i <= n; ++i) {
if (((x[i] + y[i]) & 1) != r) {
return false;
}
}
m = 3;
d[0] = 1;
for (int i = 1; i < m; ++i) {
d[i] = d[i - 1] << 1;
}
d[m] = 1;
if (r == 1) {
printf("%d\n", m);
for (int i = 0; i < m; ++i) {
if (i)
printf(" ");
printf("%d", d[i]);
}
printf("\n");
} else {
printf("%d\n", m + 1);
printf("1");
for (int i = 0; i < m; ++i) {
printf(" %d", d[i]);
}
printf("\n");
for (int i = 1; i <= n; ++i) {
++x[i];
}
}
for (int i = 1; i <= n; ++i) {
if (r == 0) {
printf("L");
}
print(x[i], y[i], m - 1);
printf("\n");
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
if (!solve()) {
printf("-1\n");
}
return 0;
} | #include <cassert>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long LL;
LL Abs(LL x) { return x < 0 ? -x : x; }
int n, m;
int d[40];
int x[1005], y[1005];
bool judge(LL x, LL y, int t) { return Abs(x) + Abs(y) < d[t + 1]; }
void print(LL x, LL y, int step) {
if (step == -1) {
return;
}
if (judge(x + d[step], y, step - 1)) {
print(x + d[step], y, step - 1);
printf("L");
return;
}
if (judge(x - d[step], y, step - 1)) {
print(x - d[step], y, step - 1);
printf("R");
return;
}
if (judge(x, y + d[step], step - 1)) {
print(x, y + d[step], step - 1);
printf("D");
return;
}
if (judge(x, y - d[step], step - 1)) {
print(x, y - d[step], step - 1);
printf("U");
return;
}
assert(0);
}
bool solve() {
int r = (x[1] + y[1]) & 1;
for (int i = 2; i <= n; ++i) {
if (((x[i] + y[i]) & 1) != r) {
return false;
}
}
m = 31;
d[0] = 1;
for (int i = 1; i < m; ++i) {
d[i] = d[i - 1] << 1;
}
d[m] = 1;
if (r == 1) {
printf("%d\n", m);
for (int i = 0; i < m; ++i) {
if (i)
printf(" ");
printf("%d", d[i]);
}
printf("\n");
} else {
printf("%d\n", m + 1);
printf("1");
for (int i = 0; i < m; ++i) {
printf(" %d", d[i]);
}
printf("\n");
for (int i = 1; i <= n; ++i) {
++x[i];
}
}
for (int i = 1; i <= n; ++i) {
if (r == 0) {
printf("L");
}
print(x[i], y[i], m - 1);
printf("\n");
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &x[i], &y[i]);
}
if (!solve()) {
printf("-1\n");
}
return 0;
} | replace | 43 | 44 | 43 | 44 | 0 | |
p03247 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, x[1010], y[1010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", y + i, x + i);
int tag = !!((x[1] + y[1]) % 2);
for (int i = 1; i <= n; i++)
if (tag != !!((x[i] + y[i]) % 2))
return puts("-1"), 0;
int m = tag ? 31 : 30;
puts("31");
if (tag == 0)
printf("1 ");
for (int i = 0; i < m; i++)
printf("%lld ", 1ll << i);
puts("");
for (int i = 1; i <= n; i++) {
int dx = x[i], dy = y[i];
if (tag == 0)
dx--, putchar('U');
for (int i = 1; i < m; i++) {
assert((dx + dy) % 2);
long long tt = ((dx + dy) % 4 + 4) % 4;
if (dx % 2) {
if (tt == 3)
putchar('U'), dx--, dx /= 2, dy /= 2;
else
putchar('D'), dx++, dx /= 2, dy /= 2;
} else {
if (tt == 3)
putchar('R'), dy--, dx /= 2, dy /= 2;
else
putchar('L'), dy++, dx /= 2, dy /= 2;
}
// cerr << dx << ' ' << dy << endl;
}
assert(abs(dx) + abs(dy) == 1);
if (dx == 1)
puts("U");
else if (dx == -1)
puts("D");
else if (dy == 1)
puts("R");
else
puts("L");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, x[1010], y[1010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", y + i, x + i);
int tag = !!((x[1] + y[1]) % 2);
for (int i = 1; i <= n; i++)
if (tag != !!((x[i] + y[i]) % 2))
return puts("-1"), 0;
int m = tag ? 32 : 31;
puts("32");
if (tag == 0)
printf("1 ");
for (int i = 0; i < m; i++)
printf("%lld ", 1ll << i);
puts("");
for (int i = 1; i <= n; i++) {
int dx = x[i], dy = y[i];
if (tag == 0)
dx--, putchar('U');
for (int i = 1; i < m; i++) {
assert((dx + dy) % 2);
long long tt = ((dx + dy) % 4 + 4) % 4;
if (dx % 2) {
if (tt == 3)
putchar('U'), dx--, dx /= 2, dy /= 2;
else
putchar('D'), dx++, dx /= 2, dy /= 2;
} else {
if (tt == 3)
putchar('R'), dy--, dx /= 2, dy /= 2;
else
putchar('L'), dy++, dx /= 2, dy /= 2;
}
// cerr << dx << ' ' << dy << endl;
}
assert(abs(dx) + abs(dy) == 1);
if (dx == 1)
puts("U");
else if (dx == -1)
puts("D");
else if (dy == 1)
puts("R");
else
puts("L");
}
return 0;
} | replace | 11 | 13 | 11 | 13 | 0 | |
p03247 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;
int n, m;
int X[N], Y[N];
int d[N];
const int dx[5] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
const char dc[5] = {'R', 'L', 'U', 'D'};
void getp(ll x, ll y) {
for (int i = m; i; i--) {
int now = d[i];
for (int j = 0; j < 4; j++) {
ll curx = x + d[i] * dx[j], cury = y + d[i] * dy[j];
if (abs(curx) + abs(cury) < now) {
cout << dc[j];
x = curx, y = cury;
break;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
int sign = 1, mx = 0;
for (int i = 1; i <= n; i++)
cin >> X[i] >> Y[i];
for (int i = 2; i <= n; i++) {
if ((abs(X[i] + Y[i]) & 1) != (abs(X[i - 1] + Y[i - 1]) & 1))
sign = 0;
mx = max(mx, abs(X[i]) + abs(Y[i]));
}
if (!sign) {
cout << -1;
return 0;
}
for (d[m = 1] = 1; d[m] << 1 <= mx; ++m, d[m] = d[m - 1] << 1)
;
if (abs(X[1] + Y[1]) & 1)
sign = 0;
cout << m + sign << '\n';
if (sign)
cout << 1 << ' ';
for (int i = m; i; i--)
cout << d[i] << " \n"[i == 1];
for (int i = 1; i <= n; i++) {
if (sign)
cout << 'R';
getp(X[i] - sign, Y[i]);
cout << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;
int n, m;
int X[N], Y[N];
ll d[N];
const int dx[5] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
const char dc[5] = {'R', 'L', 'U', 'D'};
void getp(ll x, ll y) {
for (int i = m; i; i--) {
int now = d[i];
for (int j = 0; j < 4; j++) {
ll curx = x + d[i] * dx[j], cury = y + d[i] * dy[j];
if (abs(curx) + abs(cury) < now) {
cout << dc[j];
x = curx, y = cury;
break;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
int sign = 1, mx = 0;
for (int i = 1; i <= n; i++)
cin >> X[i] >> Y[i];
for (int i = 2; i <= n; i++) {
if ((abs(X[i] + Y[i]) & 1) != (abs(X[i - 1] + Y[i - 1]) & 1))
sign = 0;
mx = max(mx, abs(X[i]) + abs(Y[i]));
}
if (!sign) {
cout << -1;
return 0;
}
for (d[m = 1] = 1; d[m] << 1 <= mx; ++m, d[m] = d[m - 1] << 1)
;
if (abs(X[1] + Y[1]) & 1)
sign = 0;
cout << m + sign << '\n';
if (sign)
cout << 1 << ' ';
for (int i = m; i; i--)
cout << d[i] << " \n"[i == 1];
for (int i = 1; i <= n; i++) {
if (sign)
cout << 'R';
getp(X[i] - sign, Y[i]);
cout << '\n';
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03247 | C++ | Runtime Error | #define DEB
#include <bits/stdc++.h>
#define REP(i, m) for (int i = 0; i < (m); ++i)
#define REPN(i, m, in) for (int i = (in); i < (m); ++i)
#define ALL(t) (t).begin(), (t).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
using namespace std;
#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr << "called:" << __LINE__ << endl
#define dumpR(x) cerr << "\x1b[31m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpY(x) cerr << "\x1b[33m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpG(x) cerr << "\x1b[32m" << #x << " = " << (x) << "\x1b[39m" << endl
template <class T> void debug(T a, T b) {
for (; a != b; ++a)
cerr << *a << ' ';
cerr << endl;
}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template <class T> void debug(T a, T b) { ; }
#endif
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef long long int lint;
typedef pair<lint, lint> pi;
namespace std {
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.fr << ',' << a.sc << ')';
return out;
}
} // namespace std
// const int INF=5e8;
int n;
pi ps[1005];
void ng() {
puts("-1");
exit(0);
}
int main() {
cin >> n;
int cnt = 0;
REP(i, n) {
cin >> ps[i].fr >> ps[i].sc;
if ((abs(ps[i].fr) + abs(ps[i].sc)) % 2 !=
(abs(ps[0].fr) + abs(ps[0].sc)) % 2) {
ng();
}
}
vector<lint> d;
REP(i, 32) { d.pb(1ll << (i + 1)); }
lint tot = accumulate(ALL(d), 0ll);
bool type = false;
if ((abs(ps[0].fr) + abs(ps[0].sc)) % 2 == 0) {
d.pb(1);
d.pb(1);
} else {
d.pb(1);
type = true;
}
int m = d.size();
cout << d.size() << endl;
for (auto e : d)
cout << e << " ";
puts("");
REP(i, n) {
string res(m, ' ');
lint xx = ps[i].fr, yy = ps[i].sc;
if (abs(yy) & 1) {
if (abs(xx + yy - 1) % 4 != 0) {
--yy;
res[m - 1] = 'U';
} else {
++yy;
res[m - 1] = 'D';
}
}
if (abs(xx) & 1) {
if (abs(xx + yy - 1) % 4 != 0) {
--xx;
if (type)
res[m - 1] = 'R';
else
res[m - 2] = 'R';
} else {
++xx;
if (type)
res[m - 1] = 'L';
else
res[m - 2] = 'L';
}
}
if (!type && res[m - 1] == ' ') {
res[m - 1] = 'L';
res[m - 2] = 'R';
}
dump(xx);
dump(yy);
lint x = (xx + yy), y = (xx - yy);
x += tot;
y += tot;
assert(x % 4 == 0);
assert(y % 4 == 0);
dump(x);
dump(y);
int idx = 0;
for (auto e : d)
if (e != 1) {
int bit = 0;
if (x & (e * 2))
bit |= 2;
if (y & (e * 2))
bit |= 1;
string code = "LDUR";
res[idx] = code[bit];
++idx;
}
cout << res << endl;
}
return 0;
}
| #define DEB
#include <bits/stdc++.h>
#define REP(i, m) for (int i = 0; i < (m); ++i)
#define REPN(i, m, in) for (int i = (in); i < (m); ++i)
#define ALL(t) (t).begin(), (t).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
using namespace std;
#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr << "called:" << __LINE__ << endl
#define dumpR(x) cerr << "\x1b[31m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpY(x) cerr << "\x1b[33m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpG(x) cerr << "\x1b[32m" << #x << " = " << (x) << "\x1b[39m" << endl
template <class T> void debug(T a, T b) {
for (; a != b; ++a)
cerr << *a << ' ';
cerr << endl;
}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template <class T> void debug(T a, T b) { ; }
#endif
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef long long int lint;
typedef pair<lint, lint> pi;
namespace std {
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.fr << ',' << a.sc << ')';
return out;
}
} // namespace std
// const int INF=5e8;
int n;
pi ps[1005];
void ng() {
puts("-1");
exit(0);
}
int main() {
cin >> n;
int cnt = 0;
REP(i, n) {
cin >> ps[i].fr >> ps[i].sc;
if ((abs(ps[i].fr) + abs(ps[i].sc)) % 2 !=
(abs(ps[0].fr) + abs(ps[0].sc)) % 2) {
ng();
}
}
vector<lint> d;
REP(i, 32) { d.pb(1ll << (i + 1)); }
lint tot = accumulate(ALL(d), 0ll);
bool type = false;
if ((abs(ps[0].fr) + abs(ps[0].sc)) % 2 == 0) {
d.pb(1);
d.pb(1);
} else {
d.pb(1);
type = true;
}
int m = d.size();
cout << d.size() << endl;
for (auto e : d)
cout << e << " ";
puts("");
REP(i, n) {
string res(m, ' ');
lint xx = ps[i].fr, yy = ps[i].sc;
if (abs(yy) & 1) {
if (abs(xx + yy - 1) % 4 != 0) {
--yy;
res[m - 1] = 'U';
} else {
++yy;
res[m - 1] = 'D';
}
}
if (abs(xx) & 1) {
if (abs(xx + yy - 1) % 4 != 0) {
--xx;
if (type)
res[m - 1] = 'R';
else
res[m - 2] = 'R';
} else {
++xx;
if (type)
res[m - 1] = 'L';
else
res[m - 2] = 'L';
}
}
if (!type && res[m - 1] == ' ') {
if (abs(xx + yy) % 4 != 0) {
res[m - 1] = 'L';
res[m - 2] = 'R';
} else {
res[m - 1] = res[m - 2] = 'L';
xx += 2;
}
}
dump(xx);
dump(yy);
lint x = (xx + yy), y = (xx - yy);
x += tot;
y += tot;
assert(x % 4 == 0);
assert(y % 4 == 0);
dump(x);
dump(y);
int idx = 0;
for (auto e : d)
if (e != 1) {
int bit = 0;
if (x & (e * 2))
bit |= 2;
if (y & (e * 2))
bit |= 1;
string code = "LDUR";
res[idx] = code[bit];
++idx;
}
cout << res << endl;
}
return 0;
}
| replace | 123 | 125 | 123 | 130 | 0 | xx = -2
yy = 0
x = 8589934588
y = 8589934588
xx = 0
yy = 2
x = 8589934592
y = 8589934588
xx = 2
yy = 0
x = 8589934592
y = 8589934592
|
p03247 | C++ | Runtime Error | //
// Created by Ильдар Ялалов on 28.10.2019.
//
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout \
if (debug) \
cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(), a.end()
bool debug = 0;
const int MAXN = 4e5 + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (1e7 + 100) * 1.5;
typedef long long li;
const li MOD = 1000000000949747713ll;
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
out << "( " << rhs.first << " , " << rhs.second << " )";
return out;
}
ll x[MAXN], y[MAXN];
ll dx[4] = {1, -1, 0, 0};
ll dy[4] = {0, 0, 1, -1};
char dc[4] = {'L', 'R', 'D', 'U'};
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x[i] >> y[i];
dout << x[i] << " " << y[i] << endl;
}
for (int i = 1; i <= n; ++i) {
if (((x[i] + y[i]) & 1) != ((x[1] + y[1]) & 1)) {
cout << -1;
return;
}
}
vector<int> vals;
if ((x[1] + y[1]) % 2 == 0) {
vals.pb(1);
}
for (int i = 0; i <= 30; ++i) {
vals.pb(1 << i);
}
reverse(all(vals));
vector<string> ans;
for (int i = 1; i <= n; ++i) {
ll x0 = x[i];
ll y0 = y[i];
ll x1, y1;
string cur;
for (int d : vals) {
char val;
for (int j = 0; j < 4; ++j) {
int x = x0 + dx[j] * d;
int y = y0 + dy[j] * d;
if (j == 0 || (abs(x) + abs(y)) <= abs(x1) + abs(y1)) {
x1 = x;
y1 = y;
val = dc[j];
}
}
dout << x1 << " " << y1 << endl;
x0 = x1;
y0 = y1;
cur.pb(val);
}
ans.pb(cur);
assert(x0 == 0 && y0 == 0);
}
cout << sz(vals) << "\n";
for (auto x : vals) {
cout << x << " ";
}
cout << "\n";
for (auto x : ans) {
cout << x << "\n";
}
}
signed main() {
#ifdef zxc
debug = 0;
freopen("../input.txt", "r", stdin);
// freopen("../output.txt", "w", stdout);
#else
#endif // zxc
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(20);
int t = 1;
while (t--)
solve();
if (debug)
cerr << endl << "time : " << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
} | //
// Created by Ильдар Ялалов on 28.10.2019.
//
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout \
if (debug) \
cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(), a.end()
bool debug = 0;
const int MAXN = 4e5 + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (1e7 + 100) * 1.5;
typedef long long li;
const li MOD = 1000000000949747713ll;
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
out << "( " << rhs.first << " , " << rhs.second << " )";
return out;
}
ll x[MAXN], y[MAXN];
ll dx[4] = {1, -1, 0, 0};
ll dy[4] = {0, 0, 1, -1};
char dc[4] = {'L', 'R', 'D', 'U'};
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> x[i] >> y[i];
dout << x[i] << " " << y[i] << endl;
}
for (int i = 1; i <= n; ++i) {
if (((x[i] + y[i]) & 1) != ((x[1] + y[1]) & 1)) {
cout << -1;
return;
}
}
vector<int> vals;
if ((x[1] + y[1]) % 2 == 0) {
vals.pb(1);
}
for (int i = 0; i <= 30; ++i) {
vals.pb(1 << i);
}
reverse(all(vals));
vector<string> ans;
for (int i = 1; i <= n; ++i) {
ll x0 = x[i];
ll y0 = y[i];
ll x1, y1;
string cur;
for (int d : vals) {
char val;
for (int j = 0; j < 4; ++j) {
ll x = x0 + dx[j] * d;
ll y = y0 + dy[j] * d;
if (j == 0 || (abs(x) + abs(y)) <= abs(x1) + abs(y1)) {
x1 = x;
y1 = y;
val = dc[j];
}
}
dout << x1 << " " << y1 << endl;
x0 = x1;
y0 = y1;
cur.pb(val);
}
ans.pb(cur);
assert(x0 == 0 && y0 == 0);
}
cout << sz(vals) << "\n";
for (auto x : vals) {
cout << x << " ";
}
cout << "\n";
for (auto x : ans) {
cout << x << "\n";
}
}
signed main() {
#ifdef zxc
debug = 0;
freopen("../input.txt", "r", stdin);
// freopen("../output.txt", "w", stdout);
#else
#endif // zxc
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(20);
int t = 1;
while (t--)
solve();
if (debug)
cerr << endl << "time : " << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
} | replace | 91 | 93 | 91 | 93 | 0 | |
p03247 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const int N = 55;
int n, x[N], y[N], d[N], m;
bool in[2];
int main() {
scanf("%d", &n);
fo(i, 1, n) {
scanf("%d%d", &x[i], &y[i]);
in[(x[i] + y[i]) & 1] = 1;
}
if (in[0] && in[1]) {
puts("-1");
return 0;
}
if (in[0])
d[++m] = 1;
fd(i, 30, 0) d[++m] = 1 << i;
printf("%d\n", m);
fo(i, 1, m) printf("%d ", d[i]);
puts("");
fo(i, 1, n) {
fo(j, 1, m) if (abs(x[i]) > abs(y[i])) {
if (x[i] > 0)
x[i] -= d[j], putchar('R');
else
x[i] += d[j], putchar('L');
}
else {
if (y[i] > 0)
y[i] -= d[j], putchar('U');
else
y[i] += d[j], putchar('D');
}
puts("");
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const int N = 1005;
int n, x[N], y[N], d[N], m;
bool in[2];
int main() {
scanf("%d", &n);
fo(i, 1, n) {
scanf("%d%d", &x[i], &y[i]);
in[(x[i] + y[i]) & 1] = 1;
}
if (in[0] && in[1]) {
puts("-1");
return 0;
}
if (in[0])
d[++m] = 1;
fd(i, 30, 0) d[++m] = 1 << i;
printf("%d\n", m);
fo(i, 1, m) printf("%d ", d[i]);
puts("");
fo(i, 1, n) {
fo(j, 1, m) if (abs(x[i]) > abs(y[i])) {
if (x[i] > 0)
x[i] -= d[j], putchar('R');
else
x[i] += d[j], putchar('L');
}
else {
if (y[i] > 0)
y[i] -= d[j], putchar('U');
else
y[i] += d[j], putchar('D');
}
puts("");
}
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03247 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool check(pair<ll, ll> a, int lim) {
return abs(a.first) + abs(a.second) <= lim;
}
int main() {
freopen("test.in", "r", stdin);
int n;
cin >> n;
vector<pair<int, int>> a(n);
int parity = -1;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
if (parity == -1)
parity = abs(x + y) % 2;
else {
if (parity != abs(x + y) % 2)
return cout << "-1\n", 0;
}
a[i] = {x, y};
}
int m = 31;
vector<int> d(m);
d[0] = 1;
for (int i = 1; i < m; ++i)
d[i] = 2 * d[i - 1];
if (parity == 0)
d.push_back(1), sort(d.begin(), d.end()), m++;
reverse(d.begin(), d.end());
cout << m << '\n';
for (int i = 0; i < m; ++i)
cout << d[i] << " ";
cout << '\n';
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int lim = d[j] - parity;
if (check(make_pair(a[i].first - d[j], a[i].second), lim))
cout << "R", a[i].first -= d[j];
else if (check(make_pair(a[i].first + d[j], a[i].second), lim))
cout << "L", a[i].first += d[j];
else if (check(make_pair(a[i].first, a[i].second - d[j]), lim))
cout << "U", a[i].second -= d[j];
else if (check(make_pair(a[i].first, a[i].second + d[j]), lim))
cout << "D", a[i].second += d[j];
else
cout << "?";
}
cout << '\n';
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool check(pair<ll, ll> a, int lim) {
return abs(a.first) + abs(a.second) <= lim;
}
int main() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
int parity = -1;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
if (parity == -1)
parity = abs(x + y) % 2;
else {
if (parity != abs(x + y) % 2)
return cout << "-1\n", 0;
}
a[i] = {x, y};
}
int m = 31;
vector<int> d(m);
d[0] = 1;
for (int i = 1; i < m; ++i)
d[i] = 2 * d[i - 1];
if (parity == 0)
d.push_back(1), sort(d.begin(), d.end()), m++;
reverse(d.begin(), d.end());
cout << m << '\n';
for (int i = 0; i < m; ++i)
cout << d[i] << " ";
cout << '\n';
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int lim = d[j] - parity;
if (check(make_pair(a[i].first - d[j], a[i].second), lim))
cout << "R", a[i].first -= d[j];
else if (check(make_pair(a[i].first + d[j], a[i].second), lim))
cout << "L", a[i].first += d[j];
else if (check(make_pair(a[i].first, a[i].second - d[j]), lim))
cout << "U", a[i].second -= d[j];
else if (check(make_pair(a[i].first, a[i].second + d[j]), lim))
cout << "D", a[i].second += d[j];
else
cout << "?";
}
cout << '\n';
}
}
| delete | 10 | 11 | 10 | 10 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03248 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = (int)s.size();
// 1 indexed にする
s = "x" + s;
if (s[1] == '0') {
cout << -1 << endl;
return 0;
}
if (s[n] == '1') {
cout << -1 << endl;
return 0;
}
for (int i = 1; i < n / 2; i++) {
if (s[i] != s[n - i]) {
cout << -1 << endl;
return 0;
}
}
int a = 0;
int b = 1;
cout << b / a << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = (int)s.size();
// 1 indexed にする
s = "x" + s;
if (s[1] == '0') {
cout << -1 << endl;
return 0;
}
if (s[n] == '1') {
cout << -1 << endl;
return 0;
}
for (int i = 1; i < n / 2; i++) {
if (s[i] != s[n - i]) {
cout << -1 << endl;
return 0;
}
}
// この時点で構築可能
vector<pair<int, int>> ans;
int cur = 0;
for (int i = 1; i < n; i++) {
cout << cur + 1 << " " << i + 1 << endl;
if (s[i] == '1')
cur = i;
}
return 0;
} | replace | 27 | 30 | 27 | 36 | 0 | |
p03248 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
using namespace std;
typedef pair<int, int> P;
string s;
vector<P> ans;
int main() {
cin >> s;
int n = (int)s.size();
bool flg = true;
if (s[n - 1] != '0') {
flg = false;
}
if (s[0] == '0') {
flg = false;
}
REP(i, n / 2) {
if (s[i] != s[n - i - 2]) {
flg = false;
}
}
if (flg) {
ans.push_back(P(1, 2));
int v = 2;
if (n == 2) {
goto COR;
}
FOR(i, 1, (n - 1) / 2) {
if (s[i] == '0') {
ans.push_back(P(v, i + 2));
} else {
ans.push_back(P(v, i + 2));
v = i + 2;
}
}
if (n & 1) {
for (auto &ite : ans) {
int &f = ite.first, &s = ite.second;
if (f == v) {
f = n;
} else if (f > v) {
f--;
}
if (s == v) {
s = n;
} else if (s > v) {
s--;
}
}
REP(i, n / 2) {
P p = ans[i];
int f = p.first, s = p.second;
if (f < n) {
f = n - f;
}
if (s < n) {
s = n - s;
}
ans.push_back(P(f, s));
}
} else {
if (s[n / 2 - 1] == '1') {
for (auto ite : ans) {
ans.push_back(P(n + 1 - ite.first, n + 1 - ite.second));
}
ans.push_back(P(v, n + 1 - v));
} else {
for (auto &ite : ans) {
int &f = ite.first, &s = ite.second;
if (f == v) {
f = n / 2;
} else if (f > v) {
f--;
}
if (s == v) {
s = n / 2;
} else if (s > v) {
s--;
}
}
REP(i, n / 2 - 1) {
P p = ans[i];
int f = p.first, s = p.second;
if (f < n / 2) {
f = n - f;
}
if (s < n / 2) {
s = n - s;
}
ans.push_back(P(f, s));
}
ans.push_back(P(n / 2, n));
}
}
COR:
for (auto ite : ans) {
cout << ite.first << " " << ite.second << endl;
}
} else {
cout << -1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) FOR(i, 0, a)
using namespace std;
typedef pair<int, int> P;
string s;
vector<P> ans;
int main() {
cin >> s;
int n = (int)s.size();
bool flg = true;
if (s[n - 1] != '0') {
flg = false;
}
if (s[0] == '0') {
flg = false;
}
REP(i, n / 2) {
if (s[i] != s[n - i - 2]) {
flg = false;
}
}
if (flg) {
ans.push_back(P(1, 2));
int v = 2;
if (n == 2) {
goto COR;
}
FOR(i, 1, (n - 1) / 2) {
if (s[i] == '0') {
ans.push_back(P(v, i + 2));
} else {
ans.push_back(P(v, i + 2));
v = i + 2;
}
}
if (n & 1) {
for (auto &ite : ans) {
int &f = ite.first, &s = ite.second;
if (f == v) {
f = n;
} else if (f > v) {
f--;
}
if (s == v) {
s = n;
} else if (s > v) {
s--;
}
}
REP(i, n / 2) {
P p = ans[i];
int f = p.first, s = p.second;
if (f < n) {
f = n - f;
}
if (s < n) {
s = n - s;
}
ans.push_back(P(f, s));
}
} else {
if (s[n / 2 - 1] == '1') {
REP(i, n / 2 - 1) {
P p = ans[i];
ans.push_back(P(n + 1 - p.first, n + 1 - p.second));
}
ans.push_back(P(v, n + 1 - v));
} else {
for (auto &ite : ans) {
int &f = ite.first, &s = ite.second;
if (f == v) {
f = n / 2;
} else if (f > v) {
f--;
}
if (s == v) {
s = n / 2;
} else if (s > v) {
s--;
}
}
REP(i, n / 2 - 1) {
P p = ans[i];
int f = p.first, s = p.second;
if (f < n / 2) {
f = n - f;
}
if (s < n / 2) {
s = n - s;
}
ans.push_back(P(f, s));
}
ans.push_back(P(n / 2, n));
}
}
COR:
for (auto ite : ans) {
cout << ite.first << " " << ite.second << endl;
}
} else {
cout << -1 << endl;
}
return 0;
} | replace | 66 | 68 | 66 | 69 | 0 | |
p03248 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
// #define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
cerr << endl;
rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
cerr << "INF";
} else
cerr << v[i][j];
cerr << (j == v[i].size() - 1 ? '\n' : ' ');
}
cerr << endl;
}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 parse(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
string s;
cin >> s;
int n = s.size();
dump(n);
vector<int> v;
string t = s.substr(0, n - 1);
string t2(t);
reverse(all(t2));
if (t != t2 or s[0] == '0' or s[n - 1] == '1' or s[n - 2] == '0') {
cout << -1 << endl;
return 0;
}
if (n <= 4) {
if (n >= 2) {
cout << 1 << " " << 2 << endl;
}
if (n >= 3) {
cout << 2 << " " << 3 << endl;
}
if (n >= 4) {
if (s[1] == '0') {
cout << 2 << " " << 4 << endl;
} else {
cout << 3 << " " << 4 << endl;
}
}
return 0;
}
rep(i, 1, n - 2) {
if (s[i] == '1' and i < (n + 1) / 2)
v.eb(i + 1);
}
v.eb(n - v.back());
dump(v);
rrep(i, 1, v.size() - 1) { v[i] -= v[i - 1]; }
dump(v);
int a = 1;
vector<int> w;
rep(i, 0, v.size()) {
int x = a++;
loop(v[i] - 1) {
int y = a++;
cout << x << " " << y << endl;
}
if (i > 0) {
cout << x << " " << w.back() << endl;
}
w.eb(x);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
// #define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
cerr << endl;
rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
cerr << "INF";
} else
cerr << v[i][j];
cerr << (j == v[i].size() - 1 ? '\n' : ' ');
}
cerr << endl;
}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 parse(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
string s;
cin >> s;
int n = s.size();
dump(n);
vector<int> v;
string t = s.substr(0, n - 1);
string t2(t);
reverse(all(t2));
if (t != t2 or s[0] == '0' or s[n - 1] == '1' or s[n - 2] == '0') {
cout << -1 << endl;
return 0;
}
if (n <= 4) {
if (n >= 2) {
cout << 1 << " " << 2 << endl;
}
if (n >= 3) {
cout << 2 << " " << 3 << endl;
}
if (n >= 4) {
if (s[1] == '0') {
cout << 2 << " " << 4 << endl;
} else {
cout << 3 << " " << 4 << endl;
}
}
return 0;
}
rep(i, 1, n - 2) {
if (s[i] == '1' and i < (n + 1) / 2)
v.eb(i + 1);
}
if (v.empty())
v.eb(1);
v.eb(n - v.back());
dump(v);
rrep(i, 1, v.size() - 1) { v[i] -= v[i - 1]; }
dump(v);
int a = 1;
vector<int> w;
rep(i, 0, v.size()) {
int x = a++;
loop(v[i] - 1) {
int y = a++;
cout << x << " " << y << endl;
}
if (i > 0) {
cout << x << " " << w.back() << endl;
}
w.eb(x);
}
return 0;
}
| insert | 134 | 134 | 134 | 136 | 0 | |
p03248 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
for (int i = 1; i < s.length() - 1; i++)
if (s[0] == '0' || s[s.length() - 1] == '1' ||
s[i] != s[s.length() - i - 2]) {
cout << -1;
return 1;
}
cout << 1 << " " << 2 << endl;
int last = 1;
for (int i = 1; i <= s.length() - 2; i++) {
cout << last << " " << i + 2 << endl;
if (s[i] == '1')
last = i + 2;
}
}
| #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
for (int i = 1; i < s.length() - 1; i++)
if (s[0] == '0' || s[s.length() - 1] == '1' ||
s[i] != s[s.length() - i - 2]) {
cout << -1;
return 0;
}
cout << 1 << " " << 2 << endl;
int last = 1;
for (int i = 1; i <= s.length() - 2; i++) {
cout << last << " " << i + 2 << endl;
if (s[i] == '1')
last = i + 2;
}
}
| replace | 15 | 16 | 15 | 16 | 1 | |
p03248 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, s_rev;
int n, j;
cin >> s;
n = s.length();
if (s[n - 1] == '1') {
cout << "-1";
return 0;
}
s.erase(n - 1);
reverse(s.begin(), s.end());
s_rev = s;
reverse(s.begin(), s.end());
if (s != s_rev) {
cout << "-1";
return 0;
}
for (int i = 0; i < n - 1; i++) {
if (s[i] == '1') {
cout << i + 1 << ' ' << i + 2 << '\n';
} else {
j = i;
cout << i + 1 << ' ' << i + 2 << '\n';
while (s[j] != '1') {
cout << i + 1 << ' ' << j + 3 << '\n';
j++;
}
i = j;
}
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, s_rev;
int n, j;
cin >> s;
n = s.length();
if (s[n - 1] == '1' || s[0] == '0') {
cout << "-1";
return 0;
}
s.erase(n - 1);
reverse(s.begin(), s.end());
s_rev = s;
reverse(s.begin(), s.end());
if (s != s_rev) {
cout << "-1";
return 0;
}
for (int i = 0; i < n - 1; i++) {
if (s[i] == '1') {
cout << i + 1 << ' ' << i + 2 << '\n';
} else {
j = i;
cout << i + 1 << ' ' << i + 2 << '\n';
while (s[j] != '1') {
cout << i + 1 << ' ' << j + 3 << '\n';
j++;
}
i = j;
}
}
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03248 | C++ | Runtime Error | #define pnode node *
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<ll, ll, hash<ll>> ht;
void bad() {
cout << -1 << "\n";
exit(0);
}
ll n;
string s;
vector<ll> a;
void solve() {
cin >> s;
n = s.size();
a.resize(n + 1);
for (ll i = 1; i <= n; ++i) {
a[i] = s[i - 1] - '0';
}
if (!a[1] || a[n])
bad();
for (ll i = 1; i <= n; ++i) {
if (a[i] != a[n - i])
bad();
}
vector<pair<ll, ll>> b;
ll curid = 1;
ll prvver = 0;
ll prv = 1;
for (ll i = 2; i < n; ++i) {
if (a[i] == 0)
continue;
ll cid = curid;
b.push_back({curid, prvver});
for (ll j = curid + 1; j < curid + (i - prv); ++j) {
b.push_back({curid, j});
}
prvver = curid;
curid = curid + (i - prv);
}
if (curid != n) {
b.push_back({curid, prvver});
for (ll i = curid + 1; i < n; ++i) {
b.push_back({curid, i});
}
}
for (auto i : b) {
cout << i.first + 1 << " " << i.second + 1 << "\n";
}
}
signed main() {
int t = 1;
srand(time(0));
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// cin >> t
while (t--) {
solve();
}
}
| #define pnode node *
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<ll, ll, hash<ll>> ht;
void bad() {
cout << -1 << "\n";
exit(0);
}
ll n;
string s;
vector<ll> a;
void solve() {
cin >> s;
n = s.size();
a.resize(n + 1);
for (ll i = 1; i <= n; ++i) {
a[i] = s[i - 1] - '0';
}
if (!a[1] || a[n])
bad();
for (ll i = 1; i <= n; ++i) {
if (a[i] != a[n - i])
bad();
}
vector<pair<ll, ll>> b;
ll curid = 1;
ll prvver = 0;
ll prv = 1;
for (ll i = 2; i < n; ++i) {
if (a[i] == 0)
continue;
ll cid = curid;
b.push_back({curid, prvver});
for (ll j = curid + 1; j < curid + (i - prv); ++j) {
b.push_back({curid, j});
}
prvver = curid;
curid = curid + (i - prv);
prv = i;
}
if (curid != n) {
b.push_back({curid, prvver});
for (ll i = curid + 1; i < n; ++i) {
b.push_back({curid, i});
}
}
for (auto i : b) {
cout << i.first + 1 << " " << i.second + 1 << "\n";
}
}
signed main() {
int t = 1;
srand(time(0));
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// cin >> t
while (t--) {
solve();
}
}
| insert | 43 | 43 | 43 | 44 | 0 | |
p03248 | C++ | Time Limit Exceeded | #include <cstdio>
#include <cstring>
#include <set>
using std::set;
int u[101000], v[101000], tot = 0;
char c[101000];
set<int> st;
void dfs(int x, int siz) {
int rt = x;
siz--;
x++;
while (1) {
set<int>::iterator it = st.lower_bound(siz);
if (it == st.begin() && (*it) != siz)
break;
if ((*it) != siz)
--it;
u[++tot] = rt;
v[tot] = x;
int new_rt = x;
x += (*it);
siz -= (*it);
st.erase(it);
dfs(new_rt, (*it));
}
while (siz)
u[++tot] = rt, v[tot] = x, x++, siz--;
}
int main() {
scanf("%s", c + 1);
int n = strlen(c + 1);
for (int i = 1; i <= (n >> 1); i++) {
if (c[i] != c[n - i])
return 0 * puts("-1");
}
if (c[1] != '1' || c[n] == '1')
return 0 * puts("-1");
for (int i = 2; i <= (n >> 1); i++)
if (c[i] == '1')
st.insert(i);
dfs(1, n);
if (st.size() != 0)
return 0 * puts("-1");
for (int i = 1; i < n; i++)
printf("%d %d\n", u[i], v[i]);
return 0;
} | #include <cstdio>
#include <cstring>
#include <set>
using std::set;
int u[101000], v[101000], tot = 0;
char c[101000];
set<int> st;
void dfs(int x, int siz) {
int rt = x;
siz--;
x++;
while (1) {
set<int>::iterator it = st.lower_bound(siz);
if (st.size() == 0 || (it == st.begin() && (*it) != siz))
break;
if ((*it) != siz)
--it;
u[++tot] = rt;
v[tot] = x;
int new_rt = x;
x += (*it);
siz -= (*it);
st.erase(it);
dfs(new_rt, (*it));
}
while (siz)
u[++tot] = rt, v[tot] = x, x++, siz--;
}
int main() {
scanf("%s", c + 1);
int n = strlen(c + 1);
for (int i = 1; i <= (n >> 1); i++) {
if (c[i] != c[n - i])
return 0 * puts("-1");
}
if (c[1] != '1' || c[n] == '1')
return 0 * puts("-1");
for (int i = 2; i <= (n >> 1); i++)
if (c[i] == '1')
st.insert(i);
dfs(1, n);
if (st.size() != 0)
return 0 * puts("-1");
for (int i = 1; i < n; i++)
printf("%d %d\n", u[i], v[i]);
return 0;
} | replace | 16 | 17 | 16 | 17 | TLE | |
p03248 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
namespace {
using Integer = long long; //__int128;
template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) {
return is >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &val : vec)
is >> val;
return is;
}
template <class T> istream &operator,(istream &is, T &val) { return is >> val; }
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
return os << p.first << " " << p.second;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i == vec.size() - 1 ? "" : " ");
return os;
}
template <class T> ostream &operator,(ostream &os, const T &val) {
return os << " " << val;
}
template <class H> void print(const H &head) { cout << head; }
template <class H, class... T> void print(const H &head, const T &...tail) {
cout << head << " ";
print(tail...);
}
template <class... T> void println(const T &...values) {
print(values...);
cout << endl;
}
template <class H> void eprint(const H &head) { cerr << head; }
template <class H, class... T> void eprint(const H &head, const T &...tail) {
cerr << head << " ";
eprint(tail...);
}
template <class... T> void eprintln(const T &...values) {
eprint(values...);
cerr << endl;
}
class range {
Integer start_, end_, step_;
public:
struct range_iterator {
Integer val, step_;
range_iterator(Integer v, Integer step) : val(v), step_(step) {}
Integer operator*() { return val; }
void operator++() { val += step_; }
bool operator!=(range_iterator &x) {
return step_ > 0 ? val < x.val : val > x.val;
}
};
range(Integer len) : start_(0), end_(len), step_(1) {}
range(Integer start, Integer end) : start_(start), end_(end), step_(1) {}
range(Integer start, Integer end, Integer step)
: start_(start), end_(end), step_(step) {}
range_iterator begin() { return range_iterator(start_, step_); }
range_iterator end() { return range_iterator(end_, step_); }
};
inline string operator"" _s(const char *str, size_t size) {
return move(string(str));
}
constexpr Integer my_pow(Integer x, Integer k, Integer z = 1) {
return k == 0 ? z
: k == 1 ? z * x
: (k & 1) ? my_pow(x * x, k >> 1, z * x)
: my_pow(x * x, k >> 1, z);
}
constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z = 1) {
return k == 0 ? z % M
: k == 1 ? z * x % M
: (k & 1) ? my_pow_mod(x * x % M, k >> 1, M, z * x % M)
: my_pow_mod(x * x % M, k >> 1, M, z);
}
constexpr unsigned long long operator"" _ten(unsigned long long value) {
return my_pow(10, value);
}
inline int k_bit(Integer x, int k) { return (x >> k) & 1; } // 0-indexed
mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count());
template <class T> string join(const vector<T> &v, const string &sep) {
stringstream ss;
for (size_t i = 0; i < v.size(); i++) {
if (i > 0)
ss << sep;
ss << v[i];
}
return ss.str();
}
inline string operator*(string s, int k) {
string ret;
while (k) {
if (k & 1)
ret += s;
s += s;
k >>= 1;
}
return ret;
}
} // namespace
constexpr long long mod = 9_ten + 7;
int main() {
string s;
cin >> s;
if (s == "10") {
println(1, 2);
return 0;
}
int n = s.size();
if (s.back() == '1') {
println(-1);
return 0;
}
if (s.front() == '0') {
println(-1);
return 0;
}
for (int i = 0; i < n - 1; i++) {
if (s[i] != s[n - 1 - i - 1]) {
println(-1);
return 0;
}
}
if (s[n / 2 - 1] == '1') {
vector<pair<int, int>> res;
int u = n / 2 - 1;
int v = n / 2 - 2;
res.emplace_back(u, v);
for (int i = n / 2 - 2; i > 0; i--) {
if (s[i] == '1') {
res.emplace_back(v, i - 1);
u = v;
v = i - 1;
} else {
res.emplace_back(u, i - 1);
}
}
for (int i = 0, j = res.size(); i < j; i++) {
res.emplace_back(res[i].first + n / 2, res[i].second + n / 2);
}
res.emplace_back(n / 2 - 1, n / 2 - 1 + n / 2);
if (n % 2 == 1) {
res.emplace_back(n / 2 - 1, n - 1);
}
assert(res.size() == n - 1);
eprintln(res.size());
for (int i = 0; i < res.size(); i++) {
println(res[i].first + 1, res[i].second + 1);
}
} else {
vector<pair<int, int>> res;
int u0 = 0, u1 = 0;
int v0 = 1, v1 = 2;
int w = 3;
res.emplace_back(u0, v0);
res.emplace_back(u1, v1);
if (n % 2 == 0) {
res.emplace_back(u0, w++);
}
for (int i = (n - 1) / 2 - 1; i > 0; i--) {
if (s[i] == '0') {
res.emplace_back(u0, w++);
res.emplace_back(u1, w++);
} else {
res.emplace_back(v0, w++);
u0 = v0;
v0 = w - 1;
res.emplace_back(v1, w++);
u1 = v1;
v1 = w - 1;
}
}
assert(res.size() == n - 1);
eprintln(res.size());
for (int i = 0; i < res.size(); i++) {
println(res[i].first + 1, res[i].second + 1);
}
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
namespace {
using Integer = long long; //__int128;
template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) {
return is >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &val : vec)
is >> val;
return is;
}
template <class T> istream &operator,(istream &is, T &val) { return is >> val; }
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
return os << p.first << " " << p.second;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i == vec.size() - 1 ? "" : " ");
return os;
}
template <class T> ostream &operator,(ostream &os, const T &val) {
return os << " " << val;
}
template <class H> void print(const H &head) { cout << head; }
template <class H, class... T> void print(const H &head, const T &...tail) {
cout << head << " ";
print(tail...);
}
template <class... T> void println(const T &...values) {
print(values...);
cout << endl;
}
template <class H> void eprint(const H &head) { cerr << head; }
template <class H, class... T> void eprint(const H &head, const T &...tail) {
cerr << head << " ";
eprint(tail...);
}
template <class... T> void eprintln(const T &...values) {
eprint(values...);
cerr << endl;
}
class range {
Integer start_, end_, step_;
public:
struct range_iterator {
Integer val, step_;
range_iterator(Integer v, Integer step) : val(v), step_(step) {}
Integer operator*() { return val; }
void operator++() { val += step_; }
bool operator!=(range_iterator &x) {
return step_ > 0 ? val < x.val : val > x.val;
}
};
range(Integer len) : start_(0), end_(len), step_(1) {}
range(Integer start, Integer end) : start_(start), end_(end), step_(1) {}
range(Integer start, Integer end, Integer step)
: start_(start), end_(end), step_(step) {}
range_iterator begin() { return range_iterator(start_, step_); }
range_iterator end() { return range_iterator(end_, step_); }
};
inline string operator"" _s(const char *str, size_t size) {
return move(string(str));
}
constexpr Integer my_pow(Integer x, Integer k, Integer z = 1) {
return k == 0 ? z
: k == 1 ? z * x
: (k & 1) ? my_pow(x * x, k >> 1, z * x)
: my_pow(x * x, k >> 1, z);
}
constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z = 1) {
return k == 0 ? z % M
: k == 1 ? z * x % M
: (k & 1) ? my_pow_mod(x * x % M, k >> 1, M, z * x % M)
: my_pow_mod(x * x % M, k >> 1, M, z);
}
constexpr unsigned long long operator"" _ten(unsigned long long value) {
return my_pow(10, value);
}
inline int k_bit(Integer x, int k) { return (x >> k) & 1; } // 0-indexed
mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count());
template <class T> string join(const vector<T> &v, const string &sep) {
stringstream ss;
for (size_t i = 0; i < v.size(); i++) {
if (i > 0)
ss << sep;
ss << v[i];
}
return ss.str();
}
inline string operator*(string s, int k) {
string ret;
while (k) {
if (k & 1)
ret += s;
s += s;
k >>= 1;
}
return ret;
}
} // namespace
constexpr long long mod = 9_ten + 7;
int main() {
string s;
cin >> s;
if (s == "10") {
println(1, 2);
return 0;
}
if (s == "110") {
println(1, 2);
println(3, 2);
return 0;
}
int n = s.size();
if (s.back() == '1') {
println(-1);
return 0;
}
if (s.front() == '0') {
println(-1);
return 0;
}
for (int i = 0; i < n - 1; i++) {
if (s[i] != s[n - 1 - i - 1]) {
println(-1);
return 0;
}
}
if (s[n / 2 - 1] == '1') {
vector<pair<int, int>> res;
int u = n / 2 - 1;
int v = n / 2 - 2;
res.emplace_back(u, v);
for (int i = n / 2 - 2; i > 0; i--) {
if (s[i] == '1') {
res.emplace_back(v, i - 1);
u = v;
v = i - 1;
} else {
res.emplace_back(u, i - 1);
}
}
for (int i = 0, j = res.size(); i < j; i++) {
res.emplace_back(res[i].first + n / 2, res[i].second + n / 2);
}
res.emplace_back(n / 2 - 1, n / 2 - 1 + n / 2);
if (n % 2 == 1) {
res.emplace_back(n / 2 - 1, n - 1);
}
assert(res.size() == n - 1);
eprintln(res.size());
for (int i = 0; i < res.size(); i++) {
println(res[i].first + 1, res[i].second + 1);
}
} else {
vector<pair<int, int>> res;
int u0 = 0, u1 = 0;
int v0 = 1, v1 = 2;
int w = 3;
res.emplace_back(u0, v0);
res.emplace_back(u1, v1);
if (n % 2 == 0) {
res.emplace_back(u0, w++);
}
for (int i = (n - 1) / 2 - 1; i > 0; i--) {
if (s[i] == '0') {
res.emplace_back(u0, w++);
res.emplace_back(u1, w++);
} else {
res.emplace_back(v0, w++);
u0 = v0;
v0 = w - 1;
res.emplace_back(v1, w++);
u1 = v1;
v1 = w - 1;
}
}
assert(res.size() == n - 1);
eprintln(res.size());
for (int i = 0; i < res.size(); i++) {
println(res[i].first + 1, res[i].second + 1);
}
}
return 0;
}
| insert | 140 | 140 | 140 | 145 | 0 | |
p03248 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ctime>
#include <iostream>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)
bool check(vector<pair<int, int>> &branch) {
string s;
cin >> s;
int n = s.length();
int nodeindex = 0;
int lastparent = 0;
int lastnum = 0;
if (s[n - 1] == '1')
return false;
rep(i, n / 2) {
if (s[i] != s[n - 2 - i])
return false;
if (i == 0) {
if (s[i] != '1')
return false;
lastparent = nodeindex++;
lastnum = i;
} else {
if (s[i] == '1') {
branch.emplace_back(lastparent, nodeindex);
lastparent = nodeindex;
nodeindex++;
while (i > lastnum + 1) {
branch.emplace_back(lastparent, nodeindex++);
}
lastnum = i;
}
}
}
int tsize = nodeindex;
int t1top = lastparent;
int branchsize = branch.size();
int t2top = lastparent + tsize;
rep(j, branchsize) {
branch.emplace_back(branch[j].first + tsize, branch[j].second + tsize);
}
nodeindex += nodeindex;
branch.emplace_back(t1top, t2top);
while (nodeindex < n) {
branch.emplace_back(t2top, nodeindex++);
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<pair<int, int>> branch;
if (check(branch)) {
vecrep(itr, branch) {
cout << itr->first + 1 << " " << itr->second + 1 << endl;
}
} else {
cout << -1 << endl;
}
} | #include <bits/stdc++.h>
#include <ctime>
#include <iostream>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)
bool check(vector<pair<int, int>> &branch) {
string s;
cin >> s;
int n = s.length();
int nodeindex = 0;
int lastparent = 0;
int lastnum = 0;
if (s[n - 1] == '1')
return false;
rep(i, n / 2) {
if (s[i] != s[n - 2 - i])
return false;
if (i == 0) {
if (s[i] != '1')
return false;
lastparent = nodeindex++;
lastnum = i;
} else {
if (s[i] == '1') {
branch.emplace_back(lastparent, nodeindex);
lastparent = nodeindex;
nodeindex++;
while (i > lastnum + 1) {
branch.emplace_back(lastparent, nodeindex++);
lastnum++;
}
lastnum = i;
}
}
}
int tsize = nodeindex;
int t1top = lastparent;
int branchsize = branch.size();
int t2top = lastparent + tsize;
rep(j, branchsize) {
branch.emplace_back(branch[j].first + tsize, branch[j].second + tsize);
}
nodeindex += nodeindex;
branch.emplace_back(t1top, t2top);
while (nodeindex < n) {
branch.emplace_back(t2top, nodeindex++);
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<pair<int, int>> branch;
if (check(branch)) {
vecrep(itr, branch) {
cout << itr->first + 1 << " " << itr->second + 1 << endl;
}
} else {
cout << -1 << endl;
}
} | insert | 33 | 33 | 33 | 34 | TLE | |
p03248 | C++ | Runtime Error | // LightOj Pass : qavajxyq
#include <bits/stdc++.h>
#define deb(x) cerr << (#x) << " : " << x << "\n"
#define ll long long int
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll powmod(ll a, ll b, ll mod = MOD) {
ll res = 1ll;
b %= (mod - 1ll), a %= mod;
while (b) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
int cnt[100010];
bool comp(int a, int b) { return cnt[a] > cnt[b]; }
int main() {
#ifndef ONLINE_JUDGE
freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.length();
if (s.back() == '1' or s[0] == '0') {
cout << -1;
return 0;
}
bool state = true;
for (int l = 0, r = n - 2; r >= 0; r--, l++) {
if (s[l] != s[r]) {
state = false;
}
}
if (!state) {
cout << -1;
return 0;
}
int cur = 2, ptr = 2;
cout << 1 << " " << 2 << "\n";
for (int i = 1; i < n - 1; i++) {
cur++;
cout << ptr << " " << cur << "\n";
if ((s[i] - '0')) {
ptr = cur;
}
}
} | // LightOj Pass : qavajxyq
#include <bits/stdc++.h>
#define deb(x) cerr << (#x) << " : " << x << "\n"
#define ll long long int
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll powmod(ll a, ll b, ll mod = MOD) {
ll res = 1ll;
b %= (mod - 1ll), a %= mod;
while (b) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
int cnt[100010];
bool comp(int a, int b) { return cnt[a] > cnt[b]; }
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.length();
if (s.back() == '1' or s[0] == '0') {
cout << -1;
return 0;
}
bool state = true;
for (int l = 0, r = n - 2; r >= 0; r--, l++) {
if (s[l] != s[r]) {
state = false;
}
}
if (!state) {
cout << -1;
return 0;
}
int cur = 2, ptr = 2;
cout << 1 << " " << 2 << "\n";
for (int i = 1; i < n - 1; i++) {
cur++;
cout << ptr << " " << cur << "\n";
if ((s[i] - '0')) {
ptr = cur;
}
}
} | delete | 25 | 29 | 25 | 25 | 0 | |
p03248 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID (l + r) / 2
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define T double
typedef complex<T> pt;
#define x real()
#define y imag()
T dot(pt v, pt w) { return (conj(v) * w).x; }
T cross(pt v, pt w) { return (conj(v) * w).y; }
T orient(pt a, pt b, pt c) { return cross(b - a, c - a); }
T dist(pt a, pt b) { return abs(a - b); }
int main() {
string s;
cin >> s;
int n = s.size();
s = "0" + s;
bool ok = true;
vi one;
for (int i = 0; i <= n; i++) {
if (s[i] != s[n - i])
ok = false;
if (s[i] == '1')
one.push_back(i);
}
if (!ok) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i <= one.size(); i++)
cout << i << " " << i + 1 << endl;
int cnt = one.size() + 2;
for (int i = 1; i < one.size(); i++) {
for (int j = 1; j < one[i] - one[i - 1]; j++)
cout << i + 1 << " " << cnt++ << endl;
}
assert(cnt == n + 1);
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID (l + r) / 2
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define T double
typedef complex<T> pt;
#define x real()
#define y imag()
T dot(pt v, pt w) { return (conj(v) * w).x; }
T cross(pt v, pt w) { return (conj(v) * w).y; }
T orient(pt a, pt b, pt c) { return cross(b - a, c - a); }
T dist(pt a, pt b) { return abs(a - b); }
int main() {
string s;
cin >> s;
int n = s.size();
s = "0" + s;
bool ok = true;
vi one;
for (int i = 0; i <= n; i++) {
if (s[i] != s[n - i])
ok = false;
if (s[i] == '1')
one.push_back(i);
}
if (!ok || s[1] == '0') {
cout << -1 << endl;
return 0;
}
for (int i = 1; i <= one.size(); i++)
cout << i << " " << i + 1 << endl;
int cnt = one.size() + 2;
for (int i = 1; i < one.size(); i++) {
for (int j = 1; j < one[i] - one[i - 1]; j++)
cout << i + 1 << " " << cnt++ << endl;
}
assert(cnt == n + 1);
}
| replace | 43 | 44 | 43 | 44 | 0 | |
p03249 | C++ | Runtime Error | // LightOj Pass : qavajxyq
#include <bits/stdc++.h>
#define deb(x) cerr << (#x) << " : " << x << "\n"
#define ll long long int
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll powmod(ll a, ll b, ll mod = MOD) {
ll res = 1ll;
b %= (mod - 1ll), a %= mod;
while (b) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
ll d[300000];
ll n;
bool comp(int a, int b) { return d[a] < d[b]; }
vector<vector<int>> edges;
int cnt = 0;
ll res = 0;
ll tree[400000];
bool visited[4000000];
bool state = true;
void dfs(int u, int par = -1, ll dpth = 0) {
cnt++;
res += dpth;
tree[u] = 1;
visited[u] = true;
int tmp = 0;
for (auto v : edges[u]) {
if (!visited[v]) {
dfs(v, u, dpth + 1ll);
tree[u] += tree[v];
} else {
tmp++;
}
}
if (tmp > 1)
state = false;
}
void dfs2(int u, int par = -1, ll ans = res) {
if (ans != d[u])
state = false;
for (auto v : edges[u]) {
if (v != par)
dfs2(v, u, ans - tree[v] * 2 + n);
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
edges.resize(n + 1);
memset(visited, false, sizeof(visited));
int arr[n];
map<ll, int> mp;
ll sub[n + 1];
for (int i = 1; i <= n; i++)
cin >> d[i], arr[i - 1] = i, mp[d[i]] = i, sub[i] = 1;
sort(arr, arr + n, comp);
bool vis[n + 1];
memset(vis, false, sizeof(vis));
int cur, par;
int parent[n];
vector<pair<int, int>> edge;
for (int i = n - 1; i >= 0; i--) {
if (vis[arr[i]])
continue;
cur = arr[i];
deb(cur);
vis[cur] = true;
while (cur != 0) {
par = 0;
if (mp.count(d[cur] + (2 * sub[cur]) - n) and
!vis[mp[d[cur] + (2 * sub[cur]) - n]])
par = mp[d[cur] + (2 * sub[cur]) - n];
if (par)
sub[par] += sub[cur], edges[cur].push_back(par),
edges[par].push_back(cur), vis[cur] = true,
edge.push_back({cur, par});
cur = par;
deb(sub[par]);
deb(par);
}
}
dfs(arr[0]);
if (cnt != n or res != d[arr[0]] or !state) {
cout << -1;
return 0;
}
dfs2(arr[0]);
if (!state) {
cout << -1;
return 0;
}
for (auto x : edge)
cout << x.first << " " << x.second << "\n";
} | // LightOj Pass : qavajxyq
#include <bits/stdc++.h>
#define deb(x) cerr << (#x) << " : " << x << "\n"
#define ll long long int
#define ld long double
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll powmod(ll a, ll b, ll mod = MOD) {
ll res = 1ll;
b %= (mod - 1ll), a %= mod;
while (b) {
if (b % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
ll d[300000];
ll n;
bool comp(int a, int b) { return d[a] < d[b]; }
vector<vector<int>> edges;
int cnt = 0;
ll res = 0;
ll tree[400000];
bool visited[4000000];
bool state = true;
void dfs(int u, int par = -1, ll dpth = 0) {
cnt++;
res += dpth;
tree[u] = 1;
visited[u] = true;
int tmp = 0;
for (auto v : edges[u]) {
if (!visited[v]) {
dfs(v, u, dpth + 1ll);
tree[u] += tree[v];
} else {
tmp++;
}
}
if (tmp > 1)
state = false;
}
void dfs2(int u, int par = -1, ll ans = res) {
if (ans != d[u])
state = false;
for (auto v : edges[u]) {
if (v != par)
dfs2(v, u, ans - tree[v] * 2 + n);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
edges.resize(n + 1);
memset(visited, false, sizeof(visited));
int arr[n];
map<ll, int> mp;
ll sub[n + 1];
for (int i = 1; i <= n; i++)
cin >> d[i], arr[i - 1] = i, mp[d[i]] = i, sub[i] = 1;
sort(arr, arr + n, comp);
bool vis[n + 1];
memset(vis, false, sizeof(vis));
int cur, par;
int parent[n];
vector<pair<int, int>> edge;
for (int i = n - 1; i >= 0; i--) {
if (vis[arr[i]])
continue;
cur = arr[i];
deb(cur);
vis[cur] = true;
while (cur != 0) {
par = 0;
if (mp.count(d[cur] + (2 * sub[cur]) - n) and
!vis[mp[d[cur] + (2 * sub[cur]) - n]])
par = mp[d[cur] + (2 * sub[cur]) - n];
if (par)
sub[par] += sub[cur], edges[cur].push_back(par),
edges[par].push_back(cur), vis[cur] = true,
edge.push_back({cur, par});
cur = par;
deb(sub[par]);
deb(par);
}
}
dfs(arr[0]);
if (cnt != n or res != d[arr[0]] or !state) {
cout << -1;
return 0;
}
dfs2(arr[0]);
if (!state) {
cout << -1;
return 0;
}
for (auto x : edge)
cout << x.first << " " << x.second << "\n";
} | delete | 63 | 67 | 63 | 63 | 0 | |
p03249 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MN 100005
int T, num, dep[MN], n, id[MN], head[MN];
ll a[MN];
map<ll, int> rea, cnt;
struct node {
int x, y;
};
vector<node> sc;
struct edge {
int to, next;
} g[MN];
bool cmp(int x, int y) { return a[x] > a[y]; }
void ins(int u, int v) {
g[++num].next = head[u];
head[u] = num;
g[num].to = v;
}
void dfs(int u, int ff) {
for (int i = head[u]; i; i = g[i].next)
if (g[i].to != ff) {
dep[g[i].to] = dep[u] + 1, dfs(g[i].to, u);
}
}
int main() {
// freopen("test.in","r",stdin);
// freopen("mysol.out","w",stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), rea[a[i]] = i, cnt[a[i]] = 1, id[i] = i;
sort(id + 1, id + n + 1, cmp);
for (int i = 1; i < n; i++) {
int t = id[i];
ll tmp = a[t] - n + 2 * cnt[a[t]];
if (rea[tmp] && tmp < a[t]) {
cnt[tmp] += cnt[a[t]];
sc.push_back((node){t, rea[tmp]});
} else
return 0 * puts("-1");
}
for (int i = 0; i < sc.size(); i++)
ins(sc[i].x, sc[i].y), ins(sc[i].y, sc[i].x);
dfs(id[n], id[n]);
ll tans = 0;
for (int i = 1; i <= n; i++)
tans += dep[i];
if (tans != a[id[n]])
return 0 * puts("-1");
for (int i = 0; i < sc.size(); i++)
printf("%d %d\n", sc[i].x, sc[i].y);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MN 100005
int T, num, dep[MN], n, id[MN], head[MN];
ll a[MN];
map<ll, int> rea, cnt;
struct node {
int x, y;
};
vector<node> sc;
struct edge {
int to, next;
} g[MN << 1];
bool cmp(int x, int y) { return a[x] > a[y]; }
void ins(int u, int v) {
g[++num].next = head[u];
head[u] = num;
g[num].to = v;
}
void dfs(int u, int ff) {
for (int i = head[u]; i; i = g[i].next)
if (g[i].to != ff) {
dep[g[i].to] = dep[u] + 1, dfs(g[i].to, u);
}
}
int main() {
// freopen("test.in","r",stdin);
// freopen("mysol.out","w",stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), rea[a[i]] = i, cnt[a[i]] = 1, id[i] = i;
sort(id + 1, id + n + 1, cmp);
for (int i = 1; i < n; i++) {
int t = id[i];
ll tmp = a[t] - n + 2 * cnt[a[t]];
if (rea[tmp] && tmp < a[t]) {
cnt[tmp] += cnt[a[t]];
sc.push_back((node){t, rea[tmp]});
} else
return 0 * puts("-1");
}
for (int i = 0; i < sc.size(); i++)
ins(sc[i].x, sc[i].y), ins(sc[i].y, sc[i].x);
dfs(id[n], id[n]);
ll tans = 0;
for (int i = 1; i <= n; i++)
tans += dep[i];
if (tans != a[id[n]])
return 0 * puts("-1");
for (int i = 0; i < sc.size(); i++)
printf("%d %d\n", sc[i].x, sc[i].y);
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03249 | C++ | Runtime Error | #include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 100005;
template <class T> void read(T &x) {
int sgn = 1;
char ch;
x = 0;
for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-')
ch = getchar(), sgn = -1;
for (; '0' <= ch && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
x *= sgn;
}
template <class T> void write(T x) {
if (x < 0)
putchar('-'), write(-x);
else if (x < 10)
putchar(x + '0');
else
write(x / 10), putchar(x % 10 + '0');
}
int n, dep[N], sz[N];
bool flag = true;
struct node {
int id;
long long dist;
bool operator<(node rhs) const { return dist < rhs.dist; }
} vec[N];
long long d[N];
vector<pair<int, int>> tree;
int main() {
read(n);
for (int i = 1; i <= n; i++)
vec[i].id = i, read(vec[i].dist);
sort(vec + 1, vec + n + 1);
for (int i = 1; i <= n; i++)
d[i] = vec[i].dist, sz[i] = 1;
for (int i = n; i > 1; i--) {
int pos = lower_bound(d + 1, d + i, d[i] - (n - sz[i]) + sz[i]) - d;
if (pos >= i || d[pos] != d[i] - (n - sz[i]) + sz[i]) {
flag = false;
break;
}
tree.push_back(make_pair(vec[i].id, vec[pos].id));
sz[pos] += sz[i];
}
dep[vec[1].id] = 0;
for (int i = n - 2; i >= 0; i--)
dep[tree[i].first] = dep[tree[i].second] + 1;
for (int i = 1; i <= n; i++)
d[1] -= dep[i];
if (d[1])
flag = false;
if (!flag)
write(-1), putchar('\n');
else {
for (int i = 0; i < tree.size(); i++) {
write(tree[i].first), putchar(' ');
write(tree[i].second), putchar('\n');
}
}
return 0;
} | #include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 100005;
template <class T> void read(T &x) {
int sgn = 1;
char ch;
x = 0;
for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-')
ch = getchar(), sgn = -1;
for (; '0' <= ch && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
x *= sgn;
}
template <class T> void write(T x) {
if (x < 0)
putchar('-'), write(-x);
else if (x < 10)
putchar(x + '0');
else
write(x / 10), putchar(x % 10 + '0');
}
int n, dep[N], sz[N];
bool flag = true;
struct node {
int id;
long long dist;
bool operator<(node rhs) const { return dist < rhs.dist; }
} vec[N];
long long d[N];
vector<pair<int, int>> tree;
int main() {
read(n);
for (int i = 1; i <= n; i++)
vec[i].id = i, read(vec[i].dist);
sort(vec + 1, vec + n + 1);
for (int i = 1; i <= n; i++)
d[i] = vec[i].dist, sz[i] = 1;
for (int i = n; i > 1; i--) {
int pos = lower_bound(d + 1, d + i, d[i] - (n - sz[i]) + sz[i]) - d;
if (pos >= i || d[pos] != d[i] - (n - sz[i]) + sz[i]) {
flag = false;
break;
}
tree.push_back(make_pair(vec[i].id, vec[pos].id));
sz[pos] += sz[i];
}
if (flag) {
dep[vec[1].id] = 0;
for (int i = n - 2; i >= 0; i--)
dep[tree[i].first] = dep[tree[i].second] + 1;
for (int i = 1; i <= n; i++)
d[1] -= dep[i];
if (d[1])
flag = false;
}
if (!flag)
write(-1), putchar('\n');
else {
for (int i = 0; i < tree.size(); i++) {
write(tree[i].first), putchar(' ');
write(tree[i].second), putchar('\n');
}
}
return 0;
} | replace | 58 | 67 | 58 | 67 | 0 | |
p03249 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ln '\n'
#define all(dat) dat.begin(), dat.end()
#define loop(i, to) for (int i = 0; i < to; ++i)
#define cont(i, to) for (int i = 1; i <= to; ++i)
#define circ(i, fr, to) for (int i = fr; i <= to; ++i)
#define foreach(i, dat) \
for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
typedef long long num;
using namespace std;
const int nsz = 1e5;
int n, rt, siz[nsz + 5];
num w[nsz + 5];
map<num, int> id, to;
vector<int> g[nsz + 5];
vector<pair<int, int>> ans;
num inline cmp(num a, num b) { return a > b; }
num calc(int u = rt, int dep = 0) {
num res = dep;
for (int v : g[u]) {
res += calc(v, dep + 1);
}
return res;
}
int main() {
freopen("dat.in", "r", stdin);
ios_base::sync_with_stdio(0);
cin >> n;
rt = n;
cont(i, n) {
cin >> w[i];
to[w[i]] = i;
}
fill(siz, siz + sizeof(siz) / sizeof(int), 1);
sort(w + 1, w + n + 1, cmp);
cont(i, n) { id[w[i]] = i; }
cout << ln;
cont(u, n) {
if (u == rt)
continue;
int v = id[w[u] - n + 2 * siz[u]];
if (!v) {
cout << -1 << ln;
return 0;
}
siz[v] += siz[u];
g[v].push_back(u);
ans.push_back({to[w[u]], to[w[v]]});
}
if (calc() != w[n]) {
cout << -1 << ln;
return 0;
}
for (pair<int, int> p : ans) {
cout << p.first << ' ' << p.second << ln;
}
}
| #include <bits/stdc++.h>
#define ln '\n'
#define all(dat) dat.begin(), dat.end()
#define loop(i, to) for (int i = 0; i < to; ++i)
#define cont(i, to) for (int i = 1; i <= to; ++i)
#define circ(i, fr, to) for (int i = fr; i <= to; ++i)
#define foreach(i, dat) \
for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
typedef long long num;
using namespace std;
const int nsz = 1e5;
int n, rt, siz[nsz + 5];
num w[nsz + 5];
map<num, int> id, to;
vector<int> g[nsz + 5];
vector<pair<int, int>> ans;
num inline cmp(num a, num b) { return a > b; }
num calc(int u = rt, int dep = 0) {
num res = dep;
for (int v : g[u]) {
res += calc(v, dep + 1);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
rt = n;
cont(i, n) {
cin >> w[i];
to[w[i]] = i;
}
fill(siz, siz + sizeof(siz) / sizeof(int), 1);
sort(w + 1, w + n + 1, cmp);
cont(i, n) { id[w[i]] = i; }
cout << ln;
cont(u, n) {
if (u == rt)
continue;
int v = id[w[u] - n + 2 * siz[u]];
if (!v) {
cout << -1 << ln;
return 0;
}
siz[v] += siz[u];
g[v].push_back(u);
ans.push_back({to[w[u]], to[w[v]]});
}
if (calc() != w[n]) {
cout << -1 << ln;
return 0;
}
for (pair<int, int> p : ans) {
cout << p.first << ' ' << p.second << ln;
}
}
| delete | 32 | 33 | 32 | 32 | 0 | |
p03249 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
#define R register
#define ll long long
const int MAXN = 1e5 + 10;
int n;
ll D[MAXN];
int siz[MAXN];
map<ll, int> loc;
set<ll> st;
struct edge {
int fr, to, next;
} e[MAXN];
int tot;
int head[MAXN];
int dep[MAXN];
inline void add(int x, int y) {
tot++;
e[tot].fr = x;
e[tot].to = y;
e[tot].next = head[x];
head[x] = tot;
}
inline void dfs(int x, int fx) {
dep[x] = dep[fx] + 1;
for (R int i = head[x]; i; i = e[i].next) {
int y = e[i].to;
if (y == fx)
continue;
dfs(y, x);
}
}
int main() {
scanf("%d", &n);
for (R int i = 1; i <= n; i++) {
scanf("%lld", &D[i]);
siz[i] = 1;
loc[D[i]] = i;
st.insert(D[i]);
}
int rt = 0, cnt = 0;
while (st.size() && cnt < n - 1) {
ll dx = *st.rbegin(), dy;
int x, y;
st.erase(dx);
x = loc[dx];
dy = dx + siz[x] * 2 - n;
y = loc[dy];
if (y == 0) {
printf("-1\n");
return 0;
}
siz[y] += siz[x];
add(x, y);
add(y, x);
cnt++;
}
rt = loc[*st.begin()];
dfs(rt, 0);
ll ans = 0;
for (R int i = 1; i <= n; i++)
ans += dep[i];
if (ans - n != D[rt]) {
printf("-1\n");
return 0;
}
for (R int i = 1; i <= tot; i += 2) {
int x = e[i].fr, y = e[i].to;
if (x > y)
swap(x, y);
printf("%d %d\n", x, y);
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <map>
#include <set>
using namespace std;
#define R register
#define ll long long
const int MAXN = 1e5 + 10;
int n;
ll D[MAXN];
int siz[MAXN];
map<ll, int> loc;
set<ll> st;
struct edge {
int fr, to, next;
} e[MAXN << 1];
int tot;
int head[MAXN];
int dep[MAXN];
inline void add(int x, int y) {
tot++;
e[tot].fr = x;
e[tot].to = y;
e[tot].next = head[x];
head[x] = tot;
}
inline void dfs(int x, int fx) {
dep[x] = dep[fx] + 1;
for (R int i = head[x]; i; i = e[i].next) {
int y = e[i].to;
if (y == fx)
continue;
dfs(y, x);
}
}
int main() {
scanf("%d", &n);
for (R int i = 1; i <= n; i++) {
scanf("%lld", &D[i]);
siz[i] = 1;
loc[D[i]] = i;
st.insert(D[i]);
}
int rt = 0, cnt = 0;
while (st.size() && cnt < n - 1) {
ll dx = *st.rbegin(), dy;
int x, y;
st.erase(dx);
x = loc[dx];
dy = dx + siz[x] * 2 - n;
y = loc[dy];
if (y == 0) {
printf("-1\n");
return 0;
}
siz[y] += siz[x];
add(x, y);
add(y, x);
cnt++;
}
rt = loc[*st.begin()];
dfs(rt, 0);
ll ans = 0;
for (R int i = 1; i <= n; i++)
ans += dep[i];
if (ans - n != D[rt]) {
printf("-1\n");
return 0;
}
for (R int i = 1; i <= tot; i += 2) {
int x = e[i].fr, y = e[i].to;
if (x > y)
swap(x, y);
printf("%d %d\n", x, y);
}
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03249 | C++ | Runtime Error | #include <bits/stdc++.h>
using std::pair;
using std::string;
using std::vector;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
const int oo = 0x3f3f3f3f;
string procStatus() {
std::ifstream t("/proc/self/status");
return string(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>());
}
template <typename T> T read(T &x) {
int f = 1;
x = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
x = x * 10 + ch - 48;
return x *= f;
}
const int N = 100000;
struct node {
ll d;
int id;
bool operator<(const node &rhs) const { return d > rhs.d; }
};
int n;
node t[N + 5];
int fa[N + 5], sz[N + 5];
std::map<ll, int> mp;
int main() {
#ifdef Wearry
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
read(n);
for (int i = 1; i <= n; ++i) {
read(t[i].d), t[i].id = i;
}
std::sort(t + 1, t + n + 1);
for (int i = 1; i <= n; ++i)
mp[t[i].d] = i;
for (int i = 1; i < n; ++i) {
++sz[i];
fa[i] = mp[t[i].d - n + 2 * sz[i]];
if (!fa[i])
return !puts("-1");
sz[fa[i]] += sz[i];
t[n].d -= sz[i];
}
if (t[n].d)
return puts("-1");
for (int i = 1; i < n; ++i) {
printf("%d %d\n", t[i].id, t[fa[i]].id);
}
return 0;
}
| #include <bits/stdc++.h>
using std::pair;
using std::string;
using std::vector;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
template <typename T> bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
const int oo = 0x3f3f3f3f;
string procStatus() {
std::ifstream t("/proc/self/status");
return string(std::istreambuf_iterator<char>(t),
std::istreambuf_iterator<char>());
}
template <typename T> T read(T &x) {
int f = 1;
x = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
x = x * 10 + ch - 48;
return x *= f;
}
const int N = 100000;
struct node {
ll d;
int id;
bool operator<(const node &rhs) const { return d > rhs.d; }
};
int n;
node t[N + 5];
int fa[N + 5], sz[N + 5];
std::map<ll, int> mp;
int main() {
#ifdef Wearry
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
read(n);
for (int i = 1; i <= n; ++i) {
read(t[i].d), t[i].id = i;
}
std::sort(t + 1, t + n + 1);
for (int i = 1; i <= n; ++i)
mp[t[i].d] = i;
for (int i = 1; i < n; ++i) {
++sz[i];
fa[i] = mp[t[i].d - n + 2 * sz[i]];
if (!fa[i])
return !puts("-1");
sz[fa[i]] += sz[i];
t[n].d -= sz[i];
}
if (t[n].d)
return !puts("-1");
for (int i = 1; i < n; ++i) {
printf("%d %d\n", t[i].id, t[fa[i]].id);
}
return 0;
}
| replace | 77 | 78 | 77 | 78 | 0 | |
p03249 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const long long mo = 50000007;
const int maxn = 200010;
int n, m, d[maxn], id[maxn], fa[maxn];
long long siz[maxn], ans, js[maxn];
int tot, nex[maxn * 2], las[maxn * 2], tov[maxn * 2];
int hs[mo + 10];
void con(int x, int y) {
tot++;
tov[tot] = y;
nex[tot] = las[x];
las[x] = tot;
}
void insert(long long x, int id) {
long long i = x % mo;
while (hs[i] != 0) {
i++;
if (i == mo)
i = 0;
}
hs[i] = id;
}
long long find(long long x) {
long long i = x % mo;
while (hs[i] != 0 && d[hs[i]] != x) {
i++;
if (i == mo)
i = 0;
}
return hs[i];
}
void qsort(int l, int r) {
int i = l;
int j = r;
long long m = d[(i + j) / 2];
while (i <= j) {
while (d[i] > m)
i++;
while (d[j] < m)
j--;
if (i <= j) {
swap(d[i], d[j]);
swap(id[i], id[j]);
i++;
j--;
}
}
if (l < j)
qsort(l, j);
if (r > i)
qsort(i, r);
}
void dfs(int x, int ff) {
js[x] = js[ff] + 1;
for (int i = las[x]; i; i = nex[i]) {
if (tov[i] != ff) {
dfs(tov[i], x);
ans += js[x];
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &d[i]);
id[i] = i;
siz[i] = 1;
}
qsort(1, n);
for (int i = 1; i <= n; i++) {
insert(d[i], i);
}
for (int i = 1; i < n; i++) {
long long op = d[i] - abs(n - 2 * siz[i]);
long long oq = find(op);
if (oq == 0) {
printf("-1\n");
return 0;
} else {
fa[i] = oq;
siz[oq] += siz[i];
con(i, oq);
con(oq, i);
}
}
dfs(n, 0);
if (ans != d[n]) {
printf("-1\n");
return 0;
} else {
for (int i = 1; i < n; i++) {
printf("%d %d\n", id[i], id[fa[i]]);
}
}
} | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const long long mo = 50000007;
const int maxn = 200010;
int n, m, id[maxn], fa[maxn];
long long d[maxn], siz[maxn], ans, js[maxn];
int tot, nex[maxn * 2], las[maxn * 2], tov[maxn * 2];
int hs[mo + 10];
void con(int x, int y) {
tot++;
tov[tot] = y;
nex[tot] = las[x];
las[x] = tot;
}
void insert(long long x, int id) {
long long i = x % mo;
while (hs[i] != 0) {
i++;
if (i == mo)
i = 0;
}
hs[i] = id;
}
long long find(long long x) {
long long i = x % mo;
while (hs[i] != 0 && d[hs[i]] != x) {
i++;
if (i == mo)
i = 0;
}
return hs[i];
}
void qsort(int l, int r) {
int i = l;
int j = r;
long long m = d[(i + j) / 2];
while (i <= j) {
while (d[i] > m)
i++;
while (d[j] < m)
j--;
if (i <= j) {
swap(d[i], d[j]);
swap(id[i], id[j]);
i++;
j--;
}
}
if (l < j)
qsort(l, j);
if (r > i)
qsort(i, r);
}
void dfs(int x, int ff) {
js[x] = js[ff] + 1;
for (int i = las[x]; i; i = nex[i]) {
if (tov[i] != ff) {
dfs(tov[i], x);
ans += js[x];
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &d[i]);
id[i] = i;
siz[i] = 1;
}
qsort(1, n);
for (int i = 1; i <= n; i++) {
insert(d[i], i);
}
for (int i = 1; i < n; i++) {
long long op = d[i] - abs(n - 2 * siz[i]);
long long oq = find(op);
if (oq == 0) {
printf("-1\n");
return 0;
} else {
fa[i] = oq;
siz[oq] += siz[i];
con(i, oq);
con(oq, i);
}
}
dfs(n, 0);
if (ans != d[n]) {
printf("-1\n");
return 0;
} else {
for (int i = 1; i < n; i++) {
printf("%d %d\n", id[i], id[fa[i]]);
}
}
} | replace | 8 | 10 | 8 | 10 | -11 | |
p03249 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define all(c) begin(c), end(c)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
// ここから編集する
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> D(N);
map<ll, int> Dtov;
rep(i, 0, N) cin >> D[i];
rep(i, 0, N) Dtov[D[i]] = i + 1;
sort(D.rbegin(), D.rend());
vector<vector<int>> G(N + 1, vector<int>()); // 自分の親
vector<vector<int>> rG(N + 1, vector<int>()); // 自分の子供
vector<int> childs(N + 1, 1); // 部分木の数
for (int i = 0; i < N - 1; ++i) {
// ll dec = N - 2 * (1 + rG[Dtov[D[i]]].size());
ll dec = N - 2 * childs[Dtov[D[i]]];
if (find(all(D), D[i] - dec) == D.end()) {
cout << -1 << endl;
return 0;
}
G[Dtov[D[i]]].push_back(Dtov[D[i] - dec]);
rG[Dtov[D[i] - dec]].push_back(Dtov[D[i]]);
childs[Dtov[D[i] - dec]] += childs[Dtov[D[i]]];
}
function<ll(int, int)> treesize = [&](int v, int dist) {
ll ret = dist;
for (auto e : rG[v]) {
ret += treesize(e, dist + 1);
}
return ret;
};
ll min_tree_size = treesize(Dtov[D.back()], 0);
if (min_tree_size != D.back()) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i <= N; ++i) {
for (auto e : G[i]) {
cout << i << " " << e << endl;
}
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define all(c) begin(c), end(c)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
// ここから編集する
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> D(N);
map<ll, int> Dtov;
rep(i, 0, N) cin >> D[i];
rep(i, 0, N) Dtov[D[i]] = i + 1;
sort(D.rbegin(), D.rend());
vector<vector<int>> G(N + 1, vector<int>()); // 自分の親
vector<vector<int>> rG(N + 1, vector<int>()); // 自分の子供
vector<int> childs(N + 1, 1); // 部分木の数
for (int i = 0; i < N - 1; ++i) {
// ll dec = N - 2 * (1 + rG[Dtov[D[i]]].size());
ll dec = N - 2 * childs[Dtov[D[i]]];
// if (find(all(D), D[i] - dec) == D.end()) {
// cout << -1 << endl;
// return 0;
// }
if (*lower_bound(all(D), D[i] - dec) == D[i] - dec) {
cout << -1 << endl;
return 0;
}
G[Dtov[D[i]]].push_back(Dtov[D[i] - dec]);
rG[Dtov[D[i] - dec]].push_back(Dtov[D[i]]);
childs[Dtov[D[i] - dec]] += childs[Dtov[D[i]]];
}
function<ll(int, int)> treesize = [&](int v, int dist) {
ll ret = dist;
for (auto e : rG[v]) {
ret += treesize(e, dist + 1);
}
return ret;
};
ll min_tree_size = treesize(Dtov[D.back()], 0);
if (min_tree_size != D.back()) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i <= N; ++i) {
for (auto e : G[i]) {
cout << i << " " << e << endl;
}
}
return 0;
}
| replace | 78 | 79 | 78 | 84 | TLE | |
p03250 | Python | Runtime Error | a, b, c = map(int, input().split())
print(max(a, b, c) * 9 + sum(a, b, c))
| a, b, c = map(int, input().split())
print(max([a, b, c]) * 9 + sum([a, b, c]))
| replace | 1 | 2 | 1 | 2 | TypeError: sum() takes at most 2 arguments (3 given) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03250/Python/s838495112.py", line 2, in <module>
print(max(a, b, c) * 9 + sum(a, b, c))
TypeError: sum() takes at most 2 arguments (3 given)
|
p03250 | Python | Runtime Error | a, b, c = map(int, input().split())
print(max(a, b, c) * 9 + sum(a, b, c))
| a, b, c = map(int, input().split())
print(max(a, b, c) * 9 + a + b + c)
| replace | 1 | 2 | 1 | 2 | TypeError: sum() takes at most 2 arguments (3 given) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03250/Python/s348388771.py", line 2, in <module>
print(max(a, b, c) * 9 + sum(a, b, c))
TypeError: sum() takes at most 2 arguments (3 given)
|
p03250 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> N(3);
for (int i = 0; i < 3; i++)
cin >> N.at(i);
sort(N.begin(), N.end());
int ans = N.at(0) + N.at(2) + N.at(3) * 10;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> N(3);
for (int i = 0; i < 3; i++)
cin >> N.at(i);
sort(N.begin(), N.end());
int ans = N.at(0) + N.at(1) + N.at(2) * 10;
cout << ans << endl;
}
| 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 3) >= this->size() (which is 3)
|
p03250 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> ans(3);
for (int i = 0; i < 5; i++)
cin >> ans.at(i);
sort(ans.begin(), ans.end());
cout << ans.at(0) + ans.at(1) + ans.at(2) * 10;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> ans(3);
for (int i = 0; i < 3; i++)
cin >> ans.at(i);
sort(ans.begin(), ans.end());
cout << ans.at(0) + ans.at(1) + ans.at(2) * 10;
}
| replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p03250 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
int main() {
int a[3];
scanf("%d %d %d", a[0], a[1], a[2]);
sort(a, a + 3);
cout << 10 * a[2] + a[1] + a[0] << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
int main() {
int a[3];
scanf("%d %d %d", &a[0], &a[1], &a[2]);
sort(a, a + 3);
cout << 10 * a[2] + a[1] + a[0] << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | -11 | |
p03250 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
#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(a) (a).begin(), (a).end()
#define PI 3.141592653589793238
#define INF 1050000000
using vi = vector<int>;
int main() {
vi v;
REP(i, 3) { cin >> v[i]; }
sort(ALL(v));
cout << v[2] * 10 + v[1] + v[0] << endl;
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
#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(a) (a).begin(), (a).end()
#define PI 3.141592653589793238
#define INF 1050000000
using vi = vector<int>;
int main() {
vi v(3);
REP(i, 3) { cin >> v[i]; }
sort(ALL(v));
cout << v[2] * 10 + v[1] + v[0] << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | -11 | |
p03250 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a;
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int ans;
ans = a[0] + a[1] + a[2] * 10;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int ans;
ans = a[0] + a[1] + a[2] * 10;
cout << ans << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | -11 | |
p03250 | C++ | Runtime Error | /* Author - Ankur Kumar Singh
IDE :- Offine Linux
---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
/* variable type :- */
/* variable type :- */
#define ll long long int
#define ld long double
#define I int
#define mod 1000000007
/* map */
#define abc pair<long long int, long long int>
map<pair<abc, abc>, long long int> pqr;
map<pair<long long int, long long int>, long long int> xyz;
/* vector */
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mp make_pair
#define ac accumulate
vector<pair<ll, string>> a1;
vector<pair<ll, string>> a2;
vector<pair<ll, string>> a3;
vector<pair<ll, string>> a4;
vector<pair<ll, string>> a5;
vector<pair<ll, string>> a6;
vector<pair<ll, string>> a7;
vector<pair<pair<ll, ll>, ll>> b;
bool compare(const pair<long long int, long long int> &x,
const pair<long long int, long long int> &y) {
return x.ff > y.ff;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.ss < b.ss);
}
bool isPowerOfTwo(ll n) { return (ceil(log2(n)) == floor(log2(n))); }
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll arr[4];
for (ll i = 0; i < 3; i++)
cin >> arr[i];
sort(arr, arr + 3);
cout << arr[2] * 10 + arr[1] + arr[0];
} | /* Author - Ankur Kumar Singh
IDE :- Offine Linux
---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
/* variable type :- */
/* variable type :- */
#define ll long long int
#define ld long double
#define I int
#define mod 1000000007
/* map */
#define abc pair<long long int, long long int>
map<pair<abc, abc>, long long int> pqr;
map<pair<long long int, long long int>, long long int> xyz;
/* vector */
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mp make_pair
#define ac accumulate
vector<pair<ll, string>> a1;
vector<pair<ll, string>> a2;
vector<pair<ll, string>> a3;
vector<pair<ll, string>> a4;
vector<pair<ll, string>> a5;
vector<pair<ll, string>> a6;
vector<pair<ll, string>> a7;
vector<pair<pair<ll, ll>, ll>> b;
bool compare(const pair<long long int, long long int> &x,
const pair<long long int, long long int> &y) {
return x.ff > y.ff;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.ss < b.ss);
}
bool isPowerOfTwo(ll n) { return (ceil(log2(n)) == floor(log2(n))); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll arr[4];
for (ll i = 0; i < 3; i++)
cin >> arr[i];
sort(arr, arr + 3);
cout << arr[2] * 10 + arr[1] + arr[0];
} | replace | 39 | 43 | 39 | 40 | 0 | |
p03250 | Python | Runtime Error | input_data = [int(i) for i in input().split(" ")]
ans = 0
for k1, v1 in enumerate(input_data):
for k2, v2 in enumerate(input_data):
for k3, v3 in enumerate(input_data):
if k1 == k2 or k2 == k3 or k3 == k1:
continue
kou1 = int(f"{v1}{v2}")
if ans < kou1 + v3:
ans = kou1 + v3
print(ans)
| input_data = [int(i) for i in input().split(" ")]
ans = 0
for k1, v1 in enumerate(input_data):
for k2, v2 in enumerate(input_data):
for k3, v3 in enumerate(input_data):
if k1 == k2 or k2 == k3 or k3 == k1:
continue
kou1 = int(str(v1) + str(v2))
kou2 = v3
if ans < kou1 + kou2:
ans = kou1 + v3
print(ans)
| replace | 8 | 10 | 8 | 11 | 0 | |
p03250 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> x;
cin >> x[0] >> x[1] >> x[2];
sort(x.begin(), x.end());
cout << x[2] * 10 + x[1] + x[0] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> x(3);
cin >> x[0] >> x[1] >> x[2];
sort(x.begin(), x.end());
cout << x[2] * 10 + x[1] + x[0] << endl;
}
| replace | 3 | 4 | 3 | 4 | -11 | |
p03250 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
for (int i = 0; i < 3; i++) {
cin >> v[i];
}
sort(v.begin(), v.end(), greater<int>());
cout << v[0] * 10 + v[1] + v[2] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v(3);
for (int i = 0; i < 3; i++) {
cin >> v[i];
}
sort(v.begin(), v.end(), greater<int>());
cout << v[0] * 10 + v[1] + v[2] << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p03250 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int A[3];
cin >> A[0] >> A[1] >> A[2];
sort(A, A + 3);
cout << (A[0] + A[1] + A[2] * 10);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int A[3];
cin >> A[0] >> A[1] >> A[2];
sort(A, A + 3);
cout << (A[0] + A[1] + A[2] * 10);
return 0;
}
| replace | 4 | 8 | 4 | 5 | 0 | |
p03250 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
// random generator
// mt19937 rndm(time(0));
ll gcd(ll a, ll b) {
while (b > 0) {
int tmp = a;
a = b;
b = tmp % b;
}
return a;
}
const int M = 1e9 + 7;
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res % mod;
} /* a^b%mod */
const int N = 1e5 + 10;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
a[2] *= 10;
a[2] += a[1] + a[0];
cout << a[2];
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
// random generator
// mt19937 rndm(time(0));
ll gcd(ll a, ll b) {
while (b > 0) {
int tmp = a;
a = b;
b = tmp % b;
}
return a;
}
const int M = 1e9 + 7;
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res % mod;
} /* a^b%mod */
const int N = 1e5 + 10;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
a[2] *= 10;
a[2] += a[1] + a[0];
cout << a[2];
return 0;
}
| replace | 33 | 37 | 33 | 34 | 0 |