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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03003 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define INF 1 << 30
#define endl '\n'
#define maxn 2048
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef long double ld;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " \
<< z << endl;
const ll mod = 1e9 + 7;
ll X[maxn], Y[maxn];
ll dp[maxn][maxn];
ll n, m;
ll fact[maxn], inv[maxn], finv[maxn];
void pre_calc() {
fact[0] = fact[1] = 1;
inv[1] = 1;
finv[0] = finv[1] = 1;
for (int i = 2; i < maxn; i++) {
fact[i] = i * fact[i - 1] % mod;
inv[i] = mod - mod / i * inv[mod % i] % mod;
finv[i] = inv[i] * finv[i - 1] % mod;
}
}
ll calc(ll n, ll k) {
if (n < k || n < 0)
return 0;
return fact[n] * finv[n - k] % mod * finv[k] % mod;
}
ll solve(int i, int j) {
if (i == n || j == m)
return 0;
if (dp[i][j] > 0)
return dp[i][j];
if (X[i] == Y[j])
dp[i][j] = (1 + solve(i + 1, j) + solve(i, j + 1)) % mod;
else
dp[i][j] =
(solve(i + 1, j) + solve(i, j + 1) - solve(i + 1, j + 1) + mod) % mod;
return dp[i][j];
}
int main() {
FASTIO
/*
//double start_time = clock();
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//*/
cin >> n >> m;
for (ll i = 0; i < n; i++)
cin >> X[i];
for (ll i = 0; i < m; i++)
cin >> Y[i];
memset(dp, -1, sizeof dp);
cout << (solve(0, 0) + 1) % mod << endl;
// double end_time = clock();
// prllf( "Time = %lf ms\n", ( (end_time - start_time) /
// CLOCKS_PER_SEC)*1000);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define INF 1 << 30
#define endl '\n'
#define maxn 2048
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef long double ld;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) \
cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " \
<< z << endl;
const ll mod = 1e9 + 7;
ll X[maxn], Y[maxn];
ll dp[maxn][maxn];
ll n, m;
ll fact[maxn], inv[maxn], finv[maxn];
void pre_calc() {
fact[0] = fact[1] = 1;
inv[1] = 1;
finv[0] = finv[1] = 1;
for (int i = 2; i < maxn; i++) {
fact[i] = i * fact[i - 1] % mod;
inv[i] = mod - mod / i * inv[mod % i] % mod;
finv[i] = inv[i] * finv[i - 1] % mod;
}
}
ll calc(ll n, ll k) {
if (n < k || n < 0)
return 0;
return fact[n] * finv[n - k] % mod * finv[k] % mod;
}
ll solve(int i, int j) {
if (i == n || j == m)
return 0;
if (dp[i][j] >= 0)
return dp[i][j];
if (X[i] == Y[j])
dp[i][j] = (1 + solve(i + 1, j) + solve(i, j + 1)) % mod;
else
dp[i][j] =
(solve(i + 1, j) + solve(i, j + 1) - solve(i + 1, j + 1) + mod) % mod;
return dp[i][j];
}
int main() {
FASTIO
/*
//double start_time = clock();
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
//*/
cin >> n >> m;
for (ll i = 0; i < n; i++)
cin >> X[i];
for (ll i = 0; i < m; i++)
cin >> Y[i];
memset(dp, -1, sizeof dp);
cout << (solve(0, 0) + 1) % mod << endl;
// double end_time = clock();
// prllf( "Time = %lf ms\n", ( (end_time - start_time) /
// CLOCKS_PER_SEC)*1000);
return 0;
}
| replace | 42 | 43 | 42 | 43 | TLE | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cstring>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <deque>
#define pi 3.141592653589793238
#include <chrono>
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
using namespace std;
ll n;
ll ncr(ll n, ll r) {
ll i, ans = 1, k = 0;
if (r == 0)
return 1;
else if (n < r)
return 0;
for (i = n; i >= n - r + 1; i--) {
ans *= i;
ans /= n - i + 1;
}
return ans;
}
void max_heapify(int a[100], int i) {
int l, r, largest = i;
l = 2 * i + 1;
r = 2 * i + 2;
if (l < n && a[l] > a[i])
largest = l;
if (r < n && a[r] > a[l])
largest = r;
if (largest != i) {
int k;
k = a[i];
a[i] = a[largest];
a[largest] = k;
max_heapify(a, largest);
}
}
int power(ll x, ll y, ll p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool square(ll n) {
double x;
x = sqrt(n);
if (x == floor(x))
return true;
else
return false;
}
bool prime(ll n) {
ll i;
for (i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
ll modi(ll a, ll m) { return power(a, m - 2, m); }
void kmp(string s, ll p[]) {
int n = (int)s.length();
p[0] = 0;
for (int i = 1; i < n; i++) {
int j = p[i - 1];
while (j > 0 && s[i] != s[j])
j = p[j - 1];
if (s[i] == s[j])
j++;
p[i] = j;
}
}
void zfunc(string s, ll z[]) {
ll n = (ll)s.length();
z[0] = 0;
for (ll i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r)
z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
++z[i];
if (i + z[i] - 1 > r)
l = i, r = i + z[i] - 1;
}
}
struct pair_hash {
size_t operator()(const pair<int, int> &p) const noexcept {
return hash<ll>()((((ll)p.first) << 32) | ((ll)p.second));
}
};
bool palin(string s) {
ll i, n;
n = s.length();
for (i = 0; i <= n / 2; i++) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll sum(ll n) {
ll i;
i = n;
ll sum = 0;
while (i > 0) {
sum += i % 10;
i = i / 10;
}
return sum;
}
ll nCr(ll n, ll r, ll p, ll fac[]) {
if (r == 0)
return 1;
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modi(fac[r], p) % p * modi(fac[n - r], p) % p) % p;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll mod(string num, ll a) {
ll res = 0;
for (ll i = 0; i < num.length(); i++)
res = (res * 10 + (ll)num[i] - '0') % a;
return res;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll parent[1000], sizer[1000];
ll findset(ll a) {
if (a == parent[a]) {
return a;
}
parent[a] = findset(parent[a]);
return parent[a];
}
void unionset(ll a, ll b) {
a = findset(a);
b = findset(b);
if (sizer[a] < sizer[b]) {
swap(a, b);
}
sizer[b] += sizer[a];
parent[b] = a;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct fenwick {
vector<ll> bit;
ll n;
fenwick(ll n, vector<ll> v) {
this->n = n;
bit.assign(n, 0);
for (ll it = 0; it < n; it++) {
add(it, v[it]);
}
}
ll sum(ll idx) {
if (idx < 0)
return 0;
ll ret = 0;
for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {
ret += bit[idx];
}
return ret;
}
void add(ll idx, ll x) {
for (; idx < n; idx = idx | (idx + 1)) {
bit[idx] += x;
bit[idx] = max(0LL, bit[idx]);
}
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
// cin >> T;
while (T--) {
ll n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < m; i++) {
cin >> t[i];
}
ll dp[100][100] = {0};
ll dp2[100][100] = {0};
ll ans = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
dp2[i + 1][j + 1] =
(dp2[i][j + 1] + dp2[i + 1][j] - dp2[i][j] + dp[i][j] + MOD) % MOD;
if (s[i] != t[j]) {
dp[i + 1][j + 1] = 0;
continue;
}
dp[i + 1][j + 1] = (dp2[i + 1][j + 1] + 1) % MOD;
ans += dp[i + 1][j + 1];
ans %= MOD;
}
}
cout << (ans + 1) % MOD;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cstring>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <deque>
#define pi 3.141592653589793238
#include <chrono>
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
using namespace std;
ll n;
ll ncr(ll n, ll r) {
ll i, ans = 1, k = 0;
if (r == 0)
return 1;
else if (n < r)
return 0;
for (i = n; i >= n - r + 1; i--) {
ans *= i;
ans /= n - i + 1;
}
return ans;
}
void max_heapify(int a[100], int i) {
int l, r, largest = i;
l = 2 * i + 1;
r = 2 * i + 2;
if (l < n && a[l] > a[i])
largest = l;
if (r < n && a[r] > a[l])
largest = r;
if (largest != i) {
int k;
k = a[i];
a[i] = a[largest];
a[largest] = k;
max_heapify(a, largest);
}
}
int power(ll x, ll y, ll p) {
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool square(ll n) {
double x;
x = sqrt(n);
if (x == floor(x))
return true;
else
return false;
}
bool prime(ll n) {
ll i;
for (i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
ll modi(ll a, ll m) { return power(a, m - 2, m); }
void kmp(string s, ll p[]) {
int n = (int)s.length();
p[0] = 0;
for (int i = 1; i < n; i++) {
int j = p[i - 1];
while (j > 0 && s[i] != s[j])
j = p[j - 1];
if (s[i] == s[j])
j++;
p[i] = j;
}
}
void zfunc(string s, ll z[]) {
ll n = (ll)s.length();
z[0] = 0;
for (ll i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r)
z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
++z[i];
if (i + z[i] - 1 > r)
l = i, r = i + z[i] - 1;
}
}
struct pair_hash {
size_t operator()(const pair<int, int> &p) const noexcept {
return hash<ll>()((((ll)p.first) << 32) | ((ll)p.second));
}
};
bool palin(string s) {
ll i, n;
n = s.length();
for (i = 0; i <= n / 2; i++) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll sum(ll n) {
ll i;
i = n;
ll sum = 0;
while (i > 0) {
sum += i % 10;
i = i / 10;
}
return sum;
}
ll nCr(ll n, ll r, ll p, ll fac[]) {
if (r == 0)
return 1;
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modi(fac[r], p) % p * modi(fac[n - r], p) % p) % p;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll mod(string num, ll a) {
ll res = 0;
for (ll i = 0; i < num.length(); i++)
res = (res * 10 + (ll)num[i] - '0') % a;
return res;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll parent[1000], sizer[1000];
ll findset(ll a) {
if (a == parent[a]) {
return a;
}
parent[a] = findset(parent[a]);
return parent[a];
}
void unionset(ll a, ll b) {
a = findset(a);
b = findset(b);
if (sizer[a] < sizer[b]) {
swap(a, b);
}
sizer[b] += sizer[a];
parent[b] = a;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct fenwick {
vector<ll> bit;
ll n;
fenwick(ll n, vector<ll> v) {
this->n = n;
bit.assign(n, 0);
for (ll it = 0; it < n; it++) {
add(it, v[it]);
}
}
ll sum(ll idx) {
if (idx < 0)
return 0;
ll ret = 0;
for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {
ret += bit[idx];
}
return ret;
}
void add(ll idx, ll x) {
for (; idx < n; idx = idx | (idx + 1)) {
bit[idx] += x;
bit[idx] = max(0LL, bit[idx]);
}
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
// cin >> T;
while (T--) {
ll n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < m; i++) {
cin >> t[i];
}
ll dp[2001][2001] = {0};
ll dp2[2001][2001] = {0};
ll ans = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
dp2[i + 1][j + 1] =
(dp2[i][j + 1] + dp2[i + 1][j] - dp2[i][j] + dp[i][j] + MOD) % MOD;
if (s[i] != t[j]) {
dp[i + 1][j + 1] = 0;
continue;
}
dp[i + 1][j + 1] = (dp2[i + 1][j + 1] + 1) % MOD;
ans += dp[i + 1][j + 1];
ans %= MOD;
}
}
cout << (ans + 1) % MOD;
}
return 0;
}
| replace | 246 | 248 | 246 | 248 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define forn(I, N) for (int I = 0; I < (N); ++I)
#define fornd(I, N) for (int I = (N)-1; I >= 0; --I)
#define forab(I, A, B) for (int I = (A); I <= (B); ++I)
#define forabd(I, A, B) for (int I = (B); I >= (A); --I)
#define FOREACH(I, A) \
for (__typeof__(A)::iterator I = A.begin(); I < A.end(); I++)
#define all(V) (V).begin(), (V).end()
#define pb push_back
#define mp make_pair
typedef long long int ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const ll mod = 1000000007;
int main() {
int N, M;
cin >> N >> M;
vector<ll> S(N), T(M);
forn(i, N) { cin >> S[i]; }
forn(j, M) { cin >> T[j]; }
vector<ll> res(N);
forn(i, N) {
ll tempSum = 0;
forn(j, M) {
ll buf = res[j];
if (S[i] == T[j]) {
res[j] = (res[j] + 1 + tempSum) % mod;
}
tempSum = (tempSum + buf) % mod;
}
}
ll ans = 1;
forn(i, M) { ans = (ans + res[i]) % mod; }
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define forn(I, N) for (int I = 0; I < (N); ++I)
#define fornd(I, N) for (int I = (N)-1; I >= 0; --I)
#define forab(I, A, B) for (int I = (A); I <= (B); ++I)
#define forabd(I, A, B) for (int I = (B); I >= (A); --I)
#define FOREACH(I, A) \
for (__typeof__(A)::iterator I = A.begin(); I < A.end(); I++)
#define all(V) (V).begin(), (V).end()
#define pb push_back
#define mp make_pair
typedef long long int ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const ll mod = 1000000007;
int main() {
int N, M;
cin >> N >> M;
vector<ll> S(N), T(M);
forn(i, N) { cin >> S[i]; }
forn(j, M) { cin >> T[j]; }
vector<ll> res(M);
forn(i, N) {
ll tempSum = 0;
forn(j, M) {
ll buf = res[j];
if (S[i] == T[j]) {
res[j] = (res[j] + 1 + tempSum) % mod;
}
tempSum = (tempSum + buf) % mod;
}
}
ll ans = 1;
forn(i, M) { ans = (ans + res[i]) % mod; }
cout << ans << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p03003 | C++ | Runtime Error | /*input
20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE
#ifdef TEMPLATE
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI =
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
return pair<T, T>(a.x + b.x, a.y + b.y);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
return pair<T, T>(a.x - b.x, a.y - b.y);
}
template <typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) {
return (a.x * b.x + a.y * b.y);
}
template <typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) {
return (a.x * b.y - a.y * b.x);
}
template <typename T> void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
#endif
struct FENWICK {
// queries [1:N]
vector<ll> A;
int N;
FENWICK(int n) : N(n) { A.resize(n + 1, 0); }
void add(int i, ll x) {
for (; i <= N; i += (i) & (-i))
A[i] = (x + A[i]) % MOD;
}
ll getQ(int i) {
ll get = 1;
for (; i > 0; i -= (i) & (-i))
get = (A[i] + get) % MOD;
return get;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N >> M;
vi pir(N);
vi ant(M);
for (int i = 0; i < N; ++i)
cin >> pir[i];
for (int i = 0; i < M; ++i)
cin >> ant[i];
FENWICK sums(M);
for (int i = 0; i < N; ++i)
for (int j = M - 1; j >= 0; --j)
if (pir[i] == ant[j])
sums.add(j + 1, sums.getQ(j));
printf("%lld\n", sums.getQ(N));
}
/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
| /*input
20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE
#ifdef TEMPLATE
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI =
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;
template <typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {
return pair<T, T>(a.x + b.x, a.y + b.y);
}
template <typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) {
return pair<T, T>(a.x - b.x, a.y - b.y);
}
template <typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) {
return (a.x * b.x + a.y * b.y);
}
template <typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) {
return (a.x * b.y - a.y * b.x);
}
template <typename T> void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
#endif
struct FENWICK {
// queries [1:N]
vector<ll> A;
int N;
FENWICK(int n) : N(n) { A.resize(n + 1, 0); }
void add(int i, ll x) {
for (; i <= N; i += (i) & (-i))
A[i] = (x + A[i]) % MOD;
}
ll getQ(int i) {
ll get = 1;
for (; i > 0; i -= (i) & (-i))
get = (A[i] + get) % MOD;
return get;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N >> M;
vi pir(N);
vi ant(M);
for (int i = 0; i < N; ++i)
cin >> pir[i];
for (int i = 0; i < M; ++i)
cin >> ant[i];
FENWICK sums(M);
for (int i = 0; i < N; ++i)
for (int j = M - 1; j >= 0; --j)
if (pir[i] == ant[j])
sums.add(j + 1, sums.getQ(j));
printf("%lld\n", sums.getQ(M));
}
/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
| replace | 105 | 106 | 105 | 106 | 0 | |
p03003 | C++ | Runtime Error | #include <iostream>
#include <map>
#include <vector>
using namespace std;
constexpr int N_max = 2'000;
constexpr int M_max = 2'000;
constexpr int mod = 1'000'000'007;
#ifdef _MSC_VER
constexpr int debug = 1;
#else
constexpr int debug = 0;
#endif
// s-pos t-pos
static int dp0[2'005][2'005];
static int dp1[2'005][2'005];
int main() {
int n, m;
cin >> n >> m;
auto s = vector<int>(n + 5);
auto t = vector<int>(m + 5);
for (int i = 0; i < n; i++)
cin >> s[i];
for (int j = 0; j < m; j++)
cin >> t[j];
dp0[0][0] = 1;
for (int i = 0; i <= s.size(); i++) {
for (int j = 0; j <= t.size(); j++) {
dp0[i + 1][j] = (dp0[i + 1][j] + dp0[i][j]) % mod;
dp1[i][j] = (dp1[i][j] + dp0[i][j]) % mod;
dp1[i][j + 1] = (dp1[i][j + 1] + dp1[i][j]) % mod;
if (s[i] == t[j]) {
dp0[i + 1][j + 1] = (dp0[i + 1][j + 1] + dp1[i][j]) % mod;
}
}
}
cout << dp1[n][m];
return 0;
}
| #include <iostream>
#include <map>
#include <vector>
using namespace std;
constexpr int N_max = 2'000;
constexpr int M_max = 2'000;
constexpr int mod = 1'000'000'007;
#ifdef _MSC_VER
constexpr int debug = 1;
#else
constexpr int debug = 0;
#endif
// s-pos t-pos
static int dp0[2'005][2'005];
static int dp1[2'005][2'005];
int main() {
int n, m;
cin >> n >> m;
auto s = vector<int>(n + 5);
auto t = vector<int>(m + 5);
for (int i = 0; i < n; i++)
cin >> s[i];
for (int j = 0; j < m; j++)
cin >> t[j];
dp0[0][0] = 1;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
dp0[i + 1][j] = (dp0[i + 1][j] + dp0[i][j]) % mod;
dp1[i][j] = (dp1[i][j] + dp0[i][j]) % mod;
dp1[i][j + 1] = (dp1[i][j + 1] + dp1[i][j]) % mod;
if (s[i] == t[j]) {
dp0[i + 1][j + 1] = (dp0[i + 1][j + 1] + dp1[i][j]) % mod;
}
}
}
cout << dp1[n][m];
return 0;
}
| replace | 30 | 32 | 30 | 32 | 0 | |
p03003 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <bits/stdc++.h>
// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i, n) for (long long i = 0, i##_len = (n); i < i##_len; i++)
#define RANGE(i, is, ie) \
for (long long i = (is), i##_end = (ie); i <= i##_end; i++)
#define DSRNG(i, is, ie) \
for (long long i = (is), i##_end = (ie); i >= i##_end; i--)
#define UNIQUE(v) \
{ \
sort((v).begin(), (v).end()); \
(v).erase(unique((v).begin(), (v).end()), (v).end()); \
}
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;
}
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) \
cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) \
{ \
cerr << "[DEBUG] " #q ": ["; \
REP(dumpall_i, (q).size()) { \
cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); \
} \
cerr << "] at " __FILE__ ":" << __LINE__ << endl; \
}
template <class T> T gcd(const T &a, const T &b) {
return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// エイリアス
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using namespace std;
// モジュール
// 処理内容
int main() {
constexpr ll p = 1000000007;
ll n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
REP(i, n) cin >> s[i];
REP(i, m) cin >> t[i];
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
// dp[0][0] = 1;
REP(i, n + 1) dp[i][0] = 1;
REP(i, m + 1) dp[0][i] = 1;
RANGE(i, 1, n) RANGE(j, 1, m) {
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] % p + (p - dp[i - 1][j - 1])) % p;
if (s[i - 1] == t[j - 1]) {
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= p;
}
}
cout << dp[n][m] << endl;
cerr << "[DEBUG]\n";
REP(i, n + 1) REP(j, m + 1) cerr << dp[i][j] << " \n"[j == m];
} | #pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <bits/stdc++.h>
// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i, n) for (long long i = 0, i##_len = (n); i < i##_len; i++)
#define RANGE(i, is, ie) \
for (long long i = (is), i##_end = (ie); i <= i##_end; i++)
#define DSRNG(i, is, ie) \
for (long long i = (is), i##_end = (ie); i >= i##_end; i--)
#define UNIQUE(v) \
{ \
sort((v).begin(), (v).end()); \
(v).erase(unique((v).begin(), (v).end()), (v).end()); \
}
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;
}
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) \
cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) \
{ \
cerr << "[DEBUG] " #q ": ["; \
REP(dumpall_i, (q).size()) { \
cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); \
} \
cerr << "] at " __FILE__ ":" << __LINE__ << endl; \
}
template <class T> T gcd(const T &a, const T &b) {
return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a;
}
template <class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }
// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// エイリアス
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using namespace std;
// モジュール
// 処理内容
int main() {
constexpr ll p = 1000000007;
ll n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
REP(i, n) cin >> s[i];
REP(i, m) cin >> t[i];
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
// dp[0][0] = 1;
REP(i, n + 1) dp[i][0] = 1;
REP(i, m + 1) dp[0][i] = 1;
RANGE(i, 1, n) RANGE(j, 1, m) {
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] % p + (p - dp[i - 1][j - 1])) % p;
if (s[i - 1] == t[j - 1]) {
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= p;
}
}
cout << dp[n][m] << endl;
} | delete | 86 | 89 | 86 | 86 | TLE | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll N, M;
vector<ll> S, T;
vector<vector<ll>> Dp;
int main() {
cin >> N >> M;
S.resize(N);
for (ll i = 0; i < N; ++i)
cin >> S[i];
T.resize(M);
for (ll j = 0; j < M; ++j)
cin >> T[j];
Dp.resize(N + 1);
for (auto &dp : Dp)
dp.resize(M + 1);
for (ll i = 0; i <= N; ++i)
Dp[i][0] = 1;
for (ll j = 0; j <= N; ++j)
Dp[0][j] = 1;
for (ll i = 1; i <= N; ++i) {
for (ll j = 1; j <= M; ++j) {
Dp[i][j] = (Dp[i - 1][j] + Dp[i][j - 1] + MOD - Dp[i - 1][j - 1]) % MOD;
if (S[i - 1] == T[j - 1])
(Dp[i][j] += Dp[i - 1][j - 1]) %= MOD;
}
}
cout << Dp[N][M] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll N, M;
vector<ll> S, T;
vector<vector<ll>> Dp;
int main() {
cin >> N >> M;
S.resize(N);
for (ll i = 0; i < N; ++i)
cin >> S[i];
T.resize(M);
for (ll j = 0; j < M; ++j)
cin >> T[j];
Dp.resize(N + 1);
for (auto &dp : Dp)
dp.resize(M + 1);
for (ll i = 0; i <= N; ++i)
Dp[i][0] = 1;
for (ll j = 0; j <= M; ++j)
Dp[0][j] = 1;
for (ll i = 1; i <= N; ++i) {
for (ll j = 1; j <= M; ++j) {
Dp[i][j] = (Dp[i - 1][j] + Dp[i][j - 1] + MOD - Dp[i - 1][j - 1]) % MOD;
if (S[i - 1] == T[j - 1])
(Dp[i][j] += Dp[i - 1][j - 1]) %= MOD;
}
}
cout << Dp[N][M] << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03003 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll N, M;
ll inf = 1e9 + 7;
int main() {
cin >> N >> M;
vector<int> S(N + 1, 0), T(N + 1, 0);
for (int i = 1; i <= N; i++)
cin >> S[i];
for (int j = 1; j <= M; j++)
cin >> T[j];
vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
vector<vector<ll>> sum(N + 1, vector<ll>(M + 1, 0));
dp[0][0] = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
if (i != 0 && j != 0 && S[i] == T[j])
(dp[i][j] += sum[i - 1][j - 1]) %= inf;
(sum[i][j] += dp[i][j]) %= inf;
if (j != 0)
(sum[i][j] += sum[i][j - 1]) %= inf;
}
if (i != 0)
for (int j = 0; j <= M; j++)
(sum[i][j] += sum[i - 1][j]) %= inf;
}
cout << sum[N][M] << endl;
} | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll N, M;
ll inf = 1e9 + 7;
int main() {
cin >> N >> M;
vector<int> S(N + 1, 0), T(M + 1, 0);
for (int i = 1; i <= N; i++)
cin >> S[i];
for (int j = 1; j <= M; j++)
cin >> T[j];
vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
vector<vector<ll>> sum(N + 1, vector<ll>(M + 1, 0));
dp[0][0] = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
if (i != 0 && j != 0 && S[i] == T[j])
(dp[i][j] += sum[i - 1][j - 1]) %= inf;
(sum[i][j] += dp[i][j]) %= inf;
if (j != 0)
(sum[i][j] += sum[i][j - 1]) %= inf;
}
if (i != 0)
for (int j = 0; j <= M; j++)
(sum[i][j] += sum[i - 1][j]) %= inf;
}
cout << sum[N][M] << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define PI acos(-1.0)
#define fir first
#define sec second
#define SZ(x) (x.size())
#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define PII pair<int, int>
#define E 2.7182818284590452353602874713527
using namespace std;
/**********************************************Head-----Template****************************************/
bool Finish_read;
template <class T> inline void read(T &x) {
Finish_read = 0;
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
if (ch == EOF)
return;
ch = getchar();
}
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
x *= f;
Finish_read = 1;
}
template <class T> inline void print(T x) {
if (x / 10 != 0)
print(x / 10);
putchar(x % 10 + '0');
}
template <class T> inline void writeln(T x) {
if (x < 0)
putchar('-');
x = abs(x);
print(x);
putchar('\n');
}
template <class T> inline void write(T x) {
if (x < 0)
putchar('-');
x = abs(x);
print(x);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll mod = 10000019;
// const ll phi_mod_prime=mod-1;
ll ksm(ll a, ll b, ll mod) {
ll ans = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll phi(ll n) {
ll rea = n;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
rea = rea - rea / i;
while (n % i == 0)
n /= i;
}
}
if (n > 1)
rea = rea - rea / n;
return rea;
}
// a^(b%modhi(mod)+phi(mod))%mod;
void exgcd(int a, int b, int &x, int &y, int &d) {
if (!b) {
x = 1;
y = 0;
d = a;
} else
exgcd(b, a % b, y, x, d), y -= a / b * x;
}
inline int inv(int a, int mod) {
int x, y, d;
exgcd(a, mod, x, y, d);
x = (x % mod + mod) % mod;
return x;
}
/********************************Head----Template**********************************************/
const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 5;
const int mod = 1000000007;
int n, m;
ll dp[maxn][maxn];
int a[maxn], b[maxn];
int main() {
while (~scanf("%d%d", &n, &m)) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
scanf("%d", &b[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i] == b[j])
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] + mod) % mod;
}
}
printf("%lld\n", (dp[n][m] + 1) % mod);
}
return 0;
}
| #include <bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define PI acos(-1.0)
#define fir first
#define sec second
#define SZ(x) (x.size())
#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define PII pair<int, int>
#define E 2.7182818284590452353602874713527
using namespace std;
/**********************************************Head-----Template****************************************/
bool Finish_read;
template <class T> inline void read(T &x) {
Finish_read = 0;
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
if (ch == EOF)
return;
ch = getchar();
}
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
x *= f;
Finish_read = 1;
}
template <class T> inline void print(T x) {
if (x / 10 != 0)
print(x / 10);
putchar(x % 10 + '0');
}
template <class T> inline void writeln(T x) {
if (x < 0)
putchar('-');
x = abs(x);
print(x);
putchar('\n');
}
template <class T> inline void write(T x) {
if (x < 0)
putchar('-');
x = abs(x);
print(x);
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll mod = 10000019;
// const ll phi_mod_prime=mod-1;
ll ksm(ll a, ll b, ll mod) {
ll ans = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll phi(ll n) {
ll rea = n;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
rea = rea - rea / i;
while (n % i == 0)
n /= i;
}
}
if (n > 1)
rea = rea - rea / n;
return rea;
}
// a^(b%modhi(mod)+phi(mod))%mod;
void exgcd(int a, int b, int &x, int &y, int &d) {
if (!b) {
x = 1;
y = 0;
d = a;
} else
exgcd(b, a % b, y, x, d), y -= a / b * x;
}
inline int inv(int a, int mod) {
int x, y, d;
exgcd(a, mod, x, y, d);
x = (x % mod + mod) % mod;
return x;
}
/********************************Head----Template**********************************************/
const int INF = 0x3f3f3f3f;
const int maxn = 2000 + 7;
const int mod = 1000000007;
int n, m;
ll dp[maxn][maxn];
int a[maxn], b[maxn];
int main() {
while (~scanf("%d%d", &n, &m)) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
scanf("%d", &b[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i] == b[j])
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] + mod) % mod;
}
}
printf("%lld\n", (dp[n][m] + 1) % mod);
}
return 0;
}
| replace | 101 | 102 | 101 | 102 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;
ll dp[2009][2009];
ll s[2009], t[2009];
ll fun(ll i, ll j) {
if (i < 0 or j < 0)
return 0;
if (i == 0 or j == 0)
return 1;
else if (dp[i][j] != -1)
return dp[i][j];
else {
if (s[i - 1] != t[j - 1])
return dp[i][j] =
(fun(i - 1, j) + fun(i, j - 1) - fun(i - 1, j - 1) + mod) %
mod;
else
return dp[i][j] = (fun(i - 1, j) + fun(i, j - 1)) % mod;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
ll n, m, x;
cin >> n >> m;
for (ll i = 0; i < n; i++)
cin >> s[i];
for (ll i = 0; i < m; i++)
cin >> t[i];
memset(dp, -1, sizeof(dp));
cout << fun(n, m) << endl;
}
| #include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;
ll dp[2009][2009];
ll s[2009], t[2009];
ll fun(ll i, ll j) {
if (i < 0 or j < 0)
return 0;
if (i == 0 or j == 0)
return 1;
else if (dp[i][j] != -1)
return dp[i][j];
else {
if (s[i - 1] != t[j - 1])
return dp[i][j] =
(fun(i - 1, j) + fun(i, j - 1) - fun(i - 1, j - 1) + mod) %
mod;
else
return dp[i][j] = (fun(i - 1, j) + fun(i, j - 1)) % mod;
}
}
int main() {
fast;
ll n, m, x;
cin >> n >> m;
for (ll i = 0; i < n; i++)
cin >> s[i];
for (ll i = 0; i < m; i++)
cin >> t[i];
memset(dp, -1, sizeof(dp));
cout << fun(n, m) << endl;
}
| delete | 36 | 41 | 36 | 36 | TLE | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int n, m, mod = 1000000007;
vector<int> s(1e3 + 3), t(1e3 + 3);
long long dp[1003][1003];
long long solve(int i, int j) {
if (i == 0 || j == 0) {
return 1;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
dp[i][j] = 0;
if (s[i] == t[j]) {
dp[i][j] += solve(i - 1, j - 1);
}
dp[i][j] += solve(i - 1, j) + solve(i, j - 1) - solve(i - 1, j - 1);
dp[i][j] += mod;
dp[i][j] %= mod;
return dp[i][j];
}
int main(void) {
ios ::sync_with_stdio(0);
cin.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
}
for (int i = 1; i <= m; ++i) {
cin >> t[i];
}
cout << solve(n, m) << "\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int n, m, mod = 1000000007;
vector<int> s(2e3 + 3), t(2e3 + 3);
long long dp[2003][2003];
long long solve(int i, int j) {
if (i == 0 || j == 0) {
return 1;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
dp[i][j] = 0;
if (s[i] == t[j]) {
dp[i][j] += solve(i - 1, j - 1);
}
dp[i][j] += solve(i - 1, j) + solve(i, j - 1) - solve(i - 1, j - 1);
dp[i][j] += mod;
dp[i][j] %= mod;
return dp[i][j];
}
int main(void) {
ios ::sync_with_stdio(0);
cin.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
}
for (int i = 1; i <= m; ++i) {
cin >> t[i];
}
cout << solve(n, m) << "\n";
return 0;
} | replace | 20 | 22 | 20 | 22 | 0 | |
p03003 | C++ | Runtime Error | #include <iostream>
using namespace std;
const int MOD = 1000000007;
int main() {
int N, M, S[2000], T[2000];
int dp[200][200] = {0};
cin >> N >> M;
for (int i = 0; i < N; i++)
cin >> S[i];
for (int i = 0; i < M; i++)
cin >> T[i];
dp[0][0] = S[0] == T[0];
for (int i = 1; i < N; i++)
dp[i][0] = dp[i - 1][0] + (S[i] == T[0]);
for (int i = 1; i < M; i++)
dp[0][i] = dp[0][i - 1] + (S[0] == T[i]);
for (int i = 1; i < N; i++)
dp[i][0] = dp[i - 1][0] + (S[i] == T[0]);
for (int i = 1; i < M; i++)
dp[0][i] = dp[0][i - 1] + (S[0] == T[i]);
for (int i = 1; i < N; i++)
for (int j = 1; j < M; j++) {
if (S[i] == T[j])
dp[i][j] = dp[i][j - 1] + dp[i - 1][j] + 1;
else
dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
}
cout << dp[N - 1][M - 1] + 1;
return 0;
}
| #include <iostream>
using namespace std;
const int MOD = 1000000007;
int main() {
int N, M, S[2000], T[2000];
int dp[2000][2000] = {0};
cin >> N >> M;
for (int i = 0; i < N; i++)
cin >> S[i];
for (int i = 0; i < M; i++)
cin >> T[i];
dp[0][0] = S[0] == T[0];
for (int i = 1; i < N; i++)
dp[i][0] = dp[i - 1][0] + (S[i] == T[0]);
for (int i = 1; i < M; i++)
dp[0][i] = dp[0][i - 1] + (S[0] == T[i]);
for (int i = 1; i < N; i++)
dp[i][0] = dp[i - 1][0] + (S[i] == T[0]);
for (int i = 1; i < M; i++)
dp[0][i] = dp[0][i - 1] + (S[0] == T[i]);
for (int i = 1; i < N; i++)
for (int j = 1; j < M; j++) {
if (S[i] == T[j])
dp[i][j] = dp[i][j - 1] + dp[i - 1][j] + 1;
else
dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
}
cout << dp[N - 1][M - 1] + 1;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T> using uset = unordered_set<T>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return (a > b && (a = b, true));
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return (a < b && (a = b, true));
}
template <typename T> bool isin(T y, T x, T h, T w) {
return (0 <= y && 0 <= x && y < h && x < w);
}
template <typename T> bool isin1(T y, T x, T h, T w) {
return (0 < y && 0 < x && y <= h && x <= w);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
os << v[0];
for (int i = 1; i < v.size(); i++)
os << " " << v[i];
return (os);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &u : v)
is >> u;
return (is);
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return (is >> p.first >> p.second);
}
void Main() {
ll N, M;
cin >> N >> M;
vll S(N), T(M);
cin >> S >> T;
vvll dp(N + 1, vll(M + 1, 0));
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= M; j++) {
if (j < M && S[i] == T[j])
(dp[i + 1][j + 1] += dp[i][j]) %= mod;
(dp[i + 1][j] += dp[i][j]) %= mod;
(dp[i][j + 1] += dp[i][j]) %= mod;
(dp[i + 1][j + 1] += mod - dp[i][j]) %= mod;
}
}
ll sum = 0;
for (int i = 0; i <= M; i++) {
(sum += dp[N][i]) %= mod;
}
cout << sum << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
Main();
return (0);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T> using uset = unordered_set<T>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return (a > b && (a = b, true));
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return (a < b && (a = b, true));
}
template <typename T> bool isin(T y, T x, T h, T w) {
return (0 <= y && 0 <= x && y < h && x < w);
}
template <typename T> bool isin1(T y, T x, T h, T w) {
return (0 < y && 0 < x && y <= h && x <= w);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
os << v[0];
for (int i = 1; i < v.size(); i++)
os << " " << v[i];
return (os);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &u : v)
is >> u;
return (is);
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return (is >> p.first >> p.second);
}
void Main() {
ll N, M;
cin >> N >> M;
vll S(N), T(M);
cin >> S >> T;
vvll dp(N + 1, vll(M + 1, 0));
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= M; j++) {
if (j < M && S[i] == T[j])
(dp[i + 1][j + 1] += dp[i][j]) %= mod;
if (i < N)
(dp[i + 1][j] += dp[i][j]) %= mod;
if (j < M)
(dp[i][j + 1] += dp[i][j]) %= mod;
if (i < N && j < M)
(dp[i + 1][j + 1] += mod - dp[i][j]) %= mod;
}
}
ll sum = 0;
for (int i = 0; i <= M; i++) {
(sum += dp[N][i]) %= mod;
}
cout << sum << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
Main();
return (0);
}
| replace | 72 | 75 | 72 | 78 | -6 | munmap_chunk(): invalid pointer
|
p03003 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> S(n), T(m);
rep(i, n) cin >> S[i];
map<int, vector<int>> mp;
rep(i, m) {
cin >> T[i];
mp[T[i]].push_back(i);
}
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
dp[0][0] = 1;
rep(i, n) {
rep(j, m + 1) {
(dp[i + 1][j] += dp[i][j]) %= mod;
auto itr = lower_bound(all(mp[S[i]]), j);
for (auto k = itr; k != mp[S[i]].end(); k++) {
(dp[i + 1][*k + 1] += dp[i][j]) %= mod;
}
}
}
ll ans = 0;
rep(i, m + 1)(ans += dp[n][i]) %= mod;
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> S(n), T(m);
rep(i, n) cin >> S[i];
map<int, vector<int>> mp;
rep(i, m) {
cin >> T[i];
mp[T[i]].push_back(i);
}
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
dp[0][0] = 1;
rep(i, n) {
rep(j, m + 1) {
(dp[i + 1][j] += dp[i][j]) %= mod;
auto itr = lower_bound(all(mp[S[i]]), j);
if (itr != mp[S[i]].end())
(dp[i + 1][*itr + 1] += dp[i][j]) %= mod;
}
for (auto &ele : mp) {
rep(j, ele.second.size()) {
if (j)
(dp[i + 1][ele.second[j] + 1] +=
(mod + dp[i + 1][ele.second[j - 1] + 1] -
dp[i][ele.second[j - 1] + 1]) %
mod) %= mod;
}
}
}
ll ans = 0;
rep(i, m + 1)(ans += dp[n][i]) %= mod;
cout << ans << "\n";
return 0;
}
| replace | 30 | 32 | 30 | 40 | TLE | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
int N, M, S[200], T[200], DP[201][201], s[201][201];
int main() {
cin >> N >> M;
for (int i = 0; i < N; ++i) {
cin >> S[i];
}
for (int i = 0; i < M; ++i) {
cin >> T[i];
}
for (int i = 0; i <= M; ++i) {
s[0][i] = 1;
}
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= M; ++j) {
s[i][j] = s[i][j - 1];
if (S[i - 1] == T[j - 1]) {
DP[i][j] = s[i - 1][j - 1];
s[i][j] += DP[i][j];
s[i][j] %= mod;
}
}
for (int j = 0; j <= M; ++j) {
s[i][j] += s[i - 1][j];
s[i][j] %= mod;
}
}
cout << s[N][M] << endl;
} | #include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
int N, M, S[2000], T[2000], DP[2001][2001], s[2001][2001];
int main() {
cin >> N >> M;
for (int i = 0; i < N; ++i) {
cin >> S[i];
}
for (int i = 0; i < M; ++i) {
cin >> T[i];
}
for (int i = 0; i <= M; ++i) {
s[0][i] = 1;
}
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= M; ++j) {
s[i][j] = s[i][j - 1];
if (S[i - 1] == T[j - 1]) {
DP[i][j] = s[i - 1][j - 1];
s[i][j] += DP[i][j];
s[i][j] %= mod;
}
}
for (int j = 0; j <= M; ++j) {
s[i][j] += s[i - 1][j];
s[i][j] %= mod;
}
}
cout << s[N][M] << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
int N, M;
cin >> N >> M;
int S[N];
int T[M];
for (int i = 0; i < N; i++)
cin >> S[i];
for (int i = 0; i < M; i++)
cin >> T[i];
ll DP[N + 1][M + 1];
vector<ll> sum(N + 1);
ll ans = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
DP[i][j] = 0;
}
}
for (int i = 0; i <= M; i++) {
sum[i] = 1;
}
DP[0][0] = 1;
for (int i = 1; i <= N; i++) {
vector<ll> newsum(M + 1);
for (int j = 0; j <= M; j++) {
newsum[j] = 0;
}
for (int j = 1; j <= M; j++) {
if (S[i - 1] == T[j - 1]) {
ll r = sum[j - 1];
r %= Mod;
DP[i][j] = r;
}
newsum[j] = newsum[j - 1] + DP[i][j];
newsum[j] %= Mod;
ans += DP[i][j];
ans %= Mod;
}
for (int j = 0; j <= M; j++) {
sum[j] += newsum[j];
sum[j] %= Mod;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
int N, M;
cin >> N >> M;
int S[N];
int T[M];
for (int i = 0; i < N; i++)
cin >> S[i];
for (int i = 0; i < M; i++)
cin >> T[i];
ll DP[N + 1][M + 1];
vector<ll> sum(M + 1);
ll ans = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
DP[i][j] = 0;
}
}
for (int i = 0; i <= M; i++) {
sum[i] = 1;
}
DP[0][0] = 1;
for (int i = 1; i <= N; i++) {
vector<ll> newsum(M + 1);
for (int j = 0; j <= M; j++) {
newsum[j] = 0;
}
for (int j = 1; j <= M; j++) {
if (S[i - 1] == T[j - 1]) {
ll r = sum[j - 1];
r %= Mod;
DP[i][j] = r;
}
newsum[j] = newsum[j - 1] + DP[i][j];
newsum[j] %= Mod;
ans += DP[i][j];
ans %= Mod;
}
for (int j = 0; j <= M; j++) {
sum[j] += newsum[j];
sum[j] %= Mod;
}
}
cout << ans << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define lowbit(x) ((x) & -(x))
const int maxn = (int)1e5 + 20;
const int MOD = 1e9 + 7;
LL fp(LL a, LL n, LL m = MOD) {
LL res = 1;
for (; n; n >>= 1, a = a * a % m)
if (n & 1)
res = res * a % m;
return res;
}
int n, m;
int s[1111], t[1111];
int dp[1111][1111];
void work() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> s[i];
for (int j = 1; j <= m; j++)
cin >> t[j];
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
for (int j = 0; j <= m; j++)
dp[0][j] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
if (s[i] == t[j])
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
}
cout << dp[n][m] << endl;
}
int main() {
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
#endif // yukihana0416
work();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define lowbit(x) ((x) & -(x))
const int maxn = (int)1e5 + 20;
const int MOD = 1e9 + 7;
LL fp(LL a, LL n, LL m = MOD) {
LL res = 1;
for (; n; n >>= 1, a = a * a % m)
if (n & 1)
res = res * a % m;
return res;
}
int n, m;
int s[3333], t[3333];
int dp[3333][3333];
void work() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> s[i];
for (int j = 1; j <= m; j++)
cin >> t[j];
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
for (int j = 0; j <= m; j++)
dp[0][j] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
if (s[i] == t[j])
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] = (dp[i][j] % MOD + MOD) % MOD;
}
cout << dp[n][m] << endl;
}
int main() {
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
#endif // yukihana0416
work();
return 0;
}
| replace | 18 | 20 | 18 | 20 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define _for(i, j, N) for (int i = (j); i < (N); i++)
#define _rep(i, j, N) for (int i = (j); i <= (N); i++)
#define ALL(x) x.begin(), x.end()
#define pb push_back
#define mk make_pair
typedef long long LL;
typedef pair<int, int> Interval;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
_for(i, 0, v.size()) os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (typename set<T>::iterator it = v.begin(); it != v.end(); it++)
os << *it << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
os << v.first << " " << v.second << endl;
return os;
}
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int maxh = 1e3 + 5;
int N, M;
vector<int> A;
vector<int> B;
int dp[maxh][maxh];
int add(LL a, LL b) { return (int)((a + b) % mod); }
int sub(LL a, LL b) { return (int)((a - b + mod) % mod); }
int main() {
cin >> N >> M;
_for(i, 0, N) {
int num;
scanf("%d", &num);
A.push_back(num);
}
_for(i, 0, M) {
int num;
scanf("%d", &num);
B.push_back(num);
}
_rep(i, 0, N) { dp[0][i] = 1; }
_rep(i, 0, M) { dp[i][0] = 1; }
_rep(i, 1, M) {
_rep(j, 1, N) {
if (B[i - 1] == A[j - 1]) {
dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
} else {
dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
dp[i][j] = sub(dp[i][j], dp[i - 1][j - 1]);
}
}
}
/*
_rep(i,0,M){
_rep(j,0,N){
printf("%d ",dp[i][j]);
}
printf("\n");
}
*/
cout << dp[M][N] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _for(i, j, N) for (int i = (j); i < (N); i++)
#define _rep(i, j, N) for (int i = (j); i <= (N); i++)
#define ALL(x) x.begin(), x.end()
#define pb push_back
#define mk make_pair
typedef long long LL;
typedef pair<int, int> Interval;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
_for(i, 0, v.size()) os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (typename set<T>::iterator it = v.begin(); it != v.end(); it++)
os << *it << " ";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
os << v.first << " " << v.second << endl;
return os;
}
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int maxh = 2e3 + 5;
int N, M;
vector<int> A;
vector<int> B;
int dp[maxh][maxh];
int add(LL a, LL b) { return (int)((a + b) % mod); }
int sub(LL a, LL b) { return (int)((a - b + mod) % mod); }
int main() {
cin >> N >> M;
_for(i, 0, N) {
int num;
scanf("%d", &num);
A.push_back(num);
}
_for(i, 0, M) {
int num;
scanf("%d", &num);
B.push_back(num);
}
_rep(i, 0, N) { dp[0][i] = 1; }
_rep(i, 0, M) { dp[i][0] = 1; }
_rep(i, 1, M) {
_rep(j, 1, N) {
if (B[i - 1] == A[j - 1]) {
dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
} else {
dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
dp[i][j] = sub(dp[i][j], dp[i - 1][j - 1]);
}
}
}
/*
_rep(i,0,M){
_rep(j,0,N){
printf("%d ",dp[i][j]);
}
printf("\n");
}
*/
cout << dp[M][N] << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, m) for (long long i = 0; i < m; i++)
#define per(i, m) for (long long i = m - 1; i >= 0; i--)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define ROF(i, n, m) for (long long i = m - 1; i >= n; i--)
#define SORT(v, n) \
do { \
sort(v, v + n); \
reverse(v, v + n); \
} while (0)
#define all(x) (x).begin(), (x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;
ll POW(ll x, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return POW(x * x, n / 2) % MOD;
return x % MOD * POW(x, n - 1) % MOD;
}
ll POW2(ll x, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return POW2(x * x, n / 2);
return x * POW2(x, n - 1);
}
ll POW3(ll x, ll n, ll m) {
x %= m;
if (n == 0)
return 1;
if (n % 2 == 0)
return POW3(x * x, n / 2, m) % m;
return x * POW3(x, n - 1, m) % m;
}
ll gcd(ll u, ll v) {
ll r;
while (0 != v) {
r = u % v;
u = v;
v = r;
}
return u;
}
ll lcm(ll u, ll v) { return u * v / gcd(u, v); }
ll KAI(ll m) {
if (m < 0)
return 0;
if (m == 0)
return 1;
return m * KAI(m - 1) % MOD;
}
ll KAI2(ll m) {
if (m < 0)
return 0;
if (m == 0)
return 1;
return m * KAI2(m - 1);
}
ll extGCD(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
inline ll mod(ll a, ll m) { return (a % m + m) % m; }
ll modinv(ll a) {
ll x, y;
extGCD(a, MOD, x, y);
return mod(x, MOD);
}
ll COM(ll m, ll n) {
if (m < n)
return 0;
if (n < 0)
return 0;
if (n == 0)
return 1;
if (m == n)
return 1;
return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD;
}
ll COM2(ll m, ll n) {
if (m < n)
return 0;
if (n < 0)
return 0;
if (n == 0)
return 1;
if (m == n)
return 1;
return KAI2(m) / KAI2(n) / KAI2(m - n);
}
ll DEC(ll x, ll m, ll n) // xのm進数でのx^nの位の値
{
return x % POW(m, n + 1) / POW(m, n);
}
ll keta(ll x, ll n) // xのn進数での桁数
{
if (x == 0)
return 0;
return keta(x / n, n) + 1;
}
ll DIV(ll x, ll n) // x!のnで割り切れる回数
{
if (x == 0)
return 0;
return x / n + DIV(x / n, n);
}
ll ORD(ll x, ll n) // xのnで割り切れる回数
{
if (x == 0)
return INF;
if (x % n != 0)
return 0;
return 1 + ORD(x / n, n);
}
ll SGS(ll x, ll y, ll m) // 1+x+…+x^(y-1)をmで割った余り
{
if (y == 0)
return 0;
if (y % 2 == 0) {
return (1 + POW3(x, y / 2, m)) * SGS(x, y / 2, m) % m;
}
return (1 + x * SGS(x, y - 1, m)) % m;
}
ll SSGS(ll x, ll y, ll m) // Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り
{
if (y == 0)
return 0;
if (y == 1)
return 1;
if (y % 2 == 0) {
return (SSGS(x, y / 2, m) * (POW3(x, y / 2, m) + 1) % m +
SGS(x, y / 2, m) * y / 2 % m) %
m;
}
return (SSGS(x, y - 1, m) * x % m + y) % m;
}
int main() {
ll n, m, s[2100], t[2100], p[210][210] = {}, ans = 0, q[210][210] = {};
cin >> n >> m;
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
rep(i, n) {
rep(j, m) {
if (s[i] == t[j]) {
p[i][j]++;
if (j != 0 && i != 0)
p[i][j] = (p[i][j] + q[i - 1][j - 1]) % MOD;
}
if (j == 0 && i == 0) {
q[i][j] = p[i][j];
} else if (j == 0) {
q[i][j] = (q[i - 1][j] + p[i][j]) % MOD;
} else if (i == 0) {
q[i][j] = (q[i][j - 1] + p[i][j]) % MOD;
} else {
q[i][j] = (q[i - 1][j] + q[i][j - 1] - q[i - 1][j - 1] + p[i][j]) % MOD;
}
}
}
rep(i, n) {
rep(j, m) { ans = (ans + p[i][j]) % MOD; }
}
printf("%lld", (ans + 1 + MOD) % MOD);
} | #include <bits/stdc++.h>
#define rep(i, m) for (long long i = 0; i < m; i++)
#define per(i, m) for (long long i = m - 1; i >= 0; i--)
#define FOR(i, n, m) for (long long i = n; i < m; i++)
#define ROF(i, n, m) for (long long i = m - 1; i >= n; i--)
#define SORT(v, n) \
do { \
sort(v, v + n); \
reverse(v, v + n); \
} while (0)
#define all(x) (x).begin(), (x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;
ll POW(ll x, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return POW(x * x, n / 2) % MOD;
return x % MOD * POW(x, n - 1) % MOD;
}
ll POW2(ll x, ll n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return POW2(x * x, n / 2);
return x * POW2(x, n - 1);
}
ll POW3(ll x, ll n, ll m) {
x %= m;
if (n == 0)
return 1;
if (n % 2 == 0)
return POW3(x * x, n / 2, m) % m;
return x * POW3(x, n - 1, m) % m;
}
ll gcd(ll u, ll v) {
ll r;
while (0 != v) {
r = u % v;
u = v;
v = r;
}
return u;
}
ll lcm(ll u, ll v) { return u * v / gcd(u, v); }
ll KAI(ll m) {
if (m < 0)
return 0;
if (m == 0)
return 1;
return m * KAI(m - 1) % MOD;
}
ll KAI2(ll m) {
if (m < 0)
return 0;
if (m == 0)
return 1;
return m * KAI2(m - 1);
}
ll extGCD(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
inline ll mod(ll a, ll m) { return (a % m + m) % m; }
ll modinv(ll a) {
ll x, y;
extGCD(a, MOD, x, y);
return mod(x, MOD);
}
ll COM(ll m, ll n) {
if (m < n)
return 0;
if (n < 0)
return 0;
if (n == 0)
return 1;
if (m == n)
return 1;
return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD;
}
ll COM2(ll m, ll n) {
if (m < n)
return 0;
if (n < 0)
return 0;
if (n == 0)
return 1;
if (m == n)
return 1;
return KAI2(m) / KAI2(n) / KAI2(m - n);
}
ll DEC(ll x, ll m, ll n) // xのm進数でのx^nの位の値
{
return x % POW(m, n + 1) / POW(m, n);
}
ll keta(ll x, ll n) // xのn進数での桁数
{
if (x == 0)
return 0;
return keta(x / n, n) + 1;
}
ll DIV(ll x, ll n) // x!のnで割り切れる回数
{
if (x == 0)
return 0;
return x / n + DIV(x / n, n);
}
ll ORD(ll x, ll n) // xのnで割り切れる回数
{
if (x == 0)
return INF;
if (x % n != 0)
return 0;
return 1 + ORD(x / n, n);
}
ll SGS(ll x, ll y, ll m) // 1+x+…+x^(y-1)をmで割った余り
{
if (y == 0)
return 0;
if (y % 2 == 0) {
return (1 + POW3(x, y / 2, m)) * SGS(x, y / 2, m) % m;
}
return (1 + x * SGS(x, y - 1, m)) % m;
}
ll SSGS(ll x, ll y, ll m) // Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り
{
if (y == 0)
return 0;
if (y == 1)
return 1;
if (y % 2 == 0) {
return (SSGS(x, y / 2, m) * (POW3(x, y / 2, m) + 1) % m +
SGS(x, y / 2, m) * y / 2 % m) %
m;
}
return (SSGS(x, y - 1, m) * x % m + y) % m;
}
int main() {
ll n, m, s[2100], t[2100], p[2100][2100] = {}, ans = 0, q[2100][2100] = {};
cin >> n >> m;
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
rep(i, n) {
rep(j, m) {
if (s[i] == t[j]) {
p[i][j]++;
if (j != 0 && i != 0)
p[i][j] = (p[i][j] + q[i - 1][j - 1]) % MOD;
}
if (j == 0 && i == 0) {
q[i][j] = p[i][j];
} else if (j == 0) {
q[i][j] = (q[i - 1][j] + p[i][j]) % MOD;
} else if (i == 0) {
q[i][j] = (q[i][j - 1] + p[i][j]) % MOD;
} else {
q[i][j] = (q[i - 1][j] + q[i][j - 1] - q[i - 1][j - 1] + p[i][j]) % MOD;
}
}
}
rep(i, n) {
rep(j, m) { ans = (ans + p[i][j]) % MOD; }
}
printf("%lld", (ans + 1 + MOD) % MOD);
} | replace | 172 | 173 | 172 | 173 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define IFOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR((i), 0, (n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> void print_container(T &container, string delim = " ") {
bool first = true;
for (auto &t : container) {
if (!first) {
cout << delim;
}
first = false;
cout << t;
}
cout << endl;
}
const int MOD = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
REP(i, n) { cin >> s[i]; }
REP(i, m) { cin >> t[i]; }
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
IFOR(i, 0, n) { dp[i][0] = dp[0][i] = 1; }
IFOR(i, 1, n) {
map<int, ll> accum;
IFOR(j, 1, m) {
dp[i][j] = dp[i - 1][j];
accum[t[j - 1]] = (accum[t[j - 1]] + dp[i - 1][j - 1]) % MOD;
dp[i][j] = (dp[i][j] + accum[s[i - 1]]) % MOD;
}
}
cout << dp[n][m] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define IFOR(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR((i), 0, (n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> void print_container(T &container, string delim = " ") {
bool first = true;
for (auto &t : container) {
if (!first) {
cout << delim;
}
first = false;
cout << t;
}
cout << endl;
}
const int MOD = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
REP(i, n) { cin >> s[i]; }
REP(i, m) { cin >> t[i]; }
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
IFOR(i, 0, n) { dp[i][0] = 1; }
IFOR(i, 0, m) { dp[0][i] = 1; }
IFOR(i, 1, n) {
map<int, ll> accum;
IFOR(j, 1, m) {
dp[i][j] = dp[i - 1][j];
accum[t[j - 1]] = (accum[t[j - 1]] + dp[i - 1][j - 1]) % MOD;
dp[i][j] = (dp[i][j] + accum[s[i - 1]]) % MOD;
}
}
cout << dp[n][m] << endl;
return 0;
} | replace | 57 | 58 | 57 | 59 | 0 | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cin;
using std::cout;
using std::endl;
template <typename T> std::vector<T> make_v(size_t a) {
return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
int main() {
int n;
scanf("%d", &n);
std::vector<i64> x(n), y(n);
std::vector<char> d(n);
std::vector<i64> D, U, L, R;
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &x[i], &y[i]);
cin >> d[i];
if (d[i] == 'L')
L.push_back(x[i]); // -1
if (d[i] == 'R')
R.push_back(x[i]); // +1
if (d[i] == 'D')
D.push_back(y[i]); // -1
if (d[i] == 'U')
U.push_back(y[i]); // +1
}
sort(begin(L), end(L));
sort(begin(R), end(R));
sort(begin(D), end(D));
sort(begin(U), end(U));
using ld = long double;
auto calc = [&](ld t) {
ld xma = -1e18, xmi = 1e18, yma = -1e18, ymi = 1e18;
for (int i = 0; i < n; i++) {
ld X = x[i], Y = y[i];
if (d[i] == 'L')
X -= t;
if (d[i] == 'R')
X += t;
if (d[i] == 'D')
Y -= t;
if (d[i] == 'U')
Y += t;
xma = std::max(xma, X);
xmi = std::min(xmi, X);
yma = std::max(yma, Y);
ymi = std::min(ymi, Y);
}
return (xma - xmi) * (yma - ymi);
};
auto latte = [&](i64 t, bool f) {
i64 xma = -(1LL << 60), xmi = 1LL << 60;
i64 yma = -(1LL << 60), ymi = 1LL << 60;
for (int i = 0; i < n; i++) {
i64 X = x[i], Y = y[i];
if (d[i] == 'L')
X -= t;
if (d[i] == 'R')
X += t;
if (d[i] == 'D')
Y -= t;
if (d[i] == 'U')
Y += t;
xma = std::max(xma, X);
xmi = std::min(xmi, X);
yma = std::max(yma, Y);
ymi = std::min(ymi, Y);
}
if (f)
return xma - xmi;
return yma - ymi;
};
auto getSegment = [&](int D, bool f) {
i64 ok = 0, ng = 1LL << 60;
for (int i = 0; i < 200 and std::abs(ok - ng) > 1; i++) {
i64 mid = (ok + ng) >> 1;
int d = latte(mid + 1, f) - latte(mid, f);
if (d <= D)
ok = mid;
else
ng = mid;
}
return ok + 1;
};
ld ans = 1e18;
if (false and std::max(L.size(), R.size()) <= 1 or
std::max(U.size(), D.size()) <= 1 or L.size() + R.size() == 2 or
U.size() + D.size() == 2) {
ld left = 0, right = 1e16;
for (int i = 0; i < 200; i++) {
ld ml = (left + left + right) / 3.;
ld mr = (left + right + right) / 3.;
if (calc(ml) <= calc(mr))
right = mr;
else
left = ml;
}
ans = calc((left + right) / 2.);
} else {
std::vector<i64> vec = {0, 1LL << 60};
for (int D = -4; D < 5; D++) {
i64 xL = getSegment(D - 1, true), xR = getSegment(D, true);
i64 yL = getSegment(D - 1, false), yR = getSegment(D, false);
vec.push_back(xL);
vec.push_back(xR);
vec.push_back(yL);
vec.push_back(yR);
}
sort(begin(vec), end(vec));
vec.erase(unique(begin(vec), end(vec)), end(vec));
for (int i = 0; i < (int)vec.size() - 1; i++) {
ld left = vec[i], right = vec[i + 1];
for (int i = 0; i < 175; i++) {
ld ml = (left + left + right) / 3.;
ld mr = (left + right + right) / 3.;
ld L = calc(ml), R = calc(mr);
ans = std::min({ans, L, R});
if (L <= R)
right = mr;
else
left = ml;
}
}
}
printf("%.12Lf\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cin;
using std::cout;
using std::endl;
template <typename T> std::vector<T> make_v(size_t a) {
return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
int main() {
int n;
scanf("%d", &n);
std::vector<i64> x(n), y(n);
std::vector<char> d(n);
std::vector<i64> D, U, L, R;
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &x[i], &y[i]);
cin >> d[i];
if (d[i] == 'L')
L.push_back(x[i]); // -1
if (d[i] == 'R')
R.push_back(x[i]); // +1
if (d[i] == 'D')
D.push_back(y[i]); // -1
if (d[i] == 'U')
U.push_back(y[i]); // +1
}
sort(begin(L), end(L));
sort(begin(R), end(R));
sort(begin(D), end(D));
sort(begin(U), end(U));
using ld = long double;
auto calc = [&](ld t) {
ld xma = -1e18, xmi = 1e18, yma = -1e18, ymi = 1e18;
for (int i = 0; i < n; i++) {
ld X = x[i], Y = y[i];
if (d[i] == 'L')
X -= t;
if (d[i] == 'R')
X += t;
if (d[i] == 'D')
Y -= t;
if (d[i] == 'U')
Y += t;
xma = std::max(xma, X);
xmi = std::min(xmi, X);
yma = std::max(yma, Y);
ymi = std::min(ymi, Y);
}
return (xma - xmi) * (yma - ymi);
};
auto latte = [&](i64 t, bool f) {
i64 xma = -(1LL << 60), xmi = 1LL << 60;
i64 yma = -(1LL << 60), ymi = 1LL << 60;
for (int i = 0; i < n; i++) {
i64 X = x[i], Y = y[i];
if (d[i] == 'L')
X -= t;
if (d[i] == 'R')
X += t;
if (d[i] == 'D')
Y -= t;
if (d[i] == 'U')
Y += t;
xma = std::max(xma, X);
xmi = std::min(xmi, X);
yma = std::max(yma, Y);
ymi = std::min(ymi, Y);
}
if (f)
return xma - xmi;
return yma - ymi;
};
auto getSegment = [&](int D, bool f) {
i64 ok = 0, ng = 1LL << 60;
for (int i = 0; i < 200 and std::abs(ok - ng) > 1; i++) {
i64 mid = (ok + ng) >> 1;
int d = latte(mid + 1, f) - latte(mid, f);
if (d <= D)
ok = mid;
else
ng = mid;
}
return ok + 1;
};
ld ans = 1e18;
if (false and std::max(L.size(), R.size()) <= 1 or
std::max(U.size(), D.size()) <= 1 or L.size() + R.size() == 2 or
U.size() + D.size() == 2) {
ld left = 0, right = 1e16;
for (int i = 0; i < 200; i++) {
ld ml = (left + left + right) / 3.;
ld mr = (left + right + right) / 3.;
if (calc(ml) <= calc(mr))
right = mr;
else
left = ml;
}
ans = calc((left + right) / 2.);
} else {
std::vector<i64> vec = {0, 1LL << 60};
for (int D = -3; D < 4; D++) {
i64 xL = getSegment(D - 1, true), xR = getSegment(D, true);
i64 yL = getSegment(D - 1, false), yR = getSegment(D, false);
vec.push_back(xL);
vec.push_back(xR);
vec.push_back(yL);
vec.push_back(yR);
}
sort(begin(vec), end(vec));
vec.erase(unique(begin(vec), end(vec)), end(vec));
for (int i = 0; i < (int)vec.size() - 1; i++) {
ld left = vec[i], right = vec[i + 1];
for (int i = 0; i < 175; i++) {
ld ml = (left + left + right) / 3.;
ld mr = (left + right + right) / 3.;
ld L = calc(ml), R = calc(mr);
ans = std::min({ans, L, R});
if (L <= R)
right = mr;
else
left = ml;
}
}
}
printf("%.12Lf\n", ans);
return 0;
}
| replace | 117 | 118 | 117 | 118 | TLE | |
p03004 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
pair<double, double> a[maxn];
double dx[maxn], dy[maxn], ans, lb = 0, lbb, rbb, rb = 2e8;
int n;
char c;
double calc(double t) {
double u, d, l, r;
l = r = a[0].first + t * dx[0], u = d = a[0].second + t * dy[0];
for (int i = 1; i < n; i++) {
l = min(l, a[i].first + t * dx[i]);
r = max(r, a[i].first + t * dx[i]);
u = max(u, a[i].second + t * dy[i]);
d = min(d, a[i].second + t * dy[i]);
}
return (u - d) * (r - l);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second >> c;
if (c == 'U')
dx[i] = 0, dy[i] = 1;
else if (c == 'D')
dx[i] = 0, dy[i] = -1;
else if (c == 'R')
dx[i] = 1, dy[i] = 0;
else
dx[i] = -1, dy[i] = 0;
}
ans = calc(0);
while (rb - lb > 1e-10) {
lbb = (2 * lb + rb) / 3;
rbb = (lb + 2 * rb) / 3;
if (calc(lbb) < calc(rbb))
rb = rbb;
else
lb = lbb;
}
cout << setprecision(10) << fixed << calc(lb) << '\n';
return 0;
}
| #pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
pair<double, double> a[maxn];
double dx[maxn], dy[maxn], ans, lb = 0, lbb, rbb, rb = 2e8;
int n;
char c;
double calc(double t) {
double u, d, l, r;
l = r = a[0].first + t * dx[0], u = d = a[0].second + t * dy[0];
for (int i = 1; i < n; i++) {
l = min(l, a[i].first + t * dx[i]);
r = max(r, a[i].first + t * dx[i]);
u = max(u, a[i].second + t * dy[i]);
d = min(d, a[i].second + t * dy[i]);
}
return (u - d) * (r - l);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second >> c;
if (c == 'U')
dx[i] = 0, dy[i] = 1;
else if (c == 'D')
dx[i] = 0, dy[i] = -1;
else if (c == 'R')
dx[i] = 1, dy[i] = 0;
else
dx[i] = -1, dy[i] = 0;
}
ans = calc(0);
for (int i = 0; i < 1000; i++) {
lbb = (2 * lb + rb) / 3;
rbb = (lb + 2 * rb) / 3;
if (calc(lbb) < calc(rbb))
rb = rbb;
else
lb = lbb;
}
cout << setprecision(10) << fixed << calc(lb) << '\n';
return 0;
}
| replace | 40 | 41 | 40 | 41 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
ll n;
double x[110000], y[110000];
char d[110000];
const double EPS = 1e-10;
double f(double a) {
double xmx = 1e8 * 3 * -1, xmi = 1e8 * 3, ymx = 1e8 * 3 * -1, ymi = 1e8 * 3;
REP(i, n) {
double nowx = x[i], nowy = y[i];
if (d[i] == 'R')
nowx += a;
if (d[i] == 'L')
nowx -= a;
if (d[i] == 'U')
nowy += a;
if (d[i] == 'D')
nowy -= a;
xmx = max(xmx, nowx);
xmi = min(xmi, nowx);
ymx = max(ymx, nowy);
ymi = min(ymi, nowy);
// cout << nowx << " " << nowy << endl;
}
// cout << xmx << " " << xmi << " " << ymx << " " << ymi << endl;
return (xmx - xmi) * (ymx - ymi);
}
int main() {
cin >> n;
REP(i, n) { cin >> x[i] >> y[i] >> d[i]; }
double low = 0.0, high = 1e8 * 3;
while (high - low > EPS) {
double width = high - low, ml = low + width / 3.0,
mr = low + 2.0 * width / 3.0;
if (f(ml) <= f(mr)) {
high = mr;
} else {
low = ml;
}
}
// cout << (high + low) * 0.5 << endl;
cout << setprecision(10) << fixed << f((high + low) * 0.5) << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
ll n;
double x[110000], y[110000];
char d[110000];
const double EPS = 1e-10;
double f(double a) {
double xmx = 1e8 * 3 * -1, xmi = 1e8 * 3, ymx = 1e8 * 3 * -1, ymi = 1e8 * 3;
REP(i, n) {
double nowx = x[i], nowy = y[i];
if (d[i] == 'R')
nowx += a;
if (d[i] == 'L')
nowx -= a;
if (d[i] == 'U')
nowy += a;
if (d[i] == 'D')
nowy -= a;
xmx = max(xmx, nowx);
xmi = min(xmi, nowx);
ymx = max(ymx, nowy);
ymi = min(ymi, nowy);
// cout << nowx << " " << nowy << endl;
}
// cout << xmx << " " << xmi << " " << ymx << " " << ymi << endl;
return (xmx - xmi) * (ymx - ymi);
}
int main() {
cin >> n;
REP(i, n) { cin >> x[i] >> y[i] >> d[i]; }
double low = 0.0, high = 1e8 * 3;
REP(i, 300) {
double width = high - low, ml = low + width / 3.0,
mr = low + 2.0 * width / 3.0;
if (f(ml) <= f(mr)) {
high = mr;
} else {
low = ml;
}
}
// cout << (high + low) * 0.5 << endl;
cout << setprecision(10) << fixed << f((high + low) * 0.5) << endl;
}
| replace | 58 | 59 | 58 | 59 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
Int n;
typedef pair<Int, Int> P;
vector<P> x, y;
constexpr double EPS = 1e-14;
double func(double t) {
double xmi = 1e10, ymi = 1e10, xma = -1e10, yma = -1e10;
for (Int i = 0; i < n; ++i) {
xmi = min(xmi, x[i].first + t * x[i].second);
xma = max(xma, x[i].first + t * x[i].second);
ymi = min(ymi, y[i].first + t * y[i].second);
yma = max(yma, y[i].first + t * y[i].second);
}
return (xma - xmi) * (yma - ymi);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (Int i = 0; i < n; ++i) {
int tx, ty;
char c;
cin >> tx >> ty >> c;
if (c == 'R' || c == 'L') {
y.push_back(P(ty, 0));
x.push_back(P(tx, c == 'R' ? 1 : -1));
} else {
x.push_back(P(tx, 0));
y.push_back(P(ty, c == 'U' ? 1 : -1));
}
}
double tl = 0.0, tr = 1e10;
while (tl + EPS < tr) {
double t1 = (2 * tl + tr) / 3;
double t2 = (tl + 2 * tr) / 3;
double f = func(t1), g = func(t2);
if (f < g) {
tr = t2;
} else {
tl = t1;
}
}
cout << fixed << setprecision(14) << func(tl) << "\n";
} | #include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
Int n;
typedef pair<Int, Int> P;
vector<P> x, y;
constexpr double EPS = 1e-14;
double func(double t) {
double xmi = 1e10, ymi = 1e10, xma = -1e10, yma = -1e10;
for (Int i = 0; i < n; ++i) {
xmi = min(xmi, x[i].first + t * x[i].second);
xma = max(xma, x[i].first + t * x[i].second);
ymi = min(ymi, y[i].first + t * y[i].second);
yma = max(yma, y[i].first + t * y[i].second);
}
return (xma - xmi) * (yma - ymi);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (Int i = 0; i < n; ++i) {
int tx, ty;
char c;
cin >> tx >> ty >> c;
if (c == 'R' || c == 'L') {
y.push_back(P(ty, 0));
x.push_back(P(tx, c == 'R' ? 1 : -1));
} else {
x.push_back(P(tx, 0));
y.push_back(P(ty, c == 'U' ? 1 : -1));
}
}
double tl = 0.0, tr = 1e10;
for (int i = 0; i < 150; ++i) {
double t1 = (2 * tl + tr) / 3;
double t2 = (tl + 2 * tr) / 3;
double f = func(t1), g = func(t2);
if (f < g) {
tr = t2;
} else {
tl = t1;
}
}
cout << fixed << setprecision(14) << func(tl) << "\n";
} | replace | 37 | 38 | 37 | 38 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR \
if (DEBUG) \
cerr
#define MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
#define pr(...) \
CERR << MACRO(__VA_ARGS__, pr10, pr9, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define pr9(a, b, c, d, e, f, g, h, i) pr1(a) << pr8(b, c, d, e, f, g, h, i)
#define pr10(a, b, c, d, e, f, g, h, i, j) \
pr1(a) << pr9(b, c, d, e, f, g, h, i, j)
#define prArr(a) \
{ \
CERR << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
CERR << (i++ ? ", " : "") << t; \
CERR << "}" << endl; \
}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a) {
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Double, Double>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
vector<P> L, R, U, D;
vector<Double> calc(Double t) {
const Double INF = 1e30;
Double x = INF, X = -INF, y = INF, Y = -INF;
for (auto p : L)
Min(x, p.first - t), Max(X, p.first - t);
for (auto p : R)
Min(x, p.first + t), Max(X, p.first + t);
for (auto p : D)
Min(y, p.second - t), Max(Y, p.second - t);
for (auto p : U)
Min(y, p.second + t), Max(Y, p.second + t);
for (auto p : L)
Min(y, p.second), Max(Y, p.second);
for (auto p : R)
Min(y, p.second), Max(Y, p.second);
for (auto p : D)
Min(x, p.first), Max(X, p.first);
for (auto p : U)
Min(x, p.first), Max(X, p.first);
return {x, X, y, Y};
}
tuple<Double, Double> search(Int idx) {
const Int f = idx == 0 || idx == 2 ? -1 : 1;
const Double INF = 5e8;
const Double EP = 0.1;
Double a, b;
{
Double L = 0, R = INF;
for (Int i = 0; i < 100; i++) {
Double M1 = (L + R) / 2;
Double M2 = (L + R) / 2 + EP;
Double y1 = f * calc(M1)[idx];
Double y2 = f * calc(M2)[idx];
y1 > y2 ? (L = M1) : (R = M1);
}
a = L;
}
{
Double L = 0, R = INF;
for (Int i = 0; i < 100; i++) {
Double M1 = (L + R) / 2;
Double M2 = (L + R) / 2 + EP;
Double y1 = f * calc(M1)[idx];
Double y2 = f * calc(M2)[idx];
y1 >= y2 ? (L = M1) : (R = M1);
}
b = L;
}
return make_tuple(a, b);
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int N;
cin >> N;
for (Int i = 0; i < N; i++) {
Int x, y;
char d;
cin >> x >> y >> d;
if (d == 'L')
L.emplace_back(x, y);
if (d == 'R')
R.emplace_back(x, y);
if (d == 'U')
U.emplace_back(x, y);
if (d == 'D')
D.emplace_back(x, y);
}
vector<Double> A;
for (Int i = 0; i < 4; i++) {
Double a, b;
tie(a, b) = search(i);
A.push_back(a);
A.push_back(b);
pr(i, a, b);
}
Double ans = INF;
for (Double t : A) {
for (Int i = -1000; i < 1000; i++) {
Double tt = max<Double>(0, Int(t) + i * 0.1);
auto v = calc(tt);
Double score = (v[1] - v[0]) * (v[3] - v[2]);
Min(ans, score);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR \
if (DEBUG) \
cerr
#define MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
#define pr(...) \
CERR << MACRO(__VA_ARGS__, pr10, pr9, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define pr9(a, b, c, d, e, f, g, h, i) pr1(a) << pr8(b, c, d, e, f, g, h, i)
#define pr10(a, b, c, d, e, f, g, h, i, j) \
pr1(a) << pr9(b, c, d, e, f, g, h, i, j)
#define prArr(a) \
{ \
CERR << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
CERR << (i++ ? ", " : "") << t; \
CERR << "}" << endl; \
}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a) {
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Double, Double>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
vector<P> L, R, U, D;
vector<Double> calc(Double t) {
const Double INF = 1e30;
Double x = INF, X = -INF, y = INF, Y = -INF;
for (auto p : L)
Min(x, p.first - t), Max(X, p.first - t);
for (auto p : R)
Min(x, p.first + t), Max(X, p.first + t);
for (auto p : D)
Min(y, p.second - t), Max(Y, p.second - t);
for (auto p : U)
Min(y, p.second + t), Max(Y, p.second + t);
for (auto p : L)
Min(y, p.second), Max(Y, p.second);
for (auto p : R)
Min(y, p.second), Max(Y, p.second);
for (auto p : D)
Min(x, p.first), Max(X, p.first);
for (auto p : U)
Min(x, p.first), Max(X, p.first);
return {x, X, y, Y};
}
tuple<Double, Double> search(Int idx) {
const Int f = idx == 0 || idx == 2 ? -1 : 1;
const Double INF = 5e8;
const Double EP = 0.1;
Double a, b;
{
Double L = 0, R = INF;
for (Int i = 0; i < 100; i++) {
Double M1 = (L + R) / 2;
Double M2 = (L + R) / 2 + EP;
Double y1 = f * calc(M1)[idx];
Double y2 = f * calc(M2)[idx];
y1 > y2 ? (L = M1) : (R = M1);
}
a = L;
}
{
Double L = 0, R = INF;
for (Int i = 0; i < 100; i++) {
Double M1 = (L + R) / 2;
Double M2 = (L + R) / 2 + EP;
Double y1 = f * calc(M1)[idx];
Double y2 = f * calc(M2)[idx];
y1 >= y2 ? (L = M1) : (R = M1);
}
b = L;
}
return make_tuple(a, b);
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int N;
cin >> N;
for (Int i = 0; i < N; i++) {
Int x, y;
char d;
cin >> x >> y >> d;
if (d == 'L')
L.emplace_back(x, y);
if (d == 'R')
R.emplace_back(x, y);
if (d == 'U')
U.emplace_back(x, y);
if (d == 'D')
D.emplace_back(x, y);
}
vector<Double> A;
for (Int i = 0; i < 4; i++) {
Double a, b;
tie(a, b) = search(i);
A.push_back(a);
A.push_back(b);
pr(i, a, b);
}
Double ans = INF;
for (Double t : A) {
for (Int i = -100; i < 100; i++) {
Double tt = max<Double>(0, Int(t) + i * 0.1);
auto v = calc(tt);
Double score = (v[1] - v[0]) * (v[3] - v[2]);
Min(ans, score);
}
}
cout << ans << endl;
return 0;
}
| replace | 157 | 158 | 157 | 158 | TLE | |
p03004 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
vector<ll> R, L, U, D, X, Y;
vector<ll> cand;
ll ret;
void hoge(vector<ll> &V) {
if (V.size()) {
sort(ALL(V));
int x = V[0];
int y = V.back();
V.clear();
V = {x, y};
}
}
void hogev(vector<ll> &A, vector<ll> &B, int d) {
if (A.size() && B.size()) {
cand.push_back(abs(A[0] - B[0]) / d);
cand.push_back(abs(A[0] - B[1]) / d);
cand.push_back(abs(A[1] - B[0]) / d);
cand.push_back(abs(A[1] - B[1]) / d);
}
}
void test(pair<ll, ll> X, pair<ll, ll> Y) {
if (X.first <= Y.first && X.second <= Y.second)
return;
if (X.first >= Y.first && X.second >= Y.second)
return;
if (X.first > Y.first)
swap(X, Y);
ll d1 = Y.first - X.first;
ll d2 = Y.second - X.second;
}
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N;
FOR(i, N) {
cin >> x >> y >> s;
x *= 2;
y *= 2;
if (s == "L") {
L.push_back(x);
Y.push_back(y);
}
if (s == "R") {
R.push_back(x);
Y.push_back(y);
}
if (s == "U") {
U.push_back(y);
X.push_back(x);
}
if (s == "D") {
D.push_back(y);
X.push_back(x);
}
}
hoge(L);
hoge(R);
hoge(U);
hoge(D);
hoge(X);
hoge(Y);
cand.push_back(0);
cand.push_back(1 << 30);
hogev(L, X, 1);
hogev(R, X, 1);
hogev(L, R, 2);
hogev(U, Y, 1);
hogev(D, Y, 1);
hogev(U, D, 2);
sort(ALL(cand));
vector<pair<ll, ll>> V;
ret = 1LL << 60;
FORR(c, cand) {
ll x1 = 1LL << 40, x2 = -1LL << 40;
ll y1 = 1LL << 40, y2 = -1LL << 40;
if (L.size())
x1 = min(x1, L[0] - c), x2 = max(x2, L[1] - c);
if (R.size())
x1 = min(x1, R[0] + c), x2 = max(x2, R[1] + c);
if (X.size())
x1 = min(x1, X[0] + 0), x2 = max(x2, X[1] + 0);
if (U.size())
y1 = min(y1, U[0] + c), y2 = max(y2, U[1] + c);
if (D.size())
y1 = min(y1, D[0] - c), y2 = max(y2, D[1] - c);
if (Y.size())
y1 = min(y1, Y[0] + 0), y2 = max(y2, U[1] + 0);
V.push_back({x2 - x1, y2 - y1});
ret = min(ret, (x2 - x1) * (y2 - y1));
}
FOR(i, V.size() - 1) test(V[i], V[i + 1]);
_P("%.12lf\n", ret / 4.0);
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
vector<ll> R, L, U, D, X, Y;
vector<ll> cand;
ll ret;
void hoge(vector<ll> &V) {
if (V.size()) {
sort(ALL(V));
int x = V[0];
int y = V.back();
V.clear();
V = {x, y};
}
}
void hogev(vector<ll> &A, vector<ll> &B, int d) {
if (A.size() && B.size()) {
cand.push_back(abs(A[0] - B[0]) / d);
cand.push_back(abs(A[0] - B[1]) / d);
cand.push_back(abs(A[1] - B[0]) / d);
cand.push_back(abs(A[1] - B[1]) / d);
}
}
void test(pair<ll, ll> X, pair<ll, ll> Y) {
if (X.first <= Y.first && X.second <= Y.second)
return;
if (X.first >= Y.first && X.second >= Y.second)
return;
if (X.first > Y.first)
swap(X, Y);
ll d1 = Y.first - X.first;
ll d2 = Y.second - X.second;
}
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N;
FOR(i, N) {
cin >> x >> y >> s;
x *= 2;
y *= 2;
if (s == "L") {
L.push_back(x);
Y.push_back(y);
}
if (s == "R") {
R.push_back(x);
Y.push_back(y);
}
if (s == "U") {
U.push_back(y);
X.push_back(x);
}
if (s == "D") {
D.push_back(y);
X.push_back(x);
}
}
hoge(L);
hoge(R);
hoge(U);
hoge(D);
hoge(X);
hoge(Y);
cand.push_back(0);
cand.push_back(1 << 30);
hogev(L, X, 1);
hogev(R, X, 1);
hogev(L, R, 2);
hogev(U, Y, 1);
hogev(D, Y, 1);
hogev(U, D, 2);
sort(ALL(cand));
vector<pair<ll, ll>> V;
ret = 1LL << 60;
FORR(c, cand) {
ll x1 = 1LL << 40, x2 = -1LL << 40;
ll y1 = 1LL << 40, y2 = -1LL << 40;
if (L.size())
x1 = min(x1, L[0] - c), x2 = max(x2, L[1] - c);
if (R.size())
x1 = min(x1, R[0] + c), x2 = max(x2, R[1] + c);
if (X.size())
x1 = min(x1, X[0] + 0), x2 = max(x2, X[1] + 0);
if (U.size())
y1 = min(y1, U[0] + c), y2 = max(y2, U[1] + c);
if (D.size())
y1 = min(y1, D[0] - c), y2 = max(y2, D[1] - c);
if (Y.size())
y1 = min(y1, Y[0] + 0), y2 = max(y2, Y[1] + 0);
V.push_back({x2 - x1, y2 - y1});
ret = min(ret, (x2 - x1) * (y2 - y1));
}
FOR(i, V.size() - 1) test(V[i], V[i + 1]);
_P("%.12lf\n", ret / 4.0);
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| replace | 110 | 111 | 110 | 111 | -11 | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const double inf = 1e18;
double x[N], y[N];
double dx[N], dy[N];
int n;
double f(double a) {
double minx = inf, maxx = -inf, miny = inf, maxy = -inf;
for (int i = 0; i < n; i++) { // n个点
double nx = x[i] + a * dx[i];
double ny = y[i] + a * dy[i];
minx = min(minx, nx);
maxx = max(maxx, nx);
miny = min(miny, ny);
maxy = max(maxy, ny);
}
return (maxx - minx) * (maxy - miny);
}
double ternary_search(double l, double r) {
double ans = inf;
while (r - l > 1e-11) {
double m1 = l + (r - l) / 3;
double m2 = r - (r - l) / 3;
// double m1 = (l*2+r) / 3;
// double m2 = (r*2+l) / 3;
double f1 = f(m1);
double f2 = f(m2);
ans = min(ans, f1);
ans = min(ans, f2);
if (f1 < f2)
r = m2;
else
l = m1;
}
return ans;
}
int main() {
// while (cin >> n) {
cin >> n;
// memset(dx, 0, sizeof(dx));
// memset(dy, 0, sizeof(dy));
string s;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> s;
if (s == "R")
dx[i] = 1;
if (s == "L")
dx[i] = -1;
if (s == "U")
dy[i] = 1;
if (s == "D")
dy[i] = -1;
}
// cout << ternary_search(0, 1e9) << endl;
printf("%lf\n", ternary_search(0, 1e9));
// }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const double inf = 1e18;
double x[N], y[N];
double dx[N], dy[N];
int n;
double f(double a) {
double minx = inf, maxx = -inf, miny = inf, maxy = -inf;
for (int i = 0; i < n; i++) { // n个点
double nx = x[i] + a * dx[i];
double ny = y[i] + a * dy[i];
minx = min(minx, nx);
maxx = max(maxx, nx);
miny = min(miny, ny);
maxy = max(maxy, ny);
}
return (maxx - minx) * (maxy - miny);
}
double ternary_search(double l, double r) {
double ans = inf;
int times = 200;
while (times--) {
double m1 = l + (r - l) / 3;
double m2 = r - (r - l) / 3;
// double m1 = (l*2+r) / 3;
// double m2 = (r*2+l) / 3;
double f1 = f(m1);
double f2 = f(m2);
ans = min(ans, f1);
ans = min(ans, f2);
if (f1 < f2)
r = m2;
else
l = m1;
}
return ans;
}
int main() {
// while (cin >> n) {
cin >> n;
// memset(dx, 0, sizeof(dx));
// memset(dy, 0, sizeof(dy));
string s;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> s;
if (s == "R")
dx[i] = 1;
if (s == "L")
dx[i] = -1;
if (s == "U")
dy[i] = 1;
if (s == "D")
dy[i] = -1;
}
// cout << ternary_search(0, 1e9) << endl;
printf("%lf\n", ternary_search(0, 1e9));
// }
return 0;
} | replace | 24 | 25 | 24 | 26 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)998244353
#define INF LLONG_MAX / 10
#define P pair<int, int>
#define prique priority_queue
using namespace std;
int n, x[100010], y[100010];
char d[100010];
long double func(long double time) {
long double mi = 200000000, ma = -200000000;
rep(i, n) {
if (d[i] == 'R') {
mi = min(mi, x[i] + time);
ma = max(ma, x[i] + time);
} else if (d[i] == 'L') {
mi = min(mi, x[i] - time);
ma = max(ma, x[i] - time);
} else {
mi = min(mi, (long double)x[i]);
ma = max(ma, (long double)x[i]);
}
}
long double memo = ma - mi;
mi = 200000000;
ma = -200000000;
rep(i, n) {
if (d[i] == 'U') {
mi = min(mi, y[i] + time);
ma = max(ma, y[i] + time);
} else if (d[i] == 'D') {
mi = min(mi, y[i] - time);
ma = max(ma, y[i] - time);
} else {
mi = min(mi, (long double)y[i]);
ma = max(ma, (long double)y[i]);
}
}
return memo * (ma - mi);
}
signed main() {
cin >> n;
rep(i, n) cin >> x[i] >> y[i] >> d[i];
long double ok = 0, ng = 300000000;
rep(i, 10000) {
long double md1 = ok + (ng - ok) / 3, md2 = ok + (ng - ok) * 2 / 3;
if (func(md1) <= func(md2))
ng = md2;
else
ok = md1;
}
printf("%.12Lf\n", func(ng));
return 0;
} | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)998244353
#define INF LLONG_MAX / 10
#define P pair<int, int>
#define prique priority_queue
using namespace std;
int n, x[100010], y[100010];
char d[100010];
long double func(long double time) {
long double mi = 200000000, ma = -200000000;
rep(i, n) {
if (d[i] == 'R') {
mi = min(mi, x[i] + time);
ma = max(ma, x[i] + time);
} else if (d[i] == 'L') {
mi = min(mi, x[i] - time);
ma = max(ma, x[i] - time);
} else {
mi = min(mi, (long double)x[i]);
ma = max(ma, (long double)x[i]);
}
}
long double memo = ma - mi;
mi = 200000000;
ma = -200000000;
rep(i, n) {
if (d[i] == 'U') {
mi = min(mi, y[i] + time);
ma = max(ma, y[i] + time);
} else if (d[i] == 'D') {
mi = min(mi, y[i] - time);
ma = max(ma, y[i] - time);
} else {
mi = min(mi, (long double)y[i]);
ma = max(ma, (long double)y[i]);
}
}
return memo * (ma - mi);
}
signed main() {
cin >> n;
rep(i, n) cin >> x[i] >> y[i] >> d[i];
long double ok = 0, ng = 300000000;
rep(i, 500) {
long double md1 = ok + (ng - ok) / 3, md2 = ok + (ng - ok) * 2 / 3;
if (func(md1) <= func(md2))
ng = md2;
else
ok = md1;
}
printf("%.12Lf\n", func(ng));
return 0;
} | replace | 68 | 69 | 68 | 69 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T> T gcd(T a, T b) {
return ((a % b == 0) ? b : gcd(b, a % b));
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
namespace Problem {
using namespace std;
class Solver {
public:
int n;
vector<double> x, y, dx, dy;
Solver(LL n) : n(n), x(n), y(n), dx(n), dy(n){};
void solve() {
for (int i = 0; i < n; ++i) {
char c;
cin >> x[i] >> y[i] >> c;
if (c == 'R')
dx[i] = 1;
if (c == 'L')
dx[i] = -1;
if (c == 'U')
dy[i] = 1;
if (c == 'D')
dy[i] = -1;
}
double LB = 0;
double UB = 1e9;
auto xminmax = [&](double t) -> double {
double xmin = LINF;
double xmax = -LINF;
for (int i = 0; i < n; ++i) {
double xtmp = x[i] + dx[i] * t;
xmin = min(xmin, xtmp);
xmax = max(xmax, xtmp);
}
return xmax - xmin;
};
auto yminmax = [&](double t) -> double {
double ymin = LINF;
double ymax = -LINF;
for (int i = 0; i < n; ++i) {
double ytmp = y[i] + dy[i] * t;
ymin = min(ymin, ytmp);
ymax = max(ymax, ytmp);
}
return ymax - ymin;
};
auto area = [&](double t) -> double {
double xmin = LINF;
double xmax = -LINF;
double ymin = LINF;
double ymax = -LINF;
for (int i = 0; i < n; ++i) {
double xtmp = x[i] + dx[i] * t;
xmin = min(xmin, xtmp);
xmax = max(xmax, xtmp);
double ytmp = y[i] + dy[i] * t;
ymin = min(ymin, ytmp);
ymax = max(ymax, ytmp);
}
return (xmax - xmin) * (ymax - ymin);
};
double t1 = ternary_search(LB, UB, xminmax);
double t2 = ternary_search(LB, UB, yminmax);
double ans = ternary_search(max(LB, min(t1, t2) - 10ll),
min(UB, max(t1, t2) + 10ll), area);
DBG(t1, t2, ans);
cout << area(ans) << endl;
}
double ternary_search(double lb, double ub, function<double(double)> f) {
while (ub - lb > 1e-10) {
vector<double> res(4);
double m1 = lb + (ub - lb) / 3;
double m2 = m1 + (ub - m1) / 2;
res[0] = f(lb);
res[1] = f(m1);
res[2] = f(m2);
res[3] = f(ub);
int p = distance(res.begin(), min_element(res.begin(), res.end()));
if (p == 0) {
ub = m1;
} else if (p == 1) {
ub = m2;
} else if (p == 2) {
lb = m1;
} else {
lb = m2;
}
}
return ub;
}
};
} // namespace Problem
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
std::cerr << std::fixed << std::setprecision(12);
std::cout << std::fixed << std::setprecision(12);
long long n = 0;
std::cin >> n;
Problem::Solver sol(n);
sol.solve();
return 0;
}
| #include <bits/stdc++.h>
#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T> T gcd(T a, T b) {
return ((a % b == 0) ? b : gcd(b, a % b));
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
namespace Problem {
using namespace std;
class Solver {
public:
int n;
vector<double> x, y, dx, dy;
Solver(LL n) : n(n), x(n), y(n), dx(n), dy(n){};
void solve() {
for (int i = 0; i < n; ++i) {
char c;
cin >> x[i] >> y[i] >> c;
if (c == 'R')
dx[i] = 1;
if (c == 'L')
dx[i] = -1;
if (c == 'U')
dy[i] = 1;
if (c == 'D')
dy[i] = -1;
}
double LB = 0;
double UB = 1e9;
auto xminmax = [&](double t) -> double {
double xmin = LINF;
double xmax = -LINF;
for (int i = 0; i < n; ++i) {
double xtmp = x[i] + dx[i] * t;
xmin = min(xmin, xtmp);
xmax = max(xmax, xtmp);
}
return xmax - xmin;
};
auto yminmax = [&](double t) -> double {
double ymin = LINF;
double ymax = -LINF;
for (int i = 0; i < n; ++i) {
double ytmp = y[i] + dy[i] * t;
ymin = min(ymin, ytmp);
ymax = max(ymax, ytmp);
}
return ymax - ymin;
};
auto area = [&](double t) -> double {
double xmin = LINF;
double xmax = -LINF;
double ymin = LINF;
double ymax = -LINF;
for (int i = 0; i < n; ++i) {
double xtmp = x[i] + dx[i] * t;
xmin = min(xmin, xtmp);
xmax = max(xmax, xtmp);
double ytmp = y[i] + dy[i] * t;
ymin = min(ymin, ytmp);
ymax = max(ymax, ytmp);
}
return (xmax - xmin) * (ymax - ymin);
};
double t1 = ternary_search(LB, UB, xminmax);
double t2 = ternary_search(LB, UB, yminmax);
double ans = ternary_search(max(LB, min(t1, t2) - 10ll),
min(UB, max(t1, t2) + 10ll), area);
DBG(t1, t2, ans);
cout << area(ans) << endl;
}
double ternary_search(double lb, double ub, function<double(double)> f) {
for (int _ = 0; _ < 100; ++_) {
vector<double> res(4);
double m1 = lb + (ub - lb) / 3;
double m2 = m1 + (ub - m1) / 2;
res[0] = f(lb);
res[1] = f(m1);
res[2] = f(m2);
res[3] = f(ub);
int p = distance(res.begin(), min_element(res.begin(), res.end()));
if (p == 0) {
ub = m1;
} else if (p == 1) {
ub = m2;
} else if (p == 2) {
lb = m1;
} else {
lb = m2;
}
}
return ub;
}
};
} // namespace Problem
int main() {
std::cin.tie(0);
std::ios_base::sync_with_stdio(false);
std::cerr << std::fixed << std::setprecision(12);
std::cout << std::fixed << std::setprecision(12);
long long n = 0;
std::cin >> n;
Problem::Solver sol(n);
sol.solve();
return 0;
}
| replace | 86 | 87 | 86 | 87 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Point {
double x, y;
int dx, dy;
};
double simulate(vector<Point> points, double t) {
double maxX = -1e18, maxY = -1e18, minX = 1e18, minY = 1e18;
for (int i = 0; i < points.size(); ++i) {
points[i].x += points[i].dx * t;
points[i].y += points[i].dy * t;
maxX = max(maxX, points[i].x);
maxY = max(maxY, points[i].y);
minX = min(minX, points[i].x);
minY = min(minY, points[i].y);
}
return (maxY - minY) * (maxX - minX);
}
int main() {
int n;
cin >> n;
vector<Point> points(n);
for (int i = 0; i < n; ++i) {
cin >> points[i].x >> points[i].y;
char ch;
cin >> ch;
if (ch == 'U') {
points[i].dx = 0, points[i].dy = 1;
} else if (ch == 'D') {
points[i].dx = 0, points[i].dy = -1;
} else if (ch == 'L') {
points[i].dx = -1, points[i].dy = 0;
} else if (ch == 'R') {
points[i].dx = 1, points[i].dy = 0;
}
}
double l = 0, r = 1e8;
while (l + 1e-9 < r) {
double m1 = l + (r - l) / 3;
double m2 = r - (r - l) / 3;
if (-simulate(points, m1) > -simulate(points, m2))
r = m2;
else
l = m1;
}
printf("%.9f\n", simulate(points, l));
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Point {
double x, y;
int dx, dy;
};
double simulate(vector<Point> points, double t) {
double maxX = -1e18, maxY = -1e18, minX = 1e18, minY = 1e18;
for (int i = 0; i < points.size(); ++i) {
points[i].x += points[i].dx * t;
points[i].y += points[i].dy * t;
maxX = max(maxX, points[i].x);
maxY = max(maxY, points[i].y);
minX = min(minX, points[i].x);
minY = min(minY, points[i].y);
}
return (maxY - minY) * (maxX - minX);
}
int main() {
int n;
cin >> n;
vector<Point> points(n);
for (int i = 0; i < n; ++i) {
cin >> points[i].x >> points[i].y;
char ch;
cin >> ch;
if (ch == 'U') {
points[i].dx = 0, points[i].dy = 1;
} else if (ch == 'D') {
points[i].dx = 0, points[i].dy = -1;
} else if (ch == 'L') {
points[i].dx = -1, points[i].dy = 0;
} else if (ch == 'R') {
points[i].dx = 1, points[i].dy = 0;
}
}
double l = 0, r = 1e8;
while (l + 1e-8 < r) {
double m1 = l + (r - l) / 3;
double m2 = r - (r - l) / 3;
if (-simulate(points, m1) > -simulate(points, m2))
r = m2;
else
l = m1;
}
printf("%.9f\n", simulate(points, l));
} | replace | 38 | 39 | 38 | 39 | TLE | |
p03004 | C++ | Time Limit Exceeded | #define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define LLINF ((long long)1e15) // 1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-12) // 0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (100006)
#define ll long double
#define ld long double
mt19937
rng(chrono::steady_clock::now()
.time_since_epoch()
.count()); // can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for (ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair<ll, ll> pi;
typedef pair<char, pi> spi;
typedef pair<pi, pi> dpi;
// inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; }
// //inclusivesss string to_string(char c) {string s(1,c);return s;}string
// to_string(bool b){return (b ? "true" : "false");}template <typename A,
// typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) +
// ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v)
// {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res
// += ", ";}first = false;res += to_string(x);}res += "}";return res;}void
// degug_out() { cerr << endl; }template <typename Head, typename... Tail>void
// degug_out(Head H, Tail... T) {cerr << " " <<
// to_string(H);degug_out(T...);}inline ll gcd(ll a,ll
// b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr \
if (0) \
cout
#endif
ll n;
spi A[MAXN];
ll tstar(ll x) {
ll mxx = -LLINF, mix = LLINF, may = -LLINF, miy = LLINF;
FOR(ii, 0, n) {
int i = ii;
ll movex = 0, movey = 0;
if (A[i].f == 'L') {
movex -= x;
} else if (A[i].f == 'R') {
movex += x;
} else if (A[i].f == 'D') {
movey -= x;
} else if (A[i].f == 'U') {
movey += x;
} else
assert(0);
mxx = max(mxx, movex + A[i].s.f);
mix = min(mix, movex + A[i].s.f);
may = max(may, movey + A[i].s.s);
miy = min(miy, movey + A[i].s.s);
}
return (mxx - mix) * (may - miy);
}
int main() {
FAST cin >> n;
FOR(i, 0, n) { cin >> A[(int)i].s.f >> A[(int)i].s.s >> A[(int)i].f; }
ll st = 0, en = 2e8 + 100;
while (1) {
ll lmid = st + (en - st) / (ld)3;
ll umid = en - (en - st) / (ld)3;
if (st == lmid && en == umid)
break;
if (tstar(lmid) > tstar(umid))
st = lmid;
else
en = umid;
}
cout << fixed << setprecision(15) << tstar((st + en) / (ld)2) << '\n';
}
| #define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define LLINF ((long long)1e15) // 1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-12) // 0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (100006)
#define ll long double
#define ld long double
mt19937
rng(chrono::steady_clock::now()
.time_since_epoch()
.count()); // can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for (ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair<ll, ll> pi;
typedef pair<char, pi> spi;
typedef pair<pi, pi> dpi;
// inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; }
// //inclusivesss string to_string(char c) {string s(1,c);return s;}string
// to_string(bool b){return (b ? "true" : "false");}template <typename A,
// typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) +
// ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v)
// {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res
// += ", ";}first = false;res += to_string(x);}res += "}";return res;}void
// degug_out() { cerr << endl; }template <typename Head, typename... Tail>void
// degug_out(Head H, Tail... T) {cerr << " " <<
// to_string(H);degug_out(T...);}inline ll gcd(ll a,ll
// b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr \
if (0) \
cout
#endif
ll n;
spi A[MAXN];
ll tstar(ll x) {
ll mxx = -LLINF, mix = LLINF, may = -LLINF, miy = LLINF;
FOR(ii, 0, n) {
int i = ii;
ll movex = 0, movey = 0;
if (A[i].f == 'L') {
movex -= x;
} else if (A[i].f == 'R') {
movex += x;
} else if (A[i].f == 'D') {
movey -= x;
} else if (A[i].f == 'U') {
movey += x;
} else
assert(0);
mxx = max(mxx, movex + A[i].s.f);
mix = min(mix, movex + A[i].s.f);
may = max(may, movey + A[i].s.s);
miy = min(miy, movey + A[i].s.s);
}
return (mxx - mix) * (may - miy);
}
int main() {
FAST cin >> n;
FOR(i, 0, n) { cin >> A[(int)i].s.f >> A[(int)i].s.s >> A[(int)i].f; }
ll st = 0, en = 2e8 + 100;
FOR(i, 0, 150) {
ll lmid = st + (en - st) / (ld)3;
ll umid = en - (en - st) / (ld)3;
if (st == lmid && en == umid)
break;
if (tstar(lmid) > tstar(umid))
st = lmid;
else
en = umid;
}
cout << fixed << setprecision(15) << tstar((st + en) / (ld)2) << '\n';
}
| replace | 83 | 84 | 83 | 84 | TLE | |
p03004 | C++ | Time Limit Exceeded | /*** Template Begin ***/
#pragma region template
#define USING_NAMESPACE
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#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 <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
typedef int64_t i64;
typedef uint64_t u64;
auto init_ = [] {
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed;
return 0;
}();
template <typename T> inline void in(T &x) { std::cin >> x; }
template <typename T, typename... Ts> inline void in(T &t, Ts &...ts) {
std::cin >> t;
in(ts...);
}
template <typename T, typename U = std::vector<T>> inline U vin(int n) {
U v(n);
for (int i = 0; i < n; ++i) {
std::cin >> v[i];
}
return v;
}
template <typename T, typename U = std::vector<T>, typename V = std::vector<U>>
inline V vin(int h, int w) {
V vv(h, U(w));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
std::cin >> vv[i][j];
}
}
return vv;
}
template <typename T> inline void out(const T &x) {
std::cout << x << std::endl;
}
template <char delimiter = ' ', typename T, typename... Ts>
inline void out(const T &t, const Ts &...ts) {
std::cout << t << delimiter;
out(ts...);
}
template <char delimiter = ' ', typename T>
inline void vout(const T &v, int n) {
for (int i = 0; i < n; ++i) {
if (i)
std::cout << delimiter;
std::cout << v[i];
}
std::cout << std::endl;
}
template <char delimiter = ' ', typename T>
inline void vout(const T &v, int h, int w) {
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (j)
std::cout << delimiter;
std::cout << v[i][j];
}
std::cout << std::endl;
}
}
template <typename T, size_t D> struct multi_vector_type {
using type = std::vector<typename multi_vector_type<T, D - 1>::type>;
};
template <typename T> struct multi_vector_type<T, 1> {
using type = std::vector<T>;
};
template <typename T> struct multi_vector_type<T, 0> {
using type = T;
};
template <typename T, size_t D>
using multi_vector = typename multi_vector_type<T, D>::type;
template <typename T, size_t D, class = typename std::enable_if<D == 0>::type>
T make_vector(const T &val = T()) {
return val;
}
template <typename T, size_t D = 1, typename... Ts,
class = typename std::enable_if<D != 0>::type>
multi_vector<T, D> make_vector(size_t n, Ts &&...args) {
return multi_vector<T, D>(n, make_vector<T, D - 1>(args...));
}
namespace detail {
template <typename F> struct Debug {
const char *delim_ = "\n";
F fun;
Debug(F f) : fun(f) {}
~Debug() { fun(delim_); }
Debug &delim(const char *d) {
delim_ = d;
return *this;
}
};
std::deque<std::string> split(const std::string &s, char c) {
std::deque<std::string> v;
std::stringstream ss(s);
std::string x;
while (std::getline(ss, x, c))
v.emplace_back(x);
return v;
}
template <typename T>
void deb(const char *delim, std::deque<std::string> v, T a) {
std::cerr << v[0].substr(v[0][0] == ' ', v[0].length()) << " = " << a << '\n';
std::cerr << std::flush;
}
template <typename T, typename... Args>
void deb(const char *delim, std::deque<std::string> v, T a, Args... args) {
std::cerr << v[0].substr(v[0][0] == ' ', v[0].length()) << " = " << a
<< delim;
v.pop_front();
deb(delim, std::move(v), args...);
}
template <typename... Args> auto wrap(std::deque<std::string> v, Args... args) {
auto f = [=](const char *delim = "\n") { deb(delim, v, args...); };
return Debug<decltype(f)>(f);
}
} // namespace detail
#define debug(args...) ::detail::wrap(::detail::split(#args, ','), args)
#ifdef USING_BOOST
#include <boost/math/common_factor.hpp>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/numeric.hpp>
inline auto rep(int begin, int end) {
if (begin > end) {
return boost::irange(0, 0);
} else {
return boost::irange(begin, end);
}
}
inline auto rep(int begin, int end, int step) {
if ((step > 0 && begin > end) || (step < 0 && begin < end)) {
return boost::irange(0, 0, step);
} else {
return boost::irange(begin, end, step);
}
}
#endif
#ifdef USING_NAMESPACE
using namespace std;
#ifdef USING_BOOST
using namespace boost;
using namespace boost::adaptors;
#endif
#endif
#pragma endregion
/*** Template End ***/
pair<long double, long double> move(long double x, long double y, char d,
long double t) {
if (d == 'R') {
return {x + t, y};
} else if (d == 'L') {
return {x - t, y};
} else if (d == 'U') {
return {x, y + t};
} else {
return {x, y - t};
}
}
long double area(vector<long double> &x, vector<long double> &y,
vector<char> &d, long double t) {
int n = x.size();
long double xmax, xmin, ymax, ymin;
auto p = move(x[0], y[0], d[0], t);
xmax = xmin = p.first;
ymax = ymin = p.second;
for (int i = 1; i < n; i++) {
auto p = move(x[i], y[i], d[i], t);
xmax = max(xmax, p.first);
xmin = min(xmin, p.first);
ymax = max(ymax, p.second);
ymin = min(ymin, p.second);
}
return (xmax - xmin) * (ymax - ymin);
}
int main() {
int n;
in(n);
vector<long double> x(n), y(n);
vector<char> d(n);
for (int i = 0; i < n; i++) {
in(x[i], y[i], d[i]);
}
long double l = 0, r = 1e12;
auto ans = min(area(x, y, d, 0), area(x, y, d, r));
for (int i = 0; i < 2000; i++) {
long double m1 = (r - l) / 3 + l;
long double m2 = (r - l) * 2 / 3 + l;
long double f1 = area(x, y, d, m1);
long double f2 = area(x, y, d, m2);
if (f1 < f2) {
r = m2;
} else {
l = m1;
}
ans = min(ans, f1);
ans = min(ans, f2);
}
out(ans);
} | /*** Template Begin ***/
#pragma region template
#define USING_NAMESPACE
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#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 <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
typedef int64_t i64;
typedef uint64_t u64;
auto init_ = [] {
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed;
return 0;
}();
template <typename T> inline void in(T &x) { std::cin >> x; }
template <typename T, typename... Ts> inline void in(T &t, Ts &...ts) {
std::cin >> t;
in(ts...);
}
template <typename T, typename U = std::vector<T>> inline U vin(int n) {
U v(n);
for (int i = 0; i < n; ++i) {
std::cin >> v[i];
}
return v;
}
template <typename T, typename U = std::vector<T>, typename V = std::vector<U>>
inline V vin(int h, int w) {
V vv(h, U(w));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
std::cin >> vv[i][j];
}
}
return vv;
}
template <typename T> inline void out(const T &x) {
std::cout << x << std::endl;
}
template <char delimiter = ' ', typename T, typename... Ts>
inline void out(const T &t, const Ts &...ts) {
std::cout << t << delimiter;
out(ts...);
}
template <char delimiter = ' ', typename T>
inline void vout(const T &v, int n) {
for (int i = 0; i < n; ++i) {
if (i)
std::cout << delimiter;
std::cout << v[i];
}
std::cout << std::endl;
}
template <char delimiter = ' ', typename T>
inline void vout(const T &v, int h, int w) {
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (j)
std::cout << delimiter;
std::cout << v[i][j];
}
std::cout << std::endl;
}
}
template <typename T, size_t D> struct multi_vector_type {
using type = std::vector<typename multi_vector_type<T, D - 1>::type>;
};
template <typename T> struct multi_vector_type<T, 1> {
using type = std::vector<T>;
};
template <typename T> struct multi_vector_type<T, 0> {
using type = T;
};
template <typename T, size_t D>
using multi_vector = typename multi_vector_type<T, D>::type;
template <typename T, size_t D, class = typename std::enable_if<D == 0>::type>
T make_vector(const T &val = T()) {
return val;
}
template <typename T, size_t D = 1, typename... Ts,
class = typename std::enable_if<D != 0>::type>
multi_vector<T, D> make_vector(size_t n, Ts &&...args) {
return multi_vector<T, D>(n, make_vector<T, D - 1>(args...));
}
namespace detail {
template <typename F> struct Debug {
const char *delim_ = "\n";
F fun;
Debug(F f) : fun(f) {}
~Debug() { fun(delim_); }
Debug &delim(const char *d) {
delim_ = d;
return *this;
}
};
std::deque<std::string> split(const std::string &s, char c) {
std::deque<std::string> v;
std::stringstream ss(s);
std::string x;
while (std::getline(ss, x, c))
v.emplace_back(x);
return v;
}
template <typename T>
void deb(const char *delim, std::deque<std::string> v, T a) {
std::cerr << v[0].substr(v[0][0] == ' ', v[0].length()) << " = " << a << '\n';
std::cerr << std::flush;
}
template <typename T, typename... Args>
void deb(const char *delim, std::deque<std::string> v, T a, Args... args) {
std::cerr << v[0].substr(v[0][0] == ' ', v[0].length()) << " = " << a
<< delim;
v.pop_front();
deb(delim, std::move(v), args...);
}
template <typename... Args> auto wrap(std::deque<std::string> v, Args... args) {
auto f = [=](const char *delim = "\n") { deb(delim, v, args...); };
return Debug<decltype(f)>(f);
}
} // namespace detail
#define debug(args...) ::detail::wrap(::detail::split(#args, ','), args)
#ifdef USING_BOOST
#include <boost/math/common_factor.hpp>
#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/numeric.hpp>
inline auto rep(int begin, int end) {
if (begin > end) {
return boost::irange(0, 0);
} else {
return boost::irange(begin, end);
}
}
inline auto rep(int begin, int end, int step) {
if ((step > 0 && begin > end) || (step < 0 && begin < end)) {
return boost::irange(0, 0, step);
} else {
return boost::irange(begin, end, step);
}
}
#endif
#ifdef USING_NAMESPACE
using namespace std;
#ifdef USING_BOOST
using namespace boost;
using namespace boost::adaptors;
#endif
#endif
#pragma endregion
/*** Template End ***/
pair<long double, long double> move(long double x, long double y, char d,
long double t) {
if (d == 'R') {
return {x + t, y};
} else if (d == 'L') {
return {x - t, y};
} else if (d == 'U') {
return {x, y + t};
} else {
return {x, y - t};
}
}
long double area(vector<long double> &x, vector<long double> &y,
vector<char> &d, long double t) {
int n = x.size();
long double xmax, xmin, ymax, ymin;
auto p = move(x[0], y[0], d[0], t);
xmax = xmin = p.first;
ymax = ymin = p.second;
for (int i = 1; i < n; i++) {
auto p = move(x[i], y[i], d[i], t);
xmax = max(xmax, p.first);
xmin = min(xmin, p.first);
ymax = max(ymax, p.second);
ymin = min(ymin, p.second);
}
return (xmax - xmin) * (ymax - ymin);
}
int main() {
int n;
in(n);
vector<long double> x(n), y(n);
vector<char> d(n);
for (int i = 0; i < n; i++) {
in(x[i], y[i], d[i]);
}
long double l = 0, r = 1e14;
long double ans = min(area(x, y, d, l), area(x, y, d, r));
for (int i = 0; i < 1000; i++) {
long double m1 = (r - l) / 3 + l;
long double m2 = (r - l) * 2 / 3 + l;
long double f1 = area(x, y, d, m1);
long double f2 = area(x, y, d, m2);
if (f1 < f2) {
r = m2;
} else {
l = m1;
}
ans = min(ans, f1);
ans = min(ans, f2);
}
out(ans);
}
| replace | 262 | 268 | 262 | 267 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for (ll i = 0; i < n; i++)
int main() {
int n;
scanf("%d", &n);
double r1 = -INF, r2 = -INF, r3 = -INF;
double l1 = INF, l2 = INF, l3 = INF;
double u1 = -INF, u2 = -INF, u3 = -INF;
double d1 = INF, d2 = INF, d3 = INF;
for (int i = 0; i < n; i++) {
double x, y;
char d;
scanf("%lf %lf %c", &x, &y, &d);
if (d == 'R') {
r1 = max(r1, x);
l3 = min(l3, x);
u2 = max(u2, y);
d2 = min(d2, y);
}
if (d == 'L') {
r3 = max(r3, x);
l1 = min(l1, x);
u2 = max(u2, y);
d2 = min(d2, y);
}
if (d == 'U') {
r2 = max(r2, x);
l2 = min(l2, x);
u1 = max(u1, y);
d3 = min(d3, y);
}
if (d == 'D') {
r2 = max(r2, x);
l2 = min(l2, x);
u3 = max(u3, y);
d1 = min(d1, y);
}
}
double ans = INF;
for (double i = 0; i <= 4e8; i += 0.5) {
ans = min(ans, (max({r1 + i, r2, r3 - i}) - min({l1 - i, l2, l3 + i})) *
(max({u1 + i, u2, u3 - i}) - min({d1 - i, d2, d3 + i})));
}
printf("%.11lf\n", ans);
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for (ll i = 0; i < n; i++)
int main() {
int n;
scanf("%d", &n);
double r1 = -INF, r2 = -INF, r3 = -INF;
double l1 = INF, l2 = INF, l3 = INF;
double u1 = -INF, u2 = -INF, u3 = -INF;
double d1 = INF, d2 = INF, d3 = INF;
for (int i = 0; i < n; i++) {
double x, y;
char d;
scanf("%lf %lf %c", &x, &y, &d);
if (d == 'R') {
r1 = max(r1, x);
l3 = min(l3, x);
u2 = max(u2, y);
d2 = min(d2, y);
}
if (d == 'L') {
r3 = max(r3, x);
l1 = min(l1, x);
u2 = max(u2, y);
d2 = min(d2, y);
}
if (d == 'U') {
r2 = max(r2, x);
l2 = min(l2, x);
u1 = max(u1, y);
d3 = min(d3, y);
}
if (d == 'D') {
r2 = max(r2, x);
l2 = min(l2, x);
u3 = max(u3, y);
d1 = min(d1, y);
}
}
double ans = 1e18;
for (double i = 0; i <= 2e8; i += 0.5) {
ans = min(ans, (max({r1 + i, r2, r3 - i}) - min({l1 - i, l2, l3 + i})) *
(max({u1 + i, u2, u3 - i}) - min({d1 - i, d2, d3 + i})));
}
printf("%.11lf\n", ans);
} | replace | 66 | 68 | 66 | 68 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = (int)1e9;
const ll mod = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0)
g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll &mod) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll &mod) { return (a - b + mod) % mod; }
ll MUL(const ll &a, const ll &b, const ll &mod) { return (1LL * a * b) % mod; }
ll DIV(const ll &a, const ll &b, const ll &mod) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1, 6);
uniform_real_distribution<double> score(0.0, 10.0);
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
map<char, vi> x;
map<char, vi> y;
for (auto &c : "RLUD") {
x[c] = vi(1, -inf), y[c] = vi(1, -inf);
}
rep(i, n) {
int xx, yy;
char d;
cin >> xx >> yy >> d;
x[d].emplace_back(xx);
y[d].emplace_back(yy);
}
map<char, int> xmax, xmin, ymax, ymin;
for (auto &c : "RLUD") {
xmax[c] = *max_element(_all(x[c]));
ymax[c] = *max_element(_all(y[c]));
x[c][0] = inf, y[c][0] = inf;
xmin[c] = *min_element(_all(x[c]));
ymin[c] = *min_element(_all(y[c]));
}
int xmab = max(xmax['U'], xmax['D']);
int xmib = min(xmin['U'], xmin['D']);
int ymab = max(ymax['R'], ymax['L']);
int ymib = min(ymin['R'], ymin['L']);
using R = double;
R res = 1LL << 61;
rep(_, 4 * ((int)1e8 + 1)) {
R loop = 0.5 * _;
R xma = max(1. * xmab, max(xmax['R'] + loop, xmax['L'] - loop));
R xmi = min(1. * xmib, min(xmin['R'] + loop, xmin['L'] - loop));
R yma = max(1. * ymab, max(ymax['U'] + loop, ymax['D'] - loop));
R ymi = min(1. * ymib, min(ymin['U'] + loop, ymin['D'] - loop));
chmin(res, (xma - xmi) * (yma - ymi));
}
cout.precision(20);
cout << fixed << res << endl;
return 0;
}
| #include <bits/stdc++.h>
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = (int)1e9;
const ll mod = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0)
g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll &mod) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll &mod) { return (a - b + mod) % mod; }
ll MUL(const ll &a, const ll &b, const ll &mod) { return (1LL * a * b) % mod; }
ll DIV(const ll &a, const ll &b, const ll &mod) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1, 6);
uniform_real_distribution<double> score(0.0, 10.0);
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
map<char, vi> x;
map<char, vi> y;
for (auto &c : "RLUD") {
x[c] = vi(1, -inf), y[c] = vi(1, -inf);
}
rep(i, n) {
int xx, yy;
char d;
cin >> xx >> yy >> d;
x[d].emplace_back(xx);
y[d].emplace_back(yy);
}
vi xmax(300), xmin(300), ymax(300), ymin(300);
for (auto &c : "RLUD") {
xmax[c] = *max_element(_all(x[c]));
ymax[c] = *max_element(_all(y[c]));
x[c][0] = inf, y[c][0] = inf;
xmin[c] = *min_element(_all(x[c]));
ymin[c] = *min_element(_all(y[c]));
}
int xmab = max(xmax['U'], xmax['D']);
int xmib = min(xmin['U'], xmin['D']);
int ymab = max(ymax['R'], ymax['L']);
int ymib = min(ymin['R'], ymin['L']);
using R = double;
R res = 1LL << 61;
rep(_, 4 * ((int)1e8 + 1)) {
R loop = 0.5 * _;
R xma = max(1. * xmab, max(xmax['R'] + loop, xmax['L'] - loop));
R xmi = min(1. * xmib, min(xmin['R'] + loop, xmin['L'] - loop));
R yma = max(1. * ymab, max(ymax['U'] + loop, ymax['D'] - loop));
R ymi = min(1. * ymib, min(ymin['U'] + loop, ymin['D'] - loop));
chmin(res, (xma - xmi) * (yma - ymi));
}
cout.precision(20);
cout << fixed << res << endl;
return 0;
}
| replace | 84 | 85 | 84 | 85 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e5 + 5;
int mul(int a, int b) { return (long long)a * b; }
typedef long long ll;
int n, x[N], y[N], d[N];
const double inf = 1e20;
double getans(double mid) {
double mnx = inf, mxx = -inf, mny = inf, mxy = -inf;
for (int i = 1; i <= n; i++) {
double xx = x[i], yy = y[i];
if (d[i] == 1)
xx -= mid;
if (d[i] == 2)
xx += mid;
if (d[i] == 3)
yy += mid;
if (d[i] == 4)
yy -= mid;
mnx = min(mnx, xx);
mxx = max(mxx, xx);
mny = min(mny, yy);
mxy = max(mxy, yy);
}
return (mxx - mnx) * (mxy - mny);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char s[5];
scanf("%d%d%s", &x[i], &y[i], s);
if (s[0] == 'L')
d[i] = 1;
else if (s[0] == 'R')
d[i] = 2;
else if (s[0] == 'U')
d[i] = 3;
else
d[i] = 4;
}
double l = 0, r = 1e10;
while (r - l > 1e-10) {
double mid = (l + r) / 2, midmid = (mid + r) / 2;
if (getans(mid) < getans(midmid))
r = midmid;
else
l = mid;
}
printf("%f\n", getans(l));
}
| #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e5 + 5;
int mul(int a, int b) { return (long long)a * b; }
typedef long long ll;
int n, x[N], y[N], d[N];
const double inf = 1e20;
double getans(double mid) {
double mnx = inf, mxx = -inf, mny = inf, mxy = -inf;
for (int i = 1; i <= n; i++) {
double xx = x[i], yy = y[i];
if (d[i] == 1)
xx -= mid;
if (d[i] == 2)
xx += mid;
if (d[i] == 3)
yy += mid;
if (d[i] == 4)
yy -= mid;
mnx = min(mnx, xx);
mxx = max(mxx, xx);
mny = min(mny, yy);
mxy = max(mxy, yy);
}
return (mxx - mnx) * (mxy - mny);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
char s[5];
scanf("%d%d%s", &x[i], &y[i], s);
if (s[0] == 'L')
d[i] = 1;
else if (s[0] == 'R')
d[i] = 2;
else if (s[0] == 'U')
d[i] = 3;
else
d[i] = 4;
}
double l = 0, r = 1e10;
for (int i = 1; i <= 1000; i++) {
double mid = l + (r - l) / 3, midmid = l + (r - l) / 3 * 2;
if (getans(mid) < getans(midmid))
r = midmid;
else
l = mid;
}
printf("%f\n", getans(l));
}
| replace | 41 | 43 | 41 | 43 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
int n;
double x[100010], y[100010];
char d[100010];
double f(double t) {
vector<double> tx(n), ty(n);
rep(i, n) {
tx[i] = x[i];
ty[i] = y[i];
if (d[i] == 'L')
tx[i] -= t;
if (d[i] == 'R')
tx[i] += t;
if (d[i] == 'U')
ty[i] += t;
if (d[i] == 'D')
ty[i] -= t;
}
sort(tx.begin(), tx.end());
sort(ty.begin(), ty.end());
return (tx[n - 1] - tx[0]) * (ty[n - 1] - ty[0]);
}
int main() {
scanf("%d", &n);
rep(i, n) cin >> x[i] >> y[i] >> d[i];
double high = 1e9;
double low = 0;
double m2 = high;
double m1 = low;
rep(i, 300) {
m1 = (high + low * 2) / 3;
m2 = (high * 2 + low) / 3;
if (f(m1) > f(m2))
low = m1;
else
high = m2;
}
printf("%.10f", min({f(low), f(m1), f(m2), f(high)}));
} | #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
int n;
double x[100010], y[100010];
char d[100010];
double f(double t) {
vector<double> tx(n), ty(n);
rep(i, n) {
tx[i] = x[i];
ty[i] = y[i];
if (d[i] == 'L')
tx[i] -= t;
if (d[i] == 'R')
tx[i] += t;
if (d[i] == 'U')
ty[i] += t;
if (d[i] == 'D')
ty[i] -= t;
}
sort(tx.begin(), tx.end());
sort(ty.begin(), ty.end());
return (tx[n - 1] - tx[0]) * (ty[n - 1] - ty[0]);
}
int main() {
scanf("%d", &n);
rep(i, n) cin >> x[i] >> y[i] >> d[i];
double high = 1e9;
double low = 0;
double m2 = high;
double m1 = low;
rep(i, 100) {
m1 = (high + low * 2) / 3;
m2 = (high * 2 + low) / 3;
if (f(m1) > f(m2))
low = m1;
else
high = m2;
}
printf("%.10f", min({f(low), f(m1), f(m2), f(high)}));
} | replace | 41 | 42 | 41 | 42 | TLE | |
p03004 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MAX 1e8
class V {
public:
vector<double> l;
vector<double> r;
V() {
l = vector<double>(3, MAX);
r = vector<double>(3, -MAX);
}
void add(double x, int d) {
d++;
l[d] = min(l[d], x);
r[d] = max(r[d], x);
}
vector<double> intersection() {
vector<double> ret;
ret.push_back(l[0] - l[1]);
ret.push_back(l[1] - l[2]);
ret.push_back((l[0] - l[2]) / 2);
ret.push_back(r[0] - r[1]);
ret.push_back(r[1] - r[2]);
ret.push_back((r[0] - r[2]) / 2);
return ret;
}
double value(double t) {
return max({r[0] - t, r[1], r[2] + t}) - min({l[0] - t, l[1], l[2] + t});
}
};
void add_candidate(vector<double> x, vector<double> &candidate) {
candidate.push_back(x[0] - x[1]);
candidate.push_back(x[1] - x[2]);
candidate.push_back((x[0] - x[2]) / 2);
}
int main() {
int N;
cin >> N;
// [minus, const, plus]
V X;
V Y;
vector<double> xmin(3, MAX);
vector<double> xmax(3, -MAX);
vector<double> ymin(3, MAX);
vector<double> ymax(3, -MAX);
double x, y;
char D;
for (int i = 0; i < N; i++) {
cin >> x >> y;
cin >> D;
switch (D) {
case 'R':
X.add(x, 1);
Y.add(y, 0);
break;
case 'L':
X.add(x, -1);
Y.add(y, 0);
break;
case 'U':
X.add(x, 0);
Y.add(y, 1);
break;
case 'D':
X.add(x, 0);
Y.add(y, -1);
break;
default:
break;
}
if (D == 'L') {
xmin[0] = min(xmin[0], x);
xmax[0] = max(xmax[0], x);
} else if (D == 'R') {
xmin[2] = min(xmin[2], x);
xmax[2] = max(xmax[2], x);
} else {
xmin[1] = min(xmin[1], x);
xmax[1] = max(xmax[1], x);
}
if (D == 'D') {
ymin[0] = min(ymin[0], y);
ymax[0] = max(ymax[0], y);
} else if (D == 'U') {
ymin[2] = min(xmin[2], y);
ymax[2] = max(xmax[2], y);
} else {
ymin[1] = min(ymin[1], y);
ymax[1] = max(ymax[1], y);
}
}
vector<double> candidate1;
for (auto c : X.intersection()) {
if (c >= 0) {
candidate1.push_back(c);
}
}
for (auto c : Y.intersection()) {
if (c >= 0) {
candidate1.push_back(c);
}
}
candidate1.push_back(0);
vector<double> candidate2;
add_candidate(xmin, candidate2);
add_candidate(xmax, candidate2);
add_candidate(ymin, candidate2);
add_candidate(ymax, candidate2);
candidate2.push_back(0);
double ans1 = 1e18;
for (double c : candidate1) {
if (c >= 0) {
// x = X.value(c);
// y = Y.value(c);
x = max({X.r[0] - c, X.r[1], X.r[2] + c}) -
min({X.l[0] - c, X.l[1], X.l[2] + c});
y = max({Y.r[0] - c, Y.r[1], Y.r[2] + c}) -
min({Y.l[0] - c, Y.l[1], Y.l[2] + c});
ans1 = min(ans1, x * y);
}
}
double ans2 = 1e18;
for (double c : candidate2) {
if (c >= 0) {
x = max({xmax[0] - c, xmax[1], xmax[2] + c}) -
min({xmin[0] - c, xmin[1], xmin[2] + c});
y = max({ymax[0] - c, ymax[1], ymax[2] + c}) -
min({ymin[0] - c, ymin[1], ymin[2] + c});
ans2 = min(ans2, x * y);
}
}
cout << fixed << setprecision(2) << ans1 << endl;
assert(ans1 == ans2);
}
| #include <bits/stdc++.h>
using namespace std;
#define MAX 1e8
class V {
public:
vector<double> l;
vector<double> r;
V() {
l = vector<double>(3, MAX);
r = vector<double>(3, -MAX);
}
void add(double x, int d) {
d++;
l[d] = min(l[d], x);
r[d] = max(r[d], x);
}
vector<double> intersection() {
vector<double> ret;
ret.push_back(l[0] - l[1]);
ret.push_back(l[1] - l[2]);
ret.push_back((l[0] - l[2]) / 2);
ret.push_back(r[0] - r[1]);
ret.push_back(r[1] - r[2]);
ret.push_back((r[0] - r[2]) / 2);
return ret;
}
double value(double t) {
return max({r[0] - t, r[1], r[2] + t}) - min({l[0] - t, l[1], l[2] + t});
}
};
void add_candidate(vector<double> x, vector<double> &candidate) {
candidate.push_back(x[0] - x[1]);
candidate.push_back(x[1] - x[2]);
candidate.push_back((x[0] - x[2]) / 2);
}
int main() {
int N;
cin >> N;
// [minus, const, plus]
V X;
V Y;
vector<double> xmin(3, MAX);
vector<double> xmax(3, -MAX);
vector<double> ymin(3, MAX);
vector<double> ymax(3, -MAX);
double x, y;
char D;
for (int i = 0; i < N; i++) {
cin >> x >> y;
cin >> D;
switch (D) {
case 'R':
X.add(x, 1);
Y.add(y, 0);
break;
case 'L':
X.add(x, -1);
Y.add(y, 0);
break;
case 'U':
X.add(x, 0);
Y.add(y, 1);
break;
case 'D':
X.add(x, 0);
Y.add(y, -1);
break;
default:
break;
}
if (D == 'L') {
xmin[0] = min(xmin[0], x);
xmax[0] = max(xmax[0], x);
} else if (D == 'R') {
xmin[2] = min(xmin[2], x);
xmax[2] = max(xmax[2], x);
} else {
xmin[1] = min(xmin[1], x);
xmax[1] = max(xmax[1], x);
}
if (D == 'D') {
ymin[0] = min(ymin[0], y);
ymax[0] = max(ymax[0], y);
} else if (D == 'U') {
ymin[2] = min(xmin[2], y);
ymax[2] = max(xmax[2], y);
} else {
ymin[1] = min(ymin[1], y);
ymax[1] = max(ymax[1], y);
}
}
vector<double> candidate1;
for (auto c : X.intersection()) {
if (c >= 0) {
candidate1.push_back(c);
}
}
for (auto c : Y.intersection()) {
if (c >= 0) {
candidate1.push_back(c);
}
}
candidate1.push_back(0);
vector<double> candidate2;
add_candidate(xmin, candidate2);
add_candidate(xmax, candidate2);
add_candidate(ymin, candidate2);
add_candidate(ymax, candidate2);
candidate2.push_back(0);
double ans1 = 1e18;
for (double c : candidate1) {
if (c >= 0) {
// x = X.value(c);
// y = Y.value(c);
x = max({X.r[0] - c, X.r[1], X.r[2] + c}) -
min({X.l[0] - c, X.l[1], X.l[2] + c});
y = max({Y.r[0] - c, Y.r[1], Y.r[2] + c}) -
min({Y.l[0] - c, Y.l[1], Y.l[2] + c});
ans1 = min(ans1, x * y);
}
}
double ans2 = 1e18;
for (double c : candidate2) {
if (c >= 0) {
x = max({xmax[0] - c, xmax[1], xmax[2] + c}) -
min({xmin[0] - c, xmin[1], xmin[2] + c});
y = max({ymax[0] - c, ymax[1], ymax[2] + c}) -
min({ymin[0] - c, ymin[1], ymin[2] + c});
ans2 = min(ans2, x * y);
}
}
cout << fixed << setprecision(2) << ans1 << endl;
// assert(ans1 == ans2);
}
| replace | 148 | 149 | 148 | 149 | 0 | |
p03004 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
typedef long double llf;
const int MN = 1e5 + 4;
const llf INF = 1e100, EPS = 7e-12, GR = (1 + sqrt(5)) / 2.0;
int N;
llf ans = INF;
struct pnt {
llf x, y;
llf ox, oy;
char c;
} pnts[MN];
static inline void mov(pnt &p, llf dt) {
switch (p.c) {
case 'R':
p.x = p.ox + dt;
p.y = p.oy;
break;
case 'L':
p.x = p.ox - dt;
p.y = p.oy;
break;
case 'U':
p.x = p.ox;
p.y = p.oy + dt;
break;
case 'D':
p.x = p.ox;
p.y = p.oy - dt;
break;
}
}
static inline llf bb() {
llf mxx = -INF, mxy = -INF, mnx = INF, mny = INF;
for (int i = 0; i < N; ++i) {
mxx = std::max(mxx, pnts[i].x);
mnx = std::min(mnx, pnts[i].x);
mxy = std::max(mxy, pnts[i].y);
mny = std::min(mny, pnts[i].y);
}
return (mxx - mnx) * (mxy - mny);
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%Lf %Lf %c", &pnts[i].ox, &pnts[i].oy, &pnts[i].c);
}
// do GSS
llf lo = 0, hi = 1e9, mi1, mi2;
while (fabs(hi - lo) > EPS) {
mi1 = hi - (hi - lo) / GR;
mi2 = lo + (hi - lo) / GR;
llf b1, b2;
for (int i = 0; i < N; ++i)
mov(pnts[i], mi1);
b1 = bb();
for (int i = 0; i < N; ++i)
mov(pnts[i], mi2);
b2 = bb();
if (b1 < b2)
hi = mi2;
else
lo = mi1;
ans = std::min(std::min(b1, b2), ans);
}
printf("%.9Lf\n", ans);
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
typedef long double llf;
const int MN = 1e5 + 4;
const llf INF = 1e100, EPS = 7e-12, GR = (1 + sqrt(5)) / 2.0;
int N;
llf ans = INF;
struct pnt {
llf x, y;
llf ox, oy;
char c;
} pnts[MN];
static inline void mov(pnt &p, llf dt) {
switch (p.c) {
case 'R':
p.x = p.ox + dt;
p.y = p.oy;
break;
case 'L':
p.x = p.ox - dt;
p.y = p.oy;
break;
case 'U':
p.x = p.ox;
p.y = p.oy + dt;
break;
case 'D':
p.x = p.ox;
p.y = p.oy - dt;
break;
}
}
static inline llf bb() {
llf mxx = -INF, mxy = -INF, mnx = INF, mny = INF;
for (int i = 0; i < N; ++i) {
mxx = std::max(mxx, pnts[i].x);
mnx = std::min(mnx, pnts[i].x);
mxy = std::max(mxy, pnts[i].y);
mny = std::min(mny, pnts[i].y);
}
return (mxx - mnx) * (mxy - mny);
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%Lf %Lf %c", &pnts[i].ox, &pnts[i].oy, &pnts[i].c);
}
// do GSS
llf lo = 0, hi = 1e9, mi1, mi2;
for (int i = 0; i < 500; ++i) {
mi1 = hi - (hi - lo) / GR;
mi2 = lo + (hi - lo) / GR;
llf b1, b2;
for (int i = 0; i < N; ++i)
mov(pnts[i], mi1);
b1 = bb();
for (int i = 0; i < N; ++i)
mov(pnts[i], mi2);
b2 = bb();
if (b1 < b2)
hi = mi2;
else
lo = mi1;
ans = std::min(std::min(b1, b2), ans);
}
printf("%.9Lf\n", ans);
}
| replace | 50 | 51 | 50 | 51 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type>
#define endl '\n'
#define FOR(i, A, B) for (auto i = (A); i != (B); i++)
#define FORD(i, A, B) for (auto i = (A); i != (B); i--)
#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))
using namespace std;
typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;
// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
int main(int argc, char **argv) {
io_init();
// Actual program code starts here.
int N;
cin >> N;
VEC(char) Directions(N);
VEC(int) X(N), Y(N);
FOR(i, 0, N) { cin >> X[i] >> Y[i] >> Directions[i]; }
auto area = [&N, &X, &Y, &Directions](double t) {
double xlo = 1e10, xhi = -(1e10);
double ylo = 1e10, yhi = -(1e10);
FOR(i, 0, N) {
double x = X[i], y = Y[i];
if (Directions[i] == 'U')
y += t;
else if (Directions[i] == 'D')
y -= t;
else if (Directions[i] == 'R')
x += t;
else
x -= t;
xlo = min(xlo, x);
ylo = min(ylo, y);
xhi = max(xhi, x);
yhi = max(yhi, y);
}
return (xhi - xlo) * (yhi - ylo);
};
double lo = 0, hi = 1e10;
while (hi - lo > 1e-10) {
double md1 = (2 * lo + hi) / 3, md2 = (lo + 2 * hi) / 3;
if (area(md1) < area(md2))
hi = md2;
else
lo = md1;
}
cout << fixed << setprecision(10) << area((lo + hi) / 2) << endl;
return 0;
};
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type>
#define endl '\n'
#define FOR(i, A, B) for (auto i = (A); i != (B); i++)
#define FORD(i, A, B) for (auto i = (A); i != (B); i--)
#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))
using namespace std;
typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;
// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
int main(int argc, char **argv) {
io_init();
// Actual program code starts here.
int N;
cin >> N;
VEC(char) Directions(N);
VEC(int) X(N), Y(N);
FOR(i, 0, N) { cin >> X[i] >> Y[i] >> Directions[i]; }
auto area = [&N, &X, &Y, &Directions](double t) {
double xlo = 1e10, xhi = -(1e10);
double ylo = 1e10, yhi = -(1e10);
FOR(i, 0, N) {
double x = X[i], y = Y[i];
if (Directions[i] == 'U')
y += t;
else if (Directions[i] == 'D')
y -= t;
else if (Directions[i] == 'R')
x += t;
else
x -= t;
xlo = min(xlo, x);
ylo = min(ylo, y);
xhi = max(xhi, x);
yhi = max(yhi, y);
}
return (xhi - xlo) * (yhi - ylo);
};
double lo = 0, hi = 1e10;
int iters = 150;
while (iters-- && hi - lo > 1e-10) {
double md1 = (2 * lo + hi) / 3, md2 = (lo + 2 * hi) / 3;
if (area(md1) < area(md2))
hi = md2;
else
lo = md1;
}
cout << fixed << setprecision(10) << area((lo + hi) / 2) << endl;
return 0;
};
| replace | 80 | 81 | 80 | 82 | TLE | |
p03004 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template <class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, n) for (int(i) = (a); (i) < (n); ++(i))
#define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); ++(i))
#define rFOR(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define erFOR(i, a, n) for (int(i) = (n); (i) >= (a); --(i))
#define each(i, a) for (auto &i : a)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
#define all(i) (i).begin(), (i).end()
#define out(y, x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n"
#define ENDL(i, n) ((i) == (n)-1 ? "\n" : " ")
#define stop system("pause") // comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; // 1e-9?
constexpr ld pi = 3.1415926535897932;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
for (auto &elemnt : v)
is >> elemnt;
return is;
}
template <class T, class U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> inline vector<T> vec(size_t a) { return vector<T>(a); }
template <class T> inline vector<T> defvec(T def, size_t a) {
return vector<T>(a, def);
}
template <class T, class... Ts> inline auto vec(size_t a, Ts... ts) {
return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));
}
template <class T, class... Ts> inline auto defvec(T def, size_t a, Ts... ts) {
return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...));
}
int main() {
init();
int n;
cin >> n;
vector<ld> x(n), y(n);
vector<char> d(n);
FOR(i, 0, n) cin >> x[i] >> y[i] >> d[i];
map<char, ld> Xdir, Ydir;
Xdir['R'] = 1, Xdir['L'] = -1;
Ydir['U'] = 1, Ydir['D'] = -1;
function<ld(ld)> f = [&](ld t) {
ld Xmax = -LLINF, Xmin = LLINF;
ld Ymax = -LLINF, Ymin = LLINF;
FOR(i, 0, n) {
ld nx = x[i] + t * Xdir[d[i]];
ld ny = y[i] + t * Ydir[d[i]];
chmax(Xmax, nx), chmin(Xmin, nx);
chmax(Ymax, ny), chmin(Ymin, ny);
}
return (Xmax - Xmin) * (Ymax - Ymin);
};
ld l = 0, r = INF;
FOR(i, 0, 1000) {
ld m1 = (l * 2 + r) / 3, m2 = (l + r * 2) / 3;
if (f(m1) < f(m2))
r = m2;
else
l = m1;
}
cout << f(l) << "\n";
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template <class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, n) for (int(i) = (a); (i) < (n); ++(i))
#define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); ++(i))
#define rFOR(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define erFOR(i, a, n) for (int(i) = (n); (i) >= (a); --(i))
#define each(i, a) for (auto &i : a)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
#define all(i) (i).begin(), (i).end()
#define out(y, x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n"
#define ENDL(i, n) ((i) == (n)-1 ? "\n" : " ")
#define stop system("pause") // comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; // 1e-9?
constexpr ld pi = 3.1415926535897932;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
for (auto &elemnt : v)
is >> elemnt;
return is;
}
template <class T, class U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> inline vector<T> vec(size_t a) { return vector<T>(a); }
template <class T> inline vector<T> defvec(T def, size_t a) {
return vector<T>(a, def);
}
template <class T, class... Ts> inline auto vec(size_t a, Ts... ts) {
return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));
}
template <class T, class... Ts> inline auto defvec(T def, size_t a, Ts... ts) {
return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...));
}
int main() {
init();
int n;
cin >> n;
vector<ld> x(n), y(n);
vector<char> d(n);
FOR(i, 0, n) cin >> x[i] >> y[i] >> d[i];
map<char, ld> Xdir, Ydir;
Xdir['R'] = 1, Xdir['L'] = -1;
Ydir['U'] = 1, Ydir['D'] = -1;
function<ld(ld)> f = [&](ld t) {
ld Xmax = -LLINF, Xmin = LLINF;
ld Ymax = -LLINF, Ymin = LLINF;
FOR(i, 0, n) {
ld nx = x[i] + t * Xdir[d[i]];
ld ny = y[i] + t * Ydir[d[i]];
chmax(Xmax, nx), chmin(Xmin, nx);
chmax(Ymax, ny), chmin(Ymin, ny);
}
return (Xmax - Xmin) * (Ymax - Ymin);
};
ld l = 0, r = INF;
FOR(i, 0, 500) {
ld m1 = (l * 2 + r) / 3, m2 = (l + r * 2) / 3;
if (f(m1) < f(m2))
r = m2;
else
l = m1;
}
cout << f(l) << "\n";
} | replace | 91 | 92 | 91 | 92 | TLE | |
p03005 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack<int>
#define stll stack<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define stp setprecision(20) // use fixed before stp
#define endl '\n'
int main() {
FAST
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ll n, k;
cin >> n >> k;
n -= k;
if (k == 1)
cout << 0;
else
cout << n;
} | #include <bits/stdc++.h>
using namespace std;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack<int>
#define stll stack<ll>
#define mseti multiset<ll>
#define msetd multiset<ll, greater<ll>>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define stp setprecision(20) // use fixed before stp
#define endl '\n'
int main() {
FAST ll n, k;
cin >> n >> k;
n -= k;
if (k == 1)
cout << 0;
else
cout << n;
} | replace | 31 | 37 | 31 | 32 | 0 | |
p03005 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
if (K == 1) {
cout << 0 << endl;
return 0;
}
return N - K;
} | #include <iostream>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
if (K == 1) {
cout << 0 << endl;
return 0;
}
cout << N - K << endl;
} | replace | 14 | 15 | 14 | 15 | 1 | |
p03005 | C++ | Runtime Error | #pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
int n, k;
cin >> n >> k;
if (k != 1)
cout << n - k;
else
cout << 0;
return 0;
} | #pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
int32_t main() {
IOS;
int n, k;
cin >> n >> k;
if (k != 1)
cout << n - k;
else
cout << 0;
return 0;
} | delete | 14 | 18 | 14 | 14 | 0 | |
p03005 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ForA(i, b, a) for (int i = a; i >= b; i--)
#define ForB(i, a, b) for (int i = a; i <= b; i++)
#define IOS \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define PI 3.1415926535897932384626433832795l
#define deci(n) cout << fixed << setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define IT(a, b) map<a, b>::iterator
#define ll long long int
#define ld long double
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define maxn 1000010
using namespace std;
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
class Print {
public:
void print(int n) {
cout << n << '\n';
exit(0);
}
void print(ll n) {
cout << n << '\n';
exit(0);
}
void print(string s) {
cout << s << '\n';
exit(0);
}
void print(ld n) {
cout << n << '\n';
exit(0);
}
};
int main() {
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
Print _p;
int n, k;
cin >> n >> k;
if (k == 1)
_p.print(0);
_p.print(n - k);
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
| #include <bits/stdc++.h>
#define ForA(i, b, a) for (int i = a; i >= b; i--)
#define ForB(i, a, b) for (int i = a; i <= b; i++)
#define IOS \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define PI 3.1415926535897932384626433832795l
#define deci(n) cout << fixed << setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define IT(a, b) map<a, b>::iterator
#define ll long long int
#define ld long double
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define maxn 1000010
using namespace std;
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
class Print {
public:
void print(int n) {
cout << n << '\n';
exit(0);
}
void print(ll n) {
cout << n << '\n';
exit(0);
}
void print(string s) {
cout << s << '\n';
exit(0);
}
void print(ld n) {
cout << n << '\n';
exit(0);
}
};
int main() {
IOS;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// #endif
Print _p;
int n, k;
cin >> n >> k;
if (k == 1)
_p.print(0);
_p.print(n - k);
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
| replace | 50 | 53 | 50 | 53 | 0 | |
p03005 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 2000000007
#define MOD 10e9 + 7
#define MAX 100005
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
int main() {
int N, K;
cin >> N >> K;
if (K == 1)
puts(0);
else
cout << (N - K) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 2000000007
#define MOD 10e9 + 7
#define MAX 100005
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
int main() {
int N, K;
cin >> N >> K;
if (K == 1)
cout << 0 << endl;
else
cout << (N - K) << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03006 | Python | Runtime Error | import sys
from collections import Counter
N = int(input())
points = []
for i, line in enumerate(sys.stdin):
x, y = map(int, line.split())
points.append([x, y])
if i == N - 1:
break
counts = []
for i in range(N):
for j in range(N):
if i == j:
continue
p = points[j][0] - points[i][0]
q = points[j][1] - points[i][1]
counts.append((p, q))
pq = Counter(counts).most_common()[0][1]
cost = N - pq
print(cost)
| import sys
from collections import Counter
N = int(input())
points = []
for i, line in enumerate(sys.stdin):
x, y = map(int, line.split())
points.append([x, y])
if i == N - 1:
break
if len(points) == 1:
print(1)
sys.exit(0)
counts = []
for i in range(N):
for j in range(N):
if i == j:
continue
p = points[j][0] - points[i][0]
q = points[j][1] - points[i][1]
counts.append((p, q))
pq = Counter(counts).most_common()[0][1]
cost = N - pq
print(cost)
| insert | 10 | 10 | 10 | 13 | 0 | |
p03006 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;
using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
struct multi {
ll first;
ll second;
ll third;
multi(ll first, ll second, ll third)
: first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec) \
do { \
sort(ALL((vec))); \
(vec).erase(std::unique(ALL((vec))), (vec).end()); \
} while (0)
ll POW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = POW(n, m / 2);
return (tmp * tmp);
} else {
return (n * POW(n, m - 1));
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N;
cin >> N;
vector<pll> P(N);
REP(i, N) {
ll x, y;
cin >> x >> y;
P[i] = make_pair(x, y);
}
sort(ALL(P));
map<pll, ll> M;
REP(i, N - 1) FOR(j, i + 1, N) {
pll po = make_pair(P[j].first - P[i].first, P[j].second - P[i].second);
if (M.find(po) == M.end()) {
M[po] = 1;
} else {
M[po]++;
}
}
vl ans;
AUTO(m, M) { ans.push_back(m.second); }
sort(ALL(ans), REV(ll));
cout << min(N - ans[0], N) << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;
using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
struct multi {
ll first;
ll second;
ll third;
multi(ll first, ll second, ll third)
: first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec) \
do { \
sort(ALL((vec))); \
(vec).erase(std::unique(ALL((vec))), (vec).end()); \
} while (0)
ll POW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = POW(n, m / 2);
return (tmp * tmp);
} else {
return (n * POW(n, m - 1));
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N;
cin >> N;
vector<pll> P(N);
REP(i, N) {
ll x, y;
cin >> x >> y;
P[i] = make_pair(x, y);
}
sort(ALL(P));
map<pll, ll> M;
REP(i, N - 1) FOR(j, i + 1, N) {
pll po = make_pair(P[j].first - P[i].first, P[j].second - P[i].second);
if (M.find(po) == M.end()) {
M[po] = 1;
} else {
M[po]++;
}
}
ll ans = 0;
AUTO(m, M) { ans = max(m.second, ans); }
cout << min(N - ans, N) << endl;
return 0;
}
| replace | 103 | 107 | 103 | 106 | 0 | |
p03006 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<pair<int, int>> v(n);
for (auto &e : v)
cin >> e.first >> e.second;
sort(v.begin(), v.end());
map<pair<int, int>, int> mp;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j)
continue;
mp[make_pair(v[i].first - v[j].first, v[i].second - v[j].second)]++;
}
}
int cnt = 0;
int p = 0, q = 0;
for (auto e : mp) {
if (cnt < e.second) {
cnt = e.second;
p = e.first.first, q = e.first.second;
}
}
int ans = 100;
do {
int sum = 1;
for (int i = 0; i < n - 1; ++i) {
if ((v[i].first - p) == v[i + 1].first &&
(v[i].second - q) == v[i + 1].second)
sum += 0;
else
sum += 1;
}
ans = min(ans, sum);
} while (next_permutation(v.begin(), v.end()));
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<pair<int, int>> v(n);
for (auto &e : v)
cin >> e.first >> e.second;
sort(v.begin(), v.end());
map<pair<int, int>, int> mp;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j)
continue;
mp[make_pair(v[i].first - v[j].first, v[i].second - v[j].second)]++;
}
}
int cnt = 0;
int p = 0, q = 0;
for (auto e : mp) {
if (cnt < e.second) {
cnt = e.second;
p = e.first.first, q = e.first.second;
}
}
cout << n - cnt << endl;
return 0;
}
| replace | 61 | 74 | 61 | 62 | TLE | |
p03006 | C++ | Runtime Error | #include <bits/stdc++.h>
#define il inline
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l + r) >> 1)
#define MAXN 1050
#define MAXM
#define mod
#define inf (1 << 30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for (register int i = x; i <= y; ++i)
#define repd(i, x, y) for (register int i = x; i >= y; --i)
#define file(s) freopen(s ".in", "r", stdin), freopen(s ".my", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; }
template <typename T> il bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; }
template <typename T> il void read(T &x) {
char ch = getchar();
int f = 1;
x = 0;
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
read(x), read(args...);
}
int n, b[MAXN << 2], x[MAXN], y[MAXN], tot;
int f[MAXN << 2][MAXN << 2];
int main() {
read(n);
rep(i, 1, n) read(x[i], y[i]);
rep(i, 1, n) rep(j, 1, n) b[++tot] = x[i] - x[j], b[++tot] = y[i] - y[j];
sort(b + 1, b + tot + 1), tot = unique(b + 1, b + tot + 1) - b - 1;
#define get(x) (lower_bound(b + 1, b + tot + 1, x) - b)
rep(i, 1, n) rep(j, 1, n) if (i != j) f[get(x[i] - x[j])][get(y[i] - y[j])]++;
int ans = 0;
rep(i, 1, tot) rep(j, 1, tot) chkmax(ans, f[i][j]);
cout << n - ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define il inline
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l + r) >> 1)
#define MAXN 3050
#define MAXM
#define mod
#define inf (1 << 30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for (register int i = x; i <= y; ++i)
#define repd(i, x, y) for (register int i = x; i >= y; --i)
#define file(s) freopen(s ".in", "r", stdin), freopen(s ".my", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; }
template <typename T> il bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; }
template <typename T> il void read(T &x) {
char ch = getchar();
int f = 1;
x = 0;
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
read(x), read(args...);
}
int n, b[MAXN << 2], x[MAXN], y[MAXN], tot;
int f[MAXN << 2][MAXN << 2];
int main() {
read(n);
rep(i, 1, n) read(x[i], y[i]);
rep(i, 1, n) rep(j, 1, n) b[++tot] = x[i] - x[j], b[++tot] = y[i] - y[j];
sort(b + 1, b + tot + 1), tot = unique(b + 1, b + tot + 1) - b - 1;
#define get(x) (lower_bound(b + 1, b + tot + 1, x) - b)
rep(i, 1, n) rep(j, 1, n) if (i != j) f[get(x[i] - x[j])][get(y[i] - y[j])]++;
int ans = 0;
rep(i, 1, tot) rep(j, 1, tot) chkmax(ans, f[i][j]);
cout << n - ans << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03006 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<p> xv;
vector<p> sub;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
xv.push_back(make_pair(x, y));
}
sort(xv.begin(), xv.end());
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sub.push_back(
make_pair((xv[j].first - xv[i].first), xv[j].second - xv[i].second));
}
}
sort(sub.begin(), sub.end());
int anssub = 0;
int count = 0;
for (int i = 0; i < sub.size() - 1; i++) {
if (sub[i].first == sub[i + 1].first &&
sub[i].second == sub[i + 1].second) {
count++;
} else {
anssub = max(anssub, count);
count = 0;
}
}
cout << n - anssub - 1 << "\n";
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<p> xv;
vector<p> sub;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
xv.push_back(make_pair(x, y));
}
if (n == 1) {
cout << 1 << "\n";
return 0;
}
sort(xv.begin(), xv.end());
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sub.push_back(
make_pair((xv[j].first - xv[i].first), xv[j].second - xv[i].second));
}
}
sort(sub.begin(), sub.end());
int anssub = 0;
int count = 0;
for (int i = 0; i < sub.size() - 1; i++) {
if (sub[i].first == sub[i + 1].first &&
sub[i].second == sub[i + 1].second) {
count++;
} else {
anssub = max(anssub, count);
count = 0;
}
}
cout << n - anssub - 1 << "\n";
} | insert | 47 | 47 | 47 | 51 | 0 | |
p03006 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define ll long long
#define all(v) v.begin(), v.end()
#define si set<int>
#define sl set<long long>
#define pair(x, y) pair<x, y>
#define frt(i, a, b) for (int i = a; i < b; i++)
#define fre(i, a, b) for (int i = a; i <= b; i++)
#define rew(i, a, b) for (int i = a; i >= b; i--)
#define mod %
#define pow ^
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define test if (TEST == 1)
#define left (2 * idx) + 1
#define right (2 * idx) + 2
#define INF 1000000000000000000
#define MOD (ll)(1e9 + 7)
#define N 7001
ll powerf(ll a, ll b, ll c) {
ll ans = 1;
while (b > 0) {
if (b & 1) {
ans = (ans * a) % c;
}
b = b >> 1;
a = (a * a) % c;
}
return ans;
}
int main() {
FIO int TEST = 0;
int t = 1;
while (t--) {
int n;
cin >> n;
vector<pair(int, int)> v;
fre(i, 1, n) {
int x, y;
cin >> x >> y;
v.pb({x, y});
}
set<pair<int, pair<int, int>>> s;
map<pair<int, int>, int> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == i)
continue;
int d_x = v[i].first - v[j].first;
int d_y = v[i].second - v[j].second;
pair<int, int> d = {d_x, d_y};
if (m[d] == 0) {
m[d] = 1;
s.insert({m[d], d});
} else {
s.erase({m[d], d});
m[d] += 1;
s.insert({m[d], d});
}
}
}
pair<int, pair<int, int>> d = *s.rbegin();
// cout << d.first << " : " << d.second.first << " " << d.second.second <<
// "\n";
cout << n - (*s.rbegin()).first << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define ll long long
#define all(v) v.begin(), v.end()
#define si set<int>
#define sl set<long long>
#define pair(x, y) pair<x, y>
#define frt(i, a, b) for (int i = a; i < b; i++)
#define fre(i, a, b) for (int i = a; i <= b; i++)
#define rew(i, a, b) for (int i = a; i >= b; i--)
#define mod %
#define pow ^
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define test if (TEST == 1)
#define left (2 * idx) + 1
#define right (2 * idx) + 2
#define INF 1000000000000000000
#define MOD (ll)(1e9 + 7)
#define N 7001
ll powerf(ll a, ll b, ll c) {
ll ans = 1;
while (b > 0) {
if (b & 1) {
ans = (ans * a) % c;
}
b = b >> 1;
a = (a * a) % c;
}
return ans;
}
int main() {
FIO int TEST = 0;
int t = 1;
while (t--) {
int n;
cin >> n;
if (n == 1) {
cout << 1 << "\n";
return 0;
}
vector<pair(int, int)> v;
fre(i, 1, n) {
int x, y;
cin >> x >> y;
v.pb({x, y});
}
set<pair<int, pair<int, int>>> s;
map<pair<int, int>, int> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == i)
continue;
int d_x = v[i].first - v[j].first;
int d_y = v[i].second - v[j].second;
pair<int, int> d = {d_x, d_y};
if (m[d] == 0) {
m[d] = 1;
s.insert({m[d], d});
} else {
s.erase({m[d], d});
m[d] += 1;
s.insert({m[d], d});
}
}
}
pair<int, pair<int, int>> d = *s.rbegin();
// cout << d.first << " : " << d.second.first << " " << d.second.second <<
// "\n";
cout << n - (*s.rbegin()).first << "\n";
}
}
| replace | 55 | 56 | 55 | 59 | 0 | |
p03006 | C++ | Runtime Error | // https://atcoder.jp/contests/
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
void addElement(pll el, vector<pair<pll, ll>> &L) {
for (auto &li : L) {
if (li.first == el) {
li.second++;
return;
}
}
L.push_back(make_pair(el, 1));
return;
}
int main() {
int N, x, y;
pll XY[50], PQ[50][50];
vector<pair<pll, ll>> PQcnt;
cin >> N;
REP(i, N) {
cin >> x >> y;
REP(j, i) {
ll p = x - XY[j].first, q = y - XY[j].second;
pll pq = make_pair(p, q);
PQ[i][j] = make_pair(p, q);
PQ[j][i] = make_pair(-p, -q);
}
XY[i] = make_pair(x, y);
}
REP(i, N) {
REP(j, N) {
if (i == j)
continue;
addElement(PQ[i][j], PQcnt);
}
}
pair<pll, ll> maxpll = PQcnt[0];
for (auto &pqcnt : PQcnt) {
if (maxpll.second < pqcnt.second)
maxpll = pqcnt;
}
ll cnt = N;
REP(i, N) {
REP(j, N) {
if (i == j)
continue;
else if (PQ[i][j] == maxpll.first)
cnt--;
}
}
cout << cnt << '\n';
return 0;
}
| // https://atcoder.jp/contests/
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
void addElement(pll el, vector<pair<pll, ll>> &L) {
for (auto &li : L) {
if (li.first == el) {
li.second++;
return;
}
}
L.push_back(make_pair(el, 1));
return;
}
int main() {
int N, x, y;
pll XY[50], PQ[50][50];
vector<pair<pll, ll>> PQcnt;
cin >> N;
REP(i, N) {
cin >> x >> y;
REP(j, i) {
ll p = x - XY[j].first, q = y - XY[j].second;
pll pq = make_pair(p, q);
PQ[i][j] = make_pair(p, q);
PQ[j][i] = make_pair(-p, -q);
}
XY[i] = make_pair(x, y);
}
REP(i, N) {
REP(j, N) {
if (i == j)
continue;
addElement(PQ[i][j], PQcnt);
}
}
pair<pll, ll> maxpll = make_pair(make_pair(0, 0), -INF);
for (auto &pqcnt : PQcnt) {
if (maxpll.second < pqcnt.second)
maxpll = pqcnt;
}
ll cnt = N;
REP(i, N) {
REP(j, N) {
if (i == j)
continue;
else if (PQ[i][j] == maxpll.first)
cnt--;
}
}
cout << cnt << '\n';
return 0;
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p03006 | Python | Runtime Error | N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]
ans = 1
rates = {}
for i in range(N):
for j in range(N):
if i == j:
continue
vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
rates[vector] = rates.get(vector, 0) + 1
print(N - max(rates.values()))
| N = int(input())
inputs = [[int(i) for i in input().split()] for _ in range(N)]
ans = 1
rates = {0: 0}
for i in range(N):
for j in range(N):
if i == j:
continue
vector = (inputs[i][0] - inputs[j][0], inputs[i][1] - inputs[j][1])
rates[vector] = rates.get(vector, 0) + 1
print(N - max(rates.values()))
| replace | 4 | 5 | 4 | 5 | 0 | |
p03006 | C++ | Time Limit Exceeded | #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
int main() {
int N;
cin >> N;
if (N == 1) {
cout << 1 << endl;
return 0;
}
vector<long long> x(N);
vector<long long> y(N);
REP(i, N) { cin >> x[i] >> y[i]; }
int res = N;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (i == j)
continue;
// 各2点間の距離を全て試して最小値を導く
ll dx = x[j] - x[i];
ll dy = y[j] - y[i];
int sub = 0;
for (int i2 = 0; i2 < N; ++i) {
for (int j2 = 0; j2 < N; ++j) {
if (i2 == j2)
continue;
if (dx == x[j2] - x[i2] && dy == y[j2] - y[i2]) {
++sub;
}
res = min(res, N - sub);
}
}
}
}
cout << res << endl;
return 0;
}
| #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
int main() {
int N;
cin >> N;
if (N == 1) {
cout << 1 << endl;
return 0;
}
vector<long long> x(N);
vector<long long> y(N);
REP(i, N) { cin >> x[i] >> y[i]; }
int res = N;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (i == j)
continue;
// 各2点間の距離を全て試して最小値を導く
ll dx = x[j] - x[i];
ll dy = y[j] - y[i];
int sub = 0;
for (int i2 = 0; i2 < N; ++i2) {
for (int j2 = 0; j2 < N; ++j2) {
if (i2 == j2)
continue;
if (dx == x[j2] - x[i2] && dy == y[j2] - y[i2]) {
++sub;
}
res = min(res, N - sub);
}
}
}
}
cout << res << endl;
return 0;
}
| replace | 38 | 40 | 38 | 40 | TLE | |
p03006 | Python | Runtime Error | from collections import Counter
N = int(input())
xys = []
for _ in range(N):
xys.append(tuple(map(int, input().split())))
sub = []
for x1, y1 in xys:
for x2, y2 in xys:
if x1 != x2 or y1 != y2:
sub.append((x1 - x2, y1 - y2))
c = Counter(sub)
m = max(c.values())
print(N - m)
| from collections import Counter
N = int(input())
xys = []
for _ in range(N):
xys.append(tuple(map(int, input().split())))
sub = []
for x1, y1 in xys:
for x2, y2 in xys:
if x1 != x2 or y1 != y2:
sub.append((x1 - x2, y1 - y2))
if not sub:
print(1)
exit(0)
c = Counter(sub)
m = max(c.values())
print(N - m)
| insert | 14 | 14 | 14 | 18 | 0 | |
p03006 | Python | Runtime Error | import collections
N = int(input())
x_y = []
for _ in range(N):
x_y.append(list(map(int, input().split())))
x_y.sort(key=lambda x: (x[0], x[1]))
pq_cand = []
for i in range(N):
for j in range(i + 1, N):
pq_cand.append((x_y[j][0] - x_y[i][0], x_y[j][1] - x_y[i][1]))
pqc = collections.Counter(pq_cand)
_, x = max(pqc.items(), key=lambda x: x[1])
print(N - 1 - x + 1)
| import collections
N = int(input())
if N == 1:
print(1)
exit()
x_y = []
for _ in range(N):
x_y.append(list(map(int, input().split())))
x_y.sort(key=lambda x: (x[0], x[1]))
pq_cand = []
for i in range(N):
for j in range(i + 1, N):
pq_cand.append((x_y[j][0] - x_y[i][0], x_y[j][1] - x_y[i][1]))
pqc = collections.Counter(pq_cand)
_, x = max(pqc.items(), key=lambda x: x[1])
print(N - 1 - x + 1)
| insert | 3 | 3 | 3 | 8 | 0 | |
p03006 | Python | Runtime Error | from collections import Counter
from itertools import permutations
N = int(input())
x, y = zip(*(map(int, input().split()) for _ in range(N))) if N else ((), ())
# (p, q) = (x_i - x_j, y_i - y_j) を満たす組(i, j)の個数が最大となるように
# p, qを定めればよい
D = Counter((x[i] - x[j], y[i] - y[j]) for i, j in permutations(range(N), 2))
ans = N - max(D.values())
print(ans)
| from collections import Counter
from itertools import permutations
N = int(input())
x, y = zip(*(map(int, input().split()) for _ in range(N))) if N else ((), ())
# (p, q) = (x_i - x_j, y_i - y_j) を満たす組(i, j)の個数が最大となるように
# p, qを定めればよい
ans = (
1
if N == 1
else N
- max(
Counter(
(x[i] - x[j], y[i] - y[j]) for i, j in permutations(range(N), 2)
).values()
)
)
print(ans)
| replace | 8 | 10 | 8 | 18 | 0 | |
p03006 | Python | Runtime Error | from collections import Counter
N = int(input())
p = []
for _ in range(N):
p.append(tuple(map(int, input().split())))
d = []
for i, p1 in enumerate(p):
for j, p2 in enumerate(p):
if i == j:
continue
x = p1[0] - p2[0]
y = p1[1] - p2[1]
d.append((x, y))
c = Counter(d)
# print(c)
print(N - c.most_common()[0][1])
| from collections import Counter
N = int(input())
p = []
for _ in range(N):
p.append(tuple(map(int, input().split())))
if N == 1:
print(1)
exit()
d = []
for i, p1 in enumerate(p):
for j, p2 in enumerate(p):
if i == j:
continue
x = p1[0] - p2[0]
y = p1[1] - p2[1]
d.append((x, y))
c = Counter(d)
# print(c)
print(N - c.most_common()[0][1])
| insert | 7 | 7 | 7 | 11 | 0 | |
p03006 | Python | Runtime Error | from collections import defaultdict
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
cnt = defaultdict(int)
for i in range(n):
for j in range(n):
if i == j:
continue
cnt[(points[i][0] - points[j][0], points[i][1] - points[j][1])] += 1
# print(cnt)
ans = n - max(cnt.values())
print(ans)
| from collections import defaultdict
n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]
cnt = defaultdict(int)
cnt[(0, 0)] = 0
for i in range(n):
for j in range(n):
if i == j:
continue
cnt[(points[i][0] - points[j][0], points[i][1] - points[j][1])] += 1
# print(cnt)
ans = n - max(cnt.values())
print(ans)
| insert | 6 | 6 | 6 | 7 | 0 | |
p03006 | Python | Runtime Error | import collections
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]
diff = []
for i in range(N):
for j in range(N):
if i == j:
continue
else:
if xy[i][0] > xy[j][0]:
diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
elif xy[i][0] == xy[j][0] and xy[i][1] >= xy[j][1]:
diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
elif xy[i][0] == xy[j][0] and xy[i][1] < xy[j][1]:
diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
else:
diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
c = collections.Counter(diff)
ans = N - sorted(list(c.values()))[-1] // 2
print(ans)
| import collections
N = int(input())
xy = [[int(i) for i in input().split()] for _ in range(N)]
diff = []
for i in range(N):
for j in range(N):
if i == j:
continue
else:
if xy[i][0] > xy[j][0]:
diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
elif xy[i][0] == xy[j][0] and xy[i][1] >= xy[j][1]:
diff.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))
elif xy[i][0] == xy[j][0] and xy[i][1] < xy[j][1]:
diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
else:
diff.append((xy[j][0] - xy[i][0], xy[j][1] - xy[i][1]))
if N == 1:
ans = 1
else:
c = collections.Counter(diff)
ans = N - sorted(list(c.values()))[-1] // 2
print(ans)
| replace | 20 | 22 | 20 | 26 | 0 | |
p03006 | Python | Runtime Error | from collections import defaultdict
n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
d = defaultdict(int)
for i in range(n):
xi, yi = z[i]
for j in range(n):
if i == j:
continue
xj, yj = z[j]
d[(xi - xj, yi - yj)] += 1
print(n - max(d.values()))
| from collections import defaultdict
n = int(input())
z = [list(map(int, input().split())) for _ in range(n)]
if n == 1:
ans = 1
else:
d = defaultdict(int)
for i in range(n):
xi, yi = z[i]
for j in range(n):
if i == j:
continue
xj, yj = z[j]
d[(xi - xj, yi - yj)] += 1
ans = n - max(d.values())
print(ans)
| replace | 4 | 13 | 4 | 17 | 0 | |
p03006 | Python | Runtime Error | import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(input())
X = []
Y = []
for _ in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
cnt = defaultdict(int)
for i in range(N):
for j in range(N):
if i == j:
continue
dx = X[j] - X[i]
dy = Y[j] - Y[i]
cnt[(dx, dy)] += 1
cnt = sorted(cnt.items(), key=lambda x: x[1], reverse=True)
ans = N - cnt[0][1]
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7
def input():
return sys.stdin.readline().strip()
def main():
N = int(input())
if N == 1:
print(1)
return
X = []
Y = []
for _ in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
cnt = defaultdict(int)
for i in range(N):
for j in range(N):
if i == j:
continue
dx = X[j] - X[i]
dy = Y[j] - Y[i]
cnt[(dx, dy)] += 1
cnt = sorted(cnt.items(), key=lambda x: x[1], reverse=True)
ans = N - cnt[0][1]
print(ans)
if __name__ == "__main__":
main()
| insert | 14 | 14 | 14 | 18 | 0 | |
p03006 | Python | Runtime Error | n = int(input())
xy = set(tuple(map(int, input().split())) for _ in range(n))
costs = []
for a in xy:
besides_a = xy - {a}
for b in besides_a:
p = b[0] - a[0]
q = b[1] - a[1]
arrow_num = 0
for c in xy:
if (c[0] + p, c[1] + q) in xy:
arrow_num += 1
cost = n - arrow_num
costs.append(cost)
print(min(costs))
| n = int(input())
xy = set(tuple(map(int, input().split())) for _ in range(n))
costs = []
for a in xy:
besides_a = xy - {a}
for b in besides_a:
p = b[0] - a[0]
q = b[1] - a[1]
arrow_num = 0
for c in xy:
if (c[0] + p, c[1] + q) in xy:
arrow_num += 1
cost = n - arrow_num
costs.append(cost)
if n == 1:
print(1)
else:
print(min(costs))
| replace | 16 | 17 | 16 | 20 | 0 | |
p03006 | Python | Runtime Error | import sys
import math # noqa
import bisect # noqa
import queue # noqa
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
X = [0 for _ in range(N)]
Y = [0 for _ in range(N)]
for i in range(N):
x, y = map(int, input().split())
X[i] = x
Y[i] = y
cnt = {}
for i in range(N):
for j in range(N):
if i == j:
continue
rx = X[i] - X[j]
ry = Y[i] - Y[j]
if (rx, ry) not in cnt:
cnt[(rx, ry)] = 1
else:
cnt[(rx, ry)] += 1
if (-rx, -ry) not in cnt:
cnt[(-rx, -ry)] = 1
else:
cnt[(-rx, -ry)] += 1
cnt = [[v, k] for k, v in cnt.items()]
cnt.sort(reverse=True)
res = N - cnt[0][0] // 2
print(res)
if __name__ == "__main__":
main()
| import sys
import math # noqa
import bisect # noqa
import queue # noqa
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
if N == 1:
return print(1)
X = [0 for _ in range(N)]
Y = [0 for _ in range(N)]
for i in range(N):
x, y = map(int, input().split())
X[i] = x
Y[i] = y
cnt = {}
for i in range(N):
for j in range(N):
if i == j:
continue
rx = X[i] - X[j]
ry = Y[i] - Y[j]
if (rx, ry) not in cnt:
cnt[(rx, ry)] = 1
else:
cnt[(rx, ry)] += 1
if (-rx, -ry) not in cnt:
cnt[(-rx, -ry)] = 1
else:
cnt[(-rx, -ry)] += 1
cnt = [[v, k] for k, v in cnt.items()]
cnt.sort(reverse=True)
res = N - cnt[0][0] // 2
print(res)
if __name__ == "__main__":
main()
| insert | 12 | 12 | 12 | 16 | 0 | |
p03006 | Python | Runtime Error | import collections
def calc(balla, ballb):
xa, ya = balla
xb, yb = ballb
return xa - xb, ya - yb
n = int(input())
balls = [tuple(map(int, input().split())) for _ in range(n)]
a = []
for i in range(0, n - 1):
for j in range(i + 1, n):
tmp = calc(balls[i], balls[j])
a += [tmp, tuple(-i for i in tmp)]
counts = collections.Counter(a)
print(n - max(counts.values()))
| import collections
def calc(balla, ballb):
xa, ya = balla
xb, yb = ballb
return xa - xb, ya - yb
n = int(input())
balls = [tuple(map(int, input().split())) for _ in range(n)]
if n == 1:
print(1)
exit()
a = []
for i in range(0, n - 1):
for j in range(i + 1, n):
tmp = calc(balls[i], balls[j])
a += [tmp, tuple(-i for i in tmp)]
counts = collections.Counter(a)
print(n - max(counts.values()))
| insert | 12 | 12 | 12 | 16 | 0 | |
p03006 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> iint;
typedef pair<ll, ll> llll;
#define ALL(x) (x).begin(), (x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; // 10^18
const int inINF = 1000000000; // 10^9
const ll MOD = 1000000007; // 10^9+7
const ll MOD2 = 998244353;
int main() {
ll N;
cin >> N;
vector<ll> x(N), y(N);
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
}
vector<llll> sa;
ll a, b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
a = x[i] - x[j];
b = y[i] - y[j];
if (a < 0) {
a = -a;
b = -b;
} else if (a == 0) {
b = abs(b);
}
sa.push_back(make_pair(a, b));
}
}
sort(ALL(sa));
ll S = sa.size();
ll k = 1;
ll tmp = 1;
a = sa[0].first;
b = sa[0].second;
for (int i = 1; i < S; i++) {
if (a == sa[i].first && b == sa[i].second) {
tmp++;
} else {
k = max(tmp, k);
tmp = 1;
a = sa[i].first;
b = sa[i].second;
}
}
k = max(tmp, k);
printf("%lld\n", N - k);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> iint;
typedef pair<ll, ll> llll;
#define ALL(x) (x).begin(), (x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; // 10^18
const int inINF = 1000000000; // 10^9
const ll MOD = 1000000007; // 10^9+7
const ll MOD2 = 998244353;
int main() {
ll N;
cin >> N;
if (N == 1) {
printf("1\n");
return 0;
}
vector<ll> x(N), y(N);
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
}
vector<llll> sa;
ll a, b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
a = x[i] - x[j];
b = y[i] - y[j];
if (a < 0) {
a = -a;
b = -b;
} else if (a == 0) {
b = abs(b);
}
sa.push_back(make_pair(a, b));
}
}
sort(ALL(sa));
ll S = sa.size();
ll k = 1;
ll tmp = 1;
a = sa[0].first;
b = sa[0].second;
for (int i = 1; i < S; i++) {
if (a == sa[i].first && b == sa[i].second) {
tmp++;
} else {
k = max(tmp, k);
tmp = 1;
a = sa[i].first;
b = sa[i].second;
}
}
k = max(tmp, k);
printf("%lld\n", N - k);
} | insert | 15 | 15 | 15 | 20 | 0 | |
p03006 | Python | Runtime Error | N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.sort(key=lambda x: x[0])
PQ = {}
for i in range(N):
x0, y0 = XY[i]
for j in range(N):
if i == j:
continue
x1, y1 = XY[j]
p, q = x0 - x1, y0 - y1
key = str(p) + "," + str(q)
if key in PQ:
PQ[key] += 1
else:
PQ[key] = 1
ansL = PQ.values()
print(N - max(list(ansL)))
| N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
if N == 1:
print(1)
exit()
XY.sort(key=lambda x: x[0])
PQ = {}
for i in range(N):
x0, y0 = XY[i]
for j in range(N):
if i == j:
continue
x1, y1 = XY[j]
p, q = x0 - x1, y0 - y1
key = str(p) + "," + str(q)
if key in PQ:
PQ[key] += 1
else:
PQ[key] = 1
ansL = PQ.values()
print(N - max(list(ansL)))
| insert | 2 | 2 | 2 | 5 | 0 | |
p03006 | Python | Runtime Error | #!/usr/bin/env python3
from collections import defaultdict
(n,), *p = [[*map(int, i.split())] for i in open(0)]
d = defaultdict(int)
for i in range(n):
for j in range(n):
if i != j:
d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += 1
print(n - max(d.values()))
| #!/usr/bin/env python3
from collections import defaultdict
(n,), *p = [[*map(int, i.split())] for i in open(0)]
d = defaultdict(int)
for i in range(n):
for j in range(n):
if i != j:
d[(p[i][0] - p[j][0], p[i][1] - p[j][1])] += 1
print(n * (n < 2) or n - max(d.values()))
| replace | 9 | 10 | 9 | 10 | 0 | |
p03006 | Python | Runtime Error | from collections import defaultdict
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
for j in range(i + 1, N):
p = X[i][0] - X[j][0]
q = X[i][1] - X[j][1]
ctr[(p, q)] += 1
ctr[(-p, -q)] += 1
print(N - max(ctr.values()))
| from collections import defaultdict
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
ctr = defaultdict(int)
for i in range(N - 1):
for j in range(i + 1, N):
p = X[i][0] - X[j][0]
q = X[i][1] - X[j][1]
ctr[(p, q)] += 1
ctr[(-p, -q)] += 1
if N == 1:
print(1)
else:
print(N - max(ctr.values()))
| replace | 14 | 15 | 14 | 18 | 0 | |
p03006 | Python | Runtime Error | from collections import Counter
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
c = Counter((y[0] - x[0], y[1] - x[1]) for x in a for y in a if x < y)
print(n - max(c.values()))
| from collections import Counter
n = int(input())
a = [tuple(map(int, input().split())) for _ in range(n)]
c = Counter((y[0] - x[0], y[1] - x[1]) for x in a for y in a if x < y)
print(n - max(c.values(), default=0))
| replace | 5 | 6 | 5 | 6 | 0 | |
p03006 | Python | Runtime Error | from itertools import combinations
N = int(input())
P = []
for _ in range(N):
x, y = map(int, input().split())
P.append((x, y))
memo = dict()
for a, b in combinations(P, 2):
p, q = a[0] - b[0], a[1] - b[1]
if p < 0:
p, q = -p, -q
elif p == 0 and q < 0:
q = -q
if (p, q) in memo:
memo[(p, q)] += 1
else:
memo[(p, q)] = 1
print(N - max(memo.values()))
| from itertools import combinations
N = int(input())
P = []
for _ in range(N):
x, y = map(int, input().split())
P.append((x, y))
memo = dict()
for a, b in combinations(P, 2):
p, q = a[0] - b[0], a[1] - b[1]
if p < 0:
p, q = -p, -q
elif p == 0 and q < 0:
q = -q
if (p, q) in memo:
memo[(p, q)] += 1
else:
memo[(p, q)] = 1
print(N - max(memo.values()) if N > 1 else 1)
| replace | 20 | 21 | 20 | 21 | 0 | |
p03006 | C++ | Runtime Error | #include <bits/stdc++.h>
#define maxn 55
using namespace std;
int n, num, a[maxn], b[maxn];
map<int, map<int, int>> mp;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d%d", a[i], b[i]);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j)
num = max(num, ++mp[a[i] - a[j]][b[i] - b[j]]);
printf("%d\n", n - num);
return 0;
}
| #include <bits/stdc++.h>
#define maxn 55
using namespace std;
int n, num, a[maxn], b[maxn];
map<int, map<int, int>> mp;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d%d", a + i, b + i);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j)
num = max(num, ++mp[a[i] - a[j]][b[i] - b[j]]);
printf("%d\n", n - num);
return 0;
}
| replace | 8 | 9 | 8 | 9 | -11 | |
p03006 | Python | Runtime Error | import sys
from collections import defaultdict
from itertools import combinations
input = sys.stdin.readline
def main():
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
x[i], y[i] = map(int, input().split())
vector = defaultdict(int)
for a, b in combinations(range(N), 2):
dx = x[a] - x[b]
dy = y[a] - y[b]
if dx == 0:
vector[(0, abs(dy))] += 1
elif dx > 0:
vector[(dx, dy)] += 1
else:
vector[(-dx, -dy)] += 1
ans = N - max(vector.values())
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import defaultdict
from itertools import combinations
input = sys.stdin.readline
def main():
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
x[i], y[i] = map(int, input().split())
if N == 1:
print(1)
sys.exit()
vector = defaultdict(int)
for a, b in combinations(range(N), 2):
dx = x[a] - x[b]
dy = y[a] - y[b]
if dx == 0:
vector[(0, abs(dy))] += 1
elif dx > 0:
vector[(dx, dy)] += 1
else:
vector[(-dx, -dy)] += 1
ans = N - max(vector.values())
print(ans)
if __name__ == "__main__":
main()
| insert | 13 | 13 | 13 | 17 | 0 | |
p03006 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;
// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(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;
}
// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)
return 0;
return (x / gcd(x, y) * y);
}
ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};
char notes[110][10];
// long longしか使わない
// 素数は1より大きい
// lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
// upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
ll n;
cin >> n;
vector<pair<ll, ll>> point;
rep(i, n) {
ll x, y;
cin >> x >> y;
point.push_back(make_pair(x, y));
}
sort(point.begin(), point.end());
vector<pair<ll, ll>> dist;
rep(i, n) {
for (ll j = i + 1; j < n; ++j) {
ll nx = point[i].first - point[j].first;
ll ny = point[i].second - point[j].second;
dist.push_back(make_pair(nx, ny));
}
}
sort(dist.begin(), dist.end());
ll k = dist.size();
ll ans = 1;
ll res = 0;
ll dx = dist[0].first;
ll dy = dist[0].second;
for (ll i = 1; i < k; ++i) {
if (dist[i].first != dx || dist[i].second != dy) {
ans = max(ans, res);
res = 1;
dx = dist[i].first;
dy = dist[i].second;
} else {
res++;
ans = max(ans, res);
}
}
cout << n - ans << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;
// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(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;
}
// 最大公約数
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)
return 0;
return (x / gcd(x, y) * y);
}
ll dx[4] = {0, 0, -1, 1};
ll dy[4] = {-1, 1, 0, 0};
char notes[110][10];
// long longしか使わない
// 素数は1より大きい
// lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
// upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
ll n;
cin >> n;
if (n == 1) {
cout << 1 << endl;
return 0;
}
vector<pair<ll, ll>> point;
rep(i, n) {
ll x, y;
cin >> x >> y;
point.push_back(make_pair(x, y));
}
sort(point.begin(), point.end());
vector<pair<ll, ll>> dist;
rep(i, n) {
for (ll j = i + 1; j < n; ++j) {
ll nx = point[i].first - point[j].first;
ll ny = point[i].second - point[j].second;
dist.push_back(make_pair(nx, ny));
}
}
sort(dist.begin(), dist.end());
ll k = dist.size();
ll ans = 1;
ll res = 0;
ll dx = dist[0].first;
ll dy = dist[0].second;
for (ll i = 1; i < k; ++i) {
if (dist[i].first != dx || dist[i].second != dy) {
ans = max(ans, res);
res = 1;
dx = dist[i].first;
dy = dist[i].second;
} else {
res++;
ans = max(ans, res);
}
}
cout << n - ans << endl;
return 0;
}
| insert | 76 | 76 | 76 | 80 | 0 | |
p03006 | C++ | Runtime Error | // diverta22019_b.cpp
// Sat Jun 15 20:50:04 2019
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
int n;
vector<P> dot;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
ll first, second;
cin >> first >> second;
P temp = make_pair(first, second);
dot.push_back(temp);
}
sort(dot.begin(), dot.end());
vector<P> difs;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
P temp;
temp.first = dot[j].first - dot[i].first;
temp.second = dot[j].second - dot[i].second;
difs.push_back(temp);
}
}
sort(difs.begin(), difs.end());
ll first = difs[0].first;
ll second = difs[0].second;
int count = 1;
int final = 1;
ll finalfirst = first;
ll finalsecond = second;
for (int i = 1; i < difs.size(); i++) {
if (difs[i].first == first && difs[i].second == second) {
count++;
} else {
if (final < count) {
final = count;
finalfirst = difs[i - 1].first;
finalsecond = difs[i - 1].second;
}
count = 1;
first = difs[i].first;
second = difs[i].second;
}
}
cout << n - final << endl;
// printf("%.4f\n",ans);
} | // diverta22019_b.cpp
// Sat Jun 15 20:50:04 2019
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
int n;
vector<P> dot;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
ll first, second;
cin >> first >> second;
P temp = make_pair(first, second);
dot.push_back(temp);
}
if (n == 1) {
cout << 1 << endl;
return 0;
}
sort(dot.begin(), dot.end());
vector<P> difs;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
P temp;
temp.first = dot[j].first - dot[i].first;
temp.second = dot[j].second - dot[i].second;
difs.push_back(temp);
}
}
sort(difs.begin(), difs.end());
ll first = difs[0].first;
ll second = difs[0].second;
int count = 1;
int final = 1;
ll finalfirst = first;
ll finalsecond = second;
for (int i = 1; i < difs.size(); i++) {
if (difs[i].first == first && difs[i].second == second) {
count++;
} else {
if (final < count) {
final = count;
finalfirst = difs[i - 1].first;
finalsecond = difs[i - 1].second;
}
count = 1;
first = difs[i].first;
second = difs[i].second;
}
}
cout << n - final << endl;
// printf("%.4f\n",ans);
} | replace | 29 | 30 | 29 | 33 | 0 | |
p03006 | Python | Runtime Error | import collections
N = int(input())
xy_array = [list(map(int, input().split())) for i in range(N)]
# print(xy_array)
distance_array = []
for i in range(N):
x_i, y_i = xy_array[i]
for j in range(N):
if i == j:
continue
x_j, y_j = xy_array[j]
distance_array.append((x_i - x_j, y_i - y_j))
ans_array = collections.Counter(distance_array)
max_count = ans_array.most_common()[0][1]
print(N - max_count)
| import collections
N = int(input())
xy_array = [list(map(int, input().split())) for i in range(N)]
if N == 1:
print(1)
exit()
# print(xy_array)
distance_array = []
for i in range(N):
x_i, y_i = xy_array[i]
for j in range(N):
if i == j:
continue
x_j, y_j = xy_array[j]
distance_array.append((x_i - x_j, y_i - y_j))
ans_array = collections.Counter(distance_array)
max_count = ans_array.most_common()[0][1]
print(N - max_count)
| insert | 4 | 4 | 4 | 7 | 0 | |
p03006 | C++ | Runtime Error | #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;
cin >> n;
vector<pair<ll, ll>> z(n), d;
rep(i, n) cin >> z[i].first >> z[i].second;
sort(z.begin(), z.end());
rep(i, n - 1) forx(j, i + 1, n) d.push_back(
make_pair(z[j].first - z[i].first, z[j].second - z[i].second));
sort(d.begin(), d.end());
int k = 1;
int mx = 1;
pair<int, int> a = d[0];
rep(i, d.size() - 1) {
if (d[i] == d[i + 1]) {
k++;
if (mx < k) {
a = d[i];
mx = k;
}
} else {
k = 1;
}
}
cout << n - mx << 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;
cin >> n;
if (n == 1) {
cout << 1 << endl;
return 0;
}
vector<pair<ll, ll>> z(n), d;
rep(i, n) cin >> z[i].first >> z[i].second;
sort(z.begin(), z.end());
rep(i, n - 1) forx(j, i + 1, n) d.push_back(
make_pair(z[j].first - z[i].first, z[j].second - z[i].second));
sort(d.begin(), d.end());
int k = 1;
int mx = 1;
pair<int, int> a = d[0];
rep(i, d.size() - 1) {
if (d[i] == d[i + 1]) {
k++;
if (mx < k) {
a = d[i];
mx = k;
}
} else {
k = 1;
}
}
cout << n - mx << endl;
return 0;
} | insert | 12 | 12 | 12 | 16 | 0 | |
p03006 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <numeric>
#include <vector>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9 + 7))
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define FIND(v, x) (binary_search(ALL(v), (x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) \
sort(ALL(v)); \
reverse(ALL(v))
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
template <class T> inline bool chmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <class T> inline bool chmax(T &a, T b) {
return a < b ? a = b, true : false;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main(void) {
ll N;
cin >> N;
vector<pll> xy(N);
for (int i = 0; i < N; i++) {
cin >> xy[i].fi >> xy[i].se;
}
if (N == 1)
return 1;
ll ans = INF;
REP(i, N) {
REP(j, N) {
if (i == j)
continue;
ll p = xy[j].fi - xy[i].fi;
ll q = xy[j].se - xy[i].se;
ll tmp = 0;
REP(i2, N) {
REP(j2, N) {
if (i2 == j2)
continue;
ll tp = xy[j2].fi - xy[i2].fi;
ll tq = xy[j2].se - xy[i2].se;
if (tp == p && tq == q)
tmp++;
}
}
ans = min(ans, N - tmp);
}
}
pr(ans);
} | #include <bits/stdc++.h>
#include <numeric>
#include <vector>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9 + 7))
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define FIND(v, x) (binary_search(ALL(v), (x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) \
sort(ALL(v)); \
reverse(ALL(v))
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
template <class T> inline bool chmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <class T> inline bool chmax(T &a, T b) {
return a < b ? a = b, true : false;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main(void) {
ll N;
cin >> N;
vector<pll> xy(N);
for (int i = 0; i < N; i++) {
cin >> xy[i].fi >> xy[i].se;
}
if (N == 1) {
pr(1);
return 0;
}
ll ans = INF;
REP(i, N) {
REP(j, N) {
if (i == j)
continue;
ll p = xy[j].fi - xy[i].fi;
ll q = xy[j].se - xy[i].se;
ll tmp = 0;
REP(i2, N) {
REP(j2, N) {
if (i2 == j2)
continue;
ll tp = xy[j2].fi - xy[i2].fi;
ll tq = xy[j2].se - xy[i2].se;
if (tp == p && tq == q)
tmp++;
}
}
ans = min(ans, N - tmp);
}
}
pr(ans);
} | replace | 59 | 61 | 59 | 63 | 0 | |
p03006 | Python | Runtime Error | import sys
import collections
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
N = int(input())
XY = [[int(x) for x in input().split()] for _ in range(N)]
c = collections.Counter()
for i in range(N):
for j in range(N):
if i == j:
continue
xi, yi = XY[i]
xj, yj = XY[j]
c[(xi - xj, yi - yj)] += 1
print(N - c.most_common()[0][1])
if __name__ == "__main__":
main()
| import sys
import collections
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
N = int(input())
XY = [[int(x) for x in input().split()] for _ in range(N)]
c = collections.Counter()
if N == 1:
print(1)
return
for i in range(N):
for j in range(N):
if i == j:
continue
xi, yi = XY[i]
xj, yj = XY[j]
c[(xi - xj, yi - yj)] += 1
print(N - c.most_common()[0][1])
if __name__ == "__main__":
main()
| insert | 14 | 14 | 14 | 18 | 0 | |
p03006 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<pair<int, int>> ball(N);
int x, y;
for (int i = 0; i < N; i++) {
cin >> x >> y;
ball[i] = make_pair(x, y);
}
sort(ball.begin(), ball.end());
map<pair<int, int>, int> count;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int diff_x = ball[i].first - ball[j].first;
int diff_y = ball[i].second - ball[j].second;
count[make_pair(diff_x, diff_y)]++;
}
}
cout << N - count.rbegin()->second << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<pair<int, int>> ball(N);
int x, y;
for (int i = 0; i < N; i++) {
cin >> x >> y;
ball[i] = make_pair(x, y);
}
sort(ball.begin(), ball.end());
map<pair<int, int>, int> count;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int diff_x = ball[i].first - ball[j].first;
int diff_y = ball[i].second - ball[j].second;
count[make_pair(diff_x, diff_y)]++;
}
}
if (N == 1) {
cout << 1 << endl;
return 0;
}
int ans = INT_MAX;
for (auto itr = count.begin(); itr != count.end(); itr++) {
ans = min(ans, N - itr->second);
}
cout << ans << endl;
}
| replace | 23 | 25 | 23 | 32 | 0 | |
p03006 | Python | Runtime Error | n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float("inf")
for i in range(n - 1):
for j in range(i + 1, n):
p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
if p == 0 and q == 0:
continue
key = (p, q)
d.setdefault(key, 0)
d[key] += 1
print(n - max(d.values()))
| n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
d = {}
ret = float("inf")
for i in range(n - 1):
for j in range(i + 1, n):
p, q = a[j][0] - a[i][0], a[j][1] - a[i][1]
if p == 0 and q == 0:
continue
key = (p, q)
d.setdefault(key, 0)
d[key] += 1
print(n - (max(d.values()) if d else 0))
| replace | 12 | 13 | 12 | 13 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1];
vector<int> p, m;
int np = 0, nm = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] >= 0) {
p.push_back(a[i]);
np++;
} else if (a[i] < 0) {
m.push_back(a[i]);
nm++;
}
}
vector<int> x, y;
int ct = 0;
if (np == 0 && nm >= 2) {
vector<int>::iterator iter = max_element(m.begin(), m.end());
size_t index = distance(m.begin(), iter);
int max = m[index];
m.erase(m.begin() + index);
iter = min_element(m.begin(), m.end());
index = distance(m.begin(), iter);
int min = m[index];
m.erase(m.begin() + index);
x.push_back(max);
y.push_back(min);
p.push_back(max - min);
ct++;
np++;
nm -= 2;
} else if (nm == 0 && np > 2) {
vector<int>::iterator iter = max_element(p.begin(), p.end());
size_t index = distance(p.begin(), iter);
int max = p[index];
p.erase(p.begin() + index);
iter = min_element(p.begin(), p.end());
index = distance(p.begin(), iter);
int min = p[index];
p.erase(p.begin() + index);
x.push_back(min);
y.push_back(max);
p.push_back(min - max);
ct++;
nm++;
np -= 2;
} else if (nm == 0 && np == 2) {
int max = (p[0] > p[1]) ? p[0] : p[1];
int min = (p[0] < p[1]) ? p[0] : p[1];
x.push_back(max);
y.push_back(min);
p.pop_back();
p.pop_back();
p.push_back(max - min);
np--;
ct++;
}
while (np + nm > 1) {
if (np <= nm) {
x.push_back(p[np - 1]);
y.push_back(m[nm - 1]);
p[np - 1] = x[ct] - y[ct];
m.pop_back();
nm--;
ct++;
} else {
x.push_back(m[nm - 1]);
y.push_back(p[np - 1]);
m[nm - 1] = x[ct] - y[ct];
p.pop_back();
np--;
ct++;
}
}
cout << x[ct - 1] - y[ct - 1] << endl;
for (int i = 0; i < ct; i++) {
cout << x[i] << ' ' << y[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1];
vector<int> p, m;
int np = 0, nm = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] >= 0) {
p.push_back(a[i]);
np++;
} else if (a[i] < 0) {
m.push_back(a[i]);
nm++;
}
}
vector<int> x, y;
int ct = 0;
if (np == 0 && nm >= 2) {
vector<int>::iterator iter = max_element(m.begin(), m.end());
size_t index = distance(m.begin(), iter);
int max = m[index];
m.erase(m.begin() + index);
iter = min_element(m.begin(), m.end());
index = distance(m.begin(), iter);
int min = m[index];
m.erase(m.begin() + index);
x.push_back(max);
y.push_back(min);
p.push_back(max - min);
ct++;
np++;
nm -= 2;
} else if (nm == 0 && np > 2) {
vector<int>::iterator iter = max_element(p.begin(), p.end());
size_t index = distance(p.begin(), iter);
int max = p[index];
p.erase(p.begin() + index);
iter = min_element(p.begin(), p.end());
index = distance(p.begin(), iter);
int min = p[index];
p.erase(p.begin() + index);
x.push_back(min);
y.push_back(max);
m.push_back(min - max);
ct++;
nm++;
np -= 2;
} else if (nm == 0 && np == 2) {
int max = (p[0] > p[1]) ? p[0] : p[1];
int min = (p[0] < p[1]) ? p[0] : p[1];
x.push_back(max);
y.push_back(min);
p.pop_back();
p.pop_back();
p.push_back(max - min);
np--;
ct++;
}
while (np + nm > 1) {
if (np <= nm) {
x.push_back(p[np - 1]);
y.push_back(m[nm - 1]);
p[np - 1] = x[ct] - y[ct];
m.pop_back();
nm--;
ct++;
} else {
x.push_back(m[nm - 1]);
y.push_back(p[np - 1]);
m[nm - 1] = x[ct] - y[ct];
p.pop_back();
np--;
ct++;
}
}
cout << x[ct - 1] - y[ct - 1] << endl;
for (int i = 0; i < ct; i++) {
cout << x[i] << ' ' << y[i] << endl;
}
return 0;
} | replace | 48 | 49 | 48 | 49 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
inline bool cmp(const int &x, const int &y) { return x > y; }
int main() {
int n;
scanf("%d", &n);
int s = 0;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), s += a[i];
sort(a + 1, a + n + 1, cmp);
if (a[n] > 0) {
s -= a[n] * 2;
printf("%d\n", s);
int t = a[n];
for (int i = 2; i < n; i++) {
printf("%d %d\n", t, a[i]);
t = t - a[i];
}
printf("%d %d\n", a[1], t);
} else if (a[2] < 0) {
s = a[1] * 2 - s;
printf("%d\n", s);
int t = a[1];
for (int i = 2; i <= n; i++) {
printf("%d %d\n", t, a[i]);
t -= a[i];
}
} else {
int k = 1;
while (a[k] >= 0)
k++;
s = 0;
for (int i = 1; i <= n; i++)
s += abs(a[i]);
printf("%d\n", s);
int t = a[k];
for (int i = 2; i < k; i++) {
printf("%d %d\n", t, a[i]);
t -= a[i];
}
printf("%d %d\n", a[1], t);
t = a[1] - t;
for (int i = k + 1; i <= n; i++) {
printf("%d %d\n", t, a[i]);
t -= a[i];
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N];
inline bool cmp(const int &x, const int &y) { return x > y; }
int main() {
int n;
scanf("%d", &n);
int s = 0;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), s += a[i];
sort(a + 1, a + n + 1, cmp);
if (a[n] > 0) {
s -= a[n] * 2;
printf("%d\n", s);
int t = a[n];
for (int i = 2; i < n; i++) {
printf("%d %d\n", t, a[i]);
t = t - a[i];
}
printf("%d %d\n", a[1], t);
} else if (a[2] < 0) {
s = a[1] * 2 - s;
printf("%d\n", s);
int t = a[1];
for (int i = 2; i <= n; i++) {
printf("%d %d\n", t, a[i]);
t -= a[i];
}
} else {
int k = 1;
while (k < n && a[k] >= 0)
k++;
s = 0;
for (int i = 1; i <= n; i++)
s += abs(a[i]);
printf("%d\n", s);
int t = a[k];
for (int i = 2; i < k; i++) {
printf("%d %d\n", t, a[i]);
t -= a[i];
}
printf("%d %d\n", a[1], t);
t = a[1] - t;
for (int i = k + 1; i <= n; i++) {
printf("%d %d\n", t, a[i]);
t -= a[i];
}
}
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p03007 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <set>
#include <vector>
#define M 1000000007
#define int long long
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i;
cin >> n;
multiset<int> a;
for (i = 0; i < n; i++) {
int p;
cin >> p;
a.insert(p);
}
int b[n - 1][2];
i = 0;
auto it = a.begin();
auto it1 = it;
for (;; i++) {
if (a.size() == 2) {
b[i][1] = *it;
it++;
b[i][0] = *it;
break;
}
it1++;
if (*it1 < 0) {
it1 = a.end();
it--;
b[i][0] = *it1;
b[i][1] = *it;
a.erase(it);
a.erase(it1);
} else {
b[i][0] = *it;
b[i][1] = *it1;
a.erase(it);
a.erase(it1);
}
a.insert(b[i][0] - b[i][1]);
it = a.begin();
it1 = it;
}
cout << b[n - 2][0] - b[n - 2][1] << endl;
for (i = 0; i < n - 1; i++)
cout << b[i][0] << ' ' << b[i][1] << endl;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <set>
#include <vector>
#define M 1000000007
#define int long long
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i;
cin >> n;
multiset<int> a;
for (i = 0; i < n; i++) {
int p;
cin >> p;
a.insert(p);
}
int b[n - 1][2];
i = 0;
auto it = a.begin();
auto it1 = it;
for (;; i++) {
if (a.size() == 2) {
b[i][1] = *it;
it++;
b[i][0] = *it;
break;
}
it1++;
if (*it1 < 0) {
it1 = a.end();
it1--;
b[i][0] = *it1;
b[i][1] = *it;
a.erase(it);
a.erase(it1);
} else {
b[i][0] = *it;
b[i][1] = *it1;
a.erase(it);
a.erase(it1);
}
a.insert(b[i][0] - b[i][1]);
it = a.begin();
it1 = it;
}
cout << b[n - 2][0] - b[n - 2][1] << endl;
for (i = 0; i < n - 1; i++)
cout << b[i][0] << ' ' << b[i][1] << endl;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, a[N];
vector<int> pos, neg;
int z;
vector<pair<int, int>> ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
if (a[i] < 0)
neg.push_back(a[i]);
else if (a[i] > 0)
pos.push_back(a[i]);
else
z++;
if (pos.size() and neg.size()) {
int po = pos[0], ne = neg[0];
for (int i = 1; i < pos.size(); i++)
ans.push_back({ne, pos[i]}), ne -= pos[i];
for (int i = 1; i < neg.size(); i++)
ans.push_back({po, neg[i]}), po -= neg[i];
ans.push_back({po, ne});
cout << po - ne << '\n';
for (pair<int, int> x : ans)
cout << x.first << ' ' << x.second << '\n';
while (z--)
cout << po - ne << " 0\n";
return 0;
} else {
if (z) {
if (pos.size() == 1 or neg.size() == 1) {
int now;
if (pos.size())
cout << pos[0] << '\n', now = pos[0];
else
cout << -neg[0] << '\n', now = neg[0];
if (neg.size())
cout << "0 " << now << '\n', z--;
now = abs(now);
while (z--)
cout << now << " 0\n";
return 0;
}
if (pos.size()) {
ans.push_back({0, pos.back()});
neg.push_back(-pos.back());
pos.resize(pos.size() - 1);
z--;
} else {
ans.push_back({0, neg.back()});
pos.push_back(-neg.back());
neg.resize(neg.size() - 1);
z--;
}
int po = pos[0], ne = neg[0];
for (int i = 1; i < pos.size(); i++)
ans.push_back({ne, pos[i]}), ne -= pos[i];
for (int i = 1; i < neg.size(); i++)
ans.push_back({po, neg[i]}), po -= neg[i];
ans.push_back({po, ne});
cout << po - ne << '\n';
for (pair<int, int> x : ans)
cout << x.first << ' ' << x.second << '\n';
while (z--)
cout << po - ne << " 0\n";
return 0;
} else {
if (pos.size()) {
int s = 0;
sort(pos.begin(), pos.end());
for (int i = 1; i < n; i++)
s += pos[i];
s -= pos[0];
cout << s << '\n';
int now = pos[0] - pos[1];
cout << pos[0] << ' ' << pos[1] << '\n';
for (int i = 2; i < n - 1; i++)
cout << now << ' ' << pos[i] << '\n', now -= pos[i];
cout << pos.back() << ' ' << now;
return 0;
} else {
int s = 0;
sort(neg.begin(), neg.end());
reverse(neg.begin(), neg.end());
for (int i = 1; i < n; i++)
s += neg[i];
s -= neg[0];
cout << -s << '\n';
int now = neg[0] - neg[1];
cout << neg[0] << ' ' << neg[1] << '\n';
for (int i = 2; i < n - 1; i++)
cout << now << ' ' << neg[i] << '\n', now -= neg[i];
cout << now << ' ' << neg.back();
return 0;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, a[N];
vector<int> pos, neg;
int z;
vector<pair<int, int>> ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
if (a[i] < 0)
neg.push_back(a[i]);
else if (a[i] > 0)
pos.push_back(a[i]);
else
z++;
if (z == n) {
cout << "0\n";
n--;
while (n--)
cout << "0 0\n";
return 0;
}
if (pos.size() and neg.size()) {
int po = pos[0], ne = neg[0];
for (int i = 1; i < pos.size(); i++)
ans.push_back({ne, pos[i]}), ne -= pos[i];
for (int i = 1; i < neg.size(); i++)
ans.push_back({po, neg[i]}), po -= neg[i];
ans.push_back({po, ne});
cout << po - ne << '\n';
for (pair<int, int> x : ans)
cout << x.first << ' ' << x.second << '\n';
while (z--)
cout << po - ne << " 0\n";
return 0;
} else {
if (z) {
if (pos.size() == 1 or neg.size() == 1) {
int now;
if (pos.size())
cout << pos[0] << '\n', now = pos[0];
else
cout << -neg[0] << '\n', now = neg[0];
if (neg.size())
cout << "0 " << now << '\n', z--;
now = abs(now);
while (z--)
cout << now << " 0\n";
return 0;
}
if (pos.size()) {
ans.push_back({0, pos.back()});
neg.push_back(-pos.back());
pos.resize(pos.size() - 1);
z--;
} else {
ans.push_back({0, neg.back()});
pos.push_back(-neg.back());
neg.resize(neg.size() - 1);
z--;
}
int po = pos[0], ne = neg[0];
for (int i = 1; i < pos.size(); i++)
ans.push_back({ne, pos[i]}), ne -= pos[i];
for (int i = 1; i < neg.size(); i++)
ans.push_back({po, neg[i]}), po -= neg[i];
ans.push_back({po, ne});
cout << po - ne << '\n';
for (pair<int, int> x : ans)
cout << x.first << ' ' << x.second << '\n';
while (z--)
cout << po - ne << " 0\n";
return 0;
} else {
if (pos.size()) {
int s = 0;
sort(pos.begin(), pos.end());
for (int i = 1; i < n; i++)
s += pos[i];
s -= pos[0];
cout << s << '\n';
int now = pos[0] - pos[1];
cout << pos[0] << ' ' << pos[1] << '\n';
for (int i = 2; i < n - 1; i++)
cout << now << ' ' << pos[i] << '\n', now -= pos[i];
cout << pos.back() << ' ' << now;
return 0;
} else {
int s = 0;
sort(neg.begin(), neg.end());
reverse(neg.begin(), neg.end());
for (int i = 1; i < n; i++)
s += neg[i];
s -= neg[0];
cout << -s << '\n';
int now = neg[0] - neg[1];
cout << neg[0] << ' ' << neg[1] << '\n';
for (int i = 2; i < n - 1; i++)
cout << now << ' ' << neg[i] << '\n', now -= neg[i];
cout << now << ' ' << neg.back();
return 0;
}
}
}
}
| insert | 26 | 26 | 26 | 34 | 0 | |
p03007 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
deque<int> neg, pos;
for (int i = 0; i < n; ++i) {
auto val = 0;
cin >> val;
if (val < 0)
neg.push_back(val);
else
pos.push_back(val);
}
sort(neg.begin(), neg.end());
sort(pos.begin(), pos.end());
vector<pair<int, int>> method;
int negSize, posSize;
for (negSize = neg.size(), posSize = pos.size();;
negSize = neg.size(), posSize = pos.size()) {
if (posSize == 1 && negSize == 0)
break;
if (negSize == 0) {
neg.push_back(pos.front());
pos.pop_front();
}
if (posSize == 0) {
pos.push_front(neg.back());
neg.pop_back();
}
if (negSize < posSize) {
auto negVal = neg.back() - pos.front();
method.push_back(make_pair(neg.back(), pos.front()));
neg.pop_back();
pos.pop_front();
neg.push_back(negVal);
} else {
auto posVal = pos.front() - neg.back();
method.push_back(make_pair(pos.front(), neg.back()));
pos.pop_front();
neg.pop_back();
pos.push_front(posVal);
}
}
cout << pos[0] << endl;
for (auto m : method) {
cout << m.first << " " << m.second << endl;
}
return 0;
} | #include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
deque<int> neg, pos;
for (int i = 0; i < n; ++i) {
auto val = 0;
cin >> val;
if (val < 0)
neg.push_back(val);
else
pos.push_back(val);
}
sort(neg.begin(), neg.end());
sort(pos.begin(), pos.end());
vector<pair<int, int>> method;
int negSize, posSize;
for (negSize = neg.size(), posSize = pos.size();;
negSize = neg.size(), posSize = pos.size()) {
if (posSize + negSize == 1)
break;
if (negSize == 0) {
neg.push_back(pos.front());
pos.pop_front();
}
if (posSize == 0) {
pos.push_front(neg.back());
neg.pop_back();
}
if (negSize < posSize) {
auto negVal = neg.back() - pos.front();
method.push_back(make_pair(neg.back(), pos.front()));
neg.pop_back();
pos.pop_front();
neg.push_back(negVal);
} else {
auto posVal = pos.front() - neg.back();
method.push_back(make_pair(pos.front(), neg.back()));
pos.pop_front();
neg.pop_back();
pos.push_front(posVal);
}
}
cout << pos[0] << endl;
for (auto m : method) {
cout << m.first << " " << m.second << endl;
}
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
Int n;
vector<Int> a;
using P = pair<Int, Int>;
vector<P> v;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
a.resize(n);
for (auto &i : a)
cin >> i;
Int mi = 1e9, ma = -1e9, imi = -1, ima = -1;
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] > ma) {
ma = a[i];
ima = i;
}
}
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] < ma && a[i] < mi) {
mi = a[i];
imi = i;
}
}
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] >= 0 && i != imi && i != ima) {
v.push_back(P(a[imi], a[i]));
a[imi] -= a[i];
}
}
for (size_t i = 0; i < a.size(); ++i) {
if ((a[i] < 0 || i == imi) && i != ima) {
v.push_back(P(a[ima], a[i]));
a[ima] -= a[i];
}
}
cout << a[ima] << "\n";
for (auto i : v)
cout << i.first << " " << i.second << "\n";
} | #include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
Int n;
vector<Int> a;
using P = pair<Int, Int>;
vector<P> v;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
a.resize(n);
for (auto &i : a)
cin >> i;
Int mi = 1e9, ma = -1e9, imi = -1, ima = -1;
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] > ma) {
ma = a[i];
ima = i;
}
}
for (size_t i = 0; i < a.size(); ++i) {
if (i != ima && a[i] < mi) {
mi = a[i];
imi = i;
}
}
for (size_t i = 0; i < a.size(); ++i) {
if (a[i] >= 0 && i != imi && i != ima) {
v.push_back(P(a[imi], a[i]));
a[imi] -= a[i];
}
}
for (size_t i = 0; i < a.size(); ++i) {
if ((a[i] < 0 || i == imi) && i != ima) {
v.push_back(P(a[ima], a[i]));
a[ima] -= a[i];
}
}
cout << a[ima] << "\n";
for (auto i : v)
cout << i.first << " " << i.second << "\n";
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03007 | C++ | Runtime Error | /**
* @brief : c++ code for AtCoder
* @author : rk222
* @created: 2019.06.15 20:56:28
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))
#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v) \
cout << #v << ":"; \
rep(i, v.size()) cout << " " << v[i]; \
cout << endl
const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1},
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
/* ------------------------------------- */
int main() {
int n;
int a[10005];
vector<int> neg;
vector<int> pog;
scanf("%d", &n);
rep(i, n) {
scanf("%d", &a[i]);
if (a[i] < 0) {
neg.pb(a[i]);
} else {
pog.pb(a[i]);
}
}
sor(neg);
sor(pog);
int negl;
if (0 < neg.size() && neg.size() < n) {
negl = neg.size();
} else if (neg.size() == 0) {
negl = 1;
} else {
negl = n - 1;
}
int m = 0;
int negcnt = 0;
vector<int> retneg;
vector<int> retpog;
rep(i, neg.size()) {
if (negcnt < negl) {
negcnt++;
retneg.pb(neg[i]);
m += -neg[i];
} else {
retpog.pb(neg[i]);
m += neg[i];
}
}
rep(i, pog.size()) {
if (negcnt < negl) {
negcnt++;
retneg.pb(pog[i]);
m += -pog[i];
} else {
retpog.pb(pog[i]);
m += pog[i];
}
}
printf("%d\n", m);
vector<P> ret;
negcnt = 0;
int pogid = 0;
int negid = 0;
bool flip = false;
rep(i, n - 1) {
// 残り回数
int nokori = n - 1 - i;
// 残りマイナス数
int negnokori = negl - negid;
// 残り+数
int pognokori = (n - negl) - pogid;
if ((negnokori == 0 && flip) || (pognokori == 0 && !flip) ||
(nokori == negnokori && !flip) || (nokori == pognokori && flip)) {
if (flip) {
m = retpog[pogid] + m;
ret.pb(P(m, retpog[pogid]));
pogid++;
} else {
m = m + retneg[negid];
ret.pb(P(m, retneg[negid]));
negid++;
}
} else {
if (flip) {
m = retneg[negid] - m;
ret.pb(P(retneg[negid], m));
negid++;
} else {
m = retpog[pogid] - m;
ret.pb(P(retpog[pogid], m));
pogid++;
}
flip = !flip;
}
}
rrep(i, n - 1) { printf("%d %d\n", ret[i].fr, ret[i].sc); }
/* --------------------------------- */
return 0;
} | /**
* @brief : c++ code for AtCoder
* @author : rk222
* @created: 2019.06.15 20:56:28
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))
#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v) \
cout << #v << ":"; \
rep(i, v.size()) cout << " " << v[i]; \
cout << endl
const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1},
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
/* ------------------------------------- */
int main() {
int n;
int a[100005];
vector<int> neg;
vector<int> pog;
scanf("%d", &n);
rep(i, n) {
scanf("%d", &a[i]);
if (a[i] < 0) {
neg.pb(a[i]);
} else {
pog.pb(a[i]);
}
}
sor(neg);
sor(pog);
int negl;
if (0 < neg.size() && neg.size() < n) {
negl = neg.size();
} else if (neg.size() == 0) {
negl = 1;
} else {
negl = n - 1;
}
int m = 0;
int negcnt = 0;
vector<int> retneg;
vector<int> retpog;
rep(i, neg.size()) {
if (negcnt < negl) {
negcnt++;
retneg.pb(neg[i]);
m += -neg[i];
} else {
retpog.pb(neg[i]);
m += neg[i];
}
}
rep(i, pog.size()) {
if (negcnt < negl) {
negcnt++;
retneg.pb(pog[i]);
m += -pog[i];
} else {
retpog.pb(pog[i]);
m += pog[i];
}
}
printf("%d\n", m);
vector<P> ret;
negcnt = 0;
int pogid = 0;
int negid = 0;
bool flip = false;
rep(i, n - 1) {
// 残り回数
int nokori = n - 1 - i;
// 残りマイナス数
int negnokori = negl - negid;
// 残り+数
int pognokori = (n - negl) - pogid;
if ((negnokori == 0 && flip) || (pognokori == 0 && !flip) ||
(nokori == negnokori && !flip) || (nokori == pognokori && flip)) {
if (flip) {
m = retpog[pogid] + m;
ret.pb(P(m, retpog[pogid]));
pogid++;
} else {
m = m + retneg[negid];
ret.pb(P(m, retneg[negid]));
negid++;
}
} else {
if (flip) {
m = retneg[negid] - m;
ret.pb(P(retneg[negid], m));
negid++;
} else {
m = retpog[pogid] - m;
ret.pb(P(retpog[pogid], m));
pogid++;
}
flip = !flip;
}
}
rrep(i, n - 1) { printf("%d %d\n", ret[i].fr, ret[i].sc); }
/* --------------------------------- */
return 0;
} | replace | 54 | 55 | 54 | 55 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INCANT \
cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), \
cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; }
template <class T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; }
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for (int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for (auto &&i : n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
INCANT;
int n, a, mn, mx;
deque<int> q;
vector<pair<int, int>> res;
cin >> n;
rep(i, n) {
cin >> a;
q.push_back(a);
}
sort(all(q));
mx = q.back();
mn = q.front();
q.pop_back();
q.pop_front();
while (q.front() < 0) {
res.push_back({mx, q.front()});
mx -= q.front();
q.pop_front();
}
while (!q.empty()) {
res.push_back({mn, q.back()});
mn -= q.back();
q.pop_back();
}
cout << mx - mn << endl;
each(p, res) { cout << p.first << ' ' << p.second << endl; }
cout << mx << ' ' << mn << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define INCANT \
cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), \
cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; }
template <class T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; }
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for (int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for (auto &&i : n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
INCANT;
int n, a, mn, mx;
deque<int> q;
vector<pair<int, int>> res;
cin >> n;
rep(i, n) {
cin >> a;
q.push_back(a);
}
sort(all(q));
mx = q.back();
mn = q.front();
q.pop_back();
q.pop_front();
while (q.front() < 0 && !q.empty()) {
res.push_back({mx, q.front()});
mx -= q.front();
q.pop_front();
}
while (!q.empty()) {
res.push_back({mn, q.back()});
mn -= q.back();
q.pop_back();
}
cout << mx - mn << endl;
each(p, res) { cout << p.first << ' ' << p.second << endl; }
cout << mx << ' ' << mn << endl;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;
}
int main() {
ll n;
cin >> n;
vector<ll> as(n);
rep(i, 0, n) cin >> as[i];
sort(as.begin(), as.end());
ll ans;
rep(i, 0, n) {
if (i == 0)
ans -= as[i];
else if (i == n - 1)
ans += as[i];
else if (as[i] >= 0)
ans += as[i];
else
ans -= as[i];
}
cout << ans << endl;
if (as[n - 1] < 0) {
ll x = as[n - 1];
rep(i, 0, n - 1) {
cout << x << " " << as[i] << endl;
x -= as[i];
}
assert(x == ans);
return 0;
}
if (as[0] > 0) {
ll x = as[0];
rep(i, 1, n - 1) {
cout << x << " " << as[i] << endl;
x -= as[i];
}
cout << as[n - 1] << " " << x << endl;
x = as[n - 1] - x;
assert(x == ans);
return 0;
}
ll p = as[n - 1], q = as[0];
rep(i, 1, n - 1) {
if (as[i] <= 0) {
cout << p << " " << as[i] << endl;
p -= as[i];
} else {
cout << q << " " << as[i] << endl;
q -= as[i];
}
}
cout << p << " " << q << endl;
p -= q;
assert(p == ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;
}
int main() {
ll n;
cin >> n;
vector<ll> as(n);
rep(i, 0, n) cin >> as[i];
sort(as.begin(), as.end());
ll ans = 0;
rep(i, 0, n) {
if (i == 0)
ans -= as[i];
else if (i == n - 1)
ans += as[i];
else if (as[i] >= 0)
ans += as[i];
else
ans -= as[i];
}
cout << ans << endl;
if (as[n - 1] < 0) {
ll x = as[n - 1];
rep(i, 0, n - 1) {
cout << x << " " << as[i] << endl;
x -= as[i];
}
assert(x == ans);
return 0;
}
if (as[0] > 0) {
ll x = as[0];
rep(i, 1, n - 1) {
cout << x << " " << as[i] << endl;
x -= as[i];
}
cout << as[n - 1] << " " << x << endl;
x = as[n - 1] - x;
assert(x == ans);
return 0;
}
ll p = as[n - 1], q = as[0];
rep(i, 1, n - 1) {
if (as[i] <= 0) {
cout << p << " " << as[i] << endl;
p -= as[i];
} else {
cout << q << " " << as[i] << endl;
q -= as[i];
}
}
cout << p << " " << q << endl;
p -= q;
assert(p == ans);
return 0;
} | replace | 23 | 24 | 23 | 24 | -6 | e12f7e03-e7c5-4682-98ad-9dc076e4ba31.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03007/C++/s867890935.cpp:61: int main(): Assertion `p == ans' failed.
|
p03007 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n = 0;
cin >> n;
vector<int> num(n);
for (int i = 0; i < n; i++) {
cin >> num.at(i);
}
sort(num.begin(), num.end());
vector<vector<long long>> ope(n - 1, vector<long long>(2));
int plus = lower_bound(num.begin(), num.end(), 0) - num.begin();
long long ans = num.at(0);
int check = 0;
if (plus == 0)
plus++;
for (int i = plus; i < n - 1; i++) {
ope.at(check).at(0) = ans;
ope.at(check).at(1) = num.at(i);
check++;
ans -= num.at(i);
}
ope.at(check).at(0) = num.at(n - 1);
ope.at(check).at(1) = ans;
check++;
ans = num.at(n - 1) - ans;
for (int i = 1; i < plus; i++) {
ope.at(check).at(0) = ans;
ope.at(check).at(1) = num.at(i);
check++;
ans -= num.at(i);
}
cout << ans << endl;
for (vector<long long> a : ope) {
cout << a.at(0) << " " << a.at(1) << endl;
}
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n = 0;
cin >> n;
vector<int> num(n);
for (int i = 0; i < n; i++) {
cin >> num.at(i);
}
sort(num.begin(), num.end());
vector<vector<long long>> ope(n - 1, vector<long long>(2));
int plus = lower_bound(num.begin(), num.end(), 0) - num.begin();
long long ans = num.at(0);
int check = 0;
if (plus > n - 1)
plus = n - 1;
if (plus == 0)
plus++;
for (int i = plus; i < n - 1; i++) {
ope.at(check).at(0) = ans;
ope.at(check).at(1) = num.at(i);
check++;
ans -= num.at(i);
}
ope.at(check).at(0) = num.at(n - 1);
ope.at(check).at(1) = ans;
check++;
ans = num.at(n - 1) - ans;
for (int i = 1; i < plus; i++) {
ope.at(check).at(0) = ans;
ope.at(check).at(1) = num.at(i);
check++;
ans -= num.at(i);
}
cout << ans << endl;
for (vector<long long> a : ope) {
cout << a.at(0) << " " << a.at(1) << endl;
}
return 0;
}
| insert | 24 | 24 | 24 | 26 | 0 | |
p03007 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int ans = 0;
vector<P> astr;
priority_queue<int> mq;
priority_queue<int, vector<int>, greater<int>> pq;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a < 0)
mq.push(a);
else
pq.push(a);
}
if (mq.empty()) {
int a, b;
a = pq.top();
pq.pop();
b = pq.top();
pq.pop();
astr.push_back(P(a, b));
mq.push(a - b);
}
if (pq.empty()) {
int a, b;
a = mq.top();
mq.pop();
b = mq.top();
mq.pop();
astr.push_back(P(a, b));
pq.push(a - b);
}
ans = mq.top();
mq.pop();
int last = pq.top();
pq.pop();
while (!pq.empty()) {
astr.push_back(P(ans, pq.top()));
ans -= pq.top();
pq.pop();
}
astr.push_back(P(last, ans));
ans = last - ans;
while (!mq.empty()) {
astr.push_back(P(ans, mq.top()));
ans -= mq.top();
mq.pop();
}
cout << ans << '\n';
for (auto a : astr)
cout << a.first << " " << a.second << '\n';
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int ans = 0;
vector<P> astr;
priority_queue<int> mq;
priority_queue<int, vector<int>, greater<int>> pq;
if (n == 2) {
int a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
cout << b - a << endl;
cout << b << " " << a << endl;
return 0;
}
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a < 0)
mq.push(a);
else
pq.push(a);
}
if (mq.empty()) {
int a, b;
a = pq.top();
pq.pop();
b = pq.top();
pq.pop();
astr.push_back(P(a, b));
mq.push(a - b);
}
if (pq.empty()) {
int a, b;
a = mq.top();
mq.pop();
b = mq.top();
mq.pop();
astr.push_back(P(a, b));
pq.push(a - b);
}
ans = mq.top();
mq.pop();
int last = pq.top();
pq.pop();
while (!pq.empty()) {
astr.push_back(P(ans, pq.top()));
ans -= pq.top();
pq.pop();
}
astr.push_back(P(last, ans));
ans = last - ans;
while (!mq.empty()) {
astr.push_back(P(ans, mq.top()));
ans -= mq.top();
mq.pop();
}
cout << ans << '\n';
for (auto a : astr)
cout << a.first << " " << a.second << '\n';
} | insert | 21 | 21 | 21 | 31 | TLE | |
p03007 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#define MAX_N (100000)
using namespace std;
int main(int argc, char *argv[]) {
// read inputs
int N, as[MAX_N];
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &as[i]);
}
// divide into positive and negative
vector<int> ps, ns;
for (int i = 0; i < N; i++) {
const int a = as[i];
if (a >= 0) {
ps.push_back(a);
} else {
ns.push_back(a);
}
}
// solve
int ans;
vector<int> xs, ys;
if (ns.size() == 0) {
sort(ps.begin(), ps.end());
const int n = ps[0] - ps[ps.size() - 1];
ns.push_back(n);
xs.push_back(ps[0]);
ys.push_back(ps[ps.size() - 1]);
vector<int> pds;
for (int i = 1; i < ps.size() - 1; i++) {
pds.push_back(ps[i]);
}
ps = pds;
} else if (ps.size() == 0) {
sort(ns.begin(), ns.end());
const int p = ns[ns.size() - 1] - ns[0];
xs.push_back(ns[ns.size() - 1]);
ys.push_back(ns[0]);
ps.push_back(p);
vector<int> nds;
for (int i = 1; i < ns.size() - 1; i++) {
nds.push_back(ns[i]);
}
ns = nds;
}
if (ps.size() > 0 && ns.size() > 0) {
for (int i = 1; i < ps.size(); i++) {
const int x = ns[0], y = ps[i];
xs.push_back(x);
ys.push_back(y);
ns[0] -= y;
}
for (int i = 0; i < ns.size(); i++) {
const int x = ps[0], y = ns[i];
xs.push_back(x);
ys.push_back(y);
ps[0] -= y;
}
ans = ps[0];
} else {
exit(-1);
}
// print ans
printf("%d\n", ans);
for (int i = 0; i < N - 1; i++) {
printf("%d %d\n", xs[i], ys[i]);
}
return 0;
}
| #include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#define MAX_N (100000)
using namespace std;
int main(int argc, char *argv[]) {
// read inputs
int N, as[MAX_N];
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &as[i]);
}
// divide into positive and negative
vector<int> ps, ns;
for (int i = 0; i < N; i++) {
const int a = as[i];
if (a >= 0) {
ps.push_back(a);
} else {
ns.push_back(a);
}
}
// solve
int ans;
vector<int> xs, ys;
if (ns.size() == 0) {
sort(ps.begin(), ps.end());
const int n = ps[0] - ps[ps.size() - 1];
ns.push_back(n);
xs.push_back(ps[0]);
ys.push_back(ps[ps.size() - 1]);
vector<int> pds;
for (int i = 1; i < ps.size() - 1; i++) {
pds.push_back(ps[i]);
}
ps = pds;
} else if (ps.size() == 0) {
sort(ns.begin(), ns.end());
const int p = ns[ns.size() - 1] - ns[0];
xs.push_back(ns[ns.size() - 1]);
ys.push_back(ns[0]);
ps.push_back(p);
vector<int> nds;
for (int i = 1; i < ns.size() - 1; i++) {
nds.push_back(ns[i]);
}
ns = nds;
}
if (ps.size() > 0 && ns.size() > 0) {
for (int i = 1; i < ps.size(); i++) {
const int x = ns[0], y = ps[i];
xs.push_back(x);
ys.push_back(y);
ns[0] -= y;
}
for (int i = 0; i < ns.size(); i++) {
const int x = ps[0], y = ns[i];
xs.push_back(x);
ys.push_back(y);
ps[0] -= y;
}
ans = ps[0];
} else if (ps.size() > 0) {
ans = ps[0];
} else if (ns.size() > 0) {
ans = -ns[0];
int tmp = xs[0];
xs[0] = ys[0];
ys[0] = tmp;
} else {
exit(-1);
}
// print ans
printf("%d\n", ans);
for (int i = 0; i < N - 1; i++) {
printf("%d %d\n", xs[i], ys[i]);
}
return 0;
}
| insert | 68 | 68 | 68 | 75 | 0 | |
p03007 | C++ | Runtime Error | // #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair<int, int> PII;
typedef pair<int64, int64> PLL;
// }
// #parameter{
#ifdef _DEBUG
#define TYPE decltype
#define RF(filename) \
{ freopen((filename), "r", stdin); }
#define WF(filename) \
{ freopen((filename), "w", stdout); }
#define DF(filename) \
{ freopen((filename), "w", stderr); }
#define eprintf printf
#else
#define TYPE __typeof
#define RF(filename) \
{ ; }
#define WF(filename) \
{ ; }
#define DF(filename) \
{ ; }
#define eprintf(...)
#define fprintf(...)
#endif
// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x) << 1)
#define R(x) ((x) << 1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) \
memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) \
sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) \
for (TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;
#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9 + 7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
int main() {
RF("input.txt");
// WF("output.txt");
DF("err.txt");
int N;
scanf("%d", &N);
vector<int> neg, pos;
int zero = 0;
for (int i = 0; i < N; i++) {
int A;
scanf("%d", &A);
if (A > 0)
pos.push_back(A);
else if (A < 0)
neg.push_back(A);
else
zero++;
}
while (zero > 0) {
if (neg.size() < pos.size())
neg.push_back(0);
else
pos.push_back(0);
zero--;
}
sort(ALL(neg));
sort(ALL(pos));
deque<int> negd, posd;
for (int &num : neg)
negd.push_back(num);
for (int &num : pos)
posd.push_back(num);
vector<PII> opes;
while (negd.size() + posd.size() > 1) {
if (negd.size() == 0) {
int a = posd.front();
posd.pop_front();
int b = posd.front();
posd.pop_front();
negd.push_back(a - b);
opes.emplace_back(a, b);
} else if (posd.size() > 1) {
int a = negd.front();
negd.pop_front();
int b = posd.front();
posd.pop_front();
negd.push_back(a - b);
opes.emplace_back(a, b);
} else {
int a = posd.front();
posd.pop_front();
int b = negd.front();
negd.pop_front();
posd.push_back(a - b);
opes.emplace_back(a, b);
}
}
int res = posd.front();
printf("%d\n", res);
for (PII &ope : opes)
printf("%d %d\n", ope.X, ope.Y);
return 0;
} | // #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair<int, int> PII;
typedef pair<int64, int64> PLL;
// }
// #parameter{
#ifdef _DEBUG
#define TYPE decltype
#define RF(filename) \
{ freopen((filename), "r", stdin); }
#define WF(filename) \
{ freopen((filename), "w", stdout); }
#define DF(filename) \
{ freopen((filename), "w", stderr); }
#define eprintf printf
#else
#define TYPE __typeof
#define RF(filename) \
{ ; }
#define WF(filename) \
{ ; }
#define DF(filename) \
{ ; }
#define eprintf(...)
#define fprintf(...)
#endif
// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x) << 1)
#define R(x) ((x) << 1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) \
memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) \
sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) \
for (TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;
#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9 + 7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
int main() {
RF("input.txt");
// WF("output.txt");
DF("err.txt");
int N;
scanf("%d", &N);
vector<int> neg, pos;
int zero = 0;
for (int i = 0; i < N; i++) {
int A;
scanf("%d", &A);
if (A > 0)
pos.push_back(A);
else if (A < 0)
neg.push_back(A);
else
zero++;
}
while (zero > 0) {
if (neg.size() < pos.size())
neg.push_back(0);
else
pos.push_back(0);
zero--;
}
sort(ALL(neg));
sort(ALL(pos));
deque<int> negd, posd;
for (int &num : neg)
negd.push_back(num);
for (int &num : pos)
posd.push_back(num);
vector<PII> opes;
while (negd.size() + posd.size() > 1) {
if (negd.size() == 0) {
int a = posd.front();
posd.pop_front();
int b = posd.front();
posd.pop_front();
negd.push_back(a - b);
opes.emplace_back(a, b);
} else if (posd.size() == 0) {
int a = negd.back();
negd.pop_back();
int b = negd.back();
negd.pop_back();
posd.push_back(a - b);
opes.emplace_back(a, b);
} else if (posd.size() > 1) {
int a = negd.front();
negd.pop_front();
int b = posd.front();
posd.pop_front();
negd.push_back(a - b);
opes.emplace_back(a, b);
} else {
int a = posd.front();
posd.pop_front();
int b = negd.front();
negd.pop_front();
posd.push_back(a - b);
opes.emplace_back(a, b);
}
}
int res = posd.front();
printf("%d\n", res);
for (PII &ope : opes)
printf("%d %d\n", ope.X, ope.Y);
return 0;
} | insert | 113 | 113 | 113 | 120 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> plus, minus;
rep(i, n) {
if (a[i] >= 0)
plus.emplace_back(a[i]);
else
minus.emplace_back(a[i]);
}
sort(plus.begin(), plus.end(), greater<int>());
sort(minus.begin(), minus.end());
if (minus.empty())
minus.emplace_back(plus.back()), plus.pop_back();
if (plus.empty())
plus.emplace_back(minus.back()), minus.pop_back();
int cur = minus[0];
vector<P> sousa;
for (int i = 0; i < (int)(plus.size() - 1); i++) {
sousa.emplace_back(P(cur, plus[i]));
cur = cur - plus[i];
}
sousa.emplace_back(P(plus.back(), cur));
cur = plus.back() - cur;
for (int i = 1; i < minus.size(); i++) {
sousa.emplace_back(P(cur, minus[i]));
cur = cur - plus[i];
}
cout << cur << endl;
for (auto x : sousa)
cout << x.first << " " << x.second << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> plus, minus;
rep(i, n) {
if (a[i] >= 0)
plus.emplace_back(a[i]);
else
minus.emplace_back(a[i]);
}
sort(plus.begin(), plus.end(), greater<int>());
sort(minus.begin(), minus.end());
if (minus.empty())
minus.emplace_back(plus.back()), plus.pop_back();
if (plus.empty())
plus.emplace_back(minus.back()), minus.pop_back();
int cur = minus[0];
vector<P> sousa;
for (int i = 0; i < (int)(plus.size() - 1); i++) {
sousa.emplace_back(P(cur, plus[i]));
cur = cur - plus[i];
}
sousa.emplace_back(P(plus.back(), cur));
cur = plus.back() - cur;
for (int i = 1; i < minus.size(); i++) {
sousa.emplace_back(P(cur, minus[i]));
cur = cur - minus[i];
}
cout << cur << endl;
for (auto x : sousa)
cout << x.first << " " << x.second << "\n";
return 0;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int A[100010] = {};
int ans = 0;
int pos = 0;
int neg = 0;
int zero = 0;
vector<int> P;
vector<int> M;
for (int i = 0; i < N; i++) {
cin >> A[i];
ans += abs(A[i]);
if (A[i] > 0) {
pos++;
P.push_back(A[i]);
}
if (A[i] < 0) {
neg++;
M.push_back(A[i]);
}
if (A[i] == 0) {
zero++;
P.push_back(A[i]);
}
}
sort(A, A + N);
if (zero == 0 && pos == 0)
ans += 2 * A[N - 1];
if (zero == 0 && neg == 0)
ans -= 2 * A[0];
cout << ans << endl;
if (zero == 0 && pos == 0) {
int tmp = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
cout << tmp << " " << A[i] << endl;
tmp = tmp - A[i];
}
}
if (zero == 0 && neg == 0) {
int tmp = A[0];
for (int i = 1; i < N - 1; i++) {
cout << tmp << " " << A[i] << endl;
tmp = tmp - A[i];
}
cout << A[N - 1] << " " << tmp << endl;
} else if (pos + zero > neg && neg > 0) {
cout << M[0] << " " << P[0] << endl;
for (int i = 1; i < neg; i++) {
cout << P[i] << " " << M[i] << endl;
}
int tmp = M[0] - P[0];
for (int i = 1; i < neg; i++) {
cout << tmp << " " << P[i] - M[i] << endl;
tmp = tmp - P[i] + M[i];
}
for (int i = neg; i < pos + zero - 1; i++) {
cout << tmp << " " << P[i] << endl;
tmp = tmp - P[i];
}
cout << P[pos + zero - 1] << " " << tmp << endl;
} else if (pos + zero < neg) {
cout << P[0] << " " << M[0] << endl;
for (int i = 1; i < pos + zero; i++) {
cout << M[i] << " " << P[i] << endl;
}
int tmp = P[0] - M[0];
for (int i = 1; i < pos + zero; i++) {
cout << tmp << " " << M[i] - P[i] << endl;
tmp = tmp - M[i] + P[i];
}
for (int i = pos + zero; i < neg; i++) {
cout << tmp << " " << M[i] << endl;
tmp = tmp - M[i];
}
} else if (pos + zero == neg) {
cout << M[0] << " " << P[0] << endl;
for (int i = 1; i < neg; i++) {
cout << P[i] << " " << M[i] << endl;
}
int tmp = M[0] - P[0];
for (int i = 1; i < neg - 1; i++) {
cout << tmp << " " << P[i] - M[i] << endl;
tmp = tmp - P[i] + M[i];
}
cout << P[pos + zero - 1] - M[pos + zero - 1] << " " << tmp << endl;
} else if (neg == 0) {
int tmp = A[0];
for (int i = 1; i < N - 1; i++) {
cout << tmp << " " << A[i] << endl;
tmp = tmp - A[i];
}
cout << A[N - 1] << " " << tmp << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int A[100010] = {};
int ans = 0;
int pos = 0;
int neg = 0;
int zero = 0;
vector<int> P;
vector<int> M;
for (int i = 0; i < N; i++) {
cin >> A[i];
ans += abs(A[i]);
if (A[i] > 0) {
pos++;
P.push_back(A[i]);
}
if (A[i] < 0) {
neg++;
M.push_back(A[i]);
}
if (A[i] == 0) {
zero++;
P.push_back(A[i]);
}
}
sort(A, A + N);
if (zero == 0 && pos == 0)
ans += 2 * A[N - 1];
if (zero == 0 && neg == 0)
ans -= 2 * A[0];
cout << ans << endl;
if (zero == 0 && pos == 0) {
int tmp = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
cout << tmp << " " << A[i] << endl;
tmp = tmp - A[i];
}
} else if (zero == 0 && neg == 0) {
int tmp = A[0];
for (int i = 1; i < N - 1; i++) {
cout << tmp << " " << A[i] << endl;
tmp = tmp - A[i];
}
cout << A[N - 1] << " " << tmp << endl;
} else if (pos + zero > neg && neg > 0) {
cout << M[0] << " " << P[0] << endl;
for (int i = 1; i < neg; i++) {
cout << P[i] << " " << M[i] << endl;
}
int tmp = M[0] - P[0];
for (int i = 1; i < neg; i++) {
cout << tmp << " " << P[i] - M[i] << endl;
tmp = tmp - P[i] + M[i];
}
for (int i = neg; i < pos + zero - 1; i++) {
cout << tmp << " " << P[i] << endl;
tmp = tmp - P[i];
}
cout << P[pos + zero - 1] << " " << tmp << endl;
} else if (pos + zero < neg) {
cout << P[0] << " " << M[0] << endl;
for (int i = 1; i < pos + zero; i++) {
cout << M[i] << " " << P[i] << endl;
}
int tmp = P[0] - M[0];
for (int i = 1; i < pos + zero; i++) {
cout << tmp << " " << M[i] - P[i] << endl;
tmp = tmp - M[i] + P[i];
}
for (int i = pos + zero; i < neg; i++) {
cout << tmp << " " << M[i] << endl;
tmp = tmp - M[i];
}
} else if (pos + zero == neg) {
cout << M[0] << " " << P[0] << endl;
for (int i = 1; i < neg; i++) {
cout << P[i] << " " << M[i] << endl;
}
int tmp = M[0] - P[0];
for (int i = 1; i < neg - 1; i++) {
cout << tmp << " " << P[i] - M[i] << endl;
tmp = tmp - P[i] + M[i];
}
cout << P[pos + zero - 1] - M[pos + zero - 1] << " " << tmp << endl;
} else if (neg == 0) {
int tmp = A[0];
for (int i = 1; i < N - 1; i++) {
cout << tmp << " " << A[i] << endl;
tmp = tmp - A[i];
}
cout << A[N - 1] << " " << tmp << endl;
}
} | replace | 40 | 42 | 40 | 41 | 0 | |
p03007 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
int N, A[100000];
vector<pii> result;
int rec(queue<int> &p, queue<int> &n) {
if (p.size() == 1) {
int ret = A[p.front()];
while (!n.empty()) {
int v = n.front();
n.pop();
result.push_back({ret, A[v]});
ret -= A[v];
}
return ret;
}
int h = p.front();
p.pop();
int r = rec(n, p);
result.push_back({A[h], r});
return A[h] - r;
}
int main() {
bool all_positive = true, all_negative;
cin >> N;
REP(i, N) {
cin >> A[i];
all_positive &= A[i] > 0;
all_negative &= A[i] <= 0;
}
sort(A, A + N);
int s = 0, e = N;
queue<int> p, n;
if (all_positive) {
n.push(0);
s = 1;
}
if (all_negative) {
p.push(N - 1);
e = N - 1;
}
FOR(i, s, e) {
if (A[i] > 0)
p.push(i);
else
n.push(i);
}
cout << rec(p, n) << endl;
for (auto p : result)
cout << p.first << " " << p.second << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
int N, A[100000];
vector<pii> result;
int rec(queue<int> &p, queue<int> &n) {
if (p.size() == 1) {
int ret = A[p.front()];
while (!n.empty()) {
int v = n.front();
n.pop();
result.push_back({ret, A[v]});
ret -= A[v];
}
return ret;
}
int h = p.front();
p.pop();
int r = rec(n, p);
result.push_back({A[h], r});
return A[h] - r;
}
int main() {
bool all_positive = true, all_negative = true;
cin >> N;
REP(i, N) {
cin >> A[i];
all_positive &= A[i] > 0;
all_negative &= A[i] <= 0;
}
sort(A, A + N);
int s = 0, e = N;
queue<int> p, n;
if (all_positive) {
n.push(0);
s = 1;
}
if (all_negative) {
p.push(N - 1);
e = N - 1;
}
FOR(i, s, e) {
if (A[i] > 0)
p.push(i);
else
n.push(i);
}
cout << rec(p, n) << endl;
for (auto p : result)
cout << p.first << " " << p.second << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | 0 | |
p03007 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int n;
vector<int> lz, mz;
vector<pair<int, int>> mv;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a < 0)
lz.push_back(a);
else
mz.push_back(a);
}
if (lz.size() == 0) {
sort(mz.begin(), mz.end());
while (mz.size() > 2) {
mv.push_back({mz[0], mz.back()});
mz[0] -= mz.back();
mz.pop_back();
}
mv.push_back({mz.back(), mz[0]});
} else if (mz.size() == 0) {
sort(lz.begin(), lz.end());
reverse(lz.begin(), lz.end());
while (lz.size() > 2) {
mv.push_back({lz[0], lz.back()});
lz[0] -= mz.back();
lz.pop_back();
}
mv.push_back({lz[0], lz.back()});
} else {
for (int i = 1; i < mz.size(); i++)
mv.push_back({lz[0], mz[i]}), lz[0] -= mz[i];
for (int i = 1; i < lz.size(); i++)
mv.push_back({mz[0], lz[i]}), mz[0] -= lz[i];
mv.push_back({mz[0], lz[0]});
}
cout << mv.back().first - mv.back().second << '\n';
for (int i = 0; i < mv.size(); i++)
cout << mv[i].first << ' ' << mv[i].second << '\n';
}
| #include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int n;
vector<int> lz, mz;
vector<pair<int, int>> mv;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a < 0)
lz.push_back(a);
else
mz.push_back(a);
}
if (lz.size() == 0) {
sort(mz.begin(), mz.end());
while (mz.size() > 2) {
mv.push_back({mz[0], mz.back()});
mz[0] -= mz.back();
mz.pop_back();
}
mv.push_back({mz.back(), mz[0]});
} else if (mz.size() == 0) {
sort(lz.begin(), lz.end());
reverse(lz.begin(), lz.end());
while (lz.size() > 2) {
mv.push_back({lz[0], lz.back()});
lz[0] -= lz.back();
lz.pop_back();
}
mv.push_back({lz[0], lz.back()});
} else {
for (int i = 1; i < mz.size(); i++)
mv.push_back({lz[0], mz[i]}), lz[0] -= mz[i];
for (int i = 1; i < lz.size(); i++)
mv.push_back({mz[0], lz[i]}), mz[0] -= lz[i];
mv.push_back({mz[0], lz[0]});
}
cout << mv.back().first - mv.back().second << '\n';
for (int i = 0; i < mv.size(); i++)
cout << mv[i].first << ' ' << mv[i].second << '\n';
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p03007 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, m, n) for (long long i = m; i < n; i++)
#define REP(i, m, n, p) for (long long i = m; i < n; i += p)
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
using pqll = priority_queue<long long>;
using pqllg = priority_queue<long long, vector<long long>, greater<long long>>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
using mlv = map<long long, vector<long long>>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
vector<ll> keta(ll x);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
// 20200416
vector<long long> inputv(long long n);
// 20200417
vector<long long> yakusuu(int n);
map<long long, long long> soinsuu(long long n);
vector<vector<long long>> maze(long long i, long long j, vector<string> &s);
// 20200423
vector<long long> eratos(long long n);
set<long long> eraset(long long n);
//////////////////////////////////////////////////////
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return -z;
else if (a == 0)
return 0;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 0に対しては{0}を返す
// 検証済み
vector<ll> keta(ll x) {
if (x == 0)
return {0};
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 20200415
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
// modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ)
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
// 整数n個の入力を受け取ってベクトルに突っ込んで返す
// チェック済み
vector<long long> inputv(long long n) {
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
return v;
}
vector<long long> yakusuu(long long n) // nの約数を列挙
{
vector<long long> ret;
for (long long i = 1; i <= sqrt(n); ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) {
ret.push_back(n / i);
}
}
}
sort(ret.begin(), ret.end());
return ret;
}
map<long long, long long> soinsuu(long long n) {
map<long long, long long> m;
long long p = sqrt(n);
while (n % 2 == 0) {
n /= 2;
if (m.count(2)) {
m[2]++;
} else {
m[2] = 1;
}
}
for (long long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
n /= i;
if (m.count(i)) {
m[i]++;
} else {
m[i] = 1;
}
}
}
if (n != 1)
m[n] = 1;
return m;
}
// スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く
// スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す
// 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要)
// 検証済み 一応O(地図の広さ)くらい
vector<vector<long long>> maze(ll i, ll j, vector<string> &s) {
ll h = s.size();
ll w = s[0].size();
queue<vector<long long>> q;
vector<vector<long long>> dis(h, vll(w, -1));
q.push({i, j});
dis[i][j] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] - 1, v[1]});
}
if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] - 1});
}
if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] + 1, v[1]});
}
if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] + 1});
}
}
return dis; // スタートから何マス離れているか(辿り着けない場合は-1)
}
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
// vector<long long> eratos(long long n){
// }
// 二項係数の剰余を求める
// 引数は剰余の形ではなくもとの数そのものである
// 未検証(検証サンプルがない)
long long modC(long long n, long long k, long long mod) {
if (n < k)
return 0;
long long p = 1, q = 1;
for (long long i = 0; i < k; i++) {
p = p * (n - i) % mod;
q = q * (i + 1) % mod;
}
return p * modinv(q, mod) % mod;
}
// 20200418
// 整数のとき限定の普通のPOW関数
// 標準機能のpow(a,n)は整数だとバグるのでこちらを使う
long long POW(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
// 20200423
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
vector<long long> eratos(long long n) {
if (n < 2)
return {};
vll v(n - 1);
rep(i, n - 1) {
v[i] = i + 2; // 2からnまで
}
ll i = 0;
while (i < n - 1) {
ll p = v[i];
for (ll j = i + 1; j < n - 1; j++) {
if (v[j] % p == 0) {
v.erase(v.begin() + j);
n--;
}
}
i++;
}
v.resize(n - 1);
return v;
}
// n以下の素数を全て詰めたset
set<long long> eraset(long long n) {
set<long long> s;
vll v = eratos(n);
for (auto &t : v) {
s.insert(t);
}
return s;
}
// 20200428
//(x1,y1),(x2,y2)を通る直線をax+by+c=0としたとき
//{a,b,c}を返す
vll line(ll x1, ll y1, ll x2, ll y2) {
vector<ll> v(3);
v[0] = y1 - y2;
v[1] = x2 - x1;
v[2] = -x1 * (y1 - y2) + y1 * (x1 - x2);
return v;
}
//(x,y)とv[0]x+v[1]y+v[2]=0との距離
double dis(vll v, ll x, ll y) {
double s = sqrt(v[0] * v[0] + v[1] * v[1]);
return (double)abs(v[0] * x + v[1] * y + v[2]) / s;
}
// 20200502
void maxin(ll &a, ll b) {
a = max(a, b);
return;
}
void minin(ll &a, ll b) {
a = min(a, b);
return;
}
// 20200506
map<long long, long long> countv(vll v) {
map<long long, long long> m;
for (auto &g : v) {
if (m.count(g))
m[g]++;
else
m[g] = 1;
}
return m;
}
// nCk modを求める
const ll MAX = 510000;
const ll MOD = 1000000007;
long long 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;
}
}
// 二項係数計算
long long commod(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;
}
/* next combination */
// 次の組み合わせをbitで返す
// 全探索のloopに使える
long long next_combination(long long sub) {
long long x = sub & -sub, y = sub + x;
return (((sub & ~y) / x) >> 1) | y;
}
//////////////////////////////////////////
struct UF { // サイズが測れるUF
vector<long long> par, size; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
// sizeはiを根とする木のサイズ
UF(long long N) : par(N), size(N) { // 最初は全てが根であるとして初期化
for (long long i = 0; i < N; i++) {
par[i] = i;
size[i] = 1;
}
}
long long root(
long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(long long x, long long y) { // xとyの木を併合
long long rx = root(x); // xの根をrx
long long ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
size[ry] += size[rx];
size[rx] = 0; // サイズの処理 根じゃなくなったらサイズは0になる
}
bool same(long long x,
long long y) { // 2つのデータx, yが属する木が同じならtrueを返す
long long rx = root(x);
long long ry = root(y);
return rx == ry;
}
};
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// int mod=17;
// const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
//////////////////////////////////////////////
// ll const mod=1e9+7;
ll const dekai = 99999999999977; // 1e11-23.素数.
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, -1, 0, 1};
ll ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// cout<<fixed<<setprecision(10);
//////////////////////////////////////////////////
int main() {
ll n;
cin >> n;
auto a = inputv(n);
sort(all(a));
vpll ans(n - 1);
ll res = a[0];
if (a[0] >= 0) {
rep(i, n - 2) {
ans[i].first = res;
ans[i].second = a[i + 1];
res -= a[i + 1];
}
ans[n - 2].first = a[n - 1];
ans[n - 2].second = res;
res = a[n - 1] - res;
} else if (a[n - 1] < 0) {
rep(i, n - 1) {
ans[i].first = a[n - 1];
ans[i].second = a[i];
a[n - 1] -= a[i];
res = a[n - 1];
}
} else {
ll k = lower_bound(all(a), 0) - a.begin();
Rep(i, k, n - 1) {
ans[i - k].first = a[0];
ans[i - k].second = a[i];
a[0] -= a[i];
}
rep(i, k) {
ans[i + k].first = a[n - 1];
ans[i + k].second = a[i];
a[n - 1] -= a[i];
}
res = a[n - 1];
}
cout << res << endl;
rep(i, n - 1) { cout << ans[i].first << " " << ans[i].second << endl; }
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, m, n) for (long long i = m; i < n; i++)
#define REP(i, m, n, p) for (long long i = m; i < n; i += p)
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using mii = map<int, int>;
using pqll = priority_queue<long long>;
using pqllg = priority_queue<long long, vector<long long>, greater<long long>>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
using mlv = map<long long, vector<long long>>;
long long divup(long long a, long long b);
long long kaijou(long long i);
long long P(long long n, long long k);
long long C(long long n, long long k);
long long GCD(long long a, long long b);
long long LCM(long long a, long long b);
bool prime(long long N);
double distance(vector<long long> p, vector<long long> q, long long n);
void press(vector<long long> &v);
void ranking(vector<long long> &v);
void erase(vector<long long> &v, long long i);
void unique(vector<long long> &v);
void printv(vector<long long> v);
vector<ll> keta(ll x);
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
// 20200416
vector<long long> inputv(long long n);
// 20200417
vector<long long> yakusuu(int n);
map<long long, long long> soinsuu(long long n);
vector<vector<long long>> maze(long long i, long long j, vector<string> &s);
// 20200423
vector<long long> eratos(long long n);
set<long long> eraset(long long n);
//////////////////////////////////////////////////////
// 端数繰りあがり割り算(検証済)
// a÷bの端数繰り上げ
// b!=0のデバグはしてないので分母に0を入れないように
// 負数対応
long long divup(long long a, long long b) {
long long x = abs(a);
long long y = abs(b);
long long z = (x + y - 1) / y;
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return -z;
else if (a == 0)
return 0;
else
return z;
}
// 階乗
// 検証済み
long long kaijou(long long i) {
if (i == 0)
return 1;
long long j = 1;
for (long long k = 1; k <= i; k++) {
j *= k;
}
return j;
}
// 順列nPk(完成)
// n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数
// n<kなら0を返す
// 敢えて負数時のデバグはしてない
long long P(long long n, long long k) {
if (n < k)
return 0;
long long y = 1;
for (long long i = 0; i < k; i++) {
y *= (n - i);
}
return y;
}
// 組み合わせnCk(検証済み)
// P,kaijouと併用
long long C(long long n, long long k) {
if (n < k)
return 0;
return P(n, k) / kaijou(k);
}
// nHk
// 区別しないn個の要素を、区別するk個のグループに分ける
// 0個のグループがあっ
// て良い
// C必須
// 最大公約数GCD,最小公倍数LCM
// LCMを使うときはGCDをセットで
// 検証済み
long long GCD(long long a, long long b) {
if (a < b)
swap(a, b);
long long d = a % b;
if (d == 0) {
return b;
}
return GCD(b, d);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
// 素数判定
// 素数ならばtrue、素数以外の整数にはfalse
// 負数は全てfalse
// 検証済み
bool prime(long long N) {
if (N == 1) {
return false;
}
if (N < 0)
return false;
long long p = sqrt(N);
for (long long i = 2; i <= p; i++) {
if (N % i == 0) {
return false;
}
}
return true;
}
// ユークリッド距離
// 検証済み
// 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的)
double distance(vector<long long> p, vector<long long> q, long long n) {
double x = 0;
for (long long i = 0; i < n; i++) {
x += pow((p.at(i) - q.at(i)), 2);
}
return sqrt(x);
}
// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1, 0}にする
void press(vector<long long> &v) {
long long n = v.size();
vector<long long> w(n);
map<long long, long long> m;
for (auto &p : v) {
m[p] = 0;
}
long long i = 0;
for (auto &p : m) {
p.second = i;
i++;
}
for (long long i = 0; i < n; i++) {
w.at(i) = m[v.at(i)];
}
v = w;
return;
}
// 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数
// 配列の要素が全て異なるときにしか正常に動作しない
// 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、
// エラーも起きないので注意
// 検証済
//{2,4,1,6,0,3,8,9,5}を
//{4,2,0,5,1,8,3,6,7}にして返す
//"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意
void ranking(vector<long long> &v) {
long long n = v.size();
map<long long, long long> m;
long long i;
for (i = 0; i < n; i++) {
m[v.at(i)] = i;
}
vector<long long> w(n);
i = 0;
for (auto &p : m) {
v.at(i) = p.second;
i++;
}
return;
}
// 部分削除(未検証)
// ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、
// 以降の要素を全て前に1ずらして参照返し
// ベクトル長は1小さくなって返る
// i>n-1の時は変化しない
void erase(vector<long long> &v, long long i) {
long long n = v.size();
if (i > n - 1)
return;
for (long long j = i; j < n - 1; j++) {
v.at(j) = v.at(j + 1);
}
v.pop_back();
return;
}
// 重複削除(未完成)
// 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除
// 参照返し
// ベクトル長も変化する
// O(logn)くらい
void unique(vector<long long> &v) {
long long n = v.size();
set<long long> s;
long long i = 0;
while (i < n) {
if (s.count(v.at(i))) {
erase(v, i);
n--;
} else {
s.insert(v.at(i));
i++;
}
}
return;
}
// ベクトルの出力(検証済)
// debug用にvectorの中身を出力する
void printv(vector<long long> v) {
cout << "{ ";
for (auto &p : v) {
cout << p << ",";
}
cout << "}" << endl;
}
// 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を
// 収納した長さnのベクトルを返す
// 0に対しては{0}を返す
// 検証済み
vector<ll> keta(ll x) {
if (x == 0)
return {0};
ll n = log10(x) + 1; // xの桁数
vll w(n, 0);
for (ll i = 0; i < n; i++) {
ll p;
p = x % 10;
x = x / 10;
w[n - 1 - i] = p;
}
return w;
}
// 20200415
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
// modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ)
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
// 整数n個の入力を受け取ってベクトルに突っ込んで返す
// チェック済み
vector<long long> inputv(long long n) {
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
}
return v;
}
vector<long long> yakusuu(long long n) // nの約数を列挙
{
vector<long long> ret;
for (long long i = 1; i <= sqrt(n); ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) {
ret.push_back(n / i);
}
}
}
sort(ret.begin(), ret.end());
return ret;
}
map<long long, long long> soinsuu(long long n) {
map<long long, long long> m;
long long p = sqrt(n);
while (n % 2 == 0) {
n /= 2;
if (m.count(2)) {
m[2]++;
} else {
m[2] = 1;
}
}
for (long long i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
n /= i;
if (m.count(i)) {
m[i]++;
} else {
m[i] = 1;
}
}
}
if (n != 1)
m[n] = 1;
return m;
}
// スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く
// スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す
// 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要)
// 検証済み 一応O(地図の広さ)くらい
vector<vector<long long>> maze(ll i, ll j, vector<string> &s) {
ll h = s.size();
ll w = s[0].size();
queue<vector<long long>> q;
vector<vector<long long>> dis(h, vll(w, -1));
q.push({i, j});
dis[i][j] = 0;
while (!q.empty()) {
auto v = q.front();
q.pop();
if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] - 1, v[1]});
}
if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] - 1});
}
if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
q.push({v[0] + 1, v[1]});
}
if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
q.push({v[0], v[1] + 1});
}
}
return dis; // スタートから何マス離れているか(辿り着けない場合は-1)
}
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
// vector<long long> eratos(long long n){
// }
// 二項係数の剰余を求める
// 引数は剰余の形ではなくもとの数そのものである
// 未検証(検証サンプルがない)
long long modC(long long n, long long k, long long mod) {
if (n < k)
return 0;
long long p = 1, q = 1;
for (long long i = 0; i < k; i++) {
p = p * (n - i) % mod;
q = q * (i + 1) % mod;
}
return p * modinv(q, mod) % mod;
}
// 20200418
// 整数のとき限定の普通のPOW関数
// 標準機能のpow(a,n)は整数だとバグるのでこちらを使う
long long POW(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
// 20200423
// エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す
vector<long long> eratos(long long n) {
if (n < 2)
return {};
vll v(n - 1);
rep(i, n - 1) {
v[i] = i + 2; // 2からnまで
}
ll i = 0;
while (i < n - 1) {
ll p = v[i];
for (ll j = i + 1; j < n - 1; j++) {
if (v[j] % p == 0) {
v.erase(v.begin() + j);
n--;
}
}
i++;
}
v.resize(n - 1);
return v;
}
// n以下の素数を全て詰めたset
set<long long> eraset(long long n) {
set<long long> s;
vll v = eratos(n);
for (auto &t : v) {
s.insert(t);
}
return s;
}
// 20200428
//(x1,y1),(x2,y2)を通る直線をax+by+c=0としたとき
//{a,b,c}を返す
vll line(ll x1, ll y1, ll x2, ll y2) {
vector<ll> v(3);
v[0] = y1 - y2;
v[1] = x2 - x1;
v[2] = -x1 * (y1 - y2) + y1 * (x1 - x2);
return v;
}
//(x,y)とv[0]x+v[1]y+v[2]=0との距離
double dis(vll v, ll x, ll y) {
double s = sqrt(v[0] * v[0] + v[1] * v[1]);
return (double)abs(v[0] * x + v[1] * y + v[2]) / s;
}
// 20200502
void maxin(ll &a, ll b) {
a = max(a, b);
return;
}
void minin(ll &a, ll b) {
a = min(a, b);
return;
}
// 20200506
map<long long, long long> countv(vll v) {
map<long long, long long> m;
for (auto &g : v) {
if (m.count(g))
m[g]++;
else
m[g] = 1;
}
return m;
}
// nCk modを求める
const ll MAX = 510000;
const ll MOD = 1000000007;
long long 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;
}
}
// 二項係数計算
long long commod(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;
}
/* next combination */
// 次の組み合わせをbitで返す
// 全探索のloopに使える
long long next_combination(long long sub) {
long long x = sub & -sub, y = sub + x;
return (((sub & ~y) / x) >> 1) | y;
}
//////////////////////////////////////////
struct UF { // サイズが測れるUF
vector<long long> par, size; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
// sizeはiを根とする木のサイズ
UF(long long N) : par(N), size(N) { // 最初は全てが根であるとして初期化
for (long long i = 0; i < N; i++) {
par[i] = i;
size[i] = 1;
}
}
long long root(
long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(long long x, long long y) { // xとyの木を併合
long long rx = root(x); // xの根をrx
long long ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
size[ry] += size[rx];
size[rx] = 0; // サイズの処理 根じゃなくなったらサイズは0になる
}
bool same(long long x,
long long y) { // 2つのデータx, yが属する木が同じならtrueを返す
long long rx = root(x);
long long ry = root(y);
return rx == ry;
}
};
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// int mod=17;
// const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
//////////////////////////////////////////////
// ll const mod=1e9+7;
ll const dekai = 99999999999977; // 1e11-23.素数.
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, -1, 0, 1};
ll ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// cout<<fixed<<setprecision(10);
//////////////////////////////////////////////////
int main() {
ll n;
cin >> n;
auto a = inputv(n);
sort(all(a));
vpll ans(n - 1);
ll res = a[0];
if (a[0] >= 0) {
rep(i, n - 2) {
ans[i].first = res;
ans[i].second = a[i + 1];
res -= a[i + 1];
}
ans[n - 2].first = a[n - 1];
ans[n - 2].second = res;
res = a[n - 1] - res;
} else if (a[n - 1] < 0) {
rep(i, n - 1) {
ans[i].first = a[n - 1];
ans[i].second = a[i];
a[n - 1] -= a[i];
res = a[n - 1];
}
} else {
ll k = lower_bound(all(a), 0) - a.begin();
Rep(i, k, n - 1) {
ans[i - k].first = a[0];
ans[i - k].second = a[i];
a[0] -= a[i];
}
rep(i, k) {
ans[i + n - 1 - k].first = a[n - 1];
ans[i + n - 1 - k].second = a[i];
a[n - 1] -= a[i];
}
res = a[n - 1];
}
cout << res << endl;
rep(i, n - 1) { cout << ans[i].first << " " << ans[i].second << endl; }
}
| replace | 630 | 632 | 630 | 632 | 0 | |
p03007 | C++ | Runtime Error | #ifdef __GNUC__
#pragma GCC optimize(2)
#endif
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#pragma warning(error : 4715 4700 4703 4533 4789 4717)
#endif
using namespace std;
namespace Bigcat {
template <typename T> inline void max_s(T &a, const T &b) { a = max(a, b); }
template <typename T> inline void min_s(T &a, const T &b) { a = min(a, b); }
template <typename T> void sort_v(T &x) { sort(x.begin(), x.end()); }
template <typename T> void erase_dup(T &x) {
x.erase(unique(x.begin(), x.end()), x.end());
} // erase duplicate
template <typename T, typename V> int pos_l(const T &x, const V &v) {
return lower_bound(x.begin(), x.end(), v) - x.begin();
}
template <typename T, typename V> int pos_u(const T &x, const V &v) {
return upper_bound(x.begin(), x.end(), v) - x.begin();
}
inline unsigned rand_g() {
static mt19937 mt_rand((int)time(0));
return mt_rand();
}
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using PII = pair<int, int>;
using VPII = vector<PII>;
} // namespace Bigcat
#define Rep(i, a) for (int i = 0; i < (int)(a); i++)
#define Loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Rep_r(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define Size(v) ((int)v.size())
using namespace Bigcat;
const LL base = LL(1e9 + 7);
const LL INFL = 1LL << 62;
const int INF = 1 << 30;
const int MAX = int(2e5 + 100);
struct Node {
int x, y, w;
};
bool operator<(const Node &n0, const Node &n1) { return n0.x < n1.y; }
void solve1() {
LL result = 0;
int n;
cin >> n;
VI za(n);
Rep(i, n) { cin >> za[i]; }
sort_v(za);
vector<bool> zp(n);
zp[0] = false;
zp.back() = true;
Loop(i, 1, n - 1) {
if (za[i] < 0)
zp[i] = false;
else
zp[i] = true;
}
VI zs1, zs2;
Rep(i, n) {
if (zp[i])
result += za[i];
else
result -= za[i];
if (zp[i]) {
zs1.push_back(za[i]);
} else {
zs2.push_back(za[i]);
}
}
cout << result << endl;
if (Size(zs1) == 1) {
int now = *zs1.begin();
for (int x : zs2) {
cout << now << ' ' << x << '\n';
now -= x;
}
assert(now == result);
} else {
int now = *zs2.begin();
Rep(i, Size(zs1) - 1) {
int x = zs1[i];
cout << now << ' ' << x << '\n';
now -= x;
}
cout << zs1.back() << ' ' << now << '\n';
now = zs1.back() - now;
Loop(i, 1, Size(zs2)) {
int x = zs1[i];
cout << now << ' ' << x << '\n';
now -= x;
}
assert(now == result);
}
}
const bool _multi_test = false;
const int _inId = 1;
const int _outId = 0;
void io_init(char *s0) {
string path(s0);
int a = path.find("build\\");
int b = path.find(
#ifdef _DEBUG
"Debug\\"
#else
"Release\\"
#endif
);
if (a > 0 && b > a) {
path = path.substr(0, a) + path.substr(a + 6, b - a - 6);
} else
path = "";
if (_inId > 0) {
cerr << "redirect stdin to input " << _inId << endl;
string s = "input";
s += to_string(_inId);
s += ".txt";
if (path != "")
s = path + s;
auto r = freopen(s.c_str(), "r", stdin);
if (r == nullptr) {
cerr << "invalid input file " << s << endl;
;
r = freopen("CON", "r", stdin); // to do con??
}
}
if (_outId > 0) {
cerr << "redirect stdout to stdout " << _outId << endl;
string s = "stdout";
s += to_string(_outId);
s += ".txt";
if (path != "")
s = path + s;
auto r = freopen(s.c_str(), "w", stdout);
if (r == nullptr) {
cerr << "invalid output file " << s << endl;
;
r = freopen("CON", "w", stdout);
}
}
}
const bool _local_test =
#ifdef _LOCAL_TEST
true;
#else
false;
#endif
void solve() {
int t = 1;
if (_multi_test)
cin >> t;
if (_local_test)
cerr << " now base " << base << endl;
for (int i = 0; i < t; ++i) {
if (_local_test)
cerr << " tasks: " << i + 1 << endl;
// cout << "Case #" << i + 1 << ": ";
solve1();
}
int x = 1;
}
signed main(signed argc, char *argv[]) {
if (_local_test) {
if (argc == 1) {
io_init(argv[0]);
}
}
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0); // close sync between cout and printf
cin.exceptions(cin.failbit);
cout.precision(11);
solve();
}
| #ifdef __GNUC__
#pragma GCC optimize(2)
#endif
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#pragma warning(error : 4715 4700 4703 4533 4789 4717)
#endif
using namespace std;
namespace Bigcat {
template <typename T> inline void max_s(T &a, const T &b) { a = max(a, b); }
template <typename T> inline void min_s(T &a, const T &b) { a = min(a, b); }
template <typename T> void sort_v(T &x) { sort(x.begin(), x.end()); }
template <typename T> void erase_dup(T &x) {
x.erase(unique(x.begin(), x.end()), x.end());
} // erase duplicate
template <typename T, typename V> int pos_l(const T &x, const V &v) {
return lower_bound(x.begin(), x.end(), v) - x.begin();
}
template <typename T, typename V> int pos_u(const T &x, const V &v) {
return upper_bound(x.begin(), x.end(), v) - x.begin();
}
inline unsigned rand_g() {
static mt19937 mt_rand((int)time(0));
return mt_rand();
}
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using PII = pair<int, int>;
using VPII = vector<PII>;
} // namespace Bigcat
#define Rep(i, a) for (int i = 0; i < (int)(a); i++)
#define Loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Rep_r(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define Size(v) ((int)v.size())
using namespace Bigcat;
const LL base = LL(1e9 + 7);
const LL INFL = 1LL << 62;
const int INF = 1 << 30;
const int MAX = int(2e5 + 100);
struct Node {
int x, y, w;
};
bool operator<(const Node &n0, const Node &n1) { return n0.x < n1.y; }
void solve1() {
LL result = 0;
int n;
cin >> n;
VI za(n);
Rep(i, n) { cin >> za[i]; }
sort_v(za);
vector<bool> zp(n);
zp[0] = false;
zp.back() = true;
Loop(i, 1, n - 1) {
if (za[i] < 0)
zp[i] = false;
else
zp[i] = true;
}
VI zs1, zs2;
Rep(i, n) {
if (zp[i])
result += za[i];
else
result -= za[i];
if (zp[i]) {
zs1.push_back(za[i]);
} else {
zs2.push_back(za[i]);
}
}
cout << result << endl;
if (Size(zs1) == 1) {
int now = *zs1.begin();
for (int x : zs2) {
cout << now << ' ' << x << '\n';
now -= x;
}
assert(now == result);
} else {
int now = *zs2.begin();
Rep(i, Size(zs1) - 1) {
int x = zs1[i];
cout << now << ' ' << x << '\n';
now -= x;
}
cout << zs1.back() << ' ' << now << '\n';
now = zs1.back() - now;
Loop(i, 1, Size(zs2)) {
int x = zs2[i];
cout << now << ' ' << x << '\n';
now -= x;
}
assert(now == result);
}
}
const bool _multi_test = false;
const int _inId = 1;
const int _outId = 0;
void io_init(char *s0) {
string path(s0);
int a = path.find("build\\");
int b = path.find(
#ifdef _DEBUG
"Debug\\"
#else
"Release\\"
#endif
);
if (a > 0 && b > a) {
path = path.substr(0, a) + path.substr(a + 6, b - a - 6);
} else
path = "";
if (_inId > 0) {
cerr << "redirect stdin to input " << _inId << endl;
string s = "input";
s += to_string(_inId);
s += ".txt";
if (path != "")
s = path + s;
auto r = freopen(s.c_str(), "r", stdin);
if (r == nullptr) {
cerr << "invalid input file " << s << endl;
;
r = freopen("CON", "r", stdin); // to do con??
}
}
if (_outId > 0) {
cerr << "redirect stdout to stdout " << _outId << endl;
string s = "stdout";
s += to_string(_outId);
s += ".txt";
if (path != "")
s = path + s;
auto r = freopen(s.c_str(), "w", stdout);
if (r == nullptr) {
cerr << "invalid output file " << s << endl;
;
r = freopen("CON", "w", stdout);
}
}
}
const bool _local_test =
#ifdef _LOCAL_TEST
true;
#else
false;
#endif
void solve() {
int t = 1;
if (_multi_test)
cin >> t;
if (_local_test)
cerr << " now base " << base << endl;
for (int i = 0; i < t; ++i) {
if (_local_test)
cerr << " tasks: " << i + 1 << endl;
// cout << "Case #" << i + 1 << ": ";
solve1();
}
int x = 1;
}
signed main(signed argc, char *argv[]) {
if (_local_test) {
if (argc == 1) {
io_init(argv[0]);
}
}
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0); // close sync between cout and printf
cin.exceptions(cin.failbit);
cout.precision(11);
solve();
}
| replace | 120 | 121 | 120 | 121 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.