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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02690 | C++ | Time Limit Exceeded | #include <iostream>
#define int long long int
using namespace std;
int X;
signed main() {
cin >> X;
for (int i = -200; i <= 200; i++) {
for (int j = -200; j = 200; j++) {
if (i * i * i * i * i - j * j * j * j * j == X) {
cout << i << " " << j << endl;
return 0;
}
}
}
} | #include <iostream>
#define int long long int
using namespace std;
int X;
signed main() {
cin >> X;
for (int i = -200; i <= 200; i++) {
for (int j = -200; j <= 200; j++) {
if (i * i * i * i * i - j * j * j * j * j == X) {
cout << i << " " << j << endl;
return 0;
}
}
}
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02690 | C++ | Time Limit Exceeded | // #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repc(i, a, b, c) \
for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) \
(n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) : 0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'
#define int ll
vector<ll> ft(1, 1LL);
/*======================================================================*/
vector<int> graph[100005];
int arr[100005];
void solve() {
int n, m;
cin >> n;
for (int i = 0;; i++) {
for (int b = 0; b < 3982; b++)
if (i * i * i * i * i == n - b * b * b * b * b) {
cout << i << " " << -b;
return;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
} | // #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repc(i, a, b, c) \
for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
// #define mp make_pair
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) \
(n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) : 0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'
#define int ll
vector<ll> ft(1, 1LL);
/*======================================================================*/
vector<int> graph[100005];
int arr[100005];
void solve() {
int n, m;
cin >> n;
for (int i = 0;; i++) {
for (int b = 0; b < 3982; b++)
if (i * i * i * i * i == n - b * b * b * b * b) {
cout << i << " " << -b;
return;
} else if (i * i * i * i * i == n + b * b * b * b * b) {
cout << i << " " << b;
return;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
} | insert | 42 | 42 | 42 | 45 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, string> P;
int main() {
int x;
cin >> x;
long long ans = 0;
for (int i = -10000; i <= 10000; i++) {
for (int j = -10000; j <= 10000; j++) {
ans = pow(i, 5) - pow(j, 5);
if (ans == x) {
cout << i << " " << j << endl;
return 0;
}
}
}
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, string> P;
int main() {
int x;
cin >> x;
long long ans = 0;
for (int i = -1000; i <= 1000; i++) {
for (int j = -1000; j <= 1000; j++) {
ans = pow(i, 5) - pow(j, 5);
if (ans == x) {
cout << i << " " << j << endl;
return 0;
}
}
}
} | replace | 17 | 19 | 17 | 19 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
long long x;
cin >> x;
for (long a = 0;; a++) {
for (long b = 0; b >= -1000000000; b--) {
long long c = (a * a * a * a * a) - (b * b * b * b * b);
if (x == c) {
cout << a << " " << b << endl;
return 0;
}
}
}
} | #include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
int main() {
long long x;
cin >> x;
for (long a = -1000;; a++) {
for (long b = 0; b >= -1000; b--) {
long long c = (a * a * a * a * a) - (b * b * b * b * b);
if (x == c) {
cout << a << " " << b << endl;
return 0;
}
}
}
} | replace | 11 | 13 | 11 | 13 | TLE | |
p02690 | C++ | Time Limit Exceeded | #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--)
#define pvec(vec) \
{ \
for (auto v : vec) \
cout << v << ' '; \
cout << endl; \
}
#define pivec(vec) \
{ \
rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; \
cout << endl; \
}
using namespace std;
using ll = long long;
unordered_map<ll, int> value5;
void init() {
ll num = 0;
for (;;) {
ll now = num * num * num * num * num;
if (now < 0)
break;
value5[now] = num++;
}
unordered_map<ll, int> new_value5(value5);
for (auto v : value5)
new_value5[-v.first] = -v.second;
swap(value5, new_value5);
}
int main() {
init();
ll x;
cin >> x;
ll num = 0;
for (;;) {
ll now = num * num * num * num * num;
ll tgt = now - x;
if (value5.count(tgt) > 0) {
cout << num << ' ' << value5[tgt] << endl;
return 0;
}
// cout << num << endl;
++num;
}
return 0;
}
| #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--)
#define pvec(vec) \
{ \
for (auto v : vec) \
cout << v << ' '; \
cout << endl; \
}
#define pivec(vec) \
{ \
rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; \
cout << endl; \
}
using namespace std;
using ll = long long;
unordered_map<ll, int> value5;
void init() {
ll num = 0;
for (;;) {
ll now = num * num * num * num * num;
if (now > 100000000000)
break;
value5[now] = num++;
}
unordered_map<ll, int> new_value5(value5);
for (auto v : value5)
new_value5[-v.first] = -v.second;
swap(value5, new_value5);
}
int main() {
init();
ll x;
cin >> x;
ll num = 0;
for (;;) {
ll now = num * num * num * num * num;
ll tgt = now - x;
if (value5.count(tgt) > 0) {
cout << num << ' ' << value5[tgt] << endl;
return 0;
}
// cout << num << endl;
++num;
}
return 0;
}
| replace | 23 | 24 | 23 | 24 | TLE | |
p02690 | C++ | Runtime Error | #include <cstdio>
int main() {
int X;
scanf("%d", X);
for (int A = 0; A < 1000; ++A)
for (int B = -1000; B < A; ++B)
if (A * A * A * A * A - B * B * B * B * B == X) {
printf("%d %d", A, B);
return 0;
}
} | #include <cstdio>
int main() {
int X;
scanf("%d", &X);
for (int A = 0; A < 1000; ++A)
for (int B = -1000; B < A; ++B)
if (A * A * A * A * A - B * B * B * B * B == X) {
printf("%d %d", A, B);
return 0;
}
} | replace | 4 | 5 | 4 | 5 | -11 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
template <typename _Ty> _Ty bpow(_Ty a, int64_t n) {
_Ty res = 1;
for (; n > 0; n >>= 1) {
if (n & 1)
res *= a;
a *= a;
}
return res;
}
void solve() {
ll X;
cin >> X;
Vl pow5(101);
for (ll i = 0; i < 101; i++) {
pow5[i] = bpow(i, 5);
}
ll a, b;
b = 0;
while (true) {
ll idx =
lower_bound(pow5.begin(), pow5.end(), X + bpow(b, 5)) - pow5.begin();
if (bpow(idx, 5) - bpow(b, 5) == X) {
a = idx;
break;
}
idx = lower_bound(pow5.begin(), pow5.end(), X - bpow(b, 5)) - pow5.begin();
if (bpow(idx, 5) + bpow(b, 5) == X) {
a = idx;
b = -b;
break;
}
++b;
}
cout << a << " " << b << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
solve();
cout << flush;
return 0;
} | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
template <typename _Ty> _Ty bpow(_Ty a, int64_t n) {
_Ty res = 1;
for (; n > 0; n >>= 1) {
if (n & 1)
res *= a;
a *= a;
}
return res;
}
void solve() {
ll X;
cin >> X;
ll mx = 6209;
Vl pow5(mx);
for (ll i = 0; i < mx; i++) {
pow5[i] = bpow(i, 5);
}
ll a, b;
b = 0;
while (true) {
ll idx =
lower_bound(pow5.begin(), pow5.end(), X + bpow(b, 5)) - pow5.begin();
if (bpow(idx, 5) - bpow(b, 5) == X) {
a = idx;
break;
}
idx = lower_bound(pow5.begin(), pow5.end(), X - bpow(b, 5)) - pow5.begin();
if (bpow(idx, 5) + bpow(b, 5) == X) {
a = idx;
b = -b;
break;
}
++b;
}
cout << a << " " << b << endl;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
solve();
cout << flush;
return 0;
} | replace | 29 | 31 | 29 | 33 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using ull = unsigned long long;
#define int long long
using namespace std;
#define dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) { Yes(!flag); }
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) { YES(!flag); }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
bool dbg = false;
} // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
// #define P pair<int, int>
// #define V vector<int>
// #define S set<int>
#define asn ans
int X;
int intpow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans *= a;
a *= a;
b /= 2;
}
return ans;
}
void solve() {
for (int A = 0;; A++) {
int Y = intpow(A, 5) - X;
if (Y == 0) {
cout << A << " " << 0 << endl;
return;
}
int minus = 1;
if (Y < 0) {
minus = -1;
Y *= -1;
}
int ok = 0;
int ng = 100;
auto check = [&](int x) { return intpow(x, 5) <= Y; };
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid)) {
ok = mid;
} else {
ng = mid;
}
}
if (intpow(ok, 5) == Y) {
cout << A << " " << ok * minus << endl;
return;
}
}
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> X;
solve();
return 0;
}
| #include <bits/stdc++.h>
using ull = unsigned long long;
#define int long long
using namespace std;
#define dump(x) \
if (dbg) { \
cerr << #x << " = " << (x) << endl; \
}
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
void Yes(bool flag = true) {
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void No(bool flag = true) { Yes(!flag); }
void YES(bool flag = true) {
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void NO(bool flag = true) { YES(!flag); }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
bool dbg = false;
} // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
// #define P pair<int, int>
// #define V vector<int>
// #define S set<int>
#define asn ans
int X;
int intpow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans *= a;
a *= a;
b /= 2;
}
return ans;
}
void solve() {
for (int A = 0;; A++) {
int Y = intpow(A, 5) - X;
if (Y == 0) {
cout << A << " " << 0 << endl;
return;
}
int minus = 1;
if (Y < 0) {
minus = -1;
Y *= -1;
}
int ok = 0;
int ng = 1000;
auto check = [&](int x) { return intpow(x, 5) <= Y; };
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (check(mid)) {
ok = mid;
} else {
ng = mid;
}
}
if (intpow(ok, 5) == Y) {
cout << A << " " << ok * minus << endl;
return;
}
}
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> X;
solve();
return 0;
}
| replace | 96 | 97 | 96 | 97 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int main() {
int x, limit;
cin >> x;
limit = pow(x, 1.0 / 5.0);
for (int i = 0; i <= limit; i++) {
for (int j = 0; j >= -limit; j--) {
if (x == pow(i, 5) - pow(j, 5)) {
cout << i << " " << j << endl;
return 0;
}
}
}
for (long long i = limit;; i++) {
for (long long j = 0;; j++) {
if (x == pow(i, 5) - pow(j, 5)) {
cout << i << " " << j << endl;
return 0;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int main() {
int x, limit;
cin >> x;
limit = pow(x, 1.0 / 5.0);
for (int i = 0; i <= limit; i++) {
for (int j = 0; j >= -limit; j--) {
if (x == pow(i, 5) - pow(j, 5)) {
cout << i << " " << j << endl;
return 0;
}
}
}
for (long long i = limit;; i++) {
for (long long j = 0; j < i; j++) {
if (x == pow(i, 5) - pow(j, 5)) {
cout << i << " " << j << endl;
return 0;
}
}
}
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
for (long long i = -3981; i <= 3981; i++)
for (long long n = -3981; n <= 3981; n++)
if ((pow(i, 5)) - (pow(n, 5)) == a) {
cout << i << " " << n;
return 0;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
for (long long i = -1000; i <= 1000; i++)
for (long long n = -1000; n <= 1000; n++)
if ((pow(i, 5)) - (pow(n, 5)) == a) {
cout << i << " " << n;
return 0;
}
return 0;
}
| replace | 5 | 7 | 5 | 7 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
ll x;
cin >> x;
ll a5, b5;
for (int i = -10000; i <= 10000; i++) {
for (int j = -10000; j <= 10000; j++) {
if (pow(i, 5) - pow(j, 5) == x) {
printf("%d %d\n", i, j);
return 0;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
ll x;
cin >> x;
ll a5, b5;
for (int i = -1000; i <= 1000; i++) {
for (int j = -1000; j <= 1000; j++) {
if (pow(i, 5) - pow(j, 5) == x) {
printf("%d %d\n", i, j);
return 0;
}
}
}
return 0;
} | replace | 11 | 13 | 11 | 13 | TLE | |
p02690 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define int long long // −9·10^18 to 9·10^18
#define lll __int128_t // −10^38 to 10^38
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int, int> mi;
// const
#define EPS 1e-9
#define INF LLONG_MAX
const int mod = 1000 * 1000 * 1000 + 7; // 1e9+7
// inputs & output & debug
#define w(t) \
int t; \
cin >> t; \
while (t--)
template <typename... T> void read(T &...args) { ((cin >> args), ...); }
template <typename... T> void write(T &&...args) {
((cout << args << " "), ...);
}
#define deb(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
// useful functions
// #define deb(x) cout<<#x<<": "<<x<<endl;
#define isPowOfTwo(x) return (x && (!(x & (x - 1))));
#define gcd(x, y) return __gcd(x, y);
void fio() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("/Users/asuryana/Desktop/CP/input.txt", "r", stdin);
freopen("/Users/asuryana/Desktop/CP/output.txt", "w", stdout);
#endif
}
void solve() {
int n;
read(n);
int s[120] = {0};
for (int i = 1; i <= 120; i++)
s[i] = pow(i, 5);
for (int i = 0; i <= 120; i++)
for (int j = 0; j <= 120; j++) {
if ((s[i] - s[j]) == n) {
write(i, j);
return;
}
if ((s[j] + s[i]) == n) {
write(j, -i);
return;
}
}
}
int32_t main() {
fio();
return solve(), 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define int long long // −9·10^18 to 9·10^18
#define lll __int128_t // −10^38 to 10^38
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int, int> mi;
// const
#define EPS 1e-9
#define INF LLONG_MAX
const int mod = 1000 * 1000 * 1000 + 7; // 1e9+7
// inputs & output & debug
#define w(t) \
int t; \
cin >> t; \
while (t--)
template <typename... T> void read(T &...args) { ((cin >> args), ...); }
template <typename... T> void write(T &&...args) {
((cout << args << " "), ...);
}
#define deb(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
// useful functions
// #define deb(x) cout<<#x<<": "<<x<<endl;
#define isPowOfTwo(x) return (x && (!(x & (x - 1))));
#define gcd(x, y) return __gcd(x, y);
void fio() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("/Users/asuryana/Desktop/CP/input.txt", "r", stdin);
freopen("/Users/asuryana/Desktop/CP/output.txt", "w", stdout);
#endif
}
void solve() {
int n;
read(n);
int s[125] = {0};
for (int i = 1; i <= 120; i++)
s[i] = pow(i, 5);
for (int i = 0; i <= 120; i++)
for (int j = 0; j <= 120; j++) {
if ((s[i] - s[j]) == n) {
write(i, j);
return;
}
if ((s[j] + s[i]) == n) {
write(j, -i);
return;
}
}
}
int32_t main() {
fio();
return solve(), 0;
}
| replace | 65 | 66 | 65 | 66 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int main() {
LLONG X;
cin >> X;
set<LLONG> divs;
for (LLONG d = 1; d * d <= X; ++d) {
if (X % d == 0) {
divs.insert(d);
divs.insert(X / d);
divs.insert(-d);
divs.insert(-X / d);
}
}
for (const LLONG d : divs) {
LLONG X2 = X / d - d * d * d * d;
if (X2 % 5 == 0) {
X2 /= 5;
if (X2 == 0) {
cout << d << ' ' << 0 << endl;
return 0;
}
set<LLONG> BCands;
for (LLONG B = 1; B * B <= abs(X2); ++B) {
if (abs(X2) % B == 0) {
for (LLONG b : {B, X2 / B, -B, -X2 / B}) {
LLONG X3 = X2 / b - d * d * d;
if (b * b * b + 2 * d * b * b + 2 * d * d * b == X3) {
cout << b + d << ' ' << b << endl;
return 0;
}
}
}
}
}
}
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int main() {
LLONG X;
cin >> X;
set<LLONG> divs;
for (LLONG d = 1; d * d <= X; ++d) {
if (X % d == 0) {
divs.insert(d);
divs.insert(X / d);
// divs.insert(-d);
// divs.insert(-X / d);
}
}
for (const LLONG d : divs) {
LLONG X2 = X / d - d * d * d * d;
if (X2 % 5 == 0) {
X2 /= 5;
if (X2 == 0) {
cout << d << ' ' << 0 << endl;
return 0;
}
set<LLONG> BCands;
for (LLONG B = 1; B * B <= abs(X2); ++B) {
if (abs(X2) % B == 0) {
for (LLONG b : {B, X2 / B, -B, -X2 / B}) {
LLONG X3 = X2 / b - d * d * d;
if (b * b * b + 2 * d * b * b + 2 * d * d * b == X3) {
cout << b + d << ' ' << b << endl;
return 0;
}
}
}
}
}
}
}
| replace | 25 | 27 | 25 | 27 | TLE | |
p02690 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cfenv>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;
ll pow5(ll x) { return x * x * x * x * x; }
int main() {
ll x;
cin >> x;
for (ll i = 0;; i++) {
ll b = abs(pow5(i) - x);
double b0 = pow((double)b, 0.2);
if (ceil(b0) == floor(b0)) {
println(i << " " << -(ll)b0);
break;
}
}
}
| #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cfenv>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;
ll pow5(ll x) { return x * x * x * x * x; }
int main() {
ll x;
cin >> x;
for (ll i = 1; i < 200; i++) {
for (ll j = 0; j < 200; j++) {
for (ll k = 0; k < 200; k++) {
if (pow5(j) - pow5(k - i) == x) {
println(j << " " << k - i);
return 0;
}
}
}
}
}
| replace | 44 | 50 | 44 | 52 | TLE | |
p02690 | C++ | Runtime Error | /*
vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu
rtll==??>>;::::~~~~......`.``````````````````
..J77!`````````...`..._T,~~~~:::;;>??==lttrrv
tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` ``
.,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! `
`` .J"~N```````````..?&.~~~~::;;>>?==llt
=??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J;
``````````..h..~~~~::;;>??=ll
?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b`
````````.S_.~~~~::;;>??=l
>;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ```````
G...~~~~::;>??=
;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` `
``````` 6...~~~~::;>??
;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([
`````.L...~~~~::;>?
:~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` `
`````,)....~~:::;>
~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` `
````(,...~~~~:;;
~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... `
``````4....~~~::;
~~~...`` .=`` ` `
.b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~::
~....` ,^`` ` `
.b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~::
.... .=``` `` `
...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~:
~...v```` `
..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9
..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??=
(v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1=
t..``
4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1
...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ ``
``````....~~~
...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! `
````....~~:
..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` `
`````....~~~:
...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` `
`````...~~~:
....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` `
```....~~~:
....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` `
``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` `
`````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` `
```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` `
`````....~~~::;;
~~j,..```````.D??>>>MM/....`........(-=` ` ` `
```````...~~~:::;>
~~~j,...````.E??>??>?MN-.........(J= ` ` `
``````....~~~~::;??
:~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` `
````````...~~~~:;;>??
::~~~?/....K??????>>?>dMN-_(7! ` ` `
````````....~~~:::>>??l
;:::~~/e.(K==?????????<dM"! ` ` ` ` ``
``````...~~~~:::;>??=l
@TT_beginner
*/
#include "bits/stdc++.h"
using namespace std;
#define ok1 cerr << "ok1\n";
#define ok2 cerr << "ok2\n";
#define M LLONG_MAX
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, s, n) for (int i = (s); i < (n); ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define REPR(i, s, n) for (int i = (s); i >= (n); --(i))
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb emplace_back // emplace_backの方が速いが使い慣れてないため
#define DOUBLE fixed << setprecision(15)
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define out(x, y) ((x) < 0 || h <= (x) || (y) < 0 || w <= (y))
#define TO_STRING(VariableName) #VariableName
#define debug(x) cout << TO_STRING(x) << " is: " << x << " " << endl;
const double pi = acos(-1.0L);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> TLL;
typedef vector<P> vP;
typedef vector<TLL> vTLL;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, -1, 0, 1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class A, class B>
ostream &operator<<(ostream &ost, const pair<A, B> &p) {
ost << "{ " << p.first << ", " << p.second << " }";
return ost;
}
template <class T> ostream &operator<<(ostream &ost, const vector<T> &v) {
ost << "{ ";
for (int i = 0; i < v.size(); i++) {
if (i)
ost << ", ";
ost << v[i];
}
ost << " }";
return ost;
}
template <class A, class B>
ostream &operator<<(ostream &ost, const map<A, B> &v) {
ost << "{ ";
for (auto p : v) {
ost << "{ " << p.first << ", " << p.second << " }";
}
ost << " }";
return ost;
}
void debugs() { std::cerr << "\n"; }
template <class T, class... Args> void debugs(const T &x, const Args &...args) {
std::cerr << TO_STRING(x) << " " << x << " ";
debugs(args...);
}
bool out_check(ll a, ll b) { return (0 <= a && a < b); }
double pitagoras(ll a, ll b, ll c, ll d) {
double dx = a - b, dy = c - d;
return pow(dx * dx + dy * dy, 0.5);
}
ll modpow(ll a, ll b) {
ll c = 1;
while (b > 0) {
if (b & 1) {
c = a * c % mod;
}
a = a * a % mod;
b >>= 1;
}
return c;
}
void Yes(bool x) { cout << ((x) ? "Yes\n" : "No\n"); }
void YES(bool x) { cout << ((x) ? "YES\n" : "NO\n"); }
void yes(bool x) { cout << ((x) ? "yes\n" : "no\n"); }
void Yay(bool x) { cout << ((x) ? "Yay!\n" : ":(\n"); }
void OK(bool x) { cout << ((x) ? "OK!\n" : "NG\n"); }
//*
ll n, m, d, e, l, k, h, w, Q, ans, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t, u;
int main() {
cin.tie(0);
ios::sync_with_stdio(false); // not interactive
cin >> n;
vll tbl;
rep(i, 50) tbl.pb(i * i * i * i * i);
// debug(tbl);
rep(i, n) {
ll b = (n - tbl[i]);
ll index = lower_bound(all(tbl), b) - tbl.begin();
// debug(b);
// cerr << i << " " << -index << endl;
if (b == tbl[index]) {
cout << i << " " << -index << endl;
break;
}
}
} | /*
vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu
rtll==??>>;::::~~~~......`.``````````````````
..J77!`````````...`..._T,~~~~:::;;>??==lttrrv
tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` ``
.,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! `
`` .J"~N```````````..?&.~~~~::;;>>?==llt
=??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J;
``````````..h..~~~~::;;>??=ll
?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b`
````````.S_.~~~~::;;>??=l
>;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ```````
G...~~~~::;>??=
;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` `
``````` 6...~~~~::;>??
;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([
`````.L...~~~~::;>?
:~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` `
`````,)....~~:::;>
~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` `
````(,...~~~~:;;
~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... `
``````4....~~~::;
~~~...`` .=`` ` `
.b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~::
~....` ,^`` ` `
.b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~::
.... .=``` `` `
...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~:
~...v```` `
..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9
..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??=
(v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1=
t..``
4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1
...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ ``
``````....~~~
...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! `
````....~~:
..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` `
`````....~~~:
...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` `
`````...~~~:
....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` `
```....~~~:
....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` `
``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` `
`````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` `
```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` `
`````....~~~::;;
~~j,..```````.D??>>>MM/....`........(-=` ` ` `
```````...~~~:::;>
~~~j,...````.E??>??>?MN-.........(J= ` ` `
``````....~~~~::;??
:~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` `
````````...~~~~:;;>??
::~~~?/....K??????>>?>dMN-_(7! ` ` `
````````....~~~:::>>??l
;:::~~/e.(K==?????????<dM"! ` ` ` ` ``
``````...~~~~:::;>??=l
@TT_beginner
*/
#include "bits/stdc++.h"
using namespace std;
#define ok1 cerr << "ok1\n";
#define ok2 cerr << "ok2\n";
#define M LLONG_MAX
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, s, n) for (int i = (s); i < (n); ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define REPR(i, s, n) for (int i = (s); i >= (n); --(i))
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb emplace_back // emplace_backの方が速いが使い慣れてないため
#define DOUBLE fixed << setprecision(15)
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define out(x, y) ((x) < 0 || h <= (x) || (y) < 0 || w <= (y))
#define TO_STRING(VariableName) #VariableName
#define debug(x) cout << TO_STRING(x) << " is: " << x << " " << endl;
const double pi = acos(-1.0L);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> TLL;
typedef vector<P> vP;
typedef vector<TLL> vTLL;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, -1, 0, 1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class A, class B>
ostream &operator<<(ostream &ost, const pair<A, B> &p) {
ost << "{ " << p.first << ", " << p.second << " }";
return ost;
}
template <class T> ostream &operator<<(ostream &ost, const vector<T> &v) {
ost << "{ ";
for (int i = 0; i < v.size(); i++) {
if (i)
ost << ", ";
ost << v[i];
}
ost << " }";
return ost;
}
template <class A, class B>
ostream &operator<<(ostream &ost, const map<A, B> &v) {
ost << "{ ";
for (auto p : v) {
ost << "{ " << p.first << ", " << p.second << " }";
}
ost << " }";
return ost;
}
void debugs() { std::cerr << "\n"; }
template <class T, class... Args> void debugs(const T &x, const Args &...args) {
std::cerr << TO_STRING(x) << " " << x << " ";
debugs(args...);
}
bool out_check(ll a, ll b) { return (0 <= a && a < b); }
double pitagoras(ll a, ll b, ll c, ll d) {
double dx = a - b, dy = c - d;
return pow(dx * dx + dy * dy, 0.5);
}
ll modpow(ll a, ll b) {
ll c = 1;
while (b > 0) {
if (b & 1) {
c = a * c % mod;
}
a = a * a % mod;
b >>= 1;
}
return c;
}
void Yes(bool x) { cout << ((x) ? "Yes\n" : "No\n"); }
void YES(bool x) { cout << ((x) ? "YES\n" : "NO\n"); }
void yes(bool x) { cout << ((x) ? "yes\n" : "no\n"); }
void Yay(bool x) { cout << ((x) ? "Yay!\n" : ":(\n"); }
void OK(bool x) { cout << ((x) ? "OK!\n" : "NG\n"); }
//*
ll n, m, d, e, l, k, h, w, Q, ans, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t, u;
int main() {
cin.tie(0);
ios::sync_with_stdio(false); // not interactive
cin >> n;
for (ll i = -1000; i <= 1000; i++) {
for (ll j = -1000; j <= 1000; j++) {
if (i * i * i * i * i - j * j * j * j * j == n) {
cout << i << " " << j << endl;
return 0;
}
}
}
} | replace | 174 | 185 | 174 | 180 | 0 | |
p02690 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) \
cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) \
<< endl;
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v);
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v)
out << item << ", ";
out << "\b\b}";
return out;
}
void _tostr_rec(ostringstream &oss) { oss << "\b\b \b"; }
template <typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
oss << head << ", ";
_tostr_rec(oss, forward<Tail>(tail)...);
}
template <typename... T> string _tostr(T &&...args) {
ostringstream oss;
int size = sizeof...(args);
if (size > 1)
oss << "{";
_tostr_rec(oss, forward<T>(args)...);
if (size > 1)
oss << "}";
return oss.str();
}
#endif
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010
int main() {
ll X;
cin >> X;
for (ll i = -100; i <= 100; i++) {
for (ll j = -100; j <= 100; j++) {
ll r = i * i * i * i * i - j * j * j * j * j;
if (r == X) {
cout << i << " " << j << endl;
return 0;
}
}
}
assert(false);
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) \
cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) \
<< endl;
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v);
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
out << "{" << p.first << ", " << p.second << "}";
return out;
}
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
out << '{';
for (const T &item : v)
out << item << ", ";
out << "\b\b}";
return out;
}
void _tostr_rec(ostringstream &oss) { oss << "\b\b \b"; }
template <typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
oss << head << ", ";
_tostr_rec(oss, forward<Tail>(tail)...);
}
template <typename... T> string _tostr(T &&...args) {
ostringstream oss;
int size = sizeof...(args);
if (size > 1)
oss << "{";
_tostr_rec(oss, forward<T>(args)...);
if (size > 1)
oss << "}";
return oss.str();
}
#endif
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010
int main() {
ll X;
cin >> X;
for (ll i = -1000; i <= 1000; i++) {
for (ll j = -1000; j <= 1000; j++) {
ll r = i * i * i * i * i - j * j * j * j * j;
if (r == X) {
cout << i << " " << j << endl;
return 0;
}
}
}
assert(false);
return 0;
} | replace | 78 | 80 | 78 | 80 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t x;
cin >> x;
int64_t rootx = 0;
while (rootx * rootx <= x) {
rootx++;
}
rootx--;
vector<int64_t> factors(0);
for (int64_t i = 1; i <= rootx; i++) {
if (x % i == 0) {
factors.push_back(i);
if (i != x / i) {
factors.push_back(x / i);
}
}
}
int64_t a = 1;
int64_t b = 0;
int64_t size = int64_t(factors.size());
for (int64_t i = 0; i < size; i++) {
int64_t d = factors.at(i);
int64_t flag = 1;
int64_t tmp = 0;
while (tmp - d < 120) {
if (tmp * tmp * tmp * tmp * tmp -
(tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) ==
x) {
a = tmp;
b = a - d;
flag = 0;
break;
}
else {
tmp++;
}
}
if (flag == 0) {
break;
}
}
cout << a << " " << b << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t x;
cin >> x;
int64_t rootx = 0;
while (rootx * rootx <= x) {
rootx++;
}
rootx--;
vector<int64_t> factors(0);
for (int64_t i = 1; i <= rootx; i++) {
if (x % i == 0) {
factors.push_back(i);
if (i != x / i) {
factors.push_back(x / i);
}
}
}
int64_t a = 1;
int64_t b = 0;
int64_t size = int64_t(factors.size());
for (int64_t i = 0; i < size; i++) {
int64_t d = factors.at(size - 1 - i);
int64_t flag = 1;
int64_t tmp = 0;
while (tmp - d < 120) {
if (tmp * tmp * tmp * tmp * tmp -
(tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) * (tmp - d) ==
x) {
a = tmp;
b = a - d;
flag = 0;
break;
}
else {
tmp++;
}
}
if (flag == 0) {
break;
}
}
cout << a << " " << b << endl;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue<string> qs;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) v.begin(), v.end()
// sort( all(v) ) などと使える
int main() {
ll x;
cin >> x;
ll aa, bb;
for (ll a = 0; a < 5000; a++)
for (ll b = -5000; b < 5000; b++) {
if (pow(a, 5) - pow(b, 5) == x) {
aa = a, bb = b;
break;
}
}
cout << aa << " " << bb << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue<string> qs;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) v.begin(), v.end()
// sort( all(v) ) などと使える
int main() {
ll x;
cin >> x;
ll aa, bb;
for (ll a = 0; a < 1000; a++)
for (ll b = -1000; b < 1000; b++) {
if (pow(a, 5) - pow(b, 5) == x) {
aa = a, bb = b;
break;
}
}
cout << aa << " " << bb << endl;
} | replace | 42 | 44 | 42 | 44 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
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;
}
// pow(llpow,modpow)
template <class T> ll llpow(ll x, T n) {
ll ans = 1;
if (x == 0)
ans = 0;
while (n) {
if (n & 1)
ans *= x;
x *= x;
n >>= 1;
}
return ans;
}
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;
}
// 最大公約数
template <class T> inline T gcd(T x, T y) {
if (y == 0)
return x;
else {
return gcd(y, x % y);
}
}
// 最小公倍数
template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
// 逆元
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
// 試験導入
#define irep(i, end_i, begin_i) \
for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--)
vll yakusu(ll x) {
vll ret;
for (ll i = 1; i * i <= x; i++) {
if (x % i == 0)
ret.push_back(i);
}
return ret;
}
long long INF = 1LL << 60;
int main() {
ll x;
cin >> x;
rep(a, 0, 1e9) {
ll f = x;
if (a)
f = x / a;
ll b = pow(f, 0.2);
if (llpow(a, 5) - llpow(b, 5) == x) {
cout << a << " " << b << endl;
return 0;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
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;
}
// pow(llpow,modpow)
template <class T> ll llpow(ll x, T n) {
ll ans = 1;
if (x == 0)
ans = 0;
while (n) {
if (n & 1)
ans *= x;
x *= x;
n >>= 1;
}
return ans;
}
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;
}
// 最大公約数
template <class T> inline T gcd(T x, T y) {
if (y == 0)
return x;
else {
return gcd(y, x % y);
}
}
// 最小公倍数
template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
// 逆元
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
// 試験導入
#define irep(i, end_i, begin_i) \
for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--)
vll yakusu(ll x) {
vll ret;
for (ll i = 1; i * i <= x; i++) {
if (x % i == 0)
ret.push_back(i);
}
return ret;
}
long long INF = 1LL << 60;
int main() {
ll x;
cin >> x;
rep(a, -120, 120) {
rep(b, -120, 120) {
if (llpow(a, 5) - llpow(b, 5) == x) {
cout << a << " " << b << endl;
return 0;
}
}
}
return 0;
}
| replace | 91 | 99 | 91 | 97 | TLE | |
p02690 | C++ | Runtime Error | /*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc166_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000
int main() {
ll x;
scanf("%lld", &x);
for (ll a = -100; a <= 100; a++) {
for (ll b = -100; b <= 100; b++) {
if (pow(a, 5) - pow(b, 5) == x) {
printf("%lld %lld\n", a, b);
return 0;
}
}
}
assert(false);
}
| /*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc166_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000
int main() {
ll x;
scanf("%lld", &x);
ll l = 2000;
for (ll a = 0; a <= l; a++) {
for (ll b = -l; b <= l; b++) {
if (pow(a, 5) - pow(b, 5) == x) {
printf("%lld %lld\n", a, b);
return 0;
}
}
}
assert(false);
}
| replace | 12 | 14 | 12 | 15 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
* For DEBUG
* https://github.com/ta7uw/cpp-pyprint
*/
#include "cpp-pyprint/pyprint.h"
#endif
ll f(ll a, ll b) {
return (a * a * a * a) + (a * a * a * b) + (a * a * b * b) + (a * b * b * b) +
(b * b * b * b);
}
vector<ll> divisor(ll N) {
vector<ll> res;
for (ll i = 1L; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
ll j = N / i;
if (j != i) {
res.push_back(j);
}
}
}
sort(res.begin(), res.end());
return res;
}
void solve() {
ll X;
cin >> X;
auto divisors = divisor(X);
for (ll d : divisors) {
ll ano = X / d;
rep2(a, -d, d + 1) {
ll b = a - d;
if (f(a, b) == ano) {
cout << a << " " << b << '\n';
return;
}
}
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
* For DEBUG
* https://github.com/ta7uw/cpp-pyprint
*/
#include "cpp-pyprint/pyprint.h"
#endif
ll f(ll a, ll b) {
return (a * a * a * a) + (a * a * a * b) + (a * a * b * b) + (a * b * b * b) +
(b * b * b * b);
}
vector<ll> divisor(ll N) {
vector<ll> res;
for (ll i = 1L; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
ll j = N / i;
if (j != i) {
res.push_back(j);
}
}
}
sort(res.begin(), res.end());
return res;
}
void solve() {
ll X;
cin >> X;
auto divisors = divisor(X);
for (ll d : divisors) {
ll ano = X / d;
rep2(a, -140, 140 + 1) {
ll b = a - d;
if (f(a, b) == ano) {
cout << a << " " << b << '\n';
return;
}
}
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
}
| replace | 52 | 53 | 52 | 53 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define pr(x) cout << x << endl;
#define pr2(x, y) cout << x << " " << y << endl;
#define pr3(x, y, z) cout << x << " " << y << endl;
#define prv(v) \
for (auto x : v) \
cout << x << " ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
const ll N = (2e5 + 5);
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238
long long binpow(long long a, long long b) {
a %= MOD;
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
res %= MOD;
return res;
}
void solve() {
ll x;
cin >> x;
for (ll a = -3000; a <= 3000; a++) {
for (ll b = -3000; b <= 3000; b++) {
// if(a==0||b==0)continue;
ll gg = pow(a, 5);
ll gg2 = pow(b, 5);
// cout<<a<<" "<<b<<" "<<gg<<" "<<gg2<<endl;
if ((gg - gg2) == x) {
// cout<<gg<<" "<<gg2<<endl;
cout << a << " " << b << endl;
return;
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll t = 1;
while (t--) {
solve();
}
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define pr(x) cout << x << endl;
#define pr2(x, y) cout << x << " " << y << endl;
#define pr3(x, y, z) cout << x << " " << y << endl;
#define prv(v) \
for (auto x : v) \
cout << x << " ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
const ll N = (2e5 + 5);
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238
long long binpow(long long a, long long b) {
a %= MOD;
long long res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
res %= MOD;
return res;
}
void solve() {
ll x;
cin >> x;
for (ll a = -1000; a <= 1000; a++) {
for (ll b = -1000; b <= 1000; b++) {
// if(a==0||b==0)continue;
ll gg = pow(a, 5);
ll gg2 = pow(b, 5);
// cout<<a<<" "<<b<<" "<<gg<<" "<<gg2<<endl;
if ((gg - gg2) == x) {
// cout<<gg<<" "<<gg2<<endl;
cout << a << " " << b << endl;
return;
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
ll t = 1;
while (t--) {
solve();
}
} | replace | 43 | 45 | 43 | 45 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
int main() {
ll x;
cin >> x;
for (ll a = -50000; a <= 50000; a++) {
for (ll b = 0; b <= 50000; b++) {
ll a5 = a * a * a * a * a;
ll b5 = b * b * b * b * b;
if (a5 - b5 == x) {
cout << fixed << a << " " << b << endl;
return 0;
}
}
}
cout << fixed << "no" << endl;
return 0;
} | #include <bits/stdc++.h>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
int main() {
ll x;
cin >> x;
for (ll a = 0; a <= 10000; a++) {
for (ll b = -10000; b <= 10000; b++) {
ll a5 = a * a * a * a * a;
ll b5 = b * b * b * b * b;
if (a5 - b5 == x) {
cout << fixed << a << " " << b << endl;
return 0;
}
}
}
cout << fixed << "no" << endl;
return 0;
} | replace | 14 | 16 | 14 | 16 | TLE | |
p02690 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int(i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template <typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
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;
}
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
LL X;
int main(void) {
cin >> X;
unordered_map<LL, LL> cand;
REP(i, INF) {
const auto tmp = 1LL * i * i * i * i * i;
if (tmp > LLINF) {
// DEBUG(tmp)
break;
}
cand[tmp] = i;
}
FORE(a, cand) {
const auto b = X - a.first;
if (cand.count(b)) {
cout << a.second << " " << -cand[b] << endl;
return 0;
}
}
assert(false);
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int(i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template <typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
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;
}
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
LL X;
int main(void) {
cin >> X;
unordered_map<LL, LL> cand;
REP(i, INF) {
const auto tmp = 1LL * i * i * i * i * i;
if (tmp > LLINF) {
// DEBUG(tmp)
break;
}
cand[tmp] = i;
cand[-tmp] = -i;
}
FORE(a, cand) {
const auto b = X - a.first;
if (cand.count(b)) {
cout << a.second << " " << -cand[b] << endl;
return 0;
}
}
assert(false);
}
| insert | 88 | 88 | 88 | 89 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;
const double pi = 3.1415;
ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); }
ll mini(ll a, ll b) { return (a > b ? b : a); }
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
return (a % b ? gcd(a % b, b) : b);
}
ll gojou(ll n) { return pow(n, 5); }
int main() {
ll x, ans1 = 0, ans2 = 0;
cin >> x;
bool f = false;
for (ll i = -50; i < 50; i++) {
for (ll j = -50; i < 50; j++) {
if (gojou(i) - gojou(j) == x) {
ans1 = i;
ans2 = j;
f = true;
}
if (f)
break;
}
if (f)
break;
}
cout << ans1 << " " << ans2;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;
const double pi = 3.1415;
ll absc(ll a, ll b) { return (a - b > 0 ? a - b : b - a); }
ll mini(ll a, ll b) { return (a > b ? b : a); }
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
return (a % b ? gcd(a % b, b) : b);
}
ll gojou(ll n) { return pow(n, 5); }
int main() {
ll x, ans1 = 0, ans2 = 0;
cin >> x;
bool f = false;
for (ll i = -200; i < 200; i++) {
for (ll j = -200; j < 200; j++) {
if (gojou(i) - gojou(j) == x) {
ans1 = i;
ans2 = j;
f = true;
}
if (f)
break;
}
if (f)
break;
}
cout << ans1 << " " << ans2;
}
| replace | 29 | 31 | 29 | 31 | TLE | |
p02690 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
template <class _T> inline void read(_T &_a) {
bool f = 0;
char _c = getchar();
_a = 0;
while (_c < '0' || _c > '9') {
if (_c == '-')
f = 1;
_c = getchar();
}
while (_c >= '0' && _c <= '9') {
_a = (_a << 3) + (_a << 1) - '0' + _c;
_c = getchar();
}
if (f)
_a = -_a;
}
const int MAXN = 1000002;
long long calc[71], n;
int main() {
read(n);
for (register long long i = 1; i <= 120; ++i)
calc[i] = (long long)pow(i, 5);
for (register int i = 0; i <= 120; ++i) {
for (register int j = 0; j <= 120; ++j) {
if (calc[i] - calc[j] == n) {
printf("%d %d", i, j);
return 0;
}
if (calc[i] + calc[j] == n) {
printf("%d %d", i, -j);
return 0;
}
if (-calc[i] - calc[j] == n) {
printf("%d %d", -i, j);
return 0;
}
}
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
template <class _T> inline void read(_T &_a) {
bool f = 0;
char _c = getchar();
_a = 0;
while (_c < '0' || _c > '9') {
if (_c == '-')
f = 1;
_c = getchar();
}
while (_c >= '0' && _c <= '9') {
_a = (_a << 3) + (_a << 1) - '0' + _c;
_c = getchar();
}
if (f)
_a = -_a;
}
const int MAXN = 1000002;
long long calc[1201], n;
int main() {
read(n);
for (register long long i = 1; i <= 120; ++i)
calc[i] = (long long)pow(i, 5);
for (register int i = 0; i <= 120; ++i) {
for (register int j = 0; j <= 120; ++j) {
if (calc[i] - calc[j] == n) {
printf("%d %d", i, j);
return 0;
}
if (calc[i] + calc[j] == n) {
printf("%d %d", i, -j);
return 0;
}
if (-calc[i] - calc[j] == n) {
printf("%d %d", -i, j);
return 0;
}
}
}
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define etm \
cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define vb vector<bool>
#define vvbb vector<vb>
#define vi vector<int>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvll vector<vector<ll>>
#define vvii vector<vector<int>>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define pqll priority_queue<ll>
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
#define input(a, n) \
ll I; \
rep(I, 0, n - 1, 1) cin >> a[I];
#define countbit __builtin_popcount // Number of set bits .
#define fbo(k) find_by_order // K-th element in a set (counting from zero) .
#define ook(k) order_of_key // Number of items strictly smaller than k .
#define lb lower_bound
#define up upper_bound
#define in insert
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
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...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll ceil(long double a) {
ll b = a;
if (a == b) {
return b;
} else {
return b + 1;
}
}
ll floor(long double a) {
ll b = a;
return b;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void sieve(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = 26) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
ll nCr(ll n, ll k) {
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
class DSU {
public:
vll parent, size;
public:
DSU(ll n) {
parent.resize(n + 1);
size.resize(n + 1);
for (ll i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
public:
ll find_set(ll x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find_set(parent[x]);
}
public:
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
parent[y] = x;
}
}
};
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.fi == p2.fi) {
return p1.se > p2.se;
}
return p1.fi > p2.fi;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
ll ToInt(char ch) { return ch - '0'; }
char ToChar(ll a) { return a + '0'; }
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void printVectorPair(vpll v) {
for (ll i = 0; i < v.size(); i++) {
cout << v[i].fi << " " << v[i].se << "\n";
}
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
mod = mod * 10 + digit;
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
struct SegmentTree {
ll n;
vll v;
SegmentTree(ll size) {
n = 4 * size + 1;
v.resize(n, 0);
}
void build(ll ar[], ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] = ar[ipos];
else {
ll mid = (ipos + fpos) / 2;
build(ar, ipos, mid, pos * 2);
build(ar, mid + 1, fpos, pos * 2 + 1);
v[pos] = v[pos * 2] + v[pos * 2 + 1];
}
}
void update(ll index, ll val, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] += val;
else {
v[pos] += val;
ll mid = (ipos + fpos) / 2;
if (mid >= index)
update(index, val, ipos, mid, pos * 2);
else
update(index, val, mid + 1, fpos, pos * 2 + 1);
}
}
ll get_sum(ll l, ll r, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return 0;
if (l > r)
return 0;
ll mid = (ipos + fpos) / 2;
if ((l == ipos) && (r == fpos))
return v[pos];
else
return get_sum(l, min(mid, r), ipos, mid, pos * 2) +
get_sum(max(mid + 1, l), r, mid + 1, fpos, pos * 2 + 1);
}
};
struct BIT {
vector<ll> bitree;
ll n;
BIT(ll n) {
this->n = n;
bitree.resize(n + 1, 0);
}
void update(ll idx, ll val) {
idx++;
while (idx <= n) {
bitree[idx] += val;
idx += idx & (-idx);
}
}
ll Sum(ll idx) {
ll sum = 0;
idx++;
while (idx > 0) {
sum += bitree[idx];
idx -= idx & (-idx);
}
return sum;
}
};
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
/*
ideas
*/
int main() {
fastio;
ll x;
cin >> x;
bool fnd = false;
rep(i, 0, 1e4, 1) {
rep(j, 0, 1e4, 1) {
if (pow(i, 5) + pow(j, 5) == x) {
cout << i << " " << -j << endl;
fnd = true;
break;
}
}
if (fnd)
break;
}
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define etm \
cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define vb vector<bool>
#define vvbb vector<vb>
#define vi vector<int>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvll vector<vector<ll>>
#define vvii vector<vector<int>>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define pqll priority_queue<ll>
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
#define input(a, n) \
ll I; \
rep(I, 0, n - 1, 1) cin >> a[I];
#define countbit __builtin_popcount // Number of set bits .
#define fbo(k) find_by_order // K-th element in a set (counting from zero) .
#define ook(k) order_of_key // Number of items strictly smaller than k .
#define lb lower_bound
#define up upper_bound
#define in insert
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
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...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll ceil(long double a) {
ll b = a;
if (a == b) {
return b;
} else {
return b + 1;
}
}
ll floor(long double a) {
ll b = a;
return b;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void sieve(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = 26) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
ll nCr(ll n, ll k) {
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
class DSU {
public:
vll parent, size;
public:
DSU(ll n) {
parent.resize(n + 1);
size.resize(n + 1);
for (ll i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
public:
ll find_set(ll x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find_set(parent[x]);
}
public:
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
parent[y] = x;
}
}
};
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.fi == p2.fi) {
return p1.se > p2.se;
}
return p1.fi > p2.fi;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
ll ToInt(char ch) { return ch - '0'; }
char ToChar(ll a) { return a + '0'; }
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void printVectorPair(vpll v) {
for (ll i = 0; i < v.size(); i++) {
cout << v[i].fi << " " << v[i].se << "\n";
}
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
mod = mod * 10 + digit;
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
struct SegmentTree {
ll n;
vll v;
SegmentTree(ll size) {
n = 4 * size + 1;
v.resize(n, 0);
}
void build(ll ar[], ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] = ar[ipos];
else {
ll mid = (ipos + fpos) / 2;
build(ar, ipos, mid, pos * 2);
build(ar, mid + 1, fpos, pos * 2 + 1);
v[pos] = v[pos * 2] + v[pos * 2 + 1];
}
}
void update(ll index, ll val, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] += val;
else {
v[pos] += val;
ll mid = (ipos + fpos) / 2;
if (mid >= index)
update(index, val, ipos, mid, pos * 2);
else
update(index, val, mid + 1, fpos, pos * 2 + 1);
}
}
ll get_sum(ll l, ll r, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return 0;
if (l > r)
return 0;
ll mid = (ipos + fpos) / 2;
if ((l == ipos) && (r == fpos))
return v[pos];
else
return get_sum(l, min(mid, r), ipos, mid, pos * 2) +
get_sum(max(mid + 1, l), r, mid + 1, fpos, pos * 2 + 1);
}
};
struct BIT {
vector<ll> bitree;
ll n;
BIT(ll n) {
this->n = n;
bitree.resize(n + 1, 0);
}
void update(ll idx, ll val) {
idx++;
while (idx <= n) {
bitree[idx] += val;
idx += idx & (-idx);
}
}
ll Sum(ll idx) {
ll sum = 0;
idx++;
while (idx > 0) {
sum += bitree[idx];
idx -= idx & (-idx);
}
return sum;
}
};
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
/*
ideas
*/
int main() {
fastio;
ll x;
cin >> x;
bool fnd = false;
rep(i, 0, 1e4, 1) {
rep(j, 0, 1e4, 1) {
if (pow(i, 5) + pow(j, 5) == x) {
cout << i << " " << -j << endl;
fnd = true;
break;
}
if (pow(i, 5) - pow(j, 5) == x) {
cout << i << " " << j << endl;
fnd = true;
break;
}
}
if (fnd)
break;
}
return 0;
}
| insert | 373 | 373 | 373 | 378 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define trace1(a) cout << #a << ": " << a << endl
#define trace2(a, b) cout << #a << ": " << a << " | ", trace1(b)
#define trace3(a, b, c) cout << #a << ": " << a << " | ", trace2(b, c)
#define trace4(a, b, c, d) cout << #a << ": " << a << " | ", trace3(b, c, d)
#define trace5(a, b, c, d, e) \
cout << #a << ": " << a << " | ", trace4(b, c, d, e)
#define trace6(a, b, c, d, e, f) \
cout << #a << ": " << a << " | ", trace5(b, c, d, e, f)
#define trace7(a, b, c, d, e, f, g) \
cout << #a << ": " << a << " | ", trace6(b, c, d, e, f, g)
#define trace8(a, b, c, d, e, f, g, h) \
cout << #a << ": " << a << " | ", trace7(b, c, d, e, f, g, h)
#define trace9(a, b, c, d, e, f, g, h, i) \
cout << #a << ": " << a << " | ", trace8(b, c, d, e, f, g, h, i)
#define trace10(a, b, c, d, e, f, g, h, i, j) \
cout << #a << ": " << a << " | ", trace9(b, c, d, e, f, g, h, i, j)
#define rep(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define reps(i, a, b, c) for (int(i) = (int)(a); (i) < (int)(b); (i) += (c))
#define rrep(i, a, b) for (int(i) = (int)(a); (i) >= (int)(b); --(i))
#define rreps(i, a, b, c) for (int(i) = (int)(a); (i) >= (int)(b); (i) -= (c))
#define fore(x, a) for (auto &x : a)
#define foreach(i, a) for (auto i = (a).begin(); i != (a).end(); ++i)
#define rforeach(i, a) for (auto i = (a).rbegin(); i != (a).rend(); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define isin(i, a, b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define dup(x, y) (((x) + (y)-1) / (y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vl = vector<ll>;
using unit = unsigned;
using vvi = vector<vi>;
using ull = unsigned long long;
using vvl = vector<vl>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using pil = pair<int, ll>;
using vpil = vector<pil>;
using pli = pair<ll, int>;
using vpli = vector<pli>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
template <class T> string join(const v(T) & v) {
stringstream s;
rep(i, 0, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <class T> istream &operator>>(istream &i, v(T) & v) {
fore(x, v) { i >> v; }
return i;
}
template <class T> ostream &operator<<(ostream &o, const v(T) & v) {
o << "[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << "deq[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const unordered_set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const unordered_multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T1, class T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const unordered_map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class T> void YES(T c) {
if (c)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> void Yes(T c) {
if (c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> void POSS(T c) {
if (c)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
}
template <class T> void Poss(T c) {
if (c)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
}
template <class T> bool chmax(T &a, const T &b) {
return a < b ? (a = b, true) : false;
}
template <class T> bool chmin(T &a, const T &b) {
return a > b ? (a = b, true) : false;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = 1001002003;
const ll LINF = 1001002003004005006LL;
const int DX[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 1, 0, -1, -1, 1, -1, 1};
void _main() {
ll X;
cin >> X;
for (ll a = -3000; a <= 3000; ++a) {
for (ll b = -3000; b <= 3000; ++b) {
if ((ll)pow(a, 5) - (ll)pow(b, 5) == X) {
cout << a << " " << b << " " << endl;
return;
}
}
}
cout << -1 << endl;
}
| #include <bits/stdc++.h>
#define trace1(a) cout << #a << ": " << a << endl
#define trace2(a, b) cout << #a << ": " << a << " | ", trace1(b)
#define trace3(a, b, c) cout << #a << ": " << a << " | ", trace2(b, c)
#define trace4(a, b, c, d) cout << #a << ": " << a << " | ", trace3(b, c, d)
#define trace5(a, b, c, d, e) \
cout << #a << ": " << a << " | ", trace4(b, c, d, e)
#define trace6(a, b, c, d, e, f) \
cout << #a << ": " << a << " | ", trace5(b, c, d, e, f)
#define trace7(a, b, c, d, e, f, g) \
cout << #a << ": " << a << " | ", trace6(b, c, d, e, f, g)
#define trace8(a, b, c, d, e, f, g, h) \
cout << #a << ": " << a << " | ", trace7(b, c, d, e, f, g, h)
#define trace9(a, b, c, d, e, f, g, h, i) \
cout << #a << ": " << a << " | ", trace8(b, c, d, e, f, g, h, i)
#define trace10(a, b, c, d, e, f, g, h, i, j) \
cout << #a << ": " << a << " | ", trace9(b, c, d, e, f, g, h, i, j)
#define rep(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define reps(i, a, b, c) for (int(i) = (int)(a); (i) < (int)(b); (i) += (c))
#define rrep(i, a, b) for (int(i) = (int)(a); (i) >= (int)(b); --(i))
#define rreps(i, a, b, c) for (int(i) = (int)(a); (i) >= (int)(b); (i) -= (c))
#define fore(x, a) for (auto &x : a)
#define foreach(i, a) for (auto i = (a).begin(); i != (a).end(); ++i)
#define rforeach(i, a) for (auto i = (a).rbegin(); i != (a).rend(); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define isin(i, a, b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define dup(x, y) (((x) + (y)-1) / (y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vl = vector<ll>;
using unit = unsigned;
using vvi = vector<vi>;
using ull = unsigned long long;
using vvl = vector<vl>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using pil = pair<int, ll>;
using vpil = vector<pil>;
using pli = pair<ll, int>;
using vpli = vector<pli>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
template <class T> string join(const v(T) & v) {
stringstream s;
rep(i, 0, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <class T> istream &operator>>(istream &i, v(T) & v) {
fore(x, v) { i >> v; }
return i;
}
template <class T> ostream &operator<<(ostream &o, const v(T) & v) {
o << "[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const deque<T> &v) {
o << "deq[";
fore(x, v) o << x << ",";
o << "]";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const unordered_set<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T>
ostream &operator<<(ostream &o, const unordered_multiset<T> &v) {
o << "{";
fore(x, v) o << x << ",";
o << "}";
return o;
}
template <class T1, class T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class TK, class TV>
ostream &operator<<(ostream &o, const unordered_map<TK, TV> &m) {
o << "{";
fore(x, m) o << x.fi << "=>" << x.se << ",";
o << "}";
return o;
}
template <class T> void YES(T c) {
if (c)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> void Yes(T c) {
if (c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> void POSS(T c) {
if (c)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
}
template <class T> void Poss(T c) {
if (c)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
}
template <class T> bool chmax(T &a, const T &b) {
return a < b ? (a = b, true) : false;
}
template <class T> bool chmin(T &a, const T &b) {
return a > b ? (a = b, true) : false;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = 1001002003;
const ll LINF = 1001002003004005006LL;
const int DX[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int DY[] = {0, 1, 0, -1, -1, 1, -1, 1};
void _main() {
ll X;
cin >> X;
unordered_map<ll, ll> m;
for (ll a = 0; a <= 6000; ++a) {
ll a5 = pow(a, 5);
m[a5] = a;
m[-a5] = -a;
ll b5 = a5 - X;
if (m.count(b5)) {
cout << a << " " << m[b5] << " " << endl;
return;
}
}
cout << -1 << endl;
}
| replace | 166 | 172 | 166 | 175 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ll n;
cin >> n;
for (ll a = -4000; a <= 4000; a++) {
for (ll b = -4000; b <= 4000; b++) {
if (pow(a, 5) - pow(b, 5) == n) {
cout << a << " " << b;
return 0;
}
}
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ll n;
cin >> n;
for (ll a = -1000; a <= 1000; a++) {
for (ll b = -1000; b <= 1000; b++) {
if (pow(a, 5) - pow(b, 5) == n) {
cout << a << " " << b;
return 0;
}
}
}
} | replace | 16 | 18 | 16 | 18 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int64_t pow(int64_t n, int64_t r) {
int ret = 1;
for (int i = 0; i < r; i++) {
ret *= n;
}
return n;
}
int main(void) {
int64_t X;
cin >> X;
for (int i = 6208; i > -6208; i--) {
for (int j = 6208; j > -6208; j--) {
if ((pow(i, 5) - pow(j, 5)) == X) {
cout << i << " " << j << "\n";
return 0;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int64_t pow(int64_t n, int64_t r) {
int ret = 1;
for (int i = 0; i < r; i++) {
ret *= n;
}
return n;
}
int main(void) {
int64_t X;
cin >> X;
for (int i = 1000; i > -1000; i--) {
for (int j = 1000; j > -1000; j--) {
if ((pow(i, 5) - pow(j, 5)) == X) {
cout << i << " " << j << "\n";
return 0;
}
}
}
return 0;
}
| replace | 15 | 17 | 15 | 17 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int long long
#define rep(i, l, r) for (register int i = l; i <= r; ++i)
int MAXN = 100010;
inline int read() {
register char cc = getchar();
register int cn(0), flus(1);
while (cc > '9' || cc < '0') {
if (cc == '-')
flus = -flus;
cc = getchar();
}
while (cc >= '0' && cc <= '9') {
cn = cn * 10 + cc - 48;
cc = getchar();
}
return cn * flus;
}
signed main() {
int x = read();
for (register int i = -100;; ++i) {
for (register int j = -100; j <= 100; ++j) {
// printf("i = %d j = %d \n",i,j);
if (i * i * i * i * i - j * j * j * j * j == x) {
printf("%lld %lld \n", i, j);
return 0;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define rep(i, l, r) for (register int i = l; i <= r; ++i)
int MAXN = 100010;
inline int read() {
register char cc = getchar();
register int cn(0), flus(1);
while (cc > '9' || cc < '0') {
if (cc == '-')
flus = -flus;
cc = getchar();
}
while (cc >= '0' && cc <= '9') {
cn = cn * 10 + cc - 48;
cc = getchar();
}
return cn * flus;
}
signed main() {
int x = read();
for (register int i = -1000;; ++i) {
for (register int j = -1000; j <= 1000; ++j) {
// printf("i = %d j = %d \n",i,j);
if (i * i * i * i * i - j * j * j * j * j == x) {
printf("%lld %lld \n", i, j);
return 0;
}
}
}
return 0;
}
| replace | 20 | 22 | 20 | 22 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
using namespace std;
int main() {
long x, a, b;
long aa, bb;
long i, j, k;
cin >> x;
for (i = 1; i * i <= x; i++) {
if (x % i == 0) {
aa = 0;
bb = 0;
for (a = 0; a <= x; a++) {
aa = pow(a, 5);
bb = pow(a - i, 5);
if (a - i <= -100000)
continue;
if (aa - bb == x) {
cout << a << " " << a - i << endl;
return 0;
}
}
aa = 0;
bb = 0;
if (x % i == 0)
j = x / i;
for (a = 0; a <= x; a++) {
aa = pow(a, 5);
bb = pow(a - j, 5);
if (a - j <= -100000)
continue;
if (aa - bb == x) {
cout << a << " " << a - j << endl;
return 0;
}
}
}
}
return 0;
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
long x, a, b;
long aa, bb;
long i, j, k;
cin >> x;
for (a = -120; a <= 120; a++) {
for (b = -120; b <= 120; b++) {
aa = pow(a, 5);
bb = pow(b, 5);
if (aa - bb == x) {
cout << a << " " << b << endl;
return 0;
}
}
}
return 0;
}
| replace | 9 | 37 | 9 | 16 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
/*
string s;
cin>>s;
if(s=="ABC")
{
cout<<"ARC"<<endl;
}
else
{
cout<<"ABC"<<endl;
}
*/
/*
int n,k;
cin>>n>>k;
map <int,int> mp;
for(int i=1;i<=k;i++)
{
int d;
cin>>d;
for(int j=1;j<=d;j++)
{
int a;
cin>>a;
mp[a]++;
}
}
int count=0;
for(int i=1;i<=n;i++)
{
if(mp[i]==0)
{
count++;
}
}
cout<<count<<endl;
*/
/*
int n,m;
cin>>n>>m;
vector <pair<bool,ll>> h(n+1); //良いか悪いか、標高
for(int i=1;i<=n;i++)
{
int height;
cin>>height;
h[i].first=true;
h[i].second=height;
}
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
if(h[a].second<=h[b].second)
{
h[a].first = false;
}
if(h[a].second>=h[b].second)
{
h[b].first=false;
}
}
int count=0;
for(int i=1;i<=n;i++)
{
if(h[i].first)
{
count++;
}
}
cout<<count<<endl;
*/
ll x;
cin >> x;
for (ll i = 1; i <= x; i++) {
if (x % i == 0) {
ll temp = x;
temp = x / i;
for (ll j = 0; j <= i; j++) {
ll a = j;
ll b = j - i;
if ((pow(a, 4) + pow(a, 3) * b + pow(a, 2) * pow(b, 2) + a * pow(b, 3) +
pow(b, 4)) == temp) {
cout << a << " " << b << endl;
return 0;
}
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
/*
string s;
cin>>s;
if(s=="ABC")
{
cout<<"ARC"<<endl;
}
else
{
cout<<"ABC"<<endl;
}
*/
/*
int n,k;
cin>>n>>k;
map <int,int> mp;
for(int i=1;i<=k;i++)
{
int d;
cin>>d;
for(int j=1;j<=d;j++)
{
int a;
cin>>a;
mp[a]++;
}
}
int count=0;
for(int i=1;i<=n;i++)
{
if(mp[i]==0)
{
count++;
}
}
cout<<count<<endl;
*/
/*
int n,m;
cin>>n>>m;
vector <pair<bool,ll>> h(n+1); //良いか悪いか、標高
for(int i=1;i<=n;i++)
{
int height;
cin>>height;
h[i].first=true;
h[i].second=height;
}
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
if(h[a].second<=h[b].second)
{
h[a].first = false;
}
if(h[a].second>=h[b].second)
{
h[b].first=false;
}
}
int count=0;
for(int i=1;i<=n;i++)
{
if(h[i].first)
{
count++;
}
}
cout<<count<<endl;
*/
ll A, B, X;
cin >> X;
for (ll i = -1000; i < 1000; i++) {
for (ll j = -1000; j < 1000; j++) {
if (i * i * i * i * i - j * j * j * j * j == X) {
cout << i << " " << j << endl;
return 0;
}
}
}
return 0;
} | replace | 83 | 97 | 83 | 90 | TLE | |
p02690 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int mod = 1e9 + 107;
const int inf = 1e8;
int h[N];
int mx[N];
void solve() {
ll x;
cin >> x;
for (ll i = 1; i * i <= x; i++) {
if (x % i == 0) {
for (ll j = -i; j <= i; j++) {
ll b = j;
ll a = i + j;
ll trt = a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b +
b * b * b * b;
// cout<<i<<" "<<a<<" "<<b<<" "<<a-b<<" "<<trt<<"
// "<<trt*(a-b)<<endl;
if (trt == x / i) {
cout << a << " " << b << endl;
return;
}
}
}
}
exit(-1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5 + 6;
const int mod = 1e9 + 107;
const int inf = 1e8;
int h[N];
int mx[N];
void solve() {
ll x;
cin >> x;
for (ll i = 1; i * i <= x; i++) {
if (x % i == 0) {
for (ll j = -300; j <= 300; j++) {
ll b = j;
ll a = i + j;
ll trt = a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b +
b * b * b * b;
// cout<<i<<" "<<a<<" "<<b<<" "<<a-b<<" "<<trt<<"
// "<<trt*(a-b)<<endl;
if (trt == x / i) {
cout << a << " " << b << endl;
return;
}
}
}
}
exit(-1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int X;
cin >> X;
long long int A = 0, B = 0;
if (X == 1) {
cout << 1 << " " << 0 << endl;
} else {
int f = 0;
for (int i = 10000; i >= -10000; --i) {
for (int j = 9999; j >= -10000; --j) {
A = pow(i, 5);
B = pow(j, 5);
if ((A - B) == X || (A + B == X)) {
f = 1;
if (A - B == X) {
A = i;
B = j;
} else {
A = i;
B = -j;
}
break;
}
}
if (f == 1) {
break;
}
}
cout << A << " " << B << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int X;
cin >> X;
long long int A = 0, B = 0;
if (X == 1) {
cout << 1 << " " << 0 << endl;
} else {
int f = 0;
for (int i = 1000; i >= -1000; --i) {
for (int j = 999; j >= -1000; --j) {
A = pow(i, 5);
B = pow(j, 5);
if ((A - B) == X || (A + B == X)) {
f = 1;
if (A - B == X) {
A = i;
B = j;
} else {
A = i;
B = -j;
}
break;
}
}
if (f == 1) {
break;
}
}
cout << A << " " << B << endl;
}
} | replace | 13 | 15 | 13 | 15 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;
int main() {
int x;
std::cin >> x;
for (ll i = -10000; i <= 10000; i++) {
for (ll j = 10000; j >= -10000; j--) {
ll a = pow(i, 5), b = pow(j, 5);
if (a - b == (ll)x) {
std::cout << i << ' ' << j << '\n';
return 0;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;
int main() {
int x;
std::cin >> x;
for (ll i = -1000; i <= 1000; i++) {
for (ll j = 1000; j >= -1000; j--) {
ll a = pow(i, 5), b = pow(j, 5);
if (a - b == (ll)x) {
std::cout << i << ' ' << j << '\n';
return 0;
}
}
}
return 0;
}
| replace | 9 | 11 | 9 | 11 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
for (int i = 1; i <= 10000; i++)
for (int j = 0; j <= i; j++) {
if (pow(i, 5) + pow(j, 5) == x) {
printf("%d %d", i, -j);
return 0;
}
}
} | #include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
for (int i = 1; i <= 1000; i++)
for (int j = -1000; j <= i; j++) {
if (pow(i, 5) + pow(j, 5) == x) {
printf("%d %d", i, -j);
return 0;
}
}
} | replace | 7 | 9 | 7 | 9 | TLE | |
p02690 | C++ | Runtime Error | #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) \
for (auto &x : v) \
cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)
#define int ll
using namespace std;
#ifdef __LOCAL
#define dbg(x) cerr << #x << " : " << x << '\n'
const int maxn = 20;
#else
#define dbg(x)
const int maxn = 2e5 + 20;
#endif
// tg: @galebickosikasa
const ll inf = (ll)2e9;
const ld pi = asin(1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int BS(int x) {
int l = -5300, r = 5300;
while (r - l > 1) {
int m = (r + l) / 2;
if (m * m * m * m * m >= x)
r = m;
else
l = m;
}
return r;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int x;
cin >> x;
for (int i = -5300; i <= 5300; ++i) {
int a = i * i * i * i * i;
int b = a - x;
int t = BS(b);
if (t * t * t * t * t == b) {
cout << i << ' ' << t;
break;
}
}
exit(1);
} | #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) \
for (auto &x : v) \
cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)
#define int ll
using namespace std;
#ifdef __LOCAL
#define dbg(x) cerr << #x << " : " << x << '\n'
const int maxn = 20;
#else
#define dbg(x)
const int maxn = 2e5 + 20;
#endif
// tg: @galebickosikasa
const ll inf = (ll)2e9;
const ld pi = asin(1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int BS(int x) {
int l = -5300, r = 5300;
while (r - l > 1) {
int m = (r + l) / 2;
if (m * m * m * m * m >= x)
r = m;
else
l = m;
}
return r;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int x;
cin >> x;
for (int i = -5300; i <= 5300; ++i) {
int a = i * i * i * i * i;
int b = a - x;
int t = BS(b);
if (t * t * t * t * t == b) {
cout << i << ' ' << t;
exit(0);
}
}
exit(1);
} | replace | 82 | 83 | 82 | 83 | 1 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define all(n) n.begin(), n.end()
#define yn(x) cout << (x ? "Yes" : "No") << endl;
ll gozyou(ll n) {
ll a = 1;
rep1(i, 5) a *= n;
return a;
}
int main() {
ll x, a, b;
cin >> x;
rep(i, 1000) rep1(k, x) {
if (x % k == 0 && gozyou(i) - gozyou(i - x / k) == x) {
a = i;
b = i - x / k;
break;
}
}
cout << a << " " << b << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define all(n) n.begin(), n.end()
#define yn(x) cout << (x ? "Yes" : "No") << endl;
ll gozyou(ll n) {
ll a = 1;
rep1(i, 5) a *= n;
return a;
}
int main() {
ll x, a, b;
cin >> x;
for (ll i = -199; i < 200; i++) {
for (ll k = -199; k < 200; k++) {
if (gozyou(i) - gozyou(k) == x) {
a = i;
b = k;
break;
}
}
}
cout << a << " " << b << endl;
return 0;
}
| replace | 17 | 22 | 17 | 25 | TLE | |
p02690 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
i64 p5(i64 x) { return x * x * x * x * x; }
int main(void) {
i64 x;
cin >> x;
vi P5(68);
for (i64 i = 1; i < 68; i++)
P5[i] = p5(i);
for (i64 a = 1; true; a++) {
i64 a5 = P5[a];
for (i64 b = -a; b < a; b++) {
i64 b5 = (b < 0 ? -P5[-b] : P5[b]);
if (a5 - b5 == x) {
cout << a << ' ' << b << '\n';
return 0;
}
}
}
return 0;
} | #define _GLIBCXX_DEBUG
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
i64 p5(i64 x) { return x * x * x * x * x; }
int main(void) {
i64 x;
cin >> x;
vi P5(120);
for (i64 i = 1; i < 120; i++)
P5[i] = p5(i);
for (i64 a = 1; true; a++) {
i64 a5 = P5[a];
for (i64 b = -a; b < a; b++) {
i64 b5 = (b < 0 ? -P5[-b] : P5[b]);
if (a5 - b5 == x) {
cout << a << ' ' << b << '\n';
return 0;
}
}
}
return 0;
} | replace | 12 | 14 | 12 | 14 | 0 | |
p02690 | C++ | Time Limit Exceeded | #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>;
ll f(ll A, ll B) { return A * A * A * A * A - B * B * B * B * B; }
int main() {
ll x;
cin >> x;
map<ll, P> mp;
for (ll A = -1000; A <= 1000; A++) {
for (ll B = -1000; B <= 1000; B++) {
mp[f(A, B)] = (P){A, B};
}
}
printf("%d %d\n", mp[x].first, mp[x].second);
}
| #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>;
ll f(ll A, ll B) { return A * A * A * A * A - B * B * B * B * B; }
int main() {
ll x;
cin >> x;
map<ll, P> mp;
for (ll A = -500; A <= 500; A++) {
for (ll B = -500; B <= 500; B++) {
mp[f(A, B)] = (P){A, B};
}
}
printf("%d %d\n", mp[x].first, mp[x].second);
}
| replace | 10 | 12 | 10 | 12 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long X, A, B;
cin >> X;
for (A = 0; A <= 100000; A++) {
for (B = -A; B <= 0; B++) {
if (pow(A, 5) - pow(B, 5) == X) {
cout << A << " " << B << endl;
return 0;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long X, A, B;
cin >> X;
for (A = -150; A <= 150; A++) {
for (B = -150; B <= 150; B++) {
if (pow(A, 5) - pow(B, 5) == X) {
cout << A << " " << B << endl;
return 0;
}
}
}
}
| replace | 9 | 11 | 9 | 11 | TLE | |
p02690 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char, int> mpci;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, p, n) for (int i = p; i <= n; i++)
#define ford(i, p, n) for (int i = n; i >= p; i--)
#define foreach(i, c) \
for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); ++i)
#define zero(a) memset(a, 0, sizeof(a))
#define number(a, num) memeset(a, num, sizeof(a))
#define INF 1e9
/*=====================================================================*/
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void write(long long x) {
static long long sta[35];
long long top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48);
puts("");
}
void finish(string s) {
cout << s << endl;
exit(0);
}
string int_to_string(int n) {
string s = "";
while (n) {
int now = n % 10;
s += now + '0';
n /= 10;
}
reverse(s.begin(), s.end());
return s;
}
int string_to_int(string s) {
int n = 0;
rep(i, s.size()) {
n *= 10;
n += s[i] - '0';
}
return n;
}
/*======================================================================*/
ll lcm(int a, int b) { return a / __gcd(a, b) * b; }
bool prime(int n) {
if (n == 0 || n == 1)
return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const ll power(int n, int k) {
ll t = 1;
rep(i, k) t *= n;
return t;
}
const string turn2(int n) {
string s = "";
while (n != 0) {
s += (char)(n % 2 + '0');
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
string turn(int n, int k) {
string s = "";
while (n) {
s += (char)(n % k + '0');
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
const string turn16(int n) {
string s = "";
while (n != 0) {
if (n % 16 > 9)
s += (char)('A' + n % 16 - 10);
else
s += (char)('0' + n % 16);
n /= 16;
}
reverse(s.begin(), s.end());
return s;
}
const ll quickpower(int n, int k) {
if (k == 1)
return n;
if (k % 2 == 1)
return n * quickpower(n, k / 2) * quickpower(n, k / 2);
else
return quickpower(n, k / 2) * (quickpower(n, k / 2));
}
/*
void merge(int a[],int left,int mid,int right)
{
int n1=mid-left;
int n2=right-mid;
for(int i=0;i<n1;i++)
{
l[i]=a[i+left];
}
for(int i=0;i<n2;i++)
{
r[i]=a[mid+i];
}
r[n2]=l[n1]=INF;
int i=0;
int j=0;
for(int k=left;k<right;k++)
{
if(l[i]<=r[j])
{
a[k]=l[i++];
}
else
{
a[k]=r[j++];
}
}
}
void mergesort(int a[],int left,int right)
{
if(left+1<right)
{
int mid=(left+right)/2;
mergesort(a,left,mid);
mergesort(a,mid,right);
merge(a,left,mid,right);
}
}
int binsearch(int x,int v[],int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else
if(x>v[mid])
low=mid+1;
else
return mid+1;
}
return -1;
}
int partition(int a[],int left,int right)
{
int p=a[left];
int i=left;
int j=right+1;
for(;;)
{
while(a[++i]<p)
if(i>=right)
break;
while(a[j--]>p)
if(j<=left)
break;
if(i>=j)
break;
else
swap(a[i],a[j]);
}
if(j>=left)
return j;
swap(a[left],a[j]);
return j;
}
void quicksort(int a[],int left,int right)
{
int q;
while(right>left)
{
q=partition(a,left,right);
if(n-q+1==k)
{
cout<<a[q];
exit(0);
}
quicksort(a,left,q-1);
quicksort(a,q+1,right);
}
}
void dfs(int n)
{
if(use[n])
return;
use[n]=true;
cout<<n<<endl;
for(int i=0;i<v[n].size();i++)
dfs(v[n][i]);
}*/
/*======================================================================*/
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int month[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
ll doit[600];
/*======================================================================*/
int main() {
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int x;
cin >> x;
for (ll i = (-300); i <= 300; i++) {
doit[i + 300] = (i * i * i * i * i);
}
rep(i, 601) {
rep(j, 601) {
if (doit[i] - doit[j] == x) {
cout << i - 300 << " " << j - 300 << endl;
return 0;
}
}
}
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char, int> mpci;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, p, n) for (int i = p; i <= n; i++)
#define ford(i, p, n) for (int i = n; i >= p; i--)
#define foreach(i, c) \
for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); ++i)
#define zero(a) memset(a, 0, sizeof(a))
#define number(a, num) memeset(a, num, sizeof(a))
#define INF 1e9
/*=====================================================================*/
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void write(long long x) {
static long long sta[35];
long long top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48);
puts("");
}
void finish(string s) {
cout << s << endl;
exit(0);
}
string int_to_string(int n) {
string s = "";
while (n) {
int now = n % 10;
s += now + '0';
n /= 10;
}
reverse(s.begin(), s.end());
return s;
}
int string_to_int(string s) {
int n = 0;
rep(i, s.size()) {
n *= 10;
n += s[i] - '0';
}
return n;
}
/*======================================================================*/
ll lcm(int a, int b) { return a / __gcd(a, b) * b; }
bool prime(int n) {
if (n == 0 || n == 1)
return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const ll power(int n, int k) {
ll t = 1;
rep(i, k) t *= n;
return t;
}
const string turn2(int n) {
string s = "";
while (n != 0) {
s += (char)(n % 2 + '0');
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
string turn(int n, int k) {
string s = "";
while (n) {
s += (char)(n % k + '0');
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
const string turn16(int n) {
string s = "";
while (n != 0) {
if (n % 16 > 9)
s += (char)('A' + n % 16 - 10);
else
s += (char)('0' + n % 16);
n /= 16;
}
reverse(s.begin(), s.end());
return s;
}
const ll quickpower(int n, int k) {
if (k == 1)
return n;
if (k % 2 == 1)
return n * quickpower(n, k / 2) * quickpower(n, k / 2);
else
return quickpower(n, k / 2) * (quickpower(n, k / 2));
}
/*
void merge(int a[],int left,int mid,int right)
{
int n1=mid-left;
int n2=right-mid;
for(int i=0;i<n1;i++)
{
l[i]=a[i+left];
}
for(int i=0;i<n2;i++)
{
r[i]=a[mid+i];
}
r[n2]=l[n1]=INF;
int i=0;
int j=0;
for(int k=left;k<right;k++)
{
if(l[i]<=r[j])
{
a[k]=l[i++];
}
else
{
a[k]=r[j++];
}
}
}
void mergesort(int a[],int left,int right)
{
if(left+1<right)
{
int mid=(left+right)/2;
mergesort(a,left,mid);
mergesort(a,mid,right);
merge(a,left,mid,right);
}
}
int binsearch(int x,int v[],int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else
if(x>v[mid])
low=mid+1;
else
return mid+1;
}
return -1;
}
int partition(int a[],int left,int right)
{
int p=a[left];
int i=left;
int j=right+1;
for(;;)
{
while(a[++i]<p)
if(i>=right)
break;
while(a[j--]>p)
if(j<=left)
break;
if(i>=j)
break;
else
swap(a[i],a[j]);
}
if(j>=left)
return j;
swap(a[left],a[j]);
return j;
}
void quicksort(int a[],int left,int right)
{
int q;
while(right>left)
{
q=partition(a,left,right);
if(n-q+1==k)
{
cout<<a[q];
exit(0);
}
quicksort(a,left,q-1);
quicksort(a,q+1,right);
}
}
void dfs(int n)
{
if(use[n])
return;
use[n]=true;
cout<<n<<endl;
for(int i=0;i<v[n].size();i++)
dfs(v[n][i]);
}*/
/*======================================================================*/
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int month[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
ll doit[700];
/*======================================================================*/
int main() {
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int x;
cin >> x;
for (ll i = (-300); i <= 300; i++) {
doit[i + 300] = (i * i * i * i * i);
}
rep(i, 601) {
rep(j, 601) {
if (doit[i] - doit[j] == x) {
cout << i - 300 << " " << j - 300 << endl;
return 0;
}
}
}
return 0;
}
| replace | 279 | 280 | 279 | 280 | 0 | |
p02690 | 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;
int n, x, m, a, b, c, k;
int main() {
for (cin >> x, a = -118; a < 120; a++) {
ll a5 = pow(a, 5);
for (b = -119; b < 119; b++) {
ll b5 = pow(b, 5);
if (a5 - b5 == x)
return printf("%d %d", a, b);
}
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int n, x, m, a, b, c, k;
int main() {
for (cin >> x, a = -118; a < 120; a++) {
ll a5 = pow(a, 5);
for (b = -119; b < 119; b++) {
ll b5 = pow(b, 5);
if (a5 - b5 == x) {
printf("%d %d", a, b);
return 0;
}
}
}
} | replace | 10 | 12 | 10 | 14 | 4 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int X;
cin >> X;
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
if (i * i * i * i * i + j * j * j * j * j == X) {
cout << i << ' ' << 0 - j << endl;
return 0;
}
for (int i = 1;; i++) {
for (int j = 1; j >= 0; j--) {
if (i * i * i * i * i - j * j * j * j * j == X) {
cout << i << ' ' << j << endl;
return 0;
}
if (i * i * i * i * i - j * j * j * j * j >= X)
break;
}
}
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int X;
cin >> X;
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
if (i * i * i * i * i + j * j * j * j * j == X) {
cout << i << ' ' << 0 - j << endl;
return 0;
}
for (int i = 1;; i++) {
for (int j = i; j >= 0; j--) {
if (i * i * i * i * i - j * j * j * j * j == X) {
cout << i << ' ' << j << endl;
return 0;
}
if (i * i * i * i * i - j * j * j * j * j >= X)
break;
}
}
} | replace | 13 | 14 | 13 | 14 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <iostream>
#ifdef MBP
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define REP(i, n) for (long long int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (long long int i = 1, i##_len = (n); i <= i##_len; ++i)
#define REP_R(i, n) for (long long int i = (n - 1); i >= 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((long long int)(x).size())
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// #define DEBUG
#ifdef DEBUG
#define OUT(x) std::cout << (x) << std::endl
#define OUT2(x, y) std::cout << (x) << "," << (y) << std::endl
#define OUT3(x, y, z) std::cout << (x) << "," << (y) << "," << (z) << std::endl
#define OUTSP(x) std::cout << (x) << " ";
#define OUTLF std::cout << std::endl
#define OUTPA(p) OUT2(p.first, p.second)
#else
#define OUT(x) NULL
#define OUT2(x, y) NULL
#define OUT3(x, y, z) NULL
#define OUTPA(p) NULL
#define OUTSP(p) NULL
#define OUTLF NULL
#endif
#define INF INT_MAX
#define INFLL LLONG_MAX
#define PB push_back
#define MOD 1000000007LL
#define LSB(x) __builtin_ctzll(x)
#define MSB(x) 64LL - __builtin_clzll(x) - 1LL
#define MSBINT(x) 32LL - __builtin_clz(x)
#define BITCNT(x) __builtin_popcountll(x)
using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using vec = vector<ll>;
using mat = vector<vector<ll>>;
using pa = pair<ll, ll>;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>;
template <class T> inline void input(T &arr) {
ll n = arr.size();
REP(i, n)
cin >> arr[i];
}
template <class T> inline void input2(T &arr1, T &arr2) {
ll n = arr1.size();
REP(i, n)
cin >> arr1[i] >> arr2[i];
}
template <class T> inline void inputPA(T &arr) {
ll n = arr.size();
REP(i, n)
cin >> arr[i].first >> arr[i].second;
}
template <class T> inline void outArr(T &arr) {
for (auto x : arr) {
OUTSP(x);
}
OUTLF;
}
template <class T> using PQ = priority_queue<T>;
template <class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
template <class T> bool chmax(T &, const T &);
template <class T> bool chmin(T &, const T &);
ll qp(ll a, ll b);
ll qp(ll a, ll b, ll mo);
ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void init_fact();
ll combination(ll, ll);
#define FACSIZE 200002LL
ll invfac[FACSIZE];
ll fac[FACSIZE];
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
ll f(ll a, ll b) { return pow(a, 5) - pow(b, 5); }
int main(void) {
ll x;
cin >> x;
ll num = 3000;
for (ll a = -num; a <= num; a++) {
for (ll b = -num; b <= num; b++) {
if (pow(a, 5) - pow(b, 5) == x) {
cout << a << " " << b << endl;
return 0;
}
}
}
return 0;
}
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 (b < a) {
a = b;
return 1;
}
return 0;
}
ll qp(ll a, ll b) {
ll ans = 1LL;
do {
if (b & 1LL)
ans = 1LL * mod_mul(ans, a) % MOD;
a = 1LL * mod_mul(a, a) % MOD;
} while (b >>= 1LL);
return ans;
}
ll qp(ll a, ll b, ll mo) {
ll ans = 1LL;
do {
if (b & 1LL)
ans = 1LL * (ans % mo) * (a % mo);
a = 1LL * (a % mo) * (a % mo);
} while (b >>= 1LL);
return ans;
}
ll mod_pow(ll x, ll r) {
if (r == 0)
return 1;
else if (r == 1)
return x % MOD;
else if (r % 2 == 0) {
ll t = mod_pow(x, r / 2) % MOD;
return t * t % MOD;
} else {
ll t = mod_pow(x, r / 2) % MOD;
ll k = t * t % MOD;
return k * x % MOD;
}
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_mul(ll a, ll b) { return (a * b) % MOD; }
ll mod_div(ll a, ll b) { return mod_mul(a, mod_pow(b, MOD - 2)); }
void make_fact(ll n) {
fac[0] = 1;
REP(i, n) { fac[i + 1] = mod_mul(fac[i], i + 1); }
}
void make_invfact(ll n) {
invfac[n] = mod_pow(fac[n], MOD - 2);
REP_R(i, n) { invfac[i] = mod_mul(invfac[i + 1], i + 1); }
}
void init_fact() {
make_fact(FACSIZE - 1);
make_invfact(FACSIZE - 1);
}
ll combination(ll n, ll c) {
return mod_mul(fac[n], mod_mul(invfac[c], invfac[n - c]));
}
///////////////fact
/*
init_fact();
cout << fac[5] << endl;
cout << invfac[5] << endl;
cout << combination(8, 4) << endl;
cout << combination(31, 8) << endl;
//*/
///////////////////
| #include <iostream>
#ifdef MBP
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define REP(i, n) for (long long int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (long long int i = 1, i##_len = (n); i <= i##_len; ++i)
#define REP_R(i, n) for (long long int i = (n - 1); i >= 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((long long int)(x).size())
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// #define DEBUG
#ifdef DEBUG
#define OUT(x) std::cout << (x) << std::endl
#define OUT2(x, y) std::cout << (x) << "," << (y) << std::endl
#define OUT3(x, y, z) std::cout << (x) << "," << (y) << "," << (z) << std::endl
#define OUTSP(x) std::cout << (x) << " ";
#define OUTLF std::cout << std::endl
#define OUTPA(p) OUT2(p.first, p.second)
#else
#define OUT(x) NULL
#define OUT2(x, y) NULL
#define OUT3(x, y, z) NULL
#define OUTPA(p) NULL
#define OUTSP(p) NULL
#define OUTLF NULL
#endif
#define INF INT_MAX
#define INFLL LLONG_MAX
#define PB push_back
#define MOD 1000000007LL
#define LSB(x) __builtin_ctzll(x)
#define MSB(x) 64LL - __builtin_clzll(x) - 1LL
#define MSBINT(x) 32LL - __builtin_clz(x)
#define BITCNT(x) __builtin_popcountll(x)
using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using vec = vector<ll>;
using mat = vector<vector<ll>>;
using pa = pair<ll, ll>;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>;
template <class T> inline void input(T &arr) {
ll n = arr.size();
REP(i, n)
cin >> arr[i];
}
template <class T> inline void input2(T &arr1, T &arr2) {
ll n = arr1.size();
REP(i, n)
cin >> arr1[i] >> arr2[i];
}
template <class T> inline void inputPA(T &arr) {
ll n = arr.size();
REP(i, n)
cin >> arr[i].first >> arr[i].second;
}
template <class T> inline void outArr(T &arr) {
for (auto x : arr) {
OUTSP(x);
}
OUTLF;
}
template <class T> using PQ = priority_queue<T>;
template <class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
template <class T> bool chmax(T &, const T &);
template <class T> bool chmin(T &, const T &);
ll qp(ll a, ll b);
ll qp(ll a, ll b, ll mo);
ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void init_fact();
ll combination(ll, ll);
#define FACSIZE 200002LL
ll invfac[FACSIZE];
ll fac[FACSIZE];
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
ll f(ll a, ll b) { return pow(a, 5) - pow(b, 5); }
int main(void) {
ll x;
cin >> x;
ll num = 1000;
for (ll a = -num; a <= num; a++) {
for (ll b = -num; b <= num; b++) {
if (pow(a, 5) - pow(b, 5) == x) {
cout << a << " " << b << endl;
return 0;
}
}
}
return 0;
}
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 (b < a) {
a = b;
return 1;
}
return 0;
}
ll qp(ll a, ll b) {
ll ans = 1LL;
do {
if (b & 1LL)
ans = 1LL * mod_mul(ans, a) % MOD;
a = 1LL * mod_mul(a, a) % MOD;
} while (b >>= 1LL);
return ans;
}
ll qp(ll a, ll b, ll mo) {
ll ans = 1LL;
do {
if (b & 1LL)
ans = 1LL * (ans % mo) * (a % mo);
a = 1LL * (a % mo) * (a % mo);
} while (b >>= 1LL);
return ans;
}
ll mod_pow(ll x, ll r) {
if (r == 0)
return 1;
else if (r == 1)
return x % MOD;
else if (r % 2 == 0) {
ll t = mod_pow(x, r / 2) % MOD;
return t * t % MOD;
} else {
ll t = mod_pow(x, r / 2) % MOD;
ll k = t * t % MOD;
return k * x % MOD;
}
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_mul(ll a, ll b) { return (a * b) % MOD; }
ll mod_div(ll a, ll b) { return mod_mul(a, mod_pow(b, MOD - 2)); }
void make_fact(ll n) {
fac[0] = 1;
REP(i, n) { fac[i + 1] = mod_mul(fac[i], i + 1); }
}
void make_invfact(ll n) {
invfac[n] = mod_pow(fac[n], MOD - 2);
REP_R(i, n) { invfac[i] = mod_mul(invfac[i + 1], i + 1); }
}
void init_fact() {
make_fact(FACSIZE - 1);
make_invfact(FACSIZE - 1);
}
ll combination(ll n, ll c) {
return mod_mul(fac[n], mod_mul(invfac[c], invfac[n - c]));
}
///////////////fact
/*
init_fact();
cout << fac[5] << endl;
cout << invfac[5] << endl;
cout << combination(8, 4) << endl;
cout << combination(31, 8) << endl;
//*/
///////////////////
| replace | 125 | 126 | 125 | 126 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define vec vector
#define rep(_i, _n) for (ll _i = 0; _i < _n; _i++)
#define rep2(_i, _s, _n) for (ll _i = _s; _i < _n; _i++)
#define elif else if
#define push(_a) push_back(_a)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) \
vec<int> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define inputVecL(_name, _n) \
vec<long> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define inputVecLL(_name, _n) \
vec<ll> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define inputVecS(_name, _n) \
vec<string> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define findMaxIdx(_name) \
distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec) \
cout << "{"; \
rep(i, _vec.size() - 1) cout << _vec[i] << ","; \
cout << _vec[_vec.size() - 1]; \
cout << "}\n";
#define append(_x) push_back(_x)
#define mapLoop(_i, _name) for (auto i = _name.begin(); i != _name.end(); i++)
#define pow5(_a) _a *_a *_a *_a *_a
int main() {
ll X;
cin >> X;
vec<ll> mylist(0);
ll buf = X;
rep2(i, 1, X + 1) {
if (X % i == 0) {
mylist.push_back(i);
}
}
int size = mylist.size();
rep(i, size) {
rep2(A, -119, 120) {
if (pow5(A) - pow5((A - mylist[i])) == X) {
cout << A << " " << (A - mylist[i]) << endl;
return 0;
}
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define vec vector
#define rep(_i, _n) for (ll _i = 0; _i < _n; _i++)
#define rep2(_i, _s, _n) for (ll _i = _s; _i < _n; _i++)
#define elif else if
#define push(_a) push_back(_a)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) \
vec<int> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define inputVecL(_name, _n) \
vec<long> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define inputVecLL(_name, _n) \
vec<ll> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define inputVecS(_name, _n) \
vec<string> _name(_n); \
rep(_i, _n) cin >> _name[_i];
#define findMaxIdx(_name) \
distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec) \
cout << "{"; \
rep(i, _vec.size() - 1) cout << _vec[i] << ","; \
cout << _vec[_vec.size() - 1]; \
cout << "}\n";
#define append(_x) push_back(_x)
#define mapLoop(_i, _name) for (auto i = _name.begin(); i != _name.end(); i++)
#define pow5(_a) _a *_a *_a *_a *_a
int main() {
ll X;
cin >> X;
ll buf1;
rep2(A, -119, 120) {
buf1 = pow5(A);
rep2(B, -119, A) {
if (buf1 - pow5(B) == X) {
cout << A << " " << B << endl;
return 0;
}
}
}
return 0;
}
| replace | 39 | 51 | 39 | 45 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct Edge {
int to; // 辺の行き先
int weight; // 辺の重み
Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>
using Graph = vector<vector<int>>;
// header area
int main() {
long long X;
cin >> X;
// long long A, B;
long long ans = 0;
long long n = 5000;
for (long long B = -n; B < n; B++) {
for (long long A = B; A < n; A++) {
ans = pow(A, 5) - pow(B, 5);
if (ans == X) {
cout << A << " " << B;
return 0;
}
}
}
cout << "nothing";
} | #include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct Edge {
int to; // 辺の行き先
int weight; // 辺の重み
Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>
using Graph = vector<vector<int>>;
// header area
int main() {
long long X;
cin >> X;
// long long A, B;
long long ans = 0;
long long n = 1000;
for (long long B = -n; B < n; B++) {
for (long long A = B; A < n; A++) {
ans = pow(A, 5) - pow(B, 5);
if (ans == X) {
cout << A << " " << B;
return 0;
}
}
}
cout << "nothing";
} | replace | 24 | 25 | 24 | 25 | TLE | |
p02690 | Python | Time Limit Exceeded | res = {}
for i in range(-1000, 1000):
for j in range(-1000, 1000):
ans = i**5 - j**5
res[ans] = (i, j)
n = int(input())
print(res[n][0], res[n][1])
| res = {}
for i in range(-500, 500):
for j in range(-500, 500):
ans = i**5 - j**5
res[ans] = (i, j)
n = int(input())
print(res[n][0], res[n][1])
| replace | 1 | 3 | 1 | 3 | TLE | |
p02690 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
cin >> a;
vector<int> yaku;
for (int i = 1; i * i <= a; i++) {
if (a % i == 0) {
yaku.push_back(i);
if (i * i != a)
yaku.push_back(a / i);
}
}
for (int i = 0; i < int(yaku.size()); i++) {
for (int j = -a; j < a; j++) {
if (pow(j, 5) - pow(j - yaku[i], 5) == a) {
cout << j << " " << j - yaku[i] << endl;
break;
}
}
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int a;
cin >> a;
int n, m;
for (n = -119; n < 120; n++) {
for (m = -119; m < 120; m++) {
if (pow(n, 5) - pow(m, 5) == a) {
cout << n << " " << m << endl;
return 0;
}
}
}
return 0;
} | replace | 11 | 24 | 11 | 17 | TLE | |
p02690 | Python | Time Limit Exceeded | x = int(input())
a = 0
b = 0
for i in range(-1000, 1000):
for j in range(-1000, 1000):
if (i**5) - (j**5) == x:
a = i
b = j
break
print("{} {}".format(a, b))
| x = int(input())
a = 0
b = 0
for i in range(-500, 500):
for j in range(-500, 500):
if (i**5) - (j**5) == x:
a = i
b = j
break
print("{} {}".format(a, b))
| replace | 3 | 5 | 3 | 5 | TLE | |
p02690 | Python | Time Limit Exceeded | x = int(input())
a, b = 0, 0
nx = "a"
while True:
if a**5 - b**5 == x:
print("{} {}".format(a, b))
break
if -(a**5) - b**5 == x:
print("{} {}".format(-a, b))
break
if a**5 - (-b) ** 5 == x:
print("{} {}".format(a, -b))
break
if -(a**5) - (-b) ** 5 == x:
print("{} {}".format(-a, -b))
break
if nx == "a":
a += 1
nx = "b"
else:
b += 1
nx = "a"
| x = int(input())
for b in range(1000):
for a in range(1000):
if a**5 - b**5 == x:
print("{} {}".format(a, b))
exit()
if (-a) ** 5 - b**5 == x:
print("{} {}".format(-a, b))
exit()
if a**5 - (-b) ** 5 == x:
print("{} {}".format(a, -b))
exit()
if (-a) ** 5 - (-b) ** 5 == x:
print("{} {}".format(-a, -b))
exit()
| replace | 1 | 22 | 1 | 15 | TLE | |
p02690 | Python | Time Limit Exceeded | import sys
x = int(input())
for i in range(-2000, 2000):
for j in range(-2000, 2000):
if i**5 - j**5 == x:
print(i, j)
sys.exit()
| import sys
x = int(input())
for i in range(-1000, 1000):
for j in range(-1000, 1000):
if i**5 - j**5 == x:
print(i, j)
sys.exit()
| replace | 4 | 6 | 4 | 6 | TLE | |
p02690 | Python | Time Limit Exceeded | X = int(input())
# for b in range(65, -64, -1):
for b in range(1000000, -1000000, -1):
a = (X + b**5) ** 0.2
# print('b a', b, a)
if type(a) == complex:
if a.imag != 0:
continue
print(int(a.real), b)
exit()
elif a.is_integer():
print(int(a), b)
exit()
for a in range(1000000, -1000000, -1):
b = (X - a**5) ** 0.2
# print('b a', b, a)
if type(b) == complex:
if b.imag != 0:
continue
print(int(b.real), a)
exit()
elif b.is_integer():
print(int(a), b)
exit()
| X = int(input())
for a in range(-1000, 1000):
for b in range(-1000, 1000):
if a**5 - b**5 == X:
print(a, b)
exit()
| replace | 2 | 26 | 2 | 7 | TLE | |
p02690 | Python | Runtime Error | """
A^5 - B^5
= (A - B)(A^4 + A^3*B + A^2*B^2 + A*B^3 + B^4)
= (A - B){(A + B) * (A^3 + B^3) + A^2*B^2}
= (A - B){(A + B)^2 * (A^2 - AB + B^2) + A^2*B^2}
-> (A + B)^2 > 1, (A^2 - AB + B^2) > 1, A^2*B^2 > 1.
"""
def main():
print(*solve())
def solve():
X = int(input())
for a in range(-100, 100):
for b in range(-100, 100):
if a**5 - b**5 == X:
return a, b
if __name__ == "__main__":
main()
| """
A^5 - B^5
= (A - B)(A^4 + A^3*B + A^2*B^2 + A*B^3 + B^4)
= (A - B){(A + B) * (A^3 + B^3) + A^2*B^2}
= (A - B){(A + B)^2 * (A^2 - AB + B^2) + A^2*B^2}
-> (A + B)^2 > 1, (A^2 - AB + B^2) > 1, A^2*B^2 > 1.
"""
def main():
print(*solve())
def solve():
X = int(input())
for a in range(-1000, 1000):
for b in range(-1000, 1000):
if a**5 - b**5 == X:
return a, b
if __name__ == "__main__":
main()
| replace | 17 | 19 | 17 | 19 | 0 | |
p02690 | Python | Time Limit Exceeded | X = int(input())
CNT = 2000
for a in range(-CNT, CNT):
for b in range(-CNT, CNT):
if X == a**5 - b**5:
print(a, b)
exit()
| X = int(input())
CNT = 500
for a in range(-CNT, CNT):
for b in range(-CNT, CNT):
if X == a**5 - b**5:
print(a, b)
exit()
| replace | 2 | 3 | 2 | 3 | TLE | |
p02690 | Python | Runtime Error | x = int(input())
my_dict = dict()
for i in range(1000):
my_dict[i**5] = i
for i in range(-1000, 1000):
target = x + (i**5)
if (-target) in my_dict:
print(-my_dict[target], i)
exit()
elif target in my_dict:
print(my_dict[target], i)
exit()
| x = int(input())
my_dict = dict()
for i in range(1000):
my_dict[i**5] = i
for i in range(-1000, 1000):
target = x + (i**5)
if (-target) in my_dict:
print(-my_dict[-target], i)
exit()
elif target in my_dict:
print(my_dict[target], i)
exit()
| replace | 10 | 11 | 10 | 11 | 0 | |
p02690 | Python | Time Limit Exceeded | X = int(input())
a = 1
flug = True
while flug:
b = -119
while b <= 118:
if a**5 - b**5 == X:
print(a, b)
flug = False
break
else:
b += 1
| X = int(input())
a = 1
flug = True
while flug:
b = -119
while b <= 118:
if a**5 - b**5 == X:
print(a, b)
flug = False
break
else:
b += 1
a += 1
| insert | 12 | 12 | 12 | 13 | TLE | |
p02690 | Python | Time Limit Exceeded | def prime_factorize(n):
"""Calculate prime factorization and return unique numbers and 1."""
ans = set()
ans_add = ans.add
ans_add(1)
while n % 2 == 0:
ans_add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
ans_add(f)
n //= f
else:
f += 2
if n != 1:
ans_add(n)
return ans
def main():
x = int(input())
# 素因数分解してユニークな因数を取る。
insu = prime_factorize(x)
# a^5 - b^5 も a - b も,ある因数の倍数となる。
# ここは a >= b と仮定すると,a は正でなくては,xが負になっちゃう。
b_min = -int(x ** (1 / 5))
for n in insu:
b = b_min
while 1:
a = b
while 1:
a += n
if a < 0:
continue
cand = a**5 - b**5
if cand == x:
return f"{a} {b}"
elif cand > x:
break
b += 1
if __name__ == "__main__":
print(main())
| def prime_factorize(n):
"""Calculate prime factorization and return unique numbers and 1."""
ans = set()
ans_add = ans.add
ans_add(1)
while n % 2 == 0:
ans_add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
ans_add(f)
n //= f
else:
f += 2
if n != 1:
ans_add(n)
return ans
def main():
x = int(input())
# 素因数分解してユニークな因数を取る。
insu = prime_factorize(x)
# a^5 - b^5 も a - b も,ある因数の倍数となる。
# ここは a >= b と仮定すると,a は正でなくては,xが負になっちゃう。
b_min = -int(x ** (1 / 5))
for n in insu:
b = b_min
while 1:
a = b
while 1:
a += n
if a < 0:
continue
cand = a**5 - b**5
if cand == x:
return f"{a} {b}"
elif cand > x:
break
b += 1
if (b + n) ** 5 - b**5 > x:
break
if __name__ == "__main__":
print(main())
| insert | 42 | 42 | 42 | 44 | TLE | |
p02690 | Python | Runtime Error | x = int(input())
rs = [i**5 for i in range(300)]
for r in rs:
if (x - r) in rs:
print(rs.index(r), -rs.index(x - r))
elif (x + r) in rs:
print(rs.index(r), rs.index(x - r))
else:
continue
break
| x = int(input())
rs = [i**5 for i in range(300)]
for r in rs:
if r <= x:
if x - r in rs:
print(rs.index(r), -rs.index(x - r))
break
if r > x:
if r - x in rs:
print(rs.index(r), rs.index(r - x))
break
| replace | 5 | 12 | 5 | 13 | 0 | |
p02690 | Python | Runtime Error | x = int(input())
for i in range(x // 2 + 1):
if pow(x - pow(i, 5), 1 / 5).is_integer():
print(i, int(-pow(x - pow(i, 5), 1 / 5)))
exit()
| import numpy as np
def main():
x = int(input())
A = np.arange(-120, 120)
a = A**5
for i, a_1 in enumerate(a):
for j, a_2 in enumerate(a):
if a_1 - a_2 == x:
print(A[i], A[j])
return
if __name__ == "__main__":
main()
| replace | 0 | 5 | 0 | 16 | 0 | |
p02690 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
int ans1 = 0;
int ans2 = 0;
for (int i = 0; i < 1000000000; i++) {
for (int j = i - 1; (i * i * i * i * i) - (j * j * j * j * j) > 0; j--) {
long long num = (i * i * i * i * i) - (j * j * j * j * j);
if (num == N) {
ans1 = i;
ans2 = j;
break;
}
}
}
cout << ans1 << " " << ans2 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
int ans1 = 0;
int ans2 = 0;
for (int i = 0; i < 5000000; i++) {
for (int j = i - 1; (i * i * i * i * i) - (j * j * j * j * j) > 0; j--) {
long long num = (i * i * i * i * i) - (j * j * j * j * j);
if (num == N) {
ans1 = i;
ans2 = j;
break;
}
}
}
cout << ans1 << " " << ans2 << endl;
}
| replace | 8 | 9 | 8 | 9 | TLE | |
p02690 | Python | Time Limit Exceeded | x = int(input())
a = int(x**0.2)
b = 0
while a**5 - b**5 != x:
b -= 1
print(a, b)
| x = int(input())
for a in range(-1000, 1000):
for b in range(-1000, 1000):
if a**5 - b**5 == x:
print(a, b)
quit()
| replace | 1 | 6 | 1 | 6 | TLE | |
p02690 | C++ | Runtime Error |
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt,
// less) : if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*"))
// ) std::cout << "YES" << std::endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using ll = long long;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll check(ll x) {
ll l = 0, r = 100;
while (r - l > 1) {
ll mid = (l + r) / 2;
ll c = std::pow(mid, 5);
if (c < x)
l = mid;
else
r = mid;
}
return r;
}
int main(void) {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ll X;
std::cin >> X;
for (ll b = -1000; b <= 1000; b++) {
ll a5 = b * b * b * b * b + X;
ll a = check(a5);
if (a5 == a * a * a * a * a) {
std::cout << a << " " << b << std::endl;
return 0;
}
}
assert(0);
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt,
// less) : if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*"))
// ) std::cout << "YES" << std::endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using ll = long long;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll check(ll x) {
ll l = -1000, r = 1000;
while (r - l > 1) {
ll mid = (l + r) / 2;
ll c = std::pow(mid, 5);
if (c < x)
l = mid;
else
r = mid;
}
return r;
}
int main(void) {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ll X;
std::cin >> X;
for (ll b = -1000; b <= 1000; b++) {
ll a5 = b * b * b * b * b + X;
ll a = check(a5);
if (a5 == a * a * a * a * a) {
std::cout << a << " " << b << std::endl;
return 0;
}
}
assert(0);
return 0;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace ::std;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
#define rep(i, n) for (lint i = 0; i < (lint)(n); i++)
#define irep(i) for (lint i = 0;; i++)
#define irep1(i) for (lint i = 1;; i++)
#define irep2(i) for (lint i = 2;; i++)
#define rrep(i, n) for (lint i = (lint)(n - 1); i > -1; i--)
#define rrepi(i, a, b) for (lint i = (lint)(b - 1); i > a - 1; i--)
#define repi(i, a, b) for (lint i = lint(a); i < lint(b); i++)
#define rep2(i, a, b, c) for (lint i = lint(a); i > lint(b); i += c)
#define all(x) (x).begin(), (x).end()
#define sl(c) (('a') <= (c) && (c) <= ('z'))
#define ll(c) (('A') <= (c) && (c) <= ('Z'))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define PI 3.141592653589793
#define cout (cout << fixed << setprecision(15))
#define makeupper(t) (transform(all(t), t.begin(), ::toupper))
#define makelower(t) (transform(all(t), t.begin(), ::tolower))
#define dist(x1, y1, x2, y2) (pow(pow(x2 - x1, 2) + pow(y2 - y1, 2), 0.5))
#define NEXT_LINE \
string junk; \
getline(cin, junk);
#define output(v) \
do { \
rep(i, v.size()) cout << (i ? " " : "") << v[i]; \
cout << "\n"; \
} while (0)
#define output2(v) \
rep(i, v.size()) { \
rep(j, v[i].size()) { cout << (j ? " " : "") << v[i][j]; } \
cout << "\n"; \
}
#define INF 1LL << 60
#define IINF 1 << 30
#define LINF 9223372036854775807
#define MOD 998244353
vector<lint> dx = {-1, 1, 0, 0, 1, 1, -1, -1};
vector<lint> dy = {0, 0, -1, 1, 1, -1, 1, -1};
vector<lint> operator+(const vector<lint> &v1, const vector<lint> &v2) {
vector<lint> v(v1.size() + v2.size(), 0);
rep(i, v1.size()) v[i] = v1[i];
rep(i, v2.size()) v[i + v1.size()] = v2[i];
return v;
}
inline lint sum(vector<lint> v) {
lint sum = 0;
rep(i, v.size()) sum += v[i];
return sum;
}
inline string replace(string str, string before, std::string after) {
string::size_type Pos(str.find(before));
while (Pos != std::string::npos) {
str.replace(Pos, before.length(), after);
Pos = str.find(before, Pos + after.length());
}
return str;
}
inline vector<string> split(string s, string delim) {
vector<string> elems;
s = replace(s, "#", "HASH");
s = replace(s, delim, "#");
stringstream ss(s);
string item;
while (getline(ss, item, '#')) {
elems.push_back(replace(item, "HASH", "#"));
}
return elems;
}
inline vector<int> cross(vector<int> a, vector<int> b) {
return {a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]};
}
inline lint GCD(lint a, lint b) { return b ? GCD(b, a % b) : a; }
inline vector<lint> primeList(lint n) {
vector<bool> p(n + 1);
vector<lint> list;
repi(i, 1, n + 1) p[i] = true;
repi(i, 2, sqrt(n) + 1) {
if (p[i]) {
repi(j, 2, n / i + 1) { p[i * j] = false; }
}
}
repi(i, 2, n + 1) if (p[i]) list.push_back(i);
return list;
}
inline set<lint> primeSet(lint n) {
vector<bool> p(n + 1);
set<lint> set;
repi(i, 1, n + 1) p[i] = true;
repi(i, 2, sqrt(n) + 1) {
if (p[i]) {
repi(j, 2, n / i + 1) { p[i * j] = false; }
}
}
repi(i, 2, n + 1) if (p[i]) set.insert(i);
return set;
}
inline bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
inline lint max(vector<lint> num) {
lint M = num[0];
rep(i, num.size()) M = max(M, num[i]);
return M;
}
inline lint min(vector<lint> num) {
lint M = num[0];
rep(i, num.size()) M = min(M, num[i]);
return M;
}
inline lint signal(lint val) {
if (val == 0)
return 0;
else
return val / abs(val);
}
struct IVector2 {
lint x, y;
};
bool operator<(const IVector2 &s, const IVector2 &t) {
return s.x == t.x ? s.y < t.y : s.x < t.x;
};
bool operator>(const IVector2 &s, const IVector2 &t) {
return s.x == t.x ? s.y > t.y : s.x > t.x;
};
struct IVector3 {
lint x, y, z;
};
struct IVector4 {
lint x, y, z, w;
};
template <typename... args> struct dfs {
public:
queue<function<void(void)>> que;
function<void(args..., dfs<args...> &)> func;
void run() {
while (!que.empty()) {
que.front()();
que.pop();
}
}
void push(args... arg) { que.push(bind(func, arg..., ref(*this))); }
dfs(args... init, function<void(args..., dfs<args...> &)> func) : func(func) {
push(init...);
run();
}
};
lint mod_pow(lint x, lint y, lint mod) {
if (y == 0)
return 1;
else if (y == 1)
return x;
else if (y % 2 == 1)
return x * mod_pow(x, y - 1, mod) % mod;
else
return mod_pow(x, y / 2, mod) * mod_pow(x, y / 2, mod) % mod;
}
lint binary_search(function<bool(lint)> func) {
lint left = -1;
lint right = IINF;
while (right - left > 1) {
lint mid = left + (right - left) / 2;
if (func(mid))
right = mid;
else
left = mid;
}
return right;
}
/*std::string RLE(string str)
{
string result = "";
char cmp = str[0];
lint cnt = 0;
rep(i, str.length())
{
if (cmp == str[i])
{
cnt++;
}
else
{
result += cmp;
result += cnt;
cnt = 0;
cmp = str[i];
}
}
}*/
int main(void) {
lint n;
cin >> n;
lint *a = new lint[n];
rep(i, n) { cin >> a[i]; }
// i - j = Ai + Aj
// i - Ai = Aj + j
lint maxX = 0;
rep(i, n) { maxX = max(maxX, i + 1 - a[i]); }
lint ans = 0;
vector<lint> ai(n, 0);
vector<lint> aj(n, 0);
rep(i, n) { ai.at(i) = i + 1 - a[i]; }
rep(j, n) { aj.at(j) = j + 1 + a[j]; }
std::sort(ai.begin(), ai.end());
std::sort(aj.begin(), aj.end());
rep(x, maxX + 1) {
lint cnti = 0;
lint cntj = 0;
rep(i, n) {
cnti = std::upper_bound(ai.begin(), ai.end(), x) -
std::lower_bound(ai.begin(), ai.end(), x);
cntj = std::upper_bound(aj.begin(), aj.end(), x) -
std::lower_bound(aj.begin(), aj.end(), x);
}
ans += cnti * cntj;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace ::std;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
#define rep(i, n) for (lint i = 0; i < (lint)(n); i++)
#define irep(i) for (lint i = 0;; i++)
#define irep1(i) for (lint i = 1;; i++)
#define irep2(i) for (lint i = 2;; i++)
#define rrep(i, n) for (lint i = (lint)(n - 1); i > -1; i--)
#define rrepi(i, a, b) for (lint i = (lint)(b - 1); i > a - 1; i--)
#define repi(i, a, b) for (lint i = lint(a); i < lint(b); i++)
#define rep2(i, a, b, c) for (lint i = lint(a); i > lint(b); i += c)
#define all(x) (x).begin(), (x).end()
#define sl(c) (('a') <= (c) && (c) <= ('z'))
#define ll(c) (('A') <= (c) && (c) <= ('Z'))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define PI 3.141592653589793
#define cout (cout << fixed << setprecision(15))
#define makeupper(t) (transform(all(t), t.begin(), ::toupper))
#define makelower(t) (transform(all(t), t.begin(), ::tolower))
#define dist(x1, y1, x2, y2) (pow(pow(x2 - x1, 2) + pow(y2 - y1, 2), 0.5))
#define NEXT_LINE \
string junk; \
getline(cin, junk);
#define output(v) \
do { \
rep(i, v.size()) cout << (i ? " " : "") << v[i]; \
cout << "\n"; \
} while (0)
#define output2(v) \
rep(i, v.size()) { \
rep(j, v[i].size()) { cout << (j ? " " : "") << v[i][j]; } \
cout << "\n"; \
}
#define INF 1LL << 60
#define IINF 1 << 30
#define LINF 9223372036854775807
#define MOD 998244353
vector<lint> dx = {-1, 1, 0, 0, 1, 1, -1, -1};
vector<lint> dy = {0, 0, -1, 1, 1, -1, 1, -1};
vector<lint> operator+(const vector<lint> &v1, const vector<lint> &v2) {
vector<lint> v(v1.size() + v2.size(), 0);
rep(i, v1.size()) v[i] = v1[i];
rep(i, v2.size()) v[i + v1.size()] = v2[i];
return v;
}
inline lint sum(vector<lint> v) {
lint sum = 0;
rep(i, v.size()) sum += v[i];
return sum;
}
inline string replace(string str, string before, std::string after) {
string::size_type Pos(str.find(before));
while (Pos != std::string::npos) {
str.replace(Pos, before.length(), after);
Pos = str.find(before, Pos + after.length());
}
return str;
}
inline vector<string> split(string s, string delim) {
vector<string> elems;
s = replace(s, "#", "HASH");
s = replace(s, delim, "#");
stringstream ss(s);
string item;
while (getline(ss, item, '#')) {
elems.push_back(replace(item, "HASH", "#"));
}
return elems;
}
inline vector<int> cross(vector<int> a, vector<int> b) {
return {a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]};
}
inline lint GCD(lint a, lint b) { return b ? GCD(b, a % b) : a; }
inline vector<lint> primeList(lint n) {
vector<bool> p(n + 1);
vector<lint> list;
repi(i, 1, n + 1) p[i] = true;
repi(i, 2, sqrt(n) + 1) {
if (p[i]) {
repi(j, 2, n / i + 1) { p[i * j] = false; }
}
}
repi(i, 2, n + 1) if (p[i]) list.push_back(i);
return list;
}
inline set<lint> primeSet(lint n) {
vector<bool> p(n + 1);
set<lint> set;
repi(i, 1, n + 1) p[i] = true;
repi(i, 2, sqrt(n) + 1) {
if (p[i]) {
repi(j, 2, n / i + 1) { p[i * j] = false; }
}
}
repi(i, 2, n + 1) if (p[i]) set.insert(i);
return set;
}
inline bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
inline lint max(vector<lint> num) {
lint M = num[0];
rep(i, num.size()) M = max(M, num[i]);
return M;
}
inline lint min(vector<lint> num) {
lint M = num[0];
rep(i, num.size()) M = min(M, num[i]);
return M;
}
inline lint signal(lint val) {
if (val == 0)
return 0;
else
return val / abs(val);
}
struct IVector2 {
lint x, y;
};
bool operator<(const IVector2 &s, const IVector2 &t) {
return s.x == t.x ? s.y < t.y : s.x < t.x;
};
bool operator>(const IVector2 &s, const IVector2 &t) {
return s.x == t.x ? s.y > t.y : s.x > t.x;
};
struct IVector3 {
lint x, y, z;
};
struct IVector4 {
lint x, y, z, w;
};
template <typename... args> struct dfs {
public:
queue<function<void(void)>> que;
function<void(args..., dfs<args...> &)> func;
void run() {
while (!que.empty()) {
que.front()();
que.pop();
}
}
void push(args... arg) { que.push(bind(func, arg..., ref(*this))); }
dfs(args... init, function<void(args..., dfs<args...> &)> func) : func(func) {
push(init...);
run();
}
};
lint mod_pow(lint x, lint y, lint mod) {
if (y == 0)
return 1;
else if (y == 1)
return x;
else if (y % 2 == 1)
return x * mod_pow(x, y - 1, mod) % mod;
else
return mod_pow(x, y / 2, mod) * mod_pow(x, y / 2, mod) % mod;
}
lint binary_search(function<bool(lint)> func) {
lint left = -1;
lint right = IINF;
while (right - left > 1) {
lint mid = left + (right - left) / 2;
if (func(mid))
right = mid;
else
left = mid;
}
return right;
}
/*std::string RLE(string str)
{
string result = "";
char cmp = str[0];
lint cnt = 0;
rep(i, str.length())
{
if (cmp == str[i])
{
cnt++;
}
else
{
result += cmp;
result += cnt;
cnt = 0;
cmp = str[i];
}
}
}*/
int main(void) {
lint n;
cin >> n;
lint *a = new lint[n];
rep(i, n) { cin >> a[i]; }
// i - j = Ai + Aj
// i - Ai = Aj + j
lint maxX = 0;
rep(i, n) { maxX = max(maxX, i + 1 - a[i]); }
lint ans = 0;
vector<lint> ai(n, 0);
vector<lint> aj(n, 0);
rep(i, n) { ai.at(i) = i + 1 - a[i]; }
rep(j, n) { aj.at(j) = j + 1 + a[j]; }
std::sort(ai.begin(), ai.end());
std::sort(aj.begin(), aj.end());
rep(x, maxX + 1) {
lint cnti = 0;
lint cntj = 0;
cnti = std::upper_bound(ai.begin(), ai.end(), x) -
std::lower_bound(ai.begin(), ai.end(), x);
cntj = std::upper_bound(aj.begin(), aj.end(), x) -
std::lower_bound(aj.begin(), aj.end(), x);
ans += cnti * cntj;
}
cout << ans << endl;
} | replace | 234 | 240 | 234 | 238 | TLE | |
p02691 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG // TLEの原因になるので注意!!!!!!!!!!!
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// #define int long long
// cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
// const ll INF = 1LL << 60;
// typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
if (b > a) {
a = b;
return true;
}
return false;
}
bool chmn(int &a, int b) {
if (b < a) {
a = b;
return true;
}
return false;
}
int A[200005];
int cc = 0;
vector<int> V;
int B[200005];
int main() {
int n;
ll ans = 0;
cin >> n;
rep(i, n) {
cin >> A[i];
B[i] = A[i] - i;
if (-200005 < B[i] && B[i] < 0) {
V.push_back(-B[i]);
}
}
sort(V.begin(), V.end());
rep(i, n) {
int k = A[i] + i;
if (200005 > k) {
int temp = upper_bound(V.begin(), V.end(), k) -
lower_bound(V.begin(), V.end(), k);
ans += temp;
}
}
cout << ans << endl;
return 0;
}
| // #define _GLIBCXX_DEBUG//TLEの原因になるので注意!!!!!!!!!!!
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// #define int long long
// cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
// const ll INF = 1LL << 60;
// typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
if (b > a) {
a = b;
return true;
}
return false;
}
bool chmn(int &a, int b) {
if (b < a) {
a = b;
return true;
}
return false;
}
int A[200005];
int cc = 0;
vector<int> V;
int B[200005];
int main() {
int n;
ll ans = 0;
cin >> n;
rep(i, n) {
cin >> A[i];
B[i] = A[i] - i;
if (-200005 < B[i] && B[i] < 0) {
V.push_back(-B[i]);
}
}
sort(V.begin(), V.end());
rep(i, n) {
int k = A[i] + i;
if (200005 > k) {
int temp = upper_bound(V.begin(), V.end(), k) -
lower_bound(V.begin(), V.end(), k);
ans += temp;
}
}
cout << ans << endl;
return 0;
}
| replace | 0 | 1 | 0 | 1 | TLE | |
p02691 | C++ | Time Limit Exceeded | #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>;
int main() {
int n;
cin >> n;
vector<ll> A(n);
rep(i, n) cin >> A[i];
int ans = 0;
rep(i, n - 1) {
for (int j = i + 1; j < n; j++) {
if (j - i == A[i] + A[j])
ans++;
}
}
cout << ans << 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>;
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
map<int, int> mp;
ll ans = 0;
rep(i, n) {
int sa = i - a[i];
// i<j j-i==Ai+Aj Ai+i==j-Aj Ai+iはmpに入れていくと計算時間を減らせる
ans += mp[sa];
int wa = a[i] + i;
mp[wa]++;
}
cout << ans << endl;
return 0;
} | replace | 9 | 17 | 9 | 19 | TLE | |
p02691 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 _int;
const int maxn = 1e5 + 6;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
int n, k;
int a[maxn];
map<int, int> num;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}
void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
signed main() {
cin >> n;
int ans = 0;
num.clear();
for (int i = 1; i <= n; i++) {
cin >> a[i];
ans += num[i - a[i]];
num[i + a[i]] += 1;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef __int128 _int;
const int maxn = 2e5 + 6;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
int n, k;
int a[maxn];
map<int, int> num;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * f;
}
void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
signed main() {
cin >> n;
int ans = 0;
num.clear();
for (int i = 1; i <= n; i++) {
cin >> a[i];
ans += num[i - a[i]];
num[i + a[i]] += 1;
}
cout << ans << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int, int>;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 最大公約数
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
// 最大公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int MAX = 1e6 + 1;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 階乗
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
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;
}
// sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) {}
int root(int x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) { return -par[root(x)]; }
};
ll count(int n, int a) {
ll bunshi = 1;
for (int i = 0; i < a; i++) {
bunshi *= (n - i);
bunshi %= MOD;
}
ll bunbo = 1;
for (int i = 1; i < a + 1; i++) {
bunbo *= i;
bunbo %= MOD;
}
bunbo = modpow(bunbo, MOD - 2, MOD);
// cout<<(bunshi*bunbo)%MOD<<endl;
return (bunshi * bunbo) % MOD;
}
// 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。
vector<ll> divisor(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// ここから開始
const ll INF = 1e18;
int main() {
int N;
cin >> N;
int a[N];
for (int i = 0; i < N; i++) {
cin >> a[i];
}
vector<ll> d;
vector<ll> e;
rep(i, N) {
// +
if (i + a[i] < 1e9)
d.push_back(i + a[i]);
if (i - a[i] > 0)
e.push_back(i - a[i]);
}
sort(d.begin(), d.end());
sort(e.begin(), e.end());
ll ans = 0;
for (int i = 0; i < e.size(); i++) {
int x = e[i];
if (x < 0)
continue;
if (i > 0 && x == e[i - 1])
continue;
// cout<<x<<endl;
ans += count(d.begin(), d.end(), x) * count(e.begin(), e.end(), x);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int, int>;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 最大公約数
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
// 最大公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int MAX = 1e6 + 1;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 階乗
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
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;
}
// sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) {}
int root(int x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) { return -par[root(x)]; }
};
ll count(int n, int a) {
ll bunshi = 1;
for (int i = 0; i < a; i++) {
bunshi *= (n - i);
bunshi %= MOD;
}
ll bunbo = 1;
for (int i = 1; i < a + 1; i++) {
bunbo *= i;
bunbo %= MOD;
}
bunbo = modpow(bunbo, MOD - 2, MOD);
// cout<<(bunshi*bunbo)%MOD<<endl;
return (bunshi * bunbo) % MOD;
}
// 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。
vector<ll> divisor(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// ここから開始
const ll INF = 1e18;
int main() {
int N;
cin >> N;
int a[N];
for (int i = 0; i < N; i++) {
cin >> a[i];
}
vector<ll> d;
vector<ll> e;
rep(i, N) {
// +
if (i + a[i] < 1e9)
d.push_back(i + a[i]);
if (i - a[i] > 0)
e.push_back(i - a[i]);
}
sort(d.begin(), d.end());
sort(e.begin(), e.end());
ll ans = 0;
for (int i = 0; i < e.size(); i++) {
int x = e[i];
if (x < 0)
continue;
if (i > 0 && x == e[i - 1])
continue;
// cout<<x<<endl;
ll xx =
upper_bound(d.begin(), d.end(), x) - lower_bound(d.begin(), d.end(), x);
ll yy =
upper_bound(e.begin(), e.end(), x) - lower_bound(e.begin(), e.end(), x);
ans += xx * yy;
}
cout << ans << endl;
return 0;
}
| replace | 261 | 262 | 261 | 266 | TLE | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main() {
ll n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
map<ll, vll> mpp;
map<ll, vll> mpm;
rep(i, n) {
ll p = i + a[i];
ll m = i - a[i];
mpp[p].push_back(i);
mpm[m].push_back(i);
}
ll ans = 0;
for (auto q : mpp) {
ll k = q.first;
vll vp = q.second;
vll vm = mpm[k];
rep(i, vp.size()) rep(j, vm.size()) {
if (vp[i] < vm[j])
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main() {
ll n;
cin >> n;
vll a(n);
rep(i, n) cin >> a[i];
map<ll, vll> mpp;
map<ll, vll> mpm;
rep(i, n) {
ll p = i + a[i];
ll m = i - a[i];
mpp[p].push_back(i);
mpm[m].push_back(i);
}
ll ans = 0;
for (auto q : mpp) {
ll k = q.first;
vll vp = q.second;
vll vm = mpm[k];
ll sp = vp.size();
ll sm = vm.size();
ans += sp * sm;
}
cout << ans << endl;
return 0;
} | replace | 28 | 32 | 28 | 31 | TLE | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> plus(N), minus(300000, 0);
rep(i, N) {
int A;
cin >> A;
plus[i] = i + 1 + A;
if (i + 1 - A > 0) {
minus.at(i + 1 - A)++;
}
}
ll ans = 0;
rep(i, N) { ans += minus[plus[i]]; }
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> plus(N), minus(300000, 0);
rep(i, N) {
int A;
cin >> A;
plus[i] = i + 1 + A;
if (i + 1 - A > 0) {
minus.at(i + 1 - A)++;
}
}
ll ans = 0;
rep(i, N) {
if (plus[i] < 300000) {
ans += minus[plus[i]];
}
}
cout << ans << endl;
} | replace | 18 | 19 | 18 | 23 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, ans = 0;
LL a[2000100], b[2000100];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > a[i]) {
b[i - a[i]]++;
}
}
for (int i = 1; i <= n; i++) {
if (i > a[i]) {
b[i - a[i]]--;
}
ans += b[i + a[i]];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, ans = 0;
LL a[2000100], b[2000100];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > a[i]) {
b[i - a[i]]++;
}
}
for (int i = 1; i <= n; i++) {
if (i > a[i]) {
b[i - a[i]]--;
}
if (i + a[i] <= n) {
ans += b[i + a[i]];
}
}
cout << ans << endl;
} | replace | 18 | 19 | 18 | 21 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
int n;
cin >> n;
int A[n];
rep(i, n) cin >> A[i];
ll count = 0;
rep(i, n) {
for (int j = i + A[i]; j < n; j++) {
if (A[i] + A[j] == j - i)
count++;
}
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main() {
int n;
cin >> n;
int A[n];
rep(i, n) cin >> A[i];
map<int, int> mp;
rep(i, n) mp[A[i] + i + 1]++;
ll ans = 0;
rep(i, n) ans += mp[i + 1 - A[i]];
cout << ans << endl;
}
| replace | 10 | 18 | 10 | 15 | TLE | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
const int maxn = 5e3 + 35;
map<LL, int> mp;
int n, a[maxn];
int main() {
cin >> n;
LL ans = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (mp.count(i - a[i]))
ans += mp[i - a[i]];
mp[i + a[i]] += 1;
}
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
const int maxn = 3e5 + 35;
map<LL, int> mp;
int n, a[maxn];
int main() {
cin >> n;
LL ans = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (mp.count(i - a[i]))
ans += mp[i - a[i]];
mp[i + a[i]] += 1;
}
cout << ans << '\n';
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;
int main() {
ll N;
cin >> N;
vector<ll> A(N, 0);
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
vector<P> C(0);
vector<P> D(0);
for (ll i = 0; i < N; i++) {
C.emplace_back(P(i + A[i], i));
if (i > 0)
D.emplace_back(P(i - A[i], i));
;
}
// 自分より番号大きいものだけ見ろ
ll ans = 0;
sort(C.begin(), C.end());
sort(D.begin(), D.end());
for (ll i = 0; i < N - 1; i++) {
ll x = C[i].first;
ll y = C[i].second; // yより大きい番号しか残すな
ll s = lower_bound(D.begin(), D.end(), P(x, 0)) - D.begin();
ll t = upper_bound(D.begin(), D.end(), P(x, INF)) -
D.begin(); // sからt-1番目までをみる
ans += t - s;
D.erase(lower_bound(D.begin(), D.end(), P(i + 1 - A[i + 1], i + 1)));
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;
int main() {
ll N;
cin >> N;
vector<ll> A(N, 0);
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
vector<P> C(0);
vector<P> D(0);
for (ll i = 0; i < N; i++) {
C.emplace_back(P(i + A[i], i));
if (i > 0)
D.emplace_back(P(i - A[i], i));
;
}
// 自分より番号大きいものだけ見ろ
ll ans = 0;
sort(C.begin(), C.end());
sort(D.begin(), D.end());
for (ll i = 0; i < N - 1; i++) {
ll x = C[i].first;
ll y = C[i].second; // yより大きい番号しか残すな
ll s = lower_bound(D.begin(), D.end(), P(x, 0)) - D.begin();
ll t = upper_bound(D.begin(), D.end(), P(x, INF)) -
D.begin(); // sからt-1番目までをみる
ans += t - s;
// D.erase(lower_bound(D.begin(), D.end(), P(i+1-A[i+1],i+1)))
;
}
cout << ans << endl;
return 0;
}
| replace | 40 | 41 | 40 | 42 | TLE | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
#define scd second
#define fst first
#define mkp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> arr(n);
for (auto &x : arr)
cin >> x;
unordered_map<int, int> cnt;
ll ans = 0;
for (int i = n - 1; i >= 0; i++) {
auto itr = cnt.find(arr[i] + i + 1);
if (itr != cnt.end()) {
ans += itr->second;
}
cnt[i + 1 - arr[i]]++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define scd second
#define fst first
#define mkp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef vector<bool> vbool;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> arr(n);
for (auto &x : arr)
cin >> x;
unordered_map<int, int> cnt;
ll ans = 0;
for (int i = n - 1; i >= 0; i--) {
auto itr = cnt.find(arr[i] + i + 1);
if (itr != cnt.end()) {
ans += itr->second;
}
cnt[i + 1 - arr[i]]++;
}
cout << ans << endl;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, M = 1e9 + 7, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0);
const double Pii = 3.14159265359;
ll n;
ll a[N], d[N], fr[N];
int main() {
FIO cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
d[i] = i - a[i];
}
for (int i = 0; i < n; ++i)
if (d[i] < N && d[i] >= 0)
fr[d[i]]++;
ll ans = 0;
for (int i = 0; i < n; ++i) {
int didx = a[i] + i;
ans += fr[didx];
// cout << didx << " " << fr[didx] << endl;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, M = 1e9 + 7, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0);
const double Pii = 3.14159265359;
ll n;
ll a[N], d[N], fr[N];
int main() {
FIO cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
d[i] = i - a[i];
}
for (int i = 0; i < n; ++i)
if (d[i] < N && d[i] >= 0)
fr[d[i]]++;
ll ans = 0;
for (int i = 0; i < n; ++i) {
int didx = a[i] + i;
if (didx >= 0 && didx < N)
ans += fr[didx];
// cout << didx << " " << fr[didx] << endl;
}
cout << ans << endl;
return 0;
}
| replace | 23 | 24 | 23 | 25 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N, A[200005], B[200005];
long long ans;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
if (i - A[i] > 0) {
B[i - A[i]]++;
}
}
for (int i = 0; i < N; i++) {
}
for (int i = 0; i < N; i++) {
ans += B[i + A[i]];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int N, A[200005], B[200005];
long long ans;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
if (i - A[i] > 0) {
B[i - A[i]]++;
}
}
for (int i = 0; i < N; i++) {
}
for (int i = 0; i < N; i++) {
if (i + A[i] < 200005) {
ans += B[i + A[i]];
}
}
cout << ans << endl;
return 0;
} | replace | 15 | 16 | 15 | 18 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #include <boost/multiprecision/cpp_ll.hpp>
// typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9 + 7)
// #define i_7 998244353
#define i_5 i_7 - 2
ll mod(ll a) {
ll c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
typedef pair<ll, ll> l_l;
ll inf = (ll)1E18;
#define rep(i, l, r) for (ll i = l; i <= r; i++)
#define pb push_back
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]);
void Min(ll &pos, ll val) { pos = min(pos, val); }
void Add(ll &pos, ll val) { pos = mod(pos + val); }
dd EPS = 1E-9;
#define endl "\n"
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
int main() {
fastio ll n;
cin >> n;
ll a[n];
rep(i, 0, n - 1) cin >> a[i];
ll dp[n + 1];
rep(i, 0, n) dp[i] = 0;
ll ans = 0;
rep(i, 0, n - 1) {
if (0 <= i - a[i] && i - a[i] <= n) {
ans += dp[i - a[i]];
}
dp[a[i] + i]++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #include <boost/multiprecision/cpp_ll.hpp>
// typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9 + 7)
// #define i_7 998244353
#define i_5 i_7 - 2
ll mod(ll a) {
ll c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
typedef pair<ll, ll> l_l;
ll inf = (ll)1E18;
#define rep(i, l, r) for (ll i = l; i <= r; i++)
#define pb push_back
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]);
void Min(ll &pos, ll val) { pos = min(pos, val); }
void Add(ll &pos, ll val) { pos = mod(pos + val); }
dd EPS = 1E-9;
#define endl "\n"
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
int main() {
fastio ll n;
cin >> n;
ll a[n];
rep(i, 0, n - 1) cin >> a[i];
ll dp[n + 1];
rep(i, 0, n) dp[i] = 0;
ll ans = 0;
rep(i, 0, n - 1) {
if (0 <= i - a[i] && i - a[i] <= n) {
ans += dp[i - a[i]];
}
if (0 <= a[i] + i && a[i] + i <= n) {
dp[a[i] + i]++;
}
}
cout << ans << endl;
return 0;
}
| replace | 53 | 54 | 53 | 56 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Cr7 \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define N 100100
ll n, a[N];
map<ll, ll> mp;
int main() {
Cr7 cin >> n;
for (ll i = 1; i <= n; i++)
cin >> a[i];
for (ll i = 2; i <= n; i++)
mp[a[i] + a[1] - i + 1]++;
ll need = 0, Res = mp[0];
for (ll i = 2; i <= n; i++) {
need--;
need -= (a[i] - a[i - 1]);
Res += mp[need];
}
cout << Res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Cr7 \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define N 200200
ll n, a[N];
map<ll, ll> mp;
int main() {
Cr7 cin >> n;
for (ll i = 1; i <= n; i++)
cin >> a[i];
for (ll i = 2; i <= n; i++)
mp[a[i] + a[1] - i + 1]++;
ll need = 0, Res = mp[0];
for (ll i = 2; i <= n; i++) {
need--;
need -= (a[i] - a[i - 1]);
Res += mp[need];
}
cout << Res << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02691 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int main() {
int n;
cin >> n;
ll sum = 0;
map<int, int> mp;
fo(i, 1, n) {
cin >> a[i];
sum += mp[i - a[i]];
mp[a[i] + i]++;
}
cout << sum << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int main() {
int n;
cin >> n;
ll sum = 0;
map<int, int> mp;
fo(i, 1, n) {
cin >> a[i];
sum += mp[i - a[i]];
mp[a[i] + i]++;
}
cout << sum << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define print(a, n) \
for (LL e = 0; e < n; e++) \
cout << a[e] << " "; \
cout << endl
#define read(a, n) \
for (LL e = 0; e < n; e++) \
cin >> a[e];
using namespace std;
int main() {
fastio;
LL n;
cin >> n;
LL a[n];
read(a, n);
LL ans = 0;
for (LL i = 1; i <= n; i++) {
for (LL j = 0; j + i < n; j++) {
if (a[j] + a[j + i] == i)
ans++;
}
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define print(a, n) \
for (LL e = 0; e < n; e++) \
cout << a[e] << " "; \
cout << endl
#define read(a, n) \
for (LL e = 0; e < n; e++) \
cin >> a[e];
using namespace std;
int main() {
fastio;
LL n;
cin >> n;
LL a[n];
read(a, n);
LL ans = 0;
map<int, int> m;
for (int i = 1; i <= n; i++) {
ans += m[i - a[i - 1]];
m[i + a[i - 1]]++;
}
cout << ans << "\n";
return 0;
}
| replace | 24 | 29 | 24 | 29 | TLE | |
p02691 | C++ | Runtime Error | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mkpr(x1, x2) make_pair(x1, x2)
typedef long long int ll;
// stack<char> stk;
// set<ll> sll;
// map<string,ll> mp,mp1;
// map<pair<ll,ll>,ll>::iterator iter;
// map<ll,ll> mp;
// deque<char> deq;
// vector<ll> vll;
ll num[ten52];
ll num2[ten52];
int main(void) {
// double ans=0.0,d,d1,d2;
// float f,g,h;
long long int m, n, i, j, k = 1;
long long int a, a1, a2, a3, sum;
string s, s1, s2;
// char c,c1;
sum = a = a1 = a2 = a3 = 0;
cin >> n;
for (i = 1; i <= n; i++)
cin >> num[i];
for (i = 1; i <= n; i++)
num2[i + num[i]]++;
for (i = 1; i <= n; i++) {
if (i - num[i] > 0)
sum += num2[i - num[i]];
}
cout << sum;
return 0;
}
| #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mkpr(x1, x2) make_pair(x1, x2)
typedef long long int ll;
// stack<char> stk;
// set<ll> sll;
// map<string,ll> mp,mp1;
// map<pair<ll,ll>,ll>::iterator iter;
// map<ll,ll> mp;
// deque<char> deq;
// vector<ll> vll;
ll num[ten52];
ll num2[ten52];
int main(void) {
// double ans=0.0,d,d1,d2;
// float f,g,h;
long long int m, n, i, j, k = 1;
long long int a, a1, a2, a3, sum;
string s, s1, s2;
// char c,c1;
sum = a = a1 = a2 = a3 = 0;
cin >> n;
for (i = 1; i <= n; i++)
cin >> num[i];
for (i = 1; i <= n; i++)
if (i + num[i] <= n)
num2[i + num[i]]++;
for (i = 1; i <= n; i++) {
if (i - num[i] > 0)
sum += num2[i - num[i]];
}
cout << sum;
return 0;
}
| replace | 45 | 46 | 45 | 47 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
int main() {
ll n, ans = 0;
cin >> n;
vector<ll> a(n);
for (auto &&e : a) {
cin >> e;
}
for (int i = 0; i < n; ++i) {
for (int j = i + a[i] + 1; j < n; ++j) {
if (a[j] == j - a[i] - i) {
ans++;
}
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
int main() {
ll n, ans = 0;
cin >> n;
vector<ll> a(n);
for (auto &&e : a) {
cin >> e;
}
map<ll, ll> minus, plus;
for (ll i = 0; i < n; ++i) {
minus[i - a[i]]++;
plus[i + a[i]]++;
}
for (const auto &e : plus) {
ans += minus[e.first] * e.second;
}
cout << ans;
} | replace | 12 | 18 | 12 | 19 | TLE | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define DEBUG(x) cout << #x << ": " << (x) << '\n'
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << ' ' << v[i]; \
cout << '\n'
#define ALL(a) (a).begin(), (a).end()
template <typename T> inline void CHMAX(T &a, const T b) {
if (a < b)
a = b;
}
template <typename T> inline void CHMIN(T &a, const T b) {
if (a > b)
a = b;
}
constexpr ll MOD = 1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
const double EPS = 1e-9;
#define EQ0(x) (abs((x)) < EPS)
#define EQ(a, b) (abs((a) - (b)) < EPS)
int cnt[425252];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout<<setprecision(10)<<fixed;
int n;
ll a[252521], b[252521];
cin >> n;
REP(i, n) {
cin >> a[i];
b[i] = i - a[i];
if (0 <= b[i] && b[i] <= n * 2) {
++cnt[b[i]];
}
}
ll ans = 0;
REP(i, n) { ans += cnt[a[i] + i]; }
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define DEBUG(x) cout << #x << ": " << (x) << '\n'
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << ' ' << v[i]; \
cout << '\n'
#define ALL(a) (a).begin(), (a).end()
template <typename T> inline void CHMAX(T &a, const T b) {
if (a < b)
a = b;
}
template <typename T> inline void CHMIN(T &a, const T b) {
if (a > b)
a = b;
}
constexpr ll MOD = 1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
const double EPS = 1e-9;
#define EQ0(x) (abs((x)) < EPS)
#define EQ(a, b) (abs((a) - (b)) < EPS)
int cnt[425252];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout<<setprecision(10)<<fixed;
int n;
ll a[252521], b[252521];
cin >> n;
REP(i, n) {
cin >> a[i];
b[i] = i - a[i];
if (0 <= b[i] && b[i] <= n * 2) {
++cnt[b[i]];
}
}
ll ans = 0;
REP(i, n) {
if (a[i] < n) {
ans += cnt[a[i] + i];
}
}
cout << ans << '\n';
return 0;
}
| replace | 56 | 57 | 56 | 61 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, l, r) for (int i = int(l); i < int(r); i++)
#define rep(i, r) rng(i, 0, r)
#define rrng(i, l, r) for (int i = int(r) - 1; i >= int(l); i--)
#define rrep(i, r) rrng(i, 0, r)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define si(x) int(x.size())
#define inf INT_MAX / 2 - 100
#define infl LLONG_MAX / 3
#ifdef LOCAL
#define dmp(x) cerr << __LINE__ << ' ' << #x << ' ' << x << endl
#else
#define dmp(x) void(0)
#endif
template <class t, class u> bool chmax(t &a, u b) {
if (a < b)
a = b;
return a < b;
}
template <class t, class u> bool chmin(t &a, u b) {
if (b < a)
a = b;
return b < a;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vector<vector<t>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
ll readl(void) {
ll x;
cin >> x;
return x;
}
int readi(void) {
int x;
cin >> x;
return x;
}
string readstr() {
string s;
cin >> s;
return s;
}
vi readvi(int n, int off = 0) {
vi v(n);
rep(i, n) v[i] = readi(), v[i] += off;
return v;
}
vl readvl(int n, int off = 0) {
vl v(n);
rep(i, n) v[i] = readl(), v[i] += off;
return v;
}
template <class t> void print(t x, int suc = 1) {
cout << x;
if (suc == 1)
cout << "\n";
if (suc == 2)
cout << " ";
}
template <class t> void print(const vc<t> &v, int suc = 1) {
rep(i, si(v)) print(v[i], i == int(si(v)) - 1 ? 1 : suc);
}
template <class t> bool inc(t a, t b, t c) { return !(c < b || b < a); }
template <class t> void compress(vc<t> &v) {
sort(all(v));
v.erase(unique(all(v)), v.ed);
}
template <class t> int lwb(const vc<t> &v, const t &a) {
return lower_bound(all(v), a) - v.bg;
}
template <class t> struct Compress {
vc<t> v;
Compress() = default;
Compress(const vc<t> &x) { add(x); }
Compress(const initializer_list<vc<t>> &x) {
for (auto &p : x)
add(p);
}
void add(const t &x) { v.eb(x); }
void add(const vc<t> &x) { copy(all(x), back_inserter(v)); }
void build() { compress(v); }
int get(const t &x) const { return lwb(v, x); }
vc<t> get(const vc<t> &x) const {
vc<t> res(x);
for (auto &p : res)
p = get(p);
return res;
}
const t &operator[](int x) const { return v[x]; }
int size() { return v.size(); }
};
void Yes(bool ex = true) {
cout << "Yes\n";
if (ex)
exit(0);
}
void YES(bool ex = true) {
cout << "YES\n";
if (ex)
exit(0);
}
void No(bool ex = true) {
cout << "No\n";
if (ex)
exit(0);
}
void NO(bool ex = true) {
cout << "NO\n";
if (ex)
exit(0);
}
void orYes(bool x, bool ex = true) {
if (x)
Yes(ex);
else
No(ex);
}
void orYES(bool x, bool ex = true) {
if (x)
YES(ex);
else
NO(ex);
}
void Possible(bool ex = true) {
cout << "Possible\n";
if (ex)
exit(0);
}
void POSSIBLE(bool ex = true) {
cout << "POSSIBLE\n";
if (ex)
exit(0);
}
void Impossible(bool ex = true) {
cout << "Impossible\n";
if (ex)
exit(0);
}
void IMPOSSIBLE(bool ex = true) {
cout << "IMPOSSIBLE\n";
if (ex)
exit(0);
}
void orPossible(bool x, bool ex = true) {
if (x)
Possible(ex);
else
Impossible(ex);
}
void orPOSSIBLE(bool x, bool ex = true) {
if (x)
POSSIBLE(ex);
else
IMPOSSIBLE(ex);
}
ll n, a[100005], ans;
map<ll, ll> p;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(0);
cin >> n;
rep(i, n) {
cin >> a[i];
ans += p[i - a[i]];
p[i + a[i]]++;
}
print(ans);
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, l, r) for (int i = int(l); i < int(r); i++)
#define rep(i, r) rng(i, 0, r)
#define rrng(i, l, r) for (int i = int(r) - 1; i >= int(l); i--)
#define rrep(i, r) rrng(i, 0, r)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define si(x) int(x.size())
#define inf INT_MAX / 2 - 100
#define infl LLONG_MAX / 3
#ifdef LOCAL
#define dmp(x) cerr << __LINE__ << ' ' << #x << ' ' << x << endl
#else
#define dmp(x) void(0)
#endif
template <class t, class u> bool chmax(t &a, u b) {
if (a < b)
a = b;
return a < b;
}
template <class t, class u> bool chmin(t &a, u b) {
if (b < a)
a = b;
return b < a;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vector<vector<t>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vc<int>;
using vl = vc<ll>;
ll readl(void) {
ll x;
cin >> x;
return x;
}
int readi(void) {
int x;
cin >> x;
return x;
}
string readstr() {
string s;
cin >> s;
return s;
}
vi readvi(int n, int off = 0) {
vi v(n);
rep(i, n) v[i] = readi(), v[i] += off;
return v;
}
vl readvl(int n, int off = 0) {
vl v(n);
rep(i, n) v[i] = readl(), v[i] += off;
return v;
}
template <class t> void print(t x, int suc = 1) {
cout << x;
if (suc == 1)
cout << "\n";
if (suc == 2)
cout << " ";
}
template <class t> void print(const vc<t> &v, int suc = 1) {
rep(i, si(v)) print(v[i], i == int(si(v)) - 1 ? 1 : suc);
}
template <class t> bool inc(t a, t b, t c) { return !(c < b || b < a); }
template <class t> void compress(vc<t> &v) {
sort(all(v));
v.erase(unique(all(v)), v.ed);
}
template <class t> int lwb(const vc<t> &v, const t &a) {
return lower_bound(all(v), a) - v.bg;
}
template <class t> struct Compress {
vc<t> v;
Compress() = default;
Compress(const vc<t> &x) { add(x); }
Compress(const initializer_list<vc<t>> &x) {
for (auto &p : x)
add(p);
}
void add(const t &x) { v.eb(x); }
void add(const vc<t> &x) { copy(all(x), back_inserter(v)); }
void build() { compress(v); }
int get(const t &x) const { return lwb(v, x); }
vc<t> get(const vc<t> &x) const {
vc<t> res(x);
for (auto &p : res)
p = get(p);
return res;
}
const t &operator[](int x) const { return v[x]; }
int size() { return v.size(); }
};
void Yes(bool ex = true) {
cout << "Yes\n";
if (ex)
exit(0);
}
void YES(bool ex = true) {
cout << "YES\n";
if (ex)
exit(0);
}
void No(bool ex = true) {
cout << "No\n";
if (ex)
exit(0);
}
void NO(bool ex = true) {
cout << "NO\n";
if (ex)
exit(0);
}
void orYes(bool x, bool ex = true) {
if (x)
Yes(ex);
else
No(ex);
}
void orYES(bool x, bool ex = true) {
if (x)
YES(ex);
else
NO(ex);
}
void Possible(bool ex = true) {
cout << "Possible\n";
if (ex)
exit(0);
}
void POSSIBLE(bool ex = true) {
cout << "POSSIBLE\n";
if (ex)
exit(0);
}
void Impossible(bool ex = true) {
cout << "Impossible\n";
if (ex)
exit(0);
}
void IMPOSSIBLE(bool ex = true) {
cout << "IMPOSSIBLE\n";
if (ex)
exit(0);
}
void orPossible(bool x, bool ex = true) {
if (x)
Possible(ex);
else
Impossible(ex);
}
void orPOSSIBLE(bool x, bool ex = true) {
if (x)
POSSIBLE(ex);
else
IMPOSSIBLE(ex);
}
ll n, a[200005], ans;
map<ll, ll> p;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(0);
cin >> n;
rep(i, n) {
cin >> a[i];
ans += p[i - a[i]];
p[i + a[i]]++;
}
print(ans);
}
| replace | 182 | 183 | 182 | 183 | 0 | |
p02691 | C++ | Time Limit Exceeded | #include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <iterator> //集合演算(積集合,和集合,差集合など)
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 // 10^5:最大のrange(素数列挙などで使用)
// debug
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) \
cout << " " << v[i]; \
cout << endl
#define DEBUG_ARR(v, n) \
cout << #v << ":"; \
REP(i, n) \
cout << " " << v[i]; \
cout << endl
ll N;
vector<ll> A;
set<ll> X;
map<ll, vector<ll>> Lmap;
map<ll, vector<ll>> Rmap;
signed main() {
ll cnt = 0;
cin >> N;
REP(i, N) {
ll ai;
cin >> ai;
// Li = i + Ai
ll l = i + ai;
Lmap[l].push_back(i);
// Rj = j - Aj
ll r = i - ai;
Rmap[r].push_back(i);
// とりうるXを保存
X.insert(l);
X.insert(r);
}
for (auto x : X) {
// cout << "x: " << x << endl;
// DEBUG_VEC(Lmap[x]);
// DEBUG_VEC(Rmap[x]);
for (auto i : Lmap[x]) {
for (auto j : Rmap[x]) {
if (i < j) {
cnt++;
}
}
}
}
cout << cnt << endl;
} | #include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <iterator> //集合演算(積集合,和集合,差集合など)
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 // 10^5:最大のrange(素数列挙などで使用)
// debug
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) \
cout << " " << v[i]; \
cout << endl
#define DEBUG_ARR(v, n) \
cout << #v << ":"; \
REP(i, n) \
cout << " " << v[i]; \
cout << endl
ll N;
vector<ll> A;
set<ll> X;
map<ll, vector<ll>> Lmap;
map<ll, vector<ll>> Rmap;
signed main() {
ll cnt = 0;
cin >> N;
REP(i, N) {
ll ai;
cin >> ai;
// Li = i + Ai
ll l = i + ai;
Lmap[l].push_back(i);
// Rj = j - Aj
ll r = i - ai;
Rmap[r].push_back(i);
// とりうるXを保存
X.insert(l);
X.insert(r);
}
for (auto x : X) {
// cout << "x: " << x << endl;
// DEBUG_VEC(Lmap[x]);
// DEBUG_VEC(Rmap[x]);
cnt += Lmap[x].size() * Rmap[x].size();
}
cout << cnt << endl;
} | replace | 83 | 91 | 83 | 85 | TLE | |
p02691 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
int binary_search(vector<int> v, int n) { // sorted v, count v=n
if (v.size() == 0)
return 0;
if (v[0] > n)
return 0;
if (v[v.size() - 1] < n)
return 0;
int l, r, mid, max, min;
l = 0;
r = v.size();
if (v[v.size() - 1] == n) {
max = v.size() - 1;
} else {
while (r - l > 1) {
mid = (l + r) / 2;
if (v[mid] <= n) { // v[l]<=n<v[r]
l = mid;
} else {
r = mid;
}
}
max = l; // max means v[all]<=n. all<=max
}
l = 0;
r = v.size();
if (v[0] == n) {
min = 0;
} else {
while (r - l > 1) {
mid = (l + r) / 2;
if (n <= v[mid]) { // v[l]<n<=v[r]
r = mid;
} else {
l = mid;
}
}
min = r; // min means v[all]<=n. all>=min
}
// cout<<max<<" "<<min<<endl;
return max - min + 1;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
long long int cnt = 0;
vector<int> v;
rep(i, n) {
// count v==i-a[i]
cnt += binary_search(v, i - a[i]);
// sorted_insert i+a[i]
v.insert(std::lower_bound(v.begin(), v.end(), i + a[i]), i + a[i]);
// binary_insert(v,i+a[i]);
// rep(i,v.size())cout<<v[i]<<" ";
// cout<<endl;
}
cout << cnt << endl;
/*
int k;
cin>>k;
binary_insert(a,k);
rep(i,a.size())cout<<a[i]<<" ";
cout<<endl;
*/
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
int binary_search(vector<int> v, int n) { // sorted v, count v=n
if (v.size() == 0)
return 0;
if (v[0] > n)
return 0;
if (v[v.size() - 1] < n)
return 0;
int l, r, mid, max, min;
l = 0;
r = v.size();
if (v[v.size() - 1] == n) {
max = v.size() - 1;
} else {
while (r - l > 1) {
mid = (l + r) / 2;
if (v[mid] <= n) { // v[l]<=n<v[r]
l = mid;
} else {
r = mid;
}
}
max = l; // max means v[all]<=n. all<=max
}
l = 0;
r = v.size();
if (v[0] == n) {
min = 0;
} else {
while (r - l > 1) {
mid = (l + r) / 2;
if (n <= v[mid]) { // v[l]<n<=v[r]
r = mid;
} else {
l = mid;
}
}
min = r; // min means v[all]<=n. all>=min
}
// cout<<max<<" "<<min<<endl;
return max - min + 1;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
long long int cnt = 0;
vector<int> v;
rep(i, n) {
// count v==i-a[i]
cnt += upper_bound(v.begin(), v.end(), i - a[i]) -
lower_bound(v.begin(), v.end(), i - a[i]);
// sorted_insert i+a[i]
v.insert(std::lower_bound(v.begin(), v.end(), i + a[i]), i + a[i]);
// binary_insert(v,i+a[i]);
// rep(i,v.size())cout<<v[i]<<" ";
// cout<<endl;
}
cout << cnt << endl;
/*
int k;
cin>>k;
binary_insert(a,k);
rep(i,a.size())cout<<a[i]<<" ";
cout<<endl;
*/
return 0;
}
| replace | 56 | 57 | 56 | 58 | TLE | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
int main() {
int n;
cin >> n;
vec<ll> a(n + 1);
vec<ll> ai(n + 1);
repc(i, 1, n) cin >> a[i];
repc(i, 1, n) { ai[i] = a[i] + i; }
int ans = 0;
repc(j, 2, n) {
int aj = j - a[j];
repc(i, 1, j - 1) {
if (ai[i] == aj)
ans++;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
int main() {
int n;
cin >> n;
vec<int> a(n);
rep(i, n) cin >> a[i];
map<int, int> mp;
ll ans = 0;
rep(i, n) {
int sa = i - a[i];
ans += mp[sa];
int wa = a[i] + i;
mp[wa]++;
}
cout << ans << endl;
return 0;
} | replace | 17 | 29 | 17 | 26 | TLE | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {
if (b > a)
return b;
else
return a;
}
int min(int a, int b) {
if (b < a)
return b;
else
return a;
}
const int INF = 1e18;
signed main() {
int N;
cin >> N;
vi A(N);
map<int, int> L, R;
rep(i, N) {
cin >> A[i];
L[A[i] + i]++;
R[i - A[i]]++;
}
int res = 0;
for (auto &l : L) {
for (auto &r : R) {
if (l.fi == r.fi)
res += l.se * r.se;
}
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {
if (b > a)
return b;
else
return a;
}
int min(int a, int b) {
if (b < a)
return b;
else
return a;
}
const int INF = 1e18;
signed main() {
int N;
cin >> N;
vi A(N);
map<int, int> L, R;
rep(i, N) {
cin >> A[i];
L[A[i] + i]++;
R[i - A[i]]++;
}
int res = 0;
for (auto &l : L) {
res += l.se * R[l.fi];
}
cout << res << endl;
return 0;
} | replace | 46 | 50 | 46 | 47 | TLE | |
p02691 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define PI 3.141592653589793238
#define mod 1000000007
#define endl '\n'
#define fastio \
; \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
int main() {
fastio;
int n;
cin >> n;
vi h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
vi neg(n), pos(n);
map<int, vector<int>> MP;
for (int i = 0; i < n; i++) {
neg[i] = i - h[i], pos[i] = i + h[i];
MP[neg[i]].pb(i);
}
ll prs = 0;
for (int i = 0; i < n - 1; i++) {
if (MP[pos[i]].size() == 0)
continue;
for (int j = 0; j < MP[pos[i]].size(); j++) {
if (MP[pos[i]][j] > i)
prs++;
}
// int k=MP[pos[i]].size();
// int idx=
}
cout << prs << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define PI 3.141592653589793238
#define mod 1000000007
#define endl '\n'
#define fastio \
; \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
int main() {
fastio;
int n;
cin >> n;
vi h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
vi neg(n), pos(n);
map<int, vector<int>> MP;
for (int i = 0; i < n; i++) {
neg[i] = i - h[i], pos[i] = i + h[i];
MP[neg[i]].pb(i);
}
ll prs = 0;
for (int i = 0; i < n - 1; i++) {
if (MP[pos[i]].size() == 0)
continue;
int k = MP[pos[i]].size();
int idx = lower_bound(MP[pos[i]].begin(), MP[pos[i]].end(), pos[i]) -
MP[pos[i]].begin();
prs += (k - idx);
}
cout << prs << endl;
return 0;
}
| replace | 37 | 45 | 37 | 41 | TLE | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
// snippets:tmp,cl,cvl,cs,co,coy,con,cov
int main() {
ll n;
cin >> n;
queue<ll> q;
queue<ll> qq;
vll d(500000, 0);
rep(i, n) {
ll a;
cin >> a;
q.push(a + i);
if (a > i)
continue;
d[i - a]++;
}
ll count = 0;
ll a = q.size();
rep(i, a) {
count += d[q.front()];
q.pop();
}
cout << count << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
// snippets:tmp,cl,cvl,cs,co,coy,con,cov
int main() {
ll n;
cin >> n;
queue<ll> q;
queue<ll> qq;
vll d(500000, 0);
rep(i, n) {
ll a;
cin >> a;
if (a > 200000)
continue;
q.push(a + i);
if (a > i)
continue;
d[i - a]++;
}
ll count = 0;
ll a = q.size();
rep(i, a) {
count += d[q.front()];
q.pop();
}
cout << count << endl;
} | insert | 22 | 22 | 22 | 24 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int n, m, cnt = 0, o, p, aa[220000], cntl = 0, ab[220000];
pair<int, int> pp[220000];
string s, ss[220000];
char c, cc[5000][5000] = {};
queue<int> que;
signed main() {
cin >> n;
rep(i, n) {
cin >> aa[i];
pp[i].first = aa[i] + i + 1;
pp[i].second = i + 1 - aa[i];
if (pp[i].second >= 2) {
ab[pp[i].second]++;
}
}
rep(i, n) {
cnt += ab[pp[i].first];
if (pp[i].second >= 2) {
ab[pp[i].second]--;
}
}
cout << cnt;
} | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int n, m, cnt = 0, o, p, aa[220000], cntl = 0, ab[220000];
pair<int, int> pp[220000];
string s, ss[220000];
char c, cc[5000][5000] = {};
queue<int> que;
signed main() {
cin >> n;
rep(i, n) {
cin >> aa[i];
pp[i].first = aa[i] + i + 1;
pp[i].second = i + 1 - aa[i];
if (pp[i].second >= 2) {
ab[pp[i].second]++;
}
}
rep(i, n) {
if (pp[i].first < 200010) {
cnt += ab[pp[i].first];
}
if (pp[i].second >= 2) {
ab[pp[i].second]--;
}
}
cout << cnt;
} | replace | 28 | 29 | 28 | 31 | 0 | |
p02691 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
#include <math.h>
// #include <stack>
// #include <queue>
/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
#define MAXV 1000000
ll VALM[MAXV] = {};
ll VALP[MAXV] = {};
ll C;
ll N;
ll M;
ll K;
int main() {
cin >> N;
ll H[N + 1];
for (int ni = 1; ni <= N; ni++) {
ll tmp;
cin >> tmp;
H[ni] = tmp;
}
ll cnt = 0;
for (int ni = N; ni >= 1; ni--) {
ll hi = H[ni];
if (hi < MAXV) {
VALP[ni + hi]++;
cnt += VALM[ni + hi];
if (ni - hi >= 0) {
VALM[ni - hi]++;
}
}
}
cout << cnt << endl;
} | #include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
#include <math.h>
// #include <stack>
// #include <queue>
/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
#define MAXV 1000000
ll VALM[MAXV] = {};
ll VALP[MAXV] = {};
ll C;
ll N;
ll M;
ll K;
int main() {
cin >> N;
ll H[N + 1];
for (int ni = 1; ni <= N; ni++) {
ll tmp;
cin >> tmp;
H[ni] = tmp;
}
ll cnt = 0;
for (int ni = N; ni >= 1; ni--) {
ll hi = H[ni];
if (hi < MAXV) {
if (ni + hi < MAXV) {
VALP[ni + hi]++;
cnt += VALM[ni + hi];
}
if (ni - hi >= 0) {
VALM[ni - hi]++;
}
}
}
cout << cnt << endl;
} | replace | 50 | 52 | 50 | 54 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;
// REPEAT
// ----------------------------------------
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REPA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) \
;
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) { \
cout << (a)[i] << " "; \
} \
cout << endl;
// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), (ll)0)
#define COUNT(x, y) count(ALL(x), y);
ll tousa_no_wa(ld a, ll n, ld d) {
return (ld(n) / (ll)2) * ((ll)2 * a + (n - (ll)1) * d);
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// 素因数分解
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
// 素数テーブル
vector<bool> prime_table(ll n) {
vector<bool> prime(n + 1, true);
if (n >= 0)
prime[0] = false;
if (n >= 1)
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (!prime[i])
continue;
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
return prime;
}
// 素数判定
bool is_prime(ll x) {
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return true;
}
// 約数列挙
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
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 (b < a) {
a = b;
return 1;
}
return 0;
}
// PRINT
// ----------------------------------------
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
// DEBUG
// ----------------------------------------
/*
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
rep(i, v.size()) {
cout << i << ":" << v[i] << " ";
}
cout << endl;
#else
(void)v;
#endif
}
*/
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
REP(z, v.size()) cerr << " " << v[z]; \
cerr << "\n";
// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000
// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;
struct UnionFind {
vll data;
UnionFind(ll sz) { data.assign(sz, -1); }
bool unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) {
return (false);
}
if (data[x] > data[y]) {
swap(x, y);
}
data[x] += data[y];
data[y] = x;
return (true);
}
ll find(ll k) {
if (data[k] < 0) {
return (k);
}
return (data[k] = find(data[k]));
}
ll size(ll k) { return (-data[find(k)]); }
ll same(ll x, ll y) { return (find(x) == find(y)); }
};
// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
// 二項係数ライブラリ
template <class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef() {}
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
init(n);
}
constexpr void init(int n) noexcept {
fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
int MOD = fact_[0].getmod();
for (int i = 2; i < n; i++) {
fact_[i] = fact_[i - 1] * i;
inv_[i] = -inv_[MOD % i] * (MOD / i);
finv_[i] = finv_[i - 1] * inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0)
return 0;
return fact_[n] * finv_[k] * finv_[n - k];
}
constexpr T fact(int n) const noexcept {
if (n < 0)
return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if (n < 0)
return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if (n < 0)
return 0;
return finv_[n];
}
};
// その他困ったらここ
// https://ei1333.github.io/luzhiled/
void Main() {
ll n;
cin >> n;
vll a(n, 0);
FOR(i, 1, n) cin >> a[i];
map<ll, ll> check;
// vll check(MAX(a) + n + 1, 0);
FOR(i, 1, n) check[i + a[i]]++;
ll ans = 0;
FOR(i, 1, n) {
if (i - a[i] < 0)
continue;
ans += check[i - a[i]];
}
COUT(ans);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
/*
3 2
*/
| #include <bits/stdc++.h>
using namespace std;
// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;
// REPEAT
// ----------------------------------------
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REPA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) \
;
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) { \
cout << (a)[i] << " "; \
} \
cout << endl;
// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), (ll)0)
#define COUNT(x, y) count(ALL(x), y);
ll tousa_no_wa(ld a, ll n, ld d) {
return (ld(n) / (ll)2) * ((ll)2 * a + (n - (ll)1) * d);
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// 素因数分解
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
// 素数テーブル
vector<bool> prime_table(ll n) {
vector<bool> prime(n + 1, true);
if (n >= 0)
prime[0] = false;
if (n >= 1)
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (!prime[i])
continue;
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
return prime;
}
// 素数判定
bool is_prime(ll x) {
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return true;
}
// 約数列挙
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
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 (b < a) {
a = b;
return 1;
}
return 0;
}
// PRINT
// ----------------------------------------
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
// DEBUG
// ----------------------------------------
/*
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
rep(i, v.size()) {
cout << i << ":" << v[i] << " ";
}
cout << endl;
#else
(void)v;
#endif
}
*/
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
REP(z, v.size()) cerr << " " << v[z]; \
cerr << "\n";
// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000
// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;
struct UnionFind {
vll data;
UnionFind(ll sz) { data.assign(sz, -1); }
bool unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) {
return (false);
}
if (data[x] > data[y]) {
swap(x, y);
}
data[x] += data[y];
data[y] = x;
return (true);
}
ll find(ll k) {
if (data[k] < 0) {
return (k);
}
return (data[k] = find(data[k]));
}
ll size(ll k) { return (-data[find(k)]); }
ll same(ll x, ll y) { return (find(x) == find(y)); }
};
// modint: mod 計算を int を扱うように扱える構造体
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
// 二項係数ライブラリ
template <class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef() {}
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
init(n);
}
constexpr void init(int n) noexcept {
fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
int MOD = fact_[0].getmod();
for (int i = 2; i < n; i++) {
fact_[i] = fact_[i - 1] * i;
inv_[i] = -inv_[MOD % i] * (MOD / i);
finv_[i] = finv_[i - 1] * inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0)
return 0;
return fact_[n] * finv_[k] * finv_[n - k];
}
constexpr T fact(int n) const noexcept {
if (n < 0)
return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if (n < 0)
return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if (n < 0)
return 0;
return finv_[n];
}
};
// その他困ったらここ
// https://ei1333.github.io/luzhiled/
void Main() {
ll n;
cin >> n;
vll a(n + 1, 0);
FOR(i, 1, n) cin >> a[i];
map<ll, ll> check;
// vll check(MAX(a) + n + 1, 0);
FOR(i, 1, n) check[i + a[i]]++;
ll ans = 0;
FOR(i, 1, n) {
if (i - a[i] < 0)
continue;
ans += check[i - a[i]];
}
COUT(ans);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
/*
3 2
*/
| replace | 317 | 318 | 317 | 318 | 0 | |
p02691 | C++ | Runtime Error | /*
Fuad Ashraful Mehmet Islam
University of Asia Pacific,Bangladesh
Date:6th May 2020
ToDo:
https://codeforces.com/problemset/problem/287/B
https://atcoder.jp/contests/abc166/tasks/abc166_e
*/
#include <bits/stdc++.h>
#define dbg(x) cerr << __LINE__ << " where " << #x << " = " << x << endl
#define all(x) (x).begin(), (x).end()
using namespace std;
template <class T> inline void read(T &res) {
res = 0;
bool bo = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
bo = 1;
else
res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
if (bo)
res = ~res + 1;
}
const int N = 2e5 + 5;
typedef long long ll;
int len, _, n, d, k, m, l, c, cs = 1;
vector<ll> tree[N];
ll a[N], cal[N];
void Solve() {
read(n);
for (int i = 1; i <= n; ++i)
read(a[i]);
} /// end func
void build(int l, int r, int node = 1) {
if (l == r) {
tree[node].push_back(a[l] + l);
return;
} // base case
int mid = (l + r) >> 1;
build(l, mid, node << 1);
build(mid + 1, r, node << 1 | 1);
merge(all(tree[node << 1]), all(tree[node << 1 | 1]),
back_inserter(tree[node]));
} /// end
ll query(int l, int r, int x, int y, ll val, int node = 1) {
if (l > y or r < x)
return 0;
if (l >= x and r <= y) {
ll lo = lower_bound(all(tree[node]), val) - tree[node].begin();
ll up = upper_bound(all(tree[node]), val) - tree[node].begin();
return up - lo;
} /// overlaped
int mid = (l + r) >> 1;
return query(l, mid, x, y, val, node << 1) +
query(mid + 1, r, x, y, val, node << 1 | 1);
} /// end func
int main() {
// for(read(_);_;_--)
Solve();
build(1, n);
ll ans = 0LL;
for (int i = 1; i <= n; ++i) {
ans += query(1, n, 1, i, i - a[i]);
}
cout << ans << "\n";
return 0;
} | /*
Fuad Ashraful Mehmet Islam
University of Asia Pacific,Bangladesh
Date:6th May 2020
ToDo:
https://codeforces.com/problemset/problem/287/B
https://atcoder.jp/contests/abc166/tasks/abc166_e
*/
#include <bits/stdc++.h>
#define dbg(x) cerr << __LINE__ << " where " << #x << " = " << x << endl
#define all(x) (x).begin(), (x).end()
using namespace std;
template <class T> inline void read(T &res) {
res = 0;
bool bo = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
bo = 1;
else
res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
if (bo)
res = ~res + 1;
}
const int N = 2e5 + 5;
typedef long long ll;
int len, _, n, d, k, m, l, c, cs = 1;
vector<ll> tree[N * 4];
ll a[N], cal[N];
void Solve() {
read(n);
for (int i = 1; i <= n; ++i)
read(a[i]);
} /// end func
void build(int l, int r, int node = 1) {
if (l == r) {
tree[node].push_back(a[l] + l);
return;
} // base case
int mid = (l + r) >> 1;
build(l, mid, node << 1);
build(mid + 1, r, node << 1 | 1);
merge(all(tree[node << 1]), all(tree[node << 1 | 1]),
back_inserter(tree[node]));
} /// end
ll query(int l, int r, int x, int y, ll val, int node = 1) {
if (l > y or r < x)
return 0;
if (l >= x and r <= y) {
ll lo = lower_bound(all(tree[node]), val) - tree[node].begin();
ll up = upper_bound(all(tree[node]), val) - tree[node].begin();
return up - lo;
} /// overlaped
int mid = (l + r) >> 1;
return query(l, mid, x, y, val, node << 1) +
query(mid + 1, r, x, y, val, node << 1 | 1);
} /// end func
int main() {
// for(read(_);_;_--)
Solve();
build(1, n);
ll ans = 0LL;
for (int i = 1; i <= n; ++i) {
ans += query(1, n, 1, i, i - a[i]);
}
cout << ans << "\n";
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
ll n, x, count = 0;
cin >> n;
vector<ll> v1(100000);
for (ll i = 0; i < n; i++) {
cin >> x;
v1[i + x]++;
if (i - x > 0)
count += v1[i - x];
}
cout << count << "\n";
}
int main() {
fast();
solve();
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve() {
ll n, x, count = 0;
cin >> n;
map<ll, ll> v1;
for (ll i = 0; i < n; i++) {
cin >> x;
v1[i + x]++;
if (i - x > 0)
count += v1[i - x];
}
cout << count << "\n";
}
int main() {
fast();
solve();
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02691 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int64_t n;
cin >> n;
int64_t ans = 0;
vector<int64_t> h(n);
rep(i, n) cin >> h.at(i);
vector<int64_t> cnt(1000005);
rep(i, n) {
cnt.at(h.at(i) + i)++;
if (i - h.at(i) >= 0 && i - h.at(i) <= 1000000) {
ans += cnt.at(i - h.at(i));
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int64_t n;
cin >> n;
int64_t ans = 0;
vector<int64_t> h(n);
rep(i, n) cin >> h.at(i);
vector<int64_t> cnt(1000005);
rep(i, n) {
if (h.at(i) + i <= 1000000)
cnt.at(h.at(i) + i)++;
if (i - h.at(i) >= 0 && i - h.at(i) <= 1000000) {
ans += cnt.at(i - h.at(i));
}
}
cout << ans << endl;
}
| replace | 12 | 13 | 12 | 14 | 0 | |
p02691 | C++ | Time Limit Exceeded | // Contest: AtCoder Beginner Contest 166 (https://atcoder.jp/contests/abc166)
// Problem: E: This Message Will Self-Destruct in 5s
// (https://atcoder.jp/contests/abc166/tasks/abc166_e)
// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#if __cplusplus >= 201703L
#include <optional>
#include <string_view>
#include <variant>
#endif
using namespace std;
#if __cplusplus >= 201703L
#define all(a) begin(a), end(a)
#define sz(x) ((int)size(x))
#else
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#endif
#define rep(a, b) for (int a = 0; a < (b); ++a)
#define reps(a, b, c) for (int a = (b); a < (c); ++a)
#define trav(a, b) for (auto &a : b)
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
#if __cplusplus >= 201703L
#define MAYBE_UNUSED [[maybe_unused]]
#else
#define MAYBE_UNUSED
#endif
MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937
rng((u32)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count());
// endregion }}}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi a(n);
trav(ai, a) cin >> ai;
ll cnt = 0;
multiset<int> s;
rep(i, n) cnt += s.count(i - a[i]), s.emplace(i + a[i]);
cout << cnt << '\n';
return 0;
} | // Contest: AtCoder Beginner Contest 166 (https://atcoder.jp/contests/abc166)
// Problem: E: This Message Will Self-Destruct in 5s
// (https://atcoder.jp/contests/abc166/tasks/abc166_e)
// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#if __cplusplus >= 201703L
#include <optional>
#include <string_view>
#include <variant>
#endif
using namespace std;
#if __cplusplus >= 201703L
#define all(a) begin(a), end(a)
#define sz(x) ((int)size(x))
#else
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#endif
#define rep(a, b) for (int a = 0; a < (b); ++a)
#define reps(a, b, c) for (int a = (b); a < (c); ++a)
#define trav(a, b) for (auto &a : b)
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
#if __cplusplus >= 201703L
#define MAYBE_UNUSED [[maybe_unused]]
#else
#define MAYBE_UNUSED
#endif
MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937
rng((u32)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count());
// endregion }}}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vi a(n);
trav(ai, a) cin >> ai;
ll cnt = 0;
map<int, int> s;
rep(i, n) cnt += s[i - a[i]], s[i + a[i]]++;
cout << cnt << '\n';
return 0;
} | replace | 93 | 95 | 93 | 95 | TLE | |
p02691 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<vector<int>> S(300000);
rep(i, N) {
int x = i - A[i];
if (x < 0)
continue;
if (x >= 300000)
continue;
S[x].push_back(i);
}
rep(i, 300000) sort(S[i].begin(), S[i].end());
long long ans = 0;
rep(i, N) {
int x = i + A[i];
int left = -1;
int right = (int)S[x].size();
while (right - left > 1) {
int mid = (right + left) / 2;
if (S[x][mid] <= i)
left = mid;
else
right = mid;
}
ans += (int)S[x].size() - right;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<vector<int>> S(300000);
rep(i, N) {
int x = i - A[i];
if (x < 0)
continue;
if (x >= 300000)
continue;
S[x].push_back(i);
}
rep(i, 300000) sort(S[i].begin(), S[i].end());
long long ans = 0;
rep(i, N) {
int x = i + A[i];
if (x < 0)
continue;
if (x > 300000)
continue;
int left = -1;
int right = (int)S[x].size();
while (right - left > 1) {
int mid = (right + left) / 2;
if (S[x][mid] <= i)
left = mid;
else
right = mid;
}
ans += (int)S[x].size() - right;
}
cout << ans << endl;
return 0;
}
| insert | 26 | 26 | 26 | 30 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.