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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
typedef pair<ll, ll> P;
#define bit(n) (1LL << (n))
// #define int long long
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }
#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX
template <ll ModVal> struct ModInt {
ll x;
ModInt(ll _x = 0) : x((_x % ModVal + ModVal) % ModVal) {}
ModInt operator-() const { return ModInt(-x); }
ModInt &operator+=(const ModInt a) {
x += a.x;
if (x >= ModVal)
x -= ModVal;
return *this;
}
ModInt &operator-=(const ModInt a) {
x = x + ModVal - a.x;
if (x >= ModVal)
x -= ModVal;
return *this;
}
ModInt &operator*=(const ModInt a) {
x *= a.x;
x %= ModVal;
return *this;
}
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll tmp = a / b;
ll d = ext_gcd(b, a - b * tmp, y, x);
y -= tmp * x;
return d;
}
// 逆元
ModInt inv(const ModInt a) {
ll u, v;
ext_gcd(a.x, ModVal, u, v);
return ModInt(u);
}
ModInt &operator/=(const ModInt a) { return (*this) *= inv(a); }
ModInt operator+(const ModInt a) const {
ModInt retval(*this);
return retval += a;
}
ModInt operator-(const ModInt a) const {
ModInt retval(*this);
return retval -= a;
}
ModInt operator*(const ModInt a) const {
ModInt retval(*this);
return retval *= a;
}
ModInt operator/(const ModInt a) const {
ModInt retval(*this);
return retval /= a;
}
ModInt pow(ll n) {
ModInt ans(1);
while (n) {
if (n & 1)
ans = ans * x;
*this = (*this) * (*this);
n = n >> 1;
}
return ans;
}
constexpr const ll &value() { return this->x; }
};
template <ll ModVal> ostream &operator<<(ostream &os, const ModInt<ModVal> &a) {
os << a.x;
return os;
}
using mint = ModInt<mod>;
template <typename T> class Combination {
public:
Combination(ll _max_n) : max_n(_max_n), factional(max_n + 1), inv(max_n + 1) {
factional[0] = 1;
inv[0] = 1;
for (ll i = 0; i < max_n; i++) {
factional[i + 1] = factional[i] * (i + 1); // n!(mod M)
inv[i + 1] = inv[i] / (i + 1); // k!^(M-2) (mod M)
}
}
// nCk
T choose(ll n, ll k) {
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
T tmp = inv[n - k] * inv[k];
return tmp * factional[n];
}
T permutation(ll n, ll k) {
if (n - k < 0) {
return 0;
}
return factional[n] / factional[n - k];
}
private:
const ll max_n;
std::vector<T> factional;
std::vector<T> inv;
};
using Comb = Combination<mint>;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll n, k;
cin >> n >> k;
vector<mint> ptn(n + 1);
Comb c(k + 1);
for (ll i = k; i > 0; i--) {
ptn[i] = mint(k / i).pow(n);
for (ll j = i * 2; j <= k; j += i) {
ptn[i] -= ptn[j];
}
}
mint ans(0);
REP(i, k + 1) { ans += ptn[i] * i; }
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
typedef pair<ll, ll> P;
#define bit(n) (1LL << (n))
// #define int long long
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }
#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX
template <ll ModVal> struct ModInt {
ll x;
ModInt(ll _x = 0) : x((_x % ModVal + ModVal) % ModVal) {}
ModInt operator-() const { return ModInt(-x); }
ModInt &operator+=(const ModInt a) {
x += a.x;
if (x >= ModVal)
x -= ModVal;
return *this;
}
ModInt &operator-=(const ModInt a) {
x = x + ModVal - a.x;
if (x >= ModVal)
x -= ModVal;
return *this;
}
ModInt &operator*=(const ModInt a) {
x *= a.x;
x %= ModVal;
return *this;
}
ll ext_gcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll tmp = a / b;
ll d = ext_gcd(b, a - b * tmp, y, x);
y -= tmp * x;
return d;
}
// 逆元
ModInt inv(const ModInt a) {
ll u, v;
ext_gcd(a.x, ModVal, u, v);
return ModInt(u);
}
ModInt &operator/=(const ModInt a) { return (*this) *= inv(a); }
ModInt operator+(const ModInt a) const {
ModInt retval(*this);
return retval += a;
}
ModInt operator-(const ModInt a) const {
ModInt retval(*this);
return retval -= a;
}
ModInt operator*(const ModInt a) const {
ModInt retval(*this);
return retval *= a;
}
ModInt operator/(const ModInt a) const {
ModInt retval(*this);
return retval /= a;
}
ModInt pow(ll n) {
ModInt ans(1);
while (n) {
if (n & 1)
ans = ans * x;
*this = (*this) * (*this);
n = n >> 1;
}
return ans;
}
constexpr const ll &value() { return this->x; }
};
template <ll ModVal> ostream &operator<<(ostream &os, const ModInt<ModVal> &a) {
os << a.x;
return os;
}
using mint = ModInt<mod>;
template <typename T> class Combination {
public:
Combination(ll _max_n) : max_n(_max_n), factional(max_n + 1), inv(max_n + 1) {
factional[0] = 1;
inv[0] = 1;
for (ll i = 0; i < max_n; i++) {
factional[i + 1] = factional[i] * (i + 1); // n!(mod M)
inv[i + 1] = inv[i] / (i + 1); // k!^(M-2) (mod M)
}
}
// nCk
T choose(ll n, ll k) {
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
T tmp = inv[n - k] * inv[k];
return tmp * factional[n];
}
T permutation(ll n, ll k) {
if (n - k < 0) {
return 0;
}
return factional[n] / factional[n - k];
}
private:
const ll max_n;
std::vector<T> factional;
std::vector<T> inv;
};
using Comb = Combination<mint>;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll n, k;
cin >> n >> k;
vector<mint> ptn(k + 1);
for (ll i = k; i > 0; i--) {
ptn[i] = mint(k / i).pow(n);
for (ll j = i * 2; j <= k; j += i) {
ptn[i] -= ptn[j];
}
}
mint ans(0);
REP(i, k + 1) { ans += ptn[i] * i; }
cout << ans << endl;
return 0;
}
| replace | 161 | 163 | 161 | 162 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long BIG = 1000000007;
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
long N, K;
long long ans = 0;
cin >> N >> K;
vector<long> vec(N + 10, -1);
for (int i = K; i > 0; i--) {
vec[i] = modpow(K / i, N, BIG);
for (int j = i * 2; j <= K; j += i) {
vec[i] = (vec[i] - vec[j] + BIG) % BIG;
}
ans = (ans % BIG + vec[i] * i % BIG) % BIG;
// cout << ans << endl;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
long BIG = 1000000007;
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
long N, K;
long long ans = 0;
cin >> N >> K;
vector<long> vec(K + 10, -1);
for (int i = K; i > 0; i--) {
vec[i] = modpow(K / i, N, BIG);
for (int j = i * 2; j <= K; j += i) {
vec[i] = (vec[i] - vec[j] + BIG) % BIG;
}
ans = (ans % BIG + vec[i] * i % BIG) % BIG;
// cout << ans << endl;
}
cout << ans << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02715 | C++ | Runtime Error | /*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &a) {
register T x = 0, flag = 1;
register char ch;
while (!isdigit(ch = getchar()))
if (ch == '-')
flag = -1;
while (x = x * 10 + (ch & 15), isdigit(ch = getchar()))
;
a = x * flag;
}
template <class T> inline void write(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
write(x / 10);
putchar(x % 10 + '0');
}
template <class T> inline bool Chkmax(T &x, const T &y) {
return x < y ? x = y, true : false;
}
template <class T> inline bool Chkmin(T &x, const T &y) {
return x > y ? x = y, true : false;
}
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define Rep(i, a, b) for (int i = (a); i >= (b); i--)
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)
#define int long long
const int maxn = 501000;
const int Mod = 1e9 + 7;
int n, k;
int prime[maxn], tot, vis[maxn], phi[maxn];
int S[maxn];
int Get_phi(int n) {
phi[1] = 1;
For(i, 2, n) {
if (vis[i] == 0) {
prime[++tot] = i;
phi[i] = i - 1;
}
For(j, 1, tot) {
int v = i * prime[j];
if (v > n)
break;
vis[v] = 1;
if (i % prime[j] == 0) {
phi[v] = phi[i] * prime[j];
break;
}
phi[v] = phi[i] * (prime[j] - 1);
}
}
For(i, 1, n) { S[i] = (S[i - 1] + phi[i]) % Mod; }
}
int Pow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1)
ans = 1ll * ans * x % Mod;
x = 1ll * x * x % Mod;
y >>= 1;
}
return ans;
}
signed main() {
int ans = 0;
cin >> n >> k;
Get_phi(k);
for (int l = 1, r = 0; l <= k; l = r + 1) {
r = min(k, k / (k / l));
ans =
(ans + 1ll * (S[r] - S[l - 1] + Mod) % Mod * Pow(k / l, n) % Mod) % Mod;
}
cout << ans;
return 0;
}
| /*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &a) {
register T x = 0, flag = 1;
register char ch;
while (!isdigit(ch = getchar()))
if (ch == '-')
flag = -1;
while (x = x * 10 + (ch & 15), isdigit(ch = getchar()))
;
a = x * flag;
}
template <class T> inline void write(T x) {
if (x < 0)
putchar('-'), x = -x;
if (x >= 10)
write(x / 10);
putchar(x % 10 + '0');
}
template <class T> inline bool Chkmax(T &x, const T &y) {
return x < y ? x = y, true : false;
}
template <class T> inline bool Chkmin(T &x, const T &y) {
return x > y ? x = y, true : false;
}
#define For(i, a, b) for (int i = (a); i <= (b); i++)
#define Rep(i, a, b) for (int i = (a); i >= (b); i--)
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)
#define int long long
const int maxn = 501000;
const int Mod = 1e9 + 7;
int n, k;
int prime[maxn], tot, vis[maxn], phi[maxn];
int S[maxn];
void Get_phi(int n) {
phi[1] = 1;
For(i, 2, n) {
if (vis[i] == 0) {
prime[++tot] = i;
phi[i] = i - 1;
}
For(j, 1, tot) {
int v = i * prime[j];
if (v > n)
break;
vis[v] = 1;
if (i % prime[j] == 0) {
phi[v] = phi[i] * prime[j];
break;
}
phi[v] = phi[i] * (prime[j] - 1);
}
}
For(i, 1, n) { S[i] = (S[i - 1] + phi[i]) % Mod; }
}
int Pow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1)
ans = 1ll * ans * x % Mod;
x = 1ll * x * x % Mod;
y >>= 1;
}
return ans;
}
signed main() {
int ans = 0;
cin >> n >> k;
Get_phi(k);
for (int l = 1, r = 0; l <= k; l = r + 1) {
r = min(k, k / (k / l));
ans =
(ans + 1ll * (S[r] - S[l - 1] + Mod) % Mod * Pow(k / l, n) % Mod) % Mod;
}
cout << ans;
return 0;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p02715 | C++ | Runtime Error | // Nihal Mittal - nihal_47
// Strike First , Strike Hard , No Mercy !!
/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(), (v).end()
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define pii pair<ll, ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
ll power(ll x, ll y) {
ll res = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
signed main() {
fast;
ll n, i, k, j, ans = 0;
cin >> n >> k;
vi(ll) dp(n + 2, 0);
for (i = k; i >= 1; i--) {
dp[i] = power(k / i, n);
for (j = 2 * i; j <= k; j += i) {
dp[i] = (dp[i] - dp[j] % mod + mod) % mod;
}
ans = (ans + (i % mod * dp[i] % mod) % mod) % mod;
}
cout << ans;
} | // Nihal Mittal - nihal_47
// Strike First , Strike Hard , No Mercy !!
/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(), (v).end()
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define pii pair<ll, ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
ll power(ll x, ll y) {
ll res = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
signed main() {
fast;
ll n, i, k, j, ans = 0;
cin >> n >> k;
vi(ll) dp(k + 2, 0);
for (i = k; i >= 1; i--) {
dp[i] = power(k / i, n);
for (j = 2 * i; j <= k; j += i) {
dp[i] = (dp[i] - dp[j] % mod + mod) % mod;
}
ans = (ans + (i % mod * dp[i] % mod) % mod) % mod;
}
cout << ans;
} | replace | 60 | 61 | 60 | 61 | 0 | |
p02715 | C++ | Runtime Error | #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define FOR(i, j, k) for (ll i = j; i < k; i++)
#define DUMP(i, v) \
for (ll i = 0; i < v.size(); i++) \
cerr << v[i] << " "
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge {
ll x, c;
};
ll mod(ll a, ll mod) {
ll res = a % mod;
if (res < 0)
res = res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }
ll gcd(ll a, ll b) {
ll r = a % b;
if (r == 0)
return b;
else
return gcd(b, a % b);
}
bool is_prime(ll n) {
ll i = 2;
if (n == 1)
return false;
if (n == 2)
return true;
bool res = true;
while (i * i < n) {
if (n % i == 0) {
res = false;
}
i = i + 1;
}
// if(i==1)res = false;
if (n % i == 0)
res = false;
return res;
}
struct UnionFind {
ll N;
llvec p;
llvec cnt;
UnionFind(ll n) {
N = n;
p = llvec(N);
cnt = llvec(N, 0);
rep(i, N) {
p[i] = i;
cnt[i] = 1;
}
}
void con(ll a, ll b) {
P at = root(a);
P bt = root(b);
if (at.second != bt.second) {
if (at.first > bt.first) {
swap(at, bt);
swap(a, b);
}
p[at.second] = bt.second;
cnt[bt.second] += cnt[at.second];
p[a] = bt.second;
}
}
P root(ll a) {
ll atmp = a;
ll c = 0;
while (atmp != p[atmp]) {
atmp = p[atmp];
c++;
}
p[a] = atmp;
return {c, atmp};
}
bool is_con(ll a, ll b) {
P at = root(a);
P bt = root(b);
return at.second == bt.second;
}
};
struct dijkstra {
ll N;
llvec d;
vector<vector<edge>> e;
dijkstra(ll n) {
N = n;
// d = llvec(N, 1e18);
e = vector<vector<edge>>(N);
}
void add_edge(ll from, ll to, ll cost) { e[from].push_back({to, cost}); }
void run(ll start) {
priority_queue<P, vector<P>, greater<P>> que;
que.push({0, start});
d = llvec(N, 1e18);
d[start] = 0;
while (!que.empty()) {
P q = que.top();
que.pop();
ll dc = q.first;
ll x = q.second;
if (dc > d[x]) {
continue;
} else {
for (auto ip : e[x]) {
if (d[ip.x] <= d[x] + ip.c) {
continue;
} else {
d[ip.x] = d[x] + ip.c;
que.push({d[ip.x], ip.x});
}
}
}
}
}
};
/**************************************
** A main function starts from here **
***************************************/
int main() {
ll N, K;
cin >> N >> K;
ll ans = 0;
llvec d(K, 0);
ll cnt = 0;
rrep(i, K + 1) {
if (i == 1)
break;
ll num = K / i;
d[i] = modpow(num, N, MOD);
ll j = 2;
while (i * j <= K) {
d[i] = mod(d[i] - d[i * j], MOD);
j++;
}
cnt = mod(cnt + d[i], MOD);
ans = mod(ans + d[i] * i, MOD);
}
ans = mod(ans + mod(modpow(K, N, MOD) - cnt, MOD), MOD);
cout << ans;
return 0;
}
| #include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define FOR(i, j, k) for (ll i = j; i < k; i++)
#define DUMP(i, v) \
for (ll i = 0; i < v.size(); i++) \
cerr << v[i] << " "
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge {
ll x, c;
};
ll mod(ll a, ll mod) {
ll res = a % mod;
if (res < 0)
res = res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }
ll gcd(ll a, ll b) {
ll r = a % b;
if (r == 0)
return b;
else
return gcd(b, a % b);
}
bool is_prime(ll n) {
ll i = 2;
if (n == 1)
return false;
if (n == 2)
return true;
bool res = true;
while (i * i < n) {
if (n % i == 0) {
res = false;
}
i = i + 1;
}
// if(i==1)res = false;
if (n % i == 0)
res = false;
return res;
}
struct UnionFind {
ll N;
llvec p;
llvec cnt;
UnionFind(ll n) {
N = n;
p = llvec(N);
cnt = llvec(N, 0);
rep(i, N) {
p[i] = i;
cnt[i] = 1;
}
}
void con(ll a, ll b) {
P at = root(a);
P bt = root(b);
if (at.second != bt.second) {
if (at.first > bt.first) {
swap(at, bt);
swap(a, b);
}
p[at.second] = bt.second;
cnt[bt.second] += cnt[at.second];
p[a] = bt.second;
}
}
P root(ll a) {
ll atmp = a;
ll c = 0;
while (atmp != p[atmp]) {
atmp = p[atmp];
c++;
}
p[a] = atmp;
return {c, atmp};
}
bool is_con(ll a, ll b) {
P at = root(a);
P bt = root(b);
return at.second == bt.second;
}
};
struct dijkstra {
ll N;
llvec d;
vector<vector<edge>> e;
dijkstra(ll n) {
N = n;
// d = llvec(N, 1e18);
e = vector<vector<edge>>(N);
}
void add_edge(ll from, ll to, ll cost) { e[from].push_back({to, cost}); }
void run(ll start) {
priority_queue<P, vector<P>, greater<P>> que;
que.push({0, start});
d = llvec(N, 1e18);
d[start] = 0;
while (!que.empty()) {
P q = que.top();
que.pop();
ll dc = q.first;
ll x = q.second;
if (dc > d[x]) {
continue;
} else {
for (auto ip : e[x]) {
if (d[ip.x] <= d[x] + ip.c) {
continue;
} else {
d[ip.x] = d[x] + ip.c;
que.push({d[ip.x], ip.x});
}
}
}
}
}
};
/**************************************
** A main function starts from here **
***************************************/
int main() {
ll N, K;
cin >> N >> K;
ll ans = 0;
llvec d(K + 1, 0);
ll cnt = 0;
rrep(i, K + 1) {
if (i == 1)
break;
ll num = K / i;
d[i] = modpow(num, N, MOD);
ll j = 2;
while (i * j <= K) {
d[i] = mod(d[i] - d[i * j], MOD);
j++;
}
cnt = mod(cnt + d[i], MOD);
ans = mod(ans + d[i] * i, MOD);
}
ans = mod(ans + mod(modpow(K, N, MOD) - cnt, MOD), MOD);
cout << ans;
return 0;
}
| replace | 161 | 162 | 161 | 162 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
ll kpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans *= a;
ans %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ans;
}
ll dp[maxn];
int main() {
ll n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
dp[i] = kpow(k / i, n); // 表示最小公因数为i的排列组合的数量
}
for (int i = k; i >= 1; i--) {
for (int j = i * 2; j <= k; j + i) {
dp[i] -= dp[j];
dp[i] = (dp[i] + mod) % mod;
}
}
ll ans = 0;
for (int i = k; i >= 1; i--) {
ans += (i * dp[i]);
ans %= mod;
}
cout << (ans + mod) % mod << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
ll kpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans *= a;
ans %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ans;
}
ll dp[maxn];
int main() {
ll n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
dp[i] = kpow(k / i, n); // 表示最小公因数为i的排列组合的数量
}
for (int i = k; i >= 1; i--) {
for (int j = i * 2; j <= k; j = j + i) {
dp[i] -= dp[j];
dp[i] = (dp[i] + mod) % mod;
}
}
ll ans = 0;
for (int i = k; i >= 1; i--) {
ans += (i * dp[i]);
ans %= mod;
}
cout << (ans + mod) % mod << endl;
return 0;
}
| replace | 43 | 44 | 43 | 44 | TLE | |
p02715 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
ll mypw(ll n, ll m) {
ll k = 1;
for (ll i = 0; i < m; i++) {
k = (k * (n % M)) % M;
}
return k;
}
int main() {
ll n, k, ans = 0;
cin >> n >> k;
vector<ll> c(k + 1);
for (ll i = k; i >= 1; i--) {
c[i] = mypw(k / i, n);
for (ll j = i * 2; j <= k; j += i) {
c[i] -= c[j];
if (c[i] < 0)
c[i] += M;
}
ans = (ans + (c[i] * i) % M) % M;
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
ll mypw(ll n, ll m) {
if (m <= 1)
return n;
ll k = mypw(n, m / 2) % M;
k = (k * k) % M;
if (m & 1)
return (k * n) % M;
else
return k;
}
int main() {
ll n, k, ans = 0;
cin >> n >> k;
vector<ll> c(k + 1);
for (ll i = k; i >= 1; i--) {
c[i] = mypw(k / i, n);
for (ll j = i * 2; j <= k; j += i) {
c[i] -= c[j];
if (c[i] < 0)
c[i] += M;
}
ans = (ans + (c[i] * i) % M) % M;
}
cout << ans << endl;
return 0;
} | replace | 6 | 11 | 6 | 14 | TLE | |
p02715 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long
template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
ll MOD = 1000000007;
ll modpow(ll a, ll n = MOD - 2) {
ll r = 1;
a %= MOD;
while (n) {
r = r * ((n % 2) ? a : 1) % MOD;
a = a * a % MOD;
n >>= 1;
}
return r;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
ll sum = 0;
vector<ll> dp(10001, 0);
for (int i = K; i >= 1; i--) {
dp[i] = modpow(K / i, N);
for (int j = i * 2; j <= K; j += i)
dp[i] -= dp[j];
sum += i * dp[i] % MOD;
}
cout << sum % MOD << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long
template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
ll MOD = 1000000007;
ll modpow(ll a, ll n = MOD - 2) {
ll r = 1;
a %= MOD;
while (n) {
r = r * ((n % 2) ? a : 1) % MOD;
a = a * a % MOD;
n >>= 1;
}
return r;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
ll sum = 0;
vector<ll> dp(100001, 0);
for (int i = K; i >= 1; i--) {
dp[i] = modpow(K / i, N);
for (int j = i * 2; j <= K; j += i)
dp[i] -= dp[j];
sum += i * dp[i] % MOD;
}
cout << sum % MOD << endl;
return 0;
}
| replace | 58 | 59 | 58 | 59 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v, d) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
const double EPS = (1e-9);
using namespace std;
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
ll setBit0(ll num, int idx) { return num & ~(1ll << idx); }
ll flipBit(int num, int idx) { return num ^ (1 << idx); }
void GO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 100000 + 9, mod = 1000000000 + 7;
ll cnt[N], fres[N];
int go(int n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
cnt[i]++;
if (n / i != i)
cnt[n / i]++;
}
}
}
ll power(ll b, ll p) {
if (p == 0)
return 1;
if ((p & (1ll))) {
return b % mod * power((b * b) % mod, p / 2) % mod;
} else {
return power((b * b) % mod, p / 2);
}
}
int main() {
GO();
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
go(i);
}
ll ans = 0;
for (int i = k; i >= 1; i--) {
fres[i] = power(cnt[i], n);
for (int j = i * 2; j <= k; j += i) {
fres[i] = ((fres[i] - fres[j]) + mod) % mod;
}
ans += (1ll * fres[i] * i) % mod;
if (ans >= mod)
ans -= mod;
}
cout << ans << "\n";
}
| #include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define pb push_back
#define mp make_pair
#define clr(v, d) memset(v, d, sizeof(v))
typedef long long ll;
typedef unsigned long long ull;
const double EPS = (1e-9);
using namespace std;
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
ll setBit0(ll num, int idx) { return num & ~(1ll << idx); }
ll flipBit(int num, int idx) { return num ^ (1 << idx); }
void GO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 100000 + 9, mod = 1000000000 + 7;
ll cnt[N], fres[N];
void go(int n) {
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
cnt[i]++;
if (n / i != i)
cnt[n / i]++;
}
}
}
ll power(ll b, ll p) {
if (p == 0)
return 1;
if ((p & (1ll))) {
return b % mod * power((b * b) % mod, p / 2) % mod;
} else {
return power((b * b) % mod, p / 2);
}
}
int main() {
GO();
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
go(i);
}
ll ans = 0;
for (int i = k; i >= 1; i--) {
fres[i] = power(cnt[i], n);
for (int j = i * 2; j <= k; j += i) {
fres[i] = ((fres[i] - fres[j]) + mod) % mod;
}
ans += (1ll * fres[i] * i) % mod;
if (ans >= mod)
ans -= mod;
}
cout << ans << "\n";
}
| replace | 22 | 23 | 22 | 23 | TLE | |
p02715 | C++ | Runtime Error |
// #pragma GCC optimize ("-O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#define popcnt __popcnt64
// # define __builtin_popcount __popcnt
#else
#define popcnt __builtin_popcountll
#endif
// #include "boost/variant.hpp"
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007LL;
constexpr ll INF = 1LL << 60;
#define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i)
#define rep_skip(i, N, M, ...) \
for (ll i = N, i##_len = (M); i < i##_len; i += (skip))
#define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i)
#define pb push_back
#define fir first
#define sec second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) \
sort(all(c)); \
for (bool c##perm = 1; c##perm; \
c##perm = next_permutation( \
all(c))) // perm(c){write(c)} writes all permutation of c
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template <typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using vpt = vector<complex<T>>;
template <int n> struct tll_impl {
using type = decltype(tuple_cat(tuple<ll>(),
declval<typename tll_impl<n - 1>::type>()));
};
template <> struct tll_impl<1> {
using type = tuple<ll>;
};
template <int n> using tll = typename tll_impl<n>::type;
template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); };
template <int n, typename T> struct vec_t_impl {
using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template <typename T> struct vec_t_impl<1, T> {
using type = vector<T>;
};
template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type;
// check
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");
// decompose vector into basetype and dimension.
template <typename T> struct vec_dec {
static constexpr int dim = 0;
using type = T;
};
template <typename T> struct vec_dec<vector<T>> {
static constexpr int dim = vec_dec<T>::dim + 1;
using type = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");
template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); }
template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) {
return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...));
} // ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));
template <typename T>
struct is_vector : std::false_type {}; // check if T is vector
template <typename T> struct is_vector<vector<T>> : std::true_type {};
static_assert(is_vector<vector<ll>>::value == true &&
is_vector<ll>::value == false,
"");
// check if T is vector
template <typename T> struct is_pair : std::false_type {};
template <typename T, typename S>
struct is_pair<pair<T, S>> : std::true_type {};
static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, "");
template <typename T, typename V,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
for (auto &&x : t)
fill_v(x, v);
} // ex: fill_v(dp, INF);
namespace std {
template <class T> bool operator<(const complex<T> &a, const complex<T> &b) {
return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
}; // namespace std
template <typename T, typename S>
istream &operator>>(istream &istr, pair<T, S> &x) {
return istr >> x.first >> x.second;
}
template <typename T> istream &operator>>(istream &istr, vector<T> &x) {
rep(i, 0, x.size()) istr >> x[i];
return istr;
}
template <typename T> istream &operator>>(istream &istr, complex<T> &x) {
T r, i;
istr >> r >> i;
x.real(r);
x.imag(i);
return istr;
}
template <typename T, typename Delim_t = string,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
cout << x << delim;
}
template <typename T, typename Delim_t = string,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim));
cout << '\n';
}
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
vll seq(ll i, ll j) {
vll res(j - i);
rep(k, i, j) res[k] = i + k;
return res;
}
constexpr ll POW_0(ll x, ll y) {
if (y == 0)
return 1;
if (y == 1)
return x;
if (y == 2)
return x * x;
if (y % 2 == 0)
return POW_0(POW_0(x, y / 2), 2LL);
return ((POW_0(POW_0(x, y / 2), 2LL)) * (x));
}
constexpr ll POW(ll x, ll y, ll mod = 0) {
if (mod == 0)
return POW_0(x, y);
if (y == 0)
return 1;
if (y == 1)
return x % mod;
if (y == 2)
return x * x % mod;
if (y % 2 == 0)
return POW(POW(x, y / 2, mod), 2LL, mod) % mod;
return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod;
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void sort_by(Inputs &inputs, Functor f) {
std::sort(std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void stable_sort_by(Inputs &inputs, Functor f) {
std::stable_sort(
std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs> void sort_uniq(Inputs &inputs) {
sort(all(inputs));
inputs.erase(unique(all(inputs)), inputs.end());
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
if (s.size() > 0 && s.front() == delim) {
elems.push_back("");
}
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
if (s.size() > 0 && s.back() == delim) {
elems.push_back("");
}
return elems;
}
template <class T> map<T, ll> inv_map(vector<T> &x) {
map<T, ll> res;
rep(i, 0, x.size()) { res[x[i]] = i; }
return res;
}
template <class T, class val_t = typename T::value_type,
enable_if_t<!is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return find(all(container), val) != container.end();
}
template <class T, class val_t = typename T::value_type,
enable_if_t<is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return container.find(val) != container.end();
}
// inner prod: |a||b|cos(theta)
template <class T> T dot(complex<T> a, complex<T> b) {
return a.real() * b.real() + a.imag() * b.imag();
}
// outer prod |a||b|sin(theta)
template <class T> T cross(complex<T> a, complex<T> b) {
return a.real() * b.imag() - a.imag() * b.real();
}
ll div_ferm(ll val, ll b, ll mod) { return (val * POW(b, mod - 2, mod)) % mod; }
// === Modint ===
// static uint_fast64_t runtime_modulus = MOD;
template <ll modulus = MOD> class modint {
public:
ll val;
constexpr modint() : val(0) {}
constexpr modint(ll x) : val((x %= mod()) < 0 ? x + mod() : x) {}
constexpr modint(ll x, ll modulus_) {
set_modulo(modulus_);
val = (x %= mod()) < 0 ? x + mod() : x;
}
template <class Ret = ll &>
static auto modulo() -> std::enable_if_t<(modulus <= 0), Ret> {
static ll runtime_modulus = numeric_limits<ll>::max();
return runtime_modulus; // singleton technique
}
template <class Ret = const ll>
static auto mod() -> std::enable_if_t<(modulus <= 0), Ret> {
return modulo();
}
template <class Ret = const ll>
static constexpr auto mod() -> std::enable_if_t<(modulus > 0), Ret> {
return modulus;
}
template <ll modulus_ = modulus,
enable_if_t<(modulus_ <= 0), nullptr_t> = nullptr>
static void set_modulo(ll mod) {
modulo() = mod;
}
void reset_modulo(ll modulus_) {
modulo() = modulus_;
val %= mod();
}
constexpr modint inv() { return pow(mod() - 2); }
constexpr ll value() const noexcept { return val; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
modint &operator+=(const modint rhs) noexcept {
val += rhs.val;
if (val >= mod()) {
val -= mod();
}
return *this;
}
modint &operator-=(const modint rhs) noexcept {
if (val < rhs.val) {
val += mod();
}
val -= rhs.val;
return *this;
}
modint &operator*=(const modint rhs) noexcept {
val = val * rhs.val % mod();
return *this;
}
modint &operator/=(modint rhs) noexcept {
ll exp = mod() - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
modint &operator++() noexcept { return *this += modint(1); }
modint operator++(int) noexcept {
modint t = *this;
*this += modint(1);
return t;
}
modint &operator--() noexcept { return *this -= modint(1); }
modint operator--(int) noexcept {
modint t = *this;
*this -= modint(1);
return t;
}
constexpr modint operator-() { return val ? mod() - val : val; }
constexpr bool operator==(const modint rhs) const noexcept {
return val == rhs.value();
}
constexpr bool operator!=(const modint rhs) const noexcept {
return val != rhs.value();
}
constexpr bool operator<(const modint rhs) const noexcept {
return val < rhs.value();
}
static constexpr modint zero() { return modint(0); }
static constexpr modint unit() { return modint(1); }
modint pow(long long k) const {
modint v = *this;
modint res(1), tmp(v);
while (k) {
if (k & 1)
res *= tmp;
tmp *= tmp;
k >>= 1;
}
return res;
}
ll log(modint b) {
modint val = *this;
const ll sq = 40000;
map<modint, ll> dp;
// dp.reserve(sq);
modint res(1);
for (ll r = 0; r < sq; r++) {
if (!dp.count(res))
dp[res] = r;
res *= val;
}
modint p = val.inv().pow(sq);
res = b;
for (ll q = 0; q <= mod() / sq + 1; q++) {
if (dp.count(res)) {
ll idx = q * sq + dp[res];
if (idx > 0)
return idx;
}
res *= p;
}
return INF;
}
friend ostream &operator<<(ostream &o, const modint<modulus> &t) {
o << t.value();
return o;
}
friend istream &operator>>(istream &in, modint<modulus> &t) {
ll x;
in >> x;
t = modint<modulus>(x);
return in;
}
friend modint<modulus> POW(modint<modulus> x, ll n) {
return modint<modulus>(POW(x.value(), n, mod()));
}
};
// user defined literal
modint<MOD> operator"" _mod(unsigned long long x) { return modint<MOD>(x); }
class Combination {
// this calculates combination (nCk).
// Constructor runs in O(MAX).
// get(n,k) returns nCk in O(1).
ll mod, N_MAX;
vll fac;
vll finv;
vll inv;
public:
Combination(ll mod = MOD, ll N_MAX = 210000)
: mod(mod), N_MAX(max(N_MAX, (ll)2)), fac(vll(N_MAX + 1)),
finv(vll(N_MAX + 1)), inv(vll(N_MAX + 1)) {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
pre_process(2LL, N_MAX + 1);
}
ll operator()(ll n, ll k) {
// choose k from n
if (N_MAX < n)
pre_process(N_MAX + 1, n + 1);
if (0 <= n && n < k)
return 0;
if (k == 0)
return 1;
if (n < 0)
return operator()(-n + k - 1, k) * (k % 2 ? -1 : 0);
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll H(ll n, ll k) {
// 1) 区間[0, k) を(空を許して)n個に分割する場合の数
// 2) n個の中からk個を重複を許して選ぶ
return operator()(n + k - 1, k);
}
ll P(ll n, ll k) {
// n (n-1) ... (n-k+1)
return (n < k || n < 0) ? 0 : fac[n] * finv[n - k];
}
ll Fac(ll n) { return P(n, n); }
ll FacInv(ll n) { return n < 0 ? 0 : finv[n]; }
private:
void pre_process(ll m, ll n) {
if (N_MAX < n) {
fac.resize(n);
inv.resize(n);
finv.resize(n);
}
rep(i, m, n) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
};
ll choose(int n, int r) { // O(r) for small n
ll acc = 1;
rep(i, 0, r) acc = acc * (n - i) / (i + 1);
return acc;
}
ll gcd(ll val, ll b) {
if (val % b == 0)
return b;
else
return gcd(b, val % b);
}
vll divisor(ll n) {
// returns common divisors in O(sqrt(min(n,m)))
vll res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
res.push_back(n / i);
}
if (i * i == n)
res.push_back(i);
}
sort(res.begin(), res.end());
return res;
}
vll divisor(ll n, ll m) {
// returns common divisors in O(sqrt(min(n,m)))
if (n > m)
swap(n, m);
vll res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (m % i == 0)
res.push_back(i);
if (m % (n / i) == 0)
res.push_back(n / i);
}
if (i * i == n && m % i == 0)
res.push_back(i);
}
sort(res.begin(), res.end());
return res;
}
vpll prime_factorize(ll n) {
// returns prime factorization of n in O(sprt(n))
vector<pll> res;
for (ll p = 2; p * p <= n; ++p) {
if (n % p != 0)
continue;
ll num = 0;
while (n % p == 0) {
++num;
n /= p;
}
res.push_back({p, num});
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n, k;
cin >> n >> k;
modint<> res = 0;
vector<modint<>> cnt(n + 1);
rrep(i, 1, k + 1) {
cnt[i] = POW(modint<>(k / i), n);
rep(j, 2, k / i + 1) cnt[i] -= cnt[i * j];
}
rep(i, 1, k + 1) { res += cnt[i] * i; }
cout << res << endl;
return 0;
}
|
// #pragma GCC optimize ("-O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#define popcnt __popcnt64
// # define __builtin_popcount __popcnt
#else
#define popcnt __builtin_popcountll
#endif
// #include "boost/variant.hpp"
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007LL;
constexpr ll INF = 1LL << 60;
#define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i)
#define rep_skip(i, N, M, ...) \
for (ll i = N, i##_len = (M); i < i##_len; i += (skip))
#define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i)
#define pb push_back
#define fir first
#define sec second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) \
sort(all(c)); \
for (bool c##perm = 1; c##perm; \
c##perm = next_permutation( \
all(c))) // perm(c){write(c)} writes all permutation of c
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template <typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using vpt = vector<complex<T>>;
template <int n> struct tll_impl {
using type = decltype(tuple_cat(tuple<ll>(),
declval<typename tll_impl<n - 1>::type>()));
};
template <> struct tll_impl<1> {
using type = tuple<ll>;
};
template <int n> using tll = typename tll_impl<n>::type;
template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); };
template <int n, typename T> struct vec_t_impl {
using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template <typename T> struct vec_t_impl<1, T> {
using type = vector<T>;
};
template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type;
// check
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");
// decompose vector into basetype and dimension.
template <typename T> struct vec_dec {
static constexpr int dim = 0;
using type = T;
};
template <typename T> struct vec_dec<vector<T>> {
static constexpr int dim = vec_dec<T>::dim + 1;
using type = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");
template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); }
template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) {
return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...));
} // ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));
template <typename T>
struct is_vector : std::false_type {}; // check if T is vector
template <typename T> struct is_vector<vector<T>> : std::true_type {};
static_assert(is_vector<vector<ll>>::value == true &&
is_vector<ll>::value == false,
"");
// check if T is vector
template <typename T> struct is_pair : std::false_type {};
template <typename T, typename S>
struct is_pair<pair<T, S>> : std::true_type {};
static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, "");
template <typename T, typename V,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
for (auto &&x : t)
fill_v(x, v);
} // ex: fill_v(dp, INF);
namespace std {
template <class T> bool operator<(const complex<T> &a, const complex<T> &b) {
return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
}; // namespace std
template <typename T, typename S>
istream &operator>>(istream &istr, pair<T, S> &x) {
return istr >> x.first >> x.second;
}
template <typename T> istream &operator>>(istream &istr, vector<T> &x) {
rep(i, 0, x.size()) istr >> x[i];
return istr;
}
template <typename T> istream &operator>>(istream &istr, complex<T> &x) {
T r, i;
istr >> r >> i;
x.real(r);
x.imag(i);
return istr;
}
template <typename T, typename Delim_t = string,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
cout << x << delim;
}
template <typename T, typename Delim_t = string,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim));
cout << '\n';
}
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
vll seq(ll i, ll j) {
vll res(j - i);
rep(k, i, j) res[k] = i + k;
return res;
}
constexpr ll POW_0(ll x, ll y) {
if (y == 0)
return 1;
if (y == 1)
return x;
if (y == 2)
return x * x;
if (y % 2 == 0)
return POW_0(POW_0(x, y / 2), 2LL);
return ((POW_0(POW_0(x, y / 2), 2LL)) * (x));
}
constexpr ll POW(ll x, ll y, ll mod = 0) {
if (mod == 0)
return POW_0(x, y);
if (y == 0)
return 1;
if (y == 1)
return x % mod;
if (y == 2)
return x * x % mod;
if (y % 2 == 0)
return POW(POW(x, y / 2, mod), 2LL, mod) % mod;
return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod;
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void sort_by(Inputs &inputs, Functor f) {
std::sort(std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void stable_sort_by(Inputs &inputs, Functor f) {
std::stable_sort(
std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs> void sort_uniq(Inputs &inputs) {
sort(all(inputs));
inputs.erase(unique(all(inputs)), inputs.end());
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
if (s.size() > 0 && s.front() == delim) {
elems.push_back("");
}
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
if (s.size() > 0 && s.back() == delim) {
elems.push_back("");
}
return elems;
}
template <class T> map<T, ll> inv_map(vector<T> &x) {
map<T, ll> res;
rep(i, 0, x.size()) { res[x[i]] = i; }
return res;
}
template <class T, class val_t = typename T::value_type,
enable_if_t<!is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return find(all(container), val) != container.end();
}
template <class T, class val_t = typename T::value_type,
enable_if_t<is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return container.find(val) != container.end();
}
// inner prod: |a||b|cos(theta)
template <class T> T dot(complex<T> a, complex<T> b) {
return a.real() * b.real() + a.imag() * b.imag();
}
// outer prod |a||b|sin(theta)
template <class T> T cross(complex<T> a, complex<T> b) {
return a.real() * b.imag() - a.imag() * b.real();
}
ll div_ferm(ll val, ll b, ll mod) { return (val * POW(b, mod - 2, mod)) % mod; }
// === Modint ===
// static uint_fast64_t runtime_modulus = MOD;
template <ll modulus = MOD> class modint {
public:
ll val;
constexpr modint() : val(0) {}
constexpr modint(ll x) : val((x %= mod()) < 0 ? x + mod() : x) {}
constexpr modint(ll x, ll modulus_) {
set_modulo(modulus_);
val = (x %= mod()) < 0 ? x + mod() : x;
}
template <class Ret = ll &>
static auto modulo() -> std::enable_if_t<(modulus <= 0), Ret> {
static ll runtime_modulus = numeric_limits<ll>::max();
return runtime_modulus; // singleton technique
}
template <class Ret = const ll>
static auto mod() -> std::enable_if_t<(modulus <= 0), Ret> {
return modulo();
}
template <class Ret = const ll>
static constexpr auto mod() -> std::enable_if_t<(modulus > 0), Ret> {
return modulus;
}
template <ll modulus_ = modulus,
enable_if_t<(modulus_ <= 0), nullptr_t> = nullptr>
static void set_modulo(ll mod) {
modulo() = mod;
}
void reset_modulo(ll modulus_) {
modulo() = modulus_;
val %= mod();
}
constexpr modint inv() { return pow(mod() - 2); }
constexpr ll value() const noexcept { return val; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
modint &operator+=(const modint rhs) noexcept {
val += rhs.val;
if (val >= mod()) {
val -= mod();
}
return *this;
}
modint &operator-=(const modint rhs) noexcept {
if (val < rhs.val) {
val += mod();
}
val -= rhs.val;
return *this;
}
modint &operator*=(const modint rhs) noexcept {
val = val * rhs.val % mod();
return *this;
}
modint &operator/=(modint rhs) noexcept {
ll exp = mod() - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
modint &operator++() noexcept { return *this += modint(1); }
modint operator++(int) noexcept {
modint t = *this;
*this += modint(1);
return t;
}
modint &operator--() noexcept { return *this -= modint(1); }
modint operator--(int) noexcept {
modint t = *this;
*this -= modint(1);
return t;
}
constexpr modint operator-() { return val ? mod() - val : val; }
constexpr bool operator==(const modint rhs) const noexcept {
return val == rhs.value();
}
constexpr bool operator!=(const modint rhs) const noexcept {
return val != rhs.value();
}
constexpr bool operator<(const modint rhs) const noexcept {
return val < rhs.value();
}
static constexpr modint zero() { return modint(0); }
static constexpr modint unit() { return modint(1); }
modint pow(long long k) const {
modint v = *this;
modint res(1), tmp(v);
while (k) {
if (k & 1)
res *= tmp;
tmp *= tmp;
k >>= 1;
}
return res;
}
ll log(modint b) {
modint val = *this;
const ll sq = 40000;
map<modint, ll> dp;
// dp.reserve(sq);
modint res(1);
for (ll r = 0; r < sq; r++) {
if (!dp.count(res))
dp[res] = r;
res *= val;
}
modint p = val.inv().pow(sq);
res = b;
for (ll q = 0; q <= mod() / sq + 1; q++) {
if (dp.count(res)) {
ll idx = q * sq + dp[res];
if (idx > 0)
return idx;
}
res *= p;
}
return INF;
}
friend ostream &operator<<(ostream &o, const modint<modulus> &t) {
o << t.value();
return o;
}
friend istream &operator>>(istream &in, modint<modulus> &t) {
ll x;
in >> x;
t = modint<modulus>(x);
return in;
}
friend modint<modulus> POW(modint<modulus> x, ll n) {
return modint<modulus>(POW(x.value(), n, mod()));
}
};
// user defined literal
modint<MOD> operator"" _mod(unsigned long long x) { return modint<MOD>(x); }
class Combination {
// this calculates combination (nCk).
// Constructor runs in O(MAX).
// get(n,k) returns nCk in O(1).
ll mod, N_MAX;
vll fac;
vll finv;
vll inv;
public:
Combination(ll mod = MOD, ll N_MAX = 210000)
: mod(mod), N_MAX(max(N_MAX, (ll)2)), fac(vll(N_MAX + 1)),
finv(vll(N_MAX + 1)), inv(vll(N_MAX + 1)) {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
pre_process(2LL, N_MAX + 1);
}
ll operator()(ll n, ll k) {
// choose k from n
if (N_MAX < n)
pre_process(N_MAX + 1, n + 1);
if (0 <= n && n < k)
return 0;
if (k == 0)
return 1;
if (n < 0)
return operator()(-n + k - 1, k) * (k % 2 ? -1 : 0);
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll H(ll n, ll k) {
// 1) 区間[0, k) を(空を許して)n個に分割する場合の数
// 2) n個の中からk個を重複を許して選ぶ
return operator()(n + k - 1, k);
}
ll P(ll n, ll k) {
// n (n-1) ... (n-k+1)
return (n < k || n < 0) ? 0 : fac[n] * finv[n - k];
}
ll Fac(ll n) { return P(n, n); }
ll FacInv(ll n) { return n < 0 ? 0 : finv[n]; }
private:
void pre_process(ll m, ll n) {
if (N_MAX < n) {
fac.resize(n);
inv.resize(n);
finv.resize(n);
}
rep(i, m, n) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
};
ll choose(int n, int r) { // O(r) for small n
ll acc = 1;
rep(i, 0, r) acc = acc * (n - i) / (i + 1);
return acc;
}
ll gcd(ll val, ll b) {
if (val % b == 0)
return b;
else
return gcd(b, val % b);
}
vll divisor(ll n) {
// returns common divisors in O(sqrt(min(n,m)))
vll res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
res.push_back(n / i);
}
if (i * i == n)
res.push_back(i);
}
sort(res.begin(), res.end());
return res;
}
vll divisor(ll n, ll m) {
// returns common divisors in O(sqrt(min(n,m)))
if (n > m)
swap(n, m);
vll res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (m % i == 0)
res.push_back(i);
if (m % (n / i) == 0)
res.push_back(n / i);
}
if (i * i == n && m % i == 0)
res.push_back(i);
}
sort(res.begin(), res.end());
return res;
}
vpll prime_factorize(ll n) {
// returns prime factorization of n in O(sprt(n))
vector<pll> res;
for (ll p = 2; p * p <= n; ++p) {
if (n % p != 0)
continue;
ll num = 0;
while (n % p == 0) {
++num;
n /= p;
}
res.push_back({p, num});
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n, k;
cin >> n >> k;
modint<> res = 0;
vector<modint<>> cnt(k + 1);
rrep(i, 1, k + 1) {
cnt[i] = POW(modint<>(k / i), n);
rep(j, 2, k / i + 1) cnt[i] -= cnt[i * j];
}
rep(i, 1, k + 1) { res += cnt[i] * i; }
cout << res << endl;
return 0;
}
| replace | 566 | 567 | 566 | 567 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> d(N + 1);
for (int i = K; i >= 1; i--) {
ll tmp = modpow(K / i, N);
for (int j = 2; j * i <= K; j++) {
tmp = (tmp + mod - d[j * i]) % mod;
}
d[i] = tmp;
}
ll ans = 0;
for (int i = 1; i <= K; i++) {
ans = (ans + i * d[i]) % mod;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> d(K + 1);
for (int i = K; i >= 1; i--) {
ll tmp = modpow(K / i, N);
for (int j = 2; j * i <= K; j++) {
tmp = (tmp + mod - d[j * i]) % mod;
}
d[i] = tmp;
}
ll ans = 0;
for (int i = 1; i <= K; i++) {
ans = (ans + i * d[i]) % mod;
}
cout << ans << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007
#define NMAX 1000 * 100 + 1
#define numberOfSetBits(S) \
__builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x, y) memset(x, y, sizeof(x))
#define gcd(a, b) __gcd(a, b)
#define all(x) x.begin(), x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x) \
for (auto it = x.begin(); it != x.end(); it++) \
cout << *it << ' '; \
cout << endl;
#define printii(x) \
for (auto it = x.begin(); it != x.end(); it++) \
cout << *it.F << ' ' << *it.S << '\t'; \
cout << endl;
#define in(x, n) \
for (int e = 0; e < n; e++) { \
ll y; \
cin >> y; \
x.pb(y); \
}
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll, ll>
#define pll pair<ll, ll>
#define vii vector<ii>
#define viii vector<pair<ii, ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a, b, c) mp(mp(a, b), c)
vi ans;
ll power(ll x, unsigned ll y, unsigned ll m = MOD) {
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, x, t, m, k;
cin >> n >> k;
ans.resize(n + 1);
for (ll i = k; i >= 1; i--) {
ans[i] = power(k / i, n);
for (int j = 2 * i; j <= k; j += i) {
ans[i] -= ans[j];
ans[i] %= MOD;
}
}
ll s = 0;
for (ll i = 1; i <= k; i++) {
s += (ans[i] * i) % MOD;
s %= MOD;
}
if (s < 0) {
s += MOD;
}
cout << s;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007
#define NMAX 1000 * 100 + 1
#define numberOfSetBits(S) \
__builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x, y) memset(x, y, sizeof(x))
#define gcd(a, b) __gcd(a, b)
#define all(x) x.begin(), x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x) \
for (auto it = x.begin(); it != x.end(); it++) \
cout << *it << ' '; \
cout << endl;
#define printii(x) \
for (auto it = x.begin(); it != x.end(); it++) \
cout << *it.F << ' ' << *it.S << '\t'; \
cout << endl;
#define in(x, n) \
for (int e = 0; e < n; e++) { \
ll y; \
cin >> y; \
x.pb(y); \
}
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll, ll>
#define pll pair<ll, ll>
#define vii vector<ii>
#define viii vector<pair<ii, ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a, b, c) mp(mp(a, b), c)
vi ans;
ll power(ll x, unsigned ll y, unsigned ll m = MOD) {
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, x, t, m, k;
cin >> n >> k;
ans.resize(k + 1);
for (ll i = k; i >= 1; i--) {
ans[i] = power(k / i, n);
for (int j = 2 * i; j <= k; j += i) {
ans[i] -= ans[j];
ans[i] %= MOD;
}
}
ll s = 0;
for (ll i = 1; i <= k; i++) {
s += (ans[i] * i) % MOD;
s %= MOD;
}
if (s < 0) {
s += MOD;
}
cout << s;
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <int mod = (int)(1e9 + 7)> struct ModInt {
int x;
constexpr ModInt() : x(0) {}
constexpr ModInt(int64_t y)
: x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
constexpr ModInt &operator+=(const ModInt &p) noexcept {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
constexpr ModInt &operator-=(const ModInt &p) noexcept {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
constexpr ModInt &operator*=(const ModInt &p) noexcept {
x = (int)(1LL * x * p.x % mod);
return *this;
}
constexpr ModInt &operator/=(const ModInt &p) noexcept {
*this *= p.inverse();
return *this;
}
constexpr ModInt operator-() const { return ModInt(-x); }
constexpr ModInt operator+(const ModInt &p) const noexcept {
return ModInt(*this) += p;
}
constexpr ModInt operator-(const ModInt &p) const noexcept {
return ModInt(*this) -= p;
}
constexpr ModInt operator*(const ModInt &p) const noexcept {
return ModInt(*this) *= p;
}
constexpr ModInt operator/(const ModInt &p) const noexcept {
return ModInt(*this) /= p;
}
constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
constexpr ModInt inverse() const noexcept {
int a = x, b = mod, u = 1, v = 0, t = 0;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
constexpr ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while (n) {
if (n & 1)
res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
return os << p.x;
}
friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
int64_t t = 0;
is >> t;
a = ModInt<mod>(t);
return (is);
}
constexpr int get_mod() { return mod; }
};
long long n, k;
vector<ModInt<>> cnt;
ModInt<> solve();
int main() {
cin >> n >> k;
cout << solve() << endl;
return 0;
}
ModInt<> solve() {
ModInt<> res = 0;
cnt.assign(n + 1, 0);
for (long long i = k; i >= 1; --i) {
cnt[i] = k / i;
cnt[i] = cnt[i].pow(n);
for (long long j = 2; i * j <= k; ++j)
cnt[i] -= cnt[i * j];
res += cnt[i] * i;
}
return res;
} | #include <bits/stdc++.h>
using namespace std;
template <int mod = (int)(1e9 + 7)> struct ModInt {
int x;
constexpr ModInt() : x(0) {}
constexpr ModInt(int64_t y)
: x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
constexpr ModInt &operator+=(const ModInt &p) noexcept {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
constexpr ModInt &operator-=(const ModInt &p) noexcept {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
constexpr ModInt &operator*=(const ModInt &p) noexcept {
x = (int)(1LL * x * p.x % mod);
return *this;
}
constexpr ModInt &operator/=(const ModInt &p) noexcept {
*this *= p.inverse();
return *this;
}
constexpr ModInt operator-() const { return ModInt(-x); }
constexpr ModInt operator+(const ModInt &p) const noexcept {
return ModInt(*this) += p;
}
constexpr ModInt operator-(const ModInt &p) const noexcept {
return ModInt(*this) -= p;
}
constexpr ModInt operator*(const ModInt &p) const noexcept {
return ModInt(*this) *= p;
}
constexpr ModInt operator/(const ModInt &p) const noexcept {
return ModInt(*this) /= p;
}
constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
constexpr ModInt inverse() const noexcept {
int a = x, b = mod, u = 1, v = 0, t = 0;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
constexpr ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while (n) {
if (n & 1)
res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
return os << p.x;
}
friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
int64_t t = 0;
is >> t;
a = ModInt<mod>(t);
return (is);
}
constexpr int get_mod() { return mod; }
};
long long n, k;
vector<ModInt<>> cnt;
ModInt<> solve();
int main() {
cin >> n >> k;
cout << solve() << endl;
return 0;
}
ModInt<> solve() {
ModInt<> res = 0;
cnt.assign(k + 1, 0);
for (long long i = k; i >= 1; --i) {
cnt[i] = k / i;
cnt[i] = cnt[i].pow(n);
for (long long j = 2; i * j <= k; ++j)
cnt[i] -= cnt[i * j];
res += cnt[i] * i;
}
return res;
} | replace | 85 | 86 | 85 | 86 | 0 | |
p02716 | C++ | Runtime Error | /* * * * * * * * * * * **
* *
* saurabh8522 *
* I will handle *
* IT. *
* *
* * * * * * * * * * * **/
#include <bits/stdc++.h>
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define FastRead \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a), 0, sizeof((a)))
#define one(a) memset((a), 1, sizeof((a)))
#define minus(a) memset((a), -1, sizeof((a)))
#define all(g) g.begin(), g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
ll modpow(ll a, ll b) {
ll res = 1;
a %= MOD;
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
ll numdigit(ll n) { return floor(log10(n)) + 1; }
bool isPowerTwo(ll x) { return x && (!(x & (x - 1))); }
const ll INF = 1e16;
vector<ll> v(200005, -INF);
ll dp[100005][2][2];
bool vis[100005][2][2];
ll n;
ll find(ll pos, ll flag1, ll flag2) {
// cout<<pos<<" "<<flag1<<" "<<flag2<<endl;
if (pos >= n)
return 0ll;
ll &ans = dp[pos][flag1][flag2];
if (vis[pos][flag1][flag2])
return ans;
vis[pos][flag1][flag2] = 1;
if (flag2 == 0) {
if (pos == n - 3) {
if (flag1 == 0)
return ans = max(v[pos], max(v[pos + 1], v[pos + 2]));
else
return ans = max(v[pos + 1], v[pos + 2]);
}
if (flag1 == 0) {
ll ans1 = find(pos + 2, 0ll, 1ll);
ll ans2 = v[pos] + find(pos + 2, 0ll, 0ll);
ll ans3 = v[pos + 1] + find(pos + 2, 1ll, 0ll);
ans = max(ans1, max(ans2, ans3));
} else {
ll ans1 = find(pos + 2, 0ll, 1ll);
ll ans2 = v[pos + 1] + find(pos + 2, 1ll, 0ll);
ans = max(ans1, ans2);
}
} else {
if (flag1 == 0) {
ll ans1 = v[pos] + find(pos + 2, 0ll, 1ll);
ll ans2 = v[pos + 1] + find(pos + 2, 1ll, 1ll);
ans = max(ans1, ans2);
} else {
ans = v[pos + 1] + find(pos + 2, 1ll, 1ll);
}
}
// cout<<pos<<" "<<flag1<<" "<<flag2<<" "<<ans<<endl;
return ans;
}
int main() {
FastRead;
ll t = 1;
while (t--) {
cin >> n;
for (ll i = 0; i < n; i++) {
cin >> v[i];
}
for (ll i = 0; i < n; i++) {
vis[i][0][0] = vis[i][0][1] = 0;
vis[i][1][0] = vis[i][1][1] = 0;
}
if (n & 1) {
cout << find(0, 0ll, 0ll) << endl;
} else {
cout << find(0, 0ll, 1ll) << endl;
}
}
} | /* * * * * * * * * * * **
* *
* saurabh8522 *
* I will handle *
* IT. *
* *
* * * * * * * * * * * **/
#include <bits/stdc++.h>
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define FastRead \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a), 0, sizeof((a)))
#define one(a) memset((a), 1, sizeof((a)))
#define minus(a) memset((a), -1, sizeof((a)))
#define all(g) g.begin(), g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
ll modpow(ll a, ll b) {
ll res = 1;
a %= MOD;
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
ll numdigit(ll n) { return floor(log10(n)) + 1; }
bool isPowerTwo(ll x) { return x && (!(x & (x - 1))); }
const ll INF = 1e16;
vector<ll> v(200005, -INF);
ll dp[200005][2][2];
bool vis[200005][2][2];
ll n;
ll find(ll pos, ll flag1, ll flag2) {
// cout<<pos<<" "<<flag1<<" "<<flag2<<endl;
if (pos >= n)
return 0ll;
ll &ans = dp[pos][flag1][flag2];
if (vis[pos][flag1][flag2])
return ans;
vis[pos][flag1][flag2] = 1;
if (flag2 == 0) {
if (pos == n - 3) {
if (flag1 == 0)
return ans = max(v[pos], max(v[pos + 1], v[pos + 2]));
else
return ans = max(v[pos + 1], v[pos + 2]);
}
if (flag1 == 0) {
ll ans1 = find(pos + 2, 0ll, 1ll);
ll ans2 = v[pos] + find(pos + 2, 0ll, 0ll);
ll ans3 = v[pos + 1] + find(pos + 2, 1ll, 0ll);
ans = max(ans1, max(ans2, ans3));
} else {
ll ans1 = find(pos + 2, 0ll, 1ll);
ll ans2 = v[pos + 1] + find(pos + 2, 1ll, 0ll);
ans = max(ans1, ans2);
}
} else {
if (flag1 == 0) {
ll ans1 = v[pos] + find(pos + 2, 0ll, 1ll);
ll ans2 = v[pos + 1] + find(pos + 2, 1ll, 1ll);
ans = max(ans1, ans2);
} else {
ans = v[pos + 1] + find(pos + 2, 1ll, 1ll);
}
}
// cout<<pos<<" "<<flag1<<" "<<flag2<<" "<<ans<<endl;
return ans;
}
int main() {
FastRead;
ll t = 1;
while (t--) {
cin >> n;
for (ll i = 0; i < n; i++) {
cin >> v[i];
}
for (ll i = 0; i < n; i++) {
vis[i][0][0] = vis[i][0][1] = 0;
vis[i][1][0] = vis[i][1][1] = 0;
}
if (n & 1) {
cout << find(0, 0ll, 0ll) << endl;
} else {
cout << find(0, 0ll, 1ll) << endl;
}
}
} | replace | 49 | 51 | 49 | 51 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
int len = d.size();
rep(i, len) {
s << d[i];
if (i < len - 1)
s << " ";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
int len = d.size();
rep(i, len) { s << d[i] << endl; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
s << "{ ";
for (auto itr = v.begin(); itr != v.end(); ++itr) {
if (itr != v.begin()) {
s << ", ";
}
s << (*itr);
}
s << " }";
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (auto itr = m.begin(); itr != m.end(); ++itr) {
s << " " << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;
ll dp[30][5][2];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
rep(i, n + 1) rep(j, 5) rep(k, 2) dp[i][j][k] = -inf;
dp[1][0][1] = a[0];
dp[2][0][0] = a[1];
dp[2][0][1] = a[1];
dp[3][0][0] = a[2];
FOR(i, 1, n) rep(j, 5) rep(k, 2) {
if (dp[i][j][k] == -inf)
continue;
int now = i / 2;
if (k)
now = (i + 1) / 2;
FOR(l, 2, 5) {
int ind = i + l;
int nk;
if (ind / 2 == now + 1)
nk = 0;
else if ((ind + 1) / 2 == now + 1)
nk = 1;
else
continue;
if (ind <= n) {
chmax(dp[ind][l][nk], dp[i][j][k] + a[ind - 1]);
if (ind % 2 == 0) {
chmax(dp[ind][l][!nk], dp[i][j][k] + a[ind - 1]);
}
}
// cout<<i<<' '<<ind<<' '<<nk<<' '<<dp[i][j][k]<<'
// '<<dp[ind][l][nk]<<endl;
}
}
ll ans = -inf;
rep(i, n + 1) {
if (i / 2 == n / 2) {
rep(j, 5) chmax(ans, dp[i][j][0]);
}
if ((i + 1) / 2 == n / 2) {
rep(j, 5) chmax(ans, dp[i][j][1]);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
return s << "(" << d.real() << ", " << d.imag() << ")";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
int len = d.size();
rep(i, len) {
s << d[i];
if (i < len - 1)
s << " ";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
int len = d.size();
rep(i, len) { s << d[i] << endl; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const set<T> &v) {
s << "{ ";
for (auto itr = v.begin(); itr != v.end(); ++itr) {
if (itr != v.begin()) {
s << ", ";
}
s << (*itr);
}
s << " }";
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (auto itr = m.begin(); itr != m.end(); ++itr) {
s << " " << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
const ll mod = 1e9 + 7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
const double EPS = 1e-10;
ll dp[200020][5][2];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) { cin >> a[i]; }
rep(i, n + 1) rep(j, 5) rep(k, 2) dp[i][j][k] = -inf;
dp[1][0][1] = a[0];
dp[2][0][0] = a[1];
dp[2][0][1] = a[1];
dp[3][0][0] = a[2];
FOR(i, 1, n) rep(j, 5) rep(k, 2) {
if (dp[i][j][k] == -inf)
continue;
int now = i / 2;
if (k)
now = (i + 1) / 2;
FOR(l, 2, 5) {
int ind = i + l;
int nk;
if (ind / 2 == now + 1)
nk = 0;
else if ((ind + 1) / 2 == now + 1)
nk = 1;
else
continue;
if (ind <= n) {
chmax(dp[ind][l][nk], dp[i][j][k] + a[ind - 1]);
if (ind % 2 == 0) {
chmax(dp[ind][l][!nk], dp[i][j][k] + a[ind - 1]);
}
}
// cout<<i<<' '<<ind<<' '<<nk<<' '<<dp[i][j][k]<<'
// '<<dp[ind][l][nk]<<endl;
}
}
ll ans = -inf;
rep(i, n + 1) {
if (i / 2 == n / 2) {
rep(j, 5) chmax(ans, dp[i][j][0]);
}
if ((i + 1) / 2 == n / 2) {
rep(j, 5) chmax(ans, dp[i][j][1]);
}
}
cout << ans << endl;
} | replace | 75 | 76 | 75 | 76 | 0 | |
p02716 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const int inf = 10000000000000007;
const int MOD = 1000000007;
int dp[5][2][300000];
signed main() {
int n;
cin >> n;
vector<int> a(n + 5, -inf);
rep1(i, n) cin >> a[i];
rep1(i, n) { a[i] += MOD; }
int res = 0;
rep(i, 5) {
rep(j, 300000) {
dp[i][0][j] = 0;
dp[i][1][j] = 0;
}
}
rep1(i, n) {
dp[0][0][i] = dp[0][1][i - 1];
dp[0][1][i] = dp[0][0][i - 1] + a[i];
dp[1][0][i] = max(dp[0][0][i - 1], dp[1][1][i - 1]);
dp[1][1][i] = dp[1][0][i - 1] + a[i];
dp[2][0][i] = max(dp[2][1][i - 1], max(-inf, dp[1][0][i - 1]));
dp[2][1][i] = dp[2][0][i - 1] + a[i];
if (i <= 1) {
dp[1][1][i] = 0;
// dp[1][0][i]=0;
}
if (i <= 1) {
dp[2][1][i] = 0;
// dp[2][0][i]=0;
}
}
if (n % 2 == 0) {
cout << max(dp[0][1][n], max(dp[0][0][n], dp[1][1][n])) - MOD * n / 2
<< endl;
} else {
// exit(1);
res = max(-max(dp[2][0][n], dp[2][1][n]), max(dp[1][1][n], dp[1][0][n]));
if (res == dp[2][0][n])
exit(1);
cout << res - n / (int)2 * MOD << endl;
// cout<<dp[2][0][n]<<"\n";
// cout<<dp[2][1][n]<<"\n";
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const int inf = 10000000000000007;
const int MOD = 1000000007;
int dp[5][2][300000];
signed main() {
int n;
cin >> n;
vector<int> a(n + 5, -inf);
rep1(i, n) cin >> a[i];
rep1(i, n) { a[i] += MOD; }
int res = 0;
rep(i, 5) {
rep(j, 300000) {
dp[i][0][j] = 0;
dp[i][1][j] = 0;
}
}
rep1(i, n) {
dp[0][0][i] = dp[0][1][i - 1];
dp[0][1][i] = dp[0][0][i - 1] + a[i];
dp[1][0][i] = max(dp[0][0][i - 1], dp[1][1][i - 1]);
dp[1][1][i] = dp[1][0][i - 1] + a[i];
dp[2][0][i] = max(dp[2][1][i - 1], max(-inf, dp[1][0][i - 1]));
dp[2][1][i] = dp[2][0][i - 1] + a[i];
if (i <= 1) {
dp[1][1][i] = 0;
// dp[1][0][i]=0;
}
if (i <= 1) {
dp[2][1][i] = 0;
// dp[2][0][i]=0;
}
}
if (n % 2 == 0) {
cout << max(dp[0][1][n], max(dp[0][0][n], dp[1][1][n])) - MOD * n / 2
<< endl;
} else {
// exit(1);
res = max(max(-dp[2][0][n], dp[2][1][n]), max(dp[1][1][n], dp[1][0][n]));
if (res == -dp[2][0][n])
exit(1);
cout << res - n / (int)2 * MOD << endl;
// cout<<dp[2][0][n]<<"\n";
// cout<<dp[2][1][n]<<"\n";
}
return 0;
}
| replace | 55 | 57 | 55 | 57 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MaxN = 1e5 + 10;
int N;
int A[MaxN];
void solve() {
vector<ll> prefix(N + 1);
vector<ll> f(N + 1);
prefix[1] = A[1];
for (int i = 3; i <= N; i += 2)
prefix[i] = prefix[i - 2] + A[i];
for (int n = 2; n <= N; n++) {
if (n & 1)
f[n] = max(f[n - 1], A[n] + f[n - 2]);
else
f[n] = max(prefix[n - 1], A[n] + f[n - 2]);
}
cout << f[N] << endl;
}
int main() {
cin >> N;
for (int i = 1; i <= N; i++)
cin >> A[i];
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MaxN = 2e5 + 10;
int N;
int A[MaxN];
void solve() {
vector<ll> prefix(N + 1);
vector<ll> f(N + 1);
prefix[1] = A[1];
for (int i = 3; i <= N; i += 2)
prefix[i] = prefix[i - 2] + A[i];
for (int n = 2; n <= N; n++) {
if (n & 1)
f[n] = max(f[n - 1], A[n] + f[n - 2]);
else
f[n] = max(prefix[n - 1], A[n] + f[n - 2]);
}
cout << f[N] << endl;
}
int main() {
cin >> N;
for (int i = 1; i <= N; i++)
cin >> A[i];
solve();
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxs = 2e5 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
void pre() {}
ll n;
ll a[maxs];
ll dp[maxs][4];
bool vis[maxs][4];
ll go(ll pos, ll have) {
if (pos >= n) {
if (have <= 1)
return 0;
return -oo;
}
ll &ans = dp[pos][have];
if (vis[pos][have])
return ans;
vis[pos][have] = true;
if (!have)
ans = a[pos] + go(pos + 2, have);
else
ans = max(a[pos] + go(pos + 2, have), go(pos + 1, have - 1));
}
void solve() {
cin >> n;
for (ll i = 0; i < n; i++)
cin >> a[i];
ll ans;
if (n & 1) {
ans = max(go(0, 2), go(1, 1));
} else {
ans = max(go(0, 1), go(1, 0));
}
cout << ans << endl;
}
int main() {
IOS;
pre();
ll T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxs = 2e5 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
void pre() {}
ll n;
ll a[maxs];
ll dp[maxs][4];
bool vis[maxs][4];
ll go(ll pos, ll have) {
if (pos >= n) {
if (have <= 1)
return 0;
return -oo;
}
ll &ans = dp[pos][have];
if (vis[pos][have])
return ans;
vis[pos][have] = true;
if (!have)
ans = a[pos] + go(pos + 2, have);
else
ans = max(a[pos] + go(pos + 2, have), go(pos + 1, have - 1));
return ans;
}
void solve() {
cin >> n;
for (ll i = 0; i < n; i++)
cin >> a[i];
ll ans;
if (n & 1) {
ans = max(go(0, 2), go(1, 1));
} else {
ans = max(go(0, 1), go(1, 0));
}
cout << ans << endl;
}
int main() {
IOS;
pre();
ll T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
} | insert | 42 | 42 | 42 | 44 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int j, n, m, po, no, flag, cnt = 0, cnt2, ar[100000], x, y, i,
co[100000], sum = 0, k, ans = INT_MIN,
sum1 = 0;
string str[1000], ptr, sr, tr, rtr, rt;
vector<long long int> v1, v2;
set<string> s;
queue<long long int> qu;
set<string>::iterator it;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> ar[i];
}
co[0] = 0;
co[1] = 0;
x = ar[1];
for (i = 2; i <= n; i++) {
if (i % 2 == 0)
co[i] = max((co[i - 2] + ar[i]), x);
else {
co[i] = max((co[i - 2] + ar[i]), co[i - 1]);
x += ar[i];
}
}
cout << co[n] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long int j, n, m, po, no, flag, cnt = 0, cnt2, ar[200001], x, y, i,
co[200001], sum = 0, k, ans = INT_MIN,
sum1 = 0;
string str[1000], ptr, sr, tr, rtr, rt;
vector<long long int> v1, v2;
set<string> s;
queue<long long int> qu;
set<string>::iterator it;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> ar[i];
}
co[0] = 0;
co[1] = 0;
x = ar[1];
for (i = 2; i <= n; i++) {
if (i % 2 == 0)
co[i] = max((co[i - 2] + ar[i]), x);
else {
co[i] = max((co[i - 2] + ar[i]), co[i - 1]);
x += ar[i];
}
}
cout << co[n] << endl;
}
| replace | 3 | 5 | 3 | 5 | 0 | |
p02716 | C++ | Runtime Error | // ABC162A.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <iostream>
void solve_A() {
int N;
std::cin >> N;
int mod_1 = N % 10;
N /= 10;
int mod_2 = N % 10;
N /= 10;
int mod_3 = N % 10;
N /= 10;
if (mod_1 == 7 || mod_2 == 7 || mod_3 == 7) {
std::cout << "Yes";
} else {
std::cout << "No";
}
}
void solve_B() {
int N;
std::cin >> N;
long long int sum = 0;
for (int i = 1; i <= N; i++) {
if (i % 3 != 0 && i % 5 != 0) {
sum += i;
}
}
std::cout << sum;
}
int gcd(int y, int x) {
if (y < x)
std::swap(x, y);
int r;
while (x > 0) {
r = y % x;
y = x;
x = r;
}
return y;
}
void solve_C() {
int K;
std::cin >> K;
int sum = 0;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
sum += gcd(gcd(i, j), k);
}
}
}
std::cout << sum;
}
#include <string>
void solve_D() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
long long r_count = 0, g_count = 0, b_count = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r_count++;
else if (s[i] == 'G')
g_count++;
else
b_count++;
}
long long ans = r_count * g_count * b_count;
for (int distance = 1; distance < n + 1; distance++) {
for (int j = 0; j + 2 * distance < n; ++j) {
if (s[j] != s[j + distance] && s[j + distance] != s[j + 2 * distance] &&
s[j] != s[j + 2 * distance])
ans -= 1;
}
}
std::cout << ans << std::endl;
}
const long long MOD = 1e9 + 7;
long long pwr(long long a, long long n) {
a %= MOD;
long long r = 1;
for (; n > 0; n >>= 1) {
if (n & 1)
r = r * a % MOD;
a = a * a % MOD;
}
return r;
}
void solve_E() {
int n, k;
std::cin >> n >> k;
long long answer = 0;
const int N = 1e5 + 10;
long long ways[N];
for (int x = k; x >= 1; x--) {
int m = k / x;
ways[x] = pwr(m, n);
for (int gg = 2 * x; gg <= k; gg += x) {
ways[x] -= ways[gg];
}
ways[x] %= MOD;
ways[x] += MOD;
ways[x] %= MOD;
answer += (ways[x] * x) % MOD;
}
answer %= MOD;
std::cout << answer << std::endl;
}
#include <algorithm>
void solve_F() {
int n;
// long long A[200001], dp[200001], sum[200001];
long long A[100], dp[100], sum[100];
std::cin >> n;
dp[0] = dp[1] = 0;
sum[0] = sum[1] = 0;
for (int i = 1; i <= n; i++) {
std::cin >> A[i];
if (i == 1) {
sum[i] = A[i];
continue;
}
sum[i] = sum[i - 2] + A[i];
}
for (int i = 2; i <= n; i++) {
if (i % 2 == 0) {
dp[i] = std::max(dp[i - 2] + A[i], sum[i - 1]);
} else if (i % 2 == 1) {
dp[i] = std::max(dp[i - 2] + A[i], dp[i - 1]);
}
}
std::cout << dp[n] << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
// solve_A();
// solve_B();
// solve_C();
// solve_D();
// solve_E();
solve_F();
return 0;
}
| // ABC162A.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <iostream>
void solve_A() {
int N;
std::cin >> N;
int mod_1 = N % 10;
N /= 10;
int mod_2 = N % 10;
N /= 10;
int mod_3 = N % 10;
N /= 10;
if (mod_1 == 7 || mod_2 == 7 || mod_3 == 7) {
std::cout << "Yes";
} else {
std::cout << "No";
}
}
void solve_B() {
int N;
std::cin >> N;
long long int sum = 0;
for (int i = 1; i <= N; i++) {
if (i % 3 != 0 && i % 5 != 0) {
sum += i;
}
}
std::cout << sum;
}
int gcd(int y, int x) {
if (y < x)
std::swap(x, y);
int r;
while (x > 0) {
r = y % x;
y = x;
x = r;
}
return y;
}
void solve_C() {
int K;
std::cin >> K;
int sum = 0;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
sum += gcd(gcd(i, j), k);
}
}
}
std::cout << sum;
}
#include <string>
void solve_D() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
long long r_count = 0, g_count = 0, b_count = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r_count++;
else if (s[i] == 'G')
g_count++;
else
b_count++;
}
long long ans = r_count * g_count * b_count;
for (int distance = 1; distance < n + 1; distance++) {
for (int j = 0; j + 2 * distance < n; ++j) {
if (s[j] != s[j + distance] && s[j + distance] != s[j + 2 * distance] &&
s[j] != s[j + 2 * distance])
ans -= 1;
}
}
std::cout << ans << std::endl;
}
const long long MOD = 1e9 + 7;
long long pwr(long long a, long long n) {
a %= MOD;
long long r = 1;
for (; n > 0; n >>= 1) {
if (n & 1)
r = r * a % MOD;
a = a * a % MOD;
}
return r;
}
void solve_E() {
int n, k;
std::cin >> n >> k;
long long answer = 0;
const int N = 1e5 + 10;
long long ways[N];
for (int x = k; x >= 1; x--) {
int m = k / x;
ways[x] = pwr(m, n);
for (int gg = 2 * x; gg <= k; gg += x) {
ways[x] -= ways[gg];
}
ways[x] %= MOD;
ways[x] += MOD;
ways[x] %= MOD;
answer += (ways[x] * x) % MOD;
}
answer %= MOD;
std::cout << answer << std::endl;
}
#include <algorithm>
void solve_F() {
int n;
long long A[200001], dp[200001], sum[200001];
// long long A[100], dp[100], sum[100];
std::cin >> n;
dp[0] = dp[1] = 0;
sum[0] = sum[1] = 0;
for (int i = 1; i <= n; i++) {
std::cin >> A[i];
if (i == 1) {
sum[i] = A[i];
continue;
}
sum[i] = sum[i - 2] + A[i];
}
for (int i = 2; i <= n; i++) {
if (i % 2 == 0) {
dp[i] = std::max(dp[i - 2] + A[i], sum[i - 1]);
} else if (i % 2 == 1) {
dp[i] = std::max(dp[i - 2] + A[i], dp[i - 1]);
}
}
std::cout << dp[n] << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
// solve_A();
// solve_B();
// solve_C();
// solve_D();
// solve_E();
solve_F();
return 0;
}
| replace | 126 | 128 | 126 | 128 | 0 | |
p02716 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define all(V) V.begin(), V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 10;
constexpr lint LINF = LLONG_MAX / 10;
constexpr double eps = 1e-9;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b;
b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }
bool isprime(lint n) {
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
lint mypow(lint a, lint b) {
if (!b)
return 1;
if (b & 1)
return mypow(a, b - 1) * a;
lint memo = mypow(a, b >> 1);
return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
lint memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
void printArray(std::vector<int> &vec) {
rep(i, vec.size() - 1) std::cout << vec[i] << " ";
std::cout << vec.back() << std::endl;
}
template <typename T> void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int> &vec) {
std::string res = "[";
rep(i, vec.size() - 1) res += std::to_string(vec[i]) + ", ";
res += std::to_string(vec.back()) + "]";
return res;
}
int n, a[100010], b[100010][2], c[100010][2];
lint dp[100010][2][2];
signed main() {
std::cin >> n;
rep(i, n) std::cin >> a[i];
rep(i, n) {
if (n % 2) {
b[i][0] = i / 2;
c[i][0] = (i + 1) / 2;
b[i][1] = (i + 1) / 2;
c[i][1] = i / 2 + 1;
if (i == 0)
b[i][1] = 1;
if (i == n - 1)
c[i][1] = n / 2;
} else {
b[i][0] = c[i][0] = (i + 1) / 2;
b[i][1] = c[i][1] = i / 2 + 1;
}
}
rep(i, n) {
rep(j, 2) { rep(k, 2) dp[i][j][k] = -LINF; }
}
dp[0][0][0] = 0;
dp[0][1][0] = a[0];
REP(i, n - 1) {
// use
if (b[i - 1][0] + 1 == b[i][1])
chmax(dp[i][1][0], dp[i - 1][0][0] + a[i]);
if (b[i - 1][0] + 2 == b[i][1])
chmax(dp[i][1][0], dp[i - 1][0][1] + a[i]);
if (b[i][1] != c[i][1] && b[i - 1][0] + 1 == b[i][1] + 1)
chmax(dp[i][1][1], dp[i - 1][0][0] + a[i]);
if (b[i][1] != c[i][1] && b[i - 1][0] + 2 == b[i][1] + 1)
chmax(dp[i][1][1], dp[i - 1][0][1] + a[i]);
// not
if (b[i - 1][0] == b[i][0])
chmax(dp[i][0][0], dp[i - 1][0][0]);
if (b[i - 1][0] + 1 == b[i][0])
chmax(dp[i][0][0], dp[i - 1][0][1]);
if (b[i][0] != c[i][0] && b[i - 1][0] == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][0][0]);
if (b[i][0] != c[i][0] && b[i - 1][0] + 1 == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][0][1]);
if (b[i - 1][1] == b[i][0])
chmax(dp[i][0][0], dp[i - 1][1][0]);
if (b[i - 1][1] + 1 == b[i][0])
chmax(dp[i][0][0], dp[i - 1][1][1]);
if (b[i][0] != c[i][0] && b[i - 1][1] == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][1][0]);
if (b[i][0] != c[i][0] && b[i - 1][1] + 1 == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][1][1]);
}
lint ans = -LINF;
rep(i, 2) { rep(j, 2) chmax(ans, dp[n - 1][i][j]); }
std::cout << ans << std::endl;
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define all(V) V.begin(), V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 10;
constexpr lint LINF = LLONG_MAX / 10;
constexpr double eps = 1e-9;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b;
b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }
bool isprime(lint n) {
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
lint mypow(lint a, lint b) {
if (!b)
return 1;
if (b & 1)
return mypow(a, b - 1) * a;
lint memo = mypow(a, b >> 1);
return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
lint memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
void printArray(std::vector<int> &vec) {
rep(i, vec.size() - 1) std::cout << vec[i] << " ";
std::cout << vec.back() << std::endl;
}
template <typename T> void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int> &vec) {
std::string res = "[";
rep(i, vec.size() - 1) res += std::to_string(vec[i]) + ", ";
res += std::to_string(vec.back()) + "]";
return res;
}
int n, a[200010], b[200010][2], c[200010][2];
lint dp[200010][2][2];
signed main() {
std::cin >> n;
rep(i, n) std::cin >> a[i];
rep(i, n) {
if (n % 2) {
b[i][0] = i / 2;
c[i][0] = (i + 1) / 2;
b[i][1] = (i + 1) / 2;
c[i][1] = i / 2 + 1;
if (i == 0)
b[i][1] = 1;
if (i == n - 1)
c[i][1] = n / 2;
} else {
b[i][0] = c[i][0] = (i + 1) / 2;
b[i][1] = c[i][1] = i / 2 + 1;
}
}
rep(i, n) {
rep(j, 2) { rep(k, 2) dp[i][j][k] = -LINF; }
}
dp[0][0][0] = 0;
dp[0][1][0] = a[0];
REP(i, n - 1) {
// use
if (b[i - 1][0] + 1 == b[i][1])
chmax(dp[i][1][0], dp[i - 1][0][0] + a[i]);
if (b[i - 1][0] + 2 == b[i][1])
chmax(dp[i][1][0], dp[i - 1][0][1] + a[i]);
if (b[i][1] != c[i][1] && b[i - 1][0] + 1 == b[i][1] + 1)
chmax(dp[i][1][1], dp[i - 1][0][0] + a[i]);
if (b[i][1] != c[i][1] && b[i - 1][0] + 2 == b[i][1] + 1)
chmax(dp[i][1][1], dp[i - 1][0][1] + a[i]);
// not
if (b[i - 1][0] == b[i][0])
chmax(dp[i][0][0], dp[i - 1][0][0]);
if (b[i - 1][0] + 1 == b[i][0])
chmax(dp[i][0][0], dp[i - 1][0][1]);
if (b[i][0] != c[i][0] && b[i - 1][0] == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][0][0]);
if (b[i][0] != c[i][0] && b[i - 1][0] + 1 == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][0][1]);
if (b[i - 1][1] == b[i][0])
chmax(dp[i][0][0], dp[i - 1][1][0]);
if (b[i - 1][1] + 1 == b[i][0])
chmax(dp[i][0][0], dp[i - 1][1][1]);
if (b[i][0] != c[i][0] && b[i - 1][1] == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][1][0]);
if (b[i][0] != c[i][0] && b[i - 1][1] + 1 == b[i][0] + 1)
chmax(dp[i][0][1], dp[i - 1][1][1]);
}
lint ans = -LINF;
rep(i, 2) { rep(j, 2) chmax(ans, dp[n - 1][i][j]); }
std::cout << ans << std::endl;
return 0;
} | replace | 106 | 108 | 106 | 108 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) {
return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
rep(i, sz(vec)) {
if (i)
os << " ";
os << vec[i];
}
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.F << " " << p.S;
return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
rep(j, sz(v)) is >> v[j];
return is;
}
template <class T, class T2> inline void add(T &a, T2 b) {
a += b;
if (a >= mod)
a -= mod;
}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int T;
// cin >> T;
T = 1;
while (T--) {
solve();
}
}
// https://atcoder.jp/contests/abc162/submissions/11879810
void solve() {
int n;
cin >> n;
vector<int> a(n);
cin >> a;
vector<map<int, ll>> dp(n + 2);
dp[0][0] = 0;
rep(i, n) {
// [0, i - 1] の個数, max sums
for (const auto &[c, val] : dp[i]) {
// 0 との max をとらないよう
if (!dp[i + 1].count(c))
dp[i + 1][c] = -INF;
chmax(dp[i + 1][c], dp[i][c]);
if (!dp[i + 2].count(c + 1))
dp[i + 2][c + 1] = -INF;
chmax(dp[i + 2][c + 1], dp[i][c] + a[i]);
}
}
ll ans = -INF;
rep(i, n + 2) if (dp[i].count(n / 2)) chmax(ans, dp[i][n / 2]);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) {
return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
rep(i, sz(vec)) {
if (i)
os << " ";
os << vec[i];
}
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.F << " " << p.S;
return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
rep(j, sz(v)) is >> v[j];
return is;
}
template <class T, class T2> inline void add(T &a, T2 b) {
a += b;
if (a >= mod)
a -= mod;
}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int T;
// cin >> T;
T = 1;
while (T--) {
solve();
}
}
// https://atcoder.jp/contests/abc162/submissions/11879810
void solve() {
int n;
cin >> n;
vector<int> a(n);
cin >> a;
vector<map<int, ll>> dp(n + 2);
dp[0][0] = 0;
rep(i, n) {
// [0, i - 1] の個数, max sums
for (const auto &[c, val] : dp[i]) {
// ないと tle
if (c < i / 2 - 1 || c > (i + 1) / 2)
continue;
// 0 との max をとらないよう
if (!dp[i + 1].count(c))
dp[i + 1][c] = -INF;
chmax(dp[i + 1][c], dp[i][c]);
if (!dp[i + 2].count(c + 1))
dp[i + 2][c + 1] = -INF;
chmax(dp[i + 2][c + 1], dp[i][c] + a[i]);
}
}
ll ans = -INF;
rep(i, n + 2) if (dp[i].count(n / 2)) chmax(ans, dp[i][n / 2]);
cout << ans << endl;
}
| insert | 93 | 93 | 93 | 96 | TLE | |
p02716 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LL long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\n", x)
#define plld(x) printf("%lld\n", x)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)
const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 1e5 + 7;
LL dp[maxn];
LL a[maxn];
LL sum[maxn];
int main() {
int n;
while (~sd(n)) {
rep(i, 1, n) slld(a[i]);
sum[1] = a[1];
rep(i, 1, n) {
if (i & 1)
sum[i] = sum[i - 1] + a[i];
else
sum[i] = sum[i - 1];
}
mem(dp);
rep(i, 2, n) {
if (i & 1)
dp[i] = max(dp[i - 2] + a[i], dp[i - 1]);
else
dp[i] = max(dp[i - 2] + a[i], sum[i - 1]);
}
plld(dp[n]);
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LL long long
#define pii pair<int, int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\n", x)
#define plld(x) printf("%lld\n", x)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)
const int INF = 1e9;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;
LL dp[maxn];
LL a[maxn];
LL sum[maxn];
int main() {
int n;
while (~sd(n)) {
rep(i, 1, n) slld(a[i]);
sum[1] = a[1];
rep(i, 1, n) {
if (i & 1)
sum[i] = sum[i - 1] + a[i];
else
sum[i] = sum[i - 1];
}
mem(dp);
rep(i, 2, n) {
if (i & 1)
dp[i] = max(dp[i - 2] + a[i], dp[i - 1]);
else
dp[i] = max(dp[i - 2] + a[i], sum[i - 1]);
}
plld(dp[n]);
}
return 0;
}
| replace | 30 | 31 | 30 | 31 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define sz(x) int(x.size())
#define pb push_back
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
const ll MOD = 1000000007, MOD2 = 998244353, INF = 1e18;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a.at(i);
vector<vector<ll>> dp(n, vector<ll>(5, -INF));
dp.at(0).at(0) = a.at(0);
dp.at(1).at(1) = a.at(1);
dp.at(2).at(2) = a.at(2);
int yutori;
if (n % 2 == 0) {
yutori = 1;
} else {
yutori = 2;
}
rep(i, n) {
rep(j, 3) {
if (i + 2 <= n - 1)
chmax(dp.at(i + 2).at(j), dp.at(i).at(j) + a.at(i + 2));
if (i + 3 <= n - 1)
chmax(dp.at(i + 3).at(j + 1), dp.at(i).at(j) + a.at(i + 3));
if (i + 4 <= n - 1)
chmax(dp.at(i + 4).at(j + 2), dp.at(i).at(j) + a.at(i + 4));
}
}
ll ans = dp.at(n - 1).at(yutori);
chmax(ans, dp.at(n - 2).at(yutori - 1));
if (yutori == 2)
chmax(ans, dp.at(n - 3).at(yutori - 2));
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define sz(x) int(x.size())
#define pb push_back
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
const ll MOD = 1000000007, MOD2 = 998244353, INF = 1e18;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a.at(i);
vector<vector<ll>> dp(n, vector<ll>(5, -INF));
dp.at(0).at(0) = a.at(0);
dp.at(1).at(1) = a.at(1);
if (n > 2)
dp.at(2).at(2) = a.at(2);
int yutori;
if (n % 2 == 0) {
yutori = 1;
} else {
yutori = 2;
}
rep(i, n) {
rep(j, 3) {
if (i + 2 <= n - 1)
chmax(dp.at(i + 2).at(j), dp.at(i).at(j) + a.at(i + 2));
if (i + 3 <= n - 1)
chmax(dp.at(i + 3).at(j + 1), dp.at(i).at(j) + a.at(i + 3));
if (i + 4 <= n - 1)
chmax(dp.at(i + 4).at(j + 2), dp.at(i).at(j) + a.at(i + 4));
}
}
ll ans = dp.at(n - 1).at(yutori);
chmax(ans, dp.at(n - 2).at(yutori - 1));
if (yutori == 2)
chmax(ans, dp.at(n - 3).at(yutori - 2));
cout << ans << endl;
}
| replace | 18 | 19 | 18 | 20 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define enld '\n'
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int k = 1 + N % 2;
vector<vector<ll>> dp(N + 1, vector<ll>(3, -INF));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < k + 1; j++) {
chmax(dp[i + 1][j + 1], dp[i][j]);
ll now = dp[i][j];
if ((i + j) % 2 == 0)
now += A[i];
chmax(dp[i + 1][j], now);
}
}
cout << dp[N][k] << enld;
return 0;
} | #include <bits/stdc++.h>
#define enld '\n'
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int k = 1 + N % 2;
vector<vector<ll>> dp(N + 1, vector<ll>(4, -INF));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < k + 1; j++) {
chmax(dp[i + 1][j + 1], dp[i][j]);
ll now = dp[i][j];
if ((i + j) % 2 == 0)
now += A[i];
chmax(dp[i + 1][j], now);
}
}
cout << dp[N][k] << enld;
return 0;
} | replace | 41 | 42 | 41 | 42 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> (i)) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPI(i, x) for (int i = 1; i <= x; i++)
#define FORI(i, m, n) for (int i = m; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FORA(i, n) for (auto &&i : n)
#define POW(a, b) ((int)(pow(a, b) + .5))
#define MODULO(a, b) (((a) % (b)) < 0 ? (a) % (b) + (b) : (a) % (b))
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0)
DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#define PRINTARR(x, y) \
cerr << #x << "=\n"; \
for (auto itr = x; itr != y; itr++) \
cerr << *itr << " "; \
cerr << endl;
#define PRINTARR2(x, i0, i1) \
cerr << #x << "=\n"; \
for (int ii0 = 0; ii0 < i0; ii0++) { \
for (int ii1 = 0; ii1 < i1; ii1++) \
cerr << x[ii0][ii1] << " "; \
cerr << endl; \
}
#else
#define DEB if (false)
#define DUMP(...)
#define PRINTARR(x, y)
#define PRINTARR2(x, i0, i1)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define pdouble pair<double, double>
#define ld long double
using namespace std;
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;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-7, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
/* set UnionFind BIT deque queue multiset segtree priority_queue bitset map
vector
[&] { return;
}();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる.
//*/
#define MAXN 200100
int N;
int a[MAXN];
int a0[MAXN];
int a1[MAXN];
int memo[MAXN];
int fact(int num) {
if (num == 0 || num == 1)
return 0ll;
if (num % 2 == 0) {
if (num == 4)
return memo[4] = max({a[0] + a[3], a[0] + a[2], a[1] + a[3]});
int val = max(a[num - 1] + fact(num - 2), a[num - 2] + a0[num - 3]);
return memo[num] = val;
} else {
int v0 = a[num - 1] + fact(num - 2);
int v1 = a[num - 2] + fact(num - 3);
int v2 = a0[num - 2];
DUMP(num, v0, v1, v2);
return memo[num] = max({v0, v1, v2});
}
}
signed main() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
cin >> N;
fill(memo, memo + N + 1, -INF);
REP(i, N) cin >> a[i];
REP(i, N) {
a0[i + 1] = a0[i] + (i % 2 == 0 ? a[i] : 0);
a1[i + 1] = a1[i] + (i % 2 == 1 ? a[i] : 0);
}
PRINTARR(a0, a0 + N + 1);
PRINTARR(a1, a1 + N + 1);
print(fact(N));
} | #include <bits/stdc++.h>
using namespace std;
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> (i)) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPI(i, x) for (int i = 1; i <= x; i++)
#define FORI(i, m, n) for (int i = m; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FORA(i, n) for (auto &&i : n)
#define POW(a, b) ((int)(pow(a, b) + .5))
#define MODULO(a, b) (((a) % (b)) < 0 ? (a) % (b) + (b) : (a) % (b))
#define DUMPOUT cerr
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0)
DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define DUMP(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#define PRINTARR(x, y) \
cerr << #x << "=\n"; \
for (auto itr = x; itr != y; itr++) \
cerr << *itr << " "; \
cerr << endl;
#define PRINTARR2(x, i0, i1) \
cerr << #x << "=\n"; \
for (int ii0 = 0; ii0 < i0; ii0++) { \
for (int ii1 = 0; ii1 < i1; ii1++) \
cerr << x[ii0][ii1] << " "; \
cerr << endl; \
}
#else
#define DEB if (false)
#define DUMP(...)
#define PRINTARR(x, y)
#define PRINTARR2(x, i0, i1)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define pdouble pair<double, double>
#define ld long double
using namespace std;
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;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-7, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
/* set UnionFind BIT deque queue multiset segtree priority_queue bitset map
vector
[&] { return;
}();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる.
//*/
#define MAXN 200100
int N;
int a[MAXN];
int a0[MAXN];
int a1[MAXN];
int memo[MAXN];
int fact(int num) {
if (memo[num] != -INF)
return memo[num];
if (num == 0 || num == 1)
return 0ll;
if (num % 2 == 0) {
if (num == 4)
return memo[4] = max({a[0] + a[3], a[0] + a[2], a[1] + a[3]});
int val = max(a[num - 1] + fact(num - 2), a[num - 2] + a0[num - 3]);
return memo[num] = val;
} else {
int v0 = a[num - 1] + fact(num - 2);
int v1 = a[num - 2] + fact(num - 3);
int v2 = a0[num - 2];
DUMP(num, v0, v1, v2);
return memo[num] = max({v0, v1, v2});
}
}
signed main() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
cin >> N;
fill(memo, memo + N + 1, -INF);
REP(i, N) cin >> a[i];
REP(i, N) {
a0[i + 1] = a0[i] + (i % 2 == 0 ? a[i] : 0);
a1[i + 1] = a1[i] + (i % 2 == 1 ? a[i] : 0);
}
PRINTARR(a0, a0 + N + 1);
PRINTARR(a1, a1 + N + 1);
print(fact(N));
} | insert | 137 | 137 | 137 | 139 | TLE | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
typedef long long ll;
const int maxn = 4e5 + 3;
const ll ninf = std::numeric_limits<ll>::min();
int n, a[maxn];
std::map<int, ll> s[maxn];
void filter(int i) {
static std::map<int, ll> t;
t.clear();
int r = (i + 1) / 2 + 5, l = r - 100;
for (auto &&[u, v] : s[i]) {
if (u < l || u > r)
continue;
t.emplace(u, v);
}
t.swap(s[i]);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
s[0][0] = 0;
s[1][0] = 0;
s[1][1] = a[0];
s[2][0] = 0;
s[2][1] = a[1];
for (int i = 3; i <= n; ++i) {
auto &cs = s[i];
for (int j = std::max(i - 4, 0); j <= i - 2; ++j) {
for (auto &&[x, y] : s[j]) {
if (cs.find(x + 1) == cs.end())
cs[x + 1] = y + a[i - 1];
else
cs[x + 1] = std::max(cs[x + 1], y + a[i - 1]);
}
}
filter(i);
}
ll ans = ninf;
for (int i = 0; i <= n; ++i) {
if (s[i].find(n / 2) != s[i].end()) {
ans = std::max(ans, s[i][n / 2]);
}
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
const int maxn = 4e5 + 3;
const ll ninf = std::numeric_limits<ll>::min();
int n, a[maxn];
std::map<int, ll> s[maxn];
void filter(int i) {
static std::map<int, ll> t;
t.clear();
int r = (i + 1) / 2 + 5, l = r - 20;
for (auto &&[u, v] : s[i]) {
if (u < l || u > r)
continue;
t.emplace(u, v);
}
t.swap(s[i]);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
s[0][0] = 0;
s[1][0] = 0;
s[1][1] = a[0];
s[2][0] = 0;
s[2][1] = a[1];
for (int i = 3; i <= n; ++i) {
auto &cs = s[i];
for (int j = std::max(i - 4, 0); j <= i - 2; ++j) {
for (auto &&[x, y] : s[j]) {
if (cs.find(x + 1) == cs.end())
cs[x + 1] = y + a[i - 1];
else
cs[x + 1] = std::max(cs[x + 1], y + a[i - 1]);
}
}
filter(i);
}
ll ans = ninf;
for (int i = 0; i <= n; ++i) {
if (s[i].find(n / 2) != s[i].end()) {
ans = std::max(ans, s[i][n / 2]);
}
}
printf("%lld\n", ans);
return 0;
} | replace | 11 | 12 | 11 | 12 | TLE | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
ll dp[N], sum[N], a[N];
int main() {
int n;
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (i == 1)
sum[i] = a[i];
else
sum[i] = sum[i - 2] + a[i];
}
for (int i = 2; i <= n; i++) {
if (i & 1)
dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
else
dp[i] = max(dp[i - 2] + a[i], sum[i - 1]);
}
printf("%lld\n", dp[n]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
ll dp[N], sum[N], a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (i == 1)
sum[i] = a[i];
else
sum[i] = sum[i - 2] + a[i];
}
for (int i = 2; i <= n; i++) {
if (i & 1)
dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
else
dp[i] = max(dp[i - 2] + a[i], sum[i - 1]);
}
printf("%lld\n", dp[n]);
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010], n;
map<int, ll> mem[100010];
ll dp(int x, int nm) {
if (nm == 1) {
if (x >= n)
return -1e17;
return a[x];
}
if (n - x < (nm - 1) * 2 + 1) {
return -1e17;
}
if (mem[x].count(nm)) {
return mem[x][nm];
}
ll res = a[x];
res = a[x] + dp(x + 2, nm - 1);
// if((n-x-2)>2*(nm-1)){
res = max(res, a[x] + dp(x + 3, nm - 1));
// }
mem[x][nm] = res;
return res;
}
int main() {
while (cin >> n) {
ll ans = 0;
for (int i = 0; i < n; ++i) {
mem[i].clear();
scanf("%d", a + i);
}
ans = max(dp(0, n / 2), dp(1, n / 2));
ans = max(ans, dp(2, n / 2));
printf("%lld\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[200010], n;
map<int, ll> mem[200010];
ll dp(int x, int nm) {
if (nm == 1) {
if (x >= n)
return -1e17;
return a[x];
}
if (n - x < (nm - 1) * 2 + 1) {
return -1e17;
}
if (mem[x].count(nm)) {
return mem[x][nm];
}
ll res = a[x];
res = a[x] + dp(x + 2, nm - 1);
// if((n-x-2)>2*(nm-1)){
res = max(res, a[x] + dp(x + 3, nm - 1));
// }
mem[x][nm] = res;
return res;
}
int main() {
while (cin >> n) {
ll ans = 0;
for (int i = 0; i < n; ++i) {
mem[i].clear();
scanf("%d", a + i);
}
ans = max(dp(0, n / 2), dp(1, n / 2));
ans = max(ans, dp(2, n / 2));
printf("%lld\n", ans);
}
return 0;
}
| replace | 7 | 9 | 7 | 9 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;
signed main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int x[n][3];
x[0][0] = a[0];
x[0][1] = MOD * MOD;
x[0][2] = MOD * MOD;
x[1][0] = MOD * MOD;
x[1][1] = a[1];
x[1][2] = MOD * MOD;
x[2][0] = a[0] + a[2];
x[2][1] = MOD * MOD;
x[2][2] = a[2];
x[3][0] = MOD * MOD;
x[3][1] = max(a[1], a[0]) + a[3];
x[3][2] = MOD * MOD;
for (int i = 4; i < n; i++) {
if (x[i - 2][0] != MOD * MOD)
x[i][0] = x[i - 2][0] + a[i];
else
x[i][0] = MOD * MOD;
if (x[i - 3][0] != MOD * MOD)
x[i][1] = x[i - 3][0] + a[i];
else
x[i][1] = MOD * MOD;
if (x[i - 3][1] != MOD * MOD)
x[i][2] = x[i - 3][1] + a[i];
else
x[i][2] = MOD * MOD;
if (x[i - 4][0] != MOD * MOD) {
if (x[i][2] != MOD * MOD)
x[i][2] = max(x[i][2], x[i - 4][0] + a[i]);
else
x[i][2] = x[i - 4][0] + a[i];
}
if (x[i][2] != MOD * MOD)
x[i][2] = max(x[i][2], x[i - 2][2] + a[i]);
else
x[i][2] = x[i - 2][2] + a[i];
if (x[i][1] != MOD * MOD)
x[i][1] = max(x[i][1], x[i - 2][1] + a[i]);
else
x[i][1] = x[i - 2][1] + a[i];
}
if (n % 2) {
if (n == 3)
cout << x[n - 2][1] << endl;
else
cout << max(x[n - 2][1], x[n - 1][2]) << endl;
} else {
cout << max(x[n - 2][0], x[n - 1][1]) << endl;
// cerr<<x[n-2][0]<<' '<<x[n-1][1]<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;
signed main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
if (n == 2) {
cout << max(a[0], a[1]) << endl;
return 0;
}
int x[n][3];
x[0][0] = a[0];
x[0][1] = MOD * MOD;
x[0][2] = MOD * MOD;
x[1][0] = MOD * MOD;
x[1][1] = a[1];
x[1][2] = MOD * MOD;
x[2][0] = a[0] + a[2];
x[2][1] = MOD * MOD;
x[2][2] = a[2];
x[3][0] = MOD * MOD;
x[3][1] = max(a[1], a[0]) + a[3];
x[3][2] = MOD * MOD;
for (int i = 4; i < n; i++) {
if (x[i - 2][0] != MOD * MOD)
x[i][0] = x[i - 2][0] + a[i];
else
x[i][0] = MOD * MOD;
if (x[i - 3][0] != MOD * MOD)
x[i][1] = x[i - 3][0] + a[i];
else
x[i][1] = MOD * MOD;
if (x[i - 3][1] != MOD * MOD)
x[i][2] = x[i - 3][1] + a[i];
else
x[i][2] = MOD * MOD;
if (x[i - 4][0] != MOD * MOD) {
if (x[i][2] != MOD * MOD)
x[i][2] = max(x[i][2], x[i - 4][0] + a[i]);
else
x[i][2] = x[i - 4][0] + a[i];
}
if (x[i][2] != MOD * MOD)
x[i][2] = max(x[i][2], x[i - 2][2] + a[i]);
else
x[i][2] = x[i - 2][2] + a[i];
if (x[i][1] != MOD * MOD)
x[i][1] = max(x[i][1], x[i - 2][1] + a[i]);
else
x[i][1] = x[i - 2][1] + a[i];
}
if (n % 2) {
if (n == 3)
cout << x[n - 2][1] << endl;
else
cout << max(x[n - 2][1], x[n - 1][2]) << endl;
} else {
cout << max(x[n - 2][0], x[n - 1][1]) << endl;
// cerr<<x[n-2][0]<<' '<<x[n-1][1]<<endl;
}
}
| insert | 13 | 13 | 13 | 17 | 0 | |
p02716 | C++ | Runtime Error | #include <iostream>
using namespace std;
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
int main() {
long long int n;
cin >> n;
vector<long long int> v;
for (long long int i = 0; i < n; i++) {
long long int in;
cin >> in;
v.push_back(in);
}
long long int d[3][114514] = {};
d[0][0] = v[0];
d[1][1] = v[1];
for (long long int i = 1; i < n; i++) {
if (i >= 2) {
d[0][i] = d[0][i - 2] + v[i];
d[1][i] = d[1][i - 2] + v[i];
d[2][i] = d[2][i - 2] + v[i];
}
if (i >= 3) {
d[1][i] = max(d[0][i - 3] + v[i], d[1][i]);
d[2][i] = max(d[1][i - 3] + v[i], d[2][i]);
}
if (i >= 4) {
d[2][i] = max(d[0][i - 4] + v[i], d[2][i]);
}
}
long long int ans = 0;
if ((n % 2) == 0) {
ans = max(d[0][n - 2], d[1][n - 1]);
} else {
ans = max(d[0][n - 3], d[1][n - 2]);
ans = max(ans, d[2][n - 1]);
}
cout << ans << endl;
return 0;
}
| #include <iostream>
using namespace std;
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
int main() {
long long int n;
cin >> n;
vector<long long int> v;
for (long long int i = 0; i < n; i++) {
long long int in;
cin >> in;
v.push_back(in);
}
long long int d[3][214514] = {};
d[0][0] = v[0];
d[1][1] = v[1];
for (long long int i = 1; i < n; i++) {
if (i >= 2) {
d[0][i] = d[0][i - 2] + v[i];
d[1][i] = d[1][i - 2] + v[i];
d[2][i] = d[2][i - 2] + v[i];
}
if (i >= 3) {
d[1][i] = max(d[0][i - 3] + v[i], d[1][i]);
d[2][i] = max(d[1][i - 3] + v[i], d[2][i]);
}
if (i >= 4) {
d[2][i] = max(d[0][i - 4] + v[i], d[2][i]);
}
}
long long int ans = 0;
if ((n % 2) == 0) {
ans = max(d[0][n - 2], d[1][n - 1]);
} else {
ans = max(d[0][n - 3], d[1][n - 2]);
ans = max(ans, d[2][n - 1]);
}
cout << ans << endl;
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1001001001001001;
ll dp[200001];
ll a[200001];
ll dpall[200001];
int n;
ll init() {
rep(i, 200001) dp[i] = -INF;
rep(i, 200001) dpall[i] = -INF;
}
ll rec(int x, int k) {
// cout << "x:" << x << "k:" << k << endl;
if (k * 2 > x)
return dpall[x];
if (k == 0)
return ll(0);
if (dp[x] > -INF)
return dp[x];
ll res = -INF;
ll temp = 0;
temp += a[x - 1];
temp += rec(x - 2, k - 1);
// cout << "x-2:k-1 " << x-2 << " : " << k-1 << " " << temp << endl;
res = max(res, temp);
temp = 0;
temp += a[x - 2];
temp += rec(x - 3, k - 1);
/*
cout << "x-3:k-1 " << x-3 << " : " << k-1 << " " << temp << endl;
cout << a[x-2] << " " << rec(x-3,k-1) << endl;
*/
res = max(res, temp);
if (x % 2 == 0)
return dp[x] = res;
temp = 0;
temp = dpall[x - 2];
// cout << "x-2:k " << x-2 << " : " << k << " " << temp << endl;
res = max(res, temp);
return dp[x] = res;
}
int main() {
cin >> n;
rep(i, n) cin >> a[i];
init();
for (int i = 1; i <= n / 2; ++i) {
if (i == 1) {
dpall[1] = a[0];
continue;
}
dpall[2 * i - 1] = dpall[2 * i - 3] + a[2 * i - 2];
}
/*
cout << "dpall" << endl;
for(int i=1; i<=n; i+=2){
cout <<"i" << i <<" : "<<dpall[i] << endl;
}*/
cout << rec(n, n / 2) << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1001001001001001;
ll dp[200001];
ll a[200001];
ll dpall[200001];
int n;
ll init() {
rep(i, 200001) dp[i] = -INF;
rep(i, 200001) dpall[i] = -INF;
return 0;
}
ll rec(int x, int k) {
// cout << "x:" << x << "k:" << k << endl;
if (k * 2 > x)
return dpall[x];
if (k == 0)
return ll(0);
if (dp[x] > -INF)
return dp[x];
ll res = -INF;
ll temp = 0;
temp += a[x - 1];
temp += rec(x - 2, k - 1);
// cout << "x-2:k-1 " << x-2 << " : " << k-1 << " " << temp << endl;
res = max(res, temp);
temp = 0;
temp += a[x - 2];
temp += rec(x - 3, k - 1);
/*
cout << "x-3:k-1 " << x-3 << " : " << k-1 << " " << temp << endl;
cout << a[x-2] << " " << rec(x-3,k-1) << endl;
*/
res = max(res, temp);
if (x % 2 == 0)
return dp[x] = res;
temp = 0;
temp = dpall[x - 2];
// cout << "x-2:k " << x-2 << " : " << k << " " << temp << endl;
res = max(res, temp);
return dp[x] = res;
}
int main() {
cin >> n;
rep(i, n) cin >> a[i];
init();
for (int i = 1; i <= n / 2; ++i) {
if (i == 1) {
dpall[1] = a[0];
continue;
}
dpall[2 * i - 1] = dpall[2 * i - 3] + a[2 * i - 2];
}
/*
cout << "dpall" << endl;
for(int i=1; i<=n; i+=2){
cout <<"i" << i <<" : "<<dpall[i] << endl;
}*/
cout << rec(n, n / 2) << endl;
}
| insert | 16 | 16 | 16 | 17 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
#include <vector>
#define int long long int
int function(int arr[], int initial, int final, int curr, int memo[][3]) {
if (initial > final) {
if (curr > 0) {
return -100000000000000;
} else
return 0;
} else {
if (curr == 0) {
int val = arr[initial] + function(arr, initial + 2, final, curr, memo);
memo[initial][curr] = val;
return memo[initial][curr];
} else {
int val1 = arr[initial] + function(arr, initial + 2, final, curr, memo);
int val2 =
arr[initial] + function(arr, initial + 3, final, curr - 1, memo);
memo[initial][curr] = max(val1, val2);
return memo[initial][curr];
}
}
}
int function2(int arr[], int initial, int final, int curr, int memo[][2]) {
if (initial > final) {
if (curr == 0 && initial == final + 4)
return -1000000000000000;
if (curr > 0)
return -1000000000000000;
return 0;
}
if (memo[initial][curr] != -1)
return memo[initial][curr];
else {
if (curr == 0) {
int x = arr[initial] + function2(arr, initial + 2, final, curr, memo);
memo[initial][curr] = x;
return memo[initial][curr];
} else {
int x = arr[initial] + function2(arr, initial + 2, final, curr, memo);
int y = arr[initial] + function2(arr, initial + 4, final, curr - 1, memo);
memo[initial][curr] = max(x, y);
return memo[initial][curr];
}
}
}
int32_t main() {
int n;
cin >> n;
int arr[n + 1];
int j;
for (j = 1; j <= n; j++) {
cin >> arr[j];
}
int memo[n + 1][3];
int i;
for (i = 0; i <= n; i++) {
for (j = 0; j < 3; j++) {
memo[i][j] = -1;
}
}
if (n % 2 == 0) {
int val1 = function(arr, 1, n, 1, memo);
int val2 = function(arr, 2, n, 0, memo);
cout << max(val1, val2) << endl;
} else {
int val1 = function(arr, 1, n, 2, memo);
int val2 = function(arr, 2, n, 1, memo);
int val3 = function(arr, 3, n, 0, memo);
int answer2 = max(val1, max(val2, val3));
int memo2[n + 1][2];
for (i = 0; i <= n; i++) {
memo2[i][0] = -1;
memo2[i][1] = -1;
}
int val4 = function2(arr, 1, n, 1, memo2);
answer2 = max(answer2, val4);
cout << answer2 << endl;
}
}
| #include <iostream>
using namespace std;
#include <vector>
#define int long long int
int function(int arr[], int initial, int final, int curr, int memo[][3]) {
if (initial > final) {
if (curr > 0) {
return -100000000000000;
} else
return 0;
}
if (memo[initial][curr] != -1)
return memo[initial][curr];
else {
if (curr == 0) {
int val = arr[initial] + function(arr, initial + 2, final, curr, memo);
memo[initial][curr] = val;
return memo[initial][curr];
} else {
int val1 = arr[initial] + function(arr, initial + 2, final, curr, memo);
int val2 =
arr[initial] + function(arr, initial + 3, final, curr - 1, memo);
memo[initial][curr] = max(val1, val2);
return memo[initial][curr];
}
}
}
int function2(int arr[], int initial, int final, int curr, int memo[][2]) {
if (initial > final) {
if (curr == 0 && initial == final + 4)
return -1000000000000000;
if (curr > 0)
return -1000000000000000;
return 0;
}
if (memo[initial][curr] != -1)
return memo[initial][curr];
else {
if (curr == 0) {
int x = arr[initial] + function2(arr, initial + 2, final, curr, memo);
memo[initial][curr] = x;
return memo[initial][curr];
} else {
int x = arr[initial] + function2(arr, initial + 2, final, curr, memo);
int y = arr[initial] + function2(arr, initial + 4, final, curr - 1, memo);
memo[initial][curr] = max(x, y);
return memo[initial][curr];
}
}
}
int32_t main() {
int n;
cin >> n;
int arr[n + 1];
int j;
for (j = 1; j <= n; j++) {
cin >> arr[j];
}
int memo[n + 1][3];
int i;
for (i = 0; i <= n; i++) {
for (j = 0; j < 3; j++) {
memo[i][j] = -1;
}
}
if (n % 2 == 0) {
int val1 = function(arr, 1, n, 1, memo);
int val2 = function(arr, 2, n, 0, memo);
cout << max(val1, val2) << endl;
} else {
int val1 = function(arr, 1, n, 2, memo);
int val2 = function(arr, 2, n, 1, memo);
int val3 = function(arr, 3, n, 0, memo);
int answer2 = max(val1, max(val2, val3));
int memo2[n + 1][2];
for (i = 0; i <= n; i++) {
memo2[i][0] = -1;
memo2[i][1] = -1;
}
int val4 = function2(arr, 1, n, 1, memo2);
answer2 = max(answer2, val4);
cout << answer2 << endl;
}
}
| replace | 10 | 11 | 10 | 14 | TLE | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
const ll INF = 9999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vl A;
ll dp[n][4]; // どこまで見たか・i番目まで見たときにi-(使った数)*2+2
rep(i, n) {
cin >> a;
A.push_back(a);
}
rep(i, n + 1) {
if (i == 0) {
dp[0][0] = A[0];
dp[0][1] = -INF;
dp[0][2] = -INF;
} else {
if (i == 1)
dp[i][0] = -INF;
else
dp[i][0] = dp[i - 2][0] + A[i];
if (i == 1)
dp[i][1] = A[i];
else
dp[i][1] = dp[i - 2][1] + A[i];
if (i > 2)
dp[i][1] = max(dp[i - 3][0] + A[i], dp[i][1]);
if (i == 1)
dp[i][2] = -INF;
else if (i == 2)
dp[i][2] = A[i];
else
dp[i][2] = dp[i - 2][2] + A[i];
if (i > 2)
dp[i][2] = max(dp[i - 3][1] + A[i], dp[i][2]);
if (i > 3)
dp[i][2] = max(dp[i - 4][0] + A[i], dp[i][2]);
}
}
if (n % 2 == 0)
ans = max(dp[n - 2][0], dp[n - 1][1]);
else
ans = max({dp[n - 3][0], dp[n - 2][1], dp[n - 1][2]});
cout << ans << endl;
} | #include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
const ll INF = 9999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
vl A;
ll dp[n][4]; // どこまで見たか・i番目まで見たときにi-(使った数)*2+2
rep(i, n) {
cin >> a;
A.push_back(a);
}
rep(i, n) {
if (i == 0) {
dp[0][0] = A[0];
dp[0][1] = -INF;
dp[0][2] = -INF;
} else {
if (i == 1)
dp[i][0] = -INF;
else
dp[i][0] = dp[i - 2][0] + A[i];
if (i == 1)
dp[i][1] = A[i];
else
dp[i][1] = dp[i - 2][1] + A[i];
if (i > 2)
dp[i][1] = max(dp[i - 3][0] + A[i], dp[i][1]);
if (i == 1)
dp[i][2] = -INF;
else if (i == 2)
dp[i][2] = A[i];
else
dp[i][2] = dp[i - 2][2] + A[i];
if (i > 2)
dp[i][2] = max(dp[i - 3][1] + A[i], dp[i][2]);
if (i > 3)
dp[i][2] = max(dp[i - 4][0] + A[i], dp[i][2]);
}
}
if (n % 2 == 0)
ans = max(dp[n - 2][0], dp[n - 1][1]);
else
ans = max({dp[n - 3][0], dp[n - 2][1], dp[n - 1][2]});
cout << ans << endl;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define fi first
#define sd second
#define lson (nd << 1)
#define rson (nd + nd + 1)
#define PB push_back
#define mid (l + r >> 1)
#define MP make_pair
#define SZ(x) (int)x.size()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
inline LL read() {
LL res = 0, f = 1;
char ch = getchar();
while (ch<'0' | ch> '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
res = res * 10 + ch - '0';
ch = getchar();
}
return res * f;
}
const int MAXN = 200'005;
const int MOD = 1000000007;
const LL inf = (LL)1e18;
void addmod(int &a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
int mulmod(int a, int b) { return 1ll * a * b % MOD; }
template <typename T> void chmin(T a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T a, T b) {
if (b > a)
a = b;
}
LL a[MAXN], n;
map<int, long long> H[MAXN];
LL dfs(int idx, int cnt) {
if (idx >= n + 1) {
if (cnt == n / 2)
return 0;
else
return -inf;
}
if (H[idx].count(cnt))
return H[idx][cnt];
if (idx - cnt - 1 > (n + 1) / 2)
return -inf;
return H[idx][cnt] = max(dfs(idx + 1, cnt), dfs(idx + 2, cnt + 1) + a[idx]);
}
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
cout << dfs(1, 0);
return 0;
}
| #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define fi first
#define sd second
#define lson (nd << 1)
#define rson (nd + nd + 1)
#define PB push_back
#define mid (l + r >> 1)
#define MP make_pair
#define SZ(x) (int)x.size()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
inline LL read() {
LL res = 0, f = 1;
char ch = getchar();
while (ch<'0' | ch> '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
res = res * 10 + ch - '0';
ch = getchar();
}
return res * f;
}
const int MAXN = 200'005;
const int MOD = 1000000007;
const LL inf = (LL)1e18;
void addmod(int &a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
int mulmod(int a, int b) { return 1ll * a * b % MOD; }
template <typename T> void chmin(T a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T a, T b) {
if (b > a)
a = b;
}
LL a[MAXN], n;
map<int, long long> H[MAXN];
LL dfs(int idx, int cnt) {
if (idx >= n + 1) {
if (cnt == n / 2)
return 0;
else
return -inf;
}
if (H[idx].count(cnt))
return H[idx][cnt];
if ((cnt + (n - idx + 2) / 2) < n / 2)
return -inf;
return H[idx][cnt] = max(dfs(idx + 1, cnt), dfs(idx + 2, cnt + 1) + a[idx]);
}
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
cout << dfs(1, 0);
return 0;
}
| replace | 72 | 73 | 72 | 73 | TLE | |
p02716 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define mst(a, b) memset(a, b, sizeof(a))
#define scd(a) scanf("%d", &a)
#define scdd(a, b) scanf("%d%d", &a, &b)
#define scddd(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define dbg(a) cout << "* " << #a << " : " << a << endl
#define fr first
#define se second
#define ls x << 1
#define rs x << 1 | 1
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define lowbit(x) x & (-x)
#define ac cout << ans << endl
// #define DEBUG 0
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const ull hashp = 131;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 100;
ll sum[2][maxn];
int a[maxn];
void solve() {
int n;
scd(n);
rep1(i, n) scd(a[i]);
ll ans = 0;
for (int i = n - 1 - (n & 1); i >= 1; i -= 2) {
ans += 1ll * a[i];
sum[0][i] = sum[0][i + 2] + a[i + 1] - a[i];
if (n & 1)
sum[1][i] = sum[1][i + 2] + a[i + 2] - a[i + 1];
}
if (n & 1) {
ll mx = 0, mark = 0;
for (int i = n - 1 - (n & 1); i >= 1; i -= 2) {
mx = max(mx, sum[1][i]);
mark = max(mark, sum[0][i] + mx);
}
ans += mark;
} else {
ll mx = 0;
for (int i = 1; i <= n; i += 2)
mx = max(mx, sum[0][i]);
ans += mx;
}
ac;
}
int main() {
// IOS;
// freopen("fenwick.in","r",stdin);
// freopen("fenwick.out","w",stdout);
solve();
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define mst(a, b) memset(a, b, sizeof(a))
#define scd(a) scanf("%d", &a)
#define scdd(a, b) scanf("%d%d", &a, &b)
#define scddd(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define dbg(a) cout << "* " << #a << " : " << a << endl
#define fr first
#define se second
#define ls x << 1
#define rs x << 1 | 1
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define lowbit(x) x & (-x)
#define ac cout << ans << endl
// #define DEBUG 0
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const ull hashp = 131;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
ll sum[2][maxn];
int a[maxn];
void solve() {
int n;
scd(n);
rep1(i, n) scd(a[i]);
ll ans = 0;
for (int i = n - 1 - (n & 1); i >= 1; i -= 2) {
ans += 1ll * a[i];
sum[0][i] = sum[0][i + 2] + a[i + 1] - a[i];
if (n & 1)
sum[1][i] = sum[1][i + 2] + a[i + 2] - a[i + 1];
}
if (n & 1) {
ll mx = 0, mark = 0;
for (int i = n - 1 - (n & 1); i >= 1; i -= 2) {
mx = max(mx, sum[1][i]);
mark = max(mark, sum[0][i] + mx);
}
ans += mark;
} else {
ll mx = 0;
for (int i = 1; i <= n; i += 2)
mx = max(mx, sum[0][i]);
ans += mx;
}
ac;
}
int main() {
// IOS;
// freopen("fenwick.in","r",stdin);
// freopen("fenwick.out","w",stdout);
solve();
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
return 0;
} | replace | 41 | 42 | 41 | 42 | 0 | |
p02716 | C++ | Time Limit Exceeded | #define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));
ll mod = 1e9 + 7;
namespace {
ll mul(ll a, ll b) {
ll val = a * b - (ll)((ld)a * b / mod) * mod;
if (val < 0)
val += mod;
if (val >= mod)
val -= mod;
return val;
}
ll poww(ll a, ll b) {
ll val = 1;
a %= mod;
while (b > 0) {
if (b % 2)
val = mul(a, val);
a = mul(a, a);
b >>= 1;
}
return val % mod;
}
ll inv(ll a) { return poww(a, mod - 2); }
} // namespace
ll const maxn = 3e5 + 5;
unordered_map<ll, ll> d[maxn];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("output.txt", "w", stdout);
ll n;
cin >> n;
vector<ll> a(n + 1);
ll sm = 0;
for (ll i = 1; i <= n; i++)
cin >> a[i], sm += a[i];
ll k = (n + 1) / 2;
d[0][0] = 0;
for (ll i = 0; i <= n; i++) {
ll ost = n - i;
for (ll cnt = max(0LL, k - ost); cnt <= k - ost / 2; cnt++) {
if (d[i].find(cnt) == d[i].end())
continue;
if (ost / 2 + cnt > k)
continue;
if (ost + cnt < k)
continue;
for (ll j = i + 1; j <= min(i + 2, n); j++) {
if (d[j].find(cnt + 1) == d[j].end()) {
d[j][cnt + 1] = d[i][cnt] + a[j];
} else {
d[j][cnt + 1] = min(d[j][cnt + 1], d[i][cnt] + a[j]);
}
}
}
}
cout << sm - min(d[n][k], d[n - 1][k]);
return 0;
}
/*
*/
| #define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));
ll mod = 1e9 + 7;
namespace {
ll mul(ll a, ll b) {
ll val = a * b - (ll)((ld)a * b / mod) * mod;
if (val < 0)
val += mod;
if (val >= mod)
val -= mod;
return val;
}
ll poww(ll a, ll b) {
ll val = 1;
a %= mod;
while (b > 0) {
if (b % 2)
val = mul(a, val);
a = mul(a, a);
b >>= 1;
}
return val % mod;
}
ll inv(ll a) { return poww(a, mod - 2); }
} // namespace
ll const maxn = 3e5 + 5;
unordered_map<ll, ll> d[maxn];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("output.txt", "w", stdout);
ll n;
cin >> n;
vector<ll> a(n + 1);
ll sm = 0;
for (ll i = 1; i <= n; i++)
cin >> a[i], sm += a[i];
ll k = (n + 1) / 2;
d[0][0] = 0;
for (ll i = 0; i <= n; i++) {
ll ost = n - i;
ll ost1 = max(0LL, i - 1);
ll left = max({k - ost, ost1 / 2, 0LL});
ll right = (k - ost / 2);
assert(right - left < 7);
for (ll cnt = left; cnt <= right; cnt++) {
if (d[i].find(cnt) == d[i].end())
continue;
if (ost / 2 + cnt > k)
continue;
if (ost + cnt < k)
continue;
for (ll j = i + 1; j <= min(i + 2, n); j++) {
if (d[j].find(cnt + 1) == d[j].end()) {
d[j][cnt + 1] = d[i][cnt] + a[j];
} else {
d[j][cnt + 1] = min(d[j][cnt + 1], d[i][cnt] + a[j]);
}
}
}
}
cout << sm - min(d[n][k], d[n - 1][k]);
return 0;
}
/*
*/
| replace | 95 | 96 | 95 | 102 | TLE | |
p02716 | C++ | Runtime Error |
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
if (p)
cout << fixed << setprecision(p) << a << "\n";
else
cout << a << "\n";
}
// end of template
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
int N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
vector<vector<ll>> dp(N, vector<ll>(3, -(1LL << 61))); // N/2, N/2+1
dp[0][2] = 0;
if (N % 2 == 1) {
dp[0][0] = A[0];
dp[1][1] = A[1];
} else {
dp[0][1] = A[0];
dp[1][2] = A[1];
}
rep(i, 2, N) {
rep(j, 3) dp[i][j] = dp[i - 2][j] + A[i];
if (i >= 3) {
rep(j, 2) dp[i][j + 1] = max(dp[i][j + 1], dp[i - 3][j] + A[i]);
}
}
output(max({dp[N - 1][2], dp[N - 2][1], dp[N - 3][0]}));
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
if (p)
cout << fixed << setprecision(p) << a << "\n";
else
cout << a << "\n";
}
// end of template
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
int N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
vector<vector<ll>> dp(N, vector<ll>(3, -(1LL << 61))); // N/2, N/2+1
dp[0][2] = 0;
if (N % 2 == 1) {
dp[0][0] = A[0];
dp[1][1] = A[1];
} else {
dp[0][1] = A[0];
dp[1][2] = A[1];
}
rep(i, 2, N) {
rep(j, 3) dp[i][j] = dp[i - 2][j] + A[i];
if (i >= 3) {
rep(j, 2) dp[i][j + 1] = max(dp[i][j + 1], dp[i - 3][j] + A[i]);
}
}
ll ans = max(dp[N - 1][2], dp[N - 2][1]);
if (N >= 3)
ans = max(ans, dp[N - 3][0]);
output(ans);
return 0;
}
| replace | 57 | 59 | 57 | 61 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll mod = 1000000007;
const double eps = 1e-8;
const ll INF = 1e16;
#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif
template <typename A, size_t N, typename T>
void st_fill(A (&arr)[N], const T &val) {
fill((T *)arr, (T *)(arr + N), val);
}
void chmax(ll &a, ll b) { a = max(a, b); }
ll dp[100010][2][3];
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
st_fill(dp, -INF);
int r = 1 + (N % 2);
dp[0][0][r - 1] = 0;
dp[0][1][r] = A[0];
for (int i = 1; i < N; ++i) {
for (int j = 0; j < 3; ++j) {
chmax(dp[i][1][j], dp[i - 1][0][j] + A[i]);
chmax(dp[i][0][j], dp[i - 1][1][j]);
if (j > 0)
chmax(dp[i][0][j - 1], dp[i - 1][0][j]);
}
}
ll res = -INF;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 3; ++j) {
res = max(res, dp[N - 1][i][j]);
}
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll mod = 1000000007;
const double eps = 1e-8;
const ll INF = 1e16;
#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif
template <typename A, size_t N, typename T>
void st_fill(A (&arr)[N], const T &val) {
fill((T *)arr, (T *)(arr + N), val);
}
void chmax(ll &a, ll b) { a = max(a, b); }
ll dp[200010][2][3];
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
st_fill(dp, -INF);
int r = 1 + (N % 2);
dp[0][0][r - 1] = 0;
dp[0][1][r] = A[0];
for (int i = 1; i < N; ++i) {
for (int j = 0; j < 3; ++j) {
chmax(dp[i][1][j], dp[i - 1][0][j] + A[i]);
chmax(dp[i][0][j], dp[i - 1][1][j]);
if (j > 0)
chmax(dp[i][0][j - 1], dp[i - 1][0][j]);
}
}
ll res = -INF;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 3; ++j) {
res = max(res, dp[N - 1][i][j]);
}
}
cout << res << endl;
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02716 | C++ | Runtime Error | // #include<bits\stdc++.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define get(x) x = read()
#define gt(x) scanf("%d", &x)
#define put(x) printf("%d\n", x)
#define putl(x) printf("%lld\n", x)
#define gc(a) scanf("%s", a + 1)
#define rep(p, n, i) for (RE ll i = p; i <= n; ++i)
#define go(x) for (ll i = lin[x], tn = ver[i]; i; tn = ver[i = nex[i]])
#define fep(n, p, i) for (RE ll i = n; i >= p; --i)
#define pii pair<ll, ll>
#define mk make_pair
#define RE register
#define P 1000000007
#define S second
#define gf(x) scanf("%lf", &x)
#define pf(x) ((x) * (x))
#define ull unsigned long long
#define mod 998244353
using namespace std;
char buf[1 << 15], *fs, *ft;
inline char getc() {
return (fs == ft &&
(ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
? 0
: *fs++;
}
inline ll read() {
register ll x = 0, f = 1;
register char ch = getc();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getc();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getc();
}
return x * f;
}
const ll MAXN = 100005;
ll n;
ll a[MAXN];
ll f[MAXN][3]; // f[i][j]前表示前i个数用掉j个空隙的最大值.
signed main() {
// freopen("1.in","r",stdin);
get(n);
rep(1, n, i) get(a[i]);
memset(f, 0xcf, sizeof(f));
f[0][0] = 0;
f[1][0] = a[1];
rep(2, n, i) {
f[i][0] = f[i - 2][0] + a[i];
if (i >= 3)
f[i][1] = max(f[i - 3][0] + a[i], f[i - 2][1] + a[i]);
if (i >= 4)
f[i][2] =
max(f[i - 4][0] + a[i], max(f[i - 3][1] + a[i], f[i - 2][2] + a[i]));
}
if (n & 1)
putl(max(max(f[n][1], f[n][2]),
max(f[n - 2][0], max(f[n - 1][0], f[n - 1][1]))));
else
putl(max(f[n][1], max(f[n][0], f[n - 1][0])));
return 0;
}
| // #include<bits\stdc++.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define get(x) x = read()
#define gt(x) scanf("%d", &x)
#define put(x) printf("%d\n", x)
#define putl(x) printf("%lld\n", x)
#define gc(a) scanf("%s", a + 1)
#define rep(p, n, i) for (RE ll i = p; i <= n; ++i)
#define go(x) for (ll i = lin[x], tn = ver[i]; i; tn = ver[i = nex[i]])
#define fep(n, p, i) for (RE ll i = n; i >= p; --i)
#define pii pair<ll, ll>
#define mk make_pair
#define RE register
#define P 1000000007
#define S second
#define gf(x) scanf("%lf", &x)
#define pf(x) ((x) * (x))
#define ull unsigned long long
#define mod 998244353
using namespace std;
char buf[1 << 15], *fs, *ft;
inline char getc() {
return (fs == ft &&
(ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))
? 0
: *fs++;
}
inline ll read() {
register ll x = 0, f = 1;
register char ch = getc();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getc();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getc();
}
return x * f;
}
const ll MAXN = 200005;
ll n;
ll a[MAXN];
ll f[MAXN][3]; // f[i][j]前表示前i个数用掉j个空隙的最大值.
signed main() {
// freopen("1.in","r",stdin);
get(n);
rep(1, n, i) get(a[i]);
memset(f, 0xcf, sizeof(f));
f[0][0] = 0;
f[1][0] = a[1];
rep(2, n, i) {
f[i][0] = f[i - 2][0] + a[i];
if (i >= 3)
f[i][1] = max(f[i - 3][0] + a[i], f[i - 2][1] + a[i]);
if (i >= 4)
f[i][2] =
max(f[i - 4][0] + a[i], max(f[i - 3][1] + a[i], f[i - 2][2] + a[i]));
}
if (n & 1)
putl(max(max(f[n][1], f[n][2]),
max(f[n - 2][0], max(f[n - 1][0], f[n - 1][1]))));
else
putl(max(f[n][1], max(f[n][0], f[n - 1][0])));
return 0;
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p02716 | Python | Runtime Error | def main():
from functools import lru_cache
inf = 2 * 10**14 + 1
N = int(input())
(*a,) = map(int, input().split())
@lru_cache(maxsize=None)
def recursion(cur, need):
"""
cur: pickableなindex
"""
if cur >= N:
if need == 0:
return 0
else:
return -inf
rest = N - cur
if (rest + 1) // 2 < need:
return -inf
return max(a[cur] + recursion(cur + 2, need - 1), recursion(cur + 1, need))
ans = recursion(0, N // 2)
print(ans)
if __name__ == "__main__":
main()
| def main():
from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)
inf = 2 * 10**14 + 1
N = int(input())
(*a,) = map(int, input().split())
@lru_cache(maxsize=None)
def recursion(cur, need):
"""
cur: pickableなindex
"""
if cur >= N:
if need == 0:
return 0
else:
return -inf
rest = N - cur
if (rest + 1) // 2 < need:
return -inf
return max(a[cur] + recursion(cur + 2, need - 1), recursion(cur + 1, need))
ans = recursion(0, N // 2)
print(ans)
if __name__ == "__main__":
main()
| insert | 2 | 2 | 2 | 5 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;
typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
int main() {
int N;
cin >> N;
vector<long long> A(N);
rep(i, N) cin >> A[i];
vector<vector<long long>> dp(N, vector<long long>(3, (-1) * LINF));
dp[0][0] = A[0];
dp[1][1] = A[1];
dp[2][0] = A[0] + A[2];
dp[2][2] = A[2];
for (int i = 3; i < N; i++) {
dp[i][0] = dp[i - 2][0] + A[i];
dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
dp[i][2] = max(
dp[i - 2][2] + A[i],
max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
}
if (N % 2 == 0)
cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
else
cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;
return 0;
} | #include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;
typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
int main() {
int N;
cin >> N;
vector<long long> A(N);
rep(i, N) cin >> A[i];
if (N == 2) {
cout << max(A[0], A[1]) << endl;
return 0;
}
vector<vector<long long>> dp(N, vector<long long>(3, (-1) * LINF));
dp[0][0] = A[0];
dp[1][1] = A[1];
dp[2][0] = A[0] + A[2];
dp[2][2] = A[2];
for (int i = 3; i < N; i++) {
dp[i][0] = dp[i - 2][0] + A[i];
dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
dp[i][2] = max(
dp[i - 2][2] + A[i],
max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
}
if (N % 2 == 0)
cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
else
cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;
return 0;
} | insert | 17 | 17 | 17 | 22 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll, ll>
#define pll pair<long long, long long>
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define vec vector
#define cend cout << endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9 * 1e9)
#define ll_MIN (ll)(-1e9 * 1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define ps(arr, n) \
for (int i = 1; i < n; i++) \
arr[i] += arr[i - 1];
#define inp(arr, n) \
for (int i = 0; i < n; i++) \
cin >> arr[i];
#define out(arr, n) \
for (int i = 0; i < n; i++) \
cout << arr[i];
#define inp1(arr, n, m) \
for (int i = 0; i < n; i++) \
for (int j = 0; j < m; j++) \
cin >> arr[i][j];
#define out1(arr, n, m) \
for (int i = 0; i < n; i++) \
for (int j = 0; j < m; j++) \
cin >> arr[i][j];
#define loop(q) for (auto it : q)
#define loop1(q) for (auto &it : q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds;
#define oset(X) \
tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) \
tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
#define okey order_of_key // lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX
int dp[1000001][5];
bool v[1000001][5];
int n;
int arr[1000001];
int s1(int i, int d) {
if (d < 0)
return -1e15;
if (i >= n)
return 0;
if (v[i][d])
return dp[i][d];
return dp[i][d] = max((arr[i] + s1(i + 2, d)), s1(i + 1, d - 1));
}
void solve() {
cin >> n;
inp(arr, n);
if (n % 2 == 0)
cout << s1(0, 1) << endl;
else
cout << s1(0, 2) << endl;
}
signed main() {
speed;
int t = 1;
// cin >> t;
while (t--)
solve();
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll, ll>
#define pll pair<long long, long long>
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define vec vector
#define cend cout << endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9 * 1e9)
#define ll_MIN (ll)(-1e9 * 1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define ps(arr, n) \
for (int i = 1; i < n; i++) \
arr[i] += arr[i - 1];
#define inp(arr, n) \
for (int i = 0; i < n; i++) \
cin >> arr[i];
#define out(arr, n) \
for (int i = 0; i < n; i++) \
cout << arr[i];
#define inp1(arr, n, m) \
for (int i = 0; i < n; i++) \
for (int j = 0; j < m; j++) \
cin >> arr[i][j];
#define out1(arr, n, m) \
for (int i = 0; i < n; i++) \
for (int j = 0; j < m; j++) \
cin >> arr[i][j];
#define loop(q) for (auto it : q)
#define loop1(q) for (auto &it : q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds;
#define oset(X) \
tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) \
tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
#define okey order_of_key // lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX
int dp[1000001][5];
bool v[1000001][5];
int n;
int arr[1000001];
int s1(int i, int d) {
if (d < 0)
return -1e15;
if (i >= n)
return 0;
if (v[i][d])
return dp[i][d];
v[i][d] = 1;
return dp[i][d] = max((arr[i] + s1(i + 2, d)), s1(i + 1, d - 1));
}
void solve() {
cin >> n;
inp(arr, n);
if (n % 2 == 0)
cout << s1(0, 1) << endl;
else
cout << s1(0, 2) << endl;
}
signed main() {
speed;
int t = 1;
// cin >> t;
while (t--)
solve();
} | insert | 81 | 81 | 81 | 82 | TLE | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
// cout<<fixed<<setprecision(10);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> void debug(T v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main() {
gearup;
int n;
cin >> n;
vl a(n);
rep(i, n) cin >> a[i];
vvl dp(n + 10, vl(3, -L_INF));
int m = n % 2 + 1; // 奇数なら2こ飛ばせる
dp[0][0] = 0;
rep(i, n) {
rep(j, m + 1) {
chmax(dp[i + 1][j + 1], dp[i][j]);
ll now = dp[i][j];
if ((i + j) % 2 == 0)
now += a[i];
chmax(dp[i + 1][j], now);
}
}
out(dp[n][m]);
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
// cout<<fixed<<setprecision(10);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> void debug(T v) {
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
signed main() {
gearup;
int n;
cin >> n;
vl a(n);
rep(i, n) cin >> a[i];
vvl dp(n + 10, vl(4, -L_INF));
int m = n % 2 + 1; // 奇数なら2こ飛ばせる
dp[0][0] = 0;
rep(i, n) {
rep(j, m + 1) {
chmax(dp[i + 1][j + 1], dp[i][j]);
ll now = dp[i][j];
if ((i + j) % 2 == 0)
now += a[i];
chmax(dp[i + 1][j], now);
}
}
out(dp[n][m]);
}
| replace | 62 | 63 | 62 | 63 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
using LL = long long;
using ULL = unsigned long long;
#ifdef __linux__
using LLL = __int128;
using ULLL = unsigned __int128;
#else
using LLL = long long;
using ULLL = unsigned long long;
#endif
namespace std {
void swap(int &x, int &y) { x ^= y ^= x ^= y; }
void swap(LL &x, LL &y) { x ^= y ^= x ^= y; }
}; // namespace std
#ifdef LX_LOCAL
class Time {
public:
clock_t begin;
long duration;
static clock_t currentTime() { return clock(); }
Time() {
begin = currentTime();
duration = 0;
}
~Time() {
auto end = currentTime();
auto d = end - begin;
duration += d;
double t = duration / 1000.0;
if (t >= 60000)
fprintf(stderr, "Time used = %.2lfmin\n", t / 60000.0);
else if (t >= 1000)
fprintf(stderr, "Time used = %.2lfs\n", t / 1000.0);
else
fprintf(stderr, "Time used = %.0lfms\n", t);
}
} timeout;
#endif
using std::swap;
#if __cplusplus >= 201402L
template <typename T, typename P> auto max(const T &x, const P &y) {
return x < y ? y : x;
}
template <typename T, typename P> auto min(const T &x, const P &y) {
return x < y ? x : y;
}
template <typename T, typename... Args>
auto max(const T &x, const Args &...args) {
return max(x, max(args...));
}
template <typename T, typename... Args>
auto min(const T &x, const Args &...args) {
return min(x, min(args...));
}
#else
template <typename T, typename P>
auto max(const T &x, const P &y) -> decltype(x < y ? y : x) {
return x < y ? y : x;
}
template <typename T, typename P>
auto min(const T &x, const P &y) -> decltype(x < y ? x : y) {
return x < y ? x : y;
}
template <typename T, typename... Args>
auto max(const T &x, const Args &...args) -> decltype(max(x, max(args...))) {
return max(x, max(args...));
}
template <typename T, typename... Args>
auto min(const T &x, const Args &...args) -> decltype(min(x, min(args...))) {
return min(x, min(args...));
}
#endif
template <typename T> T max(const T &x) { return x; }
template <typename T> T min(const T &x) { return x; }
#define lc (o << 1)
#define rc (o << 1 | 1)
#define lowbit(x) ((x) & (-(x)))
class IO {
#define MY_DEBUG 0
#if !MY_DEBUG
static const int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#endif
long double eps = 1e-8L;
LLL pow10 = 1000000;
int precision;
FILE *infile, *outfile;
public:
IO(FILE *in = nullptr, FILE *out = nullptr)
: precision(6), infile(in), outfile(out) {
#if !MY_DEBUG
p1 = p2 = buf;
pp = pbuf;
#endif
}
#if !MY_DEBUG
~IO() { fwrite(pbuf, 1, pp - pbuf, outfile); }
#endif
inline static bool blank(char ch);
inline void flush();
inline void input(const char *str);
inline void output(const char *str);
inline void input(FILE *f);
inline void output(FILE *f);
inline int getch();
template <typename T, typename... Args> bool read(T &x, Args &...args);
inline bool read();
template <typename T>
typename std::enable_if<
std::is_integral<T>::value || std::is_floating_point<T>::value ||
std::is_same<T, LLL>::value || std::is_same<T, ULLL>::value,
bool>::type
read(T &x);
bool read(char &ch);
bool read(char *s);
bool readline(char *s);
inline void putch(const char c);
inline void putback(const char c);
inline void setprecision(int n);
template <typename T, typename... Args>
void write(const T &x, const Args &...args);
inline void write();
template <typename T>
typename std::enable_if<std::is_integral<T>::value ||
std::is_same<T, LLL>::value ||
std::is_same<T, ULLL>::value,
void>::type
write(T x);
inline void write(char c);
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value, void>::type
write(T x);
void write(bool x);
void write(char *s);
void write(const char *s);
template <typename... Args> void writeln(Args... x) {
write(x...), putch('\n');
}
} io(stdin, stdout), err(nullptr, stderr);
template <typename... Args> inline void writeln(Args... x) {
io.write(x...), io.putch('\n');
}
#define dbg(x) err.write(#x " = "), err.writeln(x)
// fast io
#include <cstring>
const int maxn = 200005;
const LL INF = -1ull / 2 - 2e9;
int A[maxn];
LL sum1[maxn], sum2[maxn];
LL d[maxn][2];
bool vis[maxn][2];
LL dp(int i, bool flag) {
if (i <= 1)
return -INF;
if (vis[i][flag])
return d[i][flag];
LL &ans = d[i][flag];
if (i & 1) {
if (i == 3 && flag)
return ans = max(A[1], A[3]);
if (flag) {
return ans = max(dp(i - 2, 0), dp(i - 2, 1)) + A[i];
}
return ans = max(dp(i - 1, 1), dp(i - 1, 0));
}
if (i == 2)
if (flag)
return ans = A[2];
else
return ans = A[1];
return ans = flag ? dp(i - 1, 0) + A[i] : sum1[i - 1];
}
int main() {
int n;
io.read(n);
for (int i = 1; i <= n; i++)
io.read(A[i]);
for (int i = 1; i <= n; i++) {
sum1[i] = sum1[i - 1];
sum2[i] = sum2[i - 1];
if (i & 1)
sum1[i] += A[i];
else
sum2[i] += A[i];
}
writeln(max(dp(n, true), dp(n, false)));
return 0;
}
#define isdigit(x) (x >= '0' && x <= '9')
inline bool IO::blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void IO::flush() {
#if MY_DEBUG
fflush(outfile);
#else
fwrite(pbuf, 1, pp - pbuf, outfile), pp = pbuf;
#endif
}
inline void IO::input(const char *str) {
FILE *file = fopen(str, "rb");
infile = file;
}
inline void IO::output(const char *str) {
FILE *file = fopen(str, "wb");
outfile = file;
}
inline void IO::input(FILE *f) { infile = f; }
inline void IO::output(FILE *f) { outfile = f; }
inline int IO::getch() {
#if MY_DEBUG
return fgetc(infile);
#else
return (p1 == p2 ? (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, infile)) : 0),
(p1 == p2) ? EOF : *p1++;
#endif
}
inline void IO::putback(const char c) {
#if MY_DEBUG
ungetc(c, infile);
#else
*(--p1) = c;
#endif
}
template <typename T, typename... Args> bool IO::read(T &x, Args &...args) {
return read(x) && read(args...);
}
inline bool IO::read() { return true; }
template <typename T>
typename std::enable_if<
std::is_integral<T>::value || std::is_floating_point<T>::value ||
std::is_same<T, LLL>::value || std::is_same<T, ULLL>::value,
bool>::type
IO::read(T &x) {
double tmp = 1;
bool sign = false;
x = 0;
int ch = getch();
for (; !isdigit(ch) && ~ch; ch = getch())
if (ch == '-')
sign = true;
if (!(~ch))
return false;
for (; isdigit(ch); ch = getch())
x = x * 10 + (ch - '0');
if (ch == '.')
for (ch = getch(); isdigit(ch); ch = getch())
tmp /= 10.0, x += tmp * (ch - '0');
if (~ch)
putback(ch);
if (sign)
x = ~x + 1;
return true;
}
bool IO::read(char &ch) {
for (ch = getch(); blank(ch) && ~ch; ch = getch())
;
return ~ch;
}
bool IO::read(char *s) {
int ch = getch();
while (blank(ch))
ch = getch();
if (!(~ch))
return false;
while (!blank(ch) && ~ch)
*s++ = ch, ch = getch();
*s = 0;
if (~ch)
putback(ch);
return true;
}
bool IO::readline(char *s) {
int ch = getch();
while (blank(ch) && ch != '\n')
ch = getch();
if (!(~ch))
return false;
while (ch != '\n' && ~ch)
*s++ = ch, ch = getch();
*s = 0;
if (~ch)
putback(ch);
return true;
}
inline void IO::putch(const char c) {
#if MY_DEBUG
fputc(c, outfile);
#else
((pp - pbuf == MAXSIZE) ? fwrite(pbuf, 1, MAXSIZE, outfile), pp = pbuf : 0),
*pp++ = c;
#endif
}
inline void IO::setprecision(int n) {
precision = n;
eps = powl(10.0L, -precision - 2);
pow10 = powl(10.0L, precision) + eps;
}
template <typename T, typename... Args>
void IO::write(const T &x, const Args &...args) {
write(x);
write(args...);
}
inline void IO::write() {}
template <typename T>
typename std::enable_if<std::is_integral<T>::value ||
std::is_same<T, LLL>::value ||
std::is_same<T, ULLL>::value,
void>::type
IO::write(T x) {
if (x < 0)
x = ~x + 1, putch('-');
static T sta[100];
int top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putch(sta[--top] + '0');
}
void IO::write(bool x) { putch(x ^ 48); }
inline void IO::write(char c) { putch(c); }
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value>::type IO::write(T x) {
if (x == 0) {
putch('0'), putch('.');
for (int i = 1; i <= precision; i++)
putch('0');
return;
}
if (x < 0)
putch('-'), x = -x;
T res = (LLL)(x * pow10 + 0.5) / (pow10 * 1.0);
LLL y = LLL(res * pow10 + eps) % pow10;
write(LLL(res + eps));
if (precision) {
putch('.');
static int sta[100], p = 0;
for (; p < precision; y /= 10)
sta[++p] = y % 10;
for (int i = p; i >= 1; i--)
putch(sta[i] ^ 48);
}
}
void IO::write(char *s) {
while (*s)
putch(*s++);
}
void IO::write(const char *s) {
while (*s)
putch(*s++);
}
#undef isdigit | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
using LL = long long;
using ULL = unsigned long long;
#ifdef __linux__
using LLL = __int128;
using ULLL = unsigned __int128;
#else
using LLL = long long;
using ULLL = unsigned long long;
#endif
namespace std {
void swap(int &x, int &y) { x ^= y ^= x ^= y; }
void swap(LL &x, LL &y) { x ^= y ^= x ^= y; }
}; // namespace std
#ifdef LX_LOCAL
class Time {
public:
clock_t begin;
long duration;
static clock_t currentTime() { return clock(); }
Time() {
begin = currentTime();
duration = 0;
}
~Time() {
auto end = currentTime();
auto d = end - begin;
duration += d;
double t = duration / 1000.0;
if (t >= 60000)
fprintf(stderr, "Time used = %.2lfmin\n", t / 60000.0);
else if (t >= 1000)
fprintf(stderr, "Time used = %.2lfs\n", t / 1000.0);
else
fprintf(stderr, "Time used = %.0lfms\n", t);
}
} timeout;
#endif
using std::swap;
#if __cplusplus >= 201402L
template <typename T, typename P> auto max(const T &x, const P &y) {
return x < y ? y : x;
}
template <typename T, typename P> auto min(const T &x, const P &y) {
return x < y ? x : y;
}
template <typename T, typename... Args>
auto max(const T &x, const Args &...args) {
return max(x, max(args...));
}
template <typename T, typename... Args>
auto min(const T &x, const Args &...args) {
return min(x, min(args...));
}
#else
template <typename T, typename P>
auto max(const T &x, const P &y) -> decltype(x < y ? y : x) {
return x < y ? y : x;
}
template <typename T, typename P>
auto min(const T &x, const P &y) -> decltype(x < y ? x : y) {
return x < y ? x : y;
}
template <typename T, typename... Args>
auto max(const T &x, const Args &...args) -> decltype(max(x, max(args...))) {
return max(x, max(args...));
}
template <typename T, typename... Args>
auto min(const T &x, const Args &...args) -> decltype(min(x, min(args...))) {
return min(x, min(args...));
}
#endif
template <typename T> T max(const T &x) { return x; }
template <typename T> T min(const T &x) { return x; }
#define lc (o << 1)
#define rc (o << 1 | 1)
#define lowbit(x) ((x) & (-(x)))
class IO {
#define MY_DEBUG 0
#if !MY_DEBUG
static const int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#endif
long double eps = 1e-8L;
LLL pow10 = 1000000;
int precision;
FILE *infile, *outfile;
public:
IO(FILE *in = nullptr, FILE *out = nullptr)
: precision(6), infile(in), outfile(out) {
#if !MY_DEBUG
p1 = p2 = buf;
pp = pbuf;
#endif
}
#if !MY_DEBUG
~IO() { fwrite(pbuf, 1, pp - pbuf, outfile); }
#endif
inline static bool blank(char ch);
inline void flush();
inline void input(const char *str);
inline void output(const char *str);
inline void input(FILE *f);
inline void output(FILE *f);
inline int getch();
template <typename T, typename... Args> bool read(T &x, Args &...args);
inline bool read();
template <typename T>
typename std::enable_if<
std::is_integral<T>::value || std::is_floating_point<T>::value ||
std::is_same<T, LLL>::value || std::is_same<T, ULLL>::value,
bool>::type
read(T &x);
bool read(char &ch);
bool read(char *s);
bool readline(char *s);
inline void putch(const char c);
inline void putback(const char c);
inline void setprecision(int n);
template <typename T, typename... Args>
void write(const T &x, const Args &...args);
inline void write();
template <typename T>
typename std::enable_if<std::is_integral<T>::value ||
std::is_same<T, LLL>::value ||
std::is_same<T, ULLL>::value,
void>::type
write(T x);
inline void write(char c);
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value, void>::type
write(T x);
void write(bool x);
void write(char *s);
void write(const char *s);
template <typename... Args> void writeln(Args... x) {
write(x...), putch('\n');
}
} io(stdin, stdout), err(nullptr, stderr);
template <typename... Args> inline void writeln(Args... x) {
io.write(x...), io.putch('\n');
}
#define dbg(x) err.write(#x " = "), err.writeln(x)
// fast io
#include <cstring>
const int maxn = 200005;
const LL INF = -1ull / 2 - 2e9;
int A[maxn];
LL sum1[maxn], sum2[maxn];
LL d[maxn][2];
bool vis[maxn][2];
LL dp(int i, bool flag) {
if (i <= 1)
return -INF;
if (vis[i][flag])
return d[i][flag];
vis[i][flag] = true;
LL &ans = d[i][flag];
if (i & 1) {
if (i == 3 && flag)
return ans = max(A[1], A[3]);
if (flag) {
return ans = max(dp(i - 2, 0), dp(i - 2, 1)) + A[i];
}
return ans = max(dp(i - 1, 1), dp(i - 1, 0));
}
if (i == 2)
if (flag)
return ans = A[2];
else
return ans = A[1];
return ans = flag ? dp(i - 1, 0) + A[i] : sum1[i - 1];
}
int main() {
int n;
io.read(n);
for (int i = 1; i <= n; i++)
io.read(A[i]);
for (int i = 1; i <= n; i++) {
sum1[i] = sum1[i - 1];
sum2[i] = sum2[i - 1];
if (i & 1)
sum1[i] += A[i];
else
sum2[i] += A[i];
}
writeln(max(dp(n, true), dp(n, false)));
return 0;
}
#define isdigit(x) (x >= '0' && x <= '9')
inline bool IO::blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void IO::flush() {
#if MY_DEBUG
fflush(outfile);
#else
fwrite(pbuf, 1, pp - pbuf, outfile), pp = pbuf;
#endif
}
inline void IO::input(const char *str) {
FILE *file = fopen(str, "rb");
infile = file;
}
inline void IO::output(const char *str) {
FILE *file = fopen(str, "wb");
outfile = file;
}
inline void IO::input(FILE *f) { infile = f; }
inline void IO::output(FILE *f) { outfile = f; }
inline int IO::getch() {
#if MY_DEBUG
return fgetc(infile);
#else
return (p1 == p2 ? (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, infile)) : 0),
(p1 == p2) ? EOF : *p1++;
#endif
}
inline void IO::putback(const char c) {
#if MY_DEBUG
ungetc(c, infile);
#else
*(--p1) = c;
#endif
}
template <typename T, typename... Args> bool IO::read(T &x, Args &...args) {
return read(x) && read(args...);
}
inline bool IO::read() { return true; }
template <typename T>
typename std::enable_if<
std::is_integral<T>::value || std::is_floating_point<T>::value ||
std::is_same<T, LLL>::value || std::is_same<T, ULLL>::value,
bool>::type
IO::read(T &x) {
double tmp = 1;
bool sign = false;
x = 0;
int ch = getch();
for (; !isdigit(ch) && ~ch; ch = getch())
if (ch == '-')
sign = true;
if (!(~ch))
return false;
for (; isdigit(ch); ch = getch())
x = x * 10 + (ch - '0');
if (ch == '.')
for (ch = getch(); isdigit(ch); ch = getch())
tmp /= 10.0, x += tmp * (ch - '0');
if (~ch)
putback(ch);
if (sign)
x = ~x + 1;
return true;
}
bool IO::read(char &ch) {
for (ch = getch(); blank(ch) && ~ch; ch = getch())
;
return ~ch;
}
bool IO::read(char *s) {
int ch = getch();
while (blank(ch))
ch = getch();
if (!(~ch))
return false;
while (!blank(ch) && ~ch)
*s++ = ch, ch = getch();
*s = 0;
if (~ch)
putback(ch);
return true;
}
bool IO::readline(char *s) {
int ch = getch();
while (blank(ch) && ch != '\n')
ch = getch();
if (!(~ch))
return false;
while (ch != '\n' && ~ch)
*s++ = ch, ch = getch();
*s = 0;
if (~ch)
putback(ch);
return true;
}
inline void IO::putch(const char c) {
#if MY_DEBUG
fputc(c, outfile);
#else
((pp - pbuf == MAXSIZE) ? fwrite(pbuf, 1, MAXSIZE, outfile), pp = pbuf : 0),
*pp++ = c;
#endif
}
inline void IO::setprecision(int n) {
precision = n;
eps = powl(10.0L, -precision - 2);
pow10 = powl(10.0L, precision) + eps;
}
template <typename T, typename... Args>
void IO::write(const T &x, const Args &...args) {
write(x);
write(args...);
}
inline void IO::write() {}
template <typename T>
typename std::enable_if<std::is_integral<T>::value ||
std::is_same<T, LLL>::value ||
std::is_same<T, ULLL>::value,
void>::type
IO::write(T x) {
if (x < 0)
x = ~x + 1, putch('-');
static T sta[100];
int top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putch(sta[--top] + '0');
}
void IO::write(bool x) { putch(x ^ 48); }
inline void IO::write(char c) { putch(c); }
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value>::type IO::write(T x) {
if (x == 0) {
putch('0'), putch('.');
for (int i = 1; i <= precision; i++)
putch('0');
return;
}
if (x < 0)
putch('-'), x = -x;
T res = (LLL)(x * pow10 + 0.5) / (pow10 * 1.0);
LLL y = LLL(res * pow10 + eps) % pow10;
write(LLL(res + eps));
if (precision) {
putch('.');
static int sta[100], p = 0;
for (; p < precision; y /= 10)
sta[++p] = y % 10;
for (int i = p; i >= 1; i--)
putch(sta[i] ^ 48);
}
}
void IO::write(char *s) {
while (*s)
putch(*s++);
}
void IO::write(const char *s) {
while (*s)
putch(*s++);
}
#undef isdigit | insert | 168 | 168 | 168 | 169 | TLE | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, m, n) for (ll i = ll(m); i < ll(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
int main() {
int n;
cin >> n;
VLL a(n);
REP(i, n) cin >> a[i];
if (n <= 3) {
sort(ALL(a));
reverse(ALL(a));
cout << a[0] << endl;
return 0;
}
if (n % 2 == 0) {
VVLL dp(n, VLL(2, 0));
dp[0][0] = a[0];
dp[1][1] = a[1];
FOR(i, 2, n) {
if (i % 2 == 0)
dp[i][0] = dp[i - 2][0] + a[i];
else {
dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i];
}
}
cout << max(dp[n - 1][1], dp[n - 2][0]) << endl;
return 0;
}
assert(n == 0);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, m, n) for (ll i = ll(m); i < ll(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VP vector<pair<int, int>>
#define VPP vector<pair<int, pair<int, int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
int main() {
int n;
cin >> n;
VLL a(n);
REP(i, n) cin >> a[i];
if (n <= 3) {
sort(ALL(a));
reverse(ALL(a));
cout << a[0] << endl;
return 0;
}
if (n % 2 == 0) {
VVLL dp(n, VLL(2, 0));
dp[0][0] = a[0];
dp[1][1] = a[1];
FOR(i, 2, n) {
if (i % 2 == 0)
dp[i][0] = dp[i - 2][0] + a[i];
else {
dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i];
}
}
cout << max(dp[n - 1][1], dp[n - 2][0]) << endl;
return 0;
}
VVLL dp(n, VLL(4, -INFL));
dp[0][0] = a[0];
dp[1][1] = a[1];
dp[2][2] = a[2];
dp[2][0] = dp[0][0] + a[2];
FOR(i, 3, n) {
if (i % 2 == 0) {
dp[i][0] = dp[i - 2][0] + a[i];
dp[i][2] = max({dp[i - 2][2], dp[i - 3][1], dp[i - 4][0]}) + a[i];
} else {
dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + a[i];
}
}
ll ans = max({dp[n - 1][2], dp[n - 2][1], dp[n - 3][0]});
VVLL dq(n + 100, VLL(3, -INFL));
dq[0][0] = a[0];
FOR(i, 1, n) {
if (i % 2 == 0)
dq[i][0] = dq[i - 2][0] + a[i];
}
dq[3][1] = a[0] + a[3];
FOR(i, 5, n) {
if (i % 2 == 1) {
dq[i][1] = max(dq[i - 2][1], dq[i - 3][0]) + a[i];
} else {
if (i < 6)
continue;
dq[i][2] = max(dq[i - 2][2], dq[i - 3][1]) + a[i];
}
}
ans = max(ans, dq[n - 1][2]);
ans = max(ans, dq[n - 2][1]);
cout << ans << endl;
} | replace | 58 | 59 | 58 | 97 | 0 | |
p02716 | C++ | Runtime Error | /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <numeric>
#include <random>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
// type
#include <cstdint>
#include <functional>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>
/* ---------- Constants */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
/* ---------- Functions */
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<vector<int>> before(N + 1, vector<int>(2, -INF));
vector<vector<int>> after(N + 1, vector<int>(2, -INF));
before[0][0] = 0;
after[0][0] = 0;
for (int i = 0; i < N; i++) {
int r = N - 1 - i;
int l = i + 1;
int lower = N / 2 - (int)ceil(1.0 * r / 2);
int upper = (int)ceil(1.0 * l / 2);
lower--;
upper++;
for (int a = lower; a <= upper; a++) {
if (a < 0)
continue;
chmax(after[a + 1][1], before[a][0] + A[i]);
chmax(after[a][0], max(before[a][1], before[a][0]));
}
swap(before, after);
}
cout << max(before[N / 2][0], before[N / 2][1]) << endl;
return 0;
} | /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <numeric>
#include <random>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
// type
#include <cstdint>
#include <functional>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>
/* ---------- Constants */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
/* ---------- Functions */
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<vector<int>> before(N + 1, vector<int>(2, -INF));
vector<vector<int>> after(N + 1, vector<int>(2, -INF));
before[0][0] = 0;
after[0][0] = 0;
for (int i = 0; i < N; i++) {
int r = N - 1 - i;
int l = i + 1;
int lower = N / 2 - (int)ceil(1.0 * r / 2);
int upper = (int)ceil(1.0 * l / 2);
lower--;
upper++;
for (int a = lower; a <= upper; a++) {
if (a < 0)
continue;
if (a >= N)
continue;
chmax(after[a + 1][1], before[a][0] + A[i]);
chmax(after[a][0], max(before[a][1], before[a][0]));
}
swap(before, after);
}
cout << max(before[N / 2][0], before[N / 2][1]) << endl;
return 0;
} | insert | 95 | 95 | 95 | 97 | 0 | |
p02716 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define isSquare(x) (sqrt(x) * sqrt(x) == x)
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;
};
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
inline void out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
cout << first << " ";
out(rest...);
return;
}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <typename T> void Exit(T first) {
cout << first << endl;
exit(0);
};
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<mod>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};
const int calender[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int ucalender[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool range(int a, int b, int x) {
if (a <= x and x < b)
return true;
else
return false;
}
bool range(int a, int b, int c, int d, pii p) {
if (a <= p.first and p.first < b and c <= p.second and p.second < d)
return true;
else
return false;
}
int main() {
iosetup();
int N;
cin >> N;
vector<int> A(N);
cin >> A;
vector<vector<ll>> dp(N, vector<ll>(3, -INFLL));
dp[0][0] = A[0];
dp[1][1] = A[1];
dp[2][2] = A[2];
rep(i, 0, N) {
if (i + 2 < N)
chmax(dp[i + 2][0], dp[i][0] + A[i + 2]);
if (i + 2 < N)
chmax(dp[i + 2][1], dp[i][1] + A[i + 2]);
if (i + 2 < N)
chmax(dp[i + 2][2], dp[i][2] + A[i + 2]);
if (i + 3 < N)
chmax(dp[i + 3][1], dp[i][0] + A[i + 3]);
if (i + 3 < N)
chmax(dp[i + 3][2], dp[i][1] + A[i + 3]);
if (i + 4 < N)
chmax(dp[i + 4][2], dp[i][0] + A[i + 4]);
}
// rep(i, 0, N){
// cerr << dp[i] << endl;
// }
if (N % 2 == 0)
cout << dp[N - 1][1] << endl;
else
cout << dp[N - 1][2] << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define isSquare(x) (sqrt(x) * sqrt(x) == x)
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;
};
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
inline void out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
cout << first << " ";
out(rest...);
return;
}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <typename T> void Exit(T first) {
cout << first << endl;
exit(0);
};
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<mod>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};
const int calender[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int ucalender[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool range(int a, int b, int x) {
if (a <= x and x < b)
return true;
else
return false;
}
bool range(int a, int b, int c, int d, pii p) {
if (a <= p.first and p.first < b and c <= p.second and p.second < d)
return true;
else
return false;
}
int main() {
iosetup();
int N;
cin >> N;
vector<int> A(N);
cin >> A;
vector<vector<ll>> dp(N, vector<ll>(3, -INFLL));
if (N <= 3) {
cout << *max_element(ALL(A)) << endl;
return 0;
}
dp[0][0] = A[0];
dp[1][1] = A[1];
dp[2][2] = A[2];
rep(i, 0, N) {
if (i + 2 < N)
chmax(dp[i + 2][0], dp[i][0] + A[i + 2]);
if (i + 2 < N)
chmax(dp[i + 2][1], dp[i][1] + A[i + 2]);
if (i + 2 < N)
chmax(dp[i + 2][2], dp[i][2] + A[i + 2]);
if (i + 3 < N)
chmax(dp[i + 3][1], dp[i][0] + A[i + 3]);
if (i + 3 < N)
chmax(dp[i + 3][2], dp[i][1] + A[i + 3]);
if (i + 4 < N)
chmax(dp[i + 4][2], dp[i][0] + A[i + 4]);
}
// rep(i, 0, N){
// cerr << dp[i] << endl;
// }
if (N % 2 == 0)
cout << dp[N - 1][1] << endl;
else
cout << dp[N - 1][2] << endl;
return 0;
} | insert | 197 | 197 | 197 | 201 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long N;
long long A[200005];
int main() {
cin >> N;
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
if (N % 2 == 0) {
long long odd = 0;
long long even = 0;
for (long long i = 0; i < N; i++) {
if (i % 2 == 0) {
even += A[i];
} else {
odd += A[i];
}
}
cout << max(even, odd) << endl;
return 1;
} else {
// get count, max 1はskipしないといけない, 0はskipしなくていい
map<long long, long long> dp[2];
map<long long, long long> dpnext[2];
dp[0][0] = 0;
for (long long i = 0; i < N; i++) {
long long mini = i / 2 - 10;
long long maxi = i / 2 + 10;
// cout << "i = " << i << endl;
// cout << "dp[0]" << endl;
// for(auto item: dp[0]) {
// cout << item.first << ", " << item.second << endl;
// }
// cout << "dp[1]" << endl;
// for(auto item: dp[1]) {
// cout << item.first << ", " << item.second << endl;
// }
// 取る
for (auto item : dp[0]) {
if (item.first > mini && item.first < maxi) {
if (dpnext[1].count(item.first + 1) > 0) {
dpnext[1][item.first + 1] =
max(dpnext[1][item.first + 1], item.second + A[i]);
} else {
dpnext[1][item.first + 1] = item.second + A[i];
}
}
}
// 撮らない
for (auto item : dp[0]) {
if (item.first > mini && item.first < maxi) {
if (dpnext[0].count(item.first) > 0) {
dpnext[0][item.first] = max(dpnext[0][item.first], item.second);
} else {
dpnext[0][item.first] = item.second;
}
}
}
for (auto item : dp[1]) {
if (item.first > mini && item.first < maxi) {
if (dpnext[0].count(item.first) > 0) {
dpnext[0][item.first] = max(dpnext[0][item.first], item.second);
} else {
dpnext[0][item.first] = item.second;
}
}
}
swap(dp, dpnext);
dpnext[0].clear();
dpnext[1].clear();
}
long long ans = LONG_MIN;
// cout << "i = " << N << endl;
// cout << "dp[0]" << endl;
for (auto item : dp[0]) {
// cout << item.first << ", " << item.second << endl;
if (item.first == N / 2) {
ans = max(ans, item.second);
}
}
// cout << "dp[1]" << endl;
for (auto item : dp[1]) {
// cout << item.first << ", " << item.second << endl;
if (item.first == N / 2) {
ans = max(ans, item.second);
}
}
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
long long N;
long long A[200005];
int main() {
cin >> N;
for (long long i = 0; i < N; i++) {
cin >> A[i];
}
if (false) {
long long odd = 0;
long long even = 0;
for (long long i = 0; i < N; i++) {
if (i % 2 == 0) {
even += A[i];
} else {
odd += A[i];
}
}
cout << max(even, odd) << endl;
return 1;
} else {
// get count, max 1はskipしないといけない, 0はskipしなくていい
map<long long, long long> dp[2];
map<long long, long long> dpnext[2];
dp[0][0] = 0;
for (long long i = 0; i < N; i++) {
long long mini = i / 2 - 10;
long long maxi = i / 2 + 10;
// cout << "i = " << i << endl;
// cout << "dp[0]" << endl;
// for(auto item: dp[0]) {
// cout << item.first << ", " << item.second << endl;
// }
// cout << "dp[1]" << endl;
// for(auto item: dp[1]) {
// cout << item.first << ", " << item.second << endl;
// }
// 取る
for (auto item : dp[0]) {
if (item.first > mini && item.first < maxi) {
if (dpnext[1].count(item.first + 1) > 0) {
dpnext[1][item.first + 1] =
max(dpnext[1][item.first + 1], item.second + A[i]);
} else {
dpnext[1][item.first + 1] = item.second + A[i];
}
}
}
// 撮らない
for (auto item : dp[0]) {
if (item.first > mini && item.first < maxi) {
if (dpnext[0].count(item.first) > 0) {
dpnext[0][item.first] = max(dpnext[0][item.first], item.second);
} else {
dpnext[0][item.first] = item.second;
}
}
}
for (auto item : dp[1]) {
if (item.first > mini && item.first < maxi) {
if (dpnext[0].count(item.first) > 0) {
dpnext[0][item.first] = max(dpnext[0][item.first], item.second);
} else {
dpnext[0][item.first] = item.second;
}
}
}
swap(dp, dpnext);
dpnext[0].clear();
dpnext[1].clear();
}
long long ans = LONG_MIN;
// cout << "i = " << N << endl;
// cout << "dp[0]" << endl;
for (auto item : dp[0]) {
// cout << item.first << ", " << item.second << endl;
if (item.first == N / 2) {
ans = max(ans, item.second);
}
}
// cout << "dp[1]" << endl;
for (auto item : dp[1]) {
// cout << item.first << ", " << item.second << endl;
if (item.first == N / 2) {
ans = max(ans, item.second);
}
}
cout << ans << endl;
}
}
| replace | 12 | 13 | 12 | 13 | 1 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF (ll)1e16
int main(void) {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
int MAX_JUMP = (n % 2 == 0) ? 2 : 3;
vector<ll> dp[MAX_JUMP];
rep(i, MAX_JUMP) dp[i] = vector<ll>(n, -INF);
rep(i, MAX_JUMP) dp[i][i] = a[i];
rep(i, n) {
rep(k, MAX_JUMP) {
if (i < k)
continue;
rep(j, MAX_JUMP) {
if (k + j <= 2 && i + j + 2 < n) {
dp[k + j][i + j + 2] =
max(dp[k + j][i + j + 2], dp[k][i] + a[i + j + 2]);
}
}
}
}
if (n % 2 == 0) {
cout << max({dp[1][n - 1], dp[0][n - 2]}) << endl;
} else {
cout << max({dp[2][n - 1], dp[1][n - 2], dp[0][n - 3]}) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF (ll)1e16
int main(void) {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
int MAX_JUMP = (n % 2 == 0) ? 2 : 3;
vector<ll> dp[MAX_JUMP];
rep(i, MAX_JUMP) dp[i] = vector<ll>(n, -INF);
rep(i, MAX_JUMP) dp[i][i] = a[i];
rep(i, n) {
rep(k, MAX_JUMP) {
if (i < k)
continue;
rep(j, MAX_JUMP) {
if (k + j <= MAX_JUMP - 1 && i + j + 2 < n) {
dp[k + j][i + j + 2] =
max(dp[k + j][i + j + 2], dp[k][i] + a[i + j + 2]);
}
}
}
}
if (n % 2 == 0) {
cout << max({dp[1][n - 1], dp[0][n - 2]}) << endl;
} else {
cout << max({dp[2][n - 1], dp[1][n - 2], dp[0][n - 3]}) << endl;
}
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define AC \
ios::sync_with_stdio(false); \
cin.tie(0);
const ll N = 20005;
ll dp[N][2];
ll arr[N];
int main() {
AC ll n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];
dp[2][0] = arr[1];
dp[2][1] = arr[2];
for (int i = 3; i <= n; i++) {
if (i & 1) {
dp[i][1] = max({dp[i - 2][1], dp[i - 2][0], dp[i - 3][1], dp[i - 3][0]}) +
arr[i];
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
} else {
dp[i][1] = max(dp[i - 2][1], dp[i - 2][0]) + arr[i];
dp[i][0] = arr[i - 1] + dp[i - 2][0];
}
}
cout << max(dp[n][0], dp[n][1]) << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define AC \
ios::sync_with_stdio(false); \
cin.tie(0);
const ll N = 2e5;
ll dp[N][2];
ll arr[N];
int main() {
AC ll n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];
dp[2][0] = arr[1];
dp[2][1] = arr[2];
for (int i = 3; i <= n; i++) {
if (i & 1) {
dp[i][1] = max({dp[i - 2][1], dp[i - 2][0], dp[i - 3][1], dp[i - 3][0]}) +
arr[i];
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
} else {
dp[i][1] = max(dp[i - 2][1], dp[i - 2][0]) + arr[i];
dp[i][0] = arr[i - 1] + dp[i - 2][0];
}
}
cout << max(dp[n][0], dp[n][1]) << '\n';
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long dp[N][2][2];
int n;
int a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
dp[i][j][k] = -1e18;
}
}
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
dp[0][0][0] = dp[0][1][0] = dp[0][0][1] = dp[0][1][1] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
if (!(j & k)) {
for (int g = 0; g < 2; ++g) {
for (int t = 0; t < 2; ++t) {
int x = (i + 1) / 2 - g, y = i / 2 - t;
if (y + j == x and y >= 0) {
dp[i][g][j] = max(dp[i][g][j], dp[i - 1][t][k] + j * a[i]);
}
}
}
}
}
}
}
long long ans = -1e18;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
if ((i + 1) / 2 - j == n / 2) {
for (int k = 0; k < 2; ++k) {
ans = max(ans, dp[i][j][k]);
}
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long dp[N][2][2];
int n;
int a[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
dp[i][j][k] = -1e18;
}
}
}
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
dp[0][0][0] = dp[0][1][0] = dp[0][0][1] = dp[0][1][1] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
if (!(j & k)) {
for (int g = 0; g < 2; ++g) {
for (int t = 0; t < 2; ++t) {
int x = (i + 1) / 2 - g, y = i / 2 - t;
if (y + j == x and y >= 0) {
dp[i][g][j] = max(dp[i][g][j], dp[i - 1][t][k] + j * a[i]);
}
}
}
}
}
}
}
long long ans = -1e18;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
if ((i + 1) / 2 - j == n / 2) {
for (int k = 0; k < 2; ++k) {
ans = max(ans, dp[i][j][k]);
}
}
}
}
cout << ans;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02716 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 10;
const int M = 1e6;
const int mod7 = 1e9 + 7;
const int mod = 1e9 + 7;
void read(int &a) {
a = 0;
int d = 1;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
if (ch == '-')
d = -1;
a = ch ^ 48;
while (ch = getchar(), ch >= '0' && ch <= '9')
a = (a << 3) + (a << 1) + (ch ^ 48);
a *= d;
}
void read(ll &a) {
a = 0;
int d = 1;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
if (ch == '-')
d = -1;
a = ch ^ 48;
while (ch = getchar(), ch >= '0' && ch <= '9')
a = (a << 3) + (a << 1) + (ch ^ 48);
a *= d;
}
ll f1[N], f2[N], f3[N];
int a[N];
int main() {
int n;
read(n);
for (re int i = 1; i <= n; i++)
read(a[i]);
if (n % 2 == 0) {
f1[1] = a[1];
f1[2] = a[2];
for (re int i = 3; i <= n; i++) {
if (i & 1)
f1[i] = f1[i - 2] + a[i];
else
f1[i] = max(f1[i - 3], f1[i - 2]) + a[i];
}
printf("%lld\n", max(f1[n - 1], f1[n]));
} else {
f1[1] = a[1];
f2[1] = a[2];
f3[1] = a[3];
for (re int i = 2; i <= n / 2; i++) {
f1[i] = f1[i - 1] + a[(i << 1) - 1];
f2[i] = max(f1[i - 1], f2[i - 1]) + a[(i << 1)];
f3[i] = max(f1[i - 1], max(f2[i - 1], f3[i - 1])) + a[(i << 1) + 1];
}
printf("%lld\n", max(f1[n / 2], max(f2[n / 2], f3[n / 2])));
}
return 0;
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N = 1e6 + 10;
const int M = 1e6;
const int mod7 = 1e9 + 7;
const int mod = 1e9 + 7;
void read(int &a) {
a = 0;
int d = 1;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
if (ch == '-')
d = -1;
a = ch ^ 48;
while (ch = getchar(), ch >= '0' && ch <= '9')
a = (a << 3) + (a << 1) + (ch ^ 48);
a *= d;
}
void read(ll &a) {
a = 0;
int d = 1;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
if (ch == '-')
d = -1;
a = ch ^ 48;
while (ch = getchar(), ch >= '0' && ch <= '9')
a = (a << 3) + (a << 1) + (ch ^ 48);
a *= d;
}
ll f1[N], f2[N], f3[N];
int a[N];
int main() {
int n;
read(n);
for (re int i = 1; i <= n; i++)
read(a[i]);
if (n % 2 == 0) {
f1[1] = a[1];
f1[2] = a[2];
for (re int i = 3; i <= n; i++) {
if (i & 1)
f1[i] = f1[i - 2] + a[i];
else
f1[i] = max(f1[i - 3], f1[i - 2]) + a[i];
}
printf("%lld\n", max(f1[n - 1], f1[n]));
} else {
f1[1] = a[1];
f2[1] = a[2];
f3[1] = a[3];
for (re int i = 2; i <= n / 2; i++) {
f1[i] = f1[i - 1] + a[(i << 1) - 1];
f2[i] = max(f1[i - 1], f2[i - 1]) + a[(i << 1)];
f3[i] = max(f1[i - 1], max(f2[i - 1], f3[i - 1])) + a[(i << 1) + 1];
}
printf("%lld\n", max(f1[n / 2], max(f2[n / 2], f3[n / 2])));
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02716 | C++ | Time Limit Exceeded | #define STOPIT
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
using namespace std;
using ll = long long;
void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
cerr << " " << head;
debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...) \
do { \
cerr << boolalpha << "[" << #__VA_ARGS__ << "]:"; \
debug_impl(__VA_ARGS__); \
cerr << std::noboolalpha; \
} while (false)
#else
#define debug(...) \
{}
#endif
template <typename Container, typename Value = typename Container::value_type,
enable_if_t<!is_same<Container, string>::value, nullptr_t> = nullptr>
istream &operator>>(istream &is, Container &v) {
for (auto &x : v) {
is >> x;
}
return is;
}
template <typename Container, typename Value = typename Container::value_type,
enable_if_t<!is_same<Container, string>::value, nullptr_t> = nullptr>
ostream &operator<<(ostream &os, Container const &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); it++) {
os << (it != v.begin() ? "," : "") << *it;
}
return os << "}";
}
const ll INF = 100000000000000000;
void update_dp(int y1, int x1, int y2, int x2, vector<vector<ll>> &dp,
const vector<vector<int>> minmax, const vector<ll> &values) {
int require = minmax[y2][x2];
int now = minmax[y1][x1];
// initial point
if (x1 < 0) {
if (require == 1)
dp[y2][x2] = max(dp[y2][x2], values[x2]);
return;
}
if (require == now) {
dp[y2][x2] = max(dp[y2][x2], dp[y1][x1]);
return;
}
if (require - now > 1)
return;
if (x2 - x1 == 1)
return;
dp[y2][x2] = max(dp[y2][x2], dp[y1][x1] + values[x2]);
}
void solve(vector<ll> values, int n) {
// min/ max counts
vector<vector<int>> minmax(2, vector<int>(n, 0));
rep(i, 0, n) {
// min
minmax[0][i] = n / 2 - (n - i - 1) / 2;
// max
minmax[1][i] = (i + 2) / 2;
}
debug(minmax);
// dynamic programming
vector<vector<ll>> dp(2, vector<ll>(n, -INF));
ll res = -INF;
dp[1][0] = values[0];
rep(i, 0, n) {
rep(j, 1, 4) rep(k, 0, 2) {
update_dp(k, i - j, 0, i, dp, minmax, values);
update_dp(k, i - j, 1, i, dp, minmax, values);
}
debug(i, dp[0][i], dp[1][i]);
if (minmax[0][i] == n / 2)
res = max(res, dp[0][i]);
if (minmax[1][i] == n / 2)
res = max(res, dp[1][i]);
}
cout << res << endl;
}
int main() {
int n;
cin >> n;
vector<ll> values(n);
rep(i, 0, n) cin >> values[i];
solve(values, n);
return 0;
}
| #define STOPIT
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
using namespace std;
using ll = long long;
void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
cerr << " " << head;
debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...) \
do { \
cerr << boolalpha << "[" << #__VA_ARGS__ << "]:"; \
debug_impl(__VA_ARGS__); \
cerr << std::noboolalpha; \
} while (false)
#else
#define debug(...) \
{}
#endif
template <typename Container, typename Value = typename Container::value_type,
enable_if_t<!is_same<Container, string>::value, nullptr_t> = nullptr>
istream &operator>>(istream &is, Container &v) {
for (auto &x : v) {
is >> x;
}
return is;
}
template <typename Container, typename Value = typename Container::value_type,
enable_if_t<!is_same<Container, string>::value, nullptr_t> = nullptr>
ostream &operator<<(ostream &os, Container const &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); it++) {
os << (it != v.begin() ? "," : "") << *it;
}
return os << "}";
}
const ll INF = 100000000000000000;
void update_dp(int y1, int x1, int y2, int x2, vector<vector<ll>> &dp,
const vector<vector<int>> &minmax, const vector<ll> &values) {
int require = minmax[y2][x2];
int now = minmax[y1][x1];
// initial point
if (x1 < 0) {
if (require == 1)
dp[y2][x2] = max(dp[y2][x2], values[x2]);
return;
}
if (require == now) {
dp[y2][x2] = max(dp[y2][x2], dp[y1][x1]);
return;
}
if (require - now > 1)
return;
if (x2 - x1 == 1)
return;
dp[y2][x2] = max(dp[y2][x2], dp[y1][x1] + values[x2]);
}
void solve(vector<ll> values, int n) {
// min/ max counts
vector<vector<int>> minmax(2, vector<int>(n, 0));
rep(i, 0, n) {
// min
minmax[0][i] = n / 2 - (n - i - 1) / 2;
// max
minmax[1][i] = (i + 2) / 2;
}
debug(minmax);
// dynamic programming
vector<vector<ll>> dp(2, vector<ll>(n, -INF));
ll res = -INF;
dp[1][0] = values[0];
rep(i, 0, n) {
rep(j, 1, 4) rep(k, 0, 2) {
update_dp(k, i - j, 0, i, dp, minmax, values);
update_dp(k, i - j, 1, i, dp, minmax, values);
}
debug(i, dp[0][i], dp[1][i]);
if (minmax[0][i] == n / 2)
res = max(res, dp[0][i]);
if (minmax[1][i] == n / 2)
res = max(res, dp[1][i]);
}
cout << res << endl;
}
int main() {
int n;
cin >> n;
vector<ll> values(n);
rep(i, 0, n) cin >> values[i];
solve(values, n);
return 0;
}
| replace | 46 | 47 | 46 | 47 | TLE | |
p02716 | C++ | Runtime Error | #include <iostream>
using namespace std;
// https://atcoder.jp/contests/abc159/submissions/14840254
const long long OO = (long long)1e18;
const int N = 100008;
int n;
long long a[N];
long long dp[N][3];
// dp[i][j] is maximum possible sum choosing (i+1-j)/2 elements from first i
// elements. This is NOT a floor! So half the dp elements will be impossible
// solely because it's impossible to choose half an element.
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = -OO;
dp[0][1] = 0;
dp[0][2] = -OO;
dp[1][0] = a[0];
dp[1][1] = -OO;
dp[1][2] = 0;
for (int i = 2; i <= n; i++) {
// note that we are computing dp[i] using a[i-1] and dp[i-1]
for (int j = 0; j < 3; j++) {
// take a[i-1]
dp[i][j] = dp[i - 2][j] + a[i - 1];
if (j) {
// we have slack; don't take a[i-1]
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
}
}
}
cout << dp[n][n % 2 == 0 ? 1 : 2];
}
| #include <iostream>
using namespace std;
// https://atcoder.jp/contests/abc159/submissions/14840254
const long long OO = (long long)1e18;
const int N = 200008;
int n;
long long a[N];
long long dp[N][3];
// dp[i][j] is maximum possible sum choosing (i+1-j)/2 elements from first i
// elements. This is NOT a floor! So half the dp elements will be impossible
// solely because it's impossible to choose half an element.
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = -OO;
dp[0][1] = 0;
dp[0][2] = -OO;
dp[1][0] = a[0];
dp[1][1] = -OO;
dp[1][2] = 0;
for (int i = 2; i <= n; i++) {
// note that we are computing dp[i] using a[i-1] and dp[i-1]
for (int j = 0; j < 3; j++) {
// take a[i-1]
dp[i][j] = dp[i - 2][j] + a[i - 1];
if (j) {
// we have slack; don't take a[i-1]
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
}
}
}
cout << dp[n][n % 2 == 0 ? 1 : 2];
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
int main() {
int N;
cin >> N;
VI a(N);
rep(i, N) { cin >> a.at(i); }
ll maxi = max(max(a.at(0), a.at(1)), a.at(2));
ll left = a.at(0);
ll emax = max(a.at(0), a.at(1));
for (int i = 4; i < N + 1; i++) {
if (i % 2 == 0) {
left += a.at(i - 2);
emax = max(emax + a.at(i - 1), left);
} else {
maxi = max(emax, maxi + a.at(i - 1));
}
}
if (N % 2 == 0) {
cout << emax << endl;
} else {
cout << maxi << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
int main() {
int N;
cin >> N;
VI a(N);
rep(i, N) { cin >> a.at(i); }
if (N == 2) {
cout << max(a.at(0), a.at(1)) << endl;
return 0;
}
ll maxi = max(max(a.at(0), a.at(1)), a.at(2));
ll left = a.at(0);
ll emax = max(a.at(0), a.at(1));
for (int i = 4; i < N + 1; i++) {
if (i % 2 == 0) {
left += a.at(i - 2);
emax = max(emax + a.at(i - 1), left);
} else {
maxi = max(emax, maxi + a.at(i - 1));
}
}
if (N % 2 == 0) {
cout << emax << endl;
} else {
cout << maxi << endl;
}
return 0;
}
| insert | 12 | 12 | 12 | 16 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using state = pair<int, int>;
int64_t dp(state stat, const vector<int64_t> &data, map<state, int64_t> *memo) {
if (memo->count(stat)) {
return memo->at(stat);
} else {
const int N = data.size();
int rem, id;
tie(rem, id) = stat;
if (rem == 0) {
return memo->operator[](stat) = 0;
} else if (2 * rem - 1 == N - id) {
int64_t sum_odd = 0;
for (int i = id; i < N; i += 2) {
sum_odd += data.at(i);
}
return memo->operator[](stat) = sum_odd;
} else if (2 * rem - 1 > N - id) {
return memo->operator[](stat) = INT64_MIN;
} else {
state pick = make_pair(rem - 1, id + 2);
state nopick = make_pair(rem, id + 1);
return memo->operator[](stat) = max(data.at(id) + dp(pick, data, memo),
dp(nopick, data, memo));
}
}
}
int main() {
int N;
cin >> N;
vector<int64_t> data(N);
for (int i = 0; i < N; i++) {
cin >> data.at(i);
}
map<state, int64_t> memo;
cout << dp(make_pair(N / 2, 0), data, &memo) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using state = pair<int, int>;
int64_t dp(state stat, const vector<int64_t> &data, map<state, int64_t> *memo) {
if (memo->count(stat)) {
return memo->at(stat);
} else {
const int N = data.size();
int rem, id;
tie(rem, id) = stat;
if (rem == 0) {
return memo->operator[](stat) = 0;
} else if (2 * rem - 1 > N - id) {
return memo->operator[](stat) = INT64_MIN;
} else {
state pick = make_pair(rem - 1, id + 2);
state nopick = make_pair(rem, id + 1);
return memo->operator[](stat) = max(data.at(id) + dp(pick, data, memo),
dp(nopick, data, memo));
}
}
}
int main() {
int N;
cin >> N;
vector<int64_t> data(N);
for (int i = 0; i < N; i++) {
cin >> data.at(i);
}
map<state, int64_t> memo;
cout << dp(make_pair(N / 2, 0), data, &memo) << endl;
} | delete | 14 | 21 | 14 | 14 | TLE | |
p02716 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
ll power(long a, long b) {
return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
int A[200100];
rep(i, N) cin >> A[i];
long dp[100100][2][3];
rep(i, N + 1) rep(x, 2) rep(y, 3) dp[i][x][y] = -1LL << 60;
dp[0][1][0] = 0;
for (int i = 0; i < N; i++) {
rep(j, 2) rep(k, 3) {
// not take
if (k + j < 3)
dp[i + 1][1][k + j] = max(dp[i + 1][1][k + j], dp[i][j][k]);
// take
if (j == 1)
dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k] + A[i]);
}
}
if (N % 2 == 0)
cout << max(dp[N][1][0], dp[N][0][1]) << "\n";
else
cout << max(dp[N][0][2], dp[N][1][1]) << "\n";
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
ll power(long a, long b) {
return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
int A[200100];
rep(i, N) cin >> A[i];
long dp[200100][2][3];
rep(i, N + 1) rep(x, 2) rep(y, 3) dp[i][x][y] = -1LL << 60;
dp[0][1][0] = 0;
for (int i = 0; i < N; i++) {
rep(j, 2) rep(k, 3) {
// not take
if (k + j < 3)
dp[i + 1][1][k + j] = max(dp[i + 1][1][k + j], dp[i][j][k]);
// take
if (j == 1)
dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k] + A[i]);
}
}
if (N % 2 == 0)
cout << max(dp[N][1][0], dp[N][0][1]) << "\n";
else
cout << max(dp[N][0][2], dp[N][1][1]) << "\n";
} | replace | 39 | 40 | 39 | 40 | 0 | |
p02716 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x) * (x)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 200007;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll read() {
ll 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 * 10 + ch - '0', ch = getchar();
return x * f;
}
ll a[maxn];
ll dp[maxn][11], Sum;
int main() {
freopen("test.in", "r", stdin);
int n = read();
for (int i = 1; i <= n; i++)
a[i] = read(), Sum += a[i];
memset(dp, 0x3f, sizeof(dp));
dp[0][5] = 0;
dp[1][6] = a[1];
for (int i = 2; i <= n + 1; i++) {
for (int k = 0; k <= 10; k++) {
int now = i / 2 + k - 5;
if (now >= 1) {
int p1 = now - 1 - (i - 1) / 2 + 5;
int p2 = now - 1 - (i - 2) / 2 + 5;
if (p1 > 10 || p2 > 10 || p1 < 0 || p2 < 0)
continue;
dp[i][k] = min(dp[i - 1][p1], dp[i - 2][p2]) + a[i];
}
}
}
int you = n - (n / 2) + 1;
int p = you - (n + 1) / 2 + 5;
cout << Sum - dp[n + 1][p];
return 0;
} | #include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x) * (x)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 200007;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll read() {
ll 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 * 10 + ch - '0', ch = getchar();
return x * f;
}
ll a[maxn];
ll dp[maxn][11], Sum;
int main() {
int n = read();
for (int i = 1; i <= n; i++)
a[i] = read(), Sum += a[i];
memset(dp, 0x3f, sizeof(dp));
dp[0][5] = 0;
dp[1][6] = a[1];
for (int i = 2; i <= n + 1; i++) {
for (int k = 0; k <= 10; k++) {
int now = i / 2 + k - 5;
if (now >= 1) {
int p1 = now - 1 - (i - 1) / 2 + 5;
int p2 = now - 1 - (i - 2) / 2 + 5;
if (p1 > 10 || p2 > 10 || p1 < 0 || p2 < 0)
continue;
dp[i][k] = min(dp[i - 1][p1], dp[i - 2][p2]) + a[i];
}
}
}
int you = n - (n / 2) + 1;
int p = you - (n + 1) / 2 + 5;
cout << Sum - dp[n + 1][p];
return 0;
} | replace | 23 | 24 | 23 | 24 | TLE | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100 * 1000 + 20;
ll n, sum[N], dp[N], a[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
sum[i] = a[i] + (i > 1 ? sum[i - 2] : 0);
for (int i = 1; i < n; i++) {
if (i % 2 == 0)
dp[i] = max(a[i] + dp[i - 2], dp[i - 1]);
else
dp[i] = max(a[i] + dp[i - 2], sum[i - 1]);
}
return cout << dp[n - 1] << endl, 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2 * 100 * 1000 + 20;
ll n, sum[N], dp[N], a[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
sum[i] = a[i] + (i > 1 ? sum[i - 2] : 0);
for (int i = 1; i < n; i++) {
if (i % 2 == 0)
dp[i] = max(a[i] + dp[i - 2], dp[i - 1]);
else
dp[i] = max(a[i] + dp[i - 2], sum[i - 1]);
}
return cout << dp[n - 1] << endl, 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02716 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1e18;
// long long dp[200005][4];
long long dp[100][4];
// dp[i][j] : i個目まで見てj個余分なx(バツ)を入れたときのMAX
int main() {
int N;
cin >> N;
vector<long long> a(N);
for (int i = 0; i < N; ++i)
cin >> a[i];
// K: 何個余分のバツを入れれる?奇数は2で偶数は1
int K = 1 + N % 2;
for (int i = 0; i < N + 1; ++i) {
for (int j = 0; j < K + 1; ++j) {
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < K + 1; ++j) {
// バツを一個挿入(今見てる数をスキップ)
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
// 次の数を当てはめる,0からなので割り切れたらそれはカウント
long long now = dp[i][j];
if ((i + j) % 2 == 0)
now += a[i];
dp[i + 1][j] = max(dp[i + 1][j], now);
}
}
long long ans = dp[N][K];
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1e18;
long long dp[200005][4];
// long long dp[100][4];
// dp[i][j] : i個目まで見てj個余分なx(バツ)を入れたときのMAX
int main() {
int N;
cin >> N;
vector<long long> a(N);
for (int i = 0; i < N; ++i)
cin >> a[i];
// K: 何個余分のバツを入れれる?奇数は2で偶数は1
int K = 1 + N % 2;
for (int i = 0; i < N + 1; ++i) {
for (int j = 0; j < K + 1; ++j) {
dp[i][j] = -INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < K + 1; ++j) {
// バツを一個挿入(今見てる数をスキップ)
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
// 次の数を当てはめる,0からなので割り切れたらそれはカウント
long long now = dp[i][j];
if ((i + j) % 2 == 0)
now += a[i];
dp[i + 1][j] = max(dp[i + 1][j], now);
}
}
long long ans = dp[N][K];
cout << ans << endl;
} | replace | 8 | 10 | 8 | 10 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcountll
#define INF 1e10
#define mod 1000000007
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n + 2, -INF), pre(n + 2, -1), nxt(n + 2, -1);
repl(i, 1, n + 1) cin >> a[i];
rep(i, n + 2) {
pre[i] = i - 1;
nxt[i] = i + 1;
}
set<P> st;
rep(i, n + 2) { st.insert(P(a[i], i)); }
ll sum = 0;
rep(_, n / 2) {
P p = *st.rbegin();
sum += p.fi;
ll idx = p.se;
st.erase(st.find(P(p.fi, p.se)));
st.erase(st.find(P(a[pre[idx]], pre[idx])));
st.erase(st.find(P(a[nxt[idx]], nxt[idx])));
ll val = a[pre[idx]] + a[nxt[idx]] - a[idx];
a[idx] = -INF;
a[nxt[idx]] = -INF;
ll nnxt = nxt[nxt[idx]];
nxt[pre[idx]] = nnxt;
if (nnxt < n + 2)
pre[nnxt] = pre[idx];
a[pre[idx]] = val;
st.insert(P(a[pre[idx]], pre[idx]));
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n + 2, -INF), pre(n + 2, -1), nxt(n + 2, -1);
repl(i, 1, n + 1) cin >> a[i];
rep(i, n + 2) {
pre[i] = i - 1;
nxt[i] = i + 1;
}
set<P> st;
rep(i, n + 2) { st.insert(P(a[i], i)); }
ll sum = 0;
rep(_, n / 2) {
P p = *st.rbegin();
sum += p.fi;
ll idx = p.se;
st.erase(st.find(P(p.fi, p.se)));
st.erase(st.find(P(a[pre[idx]], pre[idx])));
st.erase(st.find(P(a[nxt[idx]], nxt[idx])));
ll val = a[pre[idx]] + a[nxt[idx]] - a[idx];
a[idx] = -INF;
a[nxt[idx]] = -INF;
ll nnxt = nxt[nxt[idx]];
nxt[pre[idx]] = nnxt;
if (nnxt < n + 2)
pre[nnxt] = pre[idx];
a[pre[idx]] = val;
st.insert(P(a[pre[idx]], pre[idx]));
}
cout << sum << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02716 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5 + 5, inf = 1e17;
ll a[N], prfx[N], dp[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
for (ll i = 1; i <= n; i++)
cin >> a[i];
prfx[1] = a[1];
for (ll i = 3; i <= n; i += 2)
prfx[i] = prfx[i - 2] + a[i];
for (ll i = 2; i <= n; i++) {
if (i & 1)
dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
else
dp[i] = max(prfx[i - 1], a[i] + dp[i - 2]);
}
cout << dp[n];
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
ll a[N], prfx[N], dp[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
for (ll i = 1; i <= n; i++)
cin >> a[i];
prfx[1] = a[1];
for (ll i = 3; i <= n; i += 2)
prfx[i] = prfx[i - 2] + a[i];
for (ll i = 2; i <= n; i++) {
if (i & 1)
dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
else
dp[i] = max(prfx[i - 1], a[i] + dp[i - 2]);
}
cout << dp[n];
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02717 | C++ | Runtime Error | // Author - Sumit
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define ll long long
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define F first
#define S second
#define mii map<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int, int>>
#define itr ::iterator it
#define WL(t) while (t--)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x, y) cout << x << " " << y << "\n";
#define debug3(x, y, z) cout << x << " " << y << " " << z << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
template <typename T, typename U> inline void remin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void remax(T &x, U y) {
if (x < y)
x = y;
}
template <typename T> T pow(T a, T b, int m) {
T ans = 1;
while (b > 0) {
if (b % 2 == 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans % m;
}
void solve() {
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
debug3(a, b, c);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
clock_t clk = clock();
int t = 1;
// cin>>t;
while (t--) {
solve();
}
cerr << ((long double)(1.00 * clock() - clk) / CLOCKS_PER_SEC) << "\n";
} | // Author - Sumit
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#define ll long long
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define F first
#define S second
#define mii map<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int, int>>
#define itr ::iterator it
#define WL(t) while (t--)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define lower(v, x) (lower_bound(all(v), x) - v.begin())
#define upper(v, x) (upper_bound(all(v), x) - v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x, y) cout << x << " " << y << "\n";
#define debug3(x, y, z) cout << x << " " << y << " " << z << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
template <typename T, typename U> inline void remin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void remax(T &x, U y) {
if (x < y)
x = y;
}
template <typename T> T pow(T a, T b, int m) {
T ans = 1;
while (b > 0) {
if (b % 2 == 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans % m;
}
void solve() {
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
debug3(a, b, c);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// freopen("error.txt","w",stderr);
// #endif
clock_t clk = clock();
int t = 1;
// cin>>t;
while (t--) {
solve();
}
cerr << ((long double)(1.00 * clock() - clk) / CLOCKS_PER_SEC) << "\n";
} | replace | 73 | 78 | 73 | 78 | 0 | |
p02717 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
#define BeatMeScanf \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define tc(x) \
int x; \
cin >> x; \
while (x--)
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define inf 1 << 28
#define mem(x, y) memset(x, y, sizeof(x))
#define ps(x, y) fixed << setprecision(y) << x
#define show(val) cout << #val << " -> " << val << endl
#define Case cout << "Case " << ++cs << ": "
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 1000000007
int main() {
BeatMeScanf;
#ifndef ONLINE_JUDGE
freopen("G:/C++/in.txt", "r", stdin);
freopen("G:/C++/out.txt", "w", stdout);
#endif
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define BeatMeScanf \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define tc(x) \
int x; \
cin >> x; \
while (x--)
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define inf 1 << 28
#define mem(x, y) memset(x, y, sizeof(x))
#define ps(x, y) fixed << setprecision(y) << x
#define show(val) cout << #val << " -> " << val << endl
#define Case cout << "Case " << ++cs << ": "
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 1000000007
int main() {
BeatMeScanf;
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << '\n';
return 0;
}
| delete | 27 | 31 | 27 | 27 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << endl;
return 0;
}
| delete | 6 | 10 | 6 | 6 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
return (sum_3(j) - sum_3(i - 1) + M) % M;
}
void solve() {
int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
return (sum_3(j) - sum_3(i - 1) + M) % M;
}
void solve() {
int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
} | delete | 32 | 36 | 32 | 32 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MX 35
#define MOD 1'000'000'007
#define set(N, pos) (N = (1LL << (pos)))
#define clear(N, pos) (N = (~(1LL << (pos))))
#define is_set(N, pos) (N & (1LL << (pos)))
#define all(v) (v).begin(), (v).end()
ll bigMod(ll base, ll pw) {
ll ret = 1, mul = base;
while (pw) {
if (pw & 1)
ret = (ret * mul) % MOD;
mul = (mul * mul) % MOD;
pw >>= 1;
}
return ret;
}
vi prime;
vector<bool> mark(MX, 0);
void sieve() {
int limit = sqrt(MX + 1);
prime.push_back(2);
for (int i = 3; i < MX; i += 2) {
if (!mark[i]) {
prime.push_back(i);
if (i < limit) {
for (int j = i * i; j < MX; j += 2 * i)
mark[j] = 1;
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
cout << c << ' ' << a << ' ' << b << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MX 35
#define MOD 1'000'000'007
#define set(N, pos) (N = (1LL << (pos)))
#define clear(N, pos) (N = (~(1LL << (pos))))
#define is_set(N, pos) (N & (1LL << (pos)))
#define all(v) (v).begin(), (v).end()
ll bigMod(ll base, ll pw) {
ll ret = 1, mul = base;
while (pw) {
if (pw & 1)
ret = (ret * mul) % MOD;
mul = (mul * mul) % MOD;
pw >>= 1;
}
return ret;
}
vi prime;
vector<bool> mark(MX, 0);
void sieve() {
int limit = sqrt(MX + 1);
prime.push_back(2);
for (int i = 3; i < MX; i += 2) {
if (!mark[i]) {
prime.push_back(i);
if (i < limit) {
for (int j = i * i; j < MX; j += 2 * i)
mark[j] = 1;
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
cout << c << ' ' << a << ' ' << b << endl;
return 0;
}
| replace | 44 | 45 | 44 | 45 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar, k, n) \
for (int i = k; i < n; i++) \
cin >> ar[i]
#define fout(ar, k, n) \
for (int i = k; i < n; i++) \
cout << ar[i] << ' '
#define vs vector<string>
#define mx INT_MAX
#define mn INT_MIN
#define all(z) z.begin(), z.end()
#define mcc 1000000007
#define mcf 998244353
#define mi map<int, int>
#define mem(a, n) memset(a, n, sizeof(a))
using namespace std;
// ll maxl(ll a,ll b) {return (a>b)? a:b;}
// ll minl(ll a,ll b) {return (a<b)? a:b;}
// ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}
void solve() {
int a, b, c;
cin >> a >> b >> c;
cout << c << ' ' << a << ' ' << b;
}
#if 1
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
#endif
//------------------------Google-------------------
#if 0
int main()
{
#ifdef __WIN32
freopen("input.txt","r",stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t,ct=0;
cin>>t;
while(t--)
{
cout<<"Case #"<<++ct<<": ";
solve();
}
return 0;
}
#endif
| #include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar, k, n) \
for (int i = k; i < n; i++) \
cin >> ar[i]
#define fout(ar, k, n) \
for (int i = k; i < n; i++) \
cout << ar[i] << ' '
#define vs vector<string>
#define mx INT_MAX
#define mn INT_MIN
#define all(z) z.begin(), z.end()
#define mcc 1000000007
#define mcf 998244353
#define mi map<int, int>
#define mem(a, n) memset(a, n, sizeof(a))
using namespace std;
// ll maxl(ll a,ll b) {return (a>b)? a:b;}
// ll minl(ll a,ll b) {return (a<b)? a:b;}
// ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}
void solve() {
int a, b, c;
cin >> a >> b >> c;
cout << c << ' ' << a << ' ' << b;
}
#if 1
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
#endif
//------------------------Google-------------------
#if 0
int main()
{
#ifdef __WIN32
freopen("input.txt","r",stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
ll t,ct=0;
cin>>t;
while(t--)
{
cout<<"Case #"<<++ct<<": ";
solve();
}
return 0;
}
#endif
| replace | 32 | 35 | 32 | 33 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio;
ll t;
t = 1;
while (t--) {
ll x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y;
}
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int main() {
fastio;
ll t;
t = 1;
while (t--) {
ll x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y;
}
return 0;
} | replace | 28 | 32 | 28 | 29 | 0 | |
p02717 | Python | Runtime Error | A, B, C = [int(i) for i in input().split()]
A, B, C = B, A, C
A, B, C = C, B, A
print(f"{A} {B} {C}")
| A, B, C = [int(i) for i in input().split()]
A, B, C = B, A, C
A, B, C = C, B, A
print("%s %s %s" % (A, B, C))
| replace | 5 | 6 | 5 | 6 | 0 | |
p02717 | Python | Runtime Error | #!/usr/bin/env python3
a = int(input())
a, b = map(int, input().split())
a = list(str(input()))
| #!/usr/bin/env python3
a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))
| replace | 2 | 5 | 2 | 4 | ValueError: invalid literal for int() with base 10: '1 2 3' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s892793306.py", line 3, in <module>
a = int(input())
ValueError: invalid literal for int() with base 10: '1 2 3'
|
p02717 | Python | Runtime Error | x, y, z = map(int, input())
print(z, x, y)
| x, y, z = map(int, input().split())
print(z, x, y)
| replace | 0 | 1 | 0 | 1 | ValueError: invalid literal for int() with base 10: ' ' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s498360594.py", line 1, in <module>
x, y, z = map(int, input())
ValueError: invalid literal for int() with base 10: ' '
|
p02717 | Python | Runtime Error | X, Y, Z = map(int, input())
print(Z, X, Y)
| X, Y, Z = map(int, input().split())
print(Z, X, Y)
| replace | 0 | 1 | 0 | 1 | ValueError: invalid literal for int() with base 10: ' ' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s623686087.py", line 1, in <module>
X, Y, Z = map(int, input())
ValueError: invalid literal for int() with base 10: ' '
|
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("outp.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b;
return 0;
} | #include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b;
return 0;
}
| delete | 8 | 12 | 8 | 8 | 0 | |
p02717 | Python | Runtime Error | x, y, z = map(int, input().split())
print(z + " " + x + " " + y)
| x, y, z = map(str, input().split())
print(z + " " + x + " " + y)
| replace | 0 | 1 | 0 | 1 | TypeError: unsupported operand type(s) for +: 'int' and 'str' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s693185745.py", line 2, in <module>
print(z + " " + x + " " + y)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
|
p02717 | Python | Runtime Error | X, Y, Z = map(int, input().split())
print(f"{Z} {X} {Y}")
| X, Y, Z = map(int, input().split())
print(Z, X, Y)
| replace | 1 | 2 | 1 | 2 | 0 | |
p02717 | Python | Runtime Error | XYZ = map(int, input().split())
print(XYZ[2], XYZ[1], XYZ[0])
| XYZ = input().split()
print(XYZ[2], XYZ[0], XYZ[1])
| replace | 0 | 2 | 0 | 2 | TypeError: 'map' object is not subscriptable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s285964975.py", line 2, in <module>
print(XYZ[2], XYZ[1], XYZ[0])
TypeError: 'map' object is not subscriptable
|
p02717 | Python | Runtime Error | import sys
if __name__ == "__main__":
print(f"{sys.argv[-1]} {sys.argv[1]} {sys.argv[2]}")
| import sys
if __name__ == "__main__":
a, b, c = map(int, input().split())
print(c, a, b)
| replace | 4 | 5 | 4 | 6 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s097242719.py", line 5, in <module>
print(f"{sys.argv[-1]} {sys.argv[1]} {sys.argv[2]}")
IndexError: list index out of range
|
p02717 | Python | Runtime Error | a = int(input())
b = int(input())
c = int(input())
print(c, a, b)
| a, b, c = map(int, input().split())
print(c, a, b)
| replace | 0 | 3 | 0 | 1 | ValueError: invalid literal for int() with base 10: '1 2 3' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s384192178.py", line 1, in <module>
a = int(input())
ValueError: invalid literal for int() with base 10: '1 2 3'
|
p02717 | Python | Runtime Error | x, y, z = input().split()
print(f"{z} {x} {y}")
| x, y, z = input().split()
print(z, x, y)
| replace | 1 | 2 | 1 | 2 | 0 | |
p02717 | Python | Runtime Error | x, y, z = map(int, input().split())
print(f"{z} {x} {y}")
| x, y, z = map(int, input().split())
print(z, end=" ")
print(x, end=" ")
print(y)
| replace | 1 | 2 | 1 | 4 | 0 | |
p02717 | C++ | Runtime Error | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int c = atoi(argv[3]);
printf("%d\n ", c);
printf("%d\n ", a);
printf("%d\n ", b);
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%d %d %d\n", c, a, b);
return 0;
} | replace | 3 | 10 | 3 | 7 | -11 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()), ((v).end())
#define clr(v, val) memset(v, val, sizeof v)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
void Run() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e5 + 20;
/***You***Can***Do***It***/
int main() {
Run();
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()), ((v).end())
#define clr(v, val) memset(v, val, sizeof v)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
void Run() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e5 + 20;
/***You***Can***Do***It***/
int main() {
// Run();
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << endl;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02717 | Python | Runtime Error | import sys
a, b, c = map(int, sys.argv[1:])
b2 = a
c2 = b
a2 = c
print(a2, b2, c2)
| in_ = input()
a, b, c = map(int, in_.split())
b2 = a
c2 = b
a2 = c
print(a2, b2, c2)
| replace | 0 | 3 | 0 | 2 | ValueError: not enough values to unpack (expected 3, got 0) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s419762460.py", line 2, in <module>
a, b, c = map(int, sys.argv[1:])
ValueError: not enough values to unpack (expected 3, got 0)
|
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
// #define ONLINE_JUDGE 1
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << "\n";
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define ONLINE_JUDGE 1
using namespace std;
const int mod = 1e9 + 7;
void solve() {
int x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y << "\n";
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02717 | C++ | Runtime Error | /*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
DON'T ADJUST THE GOALS,
ADJUST THE ACTION STEPS.
--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU
UNCOMFORTABLE.
--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
IO();
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
ll power(ll a, ll b) {
ll ans = 1;
while (b > 0) {
if (b & 1)
ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
ll powm(ll a, ll b) {
a %= MOD;
ll ans = 1;
while (b > 0) {
if (b & 1)
ans = (ans * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ans;
}
void IO() {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
//================================
int main() {
FAST;
int a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b << "\n";
return 0;
} | /*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
DON'T ADJUST THE GOALS,
ADJUST THE ACTION STEPS.
--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU
UNCOMFORTABLE.
--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
IO();
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
ll power(ll a, ll b) {
ll ans = 1;
while (b > 0) {
if (b & 1)
ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
ll powm(ll a, ll b) {
a %= MOD;
ll ans = 1;
while (b > 0) {
if (b & 1)
ans = (ans * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return ans;
}
void IO() {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
//================================
int main() {
// FAST;
int a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b << "\n";
return 0;
} | replace | 86 | 87 | 86 | 87 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <exception>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair
void fast() {
ios::sync_with_stdio(NULL);
cout.tie(NULL);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
/*freopen("output.txt", "w", stdout);
freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
fast();
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << " " << b << " " << c << endl;
return 0;
} | #include <bits/stdc++.h>
#include <exception>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair
void fast() {
ios::sync_with_stdio(NULL);
cout.tie(NULL);
cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
fast();
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << " " << b << " " << c << endl;
return 0;
}
| delete | 21 | 29 | 21 | 21 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#define maxn 10005
#define INF 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;
void slove() {
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << ' ' << b << ' ' << c << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef ONLINE_JUDGE
#else
freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
/*while (cin >> t)*/
slove();
return 0;
} | #include <bits/stdc++.h>
#define maxn 10005
#define INF 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;
void slove() {
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << ' ' << b << ' ' << c << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
/*while (cin >> t)*/
slove();
return 0;
} | replace | 19 | 24 | 19 | 20 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#define TASK "task"
using namespace std;
void rwFile() {
freopen(TASK ".in", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
void solveA() {
int x, y, z;
cin >> x >> y >> z;
cout << z << ' ' << x << ' ' << y;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
rwFile();
solveA();
}
| #include <bits/stdc++.h>
#define TASK "task"
using namespace std;
void rwFile() {
freopen(TASK ".in", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
void solveA() {
int x, y, z;
cin >> x >> y >> z;
cout << z << ' ' << x << ' ' << y;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
/// rwFile();
solveA();
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const ll mod = 1e9 + 7;
const db eps = 1e-9;
#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cout << #x << " " << x << endl
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ll a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << " " << b << " " << c;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const ll mod = 1e9 + 7;
const db eps = 1e-9;
#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cout << #x << " " << x << endl
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << " " << b << " " << c;
return 0;
} | delete | 20 | 26 | 20 | 20 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 100000000000000000
#define UB upper_bound
#define LB lower_bound
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
/////number of edges in a graph equal (v[i].size() ka summation of all the
///vertices)//
int main() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 100000000000000000
#define UB upper_bound
#define LB lower_bound
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
/////number of edges in a graph equal (v[i].size() ka summation of all the
///vertices)//
int main() {
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ll int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << endl;
} | replace | 18 | 22 | 18 | 22 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
#define loop(var, init, condition) for (int var = init; var < condition; var++)
#define rloop(var, init, condition) for (int var = init; var > condition; var--)
#define mod 1000000007
#define qmod 998244353
#define M 1000001
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define popi pop_back
#define SZ(v) ((int)(v).size())
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef unordered_map<string, int> usi;
typedef unordered_map<int, int> umii;
typedef map<int, int> omii;
typedef set<int> seti;
ll pow(ll a, ll b, ll m) {
ll x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x > m)
x %= m;
}
y = (y * y);
if (y > m)
y %= m;
b /= 2;
}
return x % m;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << " " << endl;
return 0;
}
// MAKING HARD THINGS SIMPLE AND SIMPLE THINGS HARD
// ,~~.
// ( 6 )-_,
// (\___ )=='-'
// \ . ) )
// \ `-' / battak
// ~'`~'`~'`~'`~ | #include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
#define loop(var, init, condition) for (int var = init; var < condition; var++)
#define rloop(var, init, condition) for (int var = init; var > condition; var--)
#define mod 1000000007
#define qmod 998244353
#define M 1000001
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define popi pop_back
#define SZ(v) ((int)(v).size())
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef unordered_map<string, int> usi;
typedef unordered_map<int, int> umii;
typedef map<int, int> omii;
typedef set<int> seti;
ll pow(ll a, ll b, ll m) {
ll x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x > m)
x %= m;
}
y = (y * y);
if (y > m)
y %= m;
b /= 2;
}
return x % m;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
fast;
int x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << " " << endl;
return 0;
}
// MAKING HARD THINGS SIMPLE AND SIMPLE THINGS HARD
// ,~~.
// ( 6 )-_,
// (\___ )=='-'
// \ . ) )
// \ `-' / battak
// ~'`~'`~'`~'`~ | replace | 49 | 53 | 49 | 53 | 0 | |
p02717 | C++ | Runtime Error | /*
KUNAL RAUT (ZUKONIT14) :- "DO WHAT YOU LIKE!"
-PICT,PUNE! :)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000005
#define N 1000001
#define MAX2N 1 * 1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed << setprecision(n)
#define forci(p, n) for (ll i = p; i < (ll)n; i++)
#define forcj(p, n) for (ll j = p; j < (ll)n; j++)
#define bolt \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test \
ll t; \
cin >> t; \
for (ll testi = 1; testi <= t; testi++)
#define djokovic \
freopen("input00.txt", "r", stdin); \
freopen("output00.txt", "w", stdout);
ll zero = 0;
ll one = 1;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll expo(ll x, ll y) {
ll res = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
res = (1ll * res * x) % mod;
y = y >> 1;
x = (1ll * x * x) % mod;
}
return res;
}
ll ncr(ll n, ll r) {
ll res = 1;
if (r > n - r)
r = n - r;
for (ll i = 0; i < r; i++) {
res *= n - i;
res /= i + 1;
}
return res;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }
bool prime(ll n) {
ll i;
for (i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
if (a.second == b.second)
return a.first < b.first;
return (a.second < b.second);
}
// https://www.youtube.com/watch?v=WTJSt4wP2ME
ll rr[] = {
0, 1, 1, 1, 0, -1, -1, -1,
};
ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll n, m, x, k, a[MAXN], p[MAXN];
void solve() {
ll x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y;
}
signed main() {
bolt;
#ifndef ONLINE_JUDGE
djokovic;
#endif
solve();
}
| /*
KUNAL RAUT (ZUKONIT14) :- "DO WHAT YOU LIKE!"
-PICT,PUNE! :)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000005
#define N 1000001
#define MAX2N 1 * 1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed << setprecision(n)
#define forci(p, n) for (ll i = p; i < (ll)n; i++)
#define forcj(p, n) for (ll j = p; j < (ll)n; j++)
#define bolt \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test \
ll t; \
cin >> t; \
for (ll testi = 1; testi <= t; testi++)
#define djokovic \
freopen("input00.txt", "r", stdin); \
freopen("output00.txt", "w", stdout);
ll zero = 0;
ll one = 1;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll expo(ll x, ll y) {
ll res = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
res = (1ll * res * x) % mod;
y = y >> 1;
x = (1ll * x * x) % mod;
}
return res;
}
ll ncr(ll n, ll r) {
ll res = 1;
if (r > n - r)
r = n - r;
for (ll i = 0; i < r; i++) {
res *= n - i;
res /= i + 1;
}
return res;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }
bool prime(ll n) {
ll i;
for (i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
if (a.second == b.second)
return a.first < b.first;
return (a.second < b.second);
}
// https://www.youtube.com/watch?v=WTJSt4wP2ME
ll rr[] = {
0, 1, 1, 1, 0, -1, -1, -1,
};
ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll n, m, x, k, a[MAXN], p[MAXN];
void solve() {
ll x, y, z;
cin >> x >> y >> z;
cout << z << " " << x << " " << y;
}
signed main() {
bolt;
// djokovic;
solve();
}
| replace | 93 | 96 | 93 | 94 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for (ll i = 0; i < n; i++)
#define rep2(n) for (ll j = 0; j < n; ++j)
#define repd(n) for (ll i = n - 1; i >= 0; i--)
#define MOD 1000000007
#define pii pair<ll, ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl "\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define M 998244353
#define limit 100000000
void solve() {
ll a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
ll t = 1;
// cin>>t;
rep(t) { solve(); }
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for (ll i = 0; i < n; i++)
#define rep2(n) for (ll j = 0; j < n; ++j)
#define repd(n) for (ll i = n - 1; i >= 0; i--)
#define MOD 1000000007
#define pii pair<ll, ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl "\n"
#define INF 0x3f3f3f3f
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define M 998244353
#define limit 100000000
void solve() {
ll a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b;
}
int main() {
fast;
ll t = 1;
// cin>>t;
rep(t) { solve(); }
return 0;
}
| delete | 34 | 38 | 34 | 34 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/*#ifndef ONLINE_JUDGE
#include <lol.h>
#endif*/
#define mp make_pair
#define pb push_back
#define pf push_front
#define sz(a) (int)((a).size())
#define fr(i, n) for (ll i = 0; i < n; i++)
#define fr1(i, n) for (ll i = 1; i <= n; i++)
#define frk(i, k, n) for (ll i = k; i < n; i++)
#define rfr(i, n) for (ll i = n - 1; i >= 0; i--)
#define foa(i, a, n) for (ll i = 0; i < n; i += a)
#define f first
#define s second
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define vsort(x) sort(all(x))
#define debug cout << "Hey Sweetie, Stop Right Here......" << endl;
typedef long long int ll;
typedef stack<ll> stll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef set<ll> sll;
typedef multiset<ll> msll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef long double ld;
ll modmulti(ll a, ll b, ll m) { return ((a % m) * (b % m)) % m; }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y, ll m) {
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
ll power2(ll x, ll y) {
if (y == 0)
return 1;
ll p = power2(x, y / 2);
p = (p * p);
return (y % 2 == 0) ? p : (x * p);
}
bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
if (a.first == b.first)
return (a.second < b.second);
else
return (a.first > b.first);
}
ll bin(vll a, ll left, ll right, ll x) {
ll mid = left + (right - left) / 2;
if (a[mid] == x)
return mid;
if (left <= right) {
if (a[mid] < x)
return bin(a, mid + 1, right, x);
else if (a[mid] > x)
return bin(a, left, mid - 1, x);
}
return -1;
}
ll findclosest(ll n) {
ll i;
for (i = 0; i <= 64; i++) {
if (power2(2, i) <= n)
continue;
else
break;
}
return power2(2, i - 1);
}
ll get_signi(ll n) {
while (n >= 10) {
n = n / 10;
}
return n;
}
ll get_digits(ll n) {
ll i = 0;
while (n >= 10) {
n = n / 10;
i++;
}
return i;
}
bool is_palindrome(string t) {
for (int i = 0; i < t.size() / 2; i++) {
if (t[i] != t[t.size() - i - 1])
return false;
}
return true;
}
int main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
/*#ifndef ONLINE_JUDGE
#include <lol.h>
#endif*/
#define mp make_pair
#define pb push_back
#define pf push_front
#define sz(a) (int)((a).size())
#define fr(i, n) for (ll i = 0; i < n; i++)
#define fr1(i, n) for (ll i = 1; i <= n; i++)
#define frk(i, k, n) for (ll i = k; i < n; i++)
#define rfr(i, n) for (ll i = n - 1; i >= 0; i--)
#define foa(i, a, n) for (ll i = 0; i < n; i += a)
#define f first
#define s second
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define vsort(x) sort(all(x))
#define debug cout << "Hey Sweetie, Stop Right Here......" << endl;
typedef long long int ll;
typedef stack<ll> stll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef set<ll> sll;
typedef multiset<ll> msll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef long double ld;
ll modmulti(ll a, ll b, ll m) { return ((a % m) * (b % m)) % m; }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y, ll m) {
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
ll power2(ll x, ll y) {
if (y == 0)
return 1;
ll p = power2(x, y / 2);
p = (p * p);
return (y % 2 == 0) ? p : (x * p);
}
bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
if (a.first == b.first)
return (a.second < b.second);
else
return (a.first > b.first);
}
ll bin(vll a, ll left, ll right, ll x) {
ll mid = left + (right - left) / 2;
if (a[mid] == x)
return mid;
if (left <= right) {
if (a[mid] < x)
return bin(a, mid + 1, right, x);
else if (a[mid] > x)
return bin(a, left, mid - 1, x);
}
return -1;
}
ll findclosest(ll n) {
ll i;
for (i = 0; i <= 64; i++) {
if (power2(2, i) <= n)
continue;
else
break;
}
return power2(2, i - 1);
}
ll get_signi(ll n) {
while (n >= 10) {
n = n / 10;
}
return n;
}
ll get_digits(ll n) {
ll i = 0;
while (n >= 10) {
n = n / 10;
i++;
}
return i;
}
bool is_palindrome(string t) {
for (int i = 0; i < t.size() / 2; i++) {
if (t[i] != t[t.size() - i - 1])
return false;
}
return true;
}
int main() {
fastio;
ll x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z << endl;
return 0;
} | delete | 114 | 118 | 114 | 114 | 0 | |
p02717 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define ppp pair<ll, pair<ll, ll>>
#define pp pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define pi 3.14159265358
#define MOD 998244353
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << " " << b << " " << c;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define ppp pair<ll, pair<ll, ll>>
#define pp pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define pi 3.14159265358
#define MOD 998244353
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("error.txt", "w", stderr);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
cout << a << " " << b << " " << c;
}
| replace | 16 | 21 | 16 | 21 | 0 | |
p02717 | C++ | Time Limit Exceeded |
/*
@・ω・@ <だれだろうね
*/
/*****/
#include <algorithm>
#include <array>
#include <cmath>
#include <fstream>
#include <iomanip> //cout << fixed << setprecision(桁数);
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
// #define int long long
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using pr = pair<T, T>;
template <class T> using vec = vector<T>;
#define debug(x) (std::cerr << x)
#define debugln(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t", n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " << (x) << "\n")
#define debug_tabcout(n, x) \
(std::cerr << strMulti("\t", n) << #x << " : " << (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " << (x) << "\n")
#define debug_tabheadcout(n, h, x) \
(std::cerr << strMulti("\t", n) << h << " : " << (x) << "\n")
#define str(n) (n.toString())
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define step(i, a, n) for (ll i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstep(i, a, n) \
for (ll i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define range(i, a, b) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rrange(i, a, b) for (ll i = (b)-1, i##_len = (a); i >= i##_len; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2000000100;
constexpr ll MOD = 1000000007; // 10e9+7
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> T divup(T a, T b) {
if (a % b == 0) {
return a / b;
}
return a / b + 1;
}
std::string strMulti(std::string t, int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += t;
}
return out;
}
template <class T> T math_P(T m, T n) {
T ret = 1;
for (T i = m; i > m - n; i--) {
ret *= i;
}
return ret;
}
template <class T> T math_C(T m, T n) {
T ret = math_P(m, n);
for (T i = 2; i <= n; i++) {
ret /= i;
}
return ret;
}
template <class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
template <class T> T mod_pow(T x, T n, const T &p) {
T ret = 1;
while (n > 0) {
if (n & 1) {
(ret *= x) %= p;
}
(x *= x) %= p;
n >>= 1;
}
return ret;
}
/*****/
using graph = vec<vec<ll>>;
void Main() {
ll x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z;
}
/*****/
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// std::cout << std::fixed << std::setprecision(10);
/**
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
ofstream out("output.txt");
cout.rdbuf(out.rdbuf());
/**/
/**/
while (true) {
Main();
std::cerr << flush;
cout << endl;
}
/*/
Main();
std::cerr << flush;
cout << endl;
/**/
return 0;
}
|
/*
@・ω・@ <だれだろうね
*/
/*****/
#include <algorithm>
#include <array>
#include <cmath>
#include <fstream>
#include <iomanip> //cout << fixed << setprecision(桁数);
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
// #define int long long
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using pr = pair<T, T>;
template <class T> using vec = vector<T>;
#define debug(x) (std::cerr << x)
#define debugln(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t", n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " << (x) << "\n")
#define debug_tabcout(n, x) \
(std::cerr << strMulti("\t", n) << #x << " : " << (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " << (x) << "\n")
#define debug_tabheadcout(n, h, x) \
(std::cerr << strMulti("\t", n) << h << " : " << (x) << "\n")
#define str(n) (n.toString())
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define step(i, a, n) for (ll i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstep(i, a, n) \
for (ll i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define range(i, a, b) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rrange(i, a, b) for (ll i = (b)-1, i##_len = (a); i >= i##_len; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2000000100;
constexpr ll MOD = 1000000007; // 10e9+7
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> T divup(T a, T b) {
if (a % b == 0) {
return a / b;
}
return a / b + 1;
}
std::string strMulti(std::string t, int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += t;
}
return out;
}
template <class T> T math_P(T m, T n) {
T ret = 1;
for (T i = m; i > m - n; i--) {
ret *= i;
}
return ret;
}
template <class T> T math_C(T m, T n) {
T ret = math_P(m, n);
for (T i = 2; i <= n; i++) {
ret /= i;
}
return ret;
}
template <class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
template <class T> T mod_pow(T x, T n, const T &p) {
T ret = 1;
while (n > 0) {
if (n & 1) {
(ret *= x) %= p;
}
(x *= x) %= p;
n >>= 1;
}
return ret;
}
/*****/
using graph = vec<vec<ll>>;
void Main() {
ll x, y, z;
cin >> x >> y >> z;
swap(x, y);
swap(x, z);
cout << x << " " << y << " " << z;
}
/*****/
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// std::cout << std::fixed << std::setprecision(10);
/**
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
ofstream out("output.txt");
cout.rdbuf(out.rdbuf());
/**/
/**
while (true)
{
Main();
std::cerr << flush;
cout << endl;
}
/*/
Main();
std::cerr << flush;
cout << endl;
/**/
return 0;
}
| replace | 140 | 145 | 140 | 146 | TLE | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
// cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int, int>
#define all(x) x.begin(), x.end()
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b << "\n";
return 0;
} | #include <bits/stdc++.h>
// cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define pr pair<int, int>
#define all(x) x.begin(), x.end()
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int a, b, c;
cin >> a >> b >> c;
cout << c << " " << a << " " << b << "\n";
return 0;
} | replace | 12 | 16 | 12 | 16 | 0 | |
p02717 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define vi vector<int>
#define vec(x) vector<x>
#define matrix vector<vector<int>>
#define pii pair<int, int>
#define rep(i, s, e) for (int i = s; i < e; i++)
#define rrep(i, e, s) for (int i = e; i >= s; i--)
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define w(x) \
int x; \
cin >> x; \
while (x--)
const int INF = 1e18;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
// find_by_order(k-1) returns iterator to kth element starting from 0; Returns
// the kth smallest element order_of_key(k) returns count of elements strictly
// smaller than k;Returns the number of elements less than k erase,insert same
// as normal set
void solve() {
int x, y, z;
cin >> x >> y >> z;
cout << z << ' ' << x << ' ' << y << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define vi vector<int>
#define vec(x) vector<x>
#define matrix vector<vector<int>>
#define pii pair<int, int>
#define rep(i, s, e) for (int i = s; i < e; i++)
#define rrep(i, e, s) for (int i = e; i >= s; i--)
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define w(x) \
int x; \
cin >> x; \
while (x--)
const int INF = 1e18;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
// find_by_order(k-1) returns iterator to kth element starting from 0; Returns
// the kth smallest element order_of_key(k) returns count of elements strictly
// smaller than k;Returns the number of elements less than k erase,insert same
// as normal set
void solve() {
int x, y, z;
cin >> x >> y >> z;
cout << z << ' ' << x << ' ' << y << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("input.txt", "r"))
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| replace | 59 | 63 | 59 | 61 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.