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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03186 | C++ | Time Limit Exceeded | /*#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<deque>
#include<fstream>
#include<iomanip>
#include<map>
#include <numeric>*/
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); (i)--)
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
int main() {
ll a = 0, b = 0, c = 0, d = 0, ans = 0, ret = M, n, m;
string s;
bool x = false;
cin >> a >> b >> c;
while (1) {
if (!x && c != 0) {
ans++;
c--;
x ^= 1;
} else if (b != 0) {
ans++;
b--;
x ^= 1;
} else if (a != 0) {
a--;
x ^= 1;
} else
break;
}
cout << ans << endl;
return 0;
}
| /*#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<deque>
#include<fstream>
#include<iomanip>
#include<map>
#include <numeric>*/
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); (i)--)
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
int main() {
ll a = 0, b = 0, c = 0, d = 0, ans = 0, ret = M, n, m;
string s;
bool x = false;
cin >> a >> b >> c;
if (a + b == c) {
ans = c + b;
} else if (a + b < c) {
ans = (a + b) * 2 - a + 1;
} else
ans = b + c;
cout << ans << endl;
return 0;
}
| replace | 46 | 61 | 46 | 52 | TLE | |
p03186 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// const ll INF = 1LL <<60;
const int INF = 10000;
// 最大公約数
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
// 最大公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int MAX = 510000;
const int 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 (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 階乗
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
// for(int i = ; i < ; i++){}
ll lmax(ll s, ll t) {
if (s > t) {
return s;
} else {
return t;
}
}
ll lmin(ll s, ll t) {
if (s < t) {
return s;
} else {
return t;
}
}
// ここから開始
int main() {
int a, b, c;
cin >> a >> b >> c;
int ans = 0;
int i = 0;
while (a + b >= 0) {
if (i % 2 == 0) {
if (c > 0) {
c--;
ans++;
}
} else {
if (b > 0) {
b--;
ans++;
} else {
a--;
}
}
i++;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// const ll INF = 1LL <<60;
const int INF = 10000;
// 最大公約数
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
// 最大公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int MAX = 510000;
const int 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 (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 階乗
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
// for(int i = ; i < ; i++){}
ll lmax(ll s, ll t) {
if (s > t) {
return s;
} else {
return t;
}
}
ll lmin(ll s, ll t) {
if (s < t) {
return s;
} else {
return t;
}
}
// ここから開始
int main() {
int a, b, c;
cin >> a >> b >> c;
int eat_c = min(c, (a + b) + 1);
int ans = eat_c + b;
cout << ans << endl;
return 0;
}
| replace | 115 | 133 | 115 | 117 | TLE | |
p03186 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int cnt = 0;
bool stomach = true;
while (1) {
if (stomach) {
if (c > 0) {
c--;
cnt++;
stomach = false;
}
}
if (a == 0 && b == 0)
break;
if (b > 0) {
b--;
cnt++;
stomach = true;
} else if (a > 0) {
a--;
stomach = true;
}
}
cout << cnt << endl;
} | #include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a + b + 1 >= c)
cout << b + c << endl;
else
cout << (a + b + 1) + b << endl;
} // 解説参考. | replace | 7 | 34 | 7 | 12 | TLE | |
p03186 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int eat = 0;
bool poison = false;
int cookies(int a, int b, int c) {
if (poison) {
if (b > 0) {
b--;
eat++;
poison = false;
cookies(a, b, c);
} else if (a > 0) {
a--;
poison = false;
cookies(a, b, c);
}
} else if (c > 0) {
c--;
eat++;
poison = true;
cookies(a, b, c);
} else if (b > 0) {
b--;
eat++;
poison = false;
cookies(a, b, c);
}
}
int main() {
int A, B, C;
cin >> A >> B >> C;
cookies(A, B, C);
cout << eat << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int eat = 0;
bool poison = false;
int cookies(int a, int b, int c) {
if (poison) {
if (b > 0) {
b--;
eat++;
poison = false;
cookies(a, b, c);
} else if (a > 0) {
a--;
poison = false;
cookies(a, b, c);
}
} else if (c > 0) {
c--;
eat++;
poison = true;
cookies(a, b, c);
} else if (b > 0) {
b--;
eat++;
cookies(a, b, c);
}
}
int main() {
int A, B, C;
cin >> A >> B >> C;
cookies(A, B, C);
cout << eat << endl;
}
| delete | 26 | 27 | 26 | 26 | TLE | |
p03186 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void file() {
#ifndef ONLINE_JUDGE
freopen("a_input.txt", "r", stdin);
freopen("a_output.txt", "w", stdout);
#endif
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
file();
fast();
int a, b, c;
cin >> a >> b >> c;
int mn = min(b + 1, c);
c -= mn;
b += mn;
mn = min(c, a);
b += mn;
cout << b << endl;
} | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void file() {
#ifndef ONLINE_JUDGE
freopen("a_input.txt", "r", stdin);
freopen("a_output.txt", "w", stdout);
#endif
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
// file();
// fast();
int a, b, c;
cin >> a >> b >> c;
int mn = min(b + 1, c);
c -= mn;
b += mn;
mn = min(c, a);
b += mn;
cout << b << endl;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p03186 | Python | Time Limit Exceeded | A, B, C = map(int, input().split())
ans = 0
c = C
for i in range(C):
if c > 0 and B > 0:
ans += 2
c -= 1
B -= 1
elif c > 0 and A > 0:
ans += 1
c -= 1
A -= 1
if c > 0:
ans += 1
print(ans + B)
| A, B, C = map(int, input().split())
ans = 0
if B >= C:
print(B + C)
exit()
ans = 2 * B
C -= B
if A >= C:
print(ans + C)
exit()
print(ans + A + 1)
| replace | 2 | 15 | 2 | 11 | TLE | |
p03186 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 1e9
#define LINF 1e18
#define ld double
#define ll long long
#define ull unsigned long long
namespace io {
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
char gc() {
if (++pos == buff + SZ)
fread(pos = buff, 1, SZ, stdin);
return *pos;
}
} // namespace io
template <typename T> inline void read(T &x) {
x = 0;
int f = 1, c = io ::gc();
for (; !isdigit(c); c = io ::gc())
if (c == '-')
f = -f;
for (; isdigit(c); c = io ::gc())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= f;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in", "r", stdin);
freopen("out", "w", stdout);
#endif
int a, b, c;
read(a);
read(b);
read(c);
printf("%d\n", b + min(a + b + 1, c));
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 1e9
#define LINF 1e18
#define ld double
#define ll long long
#define ull unsigned long long
namespace io {
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
char gc() {
if (++pos == buff + SZ)
fread(pos = buff, 1, SZ, stdin);
return *pos;
}
} // namespace io
template <typename T> inline void read(T &x) {
x = 0;
int f = 1, c = io ::gc();
for (; !isdigit(c); c = io ::gc())
if (c == '-')
f = -f;
for (; isdigit(c); c = io ::gc())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= f;
}
int main() {
int a, b, c;
read(a);
read(b);
read(c);
printf("%d\n", b + min(a + b + 1, c));
return 0;
}
| delete | 51 | 56 | 51 | 51 | TLE | |
p03187 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#define NDEBUG
#define SHOW(...) static_cast<void>(0)
//!===========================================================!//
//! dP dP dP !//
//! 88 88 88 !//
//! 88aaaaa88a .d8888b. .d8888b. .d888b88 .d8888b. 88d888b. !//
//! 88 88 88ooood8 88' '88 88' '88 88ooood8 88' '88 !//
//! 88 88 88. ... 88. .88 88. .88 88. ... 88 !//
//! dP dP '88888P' '88888P8 '88888P8 '88888P' dP !//
//!===========================================================!//
template <typename T, typename A>
std::istream &operator>>(std::istream &is, std::vector<T, A> &v) {
for (auto &e : v) {
is >> e;
}
return is;
}
template <typename T> T read() {
T v;
return std::cin >> v, v;
}
template <typename T> std::vector<T> readVec(const std::size_t l) {
std::vector<T> v(l);
for (auto &e : v) {
std::cin >> e;
}
return v;
}
using ld = long double;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr unsigned int MOD = 1000000007;
template <typename T> constexpr T INF = std::numeric_limits<T>::max() / 4;
template <typename F> constexpr F PI = static_cast<F>(3.1415926535897932385);
std::mt19937 mt{std::random_device{}()};
template <typename T> bool chmin(T &a, const T &b) {
return (a > b ? a = b, true : false);
}
template <typename T> bool chmax(T &a, const T &b) {
return (a < b ? a = b, true : false);
}
template <typename T> std::vector<T> Vec(const std::size_t n, T v) {
return std::vector<T>(n, v);
}
template <class... Args> auto Vec(const std::size_t n, Args... args) {
return std::vector<decltype(Vec(args...))>(n, Vec(args...));
}
template <typename T> constexpr T popCount(const T u) {
#ifdef __has_builtin
return u == 0 ? T(0) : (T)__builtin_popcountll(u);
#else
unsigned long long v = static_cast<unsigned long long>(u);
return v = (v & 0x5555555555555555ULL) + (v >> 1 & 0x5555555555555555ULL),
v = (v & 0x3333333333333333ULL) + (v >> 2 & 0x3333333333333333ULL),
v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL,
static_cast<T>(v * 0x0101010101010101ULL >> 56 & 0x7f);
#endif
}
template <typename T> constexpr T log2p1(const T u) {
#ifdef __has_builtin
return u == 0 ? T(0) : T(64 - __builtin_clzll(u));
#else
unsigned long long v = static_cast<unsigned long long>(u);
return v = static_cast<unsigned long long>(v), v |= (v >> 1), v |= (v >> 2),
v |= (v >> 4), v |= (v >> 8), v |= (v >> 16), v |= (v >> 32),
popCount(v);
#endif
}
template <typename T> constexpr T clog(const T v) {
return v == 0 ? T(0) : log2p1(v - 1);
}
template <typename T> constexpr T msbp1(const T v) { return log2p1(v); }
template <typename T> constexpr T lsbp1(const T v) {
#ifdef __has_builtin
return __builtin_ffsll(v);
#else
return v == 0 ? T(0) : popCount((v & (-v)) - T(1)) + T(1);
#endif
}
template <typename T> constexpr bool ispow2(const T v) {
return popCount(v) == 1;
}
template <typename T> constexpr T ceil2(const T v) {
return v == 0 ? T(1) : T(1) << log2p1(v - 1);
}
template <typename T> constexpr T floor2(const T v) {
return v == 0 ? T(0) : T(1) << (log2p1(v) - 1);
}
//!============================================!//
//! 8888ba.88ba oo !//
//! 88 '8b '8b !//
//! 88 88 88 .d8888b. dP 88d888b. !//
//! 88 88 88 88' '88 88 88' '88 !//
//! 88 88 88 88. .88 88 88 88 !//
//! dP dP dP '88888P8 dP dP dP !//
//!============================================!//
int main() {
const ll L = read<ll>();
const int N = read<int>();
auto X = readVec<ll>(N);
auto cwd = [&](const int s, const int t) { return (X[t] - X[s] + L) % L; };
auto naive = [&](const int s) {
bool clock = false;
ll sum = X[s];
std::set<int> res;
for (int i = s + 1; i < N; i++) {
res.insert(i);
}
for (int p = s; not res.empty(); clock = not clock) {
if (clock) {
const int nxt = *res.begin();
sum += cwd(p, nxt), res.erase(nxt), p = nxt;
} else {
const int nxt = *res.rbegin();
sum += cwd(nxt, p), res.erase(nxt), p = nxt;
}
}
return sum;
};
auto tle = [&]() {
ll ans = 0;
for (int i = 0; i < N; i++) {
chmax(ans, naive(i));
}
for (auto &e : X) {
e = L - e;
}
std::reverse(X.begin(), X.end());
for (int i = 0; i < N; i++) {
chmax(ans, naive(i));
}
std::cout << ans << std::endl;
};
tle();
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#define NDEBUG
#define SHOW(...) static_cast<void>(0)
//!===========================================================!//
//! dP dP dP !//
//! 88 88 88 !//
//! 88aaaaa88a .d8888b. .d8888b. .d888b88 .d8888b. 88d888b. !//
//! 88 88 88ooood8 88' '88 88' '88 88ooood8 88' '88 !//
//! 88 88 88. ... 88. .88 88. .88 88. ... 88 !//
//! dP dP '88888P' '88888P8 '88888P8 '88888P' dP !//
//!===========================================================!//
template <typename T, typename A>
std::istream &operator>>(std::istream &is, std::vector<T, A> &v) {
for (auto &e : v) {
is >> e;
}
return is;
}
template <typename T> T read() {
T v;
return std::cin >> v, v;
}
template <typename T> std::vector<T> readVec(const std::size_t l) {
std::vector<T> v(l);
for (auto &e : v) {
std::cin >> e;
}
return v;
}
using ld = long double;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr unsigned int MOD = 1000000007;
template <typename T> constexpr T INF = std::numeric_limits<T>::max() / 4;
template <typename F> constexpr F PI = static_cast<F>(3.1415926535897932385);
std::mt19937 mt{std::random_device{}()};
template <typename T> bool chmin(T &a, const T &b) {
return (a > b ? a = b, true : false);
}
template <typename T> bool chmax(T &a, const T &b) {
return (a < b ? a = b, true : false);
}
template <typename T> std::vector<T> Vec(const std::size_t n, T v) {
return std::vector<T>(n, v);
}
template <class... Args> auto Vec(const std::size_t n, Args... args) {
return std::vector<decltype(Vec(args...))>(n, Vec(args...));
}
template <typename T> constexpr T popCount(const T u) {
#ifdef __has_builtin
return u == 0 ? T(0) : (T)__builtin_popcountll(u);
#else
unsigned long long v = static_cast<unsigned long long>(u);
return v = (v & 0x5555555555555555ULL) + (v >> 1 & 0x5555555555555555ULL),
v = (v & 0x3333333333333333ULL) + (v >> 2 & 0x3333333333333333ULL),
v = (v + (v >> 4)) & 0x0F0F0F0F0F0F0F0FULL,
static_cast<T>(v * 0x0101010101010101ULL >> 56 & 0x7f);
#endif
}
template <typename T> constexpr T log2p1(const T u) {
#ifdef __has_builtin
return u == 0 ? T(0) : T(64 - __builtin_clzll(u));
#else
unsigned long long v = static_cast<unsigned long long>(u);
return v = static_cast<unsigned long long>(v), v |= (v >> 1), v |= (v >> 2),
v |= (v >> 4), v |= (v >> 8), v |= (v >> 16), v |= (v >> 32),
popCount(v);
#endif
}
template <typename T> constexpr T clog(const T v) {
return v == 0 ? T(0) : log2p1(v - 1);
}
template <typename T> constexpr T msbp1(const T v) { return log2p1(v); }
template <typename T> constexpr T lsbp1(const T v) {
#ifdef __has_builtin
return __builtin_ffsll(v);
#else
return v == 0 ? T(0) : popCount((v & (-v)) - T(1)) + T(1);
#endif
}
template <typename T> constexpr bool ispow2(const T v) {
return popCount(v) == 1;
}
template <typename T> constexpr T ceil2(const T v) {
return v == 0 ? T(1) : T(1) << log2p1(v - 1);
}
template <typename T> constexpr T floor2(const T v) {
return v == 0 ? T(0) : T(1) << (log2p1(v) - 1);
}
//!============================================!//
//! 8888ba.88ba oo !//
//! 88 '8b '8b !//
//! 88 88 88 .d8888b. dP 88d888b. !//
//! 88 88 88 88' '88 88 88' '88 !//
//! 88 88 88 88. .88 88 88 88 !//
//! dP dP dP '88888P8 dP dP dP !//
//!============================================!//
int main() {
const ll L = read<ll>();
const int N = read<int>();
auto X = readVec<ll>(N);
auto cwd = [&](const int s, const int t) { return (X[t] - X[s] + L) % L; };
auto naive = [&](const int s) {
bool clock = false;
ll sum = X[s];
std::set<int> res;
for (int i = s + 1; i < N; i++) {
res.insert(i);
}
for (int p = s; not res.empty(); clock = not clock) {
if (clock) {
const int nxt = *res.begin();
sum += cwd(p, nxt), res.erase(nxt), p = nxt;
} else {
const int nxt = *res.rbegin();
sum += cwd(nxt, p), res.erase(nxt), p = nxt;
}
}
return sum;
};
auto tle = [&]() {
ll ans = 0;
for (int i = 0; i < N; i++) {
chmax(ans, naive(i));
}
for (auto &e : X) {
e = L - e;
}
std::reverse(X.begin(), X.end());
for (int i = 0; i < N; i++) {
chmax(ans, naive(i));
}
std::cout << ans << std::endl;
};
auto fast = [&]() {
ll ans = X.back(), sum = ans;
for (int s = N - 1, t = N - 1; s >= 1;) {
bool hoge = (N - 1 - s) % 2 == 0;
s--, t = hoge ? t : t - 1;
sum += -cwd(s, t) + cwd(hoge ? t : (t + 1) % N, s);
chmax(ans, sum);
SHOW(s, t, sum);
}
return ans;
};
auto ac = [&]() {
ll ans = fast();
for (auto &e : X) {
e = L - e;
}
std::reverse(X.begin(), X.end());
chmax(ans, fast());
std::cout << ans << std::endl;
};
ac();
// tle();
return 0;
}
| replace | 137 | 138 | 137 | 159 | TLE | |
p03187 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
x = x * 10 + ch - '0';
return x * f;
}
const int N = 100005;
LL s1[N], s2[N], a[N], L, Ans;
int n;
LL f(int l, int r) { return s1[r] - a[l] * (r - l) - s1[l]; }
void Calc() {
for (int i = 1; i <= n; ++i)
s1[i] = s1[i - 1] + a[i], s2[i] = s2[i - 1] + (L - a[n - i + 1]);
for (int i = 0; i < n; ++i) {
LL now = a[i] * (n - i) + a[i];
int cnt = (n - i) / 2;
if ((n - i) % 2 == 0)
now += s2[cnt] * 2 + f(i, i + cnt) * 2 - (a[i + cnt] - a[i]);
else
now += s2[cnt + 1] * 2 + f(i, i + cnt) * 2 - (L - a[n - cnt]);
// puts("-------------------------------");
// if (n & 1) {
// cout << s2[cnt + 1] * 2 << " " << f(i, i + cnt) * 2 << " " << (L -
//a[n - cnt]) << " ";
// }
// else {
// cout << s2[cnt] * 2 << " " << f(i, i + cnt) * 2 << " " << (a[i +
//cnt] - a[i]) << " ";
// }
// cout << now << "\n";
Ans = max(Ans, now);
}
}
int main() {
L = read();
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
Calc();
for (int i = 1; i <= n; ++i)
a[i] = L - a[i];
reverse(a + 1, a + n + 1);
Calc();
cout << Ans;
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
f = -1;
for (; isdigit(ch); ch = getchar())
x = x * 10 + ch - '0';
return x * f;
}
const int N = 200005;
LL s1[N], s2[N], a[N], L, Ans;
int n;
LL f(int l, int r) { return s1[r] - a[l] * (r - l) - s1[l]; }
void Calc() {
for (int i = 1; i <= n; ++i)
s1[i] = s1[i - 1] + a[i], s2[i] = s2[i - 1] + (L - a[n - i + 1]);
for (int i = 0; i < n; ++i) {
LL now = a[i] * (n - i) + a[i];
int cnt = (n - i) / 2;
if ((n - i) % 2 == 0)
now += s2[cnt] * 2 + f(i, i + cnt) * 2 - (a[i + cnt] - a[i]);
else
now += s2[cnt + 1] * 2 + f(i, i + cnt) * 2 - (L - a[n - cnt]);
// puts("-------------------------------");
// if (n & 1) {
// cout << s2[cnt + 1] * 2 << " " << f(i, i + cnt) * 2 << " " << (L -
//a[n - cnt]) << " ";
// }
// else {
// cout << s2[cnt] * 2 << " " << f(i, i + cnt) * 2 << " " << (a[i +
//cnt] - a[i]) << " ";
// }
// cout << now << "\n";
Ans = max(Ans, now);
}
}
int main() {
L = read();
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
Calc();
for (int i = 1; i <= n; ++i)
a[i] = L - a[i];
reverse(a + 1, a + n + 1);
Calc();
cout << Ans;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for (int i = (l); i < (r); i++)
#define incII(i, l, r) for (int i = (l); i <= (r); i++)
#define decID(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define decII(i, l, r) for (int i = (r); i >= (l); i--)
#define inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define FOR(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define RFOR(it, v) for (auto it = v.rbegin(); it != v.rend(); ++it)
template <typename T> bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmineq(T &a, T b) {
if (b <= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmaxeq(T &a, T b) {
if (b >= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
LL l, n, x[200002], d[200001], s[200002];
LL ID(int l, int r) { return s[r] - s[l]; }
LL CD(int l, int r) { return s[r] - s[l + 1]; }
int main() {
cin >> l >> n;
assert(n <= 2000);
x[0] = 0;
inc1(i, n) { cin >> x[i]; }
x[n + 1] = l;
n++;
inc(i, n) { d[i] = x[i + 1] - x[i]; }
inc(i, n) { s[i + 1] = s[i] + d[i]; }
LL ans = 0, sum = 0;
inc(i, n) {
if (i == 0) {
sum = 0;
} else {
if (2 * i - 1 < n) {
int x = i - 1, y = 2 * i - 1;
sum += 2 * ID(0, x);
sum += -2 * CD(x, y);
sum += 2 * CD(y, n);
sum += d[x];
} else {
int x = 2 * i - 1 - n, y = i - 1;
sum += -2 * ID(0, x);
sum += 2 * CD(x, y);
sum += -2 * CD(y, n);
sum += d[y];
}
}
setmax(ans, sum);
}
inc(i, n) {
if (i == 0) {
sum = ID(1, n);
} else {
if (2 * i < n) {
int x = i, y = 2 * i;
sum += 2 * ID(0, x);
sum += -2 * CD(x, y);
sum += 2 * CD(y, n);
sum += -d[x];
} else {
int x = 2 * i - n, y = i;
sum += -2 * ID(0, x);
sum += 2 * CD(x, y);
sum += -2 * CD(y, n);
sum += -d[y];
}
}
setmax(ans, sum);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for (int i = (l); i < (r); i++)
#define incII(i, l, r) for (int i = (l); i <= (r); i++)
#define decID(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define decII(i, l, r) for (int i = (r); i >= (l); i--)
#define inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define FOR(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define RFOR(it, v) for (auto it = v.rbegin(); it != v.rend(); ++it)
template <typename T> bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmineq(T &a, T b) {
if (b <= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmaxeq(T &a, T b) {
if (b >= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
LL l, n, x[200002], d[200001], s[200002];
LL ID(int l, int r) { return s[r] - s[l]; }
LL CD(int l, int r) { return s[r] - s[l + 1]; }
int main() {
cin >> l >> n;
x[0] = 0;
inc1(i, n) { cin >> x[i]; }
x[n + 1] = l;
n++;
inc(i, n) { d[i] = x[i + 1] - x[i]; }
inc(i, n) { s[i + 1] = s[i] + d[i]; }
LL ans = 0, sum = 0;
inc(i, n) {
if (i == 0) {
sum = 0;
} else {
if (2 * i - 1 < n) {
int x = i - 1, y = 2 * i - 1;
sum += 2 * ID(0, x);
sum += -2 * CD(x, y);
sum += 2 * CD(y, n);
sum += d[x];
} else {
int x = 2 * i - 1 - n, y = i - 1;
sum += -2 * ID(0, x);
sum += 2 * CD(x, y);
sum += -2 * CD(y, n);
sum += d[y];
}
}
setmax(ans, sum);
}
inc(i, n) {
if (i == 0) {
sum = ID(1, n);
} else {
if (2 * i < n) {
int x = i, y = 2 * i;
sum += 2 * ID(0, x);
sum += -2 * CD(x, y);
sum += 2 * CD(y, n);
sum += -d[x];
} else {
int x = 2 * i - n, y = i;
sum += -2 * ID(0, x);
sum += 2 * CD(x, y);
sum += -2 * CD(y, n);
sum += -d[y];
}
}
setmax(ans, sum);
}
cout << ans << endl;
return 0;
}
| delete | 75 | 77 | 75 | 75 | 0 | |
p03187 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
int n;
ll ans, a[MAXN], L, lft, rit, nstl, nstr, num;
int main() {
SF("%lld%d", &L, &n);
for (int i = 1; i <= n; i++)
SF("%lld", &a[i]);
ans = a[n];
nstl = n;
nstr = n + 1;
for (int i = n; i >= 1; i--) { // block between i and i-1
if (i != n)
ans = max(ans, a[i] + 2 * (L - a[i + 1]));
else
ans = max(ans, L - a[i] + 2 * a[i - 1]);
num = min(n - i, i - 1);
rit -= a[i];
while (i - nstr < num && nstr > 1) {
nstr--;
rit += (a[nstr]);
}
while (nstl - i > num && nstl > 0) {
lft -= (L - a[nstl]);
nstl--;
}
// PF("[%d %lld %lld
//%lld]\n",i,lft,rit,(lft+rit)*2+max(L-a[i],a[i]));
int lastl, lastr;
if (nstl == n)
lastl = 0;
else
lastl = (L - a[nstl + 1]) * 2;
if (nstr == 0)
lastr = 0;
else
lastr = a[nstr - 1] * 2;
ans = max(ans, (lft + rit) * 2 + max(a[i] + lastl, L - a[i] + lastr));
lft += (L - a[i]);
}
PF("%lld", ans);
} | #include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
typedef long long ll;
int n;
ll ans, a[MAXN], L, lft, rit, nstl, nstr, num;
int main() {
SF("%lld%d", &L, &n);
for (int i = 1; i <= n; i++)
SF("%lld", &a[i]);
ans = a[n];
nstl = n;
nstr = n + 1;
for (int i = n; i >= 1; i--) { // block between i and i-1
if (i != n)
ans = max(ans, a[i] + 2 * (L - a[i + 1]));
else
ans = max(ans, L - a[i] + 2 * a[i - 1]);
num = min(n - i, i - 1);
rit -= a[i];
while (i - nstr < num && nstr > 1) {
nstr--;
rit += (a[nstr]);
}
while (nstl - i > num && nstl > 0) {
lft -= (L - a[nstl]);
nstl--;
}
// PF("[%d %lld %lld
//%lld]\n",i,lft,rit,(lft+rit)*2+max(L-a[i],a[i]));
int lastl, lastr;
if (nstl == n)
lastl = 0;
else
lastl = (L - a[nstl + 1]) * 2;
if (nstr == 0)
lastr = 0;
else
lastr = a[nstr - 1] * 2;
ans = max(ans, (lft + rit) * 2 + max(a[i] + lastl, L - a[i] + lastr));
lft += (L - a[i]);
}
PF("%lld", ans);
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define N 2010
#define INF 1e18
using namespace std;
template <typename T> void read(T &x) {
x = 0;
char c = getchar();
int fh = 1;
while (!isdigit(c)) {
if (c == '-')
fh = -1;
c = getchar();
}
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
x *= fh;
}
ll n, l, a[N], b[N], sa[N], sb[N], ansn;
ll getans(int x) {
ll sum = 0;
int y = n - x;
if (x <= y) {
sum = (sa[x] + sb[x + x] - sb[x]) * 2 - a[x];
} else {
sum = (sa[x] - sa[x - y - 1] + sb[n] - sb[x]) * 2 - a[x];
}
return sum;
}
int main() {
read(l);
read(n);
for (int i = 1; i <= n; i++)
read(a[i]);
for (int i = 1; i <= n; i++)
b[i] = l - a[i];
for (int i = 1; i <= n; i++)
sa[i] = sa[i - 1] + a[i], sb[i] = sb[i - 1] + b[i];
for (int i = 1; i <= n; i++) {
ansn = max(ansn, getans(i));
}
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
for (int i = 1; i <= n; i++)
swap(a[i], b[i]);
for (int i = 1; i <= n; i++)
sa[i] = sa[i - 1] + a[i], sb[i] = sb[i - 1] + b[i];
for (int i = 1; i <= n; i++) {
ansn = max(ansn, getans(i));
}
cout << ansn << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define N 200010
#define INF 1e18
using namespace std;
template <typename T> void read(T &x) {
x = 0;
char c = getchar();
int fh = 1;
while (!isdigit(c)) {
if (c == '-')
fh = -1;
c = getchar();
}
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
x *= fh;
}
ll n, l, a[N], b[N], sa[N], sb[N], ansn;
ll getans(int x) {
ll sum = 0;
int y = n - x;
if (x <= y) {
sum = (sa[x] + sb[x + x] - sb[x]) * 2 - a[x];
} else {
sum = (sa[x] - sa[x - y - 1] + sb[n] - sb[x]) * 2 - a[x];
}
return sum;
}
int main() {
read(l);
read(n);
for (int i = 1; i <= n; i++)
read(a[i]);
for (int i = 1; i <= n; i++)
b[i] = l - a[i];
for (int i = 1; i <= n; i++)
sa[i] = sa[i - 1] + a[i], sb[i] = sb[i - 1] + b[i];
for (int i = 1; i <= n; i++) {
ansn = max(ansn, getans(i));
}
reverse(a + 1, a + n + 1);
reverse(b + 1, b + n + 1);
for (int i = 1; i <= n; i++)
swap(a[i], b[i]);
for (int i = 1; i <= n; i++)
sa[i] = sa[i - 1] + a[i], sb[i] = sb[i - 1] + b[i];
for (int i = 1; i <= n; i++) {
ansn = max(ansn, getans(i));
}
cout << ansn << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);
int L, N;
int X[110000];
int l[110000], r[110000];
int lsum[110000], rsum[110000];
signed main() {
cin >> L >> N;
for (int i = 0; i < N; i++)
cin >> X[i];
for (int i = 0; i < N; i++)
l[i + 1] = X[i], r[N - i] = L - X[i];
for (int i = 1; i <= N; i++)
lsum[i] = l[i] + lsum[i - 1], rsum[i] = r[i] + rsum[i - 1];
int ans = 0;
for (int i = 1; i <= N; i++) {
int ll = i, rr = N - i;
if (ll < rr) {
ans = max(ans, l[i] + 2 * (lsum[ll - 1] + rsum[rr] - rsum[rr - ll]));
} else {
ans = max(ans, l[i] + 2 * (lsum[ll - 1] - lsum[ll - 1 - rr] + rsum[rr]));
}
rr = i, ll = N - i;
if (rr < ll) {
ans = max(ans, r[i] + 2 * (rsum[rr - 1] + lsum[ll] - lsum[ll - rr]));
} else {
ans = max(ans, r[i] + 2 * (rsum[rr - 1] - rsum[rr - 1 - ll] + lsum[ll]));
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);
int L, N;
int X[220000];
int l[220000], r[220000];
int lsum[220000], rsum[220000];
signed main() {
cin >> L >> N;
for (int i = 0; i < N; i++)
cin >> X[i];
for (int i = 0; i < N; i++)
l[i + 1] = X[i], r[N - i] = L - X[i];
for (int i = 1; i <= N; i++)
lsum[i] = l[i] + lsum[i - 1], rsum[i] = r[i] + rsum[i - 1];
int ans = 0;
for (int i = 1; i <= N; i++) {
int ll = i, rr = N - i;
if (ll < rr) {
ans = max(ans, l[i] + 2 * (lsum[ll - 1] + rsum[rr] - rsum[rr - ll]));
} else {
ans = max(ans, l[i] + 2 * (lsum[ll - 1] - lsum[ll - 1 - rr] + rsum[rr]));
}
rr = i, ll = N - i;
if (rr < ll) {
ans = max(ans, r[i] + 2 * (rsum[rr - 1] + lsum[ll] - lsum[ll - rr]));
} else {
ans = max(ans, r[i] + 2 * (rsum[rr - 1] - rsum[rr - 1 - ll] + lsum[ll]));
}
}
cout << ans << endl;
}
| replace | 13 | 16 | 13 | 16 | 0 | |
p03187 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100005;
#define ll long long
int l[N], r[N];
ll sl[N], sr[N];
inline int read() {
int x = 0;
char e = getchar();
for (; e < '0' || e > '9'; e = getchar())
;
for (; e >= '0' && e <= '9'; e = getchar())
x = (x << 1) + (x << 3) + (e ^ 48);
return x;
}
inline ll Max(ll a, ll b) { return a > b ? a : b; }
int main() {
int len = read(), n = read();
for (int i = 1; i <= n; i++)
l[i] = read();
for (int i = 1; i <= n; i++)
r[i] = len - l[n + 1 - i];
for (int i = 1; i <= n; i++) {
sl[i] = sl[i - 1] + l[i];
sr[i] = sr[i - 1] + r[i];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ll cur;
int j = i + ((n - i) >> 1), k = (n - i + 1) >> 1;
cur = (sl[j] - sl[i - 1] + sr[k]) << 1ll;
if ((n - i) & 1)
cur -= r[k];
else
cur -= l[j];
ans = Max(ans, cur);
cur = (sr[j] - sr[i - 1] + sl[k]) << 1ll;
if ((n - i) & 1)
cur -= l[k];
else
cur -= r[j];
ans = Max(ans, cur);
}
printf("%lld", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 200005;
#define ll long long
int l[N], r[N];
ll sl[N], sr[N];
inline int read() {
int x = 0;
char e = getchar();
for (; e < '0' || e > '9'; e = getchar())
;
for (; e >= '0' && e <= '9'; e = getchar())
x = (x << 1) + (x << 3) + (e ^ 48);
return x;
}
inline ll Max(ll a, ll b) { return a > b ? a : b; }
int main() {
int len = read(), n = read();
for (int i = 1; i <= n; i++)
l[i] = read();
for (int i = 1; i <= n; i++)
r[i] = len - l[n + 1 - i];
for (int i = 1; i <= n; i++) {
sl[i] = sl[i - 1] + l[i];
sr[i] = sr[i - 1] + r[i];
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ll cur;
int j = i + ((n - i) >> 1), k = (n - i + 1) >> 1;
cur = (sl[j] - sl[i - 1] + sr[k]) << 1ll;
if ((n - i) & 1)
cur -= r[k];
else
cur -= l[j];
ans = Max(ans, cur);
cur = (sr[j] - sr[i - 1] + sl[k]) << 1ll;
if ((n - i) & 1)
cur -= l[k];
else
cur -= r[j];
ans = Max(ans, cur);
}
printf("%lld", ans);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03187 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll n, m;
int main() {
ll l;
cin >> l >> n;
ll x[n + 1], cumsum[n + 1], icumsum[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> x[i];
}
for (ll i = 0; i <= n; i++) {
cumsum[i] = 0;
icumsum[i] = 0;
}
for (ll i = 1; i <= n; i++) {
for (ll j = i; j <= n; j++) {
cumsum[j] += x[i];
icumsum[j] += l - x[n - i + 1];
}
}
ll max = 0;
// for(ll i = 0; i <= n; i++){
// cout << cumsum[i] << "," << icumsum[i] << endl;
// }
for (ll i = 1; i <= n; i++) {
ll buf = 0;
if ((n - i) % 2 == 0) {
ll end = (n + i) / 2;
buf += 2 * (cumsum[end - 1] - cumsum[i - 1] + icumsum[n - end]) + x[end];
} else {
ll end = (n + i) / 2 + 1;
buf += 2 * (cumsum[end - 1] - cumsum[i - 1] + icumsum[n - end]) +
(l - x[end]);
}
if (buf > max) {
max = buf;
}
}
for (ll i = 1; i <= n; i++) {
ll buf = 0;
if (i % 2 == 0) {
ll end = i / 2;
buf += 2 * (cumsum[end - 1] + icumsum[n - end] - icumsum[n - i]) + x[end];
} else {
ll end = i / 2 + 1;
buf += 2 * (cumsum[end - 1] + icumsum[n - end] - icumsum[n - i]) +
(l - x[end]);
}
if (buf > max) {
max = buf;
}
}
cout << max;
return 0;
} | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll n, m;
int main() {
ll l;
cin >> l >> n;
ll x[n + 1], cumsum[n + 1], icumsum[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> x[i];
}
for (ll i = 0; i <= n; i++) {
cumsum[i] = 0;
icumsum[i] = 0;
}
for (ll i = 1; i <= n; i++) {
cumsum[i] = cumsum[i - 1] + x[i];
icumsum[i] = icumsum[i - 1] + l - x[n - i + 1];
}
ll max = 0;
// for(ll i = 0; i <= n; i++){
// cout << cumsum[i] << "," << icumsum[i] << endl;
// }
for (ll i = 1; i <= n; i++) {
ll buf = 0;
if ((n - i) % 2 == 0) {
ll end = (n + i) / 2;
buf += 2 * (cumsum[end - 1] - cumsum[i - 1] + icumsum[n - end]) + x[end];
} else {
ll end = (n + i) / 2 + 1;
buf += 2 * (cumsum[end - 1] - cumsum[i - 1] + icumsum[n - end]) +
(l - x[end]);
}
if (buf > max) {
max = buf;
}
}
for (ll i = 1; i <= n; i++) {
ll buf = 0;
if (i % 2 == 0) {
ll end = i / 2;
buf += 2 * (cumsum[end - 1] + icumsum[n - end] - icumsum[n - i]) + x[end];
} else {
ll end = i / 2 + 1;
buf += 2 * (cumsum[end - 1] + icumsum[n - end] - icumsum[n - i]) +
(l - x[end]);
}
if (buf > max) {
max = buf;
}
}
cout << max;
return 0;
} | replace | 20 | 24 | 20 | 22 | TLE | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define f first
#define s second
#define MAXN 2510
ll OFF;
ll L[MAXN];
ll R[MAXN];
ll sum_left[MAXN];
ll sum_right[MAXN];
ll tri_left[MAXN];
ll tri_right[MAXN];
ll len, N;
ll ans = 0;
ll range_left(ll x, ll y) {
return sum_left[y] - sum_left[x - 1];
// cout<<x<< ' '<<y<<' '<<tri_left[y] - tri_left[x-1] - (x-1) * (sum_left[y] -
// sum_left[x-1])<<'\n'; return tri_left[y] - tri_left[x-1] - (x-1) *
// (sum_left[y] - sum_left[x-1]);
}
ll range_right(ll x, ll y) {
return sum_right[x] - sum_right[y + 1];
// cout<<x<< ' '<<y<<' '<<tri_right[x] - tri_right[y+1] - (N-x+1) *
// (sum_right[x] - sum_right[y-1])<<'\n'; return tri_right[x] - tri_right[y+1]
// - (N-x+1) * (sum_right[x] - sum_right[y-1]);
}
int main() {
cin >> len >> N;
for (ll i = 1; i <= N; ++i) {
cin >> L[i];
R[i] = len - L[i];
tri_left[i] = tri_left[i - 1] + L[i] * i;
sum_left[i] = sum_left[i - 1] + L[i];
}
for (ll i = N; i > 0; --i) {
sum_right[i] = sum_right[i + 1] + R[i];
}
// for (ll i=1;i<=N;++i)cout<<tri_left[i]<< ' ';cout<<'\n';
// for (ll i=1;i<=N;++i)cout<<sum_left[i]<< ' ';cout<<'\n';
// Firstly consider if we ending on the left
for (ll lend = 1; lend < N; ++lend) {
ll lstart = 1;
ll rstart = lend + 1;
ll rend = N;
ll offset = 0;
ll dif =
(rend - rstart) - (lend - lstart) + 1; // -1 if we ending on the right
if (dif > 0) {
// Go to right first
rend -= dif;
offset = R[rend + 1];
} else if (dif < 0) {
lstart -= dif;
offset = L[lstart - 1];
}
ll tot = 0;
// First bit is the left
tot = tot + range_left(lstart, lend) * 2 - (L[lend]);
// cout<<tot<<'\n';
tot = tot + range_right(rstart, rend) * 2;
// cout<<tot<<'\n';
if (dif > 0)
tot = tot + offset * 2;
ans = max(ans, tot);
// cout<<tot<<'\n';
// cout<<"Left "<<lstart<<' '<<lend<<'\n';
// cout<<"Right "<<rstart<<' '<<rend<<'\n';
// cout<<"Offset "<<offset<<'\n';
}
// return 0;
// Firstly consider if we ending on the right
for (ll lend = 1; lend < N; ++lend) {
ll lstart = 1;
ll rstart = lend + 1;
ll rend = N;
ll offset = 0;
ll dif =
(rend - rstart) - (lend - lstart) - 1; // -1 if we ending on the right
// cout<<"Dif "<<dif<<'\n';
if (dif > 0) {
// Go to right first
rend -= dif;
offset = R[rend + 1];
} else if (dif < 0) {
lstart -= dif;
offset = L[lstart - 1];
}
ll tot = 0;
// First bit is the left
tot = tot + range_left(lstart, lend) * 2;
tot = tot + range_right(rstart, rend) * 2 - R[rstart];
if (dif < 0)
tot = tot + offset * 2;
ans = max(ans, tot);
// cout<<tot<<'\n';
// cout<<"Left "<<lstart<<' '<<lend<<'\n';
// cout<<"Right "<<rstart<<' '<<rend<<'\n';
// cout<<"Offset "<<offset<<'\n';
}
ans = max({ans, L[N], R[1]});
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define f first
#define s second
#define MAXN 200100
ll OFF;
ll L[MAXN];
ll R[MAXN];
ll sum_left[MAXN];
ll sum_right[MAXN];
ll tri_left[MAXN];
ll tri_right[MAXN];
ll len, N;
ll ans = 0;
ll range_left(ll x, ll y) {
return sum_left[y] - sum_left[x - 1];
// cout<<x<< ' '<<y<<' '<<tri_left[y] - tri_left[x-1] - (x-1) * (sum_left[y] -
// sum_left[x-1])<<'\n'; return tri_left[y] - tri_left[x-1] - (x-1) *
// (sum_left[y] - sum_left[x-1]);
}
ll range_right(ll x, ll y) {
return sum_right[x] - sum_right[y + 1];
// cout<<x<< ' '<<y<<' '<<tri_right[x] - tri_right[y+1] - (N-x+1) *
// (sum_right[x] - sum_right[y-1])<<'\n'; return tri_right[x] - tri_right[y+1]
// - (N-x+1) * (sum_right[x] - sum_right[y-1]);
}
int main() {
cin >> len >> N;
for (ll i = 1; i <= N; ++i) {
cin >> L[i];
R[i] = len - L[i];
tri_left[i] = tri_left[i - 1] + L[i] * i;
sum_left[i] = sum_left[i - 1] + L[i];
}
for (ll i = N; i > 0; --i) {
sum_right[i] = sum_right[i + 1] + R[i];
}
// for (ll i=1;i<=N;++i)cout<<tri_left[i]<< ' ';cout<<'\n';
// for (ll i=1;i<=N;++i)cout<<sum_left[i]<< ' ';cout<<'\n';
// Firstly consider if we ending on the left
for (ll lend = 1; lend < N; ++lend) {
ll lstart = 1;
ll rstart = lend + 1;
ll rend = N;
ll offset = 0;
ll dif =
(rend - rstart) - (lend - lstart) + 1; // -1 if we ending on the right
if (dif > 0) {
// Go to right first
rend -= dif;
offset = R[rend + 1];
} else if (dif < 0) {
lstart -= dif;
offset = L[lstart - 1];
}
ll tot = 0;
// First bit is the left
tot = tot + range_left(lstart, lend) * 2 - (L[lend]);
// cout<<tot<<'\n';
tot = tot + range_right(rstart, rend) * 2;
// cout<<tot<<'\n';
if (dif > 0)
tot = tot + offset * 2;
ans = max(ans, tot);
// cout<<tot<<'\n';
// cout<<"Left "<<lstart<<' '<<lend<<'\n';
// cout<<"Right "<<rstart<<' '<<rend<<'\n';
// cout<<"Offset "<<offset<<'\n';
}
// return 0;
// Firstly consider if we ending on the right
for (ll lend = 1; lend < N; ++lend) {
ll lstart = 1;
ll rstart = lend + 1;
ll rend = N;
ll offset = 0;
ll dif =
(rend - rstart) - (lend - lstart) - 1; // -1 if we ending on the right
// cout<<"Dif "<<dif<<'\n';
if (dif > 0) {
// Go to right first
rend -= dif;
offset = R[rend + 1];
} else if (dif < 0) {
lstart -= dif;
offset = L[lstart - 1];
}
ll tot = 0;
// First bit is the left
tot = tot + range_left(lstart, lend) * 2;
tot = tot + range_right(rstart, rend) * 2 - R[rstart];
if (dif < 0)
tot = tot + offset * 2;
ans = max(ans, tot);
// cout<<tot<<'\n';
// cout<<"Left "<<lstart<<' '<<lend<<'\n';
// cout<<"Right "<<rstart<<' '<<rend<<'\n';
// cout<<"Offset "<<offset<<'\n';
}
ans = max({ans, L[N], R[1]});
cout << ans;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03187 | C++ | Runtime Error | #include <cstdio>
int n, m;
long long pre[100001][2], las[100011][2], x[100001], l, ans;
long long getmax(long long aa, long long bb) {
if (aa > bb)
return (aa);
else
return (bb);
}
int main() {
scanf("%lld%d", &l, &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &x[i]);
pre[0][0] = pre[0][1] = 0;
for (int i = 1; i <= n; i++)
pre[i][0] = x[i];
las[n + 1][0] = las[n + 1][1] = 0;
for (int i = n; i >= 1; i--)
las[i][0] = l - x[i];
for (int i = 1; i <= n; i++)
pre[i][1] = pre[i - 1][1] + pre[i][0];
for (int i = n; i >= 1; i--)
las[i][1] = las[i + 1][1] + las[i][0];
ans = las[n][0];
if (pre[n][0] > ans)
ans = pre[n][0];
for (int i = 1; i < n; i++) {
if ((n - i) > i)
ans =
getmax(ans, pre[i][1] * 2 + (las[i + 1][1] - las[2 * i + 2][1]) * 2 -
las[i + 1][0]);
else
ans = getmax(ans, (pre[i][1] - pre[2 * i - n][1]) * 2 +
las[i + 1][1] * 2 - las[i + 1][0]);
if ((n - i) < i)
ans = getmax(ans, (pre[i][1] - pre[2 * i - n - 1][1]) * 2 - pre[i][0] +
las[i + 1][1] * 2);
else
ans = getmax(ans, pre[i][1] * 2 - pre[i][0] +
(las[i + 1][1] - las[2 * i + 1][1]) * 2);
}
printf("%lld\n", ans);
} | #include <cstdio>
int n, m;
long long pre[200011][2], las[200011][2], x[200011], l, ans;
long long getmax(long long aa, long long bb) {
if (aa > bb)
return (aa);
else
return (bb);
}
int main() {
scanf("%lld%d", &l, &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &x[i]);
pre[0][0] = pre[0][1] = 0;
for (int i = 1; i <= n; i++)
pre[i][0] = x[i];
las[n + 1][0] = las[n + 1][1] = 0;
for (int i = n; i >= 1; i--)
las[i][0] = l - x[i];
for (int i = 1; i <= n; i++)
pre[i][1] = pre[i - 1][1] + pre[i][0];
for (int i = n; i >= 1; i--)
las[i][1] = las[i + 1][1] + las[i][0];
ans = las[n][0];
if (pre[n][0] > ans)
ans = pre[n][0];
for (int i = 1; i < n; i++) {
if ((n - i) > i)
ans =
getmax(ans, pre[i][1] * 2 + (las[i + 1][1] - las[2 * i + 2][1]) * 2 -
las[i + 1][0]);
else
ans = getmax(ans, (pre[i][1] - pre[2 * i - n][1]) * 2 +
las[i + 1][1] * 2 - las[i + 1][0]);
if ((n - i) < i)
ans = getmax(ans, (pre[i][1] - pre[2 * i - n - 1][1]) * 2 - pre[i][0] +
las[i + 1][1] * 2);
else
ans = getmax(ans, pre[i][1] * 2 - pre[i][0] +
(las[i + 1][1] - las[2 * i + 1][1]) * 2);
}
printf("%lld\n", ans);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
typedef long long ll;
const int maxn = 2010;
ll L, a[maxn], ans, s, dp[maxn][maxn][2];
int n;
ll s1[maxn], s2[maxn];
ll F(ll x) {
if (x == 0)
return 0;
return L - x;
}
int main() {
// freopen("1.txt","r",stdin);
read(L);
read(n);
for (int i = 1; i <= n; i++)
read(a[i]);
for (int i = 1; i <= n; i++)
s1[i] = s1[i - 1] + a[i];
for (int i = n; i >= 1; i--)
s2[i] = s2[i + 1] + F(a[i]);
ans = max(a[n], F(a[1]));
for (int i = 1; i <= n / 2; i++) {
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 2]) - F(a[i + 1]);
ans = max(ans, s);
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 1]) - a[i];
ans = max(ans, s);
}
for (int i = 1; i <= n; i++)
a[i] = L - a[i];
reverse(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
s1[i] = s1[i - 1] + a[i];
for (int i = n; i >= 1; i--)
s2[i] = s2[i + 1] + F(a[i]);
for (int i = 1; i <= n / 2; i++) {
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 2]) - F(a[i + 1]);
ans = max(ans, s);
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 1]) - a[i];
ans = max(ans, s);
}
printf("%lld\n", ans);
/*
for (int i=0;i<=n;i++)
for (int j=n+1;j>=1+i;j--) {
dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0]+a[i+1]-a[i]);
dp[i][j-1][1]=max(dp[i][j-1][1],dp[i][j][0]+a[i]+F(a[j-1]));
dp[i][j-1][1]=max(dp[i][j-1][1],dp[i][j][1]+a[j]-a[j-1]);
dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]+F(a[j])+a[i+1]);
if (i==2&&j==6) printf("%lld\n",dp[i][j][1]);
}
for (int i=0;i<=n;i++)
ans=max(ans,dp[i][i+1][0]),
ans=max(ans,dp[i][i+1][1]);
printf("%lld\n",ans);
*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
typedef long long ll;
const int maxn = (2e5) + 10;
ll L, a[maxn], ans, s;
int n;
ll s1[maxn], s2[maxn];
ll F(ll x) {
if (x == 0)
return 0;
return L - x;
}
int main() {
// freopen("1.txt","r",stdin);
read(L);
read(n);
for (int i = 1; i <= n; i++)
read(a[i]);
for (int i = 1; i <= n; i++)
s1[i] = s1[i - 1] + a[i];
for (int i = n; i >= 1; i--)
s2[i] = s2[i + 1] + F(a[i]);
ans = max(a[n], F(a[1]));
for (int i = 1; i <= n / 2; i++) {
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 2]) - F(a[i + 1]);
ans = max(ans, s);
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 1]) - a[i];
ans = max(ans, s);
}
for (int i = 1; i <= n; i++)
a[i] = L - a[i];
reverse(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
s1[i] = s1[i - 1] + a[i];
for (int i = n; i >= 1; i--)
s2[i] = s2[i + 1] + F(a[i]);
for (int i = 1; i <= n / 2; i++) {
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 2]) - F(a[i + 1]);
ans = max(ans, s);
s = 2 * s1[i] + 2 * (s2[i + 1] - s2[i * 2 + 1]) - a[i];
ans = max(ans, s);
}
printf("%lld\n", ans);
/*
for (int i=0;i<=n;i++)
for (int j=n+1;j>=1+i;j--) {
dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0]+a[i+1]-a[i]);
dp[i][j-1][1]=max(dp[i][j-1][1],dp[i][j][0]+a[i]+F(a[j-1]));
dp[i][j-1][1]=max(dp[i][j-1][1],dp[i][j][1]+a[j]-a[j-1]);
dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]+F(a[j])+a[i+1]);
if (i==2&&j==6) printf("%lld\n",dp[i][j][1]);
}
for (int i=0;i<=n;i++)
ans=max(ans,dp[i][i+1][0]),
ans=max(ans,dp[i][i+1][1]);
printf("%lld\n",ans);
*/
return 0;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p03187 | C++ | Runtime Error | /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type Abbreviation ---------- */
using ll = long long;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using GPQ = priority_queue<T, vector<T>, greater<T>>;
#define mp make_pair
#define mt make_tuple
/* ----------- debug ---------- */
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> p);
template <class T> ostream &operator<<(ostream &os, vector<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, set<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> p) {
return os << "(" << p.first << "," << p.second << ")";
}
/* ---------- Constants ---------- */
// const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));
/* ---------- Short Functions ---------- */
template <typename T> inline T sq(T a) { return a * a; }
template <typename T> T gcd(T a, T b) {
if (a > b)
return gcd(b, a);
return a == 0 ? b : gcd(b % a, a);
}
template <typename T, typename U> T mypow(T b, U n) {
if (n == 0)
return 1;
if (n == 1)
return b /* % MOD */;
if (n % 2 == 0) {
return mypow(b * b /* % MOD */, n / 2);
} else {
return mypow(b, n - 1) * b /* % MOD */;
}
}
ll pcnt(ll b) { return __builtin_popcountll(b); }
template <typename T> T iceil(T n, T d) { return (n + d - 1) / d; }
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int main() {
ll L;
int N;
cin >> L >> N;
if (N > 2000)
terminate();
ll X[N + 2];
X[0] = 0;
for (int i = 1; i <= N; ++i) {
cin >> X[i];
}
X[N + 1] = L;
ll cost = 0;
ll ans = max(ans, L - X[N]);
for (int l = 1; l <= N - l; ++l) {
// X[1] ~ X[l]までのl個
// X[l+1] ~ X[2l]までのl個
cost += X[l];
cost -= L - X[l];
cost += (L - X[l * 2 - 1]) + (L - X[l * 2]);
ans = max(ans, cost * 2 - min(X[l], L - X[l + 1] - (L - X[l * 2 + 1]) * 2));
}
for (int i = 0; i <= N + 1; ++i) {
X[i] = L - X[i];
}
reverse(X, X + N + 2);
cost = 0;
ans = max(ans, L - X[N]);
for (int l = 1; l <= N - l; ++l) {
// X[1] ~ X[l]までのl個
// X[l+1] ~ X[2l]までのl個
cost += X[l];
cost -= L - X[l];
cost += (L - X[l * 2 - 1]) + (L - X[l * 2]);
ans = max(ans, cost * 2 - min(X[l], L - X[l + 1] - (L - X[l * 2 + 1]) * 2));
}
cout << ans << endl;
return 0;
}
| /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type Abbreviation ---------- */
using ll = long long;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using GPQ = priority_queue<T, vector<T>, greater<T>>;
#define mp make_pair
#define mt make_tuple
/* ----------- debug ---------- */
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> p);
template <class T> ostream &operator<<(ostream &os, vector<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, set<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> p) {
return os << "(" << p.first << "," << p.second << ")";
}
/* ---------- Constants ---------- */
// const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));
/* ---------- Short Functions ---------- */
template <typename T> inline T sq(T a) { return a * a; }
template <typename T> T gcd(T a, T b) {
if (a > b)
return gcd(b, a);
return a == 0 ? b : gcd(b % a, a);
}
template <typename T, typename U> T mypow(T b, U n) {
if (n == 0)
return 1;
if (n == 1)
return b /* % MOD */;
if (n % 2 == 0) {
return mypow(b * b /* % MOD */, n / 2);
} else {
return mypow(b, n - 1) * b /* % MOD */;
}
}
ll pcnt(ll b) { return __builtin_popcountll(b); }
template <typename T> T iceil(T n, T d) { return (n + d - 1) / d; }
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int main() {
ll L;
int N;
cin >> L >> N;
ll X[N + 2];
X[0] = 0;
for (int i = 1; i <= N; ++i) {
cin >> X[i];
}
X[N + 1] = L;
ll cost = 0;
ll ans = max(ans, L - X[N]);
for (int l = 1; l <= N - l; ++l) {
// X[1] ~ X[l]までのl個
// X[l+1] ~ X[2l]までのl個
cost += X[l];
cost -= L - X[l];
cost += (L - X[l * 2 - 1]) + (L - X[l * 2]);
ans = max(ans, cost * 2 - min(X[l], L - X[l + 1] - (L - X[l * 2 + 1]) * 2));
}
for (int i = 0; i <= N + 1; ++i) {
X[i] = L - X[i];
}
reverse(X, X + N + 2);
cost = 0;
ans = max(ans, L - X[N]);
for (int l = 1; l <= N - l; ++l) {
// X[1] ~ X[l]までのl個
// X[l+1] ~ X[2l]までのl個
cost += X[l];
cost -= L - X[l];
cost += (L - X[l * 2 - 1]) + (L - X[l * 2]);
ans = max(ans, cost * 2 - min(X[l], L - X[l + 1] - (L - X[l * 2 + 1]) * 2));
}
cout << ans << endl;
return 0;
}
| delete | 105 | 108 | 105 | 105 | 0 | |
p03187 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++)
#define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--)
#define EREP(i, a) for (int i = start[(a)]; i; i = e[i].next)
template <class T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <class T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
#define fi first
#define se second
#define mkr(a, b) make_pair(a, b)
inline int read() {
int sum = 0, p = 1;
char ch = getchar();
while (!(('0' <= ch && ch <= '9') || ch == '-'))
ch = getchar();
if (ch == '-')
p = -1, ch = getchar();
while ('0' <= ch && ch <= '9')
sum = sum * 10 + ch - 48, ch = getchar();
return sum * p;
}
const int maxn = 1e5 + 20;
int n, L, x[maxn], y[maxn];
ll sx[maxn], sy[maxn];
inline ll X(int l, int r) { return sx[r] - sx[l - 1]; }
inline ll Y(int l, int r) { return sy[r] - sy[l - 1]; }
inline void init() {
L = read();
n = read();
REP(i, 1, n) sx[i] = x[i] = read(), sy[i] = y[i] = L - x[i];
REP(i, 1, n) sx[i] += sx[i - 1], sy[i] += sy[i - 1];
}
ll ans;
inline void doing() {
ll res;
chkmax(ans, (ll)x[n]);
REP(i, 1, n >> 1) {
int A = i, B = i, now = n - A - B;
// Right
res = 0;
res += X(now + 1, now + B) * 2;
res += Y(now + B + 2, n) * 2;
res += y[now + B + 1];
chkmax(ans, res);
res = x[now];
res += X(now + 1, now + B - 1) * 2 + x[now + B];
res += Y(now + B + 1, n) * 2;
chkmax(ans, res);
if (i * 2 + 1 <= n) {
res = 0;
A = i + 1;
B = i;
now = n - A - B;
res += x[now];
res += X(now + 1, now + B) * 2;
res += Y(now + B + 2, n) * 2;
res += y[now + B + 1];
chkmax(ans, res);
res = 0;
A = i;
B = i + 1;
now = n - A - B;
res += X(now + 1, now + B - 1) * 2;
res += x[now + B];
res += Y(now + B + 1, n) * 2;
chkmax(ans, res);
}
}
}
int main() {
init();
doing();
swap(x, y);
reverse(x + 1, x + n + 1);
reverse(y + 1, y + n + 1);
REP(i, 1, n) sx[i] = sx[i - 1] + x[i], sy[i] = sy[i - 1] + y[i];
doing();
printf("%lld\n", ans);
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++)
#define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--)
#define EREP(i, a) for (int i = start[(a)]; i; i = e[i].next)
template <class T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <class T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
#define fi first
#define se second
#define mkr(a, b) make_pair(a, b)
inline int read() {
int sum = 0, p = 1;
char ch = getchar();
while (!(('0' <= ch && ch <= '9') || ch == '-'))
ch = getchar();
if (ch == '-')
p = -1, ch = getchar();
while ('0' <= ch && ch <= '9')
sum = sum * 10 + ch - 48, ch = getchar();
return sum * p;
}
const int maxn = 5e5 + 20;
int n, L, x[maxn], y[maxn];
ll sx[maxn], sy[maxn];
inline ll X(int l, int r) { return sx[r] - sx[l - 1]; }
inline ll Y(int l, int r) { return sy[r] - sy[l - 1]; }
inline void init() {
L = read();
n = read();
REP(i, 1, n) sx[i] = x[i] = read(), sy[i] = y[i] = L - x[i];
REP(i, 1, n) sx[i] += sx[i - 1], sy[i] += sy[i - 1];
}
ll ans;
inline void doing() {
ll res;
chkmax(ans, (ll)x[n]);
REP(i, 1, n >> 1) {
int A = i, B = i, now = n - A - B;
// Right
res = 0;
res += X(now + 1, now + B) * 2;
res += Y(now + B + 2, n) * 2;
res += y[now + B + 1];
chkmax(ans, res);
res = x[now];
res += X(now + 1, now + B - 1) * 2 + x[now + B];
res += Y(now + B + 1, n) * 2;
chkmax(ans, res);
if (i * 2 + 1 <= n) {
res = 0;
A = i + 1;
B = i;
now = n - A - B;
res += x[now];
res += X(now + 1, now + B) * 2;
res += Y(now + B + 2, n) * 2;
res += y[now + B + 1];
chkmax(ans, res);
res = 0;
A = i;
B = i + 1;
now = n - A - B;
res += X(now + 1, now + B - 1) * 2;
res += x[now + B];
res += Y(now + B + 1, n) * 2;
chkmax(ans, res);
}
}
}
int main() {
init();
doing();
swap(x, y);
reverse(x + 1, x + n + 1);
reverse(y + 1, y + n + 1);
REP(i, 1, n) sx[i] = sx[i - 1] + x[i], sy[i] = sy[i - 1] + y[i];
doing();
printf("%lld\n", ans);
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX_N 2000
using namespace std;
typedef long long lint;
int n, l;
int v[MAX_N + 1];
lint rez = 0;
lint st[MAX_N + 1];
lint dr[MAX_N + 2];
lint getSumSt(int s, int d) {
if (s > d)
return 0;
return (st[d] - st[s - 1]);
}
lint getSumDr(int s, int d) {
if (s > d)
return 0;
return (dr[n - d + 1] - dr[n - s + 1 + 1]);
}
void calc(int cl, int sign) {
lint cr;
int i, j, h;
for (int x = 1; x <= n; x++) {
cr = v[x];
if (cl == 1)
cr = l - v[n - x + 1];
h = cl;
i = x;
j = 0;
if (cl == 1)
swap(i, j);
cout << "AM INCEPUT " << i << " " << j << " " << h << " COST " << cr
<< "\n";
while (i + j < n) {
if (h == 0) {
cr = cr + v[i] + l - v[n - j];
j++;
}
if (h == 1) {
cr = cr + l - v[n - j + 1] + v[i + 1];
i++;
}
h = 1 - h;
}
cout << "AM TERMIANT " << i << " " << j << " " << h << " COST " << cr
<< "\n";
rez = max(rez, cr);
}
}
void calc2(int cl, int sign) {
lint cr;
int i, j, h;
for (int x = 1; x <= n; x++) {
cr = v[x];
if (cl == 1)
cr = l - v[n - x + 1];
h = cl;
i = x;
j = 0;
if (cl == 1)
swap(i, j);
// cout << "AM INCEPUT " << i << " " << j << " " << h << " COST " << cr <<
// "\n";
int oi = i;
int oj = j;
int inc = n - (i + j);
if (inc > 0) {
i += (inc >> 1);
j += (inc >> 1);
int ok = 0;
if ((inc & 1) == 1) {
if (h == 1)
i++;
else
j++;
ok = 1;
}
cr = cr + getSumSt(oi, i) +
getSumDr(oj, j) /*+ (getSumSt(oi + (1 - h), i - (1 - h)) +
getSumDr(oj + h, j - h)) * (min(getSumSt(oi + (1 -
h), i - (1 - h)), getSumDr(oj + h, j - h)) > 0)*/
;
if (ok == 0)
cr = cr + getSumSt(oi + (1 - h), i - (1 - h)) + getSumDr(oj + h, j - h);
else
cr = cr + getSumSt(oi + (1 - h), i - h) + getSumDr(oj + h, j - (1 - h));
}
// cout << "AM TERMIANT " << i << " " << j << " " << h << " COST " << cr <<
// "\n";
rez = max(rez, cr);
}
}
int main() {
cin >> l >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
st[i] = st[i - 1] + v[i];
}
for (int i = n; i >= 1; i--)
dr[i] = dr[i + 1] + (l - v[i]);
// calc(0, 1);
// calc(1, -1);
// cout << "\n";
calc2(0, 1);
calc2(1, -1);
cout << rez << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define MAX_N 200000
using namespace std;
typedef long long lint;
int n, l;
int v[MAX_N + 1];
lint rez = 0;
lint st[MAX_N + 1];
lint dr[MAX_N + 2];
lint getSumSt(int s, int d) {
if (s > d)
return 0;
return (st[d] - st[s - 1]);
}
lint getSumDr(int s, int d) {
if (s > d)
return 0;
return (dr[n - d + 1] - dr[n - s + 1 + 1]);
}
void calc(int cl, int sign) {
lint cr;
int i, j, h;
for (int x = 1; x <= n; x++) {
cr = v[x];
if (cl == 1)
cr = l - v[n - x + 1];
h = cl;
i = x;
j = 0;
if (cl == 1)
swap(i, j);
cout << "AM INCEPUT " << i << " " << j << " " << h << " COST " << cr
<< "\n";
while (i + j < n) {
if (h == 0) {
cr = cr + v[i] + l - v[n - j];
j++;
}
if (h == 1) {
cr = cr + l - v[n - j + 1] + v[i + 1];
i++;
}
h = 1 - h;
}
cout << "AM TERMIANT " << i << " " << j << " " << h << " COST " << cr
<< "\n";
rez = max(rez, cr);
}
}
void calc2(int cl, int sign) {
lint cr;
int i, j, h;
for (int x = 1; x <= n; x++) {
cr = v[x];
if (cl == 1)
cr = l - v[n - x + 1];
h = cl;
i = x;
j = 0;
if (cl == 1)
swap(i, j);
// cout << "AM INCEPUT " << i << " " << j << " " << h << " COST " << cr <<
// "\n";
int oi = i;
int oj = j;
int inc = n - (i + j);
if (inc > 0) {
i += (inc >> 1);
j += (inc >> 1);
int ok = 0;
if ((inc & 1) == 1) {
if (h == 1)
i++;
else
j++;
ok = 1;
}
cr = cr + getSumSt(oi, i) +
getSumDr(oj, j) /*+ (getSumSt(oi + (1 - h), i - (1 - h)) +
getSumDr(oj + h, j - h)) * (min(getSumSt(oi + (1 -
h), i - (1 - h)), getSumDr(oj + h, j - h)) > 0)*/
;
if (ok == 0)
cr = cr + getSumSt(oi + (1 - h), i - (1 - h)) + getSumDr(oj + h, j - h);
else
cr = cr + getSumSt(oi + (1 - h), i - h) + getSumDr(oj + h, j - (1 - h));
}
// cout << "AM TERMIANT " << i << " " << j << " " << h << " COST " << cr <<
// "\n";
rez = max(rez, cr);
}
}
int main() {
cin >> l >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
st[i] = st[i - 1] + v[i];
}
for (int i = n; i >= 1; i--)
dr[i] = dr[i + 1] + (l - v[i]);
// calc(0, 1);
// calc(1, -1);
// cout << "\n";
calc2(0, 1);
calc2(1, -1);
cout << rez << "\n";
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p03187 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
#define M 100020
using namespace std;
LL read() {
LL nm = 0, fh = 1;
char cw = getchar();
for (; !isdigit(cw); cw = getchar())
if (cw == '-')
fh = -fh;
for (; isdigit(cw); cw = getchar())
nm = nm * 10 + (cw - '0');
return nm * fh;
}
LL n, m, D, p[M], F[M], ans, pre[M], suf[M];
void solve() {
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] + p[i];
for (int i = n; i; i--)
suf[i] = suf[i + 1] + D - p[i];
for (int i = 1; i <= n; i++) {
LL lt, rt, now = 0;
lt = ((n + i) >> 1), rt = lt + 1;
now = ((pre[lt] - pre[i - 1] + suf[rt]) << 1);
if ((n - i - 1) % 2 == 0)
now -= D - p[rt];
else
now -= p[lt];
ans = max(ans, now);
}
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
D = read(), n = read();
for (int i = 1; i <= n; i++)
p[i] = read();
ans = max(D - p[1], p[n]), solve();
for (int i = 1; i <= n; i++)
p[i] = D - p[i];
reverse(p + 1, p + n + 1);
solve(), printf("%lld\n", ans);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
#define M 1000020
using namespace std;
LL read() {
LL nm = 0, fh = 1;
char cw = getchar();
for (; !isdigit(cw); cw = getchar())
if (cw == '-')
fh = -fh;
for (; isdigit(cw); cw = getchar())
nm = nm * 10 + (cw - '0');
return nm * fh;
}
LL n, m, D, p[M], F[M], ans, pre[M], suf[M];
void solve() {
for (int i = 1; i <= n; i++)
pre[i] = pre[i - 1] + p[i];
for (int i = n; i; i--)
suf[i] = suf[i + 1] + D - p[i];
for (int i = 1; i <= n; i++) {
LL lt, rt, now = 0;
lt = ((n + i) >> 1), rt = lt + 1;
now = ((pre[lt] - pre[i - 1] + suf[rt]) << 1);
if ((n - i - 1) % 2 == 0)
now -= D - p[rt];
else
now -= p[lt];
ans = max(ans, now);
}
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
D = read(), n = read();
for (int i = 1; i <= n; i++)
p[i] = read();
ans = max(D - p[1], p[n]), solve();
for (int i = 1; i <= n; i++)
p[i] = D - p[i];
reverse(p + 1, p + n + 1);
solve(), printf("%lld\n", ans);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03187 | C++ | Runtime Error | /*
对应原理
其实每次只有两种选择,所有这个题的对拍很好写
怎么确定能不能达到最大值呢
跑步的速度是可以加快的,每次贪心选择能行吗
有一些能够拿两次,最终答案一定是要将什么拿两次的
最快的办法当然是永不回头,但是最慢的办法并不是一步一回头
我们要积累7+7+1=15
顺时针能够拿两次
为了把很大的一个数拿两次,必须他的补集中有能够回去的,并且那个数字一定是我右边紧邻的那个
为了拿到这一个7两次,顺时针必须留一个,
就意味着逆时针3次对应顺时针1次
并且必须先逆3
为了拿到这个4两次,顺时针留一个
则逆2顺2 且逆先
为了拿到3两次,顺时针留一个
逆1顺3
i n-i
当i<n-i时
左i 右(i+1)减去最左边 最后一次是顺时针
a[1...i]*2+((i+1)*2*n-a[i+1...i+i+1]*2)-(n-a[i+1]) 左i减去最右边 右i
最后一次是逆时针 a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i]
i=n-i时
左i右i 减去左或减去右
a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i]/a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i+1]
i>n-i时
左n-i+1减去最右边 右n-i
左n-i,右n-i减去最左边
*/
#include <bits/stdc++.h>
#define MAXN 205
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll l, n, x, sum[MAXN], a[MAXN], fin;
int main() {
// freopen("c://duipai//939cdata.txt", "r", stdin);
// freopen("c://duipai//939cwa.txt", "w", stdout);
while (~scanf("%lld", &l)) {
// string str;
// cin>>str;
// cout<<str<<endl;
scanf("%lld", &n);
memset(sum, 0, sizeof(sum));
fin = 0;
for (ll i = 1; i <= n; i++) {
scanf("%lld", &x);
a[i] = x;
sum[i] = sum[i - 1] + x;
}
if (n == 1) {
printf("%lld\n", max(a[1], l - a[1]));
continue;
}
for (ll i = 1; i < n; i++) {
ll ans1, ans2;
if (i < n - i) {
ans1 = sum[i] * 2 + ((i + 1) * 2 * l - (sum[i + i + 1] - sum[i]) * 2) -
(l - a[i + 1]);
ans2 = sum[i] * 2 + (i * 2 * l - (sum[i + i] - sum[i]) * 2) - a[i];
} else if (i == n - i) {
ans1 = sum[i] * 2 + (i * 2 * l - (sum[i + i] - sum[i]) * 2) -
(l - a[i + 1]);
ans2 = sum[i] * 2 + (i * 2 * l - (sum[i + i] - sum[i]) * 2) - a[i];
} else {
ans1 = (sum[i] - sum[i - (n - i) - 1]) * 2 +
((n - i) * 2 * l - (sum[n] - sum[i]) * 2) - (a[i]);
ans2 = (sum[i] - sum[i - (n - i)]) * 2 +
((n - i) * 2 * l - (sum[n] - sum[i]) * 2) - (l - a[i + 1]);
}
// printf("%lld %lld\n",ans1,ans2);
ll ans = max(ans1, ans2);
fin = max(fin, ans);
}
fin = max(fin, a[n]);
fin = max(fin, l - a[1]);
printf("%lld\n", fin);
}
}
/*
*/
| /*
对应原理
其实每次只有两种选择,所有这个题的对拍很好写
怎么确定能不能达到最大值呢
跑步的速度是可以加快的,每次贪心选择能行吗
有一些能够拿两次,最终答案一定是要将什么拿两次的
最快的办法当然是永不回头,但是最慢的办法并不是一步一回头
我们要积累7+7+1=15
顺时针能够拿两次
为了把很大的一个数拿两次,必须他的补集中有能够回去的,并且那个数字一定是我右边紧邻的那个
为了拿到这一个7两次,顺时针必须留一个,
就意味着逆时针3次对应顺时针1次
并且必须先逆3
为了拿到这个4两次,顺时针留一个
则逆2顺2 且逆先
为了拿到3两次,顺时针留一个
逆1顺3
i n-i
当i<n-i时
左i 右(i+1)减去最左边 最后一次是顺时针
a[1...i]*2+((i+1)*2*n-a[i+1...i+i+1]*2)-(n-a[i+1]) 左i减去最右边 右i
最后一次是逆时针 a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i]
i=n-i时
左i右i 减去左或减去右
a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i]/a[1...i]*2+(i*2*n-a[i+1...i+i]*2)-a[i+1]
i>n-i时
左n-i+1减去最右边 右n-i
左n-i,右n-i减去最左边
*/
#include <bits/stdc++.h>
#define MAXN 200005
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll l, n, x, sum[MAXN], a[MAXN], fin;
int main() {
// freopen("c://duipai//939cdata.txt", "r", stdin);
// freopen("c://duipai//939cwa.txt", "w", stdout);
while (~scanf("%lld", &l)) {
// string str;
// cin>>str;
// cout<<str<<endl;
scanf("%lld", &n);
memset(sum, 0, sizeof(sum));
fin = 0;
for (ll i = 1; i <= n; i++) {
scanf("%lld", &x);
a[i] = x;
sum[i] = sum[i - 1] + x;
}
if (n == 1) {
printf("%lld\n", max(a[1], l - a[1]));
continue;
}
for (ll i = 1; i < n; i++) {
ll ans1, ans2;
if (i < n - i) {
ans1 = sum[i] * 2 + ((i + 1) * 2 * l - (sum[i + i + 1] - sum[i]) * 2) -
(l - a[i + 1]);
ans2 = sum[i] * 2 + (i * 2 * l - (sum[i + i] - sum[i]) * 2) - a[i];
} else if (i == n - i) {
ans1 = sum[i] * 2 + (i * 2 * l - (sum[i + i] - sum[i]) * 2) -
(l - a[i + 1]);
ans2 = sum[i] * 2 + (i * 2 * l - (sum[i + i] - sum[i]) * 2) - a[i];
} else {
ans1 = (sum[i] - sum[i - (n - i) - 1]) * 2 +
((n - i) * 2 * l - (sum[n] - sum[i]) * 2) - (a[i]);
ans2 = (sum[i] - sum[i - (n - i)]) * 2 +
((n - i) * 2 * l - (sum[n] - sum[i]) * 2) - (l - a[i + 1]);
}
// printf("%lld %lld\n",ans1,ans2);
ll ans = max(ans1, ans2);
fin = max(fin, ans);
}
fin = max(fin, a[n]);
fin = max(fin, l - a[1]);
printf("%lld\n", fin);
}
}
/*
*/
| replace | 33 | 34 | 33 | 34 | 0 | |
p03187 | C++ | Runtime Error | #include <cstdio>
#include <cstdlib>
#include <iostream>
#define int long long
using namespace std;
const int N = 1e5 + 10, inf = 1e9;
int x[N], tmp[N], d1[N], d2[N];
int L, n, ans;
int D1(int l, int r) { return r < l ? 0 : (d1[r] - d1[l - 1]); }
int D2(int l, int r) { return r < l ? 0 : (d2[r] - d2[l - 1]); }
void Calc() {
for (int i = 1; i <= n; i++)
d1[i] = d1[i - 1] + x[i];
for (int i = 1; i <= n; i++)
d2[i] = d2[i - 1] + L - x[i];
for (int i = 1, ps; i <= n / 2; i++) {
ps = n - i * 2;
ans = max(ans, D1(ps, ps + i - 1) * 2 + x[ps + i] + D2(ps + i + 1, n) * 2);
ans = max(ans, D1(ps + 1, ps + i) * 2 + D2(ps + i + 2, n) * 2 + L -
x[ps + i + 1]);
}
}
signed main() {
cin >> L >> n;
for (int i = 1; i <= n; i++)
cin >> x[i];
ans = max(ans, max(x[n], L - x[1]));
Calc();
for (int i = 1; i <= n; i++)
tmp[i] = L - x[n - i + 1];
for (int i = 1; i <= n; i++)
x[i] = tmp[i];
Calc();
cout << ans << endl;
} | #include <cstdio>
#include <cstdlib>
#include <iostream>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int x[N], tmp[N], d1[N], d2[N];
int L, n, ans;
int D1(int l, int r) { return r < l ? 0 : (d1[r] - d1[l - 1]); }
int D2(int l, int r) { return r < l ? 0 : (d2[r] - d2[l - 1]); }
void Calc() {
for (int i = 1; i <= n; i++)
d1[i] = d1[i - 1] + x[i];
for (int i = 1; i <= n; i++)
d2[i] = d2[i - 1] + L - x[i];
for (int i = 1, ps; i <= n / 2; i++) {
ps = n - i * 2;
ans = max(ans, D1(ps, ps + i - 1) * 2 + x[ps + i] + D2(ps + i + 1, n) * 2);
ans = max(ans, D1(ps + 1, ps + i) * 2 + D2(ps + i + 2, n) * 2 + L -
x[ps + i + 1]);
}
}
signed main() {
cin >> L >> n;
for (int i = 1; i <= n; i++)
cin >> x[i];
ans = max(ans, max(x[n], L - x[1]));
Calc();
for (int i = 1; i <= n; i++)
tmp[i] = L - x[n - i + 1];
for (int i = 1; i <= n; i++)
x[i] = tmp[i];
Calc();
cout << ans << endl;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD 1e9 + 7
using namespace std;
#define pp push_back
#define po pop_back
#define mp make_pair
#define clr(a) memset(a, 0, sizeof(a))
#define neg(a) memset(a, -1, sizeof(a))
#define fas(a) memset(a, false, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define debug1(x) cout << #x << ": " << x << " "
#define rev(x) reverse(x.begin(), x.end())
#define int long long
#define F first
#define S second
// int a[2000];
void printvector(std::vector<int> v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << "" << endl;
}
void printarray(int a[], int n) {
for (int i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << "" << endl;
}
int L, n;
int get(int x[], int y[]) {
// printarray(x,n);
// printarray(y,n);
int px[n], py[n];
for (int i = 0; i < n; ++i) {
px[i] = 2 * x[i];
if (i != 0)
px[i] += px[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
py[i] = 2 * y[i];
if (i != n - 1)
py[i] += py[i + 1];
}
int fans = 0;
for (int i = 0; i < n; i++) {
int ans = 0;
int left = 0, right = 0;
if (i + 1 > n - (i + 1)) {
left = n - (i + 1) + 1;
right = n - (i + 1);
} else {
left = i + 1;
right = i + 1;
}
ans += px[i] - x[i];
if (i - left >= 0)
ans -= px[i - left];
if (right > 0) {
ans += py[i + 1];
if (i + 1 + right < n)
ans -= py[i + 1 + right];
}
fans = max(fans, ans);
}
// debug(fans);
return fans;
}
void solve() {
cin >> L >> n;
int x[n], y[n];
for (int i = 0; i < n; i++)
cin >> x[i];
for (int i = 0; i < n; i++)
y[i] = L - x[i];
int ans1 = get(x, y);
for (int i = 0; i < n; i++)
swap(x[i], y[i]);
for (int i = 0; i < n / 2; i++) {
swap(x[i], x[n - i - 1]);
swap(y[i], y[n - i - 1]);
}
int ans2 = get(x, y);
cout << max(ans1, ans2) << endl;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
#define MOD 1e9 + 7
using namespace std;
#define pp push_back
#define po pop_back
#define mp make_pair
#define clr(a) memset(a, 0, sizeof(a))
#define neg(a) memset(a, -1, sizeof(a))
#define fas(a) memset(a, false, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define debug1(x) cout << #x << ": " << x << " "
#define rev(x) reverse(x.begin(), x.end())
#define int long long
#define F first
#define S second
// int a[2000];
void printvector(std::vector<int> v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << "" << endl;
}
void printarray(int a[], int n) {
for (int i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << "" << endl;
}
int L, n;
int get(int x[], int y[]) {
// printarray(x,n);
// printarray(y,n);
int px[n], py[n];
for (int i = 0; i < n; ++i) {
px[i] = 2 * x[i];
if (i != 0)
px[i] += px[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
py[i] = 2 * y[i];
if (i != n - 1)
py[i] += py[i + 1];
}
int fans = 0;
for (int i = 0; i < n; i++) {
int ans = 0;
int left = 0, right = 0;
if (i + 1 > n - (i + 1)) {
left = n - (i + 1) + 1;
right = n - (i + 1);
} else {
left = i + 1;
right = i + 1;
}
ans += px[i] - x[i];
if (i - left >= 0)
ans -= px[i - left];
if (right > 0) {
ans += py[i + 1];
if (i + 1 + right < n)
ans -= py[i + 1 + right];
}
fans = max(fans, ans);
}
// debug(fans);
return fans;
}
void solve() {
cin >> L >> n;
int x[n], y[n];
for (int i = 0; i < n; i++)
cin >> x[i];
for (int i = 0; i < n; i++)
y[i] = L - x[i];
int ans1 = get(x, y);
for (int i = 0; i < n; i++)
swap(x[i], y[i]);
for (int i = 0; i < n / 2; i++) {
swap(x[i], x[n - i - 1]);
swap(y[i], y[n - i - 1]);
}
int ans2 = get(x, y);
cout << max(ans1, ans2) << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | delete | 96 | 99 | 96 | 96 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 200011;
LL ld[MAXN], rd[MAXN];
LL a[MAXN];
int n, m;
LL l, ans;
int main() {
scanf("%lld%d", &l, &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
}
ld[n] = 0;
ld[n - 1] = l - (a[n] - a[n - 1]);
int pre = n;
for (int i = n - 2; i; --i) {
if ((n - i + 1) & 1) {
ld[i] = ld[i + 1] - (a[pre - 1] - a[i + 1]) + (l - (a[pre] - a[i]));
} else {
ld[i] = ld[i + 1] - (a[pre - 1] - a[i + 1]) + (l - (a[pre - 1] - a[i]));
--pre;
}
}
rd[1] = 0;
rd[2] = l - (a[2] - a[1]);
pre = 1;
for (int i = 3; i <= n; ++i) {
if (i & 1) {
rd[i] = rd[i - 1] - (a[i - 1] - a[pre + 1]) + (l - (a[i] - a[pre]));
} else {
rd[i] = rd[i - 1] - (a[i - 1] - a[pre + 1]) + (l - (a[i] - a[pre + 1]));
++pre;
}
}
ans = 0;
for (int i = 1; i <= n; ++i) {
ans = max(ans, a[i] + ld[i]);
ans = max(ans, l - a[i] + rd[i]);
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 200011;
LL ld[MAXN], rd[MAXN];
LL a[MAXN];
int n, m;
LL l, ans;
int main() {
scanf("%lld%d", &l, &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
}
ld[n] = 0;
ld[n - 1] = l - (a[n] - a[n - 1]);
int pre = n;
for (int i = n - 2; i > 0; --i) {
if ((n - i + 1) & 1) {
ld[i] = ld[i + 1] - (a[pre - 1] - a[i + 1]) + (l - (a[pre] - a[i]));
} else {
ld[i] = ld[i + 1] - (a[pre - 1] - a[i + 1]) + (l - (a[pre - 1] - a[i]));
--pre;
}
}
rd[1] = 0;
rd[2] = l - (a[2] - a[1]);
pre = 1;
for (int i = 3; i <= n; ++i) {
if (i & 1) {
rd[i] = rd[i - 1] - (a[i - 1] - a[pre + 1]) + (l - (a[i] - a[pre]));
} else {
rd[i] = rd[i - 1] - (a[i - 1] - a[pre + 1]) + (l - (a[i] - a[pre + 1]));
++pre;
}
}
ans = 0;
for (int i = 1; i <= n; ++i) {
ans = max(ans, a[i] + ld[i]);
ans = max(ans, l - a[i] + rd[i]);
}
printf("%lld\n", ans);
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p03187 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#define RI register int
#define CI const int &
using namespace std;
const int N = 100005;
int l, n, a[N];
long long pfx[N], sfx[N], ans;
int main() {
RI i;
for (scanf("%d%d", &l, &n), i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (i = 1; i <= n; ++i)
pfx[i] = pfx[i - 1] + a[i];
for (i = n; i; --i)
sfx[i] = sfx[i + 1] + l - a[i];
for (i = 1; i < n; ++i)
ans = max(ans, 2LL * a[i] + 2LL * (pfx[i + n >> 1] - pfx[i]) +
2LL * sfx[(i + n >> 1) + 1] -
((n - i) & 1 ? l - a[(i + n >> 1) + 1] : a[i + n >> 1]));
for (i = n; i > 1; --i)
ans = max(ans, 2LL * (l - a[i]) + 2LL * (sfx[i + 2 >> 1] - sfx[i]) +
2LL * pfx[(i + 2 >> 1) - 1] -
((i - 1) & 1 ? a[(i + 2 >> 1) - 1] : l - a[i + 2 >> 1]));
return printf("%lld", max(ans, (long long)max(a[n], l - a[1]))), 0;
} | #include <cstdio>
#include <iostream>
#define RI register int
#define CI const int &
using namespace std;
const int N = 200005;
int l, n, a[N];
long long pfx[N], sfx[N], ans;
int main() {
RI i;
for (scanf("%d%d", &l, &n), i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (i = 1; i <= n; ++i)
pfx[i] = pfx[i - 1] + a[i];
for (i = n; i; --i)
sfx[i] = sfx[i + 1] + l - a[i];
for (i = 1; i < n; ++i)
ans = max(ans, 2LL * a[i] + 2LL * (pfx[i + n >> 1] - pfx[i]) +
2LL * sfx[(i + n >> 1) + 1] -
((n - i) & 1 ? l - a[(i + n >> 1) + 1] : a[i + n >> 1]));
for (i = n; i > 1; --i)
ans = max(ans, 2LL * (l - a[i]) + 2LL * (sfx[i + 2 >> 1] - sfx[i]) +
2LL * pfx[(i + 2 >> 1) - 1] -
((i - 1) & 1 ? a[(i + 2 >> 1) - 1] : l - a[i + 2 >> 1]));
return printf("%lld", max(ans, (long long)max(a[n], l - a[1]))), 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int nmax = 2e3 + 4;
long long l, n;
long long x[nmax];
long long ac[nmax];
long long solve(bool right, int s) {
long long ans;
if (right) {
if (!((n - s) & 1)) {
ans = 2 * (-ac[s - 1] + ac[(s + n) / 2 - 1] + ac[(s + n) / 2] - ac[n]) +
x[(s + n) / 2] + (n - s) * l;
} else {
ans = 2 * (-ac[s - 1] + ac[(s + n) / 2] + ac[(s + n) / 2 + 1] - ac[n]) -
x[(s + n) / 2 + 1] + (n - s) * l;
}
} else {
if (!(s & 1)) {
ans = 2 * (ac[s / 2 - 1] + ac[s / 2] - ac[s]) + x[s / 2] + s * l;
} else {
ans = 2 * (ac[s / 2] + ac[s / 2 + 1] - ac[s]) - x[(s + 1) / 2] + s * l;
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> l >> n;
ac[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> x[i];
ac[i] = ac[i - 1] + x[i];
}
long long maxv = 0;
for (int start = 1; start <= n; start++) {
for (int right = 0; right < 2; right++) {
maxv = max(maxv, solve((bool)right, start));
}
}
cout << maxv << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5 + 4;
long long l, n;
long long x[nmax];
long long ac[nmax];
long long solve(bool right, int s) {
long long ans;
if (right) {
if (!((n - s) & 1)) {
ans = 2 * (-ac[s - 1] + ac[(s + n) / 2 - 1] + ac[(s + n) / 2] - ac[n]) +
x[(s + n) / 2] + (n - s) * l;
} else {
ans = 2 * (-ac[s - 1] + ac[(s + n) / 2] + ac[(s + n) / 2 + 1] - ac[n]) -
x[(s + n) / 2 + 1] + (n - s) * l;
}
} else {
if (!(s & 1)) {
ans = 2 * (ac[s / 2 - 1] + ac[s / 2] - ac[s]) + x[s / 2] + s * l;
} else {
ans = 2 * (ac[s / 2] + ac[s / 2 + 1] - ac[s]) - x[(s + 1) / 2] + s * l;
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> l >> n;
ac[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> x[i];
ac[i] = ac[i - 1] + x[i];
}
long long maxv = 0;
for (int start = 1; start <= n; start++) {
for (int right = 0; right < 2; right++) {
maxv = max(maxv, solve((bool)right, start));
}
}
cout << maxv << '\n';
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03187 | C++ | Time Limit Exceeded | #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll L, n, a[MAXN], ans;
ll dp[MAXN];
ll go(ll x, ll y, bool dir) {
ll ret;
if (dir)
ret = y - x;
else
ret = x - y;
if (ret < 0)
ret += L;
return ret;
}
ll findans(ll step) {
if (step == n)
return go(0, a[n], true);
else if (step == n - 1)
return go(0, a[n - 1], true) + go(a[n - 1], a[n], false);
if (dp[step] != -1)
return dp[step];
ll st = step, ed = (n - step) / 2;
return findans(step + 2) + 2 * go(0, a[st], true) +
2 * go(a[n - ed + 1], 0, true) +
((n - step) & 1 ? 1 : -1) * (a[n - ed + 1] - a[n - ed]) -
2 * go(a[st + 1], a[n - ed], true);
}
int main() {
scanf("%lld%lld", &L, &n);
for (ll i = 1; i <= n; i++)
scanf("%lld", &a[i]);
memset(dp, -1, sizeof(dp));
ll ans = 0;
for (ll i = 1; i <= n; i++)
ans = max(ans, findans(i));
reverse(a + 1, a + n + 1);
for (ll i = 1; i <= n; i++)
a[i] = L - a[i];
memset(dp, -1, sizeof(dp));
for (ll i = 1; i <= n; i++)
ans = max(ans, findans(i));
printf("%lld\n", ans);
return 0;
}
| #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll L, n, a[MAXN], ans;
ll dp[MAXN];
ll go(ll x, ll y, bool dir) {
ll ret;
if (dir)
ret = y - x;
else
ret = x - y;
if (ret < 0)
ret += L;
return ret;
}
ll findans(ll step) {
if (step == n)
return go(0, a[n], true);
else if (step == n - 1)
return go(0, a[n - 1], true) + go(a[n - 1], a[n], false);
if (dp[step] != -1)
return dp[step];
ll st = step, ed = (n - step) / 2;
return dp[step] = findans(step + 2) + 2 * go(0, a[st], true) +
2 * go(a[n - ed + 1], 0, true) +
((n - step) & 1 ? 1 : -1) * (a[n - ed + 1] - a[n - ed]) -
2 * go(a[st + 1], a[n - ed], true);
}
int main() {
scanf("%lld%lld", &L, &n);
for (ll i = 1; i <= n; i++)
scanf("%lld", &a[i]);
memset(dp, -1, sizeof(dp));
ll ans = 0;
for (ll i = 1; i <= n; i++)
ans = max(ans, findans(i));
reverse(a + 1, a + n + 1);
for (ll i = 1; i <= n; i++)
a[i] = L - a[i];
memset(dp, -1, sizeof(dp));
for (ll i = 1; i <= n; i++)
ans = max(ans, findans(i));
printf("%lld\n", ans);
return 0;
}
| replace | 30 | 34 | 30 | 34 | TLE | |
p03187 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 1e9
#define LINF 1e18
#define ld double
#define ll long long
#define ull unsigned long long
namespace io {
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
char gc() {
if (++pos == buff + SZ)
fread(pos = buff, 1, SZ, stdin);
return *pos;
}
} // namespace io
template <typename T> inline void read(T &x) {
x = 0;
int f = 1, c = io ::gc();
for (; !isdigit(c); c = io ::gc())
if (c == '-')
f = -f;
for (; isdigit(c); c = io ::gc())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= f;
}
const int N = 2005;
int x[N];
int n, L;
ll sum[N];
ll ans;
void solve() {
for (int i = 1; i <= n + n; ++i)
sum[i] = sum[i - 1] + x[i];
if (L - x[1] > ans)
ans = L - x[1];
if (x[n + n] - L > ans)
ans = x[n + n] - L;
for (int i = 2; i <= n; ++i) {
int j = i + n - 1;
int ed = j - n + i;
// printf("%d %d %d: ", i, j, ed);
ll cur = 2 * (sum[j] - sum[n]) -
(2 * (sum[ed - 1] - sum[i]) + x[i] + x[ed]) + abs(L - x[ed]);
// printf("%lld\n", cur);
if (cur > ans)
ans = cur;
}
}
int main() {
read(L);
read(n);
for (int i = 1; i <= n; ++i)
read(x[i]);
for (int i = n + 1; i <= n + n; ++i)
x[i] = x[i - n] + L;
solve();
reverse(x + 1, x + n + n + 1);
for (int i = 1; i <= n + n; ++i)
x[i] = L + L - x[i];
solve();
printf("%lld\n", ans);
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 1e9
#define LINF 1e18
#define ld double
#define ll long long
#define ull unsigned long long
namespace io {
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
char gc() {
if (++pos == buff + SZ)
fread(pos = buff, 1, SZ, stdin);
return *pos;
}
} // namespace io
template <typename T> inline void read(T &x) {
x = 0;
int f = 1, c = io ::gc();
for (; !isdigit(c); c = io ::gc())
if (c == '-')
f = -f;
for (; isdigit(c); c = io ::gc())
x = (x << 3) + (x << 1) + (c ^ 48);
x *= f;
}
const int N = 400005;
int x[N];
int n, L;
ll sum[N];
ll ans;
void solve() {
for (int i = 1; i <= n + n; ++i)
sum[i] = sum[i - 1] + x[i];
if (L - x[1] > ans)
ans = L - x[1];
if (x[n + n] - L > ans)
ans = x[n + n] - L;
for (int i = 2; i <= n; ++i) {
int j = i + n - 1;
int ed = j - n + i;
// printf("%d %d %d: ", i, j, ed);
ll cur = 2 * (sum[j] - sum[n]) -
(2 * (sum[ed - 1] - sum[i]) + x[i] + x[ed]) + abs(L - x[ed]);
// printf("%lld\n", cur);
if (cur > ans)
ans = cur;
}
}
int main() {
read(L);
read(n);
for (int i = 1; i <= n; ++i)
read(x[i]);
for (int i = n + 1; i <= n + n; ++i)
x[i] = x[i - n] + L;
solve();
reverse(x + 1, x + n + n + 1);
for (int i = 1; i <= n + n; ++i)
x[i] = L + L - x[i];
solve();
printf("%lld\n", ans);
return 0;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
const int N = 101000;
ll L, s[N], t[N];
int n, l[N];
ll dist(ll a, ll b) {
if (a > b)
swap(a, b);
return max(b - a, L - (b - a));
}
ll gao1(int l, int r) { return s[min(r, n)] - s[max(l - 1, 0)]; }
ll gao2(int l, int r) { return t[min(r, n)] - t[max(l - 1, 0)]; }
int main() {
scanf("%lld%d", &L, &n);
for (int i = 1; i <= n; i++)
scanf("%d", l + i), s[i] = s[i - 1] + l[i], t[i] = t[i - 1] + L - l[i];
if (n == 1) {
printf("%lld\n", dist(0, l[1]));
return 0;
}
ll ans = 0;
for (int s = 1; s <= n; s++) {
int fl = s - 1, r = n - s;
if (fl > 0) {
// ting zai s-1
int len = min(fl - 1, r);
ll w = 2 * (gao1(s - len - 1, s - 1) + gao2(s + 1, s + len)) - l[s - 1] +
dist(l[s - 1], l[s]);
ans = max(ans, w);
len = min(fl, r);
w = 2 * (gao1(s - len, s - 1) + gao2(s + 1, s + len)) - l[s - 1] +
dist(l[s - 1], l[s]);
ans = max(ans, w);
}
if (r > 0) {
int len = min(r - 1, fl);
ll w = 2 * (gao2(s + 1, s + len + 1) + gao1(s - len, s - 1)) -
(L - l[s + 1]) + dist(l[s], l[s + 1]);
ans = max(ans, w);
// printf("%d %d %d %d %lld\n",s,s+1,len,len+1,w);
len = min(r, fl);
w = 2 * (gao2(s + 1, s + len) + gao1(s - len, s - 1)) - (L - l[s + 1]) +
dist(l[s], l[s + 1]);
ans = max(ans, w);
// printf("%d %d %d %d %lld\n",s,s+1,len,len,w);
}
}
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head
const int N = 501000;
ll L, s[N], t[N];
int n, l[N];
ll dist(ll a, ll b) {
if (a > b)
swap(a, b);
return max(b - a, L - (b - a));
}
ll gao1(int l, int r) { return s[min(r, n)] - s[max(l - 1, 0)]; }
ll gao2(int l, int r) { return t[min(r, n)] - t[max(l - 1, 0)]; }
int main() {
scanf("%lld%d", &L, &n);
for (int i = 1; i <= n; i++)
scanf("%d", l + i), s[i] = s[i - 1] + l[i], t[i] = t[i - 1] + L - l[i];
if (n == 1) {
printf("%lld\n", dist(0, l[1]));
return 0;
}
ll ans = 0;
for (int s = 1; s <= n; s++) {
int fl = s - 1, r = n - s;
if (fl > 0) {
// ting zai s-1
int len = min(fl - 1, r);
ll w = 2 * (gao1(s - len - 1, s - 1) + gao2(s + 1, s + len)) - l[s - 1] +
dist(l[s - 1], l[s]);
ans = max(ans, w);
len = min(fl, r);
w = 2 * (gao1(s - len, s - 1) + gao2(s + 1, s + len)) - l[s - 1] +
dist(l[s - 1], l[s]);
ans = max(ans, w);
}
if (r > 0) {
int len = min(r - 1, fl);
ll w = 2 * (gao2(s + 1, s + len + 1) + gao1(s - len, s - 1)) -
(L - l[s + 1]) + dist(l[s], l[s + 1]);
ans = max(ans, w);
// printf("%d %d %d %d %lld\n",s,s+1,len,len+1,w);
len = min(r, fl);
w = 2 * (gao2(s + 1, s + len) + gao1(s - len, s - 1)) - (L - l[s + 1]) +
dist(l[s], l[s + 1]);
ans = max(ans, w);
// printf("%d %d %d %d %lld\n",s,s+1,len,len,w);
}
}
printf("%lld\n", ans);
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03187 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define inf 1050000000
#define infll 1050000000000000000ll
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mpr make_pair
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define ad(x, y) (x = (x + (y)) % mod)
#define up(x, y) (x < (y) ? x = (y) : 0)
#define dn(x, y) (x > (y) ? x = (y) : 0)
#define N 200009
using namespace std;
int n;
ll m, a[N], s[N];
ll calc(int x, int y) {
if (x > y)
return 0;
return s[y] - s[x - 1];
}
int main() {
scanf("%lld%d", &m, &n);
int i, tmp;
ll ans = 0;
for (i = 1; i <= n; i++)
scanf("%lld", &a[i]);
a[n + 1] = m;
for (i = n + 2; i <= n * 2 + 1; i++)
a[i] = a[i - n - 1] + m;
for (i = 1; i <= n * 2 + 1; i++)
s[i] = s[i - 1] + a[i];
// for (i=1; i<=n*2+1; i++) cerr<<a[i]<<' ';cerr<<'\n';
for (i = 1; i <= n; i++) {
if (i == 1)
ans = max(a[1], m - a[1]);
else {
tmp = min(i - 1, n - i + 1);
ans = max(ans, -a[i] - a[i + tmp] - 2 * calc(i + 1, i + tmp - 1) +
2 * calc(n + i - tmp + 1, n + i));
// cerr<<i<<' '<<tmp<<'\n';
tmp = min(i, n - i + 1);
ans = max(ans, -a[i] - 2 * calc(i + 1, i + tmp - 1) + a[n + i - tmp + 1] +
2 * calc(n + i - tmp + 2, n + i));
}
}
cerr << "ans:" << ans << '\n';
for (i = 1; i <= n; i++)
a[i] = m - a[i];
sort(a + 1, a + n + 1);
a[n + 1] = m;
for (i = n + 2; i <= n * 2 + 1; i++)
a[i] = a[i - n - 1] + m;
for (i = 1; i <= n * 2 + 1; i++)
s[i] = s[i - 1] + a[i];
// for (i=1; i<=n*2+1; i++) cerr<<a[i]<<' ';cerr<<'\n';
for (i = 1; i <= n; i++) {
if (i == 1)
ans = max(max(ans, a[1]), m - a[1]);
else {
tmp = min(i - 1, n - i + 1);
ans = max(ans, -a[i] - a[i + tmp] - 2 * calc(i + 1, i + tmp - 1) +
2 * calc(n + i - tmp + 1, n + i));
tmp = min(i, n - i + 1);
ans = max(ans, -a[i] - 2 * calc(i + 1, i + tmp - 1) + a[n + i - tmp + 1] +
2 * calc(n + i - tmp + 2, n + i));
}
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define inf 1050000000
#define infll 1050000000000000000ll
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mpr make_pair
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define ad(x, y) (x = (x + (y)) % mod)
#define up(x, y) (x < (y) ? x = (y) : 0)
#define dn(x, y) (x > (y) ? x = (y) : 0)
#define N 2000009
using namespace std;
int n;
ll m, a[N], s[N];
ll calc(int x, int y) {
if (x > y)
return 0;
return s[y] - s[x - 1];
}
int main() {
scanf("%lld%d", &m, &n);
int i, tmp;
ll ans = 0;
for (i = 1; i <= n; i++)
scanf("%lld", &a[i]);
a[n + 1] = m;
for (i = n + 2; i <= n * 2 + 1; i++)
a[i] = a[i - n - 1] + m;
for (i = 1; i <= n * 2 + 1; i++)
s[i] = s[i - 1] + a[i];
// for (i=1; i<=n*2+1; i++) cerr<<a[i]<<' ';cerr<<'\n';
for (i = 1; i <= n; i++) {
if (i == 1)
ans = max(a[1], m - a[1]);
else {
tmp = min(i - 1, n - i + 1);
ans = max(ans, -a[i] - a[i + tmp] - 2 * calc(i + 1, i + tmp - 1) +
2 * calc(n + i - tmp + 1, n + i));
// cerr<<i<<' '<<tmp<<'\n';
tmp = min(i, n - i + 1);
ans = max(ans, -a[i] - 2 * calc(i + 1, i + tmp - 1) + a[n + i - tmp + 1] +
2 * calc(n + i - tmp + 2, n + i));
}
}
cerr << "ans:" << ans << '\n';
for (i = 1; i <= n; i++)
a[i] = m - a[i];
sort(a + 1, a + n + 1);
a[n + 1] = m;
for (i = n + 2; i <= n * 2 + 1; i++)
a[i] = a[i - n - 1] + m;
for (i = 1; i <= n * 2 + 1; i++)
s[i] = s[i - 1] + a[i];
// for (i=1; i<=n*2+1; i++) cerr<<a[i]<<' ';cerr<<'\n';
for (i = 1; i <= n; i++) {
if (i == 1)
ans = max(max(ans, a[1]), m - a[1]);
else {
tmp = min(i - 1, n - i + 1);
ans = max(ans, -a[i] - a[i + tmp] - 2 * calc(i + 1, i + tmp - 1) +
2 * calc(n + i - tmp + 1, n + i));
tmp = min(i, n - i + 1);
ans = max(ans, -a[i] - 2 * calc(i + 1, i + tmp - 1) + a[n + i - tmp + 1] +
2 * calc(n + i - tmp + 2, n + i));
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | ans:15
|
p03187 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;
long long X[100000];
long long cum_sum_x[100000];
long long reverse_cum_sum_x[100000];
int main() {
long long L;
int N;
cin >> L >> N;
for (int i = 0; i < N; i++) {
cin >> X[i];
}
cum_sum_x[0] = X[0];
for (int i = 1; i < N; i++) {
cum_sum_x[i] = cum_sum_x[i - 1] + X[i];
}
reverse_cum_sum_x[N - 1] = L - X[N - 1];
for (int i = N - 2; i >= 0; i--) {
reverse_cum_sum_x[i] = reverse_cum_sum_x[i + 1] + (L - X[i]);
}
long long ans = 0;
// no turnaround
ans = max(ans, X[N - 1]);
ans = max(ans, L - X[0]);
for (int i = 0; i < N - 1; i++) {
int till = i + (N - (i + 1)) / 2;
int reverse_till = till + 1;
long long tmp_ans = 2 * X[i] + 2 * (cum_sum_x[till] - cum_sum_x[i] +
reverse_cum_sum_x[reverse_till]);
if ((N - (i + 1)) % 2 == 0) {
tmp_ans -= X[till];
} else {
tmp_ans -= (L - X[reverse_till]);
}
ans = max(ans, tmp_ans);
// cout << i << " " << till << " " << reverse_till << endl;
// cout << tmp_ans << endl;
}
for (int i = N - 1; i > 0; i--) {
int reverse_till = i - i / 2;
int till = reverse_till - 1;
long long tmp_ans =
2 * (L - X[i]) + 2 * (reverse_cum_sum_x[reverse_till] -
reverse_cum_sum_x[i] + cum_sum_x[till]);
if (i % 2 == 0) {
tmp_ans -= (L - X[reverse_till]);
} else {
tmp_ans -= X[till];
}
ans = max(ans, tmp_ans);
// cout << i << " " << reverse_till << " " << till << endl;
// cout << tmp_ans << endl;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;
long long X[200000];
long long cum_sum_x[200000];
long long reverse_cum_sum_x[200000];
int main() {
long long L;
int N;
cin >> L >> N;
for (int i = 0; i < N; i++) {
cin >> X[i];
}
cum_sum_x[0] = X[0];
for (int i = 1; i < N; i++) {
cum_sum_x[i] = cum_sum_x[i - 1] + X[i];
}
reverse_cum_sum_x[N - 1] = L - X[N - 1];
for (int i = N - 2; i >= 0; i--) {
reverse_cum_sum_x[i] = reverse_cum_sum_x[i + 1] + (L - X[i]);
}
long long ans = 0;
// no turnaround
ans = max(ans, X[N - 1]);
ans = max(ans, L - X[0]);
for (int i = 0; i < N - 1; i++) {
int till = i + (N - (i + 1)) / 2;
int reverse_till = till + 1;
long long tmp_ans = 2 * X[i] + 2 * (cum_sum_x[till] - cum_sum_x[i] +
reverse_cum_sum_x[reverse_till]);
if ((N - (i + 1)) % 2 == 0) {
tmp_ans -= X[till];
} else {
tmp_ans -= (L - X[reverse_till]);
}
ans = max(ans, tmp_ans);
// cout << i << " " << till << " " << reverse_till << endl;
// cout << tmp_ans << endl;
}
for (int i = N - 1; i > 0; i--) {
int reverse_till = i - i / 2;
int till = reverse_till - 1;
long long tmp_ans =
2 * (L - X[i]) + 2 * (reverse_cum_sum_x[reverse_till] -
reverse_cum_sum_x[i] + cum_sum_x[till]);
if (i % 2 == 0) {
tmp_ans -= (L - X[reverse_till]);
} else {
tmp_ans -= X[till];
}
ans = max(ans, tmp_ans);
// cout << i << " " << reverse_till << " " << till << endl;
// cout << tmp_ans << endl;
}
cout << ans << endl;
return 0;
}
| replace | 14 | 17 | 14 | 17 | 0 | |
p03188 | C++ | Runtime Error | #include <bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed << setprecision(x)
#define pii pair<int, int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen() {
freopen(title ".in", "r", stdin);
freopen(title ".out", "w", stdout);
}
int read() {
int g = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-')
f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
g = g * 10 + ch - '0';
ch = getchar();
}
return g * f;
}
const int N = 505;
const int maxn = 500;
int k;
namespace solve1 {
void Main() {
cout << k << '\n';
for (int i = 1; i <= k; i++, cout << '\n')
for (int j = 1; j <= k; j++, cout << ' ')
cout << i;
}
} // namespace solve1
namespace solve2 {
int a[N][N];
void Main() {
cout << maxn << '\n';
for (int i = 1; i <= maxn; i++)
for (int j = 1; j <= maxn; j++)
a[i][j] = (i + j - 2) % maxn + 1;
for (int i = maxn + 1; i <= k; i++)
for (int j = 1; j <= maxn; j += 2) {
int x = i - maxn - 1 + j, y = (i - x) % maxn + 1;
a[x][y] = i;
}
for (int i = 1; i <= maxn; i++, cout << '\n')
for (int j = 1; j <= maxn; j++, cout << ' ')
cout << a[i][j];
}
} // namespace solve2
signed main() {
k = read();
if (k <= 500)
solve1::Main();
else
solve2::Main();
return signed();
} | #include <bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed << setprecision(x)
#define pii pair<int, int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen() {
freopen(title ".in", "r", stdin);
freopen(title ".out", "w", stdout);
}
int read() {
int g = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-')
f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
g = g * 10 + ch - '0';
ch = getchar();
}
return g * f;
}
const int N = 505;
const int maxn = 500;
int k;
namespace solve1 {
void Main() {
cout << k << '\n';
for (int i = 1; i <= k; i++, cout << '\n')
for (int j = 1; j <= k; j++, cout << ' ')
cout << i;
}
} // namespace solve1
namespace solve2 {
int a[N][N];
void Main() {
cout << maxn << '\n';
for (int i = 1; i <= maxn; i++)
for (int j = 1; j <= maxn; j++)
a[i][j] = (i + j - 2) % maxn + 1;
for (int i = maxn + 1; i <= k; i++)
for (int j = 1; j <= maxn; j += 2) {
int x = (i - maxn - 2 + j) % maxn + 1, y = (i - x) % maxn + 1;
a[x][y] = i;
}
for (int i = 1; i <= maxn; i++, cout << '\n')
for (int j = 1; j <= maxn; j++, cout << ' ')
cout << a[i][j];
}
} // namespace solve2
signed main() {
k = read();
if (k <= 500)
solve1::Main();
else
solve2::Main();
return signed();
} | replace | 47 | 48 | 47 | 48 | 0 | |
p03188 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
int X[500][500];
int C;
cin >> C;
int K = 2 * (C + 3) / 4;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
if (i % 2 == 0)
X[i][j] = (i + j) % K;
else
X[i][j] = K + (i + j) % K;
}
}
cout << K << endl;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
++X[i][j];
if (X[i][j] > C)
X[i][j] -= K;
cout << X[i][j] << " ";
}
cout << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
int X[500][500];
int C;
cin >> C;
if (C == 1) {
cout << 1 << endl;
cout << 1 << endl;
return 0;
}
int K = 2 * ((C + 3) / 4);
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
if (i % 2 == 0)
X[i][j] = (i + j) % K;
else
X[i][j] = K + (i + j) % K;
}
}
cout << K << endl;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
++X[i][j];
if (X[i][j] > C)
X[i][j] -= K;
cout << X[i][j] << " ";
}
cout << endl;
}
}
| replace | 12 | 14 | 12 | 18 | 0 | |
p03188 | C++ | Time Limit Exceeded |
#include <cstdio>
using namespace std;
int K;
int main() {
scanf("%d", &K);
if (K <= 500) {
printf("%d\n", K);
for (int i = 1; i <= K; ++i) {
for (int j = 1; j <= K; ++j)
printf("%d ", i);
printf("\n");
}
} else
while (true)
;
return 0;
} |
#include <cstdio>
using namespace std;
int K;
int main() {
scanf("%d", &K);
if (K <= 500) {
printf("%d\n", K);
for (int i = 1; i <= K; ++i) {
for (int j = 1; j <= K; ++j)
printf("%d ", i);
printf("\n");
}
} else {
int N = ((K / 4) + (K % 4 != 0)) * 2;
printf("%d\n", N);
for (int i = 1; i <= N; ++i) {
for (int j = 1, v; j <= N; ++j) {
v = (i + j) % N + (i & 1) * N + 1;
if (v > K)
v -= N;
printf("%d ", v);
}
printf("\n");
}
}
return 0;
} | replace | 16 | 19 | 16 | 29 | TLE | |
p03188 | C++ | Runtime Error | #include <cstdio>
int main() {
int K;
scanf("%d", &K);
if (K % 2 == 0) {
printf("%d\n", K / 2);
for (int i = 1; i <= K / 2; ++i)
for (int j = 1; j <= K / 2; ++j)
printf("%d%c", (i % 2 == 1 ? 0 : K / 2) + j, " \n"[j == K / 2]);
} else
return 1;
}
| #include <cstdio>
int main() {
int K;
scanf("%d", &K);
if (K == 1)
return !puts("1\n1");
int n = (K + 3) / 4 * 2;
printf("%d\n", n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
printf("%d%c", (i % 2 && n + (i + j) % n < K ? n : 0) + (i + j) % n + 1,
" \n"[j + 1 == n]);
}
| replace | 5 | 12 | 5 | 13 | 0 | |
p03189 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int INV2 = (MOD + 1) / 2;
int dp[2005][2005];
int n, p[2005];
PII pinv[2005];
int m, u[2005], v[2005];
int cdp[2005];
int main() {
scanf("%d%d", &n, &m);
rep1(i, n) scanf("%d", &p[i]);
rep(i, m) scanf("%d%d", &u[i], &v[i]);
rep1(i, n) dp[i][i] = 1;
rep(i, m) rep1(j, n) {
int cur = 1LL * (dp[j][u[i]] + dp[j][v[i]]) * INV2 % MOD;
dp[j][u[i]] = dp[j][v[i]] = cur;
}
rep1(i, n) pinv[i] = MP(p[i], i);
sort(pinv + 1, pinv + n + 1);
int ans = 0;
rep1(i, n) {
int tot = 0;
for (int j = n; j >= 1; j--) {
ans = (ans +
1LL * (tot + 1LL * cdp[j] * INV2 % MOD) * dp[pinv[i].second][j]) %
MOD;
tot = (tot + cdp[j]) % MOD;
}
if (i == n || pinv[i].first != pinv[i + 1].first)
for (int i0 = i; i0 >= 0 && pinv[i0].first == pinv[i].first; i0--)
rep1(j, n) cdp[j] = (cdp[j] + dp[pinv[i0].second][j]) % MOD;
}
rep(i, m) ans = ans * 2 % MOD;
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int INV2 = (MOD + 1) / 2;
int dp[3005][3005];
int n, p[3005];
PII pinv[3005];
int m, u[3005], v[3005];
int cdp[3005];
int main() {
scanf("%d%d", &n, &m);
rep1(i, n) scanf("%d", &p[i]);
rep(i, m) scanf("%d%d", &u[i], &v[i]);
rep1(i, n) dp[i][i] = 1;
rep(i, m) rep1(j, n) {
int cur = 1LL * (dp[j][u[i]] + dp[j][v[i]]) * INV2 % MOD;
dp[j][u[i]] = dp[j][v[i]] = cur;
}
rep1(i, n) pinv[i] = MP(p[i], i);
sort(pinv + 1, pinv + n + 1);
int ans = 0;
rep1(i, n) {
int tot = 0;
for (int j = n; j >= 1; j--) {
ans = (ans +
1LL * (tot + 1LL * cdp[j] * INV2 % MOD) * dp[pinv[i].second][j]) %
MOD;
tot = (tot + cdp[j]) % MOD;
}
if (i == n || pinv[i].first != pinv[i + 1].first)
for (int i0 = i; i0 >= 0 && pinv[i0].first == pinv[i].first; i0--)
rep1(j, n) cdp[j] = (cdp[j] + dp[pinv[i0].second][j]) % MOD;
}
rep(i, m) ans = ans * 2 % MOD;
printf("%d\n", ans);
return 0;
} | replace | 11 | 16 | 11 | 16 | 0 | |
p03189 | C++ | Runtime Error | /* --- author: dxm --- */
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define INF 1e9
#define Inf 1e18
#define rep(i, n) for (int(i) = 0; (i) < n; i++)
#define REP(i, n) for (int(i) = 1; (i) <= n; i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
void qread(int &x) {
int neg = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
neg = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = 10 * x + c - '0', c = getchar();
x *= neg;
}
const int maxn = 2005;
const int mod = 1e9 + 7;
const int inv = (mod + 1) / 2;
int n, q;
int a[maxn], dp[maxn][maxn];
int main() {
#ifdef FILE
freopen("FILE.in", "r", stdin);
freopen("FILE.out", "w", stdout);
#endif
scanf("%d%d", &n, &q);
REP(i, n) scanf("%d", &a[i]);
REP(i, n) REP(j, n) if (a[i] > a[j]) dp[i][j] = 1;
REP(i, q) {
int x, y;
scanf("%d%d", &x, &y);
REP(j, n) {
if (j == x || j == y)
continue;
int sum = 1LL * (dp[j][x] + dp[j][y]) * inv % mod;
dp[j][x] = dp[j][y] = sum;
sum = 1LL * (dp[x][j] + dp[y][j]) * inv % mod;
dp[x][j] = dp[y][j] = sum;
}
int sum = 1LL * (dp[x][y] + dp[y][x]) * inv % mod;
dp[x][y] = dp[y][x] = sum;
}
int ans = 0;
REP(j, n) for (int k = j + 1; k <= n; k++) ans = (ans + dp[j][k]) % mod;
REP(i, q) ans = 2LL * ans % mod;
printf("%d\n", ans);
#ifdef TIME
printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC));
#endif
return 0;
}
/*
Input:
-----------------
Output:
*/
| /* --- author: dxm --- */
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define INF 1e9
#define Inf 1e18
#define rep(i, n) for (int(i) = 0; (i) < n; i++)
#define REP(i, n) for (int(i) = 1; (i) <= n; i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
void qread(int &x) {
int neg = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
neg = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = 10 * x + c - '0', c = getchar();
x *= neg;
}
const int maxn = 3005;
const int mod = 1e9 + 7;
const int inv = (mod + 1) / 2;
int n, q;
int a[maxn], dp[maxn][maxn];
int main() {
#ifdef FILE
freopen("FILE.in", "r", stdin);
freopen("FILE.out", "w", stdout);
#endif
scanf("%d%d", &n, &q);
REP(i, n) scanf("%d", &a[i]);
REP(i, n) REP(j, n) if (a[i] > a[j]) dp[i][j] = 1;
REP(i, q) {
int x, y;
scanf("%d%d", &x, &y);
REP(j, n) {
if (j == x || j == y)
continue;
int sum = 1LL * (dp[j][x] + dp[j][y]) * inv % mod;
dp[j][x] = dp[j][y] = sum;
sum = 1LL * (dp[x][j] + dp[y][j]) * inv % mod;
dp[x][j] = dp[y][j] = sum;
}
int sum = 1LL * (dp[x][y] + dp[y][x]) * inv % mod;
dp[x][y] = dp[y][x] = sum;
}
int ans = 0;
REP(j, n) for (int k = j + 1; k <= n; k++) ans = (ans + dp[j][k]) % mod;
REP(i, q) ans = 2LL * ans % mod;
printf("%d\n", ans);
#ifdef TIME
printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC));
#endif
return 0;
}
/*
Input:
-----------------
Output:
*/
| replace | 35 | 36 | 35 | 36 | 0 | |
p03189 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) \
{ \
freopen(#x ".in", "r", stdin); \
freopen(#x ".out", "w", stdout); \
}
#define Edg \
int M = 0, fst[SZ], vb[SZ], nxt[SZ]; \
void ad_de(int a, int b) { \
++M; \
nxt[M] = fst[a]; \
fst[a] = M; \
vb[M] = b; \
} \
void adde(int a, int b) { \
ad_de(a, b); \
ad_de(b, a); \
}
#define Edgc \
int M = 0, fst[SZ], vb[SZ], nxt[SZ], vc[SZ]; \
void ad_de(int a, int b, int c) { \
++M; \
nxt[M] = fst[a]; \
fst[a] = M; \
vb[M] = b; \
vc[M] = c; \
} \
void adde(int a, int b, int c) { \
ad_de(a, b, c); \
ad_de(b, a, c); \
}
#define es(x, e) (int e = fst[x]; e; e = nxt[e])
#define esb(x, e, b) (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
#define SZ 666666
const int MOD = 1e9 + 7;
ll r2 = (MOD + 1) / 2;
int n, a[SZ], m, p[SZ], q[SZ], f[2333][2333];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= m; ++i)
cin >> p[i] >> q[i];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j)
f[i][j] = (a[i] > a[j]);
ll ans = 0;
for (int i = 1; i <= m; ++i) {
int u = (f[p[i]][q[i]] + f[q[i]][p[i]]) % MOD * r2 % MOD;
f[p[i]][q[i]] = f[q[i]][p[i]] = u;
for (int t = 1; t <= n; ++t) {
if (t != p[i] && t != q[i])
;
else
continue;
int u = (f[t][p[i]] + f[t][q[i]]) % MOD * r2 % MOD;
f[t][p[i]] = f[t][q[i]] = u;
u = (f[p[i]][t] + f[q[i]][t]) % MOD * r2 % MOD;
f[p[i]][t] = f[q[i]][t] = u;
}
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
(ans += f[i][j]) %= MOD;
for (int j = 1; j <= m; ++j)
ans = ans * 2LL % MOD;
ans = (ans % MOD + MOD) % MOD;
cout << ans << "\n";
}
| #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) \
{ \
freopen(#x ".in", "r", stdin); \
freopen(#x ".out", "w", stdout); \
}
#define Edg \
int M = 0, fst[SZ], vb[SZ], nxt[SZ]; \
void ad_de(int a, int b) { \
++M; \
nxt[M] = fst[a]; \
fst[a] = M; \
vb[M] = b; \
} \
void adde(int a, int b) { \
ad_de(a, b); \
ad_de(b, a); \
}
#define Edgc \
int M = 0, fst[SZ], vb[SZ], nxt[SZ], vc[SZ]; \
void ad_de(int a, int b, int c) { \
++M; \
nxt[M] = fst[a]; \
fst[a] = M; \
vb[M] = b; \
vc[M] = c; \
} \
void adde(int a, int b, int c) { \
ad_de(a, b, c); \
ad_de(b, a, c); \
}
#define es(x, e) (int e = fst[x]; e; e = nxt[e])
#define esb(x, e, b) (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
#define SZ 666666
const int MOD = 1e9 + 7;
ll r2 = (MOD + 1) / 2;
int n, a[SZ], m, p[SZ], q[SZ], f[3333][3333];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= m; ++i)
cin >> p[i] >> q[i];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (i != j)
f[i][j] = (a[i] > a[j]);
ll ans = 0;
for (int i = 1; i <= m; ++i) {
int u = (f[p[i]][q[i]] + f[q[i]][p[i]]) % MOD * r2 % MOD;
f[p[i]][q[i]] = f[q[i]][p[i]] = u;
for (int t = 1; t <= n; ++t) {
if (t != p[i] && t != q[i])
;
else
continue;
int u = (f[t][p[i]] + f[t][q[i]]) % MOD * r2 % MOD;
f[t][p[i]] = f[t][q[i]] = u;
u = (f[p[i]][t] + f[q[i]][t]) % MOD * r2 % MOD;
f[p[i]][t] = f[q[i]][t] = u;
}
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
(ans += f[i][j]) %= MOD;
for (int j = 1; j <= m; ++j)
ans = ans * 2LL % MOD;
ans = (ans % MOD + MOD) % MOD;
cout << ans << "\n";
}
| replace | 61 | 62 | 61 | 62 | 0 | |
p03189 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 1010
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int inv2 = 500000004;
char *p1, *p2, buf[100000];
#define nc() \
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) \
? EOF \
: *p1++)
int rd() {
int x = 0, f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
}
int a[N], f[N][N];
int main() {
int n = rd(), q = rd(), mdl = 1;
for (int i = 1; i <= n; i++) {
a[i] = rd();
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i] < a[j]) {
f[i][j] = 1;
}
}
}
for (int i = 1; i <= q; i++) {
mdl = (ll)mdl * 2 % mod;
int x = rd(), y = rd();
f[x][y] = f[y][x] = ((ll)f[x][y] + f[y][x]) * inv2 % mod;
for (int j = 1; j <= n; j++) {
if (j != x && j != y) {
f[x][j] = f[y][j] = ((ll)f[x][j] + f[y][j]) * inv2 % mod;
f[j][x] = f[j][y] = ((ll)f[j][x] + f[j][y]) * inv2 % mod;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
(ans += f[i][j]) %= mod;
}
}
ans = (ll)ans * mdl % mod, (ans += mod) %= mod;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define N 3010
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int inv2 = 500000004;
char *p1, *p2, buf[100000];
#define nc() \
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) \
? EOF \
: *p1++)
int rd() {
int x = 0, f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
}
int a[N], f[N][N];
int main() {
int n = rd(), q = rd(), mdl = 1;
for (int i = 1; i <= n; i++) {
a[i] = rd();
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i] < a[j]) {
f[i][j] = 1;
}
}
}
for (int i = 1; i <= q; i++) {
mdl = (ll)mdl * 2 % mod;
int x = rd(), y = rd();
f[x][y] = f[y][x] = ((ll)f[x][y] + f[y][x]) * inv2 % mod;
for (int j = 1; j <= n; j++) {
if (j != x && j != y) {
f[x][j] = f[y][j] = ((ll)f[x][j] + f[y][j]) * inv2 % mod;
f[j][x] = f[j][y] = ((ll)f[j][x] + f[j][y]) * inv2 % mod;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
(ans += f[i][j]) %= mod;
}
}
ans = (ll)ans * mdl % mod, (ans += mod) %= mod;
cout << ans << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03189 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#define MAX_N 105
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll mpow(ll x, ll n) {
ll ret = 1;
while (n > 0) {
if ((n & 1) == 1) {
ret *= x;
ret %= mod;
}
x = (x * x) % mod;
n >>= 1;
}
return ret % mod;
}
ll inv(ll x) { return mpow(x, mod - 2); }
int main() {
int N, Q;
ll A[MAX_N];
ll dp[2][MAX_N][MAX_N];
cin >> N >> Q;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll _2q = mpow(2, Q);
ll inv2 = inv(2);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j]) {
dp[0][i][j] = dp[1][i][j] = 1;
} else {
dp[0][i][j] = dp[1][i][j] = 0;
}
}
}
for (int qqq = 0; qqq < Q; qqq++) {
int x, y;
cin >> x >> y;
x--, y--;
for (int i = 0; i < N; i++) {
if (i != x && i != y) {
dp[1][x][i] = (dp[0][x][i] * inv2 + dp[0][y][i] * inv2) % mod;
dp[1][i][x] = (dp[0][i][x] * inv2 + dp[0][i][y] * inv2) % mod;
dp[1][y][i] = (dp[0][y][i] * inv2 + dp[0][x][i] * inv2) % mod;
dp[1][i][y] = (dp[0][i][y] * inv2 + dp[0][i][x] * inv2) % mod;
}
}
dp[1][x][y] = dp[1][y][x] = (dp[0][x][y] * inv2 + dp[0][y][x] * inv2) % mod;
for (int i = 0; i < N; i++) {
dp[0][i][x] = dp[1][i][x];
dp[0][i][y] = dp[1][i][y];
dp[0][x][i] = dp[1][x][i];
dp[0][y][i] = dp[1][y][i];
}
}
ll ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
ans += dp[0][i][j];
ans %= mod;
// cout<<(_2q*dp[0][i][j])%mod<<" ";
}
// cout<<endl;
}
cout << (ans * _2q) % mod << endl;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#define MAX_N 3005
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll mpow(ll x, ll n) {
ll ret = 1;
while (n > 0) {
if ((n & 1) == 1) {
ret *= x;
ret %= mod;
}
x = (x * x) % mod;
n >>= 1;
}
return ret % mod;
}
ll inv(ll x) { return mpow(x, mod - 2); }
int main() {
int N, Q;
ll A[MAX_N];
ll dp[2][MAX_N][MAX_N];
cin >> N >> Q;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll _2q = mpow(2, Q);
ll inv2 = inv(2);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (A[i] > A[j]) {
dp[0][i][j] = dp[1][i][j] = 1;
} else {
dp[0][i][j] = dp[1][i][j] = 0;
}
}
}
for (int qqq = 0; qqq < Q; qqq++) {
int x, y;
cin >> x >> y;
x--, y--;
for (int i = 0; i < N; i++) {
if (i != x && i != y) {
dp[1][x][i] = (dp[0][x][i] * inv2 + dp[0][y][i] * inv2) % mod;
dp[1][i][x] = (dp[0][i][x] * inv2 + dp[0][i][y] * inv2) % mod;
dp[1][y][i] = (dp[0][y][i] * inv2 + dp[0][x][i] * inv2) % mod;
dp[1][i][y] = (dp[0][i][y] * inv2 + dp[0][i][x] * inv2) % mod;
}
}
dp[1][x][y] = dp[1][y][x] = (dp[0][x][y] * inv2 + dp[0][y][x] * inv2) % mod;
for (int i = 0; i < N; i++) {
dp[0][i][x] = dp[1][i][x];
dp[0][i][y] = dp[1][i][y];
dp[0][x][i] = dp[1][x][i];
dp[0][y][i] = dp[1][y][i];
}
}
ll ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
ans += dp[0][i][j];
ans %= mod;
// cout<<(_2q*dp[0][i][j])%mod<<" ";
}
// cout<<endl;
}
cout << (ans * _2q) % mod << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03189 | C++ | Time Limit Exceeded | #include <iostream>
using i64 = long long;
const int N = 3000 + 7;
const i64 MOD = 1000000007;
const i64 Inv2 = MOD - MOD / 2;
int n, q;
int a[N];
i64 f[N][N], g[N][N], ans, coe = 1;
int main() {
// freopen("code.in", "r", stdin);
// freopen("code.out", "w", stdout);
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i)
scanf("%d", a + i);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
f[i][j] = g[i][j] = a[i] > a[j];
for (int x, y; q; --q) {
scanf("%d%d", &x, &y);
for (int i = 1; i <= n; ++i) {
if (i != x)
g[i][x] = (f[i][x] + f[i][y]) * Inv2 % MOD,
g[x][i] = (f[x][i] + f[y][i]) * Inv2 % MOD;
if (i != y)
g[i][y] = (f[i][x] + f[i][y]) * Inv2 % MOD,
g[y][i] = (f[x][i] + f[y][i]) * Inv2 % MOD;
}
g[x][y] = g[y][x] = (f[x][y] + f[y][x]) * Inv2 % MOD;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
f[i][j] = g[i][j];
coe = coe * 2 % MOD;
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
(ans += f[i][j]) %= MOD;
printf("%lld ", ans * coe % MOD);
return 0;
}
| #include <iostream>
using i64 = long long;
const int N = 3000 + 7;
const i64 MOD = 1000000007;
const i64 Inv2 = MOD - MOD / 2;
int n, q;
int a[N];
i64 f[N][N], g[N][N], ans, coe = 1;
int main() {
// freopen("code.in", "r", stdin);
// freopen("code.out", "w", stdout);
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i)
scanf("%d", a + i);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
f[i][j] = g[i][j] = a[i] > a[j];
for (int x, y; q; --q) {
scanf("%d%d", &x, &y);
for (int i = 1; i <= n; ++i) {
if (i != x)
g[i][x] = (f[i][x] + f[i][y]) * Inv2 % MOD,
g[x][i] = (f[x][i] + f[y][i]) * Inv2 % MOD;
if (i != y)
g[i][y] = (f[i][x] + f[i][y]) * Inv2 % MOD,
g[y][i] = (f[x][i] + f[y][i]) * Inv2 % MOD;
}
g[x][y] = g[y][x] = (f[x][y] + f[y][x]) * Inv2 % MOD;
for (int i = 1; i <= n; ++i)
f[i][x] = g[i][x], f[x][i] = g[x][i], f[i][y] = g[i][y],
f[y][i] = g[y][i];
f[x][y] = f[y][x] = g[x][y];
coe = coe * 2 % MOD;
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
(ans += f[i][j]) %= MOD;
printf("%lld ", ans * coe % MOD);
return 0;
}
| replace | 34 | 36 | 34 | 37 | TLE | |
p03189 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
LL powmod(LL a, LL n) {
if (n == 0)
return 1;
if (n % 2)
return (a * powmod(a, n - 1)) % MOD;
LL c = powmod(a, n / 2);
return (c * c) % MOD;
}
LL inv(LL a) { return powmod(a, MOD - 2); }
LL fact[110000];
LL invfact[110000];
LL ncr(LL n, LL r) {
if (r < 0 || n < 0)
return 0;
if (n < r)
return 0;
LL a = fact[n];
a = (a * invfact[r]) % MOD;
a = (a * invfact[n - r]) % MOD;
return a;
}
LL inv2;
void init() {
fact[0] = 1;
invfact[0] = 1;
inv2 = inv(2);
for (LL i = 1; i < 110000; i++) {
fact[i] = (i * fact[i - 1]) % MOD;
invfact[i] = inv(fact[i]);
}
}
LL prob[1000][1000]; // prob i > j
LL temp1[1000][1000];
LL temp2[1000][1000];
int c, d;
int f(int a) {
if (a == c)
return d;
if (a == d)
return c;
return a;
}
int main() {
init();
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j]) {
prob[i][j] = 1;
} else {
prob[i][j] = 0;
}
}
}
for (int i = 0; i < m; i++) {
cin >> c >> d;
c--;
d--;
vector<int> r, s;
for (int j = 0; j < n; j++) {
r.push_back(j);
s.push_back(c);
r.push_back(j);
s.push_back(d);
r.push_back(c);
s.push_back(j);
r.push_back(d);
s.push_back(j);
}
for (int j = 0; j < r.size(); j++) {
int u = r[j];
int v = s[j];
temp1[u][v] = prob[u][v];
temp2[u][v] = prob[f(u)][f(v)];
}
for (int j = 0; j < r.size(); j++) {
int u = r[j];
int v = s[j];
prob[u][v] = (temp1[u][v] + temp2[u][v]) * inv2;
prob[u][v] %= MOD;
}
}
LL ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i < j) {
ans += prob[i][j];
ans %= MOD;
}
}
}
ans = ans * powmod(2, m);
ans %= MOD;
if (ans < 0)
ans += MOD;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
LL powmod(LL a, LL n) {
if (n == 0)
return 1;
if (n % 2)
return (a * powmod(a, n - 1)) % MOD;
LL c = powmod(a, n / 2);
return (c * c) % MOD;
}
LL inv(LL a) { return powmod(a, MOD - 2); }
LL fact[110000];
LL invfact[110000];
LL ncr(LL n, LL r) {
if (r < 0 || n < 0)
return 0;
if (n < r)
return 0;
LL a = fact[n];
a = (a * invfact[r]) % MOD;
a = (a * invfact[n - r]) % MOD;
return a;
}
LL inv2;
void init() {
fact[0] = 1;
invfact[0] = 1;
inv2 = inv(2);
for (LL i = 1; i < 110000; i++) {
fact[i] = (i * fact[i - 1]) % MOD;
invfact[i] = inv(fact[i]);
}
}
LL prob[3100][3100]; // prob i > j
LL temp1[3100][3100];
LL temp2[3100][3100];
int c, d;
int f(int a) {
if (a == c)
return d;
if (a == d)
return c;
return a;
}
int main() {
init();
int n, m;
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] > a[j]) {
prob[i][j] = 1;
} else {
prob[i][j] = 0;
}
}
}
for (int i = 0; i < m; i++) {
cin >> c >> d;
c--;
d--;
vector<int> r, s;
for (int j = 0; j < n; j++) {
r.push_back(j);
s.push_back(c);
r.push_back(j);
s.push_back(d);
r.push_back(c);
s.push_back(j);
r.push_back(d);
s.push_back(j);
}
for (int j = 0; j < r.size(); j++) {
int u = r[j];
int v = s[j];
temp1[u][v] = prob[u][v];
temp2[u][v] = prob[f(u)][f(v)];
}
for (int j = 0; j < r.size(); j++) {
int u = r[j];
int v = s[j];
prob[u][v] = (temp1[u][v] + temp2[u][v]) * inv2;
prob[u][v] %= MOD;
}
}
LL ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i < j) {
ans += prob[i][j];
ans %= MOD;
}
}
}
ans = ans * powmod(2, m);
ans %= MOD;
if (ans < 0)
ans += MOD;
cout << ans << endl;
} | replace | 38 | 41 | 38 | 41 | 0 | |
p03189 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ld long double
// This code is written by Itst
using namespace std;
inline int read() {
int a = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c) && c != EOF) {
if (c == '-')
f = 1;
c = getchar();
}
if (c == EOF)
exit(0);
while (isdigit(c)) {
a = a * 10 + c - 48;
c = getchar();
}
return f ? -a : a;
}
const int MOD = 1e9 + 7, inv2 = 5e8 + 4;
long long dp[2007][2007];
int num[2007], N, M;
int main() {
N = read();
M = read();
for (int i = 1; i <= N; ++i)
num[i] = read();
for (int i = 1; i <= N; ++i)
for (int j = i - 1; j; --j) {
dp[i][j] = num[i] > num[j];
dp[j][i] = num[j] > num[i];
}
for (int i = 1; i <= M; ++i) {
int a = read(), b = read();
for (int j = 1; j <= N; ++j)
if (j != a && j != b) {
dp[j][a] = dp[j][b] = (dp[j][a] + dp[j][b]) * inv2 % MOD;
dp[a][j] = dp[b][j] = (dp[a][j] + dp[b][j]) * inv2 % MOD;
}
dp[a][b] = dp[b][a] = (dp[a][b] + dp[b][a]) * inv2 % MOD;
}
long long sum = 0;
for (int i = 1; i <= N; ++i)
for (int j = i - 1; j; --j)
sum = (sum + dp[j][i]) % MOD;
for (int i = 1; i <= M; ++i)
sum = sum * 2 % MOD;
cout << sum;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ld long double
// This code is written by Itst
using namespace std;
inline int read() {
int a = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c) && c != EOF) {
if (c == '-')
f = 1;
c = getchar();
}
if (c == EOF)
exit(0);
while (isdigit(c)) {
a = a * 10 + c - 48;
c = getchar();
}
return f ? -a : a;
}
const int MOD = 1e9 + 7, inv2 = 5e8 + 4;
long long dp[3007][3007];
int num[3007], N, M;
int main() {
N = read();
M = read();
for (int i = 1; i <= N; ++i)
num[i] = read();
for (int i = 1; i <= N; ++i)
for (int j = i - 1; j; --j) {
dp[i][j] = num[i] > num[j];
dp[j][i] = num[j] > num[i];
}
for (int i = 1; i <= M; ++i) {
int a = read(), b = read();
for (int j = 1; j <= N; ++j)
if (j != a && j != b) {
dp[j][a] = dp[j][b] = (dp[j][a] + dp[j][b]) * inv2 % MOD;
dp[a][j] = dp[b][j] = (dp[a][j] + dp[b][j]) * inv2 % MOD;
}
dp[a][b] = dp[b][a] = (dp[a][b] + dp[b][a]) * inv2 % MOD;
}
long long sum = 0;
for (int i = 1; i <= N; ++i)
for (int j = i - 1; j; --j)
sum = (sum + dp[j][i]) % MOD;
for (int i = 1; i <= M; ++i)
sum = sum * 2 % MOD;
cout << sum;
return 0;
} | replace | 38 | 40 | 38 | 40 | 0 | |
p03189 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
typedef long long LL;
const int maxn = 3010, mod = 1e9 + 7;
int a[maxn], f[maxn][maxn];
int Pow(int x, int p) {
int r = 1;
while (p) {
if (p & 1)
r = (LL)x * r % mod;
x = (LL)x * x % mod;
p >>= 1;
}
return r;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#endif
int n = read(), Q = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (a[i] < a[j])
f[i][j] = 1;
int inv2 = 500000004, tmp = Pow(2, Q);
while (Q--) {
int x = read(), y = read();
f[x][y] = f[y][x] = (LL)(f[x][y] + f[y][x]) * inv2 % mod;
for (int i = 1; i <= n; ++i)
if (i != x && i != y)
f[i][x] = f[i][y] = (LL)inv2 * (f[i][x] + f[i][y]) % mod,
f[x][i] = f[y][i] = (LL)inv2 * (f[x][i] + f[y][i]) % mod;
}
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j < i; ++j)
(ans += f[i][j]) %= mod;
cout << (LL)ans * tmp % mod << endl;
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
typedef long long LL;
const int maxn = 3010, mod = 1e9 + 7;
int a[maxn], f[maxn][maxn];
int Pow(int x, int p) {
int r = 1;
while (p) {
if (p & 1)
r = (LL)x * r % mod;
x = (LL)x * x % mod;
p >>= 1;
}
return r;
}
int main() {
int n = read(), Q = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if (a[i] < a[j])
f[i][j] = 1;
int inv2 = 500000004, tmp = Pow(2, Q);
while (Q--) {
int x = read(), y = read();
f[x][y] = f[y][x] = (LL)(f[x][y] + f[y][x]) * inv2 % mod;
for (int i = 1; i <= n; ++i)
if (i != x && i != y)
f[i][x] = f[i][y] = (LL)inv2 * (f[i][x] + f[i][y]) % mod,
f[x][i] = f[y][i] = (LL)inv2 * (f[x][i] + f[y][i]) % mod;
}
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j < i; ++j)
(ans += f[i][j]) %= mod;
cout << (LL)ans * tmp % mod << endl;
return 0;
} | delete | 38 | 42 | 38 | 38 | TLE | |
p03189 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
void solve() {
const i64 mod = 1'000'000'007;
i64 N, Q;
cin >> N >> Q;
if (max(Q * N * N, N * N * N) >= 300000000) {
assert(false);
}
vector<i64> A(N);
rep(i, 0, N) { cin >> A[i]; }
vector<i64> X(Q), Y(Q);
rep(i, 0, Q) {
cin >> X[i] >> Y[i];
--X[i];
--Y[i];
}
const i64 size = 3000;
static i64 pow2[size + 1];
pow2[0] = 1;
rep(i, 1, size + 1) { pow2[i] = pow2[i - 1] * 2 % mod; }
static i64 dp[size][size];
static i64 last[size][size];
fill_n((i64 *)dp, size * size, 0);
fill_n((i64 *)last, size * size, -1);
rep(i, 0, N) {
rep(j, 0, N) {
if (A[j] <= A[i])
continue;
++dp[j][i];
}
}
rep(j, 0, Q) {
i64 x = X[j], y = Y[j];
auto evaluate = [&](i64 k, i64 l) {
if (last[k][l] < j) {
dp[k][l] *= pow2[j - last[k][l] - 1];
dp[k][l] %= mod;
}
last[k][l] = j;
};
vector<i64> xk(N), kx(N), yk(N), ky(N);
rep(k, 0, N) {
evaluate(x, k);
xk[k] = dp[x][k];
evaluate(k, x);
kx[k] = dp[k][x];
evaluate(y, k);
yk[k] = dp[y][k];
evaluate(k, y);
ky[k] = dp[k][y];
}
rep(k, 0, N) {
if (k == x)
continue;
dp[x][k] += yk[k];
dp[x][k] %= mod;
dp[k][x] += ky[k];
dp[k][x] %= mod;
}
rep(k, 0, N) {
if (k == y)
continue;
dp[y][k] += xk[k];
dp[y][k] %= mod;
dp[k][y] += kx[k];
dp[k][y] %= mod;
}
dp[y][x] += xk[y];
dp[y][x] %= mod;
dp[x][y] += yk[x];
dp[x][y] %= mod;
}
i64 ans = 0;
rep(j, 0, N) {
rep(k, j + 1, N) {
dp[j][k] *= pow2[Q - last[j][k] - 1];
dp[j][k] %= mod;
ans += dp[j][k];
ans %= mod;
}
}
cout << ans << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
void solve() {
const i64 mod = 1'000'000'007;
i64 N, Q;
cin >> N >> Q;
vector<i64> A(N);
rep(i, 0, N) { cin >> A[i]; }
vector<i64> X(Q), Y(Q);
rep(i, 0, Q) {
cin >> X[i] >> Y[i];
--X[i];
--Y[i];
}
const i64 size = 3000;
static i64 pow2[size + 1];
pow2[0] = 1;
rep(i, 1, size + 1) { pow2[i] = pow2[i - 1] * 2 % mod; }
static i64 dp[size][size];
static i64 last[size][size];
fill_n((i64 *)dp, size * size, 0);
fill_n((i64 *)last, size * size, -1);
rep(i, 0, N) {
rep(j, 0, N) {
if (A[j] <= A[i])
continue;
++dp[j][i];
}
}
rep(j, 0, Q) {
i64 x = X[j], y = Y[j];
auto evaluate = [&](i64 k, i64 l) {
if (last[k][l] < j) {
dp[k][l] *= pow2[j - last[k][l] - 1];
dp[k][l] %= mod;
}
last[k][l] = j;
};
vector<i64> xk(N), kx(N), yk(N), ky(N);
rep(k, 0, N) {
evaluate(x, k);
xk[k] = dp[x][k];
evaluate(k, x);
kx[k] = dp[k][x];
evaluate(y, k);
yk[k] = dp[y][k];
evaluate(k, y);
ky[k] = dp[k][y];
}
rep(k, 0, N) {
if (k == x)
continue;
dp[x][k] += yk[k];
dp[x][k] %= mod;
dp[k][x] += ky[k];
dp[k][x] %= mod;
}
rep(k, 0, N) {
if (k == y)
continue;
dp[y][k] += xk[k];
dp[y][k] %= mod;
dp[k][y] += kx[k];
dp[k][y] %= mod;
}
dp[y][x] += xk[y];
dp[y][x] %= mod;
dp[x][y] += yk[x];
dp[x][y] %= mod;
}
i64 ans = 0;
rep(j, 0, N) {
rep(k, j + 1, N) {
dp[j][k] *= pow2[Q - last[j][k] - 1];
dp[j][k] %= mod;
ans += dp[j][k];
ans %= mod;
}
}
cout << ans << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| delete | 34 | 38 | 34 | 34 | -11 | |
p03190 | C++ | Runtime Error | // BadWaper gg
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 5010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read() {
char ch = getchar();
ll s = 0, w = 1;
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
int a[N], b[N];
char s[N], t[N];
int n;
inline int calc() {
int t1 = 0, t2 = 0;
for (register int i = 1; i < n; i++)
if (s[i] == '0' && s[i + 1] == '1')
a[++t1] = i;
for (register int i = 1; i <= n; i++)
b[++t2] = 0;
for (register int i = 1; i < n; i++)
if (t[i] == '0' && t[i + 1] == '1')
b[++t2] = i;
for (register int i = 1; i <= n; i++)
b[++t2] = n;
int ans = inf;
for (register int i = 1; i <= t2 - t1 + 1; i++) {
int sum = 0;
for (register int j = 1; j < i; j++)
sum += b[j];
for (register int j = 1; j <= t1; j++)
sum += abs(a[j] - b[i + j - 1]);
for (register int j = i + t1; j <= t2; j++)
sum += n - b[j];
ans = min(ans, sum);
}
return ans;
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n = read();
scanf("%s%s", s + 1, t + 1);
if (n <= 2) {
int ans = 0;
for (register int i = 1; i <= n; i++)
ans += (s[i] != t[i]);
printf("%d\n", ans);
return 0;
}
int ans = calc();
for (register int i = 1; i <= n; i++)
s[i] = '1' + '0' - s[i];
for (register int i = 1; i <= n; i++)
t[i] = '1' + '0' - t[i];
ans = ans + calc();
printf("%d\n", ans);
return 0;
}
| // BadWaper gg
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 20010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read() {
char ch = getchar();
ll s = 0, w = 1;
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
int a[N], b[N];
char s[N], t[N];
int n;
inline int calc() {
int t1 = 0, t2 = 0;
for (register int i = 1; i < n; i++)
if (s[i] == '0' && s[i + 1] == '1')
a[++t1] = i;
for (register int i = 1; i <= n; i++)
b[++t2] = 0;
for (register int i = 1; i < n; i++)
if (t[i] == '0' && t[i + 1] == '1')
b[++t2] = i;
for (register int i = 1; i <= n; i++)
b[++t2] = n;
int ans = inf;
for (register int i = 1; i <= t2 - t1 + 1; i++) {
int sum = 0;
for (register int j = 1; j < i; j++)
sum += b[j];
for (register int j = 1; j <= t1; j++)
sum += abs(a[j] - b[i + j - 1]);
for (register int j = i + t1; j <= t2; j++)
sum += n - b[j];
ans = min(ans, sum);
}
return ans;
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n = read();
scanf("%s%s", s + 1, t + 1);
if (n <= 2) {
int ans = 0;
for (register int i = 1; i <= n; i++)
ans += (s[i] != t[i]);
printf("%d\n", ans);
return 0;
}
int ans = calc();
for (register int i = 1; i <= n; i++)
s[i] = '1' + '0' - s[i];
for (register int i = 1; i <= n; i++)
t[i] = '1' + '0' - t[i];
ans = ans + calc();
printf("%d\n", ans);
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p03190 | C++ | Runtime Error | #include <cstdio>
using namespace std;
#define N 5005
int a[N], b[N], n, s1, s2;
char s[N], t[N];
long long solve(int t) {
long long as = 0;
int fg = 0;
if (t < 0) {
t = -t;
fg = 1;
for (int i = 1; i <= n; i++)
a[i] ^= b[i] ^= a[i] ^= b[i];
s1 ^= s2 ^= s1 ^= s2;
}
int l1 = 1, r1 = 1 - t;
while (1) {
int tp1 = a[l1], tp2 = r1 < 0 ? 0 : b[r1];
if (l1 > s1)
tp1 = n;
if (r1 > s2)
tp2 = n;
as += tp1 < tp2 ? tp2 - tp1 : tp1 - tp2;
if (tp1 == tp2 && tp1 == n)
break;
l1++, r1++;
}
if (fg) {
for (int i = 1; i <= n; i++)
a[i] ^= b[i] ^= a[i] ^= b[i];
s1 ^= s2 ^= s1 ^= s2;
}
return as;
}
int main() {
scanf("%d%s%s", &n, s + 1, t + 1);
for (int i = 1; i <= n; i++)
if (s[i] != s[i + 1])
a[++s1] = i;
for (int i = 1; i <= n; i++)
if (t[i] != t[i + 1])
b[++s2] = i;
solve(-1);
long long mn = 1e18;
for (int i = s[1] == t[1] ? -5000 : -5001; i <= 5000; i += 2) {
long long tp = solve(i);
if (tp < mn)
mn = tp;
}
printf("%lld\n", mn);
} | #include <cstdio>
using namespace std;
#define N 15005
int a[N], b[N], n, s1, s2;
char s[N], t[N];
long long solve(int t) {
long long as = 0;
int fg = 0;
if (t < 0) {
t = -t;
fg = 1;
for (int i = 1; i <= n; i++)
a[i] ^= b[i] ^= a[i] ^= b[i];
s1 ^= s2 ^= s1 ^= s2;
}
int l1 = 1, r1 = 1 - t;
while (1) {
int tp1 = a[l1], tp2 = r1 < 0 ? 0 : b[r1];
if (l1 > s1)
tp1 = n;
if (r1 > s2)
tp2 = n;
as += tp1 < tp2 ? tp2 - tp1 : tp1 - tp2;
if (tp1 == tp2 && tp1 == n)
break;
l1++, r1++;
}
if (fg) {
for (int i = 1; i <= n; i++)
a[i] ^= b[i] ^= a[i] ^= b[i];
s1 ^= s2 ^= s1 ^= s2;
}
return as;
}
int main() {
scanf("%d%s%s", &n, s + 1, t + 1);
for (int i = 1; i <= n; i++)
if (s[i] != s[i + 1])
a[++s1] = i;
for (int i = 1; i <= n; i++)
if (t[i] != t[i + 1])
b[++s2] = i;
solve(-1);
long long mn = 1e18;
for (int i = s[1] == t[1] ? -5000 : -5001; i <= 5000; i += 2) {
long long tp = solve(i);
if (tp < mn)
mn = tp;
}
printf("%lld\n", mn);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03190 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int N = 5e3 + 5;
char S[N], T[N];
int n, ans = 1e9, cnt1, cnt2, A[N], B[N], tmpA[N], tmpB[N];
template <typename _Tp> inline void IN(_Tp &x) {
char ch;
bool flag = 0;
x = 0;
while (ch = getchar(), !isdigit(ch))
if (ch == '-')
flag = 1;
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
if (flag)
x = -x;
}
int main() {
IN(n), scanf("%s%s", S + 1, T + 1);
cnt1 = (bool)(S[1] == '1'), cnt2 = (bool)(T[1] == '1');
for (int i = 1; i < n; ++i)
(S[i] != S[i + 1]) ? tmpA[++cnt1] = i : 0,
(T[i] != T[i + 1]) ? tmpB[++cnt2] = i : 0;
(S[n] == '1') ? tmpA[++cnt1] = n : 0, (T[n] == '1') ? tmpB[++cnt2] = n : 0;
int lim = cnt1 + cnt2 + cnt2;
for (int i = cnt2 + 1; i <= lim; ++i)
A[i] = (i <= cnt1 + cnt2) ? tmpA[i - cnt2] : n;
for (int i = 0; i <= cnt1 + cnt2; i += 2) {
int res = 0;
for (int j = 1; j <= lim; ++j)
B[j] = j <= i ? 0 : (j <= i + cnt2 ? tmpB[j - i] : n);
for (int j = 1; j <= lim; ++j)
res += abs(A[j] - B[j]);
ans = min(ans, res);
}
return printf("%d\n", ans), 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int N = 1e5 + 5;
char S[N], T[N];
int n, ans = 1e9, cnt1, cnt2, A[N], B[N], tmpA[N], tmpB[N];
template <typename _Tp> inline void IN(_Tp &x) {
char ch;
bool flag = 0;
x = 0;
while (ch = getchar(), !isdigit(ch))
if (ch == '-')
flag = 1;
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
if (flag)
x = -x;
}
int main() {
IN(n), scanf("%s%s", S + 1, T + 1);
cnt1 = (bool)(S[1] == '1'), cnt2 = (bool)(T[1] == '1');
for (int i = 1; i < n; ++i)
(S[i] != S[i + 1]) ? tmpA[++cnt1] = i : 0,
(T[i] != T[i + 1]) ? tmpB[++cnt2] = i : 0;
(S[n] == '1') ? tmpA[++cnt1] = n : 0, (T[n] == '1') ? tmpB[++cnt2] = n : 0;
int lim = cnt1 + cnt2 + cnt2;
for (int i = cnt2 + 1; i <= lim; ++i)
A[i] = (i <= cnt1 + cnt2) ? tmpA[i - cnt2] : n;
for (int i = 0; i <= cnt1 + cnt2; i += 2) {
int res = 0;
for (int j = 1; j <= lim; ++j)
B[j] = j <= i ? 0 : (j <= i + cnt2 ? tmpB[j - i] : n);
for (int j = 1; j <= lim; ++j)
res += abs(A[j] - B[j]);
ans = min(ans, res);
}
return printf("%d\n", ans), 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03190 | C++ | Runtime Error | /*
_|_| _| _| _|
_| _| _| _|_| _|_|_|_| _| _| _|
_| _| _|_| _| _| _|_|
_| _| _| _| _| _| _| _|
_|_| _| _|_|_|_| _|_| _| _|
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
// #define ls (rt<<1)
// #define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn = 5005;
char s[maxn], t[maxn];
vi marks, markt;
int a[maxn], b[maxn];
int main() {
int n;
scanf("%d%s%s", &n, s + 1, t + 1);
if (s[1] == '1')
marks.pb(0);
rep(i, 1, n - 1) if (s[i] != s[i + 1]) marks.pb(i);
if (s[n] == '1')
marks.pb(n);
if (t[1] == '1')
markt.pb(0);
rep(i, 1, n - 1) if (t[i] != t[i + 1]) markt.pb(i);
if (t[n] == '1')
markt.pb(n);
int cnts = marks.size(), cntt = markt.size(), add = cntt - cnts;
int ans = 1e9 + 100;
rep(i, 1, cnts) a[i + cntt] = marks[i - 1];
rep(i, 1, cntt) a[i + cnts + cntt] = n;
for (int i = 0; i <= cnts + cntt; i += 2) {
int tmp = 0;
rep(j, 1, i) b[j] = 0;
// cout<<markt[0]<<endl;
rep(j, 1, cntt) b[i + j] = markt[j - 1];
rep(j, 1, cnts + cntt - i) b[j + i + cntt] = n;
rep(j, 1, cnts + cntt * 2) tmp += abs(a[j] - b[j]);
ans = min(ans, tmp);
}
/* rep(i,-cnts,cnts+add){//从开头通过的
int tmp=0;
int but=add-i;//从结尾通过的
if(i<0){
rep(j,1,-i)tmp+=abs(s[i-1]-0);
rep(j,-i+1,cnts)tmp+=abs(s[i-1]-t[j+i-1]);
rep(j,cnts+i+1,cnts)tmp+=abs(n-t[j-1]);
}
else{
rep(j,cnts+but+1,cnts)tmp+=abs(s[i-1]-n);
for(int j=cnts+but;j>=i;j--)tmp+=abs(s[i-1]-t[i-1]);
rep(j,1,i)tmp+=t[i];
}
ans=min(ans,tmp);
cout<<tmp<<endl;
}*/
cout << ans;
return 0;
} | /*
_|_| _| _| _|
_| _| _| _|_| _|_|_|_| _| _| _|
_| _| _|_| _| _| _|_|
_| _| _| _| _| _| _| _|
_|_| _| _|_|_|_| _|_| _| _|
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
// #define ls (rt<<1)
// #define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn = 3 * 5005;
char s[maxn], t[maxn];
vi marks, markt;
int a[maxn], b[maxn];
int main() {
int n;
scanf("%d%s%s", &n, s + 1, t + 1);
if (s[1] == '1')
marks.pb(0);
rep(i, 1, n - 1) if (s[i] != s[i + 1]) marks.pb(i);
if (s[n] == '1')
marks.pb(n);
if (t[1] == '1')
markt.pb(0);
rep(i, 1, n - 1) if (t[i] != t[i + 1]) markt.pb(i);
if (t[n] == '1')
markt.pb(n);
int cnts = marks.size(), cntt = markt.size(), add = cntt - cnts;
int ans = 1e9 + 100;
rep(i, 1, cnts) a[i + cntt] = marks[i - 1];
rep(i, 1, cntt) a[i + cnts + cntt] = n;
for (int i = 0; i <= cnts + cntt; i += 2) {
int tmp = 0;
rep(j, 1, i) b[j] = 0;
// cout<<markt[0]<<endl;
rep(j, 1, cntt) b[i + j] = markt[j - 1];
rep(j, 1, cnts + cntt - i) b[j + i + cntt] = n;
rep(j, 1, cnts + cntt * 2) tmp += abs(a[j] - b[j]);
ans = min(ans, tmp);
}
/* rep(i,-cnts,cnts+add){//从开头通过的
int tmp=0;
int but=add-i;//从结尾通过的
if(i<0){
rep(j,1,-i)tmp+=abs(s[i-1]-0);
rep(j,-i+1,cnts)tmp+=abs(s[i-1]-t[j+i-1]);
rep(j,cnts+i+1,cnts)tmp+=abs(n-t[j-1]);
}
else{
rep(j,cnts+but+1,cnts)tmp+=abs(s[i-1]-n);
for(int j=cnts+but;j>=i;j--)tmp+=abs(s[i-1]-t[i-1]);
rep(j,1,i)tmp+=t[i];
}
ans=min(ans,tmp);
cout<<tmp<<endl;
}*/
cout << ans;
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p03191 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 310, mod = 1e9 + 7;
int n, a[N], t[N], c[N], cnt, CNT;
void pls(int &x, int y) {
x += y;
x >= mod ? x -= mod : 0;
}
int dp[N << 1][N][N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= 2 * n; i += 2)
if (a[i] != -1 && a[i + 1] != -1)
t[a[i]] = t[a[i + 1]] = 2;
else if (a[i] != -1)
t[a[i]] = 1;
else if (a[i + 1] != -1)
t[a[i + 1]] = 1;
else
CNT++;
for (int i = 1; i <= 2 * n; i++)
if (t[i] == 1)
c[++cnt] = 1;
else if (!t[i])
c[++cnt] = 0;
dp[cnt][0][0] = 1;
for (int i = cnt; i; i--)
for (int j = 0; j <= cnt && j <= n; j++)
for (int k = 0; k <= cnt && k <= n; k++)
if (c[i] == 1) {
pls(dp[i - 1][j + 1][k], dp[i][j][k]);
if (k)
pls(dp[i - 1][j][k - 1], dp[i][j][k]);
} else {
pls(dp[i - 1][j][k + 1], dp[i][j][k]);
if (k)
pls(dp[i - 1][j][k - 1], dp[i][j][k]);
if (j)
pls(dp[i - 1][j - 1][k], (ll)dp[i][j][k] * j % mod);
}
ll ans = dp[0][0][0];
for (int i = 1; i <= CNT; i++)
ans = ans * i % mod;
cout << ans;
} | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 310, mod = 1e9 + 7;
int n, a[N << 1], t[N << 1], c[N << 1], cnt, CNT;
void pls(int &x, int y) {
x += y;
x >= mod ? x -= mod : 0;
}
int dp[N << 1][N][N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= 2 * n; i += 2)
if (a[i] != -1 && a[i + 1] != -1)
t[a[i]] = t[a[i + 1]] = 2;
else if (a[i] != -1)
t[a[i]] = 1;
else if (a[i + 1] != -1)
t[a[i + 1]] = 1;
else
CNT++;
for (int i = 1; i <= 2 * n; i++)
if (t[i] == 1)
c[++cnt] = 1;
else if (!t[i])
c[++cnt] = 0;
dp[cnt][0][0] = 1;
for (int i = cnt; i; i--)
for (int j = 0; j <= cnt && j <= n; j++)
for (int k = 0; k <= cnt && k <= n; k++)
if (c[i] == 1) {
pls(dp[i - 1][j + 1][k], dp[i][j][k]);
if (k)
pls(dp[i - 1][j][k - 1], dp[i][j][k]);
} else {
pls(dp[i - 1][j][k + 1], dp[i][j][k]);
if (k)
pls(dp[i - 1][j][k - 1], dp[i][j][k]);
if (j)
pls(dp[i - 1][j - 1][k], (ll)dp[i][j][k] * j % mod);
}
ll ans = dp[0][0][0];
for (int i = 1; i <= CNT; i++)
ans = ans * i % mod;
cout << ans;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p03191 | C++ | Runtime Error | using namespace std;
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#define N 310
#define mo 1000000007
#define ll long long
int n;
int bz[N];
int f[N * 2][N][N];
inline void add(int &a, ll b) { a = (a + b) % mo; }
int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
scanf("%d", &n);
for (int i = n; i >= 1; --i) {
int x, y;
scanf("%d%d", &x, &y);
if (x != -1 && y != -1)
bz[x] = -1, bz[y] = -1;
else if (x != -1)
bz[x] = 1;
else if (y != -1)
bz[y] = 1;
}
int tmpn = n;
n = 0;
for (int i = 1; i <= tmpn * 2; ++i)
if (bz[i] != -1)
bz[++n] = bz[i];
n >>= 1;
f[2 * n + 1][0][0] = 1;
for (int i = 2 * n + 1; i > 1; --i)
for (int j = 0; j <= 2 * n - i + 1 && j <= n; ++j)
for (int k = 0; j + k <= 2 * n - i + 1 && k <= n; ++k) {
ll tmp = f[i][j][k];
if (!tmp)
continue;
if (bz[i - 1] == 1) {
add(f[i - 1][j][k + 1], tmp);
if (j)
add(f[i - 1][j - 1][k], tmp);
} else {
add(f[i - 1][j + 1][k], tmp);
if (j)
add(f[i - 1][j - 1][k], tmp);
if (k)
add(f[i - 1][j][k - 1], tmp * k);
}
}
int cnt = 0;
ll ans = 1;
for (int i = 1; i <= 2 * n; ++i)
if (bz[i] == 1)
cnt++;
for (int i = 1; i <= n - cnt; ++i)
ans = ans * i % mo;
ans = ans * f[1][0][0] % mo;
printf("%lld\n", ans);
return 0;
} | using namespace std;
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#define N 310
#define mo 1000000007
#define ll long long
int n;
int bz[N * 2];
int f[N * 2][N][N];
inline void add(int &a, ll b) { a = (a + b) % mo; }
int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
scanf("%d", &n);
for (int i = n; i >= 1; --i) {
int x, y;
scanf("%d%d", &x, &y);
if (x != -1 && y != -1)
bz[x] = -1, bz[y] = -1;
else if (x != -1)
bz[x] = 1;
else if (y != -1)
bz[y] = 1;
}
int tmpn = n;
n = 0;
for (int i = 1; i <= tmpn * 2; ++i)
if (bz[i] != -1)
bz[++n] = bz[i];
n >>= 1;
f[2 * n + 1][0][0] = 1;
for (int i = 2 * n + 1; i > 1; --i)
for (int j = 0; j <= 2 * n - i + 1 && j <= n; ++j)
for (int k = 0; j + k <= 2 * n - i + 1 && k <= n; ++k) {
ll tmp = f[i][j][k];
if (!tmp)
continue;
if (bz[i - 1] == 1) {
add(f[i - 1][j][k + 1], tmp);
if (j)
add(f[i - 1][j - 1][k], tmp);
} else {
add(f[i - 1][j + 1][k], tmp);
if (j)
add(f[i - 1][j - 1][k], tmp);
if (k)
add(f[i - 1][j][k - 1], tmp * k);
}
}
int cnt = 0;
ll ans = 1;
for (int i = 1; i <= 2 * n; ++i)
if (bz[i] == 1)
cnt++;
for (int i = 1; i <= n - cnt; ++i)
ans = ans * i % mo;
ans = ans * f[1][0][0] % mo;
printf("%lld\n", ans);
return 0;
} | replace | 9 | 10 | 9 | 10 | -11 | |
p03191 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define re register
const int mod = 1e9 + 7;
struct par {
int x, tp;
} c[1010];
int a[610], b[610], qq[610], f[310][610], g[310][610];
inline bool cmp(const par &A, const par &B) { return A.x < B.x; }
int main() {
re int n, nm1 = 0, tt = 0;
scanf("%d", &n);
for (re int i = 1; i <= 2 * n; i++) {
scanf("%d", &a[i]);
a[i] = a[i] != -1 ? 2 * n + 1 - a[i] : -1;
if (a[i] != -1)
b[a[i]] = 1;
}
for (re int i = 1; i <= 2 * n; i++)
if (!b[i])
c[++tt] = (par){i, 1};
for (re int i = 1; i <= n; i++)
if (a[i * 2 - 1] == -1 && a[i * 2] == -1)
nm1++;
else if (a[i * 2 - 1] == -1 || a[i * 2] == -1)
c[++tt] = (par){max(a[i * 2 - 1], a[i * 2]), 0};
sort(c + 1, c + tt + 1, cmp);
f[0][0] = 1;
re int a1 = 0, b1 = 0;
for (re int i = 1; i <= tt; i++) {
memcpy(g, f, sizeof(f));
memset(f, 0, sizeof(f));
// printf("**%d %d\n",c[i].tp,c[i].x);
if (c[i].tp) {
a1++;
for (re int j = 0; j <= a1; j++)
for (re int k = 0; k <= b1; k++)
f[j][k] = ((long long)g[j][k + 1] * (k + 1) + (j ? g[j - 1][k] : 0) +
g[j + 1][k]) %
mod; //,printf("*l*%d %d %d\n",j,k,f[j][k]);
} else {
b1++;
for (re int j = 0; j <= a1; j++)
for (re int k = 0; k <= b1; k++)
f[j][k] = ((k ? g[j][k - 1] : 0) + g[j + 1][k]) %
mod; //,printf("*l*%d %d %d\n",j,k,f[j][k]);
}
}
for (re int i = 1; i <= nm1; i++)
f[0][0] = (long long)f[0][0] * i % mod;
printf("%d\n", f[0][0]);
} | #include <bits/stdc++.h>
using namespace std;
#define re register
const int mod = 1e9 + 7;
struct par {
int x, tp;
} c[1010];
int a[610], b[610], qq[610], f[610][310], g[610][310];
inline bool cmp(const par &A, const par &B) { return A.x < B.x; }
int main() {
re int n, nm1 = 0, tt = 0;
scanf("%d", &n);
for (re int i = 1; i <= 2 * n; i++) {
scanf("%d", &a[i]);
a[i] = a[i] != -1 ? 2 * n + 1 - a[i] : -1;
if (a[i] != -1)
b[a[i]] = 1;
}
for (re int i = 1; i <= 2 * n; i++)
if (!b[i])
c[++tt] = (par){i, 1};
for (re int i = 1; i <= n; i++)
if (a[i * 2 - 1] == -1 && a[i * 2] == -1)
nm1++;
else if (a[i * 2 - 1] == -1 || a[i * 2] == -1)
c[++tt] = (par){max(a[i * 2 - 1], a[i * 2]), 0};
sort(c + 1, c + tt + 1, cmp);
f[0][0] = 1;
re int a1 = 0, b1 = 0;
for (re int i = 1; i <= tt; i++) {
memcpy(g, f, sizeof(f));
memset(f, 0, sizeof(f));
// printf("**%d %d\n",c[i].tp,c[i].x);
if (c[i].tp) {
a1++;
for (re int j = 0; j <= a1; j++)
for (re int k = 0; k <= b1; k++)
f[j][k] = ((long long)g[j][k + 1] * (k + 1) + (j ? g[j - 1][k] : 0) +
g[j + 1][k]) %
mod; //,printf("*l*%d %d %d\n",j,k,f[j][k]);
} else {
b1++;
for (re int j = 0; j <= a1; j++)
for (re int k = 0; k <= b1; k++)
f[j][k] = ((k ? g[j][k - 1] : 0) + g[j + 1][k]) %
mod; //,printf("*l*%d %d %d\n",j,k,f[j][k]);
}
}
for (re int i = 1; i <= nm1; i++)
f[0][0] = (long long)f[0][0] * i % mod;
printf("%d\n", f[0][0]);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03191 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 605, mo = 1e9 + 7;
int a[N], ty[N], n, cnt, _;
ll f[2][N][N];
void move(ll &a, ll b) { a = (a + b) % mo; }
int main() {
cin >> n;
for (int i = 1; i <= 2 * n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= 2 * n; i += 2) {
if (a[i] != -1 && a[i + 1] != -1)
ty[a[i]] = ty[a[i + 1]] = 3;
else if (a[i] != a[i + 1])
ty[a[i] ^ a[i + 1] ^ -1] = 1;
else
cnt++;
}
f[_ = 1][0][0] = 1;
for (int i = 2 * n; i >= 1; i--) {
_ ^= 1;
memset(f[_], 0, sizeof f[_]);
for (int j = 0; j <= 2 * n - i + 1; j++)
for (int k = 0; j + k <= 2 * n - i + 1; k++) {
if (ty[i] == 1)
move(f[_][j - 1][k], f[!_][j][k]), move(f[_][j][k + 1], f[!_][j][k]);
if (ty[i] == 0)
move(f[_][j - 1][k], f[!_][j][k]), move(f[_][j + 1][k], f[!_][j][k]),
move(f[_][j][k - 1], (ll)f[!_][j][k] * k);
if (ty[i] == 3)
move(f[_][j][k], f[!_][j][k]);
}
}
ll ans = f[_][0][0];
for (; cnt; cnt--)
ans = ans * cnt % mo;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 605, mo = 1e9 + 7;
int a[N], ty[N], n, cnt, _;
ll f[2][N][N];
void move(ll &a, ll b) { a = (a + b) % mo; }
int main() {
cin >> n;
for (int i = 1; i <= 2 * n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= 2 * n; i += 2) {
if (a[i] != -1 && a[i + 1] != -1)
ty[a[i]] = ty[a[i + 1]] = 3;
else if (a[i] != a[i + 1])
ty[a[i] ^ a[i + 1] ^ -1] = 1;
else
cnt++;
}
f[_ = 1][0][0] = 1;
for (int i = 2 * n; i >= 1; i--) {
_ ^= 1;
memset(f[_], 0, sizeof f[_]);
for (int j = 0; j <= 2 * n - i + 1; j++)
for (int k = 0; j + k <= 2 * n - i + 1; k++) {
if (ty[i] == 1) {
if (j)
move(f[_][j - 1][k], f[!_][j][k]);
move(f[_][j][k + 1], f[!_][j][k]);
}
if (ty[i] == 0) {
if (j)
move(f[_][j - 1][k], f[!_][j][k]);
move(f[_][j + 1][k], f[!_][j][k]);
if (k)
move(f[_][j][k - 1], (ll)f[!_][j][k] * k);
}
if (ty[i] == 3)
move(f[_][j][k], f[!_][j][k]);
}
}
ll ans = f[_][0][0];
for (; cnt; cnt--)
ans = ans * cnt % mo;
cout << ans << endl;
} | replace | 25 | 30 | 25 | 37 | 0 | |
p03191 | C++ | Runtime Error | // minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
template <class T> inline bool cmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <class T> inline bool cmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
using namespace std;
const int P = 1e9 + 7;
inline void upd(R int &x, R int y) { (x += y) >= P ? x -= P : 0; }
inline int inc(R int x, R int y) { return x + y >= P ? x + y - P : x + y; }
inline int dec(R int x, R int y) { return x - y < 0 ? x - y + P : x - y; }
inline int mul(R int x, R int y) { return 1ll * x * y - 1ll * x * y / P * P; }
int ksm(R int x, R int y) {
R int res = 1;
for (; y; y >>= 1, x = mul(x, x))
(y & 1) ? res = mul(res, x) : 0;
return res;
}
const int N = 305;
int f[N][N][N], a[N << 1], st[N << 1], vis[N << 1], bk[N << 1], top, n, cnt, ct,
res;
int main() {
// freopen("testdata.in","r",stdin);
scanf("%d", &n);
fp(i, 1, n << 1) scanf("%d", &a[i]);
for (R int i = 1; i <= (n << 1); i += 2) {
if (a[i] == a[i + 1])
++cnt;
else if (a[i] > 0 && a[i + 1] > 0)
vis[a[i]] = vis[a[i + 1]] = 1;
else
bk[(~a[i]) ? a[i] : a[i + 1]] = 1, ++ct;
}
fd(i, n << 1, 1) if (!vis[i]) st[++top] = i;
f[0][0][0] = 1;
fp(i, 1, top) fp(j, 0, cnt + ct) fp(k, 0, ct) if (f[i - 1][j][k]) {
R int coef = f[i - 1][j][k];
if (!bk[st[i]]) {
upd(f[i][j + 1][k], coef);
if (j)
upd(f[i][j - 1][k], coef);
if (k)
upd(f[i][j][k - 1], mul(coef, k));
} else {
upd(f[i][j][k + 1], coef);
if (j)
upd(f[i][j - 1][k], coef);
}
}
res = f[top][0][0];
fp(i, 1, cnt) res = mul(res, i);
printf("%d\n", res);
return 0;
} | // minamoto
#include <bits/stdc++.h>
#define R register
#define fp(i, a, b) for (R int i = (a), I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (R int i = (a), I = (b)-1; i > I; --i)
#define go(u) for (int i = head[u], v = e[i].v; i; i = e[i].nx, v = e[i].v)
template <class T> inline bool cmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <class T> inline bool cmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
using namespace std;
const int P = 1e9 + 7;
inline void upd(R int &x, R int y) { (x += y) >= P ? x -= P : 0; }
inline int inc(R int x, R int y) { return x + y >= P ? x + y - P : x + y; }
inline int dec(R int x, R int y) { return x - y < 0 ? x - y + P : x - y; }
inline int mul(R int x, R int y) { return 1ll * x * y - 1ll * x * y / P * P; }
int ksm(R int x, R int y) {
R int res = 1;
for (; y; y >>= 1, x = mul(x, x))
(y & 1) ? res = mul(res, x) : 0;
return res;
}
const int N = 305;
int f[N << 1][N][N], a[N << 1], st[N << 1], vis[N << 1], bk[N << 1], top, n,
cnt, ct, res;
int main() {
// freopen("testdata.in","r",stdin);
scanf("%d", &n);
fp(i, 1, n << 1) scanf("%d", &a[i]);
for (R int i = 1; i <= (n << 1); i += 2) {
if (a[i] == a[i + 1])
++cnt;
else if (a[i] > 0 && a[i + 1] > 0)
vis[a[i]] = vis[a[i + 1]] = 1;
else
bk[(~a[i]) ? a[i] : a[i + 1]] = 1, ++ct;
}
fd(i, n << 1, 1) if (!vis[i]) st[++top] = i;
f[0][0][0] = 1;
fp(i, 1, top) fp(j, 0, cnt + ct) fp(k, 0, ct) if (f[i - 1][j][k]) {
R int coef = f[i - 1][j][k];
if (!bk[st[i]]) {
upd(f[i][j + 1][k], coef);
if (j)
upd(f[i][j - 1][k], coef);
if (k)
upd(f[i][j][k - 1], mul(coef, k));
} else {
upd(f[i][j][k + 1], coef);
if (j)
upd(f[i][j - 1][k], coef);
}
}
res = f[top][0][0];
fp(i, 1, cnt) res = mul(res, i);
printf("%d\n", res);
return 0;
} | replace | 25 | 27 | 25 | 27 | -11 | |
p03191 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename T> inline T read() {
T f = 0, x = 0;
char c = getchar();
while (!isdigit(c))
f = c == '-', c = getchar();
while (isdigit(c))
x = x * 10 + c - 48, c = getchar();
return f ? -x : x;
}
namespace run {
const int N = 309, mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x - mod + y : x + y; }
inline int sub(int x, int y) { return x >= y ? x - y : x + mod - y; }
inline int qpow(int x, int y) {
int ret = 1;
while (y) {
if (y & 1)
ret = 1LL * x * ret % mod;
x = 1LL * x * x % mod, y >>= 1;
}
return ret;
}
int vis[N], n, a[N], m, f[N][N][N];
int main() {
n = read<int>() * 2;
for (int i = 1; i <= n; i++) {
a[i] = read<int>();
if (~a[i])
vis[a[i]] = 1;
if (~i & 1 && ~a[i] && ~a[i - 1])
vis[a[i]] = 2, vis[a[i - 1]] = 2;
}
for (int i = 1; i <= n; i++)
if (vis[i] != 2)
vis[++m] = vis[i];
f[m + 1][0][0] = 1;
for (int i = m; i >= 1; i--) {
for (int j = 0; j <= m - i + 1; j++)
for (int k = 0; k <= m - i + 1 - j; k++) {
if (!vis[i]) {
f[i][j][k] = add(f[i + 1][j + 1][k], f[i][j][k]);
f[i][j][k] = (1LL * f[i + 1][j][k + 1] * (k + 1) + f[i][j][k]) % mod;
f[i][j][k] = add(f[i + 1][j - 1][k], f[i][j][k]);
} else {
f[i][j][k] = add(f[i + 1][j + 1][k], f[i][j][k]);
f[i][j][k] = add(f[i + 1][j][k - 1], f[i][j][k]);
}
}
}
int ans = f[1][0][0], sum = 0;
for (int i = 1; i <= m; i++)
if (vis[i])
sum++;
for (int i = 1; i <= m / 2 - sum; i++)
ans = 1LL * i * ans % mod;
printf("%d\n", ans);
return 0;
}
} // namespace run
int main() {
#ifdef my
freopen("minimum.in", "r", stdin);
freopen("minimum.out", "w", stdout);
#endif
return run::main();
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> inline T read() {
T f = 0, x = 0;
char c = getchar();
while (!isdigit(c))
f = c == '-', c = getchar();
while (isdigit(c))
x = x * 10 + c - 48, c = getchar();
return f ? -x : x;
}
namespace run {
const int N = 309, mod = 1e9 + 7;
inline int add(int x, int y) { return x + y >= mod ? x - mod + y : x + y; }
inline int sub(int x, int y) { return x >= y ? x - y : x + mod - y; }
inline int qpow(int x, int y) {
int ret = 1;
while (y) {
if (y & 1)
ret = 1LL * x * ret % mod;
x = 1LL * x * x % mod, y >>= 1;
}
return ret;
}
int vis[N * 2], n, a[N * 2], m, f[N * 2][N * 2][N * 2];
int main() {
n = read<int>() * 2;
for (int i = 1; i <= n; i++) {
a[i] = read<int>();
if (~a[i])
vis[a[i]] = 1;
if (~i & 1 && ~a[i] && ~a[i - 1])
vis[a[i]] = 2, vis[a[i - 1]] = 2;
}
for (int i = 1; i <= n; i++)
if (vis[i] != 2)
vis[++m] = vis[i];
f[m + 1][0][0] = 1;
for (int i = m; i >= 1; i--) {
for (int j = 0; j <= m - i + 1; j++)
for (int k = 0; k <= m - i + 1 - j; k++) {
if (!vis[i]) {
f[i][j][k] = add(f[i + 1][j + 1][k], f[i][j][k]);
f[i][j][k] = (1LL * f[i + 1][j][k + 1] * (k + 1) + f[i][j][k]) % mod;
f[i][j][k] = add(f[i + 1][j - 1][k], f[i][j][k]);
} else {
f[i][j][k] = add(f[i + 1][j + 1][k], f[i][j][k]);
f[i][j][k] = add(f[i + 1][j][k - 1], f[i][j][k]);
}
}
}
int ans = f[1][0][0], sum = 0;
for (int i = 1; i <= m; i++)
if (vis[i])
sum++;
for (int i = 1; i <= m / 2 - sum; i++)
ans = 1LL * i * ans % mod;
printf("%d\n", ans);
return 0;
}
} // namespace run
int main() {
#ifdef my
freopen("minimum.in", "r", stdin);
freopen("minimum.out", "w", stdout);
#endif
return run::main();
} | replace | 25 | 26 | 25 | 26 | -11 | |
p03191 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 700;
const int MOD = 1e9 + 7;
int n;
int F[N][N][N], flg[N], fac = 1, rua;
void ADD(int &t, int d) {
t += d;
if (t >= MOD)
t -= MOD;
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
int a, b;
scanf("%d%d", &a, &b);
if ((a != -1) && (b != -1))
flg[a] = flg[b] = 2;
else if (a != -1)
flg[a] = 1;
else if (b != -1)
flg[b] = 1;
else
rua++;
}
F[0][0][0] = 1;
for (int i = 1; i <= 2 * n; ++i)
for (int j = 0; j <= 2 * n; ++j)
for (int k = 0; k <= 2 * n; ++k) {
if (flg[i] == 2) {
ADD(F[i][j][k], F[i - 1][j][k]);
} else if (flg[i] == 1) {
ADD(F[i][j][k + 1], F[i - 1][j][k]);
if (j)
ADD(F[i][j - 1][k], 1ll * F[i - 1][j][k] * j % MOD);
} else {
ADD(F[i][j][k + 1], F[i - 1][j][k]);
ADD(F[i][j + 1][k], F[i - 1][j][k]);
if (k)
ADD(F[i][j][k - 1], F[i - 1][j][k]);
}
}
for (int i = 1; i <= rua; ++i)
fac = 1ll * fac * i % MOD;
cout << 1ll * F[2 * n][0][0] * fac % MOD << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 610;
const int MOD = 1e9 + 7;
int n;
int F[N][N][N], flg[N], fac = 1, rua;
void ADD(int &t, int d) {
t += d;
if (t >= MOD)
t -= MOD;
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
int a, b;
scanf("%d%d", &a, &b);
if ((a != -1) && (b != -1))
flg[a] = flg[b] = 2;
else if (a != -1)
flg[a] = 1;
else if (b != -1)
flg[b] = 1;
else
rua++;
}
F[0][0][0] = 1;
for (int i = 1; i <= 2 * n; ++i)
for (int j = 0; j <= 2 * n; ++j)
for (int k = 0; k <= 2 * n; ++k) {
if (flg[i] == 2) {
ADD(F[i][j][k], F[i - 1][j][k]);
} else if (flg[i] == 1) {
ADD(F[i][j][k + 1], F[i - 1][j][k]);
if (j)
ADD(F[i][j - 1][k], 1ll * F[i - 1][j][k] * j % MOD);
} else {
ADD(F[i][j][k + 1], F[i - 1][j][k]);
ADD(F[i][j + 1][k], F[i - 1][j][k]);
if (k)
ADD(F[i][j][k - 1], F[i - 1][j][k]);
}
}
for (int i = 1; i <= rua; ++i)
fac = 1ll * fac * i % MOD;
cout << 1ll * F[2 * n][0][0] * fac % MOD << endl;
} | replace | 3 | 4 | 3 | 4 | MLE | |
p03191 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long LL;
typedef double db;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9')
s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' && ch <= '9')
s = s * 10 + ch - '0';
return s;
}
const int N = 605;
const int mo = 1e9 + 7;
int n;
int a[N];
bool bz[N];
bool can[N];
LL f[N][N][N];
LL add(LL x, LL y) { return x + y >= mo ? x + y - mo : x + y; }
int main() {
n = get();
fo(i, 1, n * 2) a[i] = get();
fo(i, 1, n * 2) if (a[i] != -1) bz[a[i]] = 1;
fo(i, 1, n * 2) can[i] = 1;
fo(i, 1, n) if (a[i * 2 - 1] != -1 && a[i * 2] != -1) can[a[i * 2 - 1]] =
can[a[i * 2]] = 0;
f[n * 2 + 1][0][0] = 1;
fd(i, n * 2, 1) if (can[i]) {
if (bz[i]) {
fo(j, 0, n) fo(k, 0, n) if (f[i + 1][j][k]) {
//(
if (j)
f[i][j - 1][k] = add(f[i][j - 1][k], f[i + 1][j][k]);
//)
f[i][j][k + 1] = add(f[i][j][k + 1], f[i + 1][j][k]);
}
} else {
fo(j, 0, n) fo(k, 0, n) if (f[i + 1][j][k]) {
//(
if (j)
f[i][j - 1][k] = add(f[i][j - 1][k], f[i + 1][j][k]);
if (k)
f[i][j][k - 1] = (f[i][j][k - 1] + f[i + 1][j][k] * k) % mo;
//)
f[i][j + 1][k] = add(f[i][j + 1][k], f[i + 1][j][k]);
}
}
}
else fo(j, 0, n) fo(k, 0, n) f[i][j][k] = f[i + 1][j][k];
int cnt = 0;
fo(i, 1, n) if (a[i * 2 - 1] == -1 && a[i * 2] == -1) cnt++;
LL ans = f[1][0][0];
fo(i, 1, cnt) ans = ans * i % mo;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long LL;
typedef double db;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9')
s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' && ch <= '9')
s = s * 10 + ch - '0';
return s;
}
const int N = 605;
const int mo = 1e9 + 7;
int n;
int a[N];
bool bz[N];
bool can[N];
LL f[N][305][305];
LL add(LL x, LL y) { return x + y >= mo ? x + y - mo : x + y; }
int main() {
n = get();
fo(i, 1, n * 2) a[i] = get();
fo(i, 1, n * 2) if (a[i] != -1) bz[a[i]] = 1;
fo(i, 1, n * 2) can[i] = 1;
fo(i, 1, n) if (a[i * 2 - 1] != -1 && a[i * 2] != -1) can[a[i * 2 - 1]] =
can[a[i * 2]] = 0;
f[n * 2 + 1][0][0] = 1;
fd(i, n * 2, 1) if (can[i]) {
if (bz[i]) {
fo(j, 0, n) fo(k, 0, n) if (f[i + 1][j][k]) {
//(
if (j)
f[i][j - 1][k] = add(f[i][j - 1][k], f[i + 1][j][k]);
//)
f[i][j][k + 1] = add(f[i][j][k + 1], f[i + 1][j][k]);
}
} else {
fo(j, 0, n) fo(k, 0, n) if (f[i + 1][j][k]) {
//(
if (j)
f[i][j - 1][k] = add(f[i][j - 1][k], f[i + 1][j][k]);
if (k)
f[i][j][k - 1] = (f[i][j][k - 1] + f[i + 1][j][k] * k) % mo;
//)
f[i][j + 1][k] = add(f[i][j + 1][k], f[i + 1][j][k]);
}
}
}
else fo(j, 0, n) fo(k, 0, n) f[i][j][k] = f[i + 1][j][k];
int cnt = 0;
fo(i, 1, n) if (a[i * 2 - 1] == -1 && a[i * 2] == -1) cnt++;
LL ans = f[1][0][0];
fo(i, 1, cnt) ans = ans * i % mo;
cout << ans << endl;
return 0;
} | replace | 33 | 34 | 33 | 34 | MLE | |
p03191 | C++ | Runtime Error | #include <cstdio>
const int mod = 1000000007;
int N, A[610], c[610], f[610][310][310];
bool del[610];
int main() {
scanf("%d", &N);
for (int i = 0; i < N * 2; i++)
scanf("%d", A + i), c[A[i]]++;
int m = 0;
for (int i = 0; i < N * 2; i++) {
if (A[i * 2] != -1 && A[i * 2 + 1] != -1)
del[A[i * 2]] = del[A[i * 2 + 1]] = 1;
if (A[i * 2] == -1 && A[i * 2 + 1] == -1)
m++;
}
int s = 0, t = 0;
f[N * 2][0][0] = 1;
for (int i = N * 2; i; i--) {
for (int j = 0; j <= N; j++)
for (int k = 0; k <= N; k++)
if (f[i][j][k]) {
if (del[i])
f[i - 1][j][k] = f[i][j][k];
else {
if (c[i])
(f[i - 1][j][k + 1] += f[i][j][k]) %= mod;
else
(f[i - 1][j + 1][k] += f[i][j][k]) %= mod;
if (c[i]) {
if (j)
(f[i - 1][j - 1][k] += f[i][j][k]) %= mod;
} else {
if (k)
f[i - 1][j][k - 1] =
(f[i - 1][j][k - 1] + 1ll * k * f[i][j][k]) % mod;
if (j && m + s + (j - k - t) / 2 > 0)
f[i - 1][j - 1][k] =
(f[i - 1][j - 1][k] +
1ll * (m + s + (j - k - t) / 2) * f[i][j][k]) %
mod;
}
}
}
if (!del[i])
s += c[i], t++;
}
printf("%d\n", f[0][0][0]);
} | #include <cstdio>
const int mod = 1000000007;
int N, A[610], c[610], f[610][310][310];
bool del[610];
int main() {
scanf("%d", &N);
for (int i = 0; i < N * 2; i++)
scanf("%d", A + i), c[A[i]]++;
int m = 0;
for (int i = 0; i < N; i++) {
if (A[i * 2] != -1 && A[i * 2 + 1] != -1)
del[A[i * 2]] = del[A[i * 2 + 1]] = 1;
if (A[i * 2] == -1 && A[i * 2 + 1] == -1)
m++;
}
int s = 0, t = 0;
f[N * 2][0][0] = 1;
for (int i = N * 2; i; i--) {
for (int j = 0; j <= N; j++)
for (int k = 0; k <= N; k++)
if (f[i][j][k]) {
if (del[i])
f[i - 1][j][k] = f[i][j][k];
else {
if (c[i])
(f[i - 1][j][k + 1] += f[i][j][k]) %= mod;
else
(f[i - 1][j + 1][k] += f[i][j][k]) %= mod;
if (c[i]) {
if (j)
(f[i - 1][j - 1][k] += f[i][j][k]) %= mod;
} else {
if (k)
f[i - 1][j][k - 1] =
(f[i - 1][j][k - 1] + 1ll * k * f[i][j][k]) % mod;
if (j && m + s + (j - k - t) / 2 > 0)
f[i - 1][j - 1][k] =
(f[i - 1][j - 1][k] +
1ll * (m + s + (j - k - t) / 2) * f[i][j][k]) %
mod;
}
}
}
if (!del[i])
s += c[i], t++;
}
printf("%d\n", f[0][0][0]);
} | replace | 9 | 10 | 9 | 10 | -11 | |
p03191 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 333, mod = 1000000007;
#define MP make_pair
#define PB push_back
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
inline ll read() {
char ch = getchar();
ll x = 0, f = 0;
while (ch < '0' || ch > '9')
f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int n, f[maxn * 2][maxn][maxn], cnt1, cnt2, ans;
bool vis[maxn], ind[maxn];
int main() {
n = read();
FOR(i, 1, n) {
int x = read(), y = read();
if (~x && ~y)
vis[x] = vis[y] = true;
else if (~x)
ind[x] = true, cnt2++;
else if (~y)
ind[y] = true, cnt2++;
else
cnt1++;
}
f[2 * n + 1][0][0] = 1;
ROF(i, 2 * n, 1) FOR(j, 0, cnt1 + cnt2) FOR(k, 0, cnt2) {
if (vis[i])
f[i][j][k] = f[i + 1][j][k];
else if (ind[i]) {
if (k)
f[i][j][k] = (f[i][j][k] + f[i + 1][j][k - 1]) % mod;
if (j != cnt1 + cnt2)
f[i][j][k] = (f[i][j][k] + f[i + 1][j + 1][k]) % mod;
} else {
if (j)
f[i][j][k] = (f[i][j][k] + f[i + 1][j - 1][k]) % mod;
if (j != cnt1 + cnt2)
f[i][j][k] = (f[i][j][k] + f[i + 1][j + 1][k]) % mod;
if (k != cnt2)
f[i][j][k] = (f[i][j][k] + 1ll * (k + 1) * f[i + 1][j][k + 1]) % mod;
}
}
ans = f[1][0][0];
FOR(i, 1, cnt1) ans = 1ll * ans * i % mod;
printf("%d\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int maxn = 333, mod = 1000000007;
#define MP make_pair
#define PB push_back
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
inline ll read() {
char ch = getchar();
ll x = 0, f = 0;
while (ch < '0' || ch > '9')
f |= ch == '-', ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int n, f[maxn * 2][maxn][maxn], cnt1, cnt2, ans;
bool vis[maxn * 2], ind[maxn * 2];
int main() {
n = read();
FOR(i, 1, n) {
int x = read(), y = read();
if (~x && ~y)
vis[x] = vis[y] = true;
else if (~x)
ind[x] = true, cnt2++;
else if (~y)
ind[y] = true, cnt2++;
else
cnt1++;
}
f[2 * n + 1][0][0] = 1;
ROF(i, 2 * n, 1) FOR(j, 0, cnt1 + cnt2) FOR(k, 0, cnt2) {
if (vis[i])
f[i][j][k] = f[i + 1][j][k];
else if (ind[i]) {
if (k)
f[i][j][k] = (f[i][j][k] + f[i + 1][j][k - 1]) % mod;
if (j != cnt1 + cnt2)
f[i][j][k] = (f[i][j][k] + f[i + 1][j + 1][k]) % mod;
} else {
if (j)
f[i][j][k] = (f[i][j][k] + f[i + 1][j - 1][k]) % mod;
if (j != cnt1 + cnt2)
f[i][j][k] = (f[i][j][k] + f[i + 1][j + 1][k]) % mod;
if (k != cnt2)
f[i][j][k] = (f[i][j][k] + 1ll * (k + 1) * f[i + 1][j][k + 1]) % mod;
}
}
ans = f[1][0][0];
FOR(i, 1, cnt1) ans = 1ll * ans * i % mod;
printf("%d\n", ans);
} | replace | 22 | 23 | 22 | 23 | -11 | |
p03191 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300, mod = 1000000007;
int n, m, f[N][N], g[N][N];
bool fix[N], banned[N];
int main() {
scanf("%d", &n);
int t = 1;
for (int i = 1, x, y; i <= n; i++) {
scanf("%d%d", &x, &y);
if (~x && ~y) {
fix[x] = fix[y] = true;
} else if (~x || ~y) {
banned[x + y + 1] = true;
} else {
t = (ll)t * (++m) % mod;
}
}
f[0][0] = 1;
for (int x = n * 2; x; x--)
if (!fix[x]) {
memset(g, 0, sizeof g);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++)
if (f[i][j]) {
if (banned[x]) {
g[i][j + 1] = (g[i][j + 1] + f[i][j]) % mod;
if (i)
g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
} else {
g[i + 1][j] = (g[i + 1][j] + f[i][j]) % mod;
if (i)
g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
if (j)
g[i][j - 1] = (g[i][j - 1] + (ll)f[i][j] * j) % mod;
}
}
}
memcpy(f, g, sizeof g);
}
int ans = (ll)f[0][0] * t % mod;
printf("%d\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 666, mod = 1000000007;
int n, m, f[N][N], g[N][N];
bool fix[N], banned[N];
int main() {
scanf("%d", &n);
int t = 1;
for (int i = 1, x, y; i <= n; i++) {
scanf("%d%d", &x, &y);
if (~x && ~y) {
fix[x] = fix[y] = true;
} else if (~x || ~y) {
banned[x + y + 1] = true;
} else {
t = (ll)t * (++m) % mod;
}
}
f[0][0] = 1;
for (int x = n * 2; x; x--)
if (!fix[x]) {
memset(g, 0, sizeof g);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++)
if (f[i][j]) {
if (banned[x]) {
g[i][j + 1] = (g[i][j + 1] + f[i][j]) % mod;
if (i)
g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
} else {
g[i + 1][j] = (g[i + 1][j] + f[i][j]) % mod;
if (i)
g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
if (j)
g[i][j - 1] = (g[i][j - 1] + (ll)f[i][j] * j) % mod;
}
}
}
memcpy(f, g, sizeof g);
}
int ans = (ll)f[0][0] * t % mod;
printf("%d\n", ans);
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03191 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
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;
}
template <unsigned int mod> class ModInt {
private:
unsigned int v;
static unsigned int norm(const unsigned int &x) {
return x < mod ? x : x - mod;
}
static ModInt make(const unsigned int &x) {
ModInt m;
return m.v = x, m;
}
static ModInt inv(const ModInt &x) { return make(inverse(x.v, mod)); }
static unsigned int inverse(int a, int m) {
int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
while (*v) {
t = *u / *v;
swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]),
swap(u[2] -= t * v[2], v[2]);
}
return (u[1] % m + m) % m;
}
public:
ModInt() : v{0} {}
ModInt(const long long val) : v{norm(val % mod + mod)} {}
ModInt(const ModInt<mod> &n) : v{n()} {}
explicit operator bool() const noexcept { return v != 0; }
bool operator!() const noexcept { return !static_cast<bool>(*this); }
ModInt &operator=(const ModInt &n) { return v = n(), (*this); }
ModInt &operator=(const long long val) {
return v = norm(val % mod + mod), (*this);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { return v == 0 ? make(0) : make(mod - v); }
ModInt operator+(const ModInt &val) const { return make(norm(v + val())); }
ModInt operator-(const ModInt &val) const {
return make(norm(v + mod - val()));
}
ModInt operator*(const ModInt &val) const {
return make((long long)v * val() % mod);
}
ModInt operator/(const ModInt &val) const { return *this * inv(val); }
ModInt &operator+=(const ModInt &val) { return *this = *this + val; }
ModInt &operator-=(const ModInt &val) { return *this = *this - val; }
ModInt &operator*=(const ModInt &val) { return *this = *this * val; }
ModInt &operator/=(const ModInt &val) { return *this = *this / val; }
ModInt operator+(const long long val) const { return ModInt{v + val}; }
ModInt operator-(const long long val) const { return ModInt{v - val}; }
ModInt operator*(const long long val) const {
return ModInt{(long long)v * (val % mod)};
}
ModInt operator/(const long long val) const {
return ModInt{(long long)v * inv(val)};
}
ModInt &operator+=(const long long val) { return *this = *this + val; }
ModInt &operator-=(const long long val) { return *this = *this - val; }
ModInt &operator*=(const long long val) { return *this = *this * val; }
ModInt &operator/=(const long long val) { return *this = *this / val; }
bool operator==(const ModInt &val) const { return v == val.v; }
bool operator!=(const ModInt &val) const { return !(*this == val); }
bool operator==(const long long val) const {
return v == norm(val % mod + mod);
}
bool operator!=(const long long val) const { return !(*this == val); }
unsigned int operator()() const { return v; }
friend ModInt operator+(const long long val, const ModInt &n) {
return n + val;
}
friend ModInt operator-(const long long val, const ModInt &n) {
return ModInt{val - n()};
}
friend ModInt operator*(const long long val, const ModInt &n) {
return n * val;
}
friend ModInt operator/(const long long val, const ModInt &n) {
return ModInt{val} / n;
}
friend bool operator==(const long long val, const ModInt &n) {
return n == val;
}
friend bool operator!=(const long long val, const ModInt &n) {
return !(val == n);
}
friend istream &operator>>(istream &is, ModInt &n) {
unsigned int v;
return is >> v, n = v, is;
}
friend ostream &operator<<(ostream &os, const ModInt &n) {
return (os << n());
}
friend ModInt mod_pow(ModInt x, long long n) {
ModInt ans = 1;
while (n) {
if (n & 1)
ans *= x;
x *= x, n >>= 1;
}
return ans;
}
};
#define MOD 1000000007
using mod = ModInt<MOD>;
#define MAX_N 200000
mod inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
inv[i] = MOD - inv[MOD % i] * (MOD / i);
fac[i] = fac[i - 1] * i;
finv[i] = finv[i - 1] * inv[i];
}
}
mod comb(int a, int b) {
if (a < b)
return 0;
return fac[a] * finv[b] * finv[a - b];
}
mod dp[303][303][303];
int cc[303];
int main() {
make();
int n;
cin >> n;
vector<int> a(2 * n);
rep(i, 2 * n) cin >> a[i];
vector<bool> p(2 * n + 1);
p[0] = 1;
vector<int> b;
rep(i, n) {
if (a[2 * i] != -1 && a[2 * i + 1] != -1) {
p[a[2 * i]] = 1;
p[a[2 * i + 1]] = 1;
} else {
b.push_back(a[2 * i]);
b.push_back(a[2 * i + 1]);
}
}
map<int, int> mp;
mp[-1] = -1;
int c = 1;
rep(i, 2 * n + 1) {
if (!p[i]) {
mp[i] = c;
c++;
}
}
int m = b.size();
m /= 2;
rep(i, m) {
b[2 * i] = mp[b[2 * i]];
b[2 * i + 1] = mp[b[2 * i + 1]];
}
set<int> st;
int T = 0;
rep(i, m) {
cerr << b[2 * i] << " " << b[2 * i + 1] << endl;
if (b[2 * i] == -1 && b[2 * i + 1] == -1) {
T++;
} else {
st.insert(max(b[2 * i], b[2 * i + 1]));
cc[max(b[2 * i], b[2 * i + 1])]++;
}
}
for (int i = 0; i < 2 * m; i++) {
cc[i + 1] += cc[i];
}
dp[2 * m][0][T] = 1;
for (int k = 2 * m; k >= 1; k--) {
for (int s = 0; s <= 2 * m; s++) {
for (int t = 0; t <= T; t++) {
int u = s + 2 * t + 2 * cc[k] - k;
if (u < 0)
continue;
if (st.count(k)) {
dp[k - 1][s + 1][t] += dp[k][s][t];
dp[k - 1][s][t] += dp[k][s][t];
} else {
dp[k - 1][s][t] += dp[k][s][t];
if (t != 0)
dp[k - 1][s][t - 1] += dp[k][s][t];
// if(t!=0) dp[k-1][s+1][t-1] += dp[k][s][t];
if (s != 0)
dp[k - 1][s - 1][t] += dp[k][s][t] * s;
}
}
}
}
cout << dp[0][0][0] * fac[T] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
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;
}
template <unsigned int mod> class ModInt {
private:
unsigned int v;
static unsigned int norm(const unsigned int &x) {
return x < mod ? x : x - mod;
}
static ModInt make(const unsigned int &x) {
ModInt m;
return m.v = x, m;
}
static ModInt inv(const ModInt &x) { return make(inverse(x.v, mod)); }
static unsigned int inverse(int a, int m) {
int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
while (*v) {
t = *u / *v;
swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]),
swap(u[2] -= t * v[2], v[2]);
}
return (u[1] % m + m) % m;
}
public:
ModInt() : v{0} {}
ModInt(const long long val) : v{norm(val % mod + mod)} {}
ModInt(const ModInt<mod> &n) : v{n()} {}
explicit operator bool() const noexcept { return v != 0; }
bool operator!() const noexcept { return !static_cast<bool>(*this); }
ModInt &operator=(const ModInt &n) { return v = n(), (*this); }
ModInt &operator=(const long long val) {
return v = norm(val % mod + mod), (*this);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { return v == 0 ? make(0) : make(mod - v); }
ModInt operator+(const ModInt &val) const { return make(norm(v + val())); }
ModInt operator-(const ModInt &val) const {
return make(norm(v + mod - val()));
}
ModInt operator*(const ModInt &val) const {
return make((long long)v * val() % mod);
}
ModInt operator/(const ModInt &val) const { return *this * inv(val); }
ModInt &operator+=(const ModInt &val) { return *this = *this + val; }
ModInt &operator-=(const ModInt &val) { return *this = *this - val; }
ModInt &operator*=(const ModInt &val) { return *this = *this * val; }
ModInt &operator/=(const ModInt &val) { return *this = *this / val; }
ModInt operator+(const long long val) const { return ModInt{v + val}; }
ModInt operator-(const long long val) const { return ModInt{v - val}; }
ModInt operator*(const long long val) const {
return ModInt{(long long)v * (val % mod)};
}
ModInt operator/(const long long val) const {
return ModInt{(long long)v * inv(val)};
}
ModInt &operator+=(const long long val) { return *this = *this + val; }
ModInt &operator-=(const long long val) { return *this = *this - val; }
ModInt &operator*=(const long long val) { return *this = *this * val; }
ModInt &operator/=(const long long val) { return *this = *this / val; }
bool operator==(const ModInt &val) const { return v == val.v; }
bool operator!=(const ModInt &val) const { return !(*this == val); }
bool operator==(const long long val) const {
return v == norm(val % mod + mod);
}
bool operator!=(const long long val) const { return !(*this == val); }
unsigned int operator()() const { return v; }
friend ModInt operator+(const long long val, const ModInt &n) {
return n + val;
}
friend ModInt operator-(const long long val, const ModInt &n) {
return ModInt{val - n()};
}
friend ModInt operator*(const long long val, const ModInt &n) {
return n * val;
}
friend ModInt operator/(const long long val, const ModInt &n) {
return ModInt{val} / n;
}
friend bool operator==(const long long val, const ModInt &n) {
return n == val;
}
friend bool operator!=(const long long val, const ModInt &n) {
return !(val == n);
}
friend istream &operator>>(istream &is, ModInt &n) {
unsigned int v;
return is >> v, n = v, is;
}
friend ostream &operator<<(ostream &os, const ModInt &n) {
return (os << n());
}
friend ModInt mod_pow(ModInt x, long long n) {
ModInt ans = 1;
while (n) {
if (n & 1)
ans *= x;
x *= x, n >>= 1;
}
return ans;
}
};
#define MOD 1000000007
using mod = ModInt<MOD>;
#define MAX_N 200000
mod inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
inv[i] = MOD - inv[MOD % i] * (MOD / i);
fac[i] = fac[i - 1] * i;
finv[i] = finv[i - 1] * inv[i];
}
}
mod comb(int a, int b) {
if (a < b)
return 0;
return fac[a] * finv[b] * finv[a - b];
}
mod dp[603][603][603];
int cc[603];
int main() {
make();
int n;
cin >> n;
vector<int> a(2 * n);
rep(i, 2 * n) cin >> a[i];
vector<bool> p(2 * n + 1);
p[0] = 1;
vector<int> b;
rep(i, n) {
if (a[2 * i] != -1 && a[2 * i + 1] != -1) {
p[a[2 * i]] = 1;
p[a[2 * i + 1]] = 1;
} else {
b.push_back(a[2 * i]);
b.push_back(a[2 * i + 1]);
}
}
map<int, int> mp;
mp[-1] = -1;
int c = 1;
rep(i, 2 * n + 1) {
if (!p[i]) {
mp[i] = c;
c++;
}
}
int m = b.size();
m /= 2;
rep(i, m) {
b[2 * i] = mp[b[2 * i]];
b[2 * i + 1] = mp[b[2 * i + 1]];
}
set<int> st;
int T = 0;
rep(i, m) {
cerr << b[2 * i] << " " << b[2 * i + 1] << endl;
if (b[2 * i] == -1 && b[2 * i + 1] == -1) {
T++;
} else {
st.insert(max(b[2 * i], b[2 * i + 1]));
cc[max(b[2 * i], b[2 * i + 1])]++;
}
}
for (int i = 0; i < 2 * m; i++) {
cc[i + 1] += cc[i];
}
dp[2 * m][0][T] = 1;
for (int k = 2 * m; k >= 1; k--) {
for (int s = 0; s <= 2 * m; s++) {
for (int t = 0; t <= T; t++) {
int u = s + 2 * t + 2 * cc[k] - k;
if (u < 0)
continue;
if (st.count(k)) {
dp[k - 1][s + 1][t] += dp[k][s][t];
dp[k - 1][s][t] += dp[k][s][t];
} else {
dp[k - 1][s][t] += dp[k][s][t];
if (t != 0)
dp[k - 1][s][t - 1] += dp[k][s][t];
// if(t!=0) dp[k-1][s+1][t-1] += dp[k][s][t];
if (s != 0)
dp[k - 1][s - 1][t] += dp[k][s][t] * s;
}
}
}
}
cout << dp[0][0][0] * fac[T] << endl;
return 0;
} | replace | 177 | 179 | 177 | 179 | -11 | |
p03191 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define P 1000000007
using namespace std;
typedef long long ll;
int n, A[777], B[777];
ll F[2][333][333], Fac[777], Rev[777], bra[777];
void add(ll &x, ll y) { x = (x + y) % P; }
ll powmod(ll x, ll y = P - 2, ll p = P) {
ll ans = 1;
while (y) {
if (y & 1)
ans = ans * x % p;
x = x * x % p;
y >>= 1;
}
return ans;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n * 2; i++)
scanf("%d", &A[i]);
for (int i = 0; i <= n * 2; i++)
Fac[i] = !i ? 1 : Fac[i - 1] * i % P, Rev[i] = powmod(Fac[i]);
for (int i = 0; i <= n; i++)
bra[i] =
Fac[i * 2] * Rev[i] % P * Rev[i] % P * powmod(i + 1) % P * Fac[i] % P;
int a = 0, b = 1, cnt = 0;
for (int i = 1; i <= n * 2; i += 2) {
if (A[i] != -1 && A[i + 1] != -1) {
B[A[i]] = (B[A[i + 1]] = 2);
} else if (A[i] != -1)
B[A[i]] = 1;
else if (A[i + 1] != -1)
B[A[i + 1]] = 1;
else
cnt++;
}
memset(F, 0, sizeof F);
F[a][0][0] = 1;
for (int i = 1; i <= n * 2; i++)
if (B[i] != 2) {
memset(F[b], 0, sizeof F[b]);
for (int j = 0; j <= i; j++)
for (int k = 0; k <= i; k++)
if (F[a][j][k]) {
ll v = F[a][j][k];
if (B[i] == 0) {
if (k)
add(F[b][j][k - 1], v);
add(F[b][j][k + 1], v);
add(F[b][j + 1][k], v);
} else {
if (j)
add(F[b][j - 1][k], v * j);
add(F[b][j][k + 1], v);
}
}
swap(a, b);
}
ll ans = 0;
// for(int i = 0; i <= n; i++) ans = (ans + bra[i] * F[a][i * 2][0]) % P;
printf("%lld\n", (F[a][0][0] * Fac[cnt] % P + P) % P);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define P 1000000007
using namespace std;
typedef long long ll;
int n, A[777], B[777];
ll F[2][333][333], Fac[777], Rev[777], bra[777];
void add(ll &x, ll y) { x = (x + y) % P; }
ll powmod(ll x, ll y = P - 2, ll p = P) {
ll ans = 1;
while (y) {
if (y & 1)
ans = ans * x % p;
x = x * x % p;
y >>= 1;
}
return ans;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n * 2; i++)
scanf("%d", &A[i]);
for (int i = 0; i <= n * 2; i++)
Fac[i] = !i ? 1 : Fac[i - 1] * i % P, Rev[i] = powmod(Fac[i]);
for (int i = 0; i <= n; i++)
bra[i] =
Fac[i * 2] * Rev[i] % P * Rev[i] % P * powmod(i + 1) % P * Fac[i] % P;
int a = 0, b = 1, cnt = 0;
for (int i = 1; i <= n * 2; i += 2) {
if (A[i] != -1 && A[i + 1] != -1) {
B[A[i]] = (B[A[i + 1]] = 2);
} else if (A[i] != -1)
B[A[i]] = 1;
else if (A[i + 1] != -1)
B[A[i + 1]] = 1;
else
cnt++;
}
memset(F, 0, sizeof F);
F[a][0][0] = 1;
for (int i = 1; i <= n * 2; i++)
if (B[i] != 2) {
memset(F[b], 0, sizeof F[b]);
for (int j = 0; j <= i && j <= n; j++)
for (int k = 0; k <= i && k <= n; k++)
if (F[a][j][k]) {
ll v = F[a][j][k];
if (B[i] == 0) {
if (k)
add(F[b][j][k - 1], v);
add(F[b][j][k + 1], v);
add(F[b][j + 1][k], v);
} else {
if (j)
add(F[b][j - 1][k], v * j);
add(F[b][j][k + 1], v);
}
}
swap(a, b);
}
ll ans = 0;
// for(int i = 0; i <= n; i++) ans = (ans + bra[i] * F[a][i * 2][0]) % P;
printf("%lld\n", (F[a][0][0] * Fac[cnt] % P + P) % P);
return 0;
} | replace | 52 | 54 | 52 | 54 | 0 | |
p03191 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LL long long
#define pii pair<int, int>
using namespace std;
const int inf = 2147483647;
const int mod = 1e9 + 7;
const int N = 301;
int _max(int x, int y) { return x > y ? x : y; }
int _min(int x, int y) { return x < y ? x : y; }
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return x * f;
}
void put(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
put(x / 10);
putchar(x % 10 + '0');
}
int f[2][N][N], p[N * 2];
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int main() {
int n = read(), s = 0;
for (int i = 1; i <= n; i++) {
int x = read(), y = read();
if (x != -1 && y != -1) {
p[x] = p[y] = -1;
continue;
}
if (x != -1)
p[x] = 1;
else if (y != -1)
p[y] = 1;
else
s++;
}
int now = 0, s1 = 0, s2 = 0;
f[0][0][0] = 1;
for (int i = 2 * n; i >= 1; i--) {
if (p[i] == -1)
continue;
now ^= 1;
memset(f[now], 0, sizeof(f[now]));
for (int j = 0; j <= s1; j++)
for (int k = 0; k <= s2; k++)
if (f[now ^ 1][j][k]) {
int c = f[now ^ 1][j][k];
if (p[i]) {
if (j)
f[now][j - 1][k] = add(f[now][j - 1][k], c);
f[now][j][k + 1] = add(f[now][j][k + 1], c);
} else {
f[now][j + 1][k] = add(f[now][j + 1][k], c);
if (j)
f[now][j - 1][k] = add(f[now][j - 1][k], c);
if (k)
f[now][j][k - 1] = add(f[now][j][k - 1], (LL)c * k % mod);
}
}
s1 += p[i] == 0, s2 += p[i] == 1;
}
int ans = f[now][0][0];
for (int i = 1; i <= s; i++)
ans = (LL)ans * i % mod;
put(ans), puts("");
return 0;
}
| #include <bits/stdc++.h>
#define LL long long
#define pii pair<int, int>
using namespace std;
const int inf = 2147483647;
const int mod = 1e9 + 7;
const int N = 301;
int _max(int x, int y) { return x > y ? x : y; }
int _min(int x, int y) { return x < y ? x : y; }
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return x * f;
}
void put(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
put(x / 10);
putchar(x % 10 + '0');
}
int f[2][N][N], p[N * 2];
int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
int main() {
int n = read(), s = 0;
for (int i = 1; i <= n; i++) {
int x = read(), y = read();
if (x != -1 && y != -1) {
p[x] = p[y] = -1;
continue;
}
if (x != -1)
p[x] = 1;
else if (y != -1)
p[y] = 1;
else
s++;
}
int now = 0, s1 = 0, s2 = 0;
f[0][0][0] = 1;
for (int i = 2 * n; i >= 1; i--) {
if (p[i] == -1)
continue;
now ^= 1;
memset(f[now], 0, sizeof(f[now]));
for (int j = 0; j <= _min(s1, n); j++)
for (int k = 0; k <= _min(s2, n); k++)
if (f[now ^ 1][j][k]) {
int c = f[now ^ 1][j][k];
if (p[i]) {
if (j)
f[now][j - 1][k] = add(f[now][j - 1][k], c);
f[now][j][k + 1] = add(f[now][j][k + 1], c);
} else {
f[now][j + 1][k] = add(f[now][j + 1][k], c);
if (j)
f[now][j - 1][k] = add(f[now][j - 1][k], c);
if (k)
f[now][j][k - 1] = add(f[now][j][k - 1], (LL)c * k % mod);
}
}
s1 += p[i] == 0, s2 += p[i] == 1;
}
int ans = f[now][0][0];
for (int i = 1; i <= s; i++)
ans = (LL)ans * i % mod;
put(ans), puts("");
return 0;
}
| replace | 60 | 62 | 60 | 62 | 0 | |
p03191 | C++ | Runtime Error | #include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
} // namespace RA
/******************heading******************/
const int N = 305, P = 1e9 + 7;
int n, tot;
int typ[N]; // 1:已确定;0:(-1,-1);-1:(-1,x)
int f[N * 2][N][N]; //
int main() {
scanf("%d", &n);
FOR(i, 1, n) {
int x, y;
scanf("%d%d", &x, &y);
if (x != -1 && y != -1)
typ[x] = typ[y] = 1;
else if (x == -1 && y == -1)
++tot;
else if (x != -1)
typ[x] = -1;
else
typ[y] = -1;
}
f[n * 2 + 1][0][0] = 1;
ROF(i, n * 2, 0) {
if (typ[i] == 1)
memcpy(f[i], f[i + 1], sizeof(f[i + 1]));
else if (typ[i] == 0) {
FOR(j, 0, n) FOR(k, 0, n) {
f[i][j][k + 1] =
(f[i][j][k + 1] + f[i + 1][j][k]) % P; // 添加一个普通括号
if (j)
f[i][j - 1][k] = (f[i][j - 1][k] + f[i + 1][j][k] * 1ll * j) %
P; // 匹配一个特殊括号
if (k)
f[i][j][k - 1] =
(f[i][j][k - 1] + f[i + 1][j][k]) % P; // 匹配一个普通括号
}
} else {
FOR(j, 0, n) FOR(k, 0, n) {
f[i][j + 1][k] =
(f[i][j + 1][k] + f[i + 1][j][k]) % P; // 添加一个特殊括号
if (k)
f[i][j][k - 1] =
(f[i][j][k - 1] + f[i + 1][j][k]) % P; // 匹配一个普通括号
}
}
}
int ans = f[1][0][0];
FOR(i, 1, tot) ans = 1ll * ans * i % P;
printf("%d\n", ans);
return 0;
}
| #include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
} // namespace RA
/******************heading******************/
const int N = 305, P = 1e9 + 7;
int n, tot;
int typ[N * 2]; // 1:已确定;0:(-1,-1);-1:(-1,x)
int f[N * 2][N][N]; //
int main() {
scanf("%d", &n);
FOR(i, 1, n) {
int x, y;
scanf("%d%d", &x, &y);
if (x != -1 && y != -1)
typ[x] = typ[y] = 1;
else if (x == -1 && y == -1)
++tot;
else if (x != -1)
typ[x] = -1;
else
typ[y] = -1;
}
f[n * 2 + 1][0][0] = 1;
ROF(i, n * 2, 0) {
if (typ[i] == 1)
memcpy(f[i], f[i + 1], sizeof(f[i + 1]));
else if (typ[i] == 0) {
FOR(j, 0, n) FOR(k, 0, n) {
f[i][j][k + 1] =
(f[i][j][k + 1] + f[i + 1][j][k]) % P; // 添加一个普通括号
if (j)
f[i][j - 1][k] = (f[i][j - 1][k] + f[i + 1][j][k] * 1ll * j) %
P; // 匹配一个特殊括号
if (k)
f[i][j][k - 1] =
(f[i][j][k - 1] + f[i + 1][j][k]) % P; // 匹配一个普通括号
}
} else {
FOR(j, 0, n) FOR(k, 0, n) {
f[i][j + 1][k] =
(f[i][j + 1][k] + f[i + 1][j][k]) % P; // 添加一个特殊括号
if (k)
f[i][j][k - 1] =
(f[i][j][k - 1] + f[i + 1][j][k]) % P; // 匹配一个普通括号
}
}
}
int ans = f[1][0][0];
FOR(i, 1, tot) ans = 1ll * ans * i % P;
printf("%d\n", ans);
return 0;
}
| replace | 28 | 29 | 28 | 29 | -11 | |
p03192 | C++ | Runtime Error | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char const *argv[]) {
char s[4] = {'\0'};
int n, count = 0, ret;
ret = scanf("%d", &n);
sprintf(s, "%d", n);
for (int i = 0; i < 4; i++) {
if (s[i] == '2')
count++;
}
printf("%d\n", count);
return 0;
}
| #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char const *argv[]) {
char s[5];
int n, count = 0, ret;
ret = scanf("%d", &n);
sprintf(s, "%d", n);
for (int i = 0; i < 4; i++) {
if (s[i] == '2')
count++;
}
printf("%d\n", count);
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03192 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define co(n) cout << n << endl
using namespace std;
int main() {
string s;
int c = 0;
rep(i, 0, 4) if (s.at(i) == '2') c++;
co(c);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define co(n) cout << n << endl
using namespace std;
int main() {
string s;
cin >> s;
int c = 0;
rep(i, 0, 4) if (s.at(i) == '2') c++;
co(c);
return 0;
}
| insert | 6 | 6 | 6 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p03192 | Python | Runtime Error | def main(n):
print(str(n).count("2"))
if __name__ == "__main__":
n = int(input())
main()
| def main(n):
print(str(n).count("2"))
if __name__ == "__main__":
n = int(input())
main(n)
| replace | 6 | 7 | 6 | 7 | TypeError: main() missing 1 required positional argument: 'n' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03192/Python/s987134769.py", line 7, in <module>
main()
TypeError: main() missing 1 required positional argument: 'n'
|
p03192 | C++ | Runtime Error | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char const *argv[]) {
char s[4];
int n, count = 0, ret;
ret = scanf("%d", &n);
sprintf(s, "%d", n);
for (int i = 0; i < 4; i++) {
if (s[i] == '2')
count++;
}
printf("%d\n", count);
return 0;
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char const *argv[]) {
char s[5];
int n, count = 0, ret;
ret = scanf("%d", &n);
sprintf(s, "%d", n);
for (int i = 0; i < 4; i++) {
if (s[i] == '2')
count++;
}
printf("%d\n", count);
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03193 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, H, W;
cin >> N >> H >> W;
vector<vector<long long>> vec(H, vector<long long>(W));
for (int i = 0; i < N; i++) {
for (int j = 0; j < 2; j++) {
cin >> vec.at(i).at(j);
}
}
int ans = 0;
for (int k = 0; k < N; k++) {
if ((vec.at(k).at(0) >= H) && (vec.at(k).at(1) >= W)) {
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, H, W;
cin >> N >> H >> W;
vector<vector<long long>> vec(N, vector<long long>(2));
for (int i = 0; i < N; i++) {
for (int j = 0; j < 2; j++) {
cin >> vec.at(i).at(j);
}
}
int ans = 0;
for (int k = 0; k < N; k++) {
if ((vec.at(k).at(0) >= H) && (vec.at(k).at(1) >= W)) {
ans++;
}
}
cout << ans << endl;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03193 | Python | Runtime Error | def read():
N, H, W = list(map(int, input().strip().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().strip().split()))
A.append(a)
B.append(b)
return N, H, W, A, B
def solve(N, H, W, A, B):
count = 0
for i in range(N):
if A[i] >= H and B[i] >= W:
count += 1
return count
if __name__ == "__main__":
inputs = read()
print(solve(inputs))
| def read():
N, H, W = list(map(int, input().strip().split()))
A = []
B = []
for i in range(N):
a, b = list(map(int, input().strip().split()))
A.append(a)
B.append(b)
return N, H, W, A, B
def solve(N, H, W, A, B):
count = 0
for i in range(N):
if A[i] >= H and B[i] >= W:
count += 1
return count
if __name__ == "__main__":
inputs = read()
print(solve(*inputs))
| replace | 21 | 22 | 21 | 22 | TypeError: solve() missing 4 required positional arguments: 'H', 'W', 'A', and 'B' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03193/Python/s433009043.py", line 22, in <module>
print(solve(inputs))
TypeError: solve() missing 4 required positional arguments: 'H', 'W', 'A', and 'B'
|
p03193 | C++ | Runtime Error | #include <cstdio>
#include <ctype.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, count = 0;
int H, W;
cin >> N >> H >> W;
long int A[H], B[W];
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
if (A[i] >= H && B[i] >= W) {
count++;
}
}
cout << count << endl;
return 0;
} | #include <cstdio>
#include <ctype.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, count = 0;
int H, W;
cin >> N >> H >> W;
long int A[N], B[N];
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
if (A[i] >= H && B[i] >= W) {
count++;
}
}
cout << count << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;
#ifdef INPUT
stringstream input(R"(
4 972439611840
)");
#define cin input
#endif
std::map<long long, int> primeFactors(long long n) {
std::map<long long, int> m;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
++m[i];
n /= i;
}
}
if (n > 1)
++m[n];
return m;
}
int main() {
ll n, p, a;
ll ans = 1;
cin >> n >> p;
if (n == 1)
ans = p;
else if (p == 1)
ans = 1;
else {
const auto m = primeFactors(p);
for (const auto &i : m) {
for (int j = 0; j < i.second / n; j++) {
ans *= i.first;
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;
#ifdef INPUT
stringstream input(R"(
4 972439611840
)");
#define cin input
#endif
std::map<long long, int> primeFactors(long long n) {
std::map<long long, int> m;
for (long long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
++m[i];
n /= i;
}
}
if (n > 1)
++m[n];
return m;
}
int main() {
ll n, p, a;
ll ans = 1;
cin >> n >> p;
if (n == 1)
ans = p;
else if (p == 1)
ans = 1;
else {
const auto m = primeFactors(p);
for (const auto &i : m) {
for (int j = 0; j < i.second / n; j++) {
ans *= i.first;
}
}
}
cout << ans << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p03194 | C++ | Time Limit Exceeded | // Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
#ifdef LOCAL
freopen("./input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, P;
cin >> N >> P;
if (N == 1) {
cout << P << endl;
return 0;
}
ll p = P;
ll divisor = 2;
ll ans = 1;
while (p && divisor < p) {
while (p % divisor != 0) {
divisor++;
}
int cnt = 0;
while (p % divisor == 0) {
p = p / divisor;
++cnt;
}
ans *= pow(divisor, cnt / N);
}
cout << ans << endl;
return 0;
}
| // Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
#ifdef LOCAL
freopen("./input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, P;
cin >> N >> P;
if (N == 1) {
cout << P << endl;
return 0;
}
ll p = P;
ll divisor = 2;
ll ans = 1;
while (p && pow(divisor, N) <= p) {
while (p % divisor != 0) {
divisor++;
}
int cnt = 0;
while (p % divisor == 0) {
p = p / divisor;
++cnt;
}
ans *= pow(divisor, cnt / N);
}
cout << ans << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p03194 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005], b[1005];
ll zyou(ll i, ll n) {
ll k = 1;
while (n > 0) {
if (n & 1)
k = k * i;
i = i * i;
n >>= 1;
}
return k;
}
int main(void) {
ll n, p;
cin >> n >> p;
ll ans = 1;
if (n == 1) {
cout << p << endl;
return 0;
}
for (ll i = 2; zyou(i, n) <= p; i++) {
while (p % zyou(i, n) == 0) {
ans = ans * i;
p = p / zyou(i, n);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005], b[1005];
ll zyou(ll i, ll n) {
ll k = 1;
while (n > 0) {
if (n & 1)
k = k * i;
i = i * i;
n >>= 1;
}
return k;
}
int main(void) {
ll n, p;
cin >> n >> p;
ll ans = 1;
if (n == 1) {
cout << p << endl;
return 0;
}
if (n >= 40) {
cout << 1 << endl;
return 0;
}
for (ll i = 2; zyou(i, n) <= p; i++) {
while (p % zyou(i, n) == 0) {
ans = ans * i;
p = p / zyou(i, n);
}
}
cout << ans << endl;
}
| insert | 22 | 22 | 22 | 26 | 0 | |
p03194 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N, P;
cin >> N >> P;
ll i = 2, l = 1;
while (P != 1) {
if (P % i == 0) {
ll ni = 0;
while (P % i == 0) {
ni++;
P /= i;
}
l *= pow(i, ni / N);
} else {
i++;
}
}
cout << l << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N, P;
cin >> N >> P;
ll i = 2, l = 1;
while (P != 1) {
if (P % i == 0) {
ll ni = 0;
while (P % i == 0) {
ni++;
P /= i;
}
l *= pow(i, ni / N);
} else if (i * i > P) {
if (N == 1)
l *= P;
break;
} else {
i++;
}
}
cout << l << endl;
} | insert | 17 | 17 | 17 | 21 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll, ll>> v;
int main() {
ll n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
ll ans = 1;
for (ll i = 2;;) {
ll po = pow(i, n);
if (po > p) {
break;
} else if (p % po == 0) {
p /= po;
ans *= i;
} else {
i++;
}
}
cout << ans << endl;
return 0;
}
| #include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll, ll>> v;
int main() {
ll n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
if (n >= 40) {
cout << 1 << endl;
return 0;
}
ll ans = 1;
for (ll i = 2;;) {
ll po = pow(i, n);
if (po > p) {
break;
} else if (p % po == 0) {
p /= po;
ans *= i;
} else {
i++;
}
}
cout << ans << endl;
return 0;
}
| insert | 16 | 16 | 16 | 21 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll N, P, kN;
cin >> N >> P;
ll k = 2;
ll ans = 1;
while (P >= pow(k, N)) {
kN = pow(k, N);
if (P % kN == 0) {
P /= kN;
ans *= k;
} else {
k++;
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll N, P, kN;
cin >> N >> P;
ll k = 2;
ll ans = 1;
if (N == 1)
ans = P;
else {
while (P >= pow(k, N)) {
kN = pow(k, N);
if (P % kN == 0) {
P /= kN;
ans *= k;
} else {
k++;
}
}
}
cout << ans << endl;
}
| replace | 19 | 26 | 19 | 30 | TLE | |
p03194 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
// cout << fixed << std::setprecision(9)
// memset(a, 0, sizeof(a));
//--------------------------
ll Pow(ll x, ll k) {
if (k == 0)
return 1;
if (k % 2 == 0)
return Pow(x * x, k / 2);
else
return x * Pow(x, k - 1);
}
int main() {
ll n, p;
ll ans = 1;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
ll a = 2;
while (a * a <= p) {
if (p % a == 0) {
ll div = Pow(a, n);
while (p % div == 0) {
p /= div;
ans *= a;
}
}
a++;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
// cout << fixed << std::setprecision(9)
// memset(a, 0, sizeof(a));
//--------------------------
ll Pow(ll x, ll k) {
if (k == 0)
return 1;
if (k % 2 == 0)
return Pow(x * x, k / 2);
else
return x * Pow(x, k - 1);
}
int main() {
ll n, p;
ll ans = 1;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
if (n > 40) {
cout << 1 << endl;
return 0;
}
ll a = 2;
while (a * a <= p) {
if (p % a == 0) {
ll div = Pow(a, n);
while (p % div == 0) {
p /= div;
ans *= a;
}
}
a++;
}
cout << ans << endl;
return 0;
}
| insert | 44 | 44 | 44 | 49 | 0 | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007
using namespace std;
int main(void) {
long long n, p, temp, ans = 1;
int count = 0;
cin >> n >> p;
if (n >= 40) {
cout << 1 << endl;
return 0;
}
for (long long i = 2; i <= p; i++) {
temp = 1;
for (int j = 0; j < n; j++)
temp *= i;
while (p % temp == 0) {
ans *= i;
p /= temp;
}
while (p % i == 0)
p /= i;
if (temp >= p)
break;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007
using namespace std;
int main(void) {
long long n, p, temp, ans = 1;
int count = 0;
cin >> n >> p;
if (n >= 40) {
cout << 1 << endl;
return 0;
}
if (n == 1) {
cout << p << endl;
return 0;
}
for (long long i = 2; i <= p; i++) {
temp = 1;
for (int j = 0; j < n; j++)
temp *= i;
while (p % temp == 0) {
ans *= i;
p /= temp;
}
while (p % i == 0)
p /= i;
if (temp >= p)
break;
}
cout << ans << endl;
return 0;
}
| insert | 19 | 19 | 19 | 23 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int main() {
long n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
} else if (n >= 40) {
cout << 1 << endl;
return 0;
}
int cnt = 0;
int ans = 1;
for (int i = 2; i <= p; i++) {
// cout << "A" << i << endl;
while ((p % i) == 0) {
p /= i;
cnt++;
// cout << "b p;" << p << "cnt" << cnt << endl;
}
while (cnt >= n) {
ans *= i;
cnt -= n;
}
cnt = 0;
}
cout << ans << endl;
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
long n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
} else if (n >= 40) {
cout << 1 << endl;
return 0;
}
int cnt = 0;
int ans = 1;
for (int i = 2; i <= p && i <= 1000000; i++) {
// cout << "A" << i << endl;
while ((p % i) == 0) {
p /= i;
cnt++;
// cout << "b p;" << p << "cnt" << cnt << endl;
}
while (cnt >= n) {
ans *= i;
cnt -= n;
}
cnt = 0;
}
cout << ans << endl;
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <valarray>
#include <vector>
using ll = long long;
using ull = unsigned long long;
// vector
template <class T> using vec = std::vector<T>;
template <class T> using vvec = vec<vec<T>>;
constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }
ll pow_n(ll l, ll n, ll p) {
if (l > 1000000 && n >= 2)
return -1;
ll ret{1};
for (ll i = 0; i < n; ++i) {
ret *= l;
if (ret > p || ret < 0) {
ret = -1;
break;
}
}
return ret;
}
int main() {
using namespace std;
ll n, p;
cin >> n >> p;
ll ans{1};
for (ll i = 2; pow_n(i, n, p) > 0; ++i) {
auto po = pow_n(i, n, p);
if (p % po == 0)
ans = i;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <valarray>
#include <vector>
using ll = long long;
using ull = unsigned long long;
// vector
template <class T> using vec = std::vector<T>;
template <class T> using vvec = vec<vec<T>>;
constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }
ll pow_n(ll l, ll n, ll p) {
if (l > 1000000 && n >= 2)
return -1;
ll ret{1};
for (ll i = 0; i < n; ++i) {
ret *= l;
if (ret > p || ret < 0) {
ret = -1;
break;
}
}
return ret;
}
int main() {
using namespace std;
ll n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
ll ans{1};
for (ll i = 2; pow_n(i, n, p) > 0; ++i) {
auto po = pow_n(i, n, p);
if (p % po == 0)
ans = i;
}
cout << ans << endl;
return 0;
}
| insert | 59 | 59 | 59 | 64 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);
int main(void) {
ll N = 0;
ll A = 0;
ll B = 0;
ll C = 0;
ll D = 0;
ll P = 0;
// ll T = 0;
// ll M = 0;
ll h[1000] = {};
// ll b[100] = {};
// ll c[100] = {};
// ll d[100] = {};
// ll v[3] = {};
// ll *c, *s, *n;
string S[50], T[50], U[52];
ll count = 0;
ll count2 = 0;
float sum = 0;
ll min = 1000000000000;
ll max = 1;
ll smax = 0;
ll max2 = 0;
ll smax2 = 0;
int tmax = 0;
int tmax2 = 0;
// int flag = 0;
char temp, head;
// int is = 0;
bool flag = false;
// char p;
ll all = 0;
ll niku = 0;
ll state = 2;
bool down = true;
// cin >> S;
vector<pair<int, int>> ch(1000);
cin >> N >> P;
if (N == 1) {
cout << P << endl;
return 0;
}
down = IsPrime(P);
if (down == true) {
cout << 1 << endl;
return 0;
}
while (P % 2 == 0) {
P /= 2;
// cout << P << endl;
if (count != (N - 1)) {
count++;
// cout << "N =" << 2 << endl;
} else {
max *= 2;
// cout << "N =" << 2 << endl;
count = 0;
}
}
count = 0;
for (int i = 3; i < P; i += 2) {
/*if ((i % 3 == 0) || (i % 5 == 0) || (i % 7 == 0) || (i % 11 == 0) || (i %
13 == 0) || (i % 17 == 0) || (i % 19 == 0) || (i % 23 == 0) || (i % 29 == 0)
|| (i % 31 == 0) || (i % 37 == 0) || (i % 41 == 0) || (i % 43 == 0) || (i %
47 == 0) || (i % 53 == 0) || (i % 59 == 0) || (i % 61 == 0) || (i % 67 == 0)
|| (i % 71 == 0) || (i % 73 == 0) || (i % 79 == 0) || (i % 83 == 0) || (i %
89 == 0) || (i % 97 == 0) || (i % 101 == 0) || (i % 103 == 0) || (i % 107 ==
0)) { i += 2;
}*/
while (P % i == 0) {
P /= i;
// cout << P << endl;
if (count != (N - 1)) {
count++;
// cout << "N=" << i << endl;
} else {
max *= i;
// cout << "N=" <<i << endl;
count = 0;
}
}
count = 0;
down = IsPrime(P);
if (down == true) {
cout << max << endl;
return 0;
}
}
cout << max << endl;
// x = (ll *)malloc((N+1) * sizeof(ll));
// c = (ll *)malloc((N) * sizeof(ll));
// cin >> D >> G;
// vector<pair<int,int>> tr(M);
// vector<pair<int,int>> qes(Q);
// sort(c.begin(), c.end());
// cout << c[2] - c[1] << endl;
/*A = N / 1000;
N %= 1000;
B = N / 100;
N %= 100;
C = N / 10;
N %= 10;
D = N;*/
// cin >> N >> M;
// vector<pair<int,int>> c(M);
////vector<pair<int, int>> e(M);
// vector<ll> d(M);
// rep(i, 0, M) {
// cin >> c[i].first >> c[i].second;
// //e[i].first = c[i].first;
// //e[i].second = c[i].second;
//}
////sort(c.begin(), c.end());
//
// rep(i, 0, M) {
//
//
// rep(j, 0, M) {
// if (c[i].first == c[j].first && c[j].second < c[i].second) {
// d[i]++;
// //cout << j << endl;
// }
// }
// cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
// cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 <<
//endl;
//}
return 0;
}
ll bur(ll N, ll X) {
ll pan = 1;
ll pat = 1;
ll burg = 0;
if (X > burg) {
if (N == 0)
return pat;
burg += pan;
burg += bur(N - 1, X);
burg += pat;
burg += bur(N - 1, X);
burg += pan;
}
return burg;
}
ll gcd(ll a, ll b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll x = b;
ll y = a;
/* ユークリッドの互除法 */
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return y / b * x;
}
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);
int main(void) {
ll N = 0;
ll A = 0;
ll B = 0;
ll C = 0;
ll D = 0;
ll P = 0;
// ll T = 0;
// ll M = 0;
ll h[1000] = {};
// ll b[100] = {};
// ll c[100] = {};
// ll d[100] = {};
// ll v[3] = {};
// ll *c, *s, *n;
string S[50], T[50], U[52];
ll count = 0;
ll count2 = 0;
float sum = 0;
ll min = 1000000000000;
ll max = 1;
ll smax = 0;
ll max2 = 0;
ll smax2 = 0;
int tmax = 0;
int tmax2 = 0;
// int flag = 0;
char temp, head;
// int is = 0;
bool flag = false;
// char p;
ll all = 0;
ll niku = 0;
ll state = 2;
bool down = true;
// cin >> S;
vector<pair<int, int>> ch(1000);
cin >> N >> P;
if (N == 1) {
cout << P << endl;
return 0;
}
down = IsPrime(P);
if (down == true) {
cout << 1 << endl;
return 0;
}
while (P % 2 == 0) {
P /= 2;
// cout << P << endl;
if (count != (N - 1)) {
count++;
// cout << "N =" << 2 << endl;
} else {
max *= 2;
// cout << "N =" << 2 << endl;
count = 0;
}
}
count = 0;
for (int i = 3; i < P; i += 2) {
/*if ((i % 3 == 0) || (i % 5 == 0) || (i % 7 == 0) || (i % 11 == 0) || (i %
13 == 0) || (i % 17 == 0) || (i % 19 == 0) || (i % 23 == 0) || (i % 29 == 0)
|| (i % 31 == 0) || (i % 37 == 0) || (i % 41 == 0) || (i % 43 == 0) || (i %
47 == 0) || (i % 53 == 0) || (i % 59 == 0) || (i % 61 == 0) || (i % 67 == 0)
|| (i % 71 == 0) || (i % 73 == 0) || (i % 79 == 0) || (i % 83 == 0) || (i %
89 == 0) || (i % 97 == 0) || (i % 101 == 0) || (i % 103 == 0) || (i % 107 ==
0)) { i += 2;
}*/
while (P % i == 0) {
P /= i;
// cout << P << endl;
if (count != (N - 1)) {
count++;
// cout << "N=" << i << endl;
} else {
max *= i;
// cout << "N=" <<i << endl;
count = 0;
}
}
count = 0;
down = IsPrime(P);
if (down == true) {
cout << max << endl;
return 0;
}
if (i > 100000)
break;
}
cout << max << endl;
// x = (ll *)malloc((N+1) * sizeof(ll));
// c = (ll *)malloc((N) * sizeof(ll));
// cin >> D >> G;
// vector<pair<int,int>> tr(M);
// vector<pair<int,int>> qes(Q);
// sort(c.begin(), c.end());
// cout << c[2] - c[1] << endl;
/*A = N / 1000;
N %= 1000;
B = N / 100;
N %= 100;
C = N / 10;
N %= 10;
D = N;*/
// cin >> N >> M;
// vector<pair<int,int>> c(M);
////vector<pair<int, int>> e(M);
// vector<ll> d(M);
// rep(i, 0, M) {
// cin >> c[i].first >> c[i].second;
// //e[i].first = c[i].first;
// //e[i].second = c[i].second;
//}
////sort(c.begin(), c.end());
//
// rep(i, 0, M) {
//
//
// rep(j, 0, M) {
// if (c[i].first == c[j].first && c[j].second < c[i].second) {
// d[i]++;
// //cout << j << endl;
// }
// }
// cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
// cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 <<
//endl;
//}
return 0;
}
ll bur(ll N, ll X) {
ll pan = 1;
ll pat = 1;
ll burg = 0;
if (X > burg) {
if (N == 0)
return pat;
burg += pan;
burg += bur(N - 1, X);
burg += pat;
burg += bur(N - 1, X);
burg += pan;
}
return burg;
}
ll gcd(ll a, ll b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll x = b;
ll y = a;
/* ユークリッドの互除法 */
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return y / b * x;
}
bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
} | insert | 135 | 135 | 135 | 138 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int mod = 1e9 + 7;
int main() {
ll n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
ll ans = 1;
for (int i = 2; i * i <= p; i++) {
ll cnt = 0;
while (p % i == 0) {
p /= i;
cnt++;
if (cnt % n == 0)
ans *= i;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int mod = 1e9 + 7;
int main() {
ll n, p;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
ll ans = 1;
for (int i = 2; pow(i, n) <= p; i++) {
while (p % (ll)pow(i, n) == 0) {
p /= pow(i, n);
ans *= i;
}
}
cout << ans << endl;
return 0;
} | replace | 18 | 25 | 18 | 22 | TLE | |
p03194 | C++ | Runtime Error | #ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif
// 継承可能な型
template <class Type> struct IN : Type {
IN() { std::cin >> *this; }
};
// 継承不可能な型
template <class Type> struct IN_ {
Type val;
IN_() { std::cin >> val; }
operator Type &() { return val; }
IN_<Type> &operator=(const Type &_value) {
val = _value;
return *this;
}
};
template <class Char, class Type>
std::basic_ostream<Char> &operator<<(std::basic_ostream<Char> &os,
const IN_<Type> &value) {
return os << value.val;
}
template <class Char, class Type>
std::basic_istream<Char> &operator>>(std::basic_istream<Char> &is,
IN_<Type> &value) {
return is >> value.val;
}
template <class Type> void OUT(const Type &value) {
std::cout << value << std::endl;
}
template <class Type, class... Args>
void OUT(const Type &value, const Args &...args) {
std::cout << value << ' ';
OUT(args...);
}
void YES() { OUT("YES"); }
void NO() { OUT("NO"); }
void YESNO(const bool cond) { OUT(cond ? "YES" : "NO"); }
void Yes() { OUT("Yes"); }
void No() { OUT("No"); }
void YesNo(const bool cond) { OUT(cond ? "Yes" : "No"); }
using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using P = std::pair<ll, ll>;
using instr = IN<std::string>;
// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n) {
for (ll i = n - 1; i > 1; --i)
n *= i;
return n;
}
// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r) {
if (r * 2 > n)
r = n - r;
ll dividend = 1, divisor = 1;
for (ll i = 1; i <= r; ++i) {
dividend *= n - i + 1;
divisor *= i;
}
return dividend / divisor;
}
// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num) {
if (num < 2)
return false;
if (num == 2)
return true;
if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n) {
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 2つの数の最大公約数を求める
ll gcd(ll m, ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// ユークリッドの方法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
// 2つの数の最小公倍数を求める
ll lcm(const ll m, const ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// lcm = m * n / gcd(m,n)
return m / gcd(m, n) * n;
}
// 3以上の数の最大公約数を求める
template <class Container> ll gcd(const Container &v) {
ll res = *std::begin(v);
for (const auto &i : v) {
res = gcd(res, i);
}
return res;
}
// 3以上の数の最小公倍数を求める
template <class Container> ll lcm(const Container &v) {
ll res = *std::begin(v);
for (const auto &i : v) {
res = lcm(res, i);
}
return res;
}
// 結果を切り上げる除算
ll divup(const ll a, const ll b) { return (a + b - 1) / b; }
ll inrange(const ll x, const ll y, const ll w, const ll h) {
return 0 <= x && x < w && 0 <= y && y < h;
}
// 指数が整数のpow
// https://kazu-yamamoto.hatenablog.jp/entry/20090223/1235372875
template <typename Type> Type pow_i(const Type x, const ll n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return pow_i(x * x, n / 2);
else
return x * pow_i(x, n - 1);
}
// 指数が整数のpow (mを法として)
// http://augusuto04.hatenablog.com/entry/2015/05/02/183451
ll pow_im(const ll x, const ll n, const ll m) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return pow_im(x * x % m, n / 2, m);
else
return x * pow_im(x, n - 1, m) % m;
}
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18;
const ll dy[] = {0, 0, 1, -1};
const ll dx[] = {1, -1, 0, 0};
#define FOR(i, m, n) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll(i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto(it) = (v).rbegin(); (it) != (v).rend(); ++(it))
void Main();
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
Main();
#ifdef _DEBUG
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << std::endl << "Press Enter key to continue...";
std::cin.get();
#endif
return 0;
}
using namespace std;
//////////////////////////////
void Main() {
inll n, p;
if (n == 1)
return OUT(p);
ll i = (pow((double)p, 1.0 / (double)n) + 1.0);
for (; i >= 1; i--) {
if (p % pow_i(i, n) == 0)
return OUT(i);
}
return OUT(1);
}
| #ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif
// 継承可能な型
template <class Type> struct IN : Type {
IN() { std::cin >> *this; }
};
// 継承不可能な型
template <class Type> struct IN_ {
Type val;
IN_() { std::cin >> val; }
operator Type &() { return val; }
IN_<Type> &operator=(const Type &_value) {
val = _value;
return *this;
}
};
template <class Char, class Type>
std::basic_ostream<Char> &operator<<(std::basic_ostream<Char> &os,
const IN_<Type> &value) {
return os << value.val;
}
template <class Char, class Type>
std::basic_istream<Char> &operator>>(std::basic_istream<Char> &is,
IN_<Type> &value) {
return is >> value.val;
}
template <class Type> void OUT(const Type &value) {
std::cout << value << std::endl;
}
template <class Type, class... Args>
void OUT(const Type &value, const Args &...args) {
std::cout << value << ' ';
OUT(args...);
}
void YES() { OUT("YES"); }
void NO() { OUT("NO"); }
void YESNO(const bool cond) { OUT(cond ? "YES" : "NO"); }
void Yes() { OUT("Yes"); }
void No() { OUT("No"); }
void YesNo(const bool cond) { OUT(cond ? "Yes" : "No"); }
using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using P = std::pair<ll, ll>;
using instr = IN<std::string>;
// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n) {
for (ll i = n - 1; i > 1; --i)
n *= i;
return n;
}
// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r) {
if (r * 2 > n)
r = n - r;
ll dividend = 1, divisor = 1;
for (ll i = 1; i <= r; ++i) {
dividend *= n - i + 1;
divisor *= i;
}
return dividend / divisor;
}
// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num) {
if (num < 2)
return false;
if (num == 2)
return true;
if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (ll i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n) {
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 2つの数の最大公約数を求める
ll gcd(ll m, ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// ユークリッドの方法
while (m != n) {
if (m > n)
m = m - n;
else
n = n - m;
}
return m;
}
// 2つの数の最小公倍数を求める
ll lcm(const ll m, const ll n) {
// 引数に0がある場合は0を返す
if (m == 0 || n == 0)
return 0;
// lcm = m * n / gcd(m,n)
return m / gcd(m, n) * n;
}
// 3以上の数の最大公約数を求める
template <class Container> ll gcd(const Container &v) {
ll res = *std::begin(v);
for (const auto &i : v) {
res = gcd(res, i);
}
return res;
}
// 3以上の数の最小公倍数を求める
template <class Container> ll lcm(const Container &v) {
ll res = *std::begin(v);
for (const auto &i : v) {
res = lcm(res, i);
}
return res;
}
// 結果を切り上げる除算
ll divup(const ll a, const ll b) { return (a + b - 1) / b; }
ll inrange(const ll x, const ll y, const ll w, const ll h) {
return 0 <= x && x < w && 0 <= y && y < h;
}
// 指数が整数のpow
// https://kazu-yamamoto.hatenablog.jp/entry/20090223/1235372875
template <typename Type> Type pow_i(const Type x, const ll n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return pow_i(x * x, n / 2);
else
return x * pow_i(x, n - 1);
}
// 指数が整数のpow (mを法として)
// http://augusuto04.hatenablog.com/entry/2015/05/02/183451
ll pow_im(const ll x, const ll n, const ll m) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return pow_im(x * x % m, n / 2, m);
else
return x * pow_im(x, n - 1, m) % m;
}
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18;
const ll dy[] = {0, 0, 1, -1};
const ll dx[] = {1, -1, 0, 0};
#define FOR(i, m, n) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll(i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto(it) = (v).rbegin(); (it) != (v).rend(); ++(it))
void Main();
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
Main();
#ifdef _DEBUG
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << std::endl << "Press Enter key to continue...";
std::cin.get();
#endif
return 0;
}
using namespace std;
//////////////////////////////
void Main() {
inll n, p;
if (n == 1)
return OUT(p);
ll i = (pow((double)p, 1.0 / (double)n) + 1.0);
for (; i >= 1; i--) {
if (p % (ll)pow((double)i, (double)n) == 0)
return OUT(i);
}
return OUT(1);
}
| replace | 227 | 228 | 227 | 228 | 0 | |
p03194 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll beki(ll a, ll n) {
if (n == 0) {
return 1;
}
ll ans = beki(a, n / 2);
ans = ans * ans;
if (n % 2 == 1)
ans = ans * a;
return ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, P;
cin >> N >> P;
if (N == 1) {
cout << P << endl;
return 0;
}
if (P == 1) {
cout << 1 << endl;
return 0;
}
ll ans = 1;
for (ll i = 1; beki(i, N) <= P; i++) {
ll c = beki(i, N);
if (P % c == 0)
ans = i;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll beki(ll a, ll n) {
if (n == 0) {
return 1;
}
ll ans = beki(a, n / 2);
ans = ans * ans;
if (n % 2 == 1)
ans = ans * a;
return ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, P;
cin >> N >> P;
if (N == 1) {
cout << P << endl;
return 0;
}
if (N >= 41) {
cout << 1 << endl;
return 0;
}
if (P == 1) {
cout << 1 << endl;
return 0;
}
ll ans = 1;
for (ll i = 1; beki(i, N) <= P; i++) {
ll c = beki(i, N);
if (P % c == 0)
ans = i;
}
cout << ans << endl;
return 0;
} | insert | 70 | 70 | 70 | 74 | 0 | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll fastPow(ll i, ll x) {
if (x == 0)
return 1LL;
if (x % 2 == 1)
return i * fastPow(i, x - 1);
else {
ll ret = fastPow(i, x / 2);
return ret * ret;
}
}
int main() {
ll n, p;
cin >> n >> p;
ll ans = 0;
for (ll i = 1; pow(i, n) <= p; i++) {
ll D = fastPow(i, n);
if (p % D == 0)
ans = max(ans, i);
}
cout << ans;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll fastPow(ll i, ll x) {
if (x == 0)
return 1LL;
if (x % 2 == 1)
return i * fastPow(i, x - 1);
else {
ll ret = fastPow(i, x / 2);
return ret * ret;
}
}
int main() {
ll n, p;
cin >> n >> p;
ll ans = 0;
if (p == 1) {
cout << 1;
return 0;
}
if (n == 1) {
cout << p;
return 0;
}
for (ll i = 1; pow(i, n) <= p; i++) {
ll D = fastPow(i, n);
if (p % D == 0)
ans = max(ans, i);
}
cout << ans;
} | insert | 27 | 27 | 27 | 35 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
long long n, p;
cin >> n >> p;
long long ans = 1;
if (n == 1) {
cout << p << endl;
return 0;
}
for (int i = 2; i * i <= p; ++i) {
int cnt = 0;
while (p % i == 0) {
cnt++;
p /= i;
if (cnt == n) {
ans *= i;
cnt = 0;
}
}
}
cout << ans << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
long long n, p;
cin >> n >> p;
long long ans = 1;
if (n == 1) {
cout << p << endl;
return 0;
}
for (long long i = 2; i * i <= p; ++i) {
int cnt = 0;
while (p % i == 0) {
cnt++;
p /= i;
if (cnt == n) {
ans *= i;
cnt = 0;
}
}
}
cout << ans << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
class question {
public:
ll N, P;
ll pow(ll a, ll b) {
if (b == 0)
return 1;
if (b % 2)
return a * pow(a, b - 1);
ll tmp = pow(a, b / 2);
return tmp * tmp;
}
void ans() {
cin >> N >> P;
int res;
for (int i = 1; pow(i, N) <= P && pow(i, N) > 0; i++) {
if (P % pow(i, N) == 0)
res = i;
}
cout << res << "\n";
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
question q;
q.ans();
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
class question {
public:
ll N, P;
ll pow(ll a, ll b) {
if (b == 0)
return 1;
if (b % 2)
return a * pow(a, b - 1);
ll tmp = pow(a, b / 2);
return tmp * tmp;
}
void ans() {
cin >> N >> P;
int res;
if (N == 1) {
cout << P << "\n";
return;
}
for (int i = 1; pow(i, N) <= P && pow(i, N) > 0; i++) {
if (P % pow(i, N) == 0)
res = i;
}
cout << res << "\n";
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
question q;
q.ans();
return 0;
}
| insert | 33 | 33 | 33 | 37 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
long long power(long long a, long long b) {
if (b == 0) {
return 1;
}
long long result = 1;
for (int i = 0; i < b; i++) {
result *= a;
}
return result;
}
int main(int argc, char *argv[]) {
long long N, P;
cin >> N >> P;
vector<long long> v;
map<long long, long long> m;
int i;
if (N == 1) {
// do nothing
} else {
for (i = 2; i * i <= P; i++) {
while (P % i == 0) {
m[i]++;
// v.push_back(i);
P /= i;
}
}
}
if (P != 1) {
// v.push_back(P);
m[P]++;
}
long long ans = 1;
for (auto p : m) {
if (p.second < N) {
continue;
} else {
ans *= power(p.first, (p.second / N));
}
// cout << p.first << " -> " << p.second << endl;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
long long power(long long a, long long b) {
if (b == 0) {
return 1;
}
long long result = 1;
for (int i = 0; i < b; i++) {
result *= a;
}
return result;
}
int main(int argc, char *argv[]) {
long long N, P;
cin >> N >> P;
vector<long long> v;
map<long long, long long> m;
ll i;
if (N == 1) {
// do nothing
} else {
for (i = 2; i * i <= P; i++) {
while (P % i == 0) {
m[i]++;
// v.push_back(i);
P /= i;
}
}
}
if (P != 1) {
// v.push_back(P);
m[P]++;
}
long long ans = 1;
for (auto p : m) {
if (p.second < N) {
continue;
} else {
ans *= power(p.first, (p.second / N));
}
// cout << p.first << " -> " << p.second << endl;
}
cout << ans << endl;
return 0;
}
| replace | 36 | 37 | 36 | 37 | TLE | |
p03194 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
unsigned long long p;
unsigned long long quick(unsigned long long a, unsigned long long b) {
if (b == 1)
return a;
unsigned long long ret = quick(a, b / 2);
if (b % 2 == 1)
return ret * ret * a;
return ret * ret;
}
int main() {
int n;
unsigned long long pp = 2, ans = 1, tmp;
scanf("%d%lld", &n, &p);
if (n == 1) {
printf("%lld", p);
return 0;
}
while (p != 1) {
tmp = quick(pp, n);
if (p < tmp)
break;
while (p % tmp == 0) {
p /= tmp;
ans *= pp;
if (p < tmp)
break;
}
pp++;
}
printf("%lld", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
unsigned long long p;
unsigned long long quick(unsigned long long a, unsigned long long b) {
if (b == 1)
return a;
unsigned long long ret = quick(a, b / 2);
if (b % 2 == 1)
return ret * ret * a;
return ret * ret;
}
int main() {
int n;
unsigned long long pp = 2, ans = 1, tmp;
scanf("%d%lld", &n, &p);
if (n == 1) {
printf("%lld", p);
return 0;
}
while (p != 1) {
tmp = quick(pp, n);
if (p < tmp || tmp == 0)
break;
while (p % tmp == 0) {
p /= tmp;
ans *= pp;
if (p < tmp)
break;
}
pp++;
}
printf("%lld", ans);
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03194 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
ll n, p, a = 1, ans;
cin >> n >> p;
while (pow(a, n) <= p) {
if (p % (ll)pow(a, n) == 0) {
ans = a;
}
a++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
ll n, p, a = 1, ans;
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
while (pow(a, n) <= p) {
if (p % (ll)pow(a, n) == 0) {
ans = a;
}
a++;
}
cout << ans << endl;
}
| insert | 7 | 7 | 7 | 11 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 1000000000001
using namespace std;
int main() {
ull n, p;
cin >> n >> p;
ull max = 1, i = 2;
while (pow(i, n) <= p) {
if (p % (ull)pow(i, n) == 0) {
max = i;
}
i++;
}
cout << max << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 1000000000001
using namespace std;
int main() {
ull n, p;
cin >> n >> p;
ull max = 1, i = 2, x;
if (n == 1) {
cout << p << endl;
return 0;
}
while ((x = pow(i, n)) && (x <= p)) {
if (p % x == 0) {
max = i;
}
i++;
}
cout << max << endl;
return 0;
} | replace | 14 | 17 | 14 | 21 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, p, i = 1, ans = 0;
int main(void) {
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
while (p >= (ll)pow(i, n)) {
if (p % (ll)pow(i, n) == 0) {
ans = i;
}
i++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, p, i = 1, ans = 0;
int main(void) {
cin >> n >> p;
if (n == 1) {
cout << p << endl;
return 0;
}
if (n > 40) {
cout << 1 << endl;
return 0;
}
while (p >= (ll)pow(i, n)) {
if (p % (ll)pow(i, n) == 0) {
ans = i;
}
i++;
}
cout << ans << endl;
return 0;
}
| insert | 11 | 11 | 11 | 15 | TLE | |
p03194 | C++ | Time Limit Exceeded | /*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
void solve(int test_case) { // 222
ll n, p;
cin >> n >> p;
if (n > 40 || p == 1) {
cout << 1;
return;
}
ll mx = 1;
for (ll i = 1; i <= p; i++) {
ll val = pow(i, n);
if (val > p || val < 0)
break;
if (p % val == 0) {
mx = i;
}
}
cout << mx;
}
int main() {
////// FILE BASED IO////
// freopen("wormhole.in", "r", stdin);
// freopen("wormhole.out", "w", stdout);
///////////////
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin>>t;
REP(i, 1, t) { solve(i); }
return 0;
}
| /*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
void solve(int test_case) { // 222
ll n, p;
cin >> n >> p;
if (n > 40 || p == 1) {
cout << 1;
return;
}
if (n == 1) {
cout << p;
return;
}
ll mx = 1;
for (ll i = 1; i <= p; i++) {
ll val = pow(i, n);
if (val > p || val < 0)
break;
if (p % val == 0) {
mx = i;
}
}
cout << mx;
}
int main() {
////// FILE BASED IO////
// freopen("wormhole.in", "r", stdin);
// freopen("wormhole.out", "w", stdout);
///////////////
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin>>t;
REP(i, 1, t) { solve(i); }
return 0;
}
| insert | 35 | 35 | 35 | 39 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n, k;
cin >> n >> k;
if (n == 1) {
cout << k;
return 0;
}
double c = 1;
for (double i = 1;; i++) {
if (k % (ll)pow(i, (double)n) == 0) {
c = i;
}
if (k < (ll)pow(i, (double)n))
break;
}
cout << (ll)c;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n, k;
cin >> n >> k;
if (n == 1) {
cout << k;
return 0;
}
if (n > 1000000) {
cout << 1;
return 0;
}
double c = 1;
for (double i = 1;; i++) {
if (k % (ll)pow(i, (double)n) == 0) {
c = i;
}
if (k < (ll)pow(i, (double)n))
break;
}
cout << (ll)c;
} | insert | 8 | 8 | 8 | 12 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;
template <typename T> map<T, T> prime_factor(T n) {
map<T, T> res;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1)
res[n] = 1;
return res;
}
int main(void) {
ll n, p;
cin >> n >> p;
auto prf = prime_factor(p);
ll ans = 1LL;
for (auto x : prf) {
if (x.second >= n) {
ans *= (ll)pow(x.first, x.second / n);
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;
template <typename T> map<T, T> prime_factor(T n) {
map<T, T> res;
for (T i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1)
res[n] = 1;
return res;
}
int main(void) {
ll n, p;
cin >> n >> p;
auto prf = prime_factor(p);
ll ans = 1LL;
for (auto x : prf) {
if (x.second >= n) {
ans *= (ll)pow(x.first, x.second / n);
}
}
cout << ans << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
long long int n, p, ans = 1;
cin >> n >> p;
long long int i = 1;
long long int a = pow(2, n);
long long int min = 2;
int l = 2;
while (pow(i, n) <= p) {
long long int tmp = pow(i, n);
if (p % tmp == 0) {
ans *= i;
p /= tmp;
if (i == 1)
i++;
} else {
if (i == 3)
i += 2;
else if (i > 4) {
i += l;
l = 6 - l;
} else
i++;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
long long int n, p, ans = 1;
cin >> n >> p;
long long int i = 1;
long long int a = pow(2, n);
long long int min = 2;
int l = 2;
if (n == 1) {
cout << p << endl;
return 0;
}
while (pow(i, n) <= p) {
long long int tmp = pow(i, n);
if (p % tmp == 0) {
ans *= i;
p /= tmp;
if (i == 1)
i++;
} else {
if (i == 3)
i += 2;
else if (i > 4) {
i += l;
l = 6 - l;
} else
i++;
}
}
cout << ans << endl;
return 0;
} | insert | 12 | 12 | 12 | 16 | TLE | |
p03194 | C++ | Time Limit Exceeded | #include <iostream>
#include <math.h>
using namespace std;
int main(void) {
long long N, P;
cin >> N;
cin >> P;
long long ans = 1;
int i;
if (N == 1) {
ans = P;
} else {
for (i = 1; i < 100000000; i++) {
long long kn = pow(i, N);
if ((P % kn) == 0) {
ans = i;
}
if (P < kn) {
break;
}
}
}
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <math.h>
using namespace std;
int main(void) {
long long N, P;
cin >> N;
cin >> P;
long long ans = 1;
int i;
if (N == 1) {
ans = P;
} else {
for (i = 2; i <= 1000010; i++) {
long long kn = pow(i, N);
if ((P % kn) == 0) {
ans = i;
}
if (P < kn) {
break;
}
}
}
cout << ans << endl;
return 0;
}
| replace | 17 | 18 | 17 | 18 | TLE |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.