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
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; #define SZ(a) (int)(a).size() using ll = long long; int main() { cin.sync_with_stdio(false); ll n, m; cin >> n >> m; if (n == 1) { printf("%lld\n", m); return 0; } int ans = 1; for (int i = 2; i * i <= m; i++) { int cnt = 0; while (m % i == 0) { m /= i; cnt++; if (cnt % n == 0) { ans *= i; } } } printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; #define SZ(a) (int)(a).size() using ll = long long; int main() { cin.sync_with_stdio(false); ll n, m; cin >> n >> m; if (n == 1) { printf("%lld\n", m); return 0; } int ans = 1; for (ll i = 2; i * i <= m; i++) { int cnt = 0; while (m % i == 0) { m /= i; cnt++; if (cnt % n == 0) { ans *= i; } } } printf("%d\n", ans); return 0; }
replace
18
19
18
19
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pi = pair<int, int>; constexpr int INF = (1 << 30) - 1; constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); } int main() { ll N, P; ll ans = 1; cin >> N >> P; for (int i = 2; i * i <= P; i++) { int cnt = 0; while (P % i == 0) { P /= i; cnt++; } cnt /= N; for (int j = 0; j < cnt; j++) { ans *= i; } } if (N == 1) { ans *= P; } cout << ans << endl; return (0); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pi = pair<int, int>; constexpr int INF = (1 << 30) - 1; constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); } int main() { ll N, P; ll ans = 1; cin >> N >> P; for (ll i = 2; i * i <= P; i++) { int cnt = 0; while (P % i == 0) { P /= i; cnt++; } cnt /= N; for (int j = 0; j < cnt; j++) { ans *= i; } } if (N == 1) { ans *= P; } cout << ans << endl; return (0); }
replace
18
19
18
19
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K, ans = 1; cin >> N >> K; if (N == 1) { cout << K << endl; return 0; } for (int i = 2; i * i <= K; i++) { int cnt = 0; ll tmp = i; while (K % tmp == 0) { cnt++; K /= tmp; } cnt /= N; for (int j = 0; j < cnt; j++) { ans *= tmp; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll N, K, ans = 1; cin >> N >> K; if (N == 1) { cout << K << endl; return 0; } for (int i = 2; i <= sqrt(K); i++) { int cnt = 0; ll tmp = i; while (K % tmp == 0) { cnt++; K /= tmp; } cnt /= N; for (int j = 0; j < cnt; j++) { ans *= tmp; } } cout << ans << endl; }
replace
13
14
13
14
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> int main() { long long n, p, ans{1}; scanf("%lld%lld", &n, &p); for (int i = 2; i * i <= p; i++) { if (p % i) continue; int tmp{}; while (!(p % i)) { p /= i; tmp++; } tmp /= n; for (int j = 0; j < tmp; j++) ans *= i; } if (n == 1) ans *= p; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> int main() { long long n, p, ans{1}; scanf("%lld%lld", &n, &p); for (long long i = 2; i * i <= p; i++) { if (p % i) continue; int tmp{}; while (!(p % i)) { p /= i; tmp++; } tmp /= n; for (int j = 0; j < tmp; j++) ans *= i; } if (n == 1) ans *= p; printf("%lld\n", ans); return 0; }
replace
5
6
5
6
TLE
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int lint; typedef pair<int, int> IP; typedef pair<lint, lint> LLP; typedef pair<char, char> CP; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define sort(v) sort((v).begin(), (v).end()) #define reverse(v) reverse((v).begin(), (v).end()) #define upper(v, hoge) upper_bound(v.begin(), v.end(), hoge) #define lower(v, hoge) lower_bound(v.begin(), v.end(), hoge) #define llower(v, hoge) *lower_bound(v.begin(), v.end(), hoge) #define lupper(v, hoge) *upper_bound(v.begin(), v.end(), hoge) vector<lint> prime_factorization(lint N) { // 素因数分解して配列で返す vector<lint> R; if (N < 2) return R; for (int i = 2; i * i <= N; i++) { while (N % i == 0) { R.push_back(i); N /= i; } } if (N != 1) { R.push_back(N); } return R; } int main() { lint N, P; cin >> N >> P; vector<lint> V = prime_factorization(P); sort(V); lint VS = V.size(); if (VS == 0) { cout << P << endl; return 0; } lint cnt = 1; lint ans = 1; for (int i = 1; i < VS; i++) { if (V[i - 1] == V[i]) { cnt++; } else { if (cnt / N * V[i - 1] != 0) { ans *= pow(V[i - 1], cnt / N); } cnt = 1; } } if (cnt / N * V[VS - 1] != 0) { ans *= pow(V[VS - 1], cnt / N); } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int lint; typedef pair<int, int> IP; typedef pair<lint, lint> LLP; typedef pair<char, char> CP; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define sort(v) sort((v).begin(), (v).end()) #define reverse(v) reverse((v).begin(), (v).end()) #define upper(v, hoge) upper_bound(v.begin(), v.end(), hoge) #define lower(v, hoge) lower_bound(v.begin(), v.end(), hoge) #define llower(v, hoge) *lower_bound(v.begin(), v.end(), hoge) #define lupper(v, hoge) *upper_bound(v.begin(), v.end(), hoge) vector<lint> prime_factorization(lint N) { // 素因数分解して配列で返す vector<lint> R; if (N < 2) return R; for (lint i = 2; i * i <= N; i++) { while (N % i == 0) { R.push_back(i); N /= i; } } if (N != 1) { R.push_back(N); } return R; } int main() { lint N, P; cin >> N >> P; vector<lint> V = prime_factorization(P); sort(V); lint VS = V.size(); if (VS == 0) { cout << P << endl; return 0; } lint cnt = 1; lint ans = 1; for (int i = 1; i < VS; i++) { if (V[i - 1] == V[i]) { cnt++; } else { if (cnt / N * V[i - 1] != 0) { ans *= pow(V[i - 1], cnt / N); } cnt = 1; } } if (cnt / N * V[VS - 1] != 0) { ans *= pow(V[VS - 1], cnt / N); } cout << ans << endl; }
replace
39
40
39
40
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p; return 0; } ll ans = 1; for (int i = 2; i * i <= p; i += 2) { ll cnt = 0; while (p % i == 0) { cnt++; p /= i; } if (cnt != 0) { cnt /= n; ans *= pow(i, cnt); } if (i == 2) { i = 1; } } cout << ans; // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p; return 0; } ll ans = 1; for (ll i = 2; i * i <= p; i += 2) { ll cnt = 0; while (p % i == 0) { cnt++; p /= i; } if (cnt != 0) { cnt /= n; ans *= pow(i, cnt); } if (i == 2) { i = 1; } } cout << ans; // your code goes here return 0; }
replace
14
15
14
15
TLE
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> using namespace std; #define int long long signed main() { int n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } int ans = 1; for (int i = 2;; i++) { int w = 1; for (int j = 0; j < n; j++) w *= i; if (p < w) break; if (!(p % w)) ans = i; } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> using namespace std; #define int long long signed main() { int n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } if (n > 50) { cout << 1 << endl; return 0; } int ans = 1; for (int i = 2;; i++) { int w = 1; for (int j = 0; j < n; j++) w *= i; if (p < w) break; if (!(p % w)) ans = i; } cout << ans << endl; }
insert
10
10
10
14
TLE
p03196
C++
Time Limit Exceeded
typedef long long ll; #include <bits/stdc++.h> using namespace std; int main() { ll n, p; std::cin >> n >> p; unordered_map<ll, ll> in; ll rem = p; for (int i = 2; i <= sqrt(p); i++) { while (rem % i == 0) { rem /= i; in[i]++; } } for (int i = 2; i <= rem; i++) { while (rem % i == 0) { rem /= i; in[i]++; } } ll result = 1; for (auto i : in) { result *= (ll)pow(i.first, (ll)(i.second / n)); } std::cout << result << std::endl; }
typedef long long ll; #include <bits/stdc++.h> using namespace std; int main() { ll n, p; std::cin >> n >> p; unordered_map<ll, ll> in; ll rem = p; for (int i = 2; i <= sqrt(p); i++) { while (rem % i == 0) { rem /= i; in[i]++; } } in[rem]++; ll result = 1; for (auto i : in) { result *= (ll)pow(i.first, (ll)(i.second / n)); } std::cout << result << std::endl; }
replace
16
22
16
18
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, a, b) for (ll i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } inline ll powint(unsigned long long x, ll y) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; y >>= 1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; r %= m; x %= m; y >>= 1; } return r; } 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; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif map<ll, ll> pd; void primediv(ll p) { for (int i = 2; i * i <= p; i++) { if (p % i == 0) { pd[i]++; p /= i; i = 1; } } pd[p]++; } void pr(ll n) { cout << n << endl; exit(0); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n, p; cin >> n >> p; if (p == 1) { pr(1); } if (n == 1) { pr(p); } primediv(p); dump(pd); ll ans = 1; for (auto &&e : pd) { ans *= powint(e.first, (e.second / n)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, a, b) for (ll i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } inline ll powint(unsigned long long x, ll y) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; y >>= 1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; r %= m; x %= m; y >>= 1; } return r; } 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; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif map<ll, ll> pd; void primediv(ll p) { for (ll i = 2; i * i <= p; i++) { if (p % i == 0) { pd[i]++; p /= i; i = 1; } } pd[p]++; } void pr(ll n) { cout << n << endl; exit(0); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n, p; cin >> n >> p; if (p == 1) { pr(1); } if (n == 1) { pr(p); } primediv(p); dump(pd); ll ans = 1; for (auto &&e : pd) { ans *= powint(e.first, (e.second / n)); } cout << ans << endl; return 0; }
replace
65
66
65
66
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long lint; lint n, p; lint rez; int main() { rez = 1; cin >> n >> p; if (n == 1) { cout << p << "\n"; return 0; } for (int i = 2; i * i <= p; i++) { int x = 0; while (p % i == 0) x++, p /= i; rez = rez * pow(i, x / n); } cout << rez << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; lint n, p; lint rez; int main() { rez = 1; cin >> n >> p; if (n == 1) { cout << p << "\n"; return 0; } for (int i = 2; 1LL * i * i <= p; i++) { int x = 0; while (p % i == 0) x++, p /= i; rez = rez * pow(i, x / n); } cout << rez << "\n"; return 0; }
replace
20
21
20
21
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll solve(ll N, ll P) { if (N == 1) return P; double x = powl(P, 1.0 / N); if (x < 2.0) return 1; // x >= 2 int d = (int)ceil(x); for (ll n = d; n >= 1; --n) { int cnt = 0; ll y = P; while (y % n == 0) { ++cnt; y /= n; } if (cnt >= N) return n; } return 1; } int main() { ll N, P; cin >> N >> P; cout << solve(N, P) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll solve(ll N, ll P) { if (N == 1) return P; double x = powl(P, 1.0 / N); if (x < 2.0) return 1; // x >= 2 int d = (int)ceil(x); for (ll n = d; n >= 2; --n) { int cnt = 0; ll y = P; while (y % n == 0) { ++cnt; y /= n; } if (cnt >= N) return n; } return 1; } int main() { ll N, P; cin >> N >> P; cout << solve(N, P) << endl; return 0; }
replace
15
16
15
16
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; ll p; map<ll, ll> insuu; void prime_factor(ll p) { ll k = p; for (int i = 2; i * i <= p; i++) { while (k % i == 0) { insuu[i]++; k /= i; } } if (k != 1) insuu[k] = 1; return; } int main() { ll n; cin >> n >> p; ll ans = 1; prime_factor(p); for (auto p : insuu) { for (int i = 0; i < p.S / n; i++) { ans *= p.F; } } COUT(ans); }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; ll p; map<ll, ll> insuu; void prime_factor(ll p) { ll k = p; for (ll i = 2; i * i <= p; i++) { while (k % i == 0) { insuu[i]++; k /= i; } } if (k != 1) insuu[k] = 1; return; } int main() { ll n; cin >> n >> p; ll ans = 1; prime_factor(p); for (auto p : insuu) { for (int i = 0; i < p.S / n; i++) { ans *= p.F; } } COUT(ans); }
replace
45
46
45
46
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 int main() { ll n, k; cin >> n >> k; ll ans = 1; if (n == 1) { cout << k; return 0; } for (int i = 2; i * i <= k; i += 2) { ll cnt = 0; while (k % i == 0) { cnt++; k /= i; } if (cnt != 0) { cnt = cnt / n; ans *= pow(i, cnt); } if (i == 2) { i--; } } cout << ans; // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 int main() { ll n, k; cin >> n >> k; ll ans = 1; if (n == 1) { cout << k; return 0; } for (ll i = 2; i * i <= k; i += 2) { ll cnt = 0; while (k % i == 0) { cnt++; k /= i; } if (cnt != 0) { cnt = cnt / n; ans *= pow(i, cnt); } if (i == 2) { i--; } } cout << ans; // your code goes here return 0; }
replace
14
15
14
15
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define PI acos(-1) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ll mod = 1e9 + 7; int main() { fast_io ll n, p; cin >> n >> p; ll ans = 1; for (int i = 2; i * i <= p; i++) { int num = 0; while (p % i == 0) { num++; p /= i; } int cnt = num / n; for (int j = 0; j < cnt; j++) ans *= i; } if (n == 1) ans *= p; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define PI acos(-1) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ll mod = 1e9 + 7; int main() { fast_io ll n, p; cin >> n >> p; ll ans = 1; for (ll i = 2; i * i <= p; i++) { int num = 0; while (p % i == 0) { num++; p /= i; } int cnt = num / n; for (int j = 0; j < cnt; j++) ans *= i; } if (n == 1) ans *= p; cout << ans << endl; return 0; }
replace
20
21
20
21
TLE
p03196
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define forn(i, a, b) for (int i = a; i <= b; i++) #define INF 2147483647 #define LLINF 9223372036854775807 using namespace std; map<long long, long long> mp; int main() { long long n, p; cin >> n >> p; set<long long> s; long long P = p; vector<int> v; for (long long i = 2; i * i <= P; i++) { if (P % i == 0) { while (p && p % i == 0) { p /= i; s.insert(i); mp[i]++; } v.push_back(P / i); } } for (int i = 0; i < v.size(); i++) { while (p && p % v[i] == 0) { p /= v[i]; s.insert(v[i]); mp[v[i]]++; } } if (s.size() == 0) { s.insert(P); mp[P]++; } long long cnt = 1; for (set<long long>::iterator it = s.begin(); it != s.end(); it++) { if (mp[*it] >= n) { for (int j = 0; j < mp[*it] / n; j++) cnt *= *it; } } cout << cnt << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define forn(i, a, b) for (int i = a; i <= b; i++) #define INF 2147483647 #define LLINF 9223372036854775807 using namespace std; map<long long, long long> mp; int main() { long long n, p; cin >> n >> p; set<long long> s; long long P = p; vector<long long> v; for (long long i = 2; i * i <= P; i++) { if (P % i == 0) { while (p && p % i == 0) { p /= i; s.insert(i); mp[i]++; } v.push_back(P / i); } } for (int i = 0; i < v.size(); i++) { while (p && p % v[i] == 0) { p /= v[i]; s.insert(v[i]); mp[v[i]]++; } } if (s.size() == 0) { s.insert(P); mp[P]++; } long long cnt = 1; for (set<long long>::iterator it = s.begin(); it != s.end(); it++) { if (mp[*it] >= n) { for (int j = 0; j < mp[*it] / n; j++) cnt *= *it; } } cout << cnt << endl; return 0; }
replace
30
31
30
31
0
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define Task "" using namespace std; typedef long long ll; const int maxn = 1e5 + 5; map<ll, int> ma; ll N, P; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")) { freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } if (fopen(Task ".INP", "r")) { freopen(Task ".INP", "r", stdin); freopen(Task ".OUT", "w", stdout); } cin >> N >> P; for (int i = 2; i * i <= P; ++i) { while (P % i == 0) { ma[i]++; P /= i; } } if (P != 1) ma[P]++; ll res = 1; for (auto it : ma) { int cnt = it.se / N; while (cnt--) { res *= it.fi; } } cout << res << '\n'; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define Task "" using namespace std; typedef long long ll; const int maxn = 1e5 + 5; map<ll, int> ma; ll N, P; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")) { freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } if (fopen(Task ".INP", "r")) { freopen(Task ".INP", "r", stdin); freopen(Task ".OUT", "w", stdout); } cin >> N >> P; for (int i = 2; 1ll * i * i <= P; ++i) { while (P % i == 0) { ma[i]++; P /= i; } } if (P != 1) ma[P]++; ll res = 1; for (auto it : ma) { int cnt = it.se / N; while (cnt--) { res *= it.fi; } } cout << res << '\n'; }
replace
29
30
29
30
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(c) (c).begin(), (c).end() const int MOD = 1000000007; int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } map<ll, ll> m; ll d = 2; ll l = p / 2; while (p > 1 && l >= d) { if (p % d == 0) { m[d]++; p /= d; } else { if (d == 2) { d++; } else { d += 2; } } } ll ans = 1; for (const auto q : m) { if (q.second >= n) { ans *= (ll)pow(q.first, q.second / n); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(c) (c).begin(), (c).end() const int MOD = 1000000007; int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } map<ll, ll> m; ll d = 2; ll l = p; while (p > 1 && l >= d * d) { if (p % d == 0) { m[d]++; p /= d; } else { if (d == 2) { d++; } else { d += 2; } } } ll ans = 1; for (const auto q : m) { if (q.second >= n) { ans *= (ll)pow(q.first, q.second / n); } } cout << ans << endl; }
replace
18
20
18
20
TLE
p03196
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; #define ll long long ll N, P; int solve() { ll ans = 1; ll store; for (int i = 1; pow(i, N) <= P; i++) { store = static_cast<ll>(pow(i, N)); if (P % store == 0) { ans = i; } } cout << ans << endl; return 0; } int main() { cin >> N >> P; solve(); return 0; }
#include <iostream> #include <math.h> using namespace std; #define ll long long ll N, P; int solve() { ll ans = 1; ll store; for (int i = 1; pow(i, N) <= P; i++) { store = static_cast<ll>(pow(i, N)); if (P % store == 0) { ans = i; } } cout << ans << endl; return 0; } int main() { cin >> N >> P; if (N == 1) { cout << P << endl; return 0; } solve(); return 0; }
insert
22
22
22
26
TLE
p03196
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); ll n, p; cin >> n >> p; vector<ll> D; for (ll d = 1; d * d <= p; ++d) { if (p % d == 0) { D.push_back(d); D.push_back(p / d); } } ll odp = 1; for (int i = 0; i < D.size(); ++i) { ll t = p; ll j; for (j = 0; j < n; ++j) { if (t % D[i] != 0) break; t /= D[i]; } if (t >= 1 && j == n) odp = max(odp, D[i]); } cout << odp; return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); ll n, p; cin >> n >> p; vector<ll> D; for (ll d = 1; d * d <= p; ++d) { if (p % d == 0) { D.push_back(d); D.push_back(p / d); } } ll odp = 1; for (int i = 0; i < D.size(); ++i) { if (D[i] == 1) continue; ll t = p; ll j; for (j = 0; j < n; ++j) { if (t % D[i] != 0) break; t /= D[i]; } if (t >= 1 && j == n) odp = max(odp, D[i]); } cout << odp; return 0; }
insert
20
20
20
22
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, a) FOR(i, 0, a) typedef long long ll; ll N, P; ll pw(ll n, int m) { ll ret = 1; while (m) { if (m & 1) { ret *= n; } n *= n; m >>= 1; } return ret; } int main() { cin >> N >> P; ll ans = 1; for (int i = 2; i * i <= P; i++) { int cnt = 0; while (P % i == 0) { P /= i; cnt++; } if (cnt >= N) { ans *= pw(i, (cnt / N)); } } if (P != 1 && N == 1) { ans *= P; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, a) FOR(i, 0, a) typedef long long ll; ll N, P; ll pw(ll n, int m) { ll ret = 1; while (m) { if (m & 1) { ret *= n; } n *= n; m >>= 1; } return ret; } int main() { cin >> N >> P; ll ans = 1; for (ll i = 2; i * i <= P; i++) { int cnt = 0; while (P % i == 0) { P /= i; cnt++; } if (cnt >= N) { ans *= pw(i, (cnt / N)); } } if (P != 1 && N == 1) { ans *= P; } cout << ans << endl; return 0; }
replace
21
22
21
22
TLE
p03196
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { long n, p; cin >> n >> p; int c = 2; long t = static_cast<long>(pow(c, n)); long r = 1; if (n == 1) { cout << p << endl; return 0; } while (t <= p) { if (p % t == 0) { r = c; } ++c; t = static_cast<long>(pow(c, n)); } cout << r << endl; }
#include <cmath> #include <iostream> using namespace std; int main() { long n, p; cin >> n >> p; int c = 2; long t = static_cast<long>(pow(c, n)); long r = 1; if (n == 1) { cout << p << endl; return 0; } else if (n >= 40) { cout << 1 << endl; return 0; } while (t <= p) { if (p % t == 0) { r = c; } ++c; t = static_cast<long>(pow(c, n)); } cout << r << endl; }
insert
14
14
14
17
TLE
p03196
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { int64 N, P; cin >> N >> P; vector<int64> divisor; for (int64 i = 1; i * i <= P; i++) { if (P % i == 0) { divisor.emplace_back(i); if (i * i != P) divisor.emplace_back(P / i); } } int64 ret = 1; for (auto &p : divisor) { if (p == 1) continue; int64 mul = 1; for (int64 i = 0; i < N; i++) { mul *= p; if (mul > P) break; } if (mul <= P && P % mul == 0) { ret = max(ret, p); } } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { int64 N, P; cin >> N >> P; vector<int64> divisor; for (int64 i = 1; i * i <= P; i++) { if (P % i == 0) { divisor.emplace_back(i); if (i * i != P) divisor.emplace_back(P / i); } } int64 ret = 1; for (auto &p : divisor) { if (p == 1) continue; __int128_t mul = 1; for (int64 i = 0; i < N; i++) { mul *= p; if (mul > P) break; } if (mul <= P && P % mul == 0) { ret = max(ret, p); } } cout << ret << endl; }
replace
21
22
21
22
0
p03196
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long n, p; vector<int> prime; cin >> n >> p; if (n == 1) cout << p << endl; else if (n == 2) { int ans = 1; for (int i = 2; i <= sqrt(p); i++) { if (p % (i * i) == 0) ans = i; } cout << ans << endl; } else { int ans = 1; for (int i = 2; i <= p; i++) { long tmp = 1; bool chk = true; for (int j = 0; j < n; j++) { tmp *= i; if (tmp > p) { chk = false; break; } } if (chk) { if (p % tmp == 0) ans = i; } else break; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long n, p; vector<int> prime; cin >> n >> p; if (n == 1) cout << p << endl; else if (n == 2) { int ans = 1; for (long i = 2; i <= sqrt(p); i++) { if (p % (i * i) == 0) ans = i; } cout << ans << endl; } else { int ans = 1; for (int i = 2; i <= p; i++) { long tmp = 1; bool chk = true; for (int j = 0; j < n; j++) { tmp *= i; if (tmp > p) { chk = false; break; } } if (chk) { if (p % tmp == 0) ans = i; } else break; } cout << ans << endl; } }
replace
10
11
10
11
0
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int N, P; cin >> N >> P; if (N == 1) { cout << P << endl; return 0; } int A = P; int ans = 1; int cnt = 2; int waru = 0; while (P > 1 || cnt <= sqrt(A)) { if (P % cnt == 0 && P / cnt > 0) { waru++; P /= cnt; } else if (P % cnt != 0) { cnt++; waru = 0; } if (waru == N) { ans *= cnt; waru = 0; } } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int N, P; cin >> N >> P; if (N == 1) { cout << P << endl; return 0; } int A = P; int ans = 1; int cnt = 2; int waru = 0; while (P > 1 && cnt <= sqrt(A)) { if (P % cnt == 0 && P / cnt > 0) { waru++; P /= cnt; } else if (P % cnt != 0) { cnt++; waru = 0; } if (waru == N) { ans *= cnt; waru = 0; } } cout << ans << endl; }
replace
17
18
17
18
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; using tll = tuple<ll, ll>; using vs = vector<string>; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define rep(i, n) range(i, 0, n) #define range(i, a, n) for (int i = (a); i < (n); i++) #define LINF ((ll)1ll << 60) #define INF ((int)1 << 30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout << setprecision(a) << fixed #define fs first #define sc second #define PI 3.1415926535897932384 int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) { os << "[" << p.first << ", " << p.second << "]"; return os; }; template <class S> auto &operator<<(ostream &os, vector<S> t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; } void OUT(bool b) { cout << (b ? "YES" : "NO") << endl; } void Out(bool b) { cout << (b ? "Yes" : "No") << endl; } void out(bool b) { cout << (b ? "yes" : "no") << endl; } int popcnt(int x) { return __builtin_popcount(x); } int popcnt(ll x) { return __builtin_popcountll(x); } int clz(int x) { return 31 - __builtin_clz(x); } int clz(ll x) { return 63 - __builtin_clzll(x); } int ctz(int x) { return __builtin_ctz(x); } int ctz(ll x) { return __builtin_ctzll(x); } class compare { public: bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) { return (get<1>(a) > get<1>(b)); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, p; ll ans = 1; cin >> n >> p; map<ll, ll> mp; range(i, 2, p + 1) { ll t = 1; rep(j, n) { t *= i; if (t > p) { cout << ans << endl; return 0; } } if (p % t == 0) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; using tll = tuple<ll, ll>; using vs = vector<string>; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define rep(i, n) range(i, 0, n) #define range(i, a, n) for (int i = (a); i < (n); i++) #define LINF ((ll)1ll << 60) #define INF ((int)1 << 30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout << setprecision(a) << fixed #define fs first #define sc second #define PI 3.1415926535897932384 int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) { os << "[" << p.first << ", " << p.second << "]"; return os; }; template <class S> auto &operator<<(ostream &os, vector<S> t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; } void OUT(bool b) { cout << (b ? "YES" : "NO") << endl; } void Out(bool b) { cout << (b ? "Yes" : "No") << endl; } void out(bool b) { cout << (b ? "yes" : "no") << endl; } int popcnt(int x) { return __builtin_popcount(x); } int popcnt(ll x) { return __builtin_popcountll(x); } int clz(int x) { return 31 - __builtin_clz(x); } int clz(ll x) { return 63 - __builtin_clzll(x); } int ctz(int x) { return __builtin_ctz(x); } int ctz(ll x) { return __builtin_ctzll(x); } class compare { public: bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) { return (get<1>(a) > get<1>(b)); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, p; ll ans = 1; cin >> n >> p; map<ll, ll> mp; if (n == 1) { cout << p << endl; return 0; } range(i, 2, p + 1) { ll t = 1; rep(j, n) { t *= i; if (t > p) { cout << ans << endl; return 0; } } if (p % t == 0) ans = i; } cout << ans << endl; }
insert
63
63
63
67
TLE
p03196
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long int lli; lli modpow(lli a, lli p, lli mod) { lli ret = 1; for (int i = 63; i >= 0; i--) { ret *= ret; if (ret > mod) return -1; if ((1LL << i & p) != 0) { ret *= a; if (ret > mod) return -1; } } return ret; } int main() { lli n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } lli ans = 1; for (lli i = 2;; i++) { lli ret = modpow(i, n, p); if (ret == -1) break; while (p % ret == 0) { p /= ret; ans *= i; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long int lli; lli modpow(lli a, lli p, lli mod) { lli ret = 1; for (int i = 63; i >= 0; i--) { if (ret > (lli)1e7) return -1; ret *= ret; if (ret > mod) return -1; if ((1LL << i & p) != 0) { ret *= a; if (ret > mod) return -1; } } return ret; } int main() { lli n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } lli ans = 1; for (lli i = 2;; i++) { lli ret = modpow(i, n, p); if (ret == -1) break; while (p % ret == 0) { p /= ret; ans *= i; } } cout << ans << endl; return 0; }
insert
9
9
9
11
0
p03196
C++
Time Limit Exceeded
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> #include <iostream> // cout, endl, cin #include <map> // map #include <math.h> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; #define int long long signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, p; cin >> n >> p; vector<int> a(100000001); if (p == 1) { cout << 1 << endl; return 0; } if (n == 1) { cout << p << endl; return 0; } int i = 2; while (p > 1) { if (p % i == 0) { a.at(i)++; p /= i; } else { i++; } } int ans = 1; for (int i = 2; i < 100000001; i++) { if (a.at(i) >= n) { int j = a.at(i) / n; ans *= pow(i, j); } } cout << ans << endl; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <iomanip> #include <iostream> // cout, endl, cin #include <map> // map #include <math.h> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; #define int long long signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, p; cin >> n >> p; vector<int> a(100000001); if (p == 1) { cout << 1 << endl; return 0; } if (n == 1) { cout << p << endl; return 0; } int i = 2; while (p > 1 && i < 10000000) { if (p % i == 0) { a.at(i)++; p /= i; } else { i++; } } int ans = 1; for (int i = 2; i < 100000001; i++) { if (a.at(i) >= n) { int j = a.at(i) / n; ans *= pow(i, j); } } cout << ans << endl; }
replace
43
44
43
44
TLE
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; int main() { ll N, P, tmp, ans; cin >> N >> P; ans = 1; if (N == 1) { cout << P; return 0; } for (ll i = 1; i <= 1e6; i++) { bool flag = true; tmp = P; for (int j = 0; j < N; j++) { if (tmp % i == 0) { tmp /= i; } else { tmp /= i; flag = false; break; } } if (flag) ans = i; if (tmp < 1) break; } cout << ans; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; int main() { ll N, P, tmp, ans; cin >> N >> P; ans = 1; if (N == 1) { cout << P; return 0; } for (ll i = 2; i <= 1e6; i++) { bool flag = true; tmp = P; for (int j = 0; j < N; j++) { if (tmp % i == 0) { tmp /= i; } else { tmp /= i; flag = false; break; } } if (flag) ans = i; if (tmp < 1) break; } cout << ans; return 0; }
replace
25
26
25
26
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 9; const int INF = 1e9; const double EPS = 1e-9; map<long long, long long> mp; long long n, p; long long quickPow(long long a, long long b) { if (b == 0) return 1; long long tmp = quickPow(a, b / 2); if (b & 1) return tmp * tmp * a; return tmp * tmp; } void read() { cin >> n >> p; } void solv() { for (int i = 2; i * i <= p; i++) { if (p % i == 0) { while (p % i == 0) { mp[i]++; p /= i; } } } if (p > 1) mp[p]++; long long res = 1; for (map<long long, long long>::iterator it = mp.begin(); it != mp.end(); it++) { res *= quickPow(it->first, it->second / n); } cout << res << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef DEBUG freopen("in.txt", "r", stdin); #endif read(); solv(); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 100 * 1000 + 9; const int INF = 1e9; const double EPS = 1e-9; map<long long, long long> mp; long long n, p; long long quickPow(long long a, long long b) { if (b == 0) return 1; long long tmp = quickPow(a, b / 2); if (b & 1) return tmp * tmp * a; return tmp * tmp; } void read() { cin >> n >> p; } void solv() { for (long long i = 2; i * i <= p; i++) { if (p % i == 0) { while (p % i == 0) { mp[i]++; p /= i; } } } if (p > 1) mp[p]++; long long res = 1; for (map<long long, long long>::iterator it = mp.begin(); it != mp.end(); it++) { res *= quickPow(it->first, it->second / n); } cout << res << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef DEBUG freopen("in.txt", "r", stdin); #endif read(); solv(); return 0; }
replace
22
23
22
23
TLE
p03196
C++
Runtime Error
#include <iostream> using namespace std; typedef long long ll; ll n, p, ans; ll pow(ll x, ll y) { if (y == 0) return 1; if (y % 2) { return x * pow(x, y - 1); } else { ll yy = pow(x, y / 2); return yy * yy; } } int main() { cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } if (n > 100) { cout << 1 << endl; } for (ll i = 1; pow(i, n) <= p; i++) { if (p % pow(i, n) == 0) ans = i; } cout << ans << endl; }
#include <iostream> using namespace std; typedef long long ll; ll n, p, ans; ll pow(ll x, ll y) { if (y == 0) return 1; if (y % 2) { return x * pow(x, y - 1); } else { ll yy = pow(x, y / 2); return yy * yy; } } int main() { cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } if (n > 100) { cout << 1 << endl; return 0; } for (ll i = 1; pow(i, n) <= p; i++) { if (p % pow(i, n) == 0) ans = i; } cout << ans << endl; }
insert
24
24
24
25
0
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; const double PI = acos(-1); template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } int main() { ll n, p; cin >> n >> p; ll m = 0; for (ll i = 1; pow(i, n) <= p; ++i) { if (p % (ll)pow(i, n) == 0) m = max(m, i); } cout << m << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; const double PI = acos(-1); template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } int main() { ll n, p; cin >> n >> p; ll m = 0; if (n == 1) { m = p; } else { for (ll i = 1; pow(i, n) <= p; ++i) { if (p % (ll)pow(i, n) == 0) m = max(m, i); } } cout << m << endl; return 0; }
replace
16
19
16
23
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long A; cin >> A; long long N; cin >> N; if (A == 1) { cout << N << endl; return 0; } long long temp = N; map<long long, long long> mp; int i = 2; while (temp > 1) { if (temp % i == 0) { mp[i]++; temp = temp / i; // cout<<i<<endl; } else i++; if (i > 500000000) { cout << 1 << endl; return 0; } } long long ans = 1; long long mult = 0; for (auto itr = mp.begin(); itr != mp.end(); itr++) { if ((itr->second) >= A) { mult = (itr->second) / A; ans = ans * pow((itr->first), mult); // cout<<itr->first<<endl; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long A; cin >> A; long long N; cin >> N; if (A == 1) { cout << N << endl; return 0; } long long temp = N; map<long long, long long> mp; int i = 2; while (temp > 1) { if (temp % i == 0) { mp[i]++; temp = temp / i; // cout<<i<<endl; } else i++; if (i > 100000000) { cout << 1 << endl; return 0; } } long long ans = 1; long long mult = 0; for (auto itr = mp.begin(); itr != mp.end(); itr++) { if ((itr->second) >= A) { mult = (itr->second) / A; ans = ans * pow((itr->first), mult); // cout<<itr->first<<endl; } } cout << ans << endl; return 0; }
replace
22
23
22
23
TLE
p03196
C++
Time Limit Exceeded
#include <iostream> using namespace std; typedef long long int LL; int main() { LL n, m, a, b; int i, j; int s = 1; cin >> n >> m; if (n == 1) { cout << m << endl; return 0; } for (a = 1;; a++) { for (b = 1, i = 0; i < n; i++) { b *= a; if (b > m) { cout << s << endl; return 0; } } if (b > m) break; if (m % b == 0) s = a; } cout << s << endl; return 0; }
#include <iostream> using namespace std; typedef long long int LL; int main() { LL n, m, a, b; int i, j; int s = 1; cin >> n >> m; if (n == 1) { cout << m << endl; return 0; } if (n > 100) { cout << 1 << endl; return 0; } for (a = 1;; a++) { for (b = 1, i = 0; i < n; i++) { b *= a; if (b > m) { cout << s << endl; return 0; } } if (b > m) break; if (m % b == 0) s = a; } cout << s << endl; return 0; }
insert
10
10
10
14
TLE
p03196
C++
Runtime Error
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; long long pw(long long e, long long x) { if (x == 0) return 1; if (x == 1) return e; if (x % 2 == 0) return pw(e * e, x / 2); return e * pw(e, x - 1); } int main() { long long n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } long long ans = 1; for (long long i = 2; pw(i, n) <= p; i++) { if (p % pw(i, n) == 0) ans = i; } cout << ans << endl; return 0; }
#include <algorithm> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; long long pw(long long e, long long x) { if (x == 0) return 1; if (x == 1) return e; if (x % 2 == 0) return pw(e * e, x / 2); return e * pw(e, x - 1); } int main() { long long n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } long long ans = 1; if (n > 1000000) { cout << 1 << endl; return 0; } for (long long i = 2; pw(i, n) <= p; i++) { if (p % pw(i, n) == 0) ans = i; } cout << ans << endl; return 0; }
insert
32
32
32
36
0
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int A, B, C = 1; cin >> A >> B; if (A == 1) { cout << B << endl; return 0; } for (int i = 2; i * i <= B; i++) if (B % i == 0) { int cnt = 0; while (B % i == 0) B /= i, cnt++; cnt = (int)(cnt / A); while (cnt--) C *= i; } cout << C << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int A, B, C = 1; cin >> A >> B; if (A == 1) { cout << B << endl; return 0; } for (long long int i = 2; i * i <= B; i++) if (B % i == 0) { int cnt = 0; while (B % i == 0) B /= i, cnt++; cnt = (int)(cnt / A); while (cnt--) C *= i; } cout << C << endl; return 0; }
replace
9
10
9
10
TLE
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #define MOD 1000000007 typedef long long ll; using namespace std; int main() { ll n, P; cin >> n >> P; ll p = P; // map<ll,ll> mp; ll ans = 1; vector<ll> last; for (int i = 2; i * i <= p; i++) { ll tmp = 0; if (p % i == 0) { while (p % i == 0) { tmp++; p /= i; } // mp[i]=tmp; } if (tmp >= n) { ans *= pow((ll)i, tmp / n); // last.push_back(i); } if (p < pow((ll)i, n) || pow((ll)i, n) < 0) break; } if (p != 1) { ll tmp = 0; while (P % p == 0) { P /= p; tmp++; } if (tmp % n == 0) ans *= p; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #define MOD 1000000007 typedef long long ll; using namespace std; int main() { ll n, P; cin >> n >> P; ll p = P; // map<ll,ll> mp; ll ans = 1; vector<ll> last; if (n == 1) { cout << p << endl; return 0; } for (int i = 2; i * i <= p; i++) { ll tmp = 0; if (p % i == 0) { while (p % i == 0) { tmp++; p /= i; } // mp[i]=tmp; } if (tmp >= n) { ans *= pow((ll)i, tmp / n); // last.push_back(i); } if (p < pow((ll)i, n) || pow((ll)i, n) < 0) break; } if (p != 1) { ll tmp = 0; while (P % p == 0) { P /= p; tmp++; } if (tmp % n == 0) ans *= p; } cout << ans << endl; return 0; }
insert
20
20
20
24
TLE
p03196
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define chmin(a, b) \ if ((a) > (b)) \ (a) = (b); #define chmax(a, b) \ if ((a) < (b)) \ (a) = (b); #define vi vector<int> #define pii pair<int, int> #define all(v) (v).begin(), (v).end() #define allr(v) (v).rbegin(), (v).rend() #define pb push_back #define pf push_front int gcd(int a, int b) { /*a>=0,b>=0,¬(a=b=0)*/ while (min(a, b) > 0) { if (a < b) swap(a, b); a %= b; } return max(a, b); } int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int MOD = 1e9 + 7; const long long INF = 1e18 + 10; /*--------------------------------------------------------------------*/ bool isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } signed main() { int n, p; cin >> n >> p; vi prime; for (int i = 2; i <= min((int)(1e6 + 3e5), p); i++) { if (isprime(i)) { prime.pb(i); } } vector<pii> sosuu; rep(i, prime.size()) { int cnt = 0; while (p % prime[i] == 0) { cnt++; p /= prime[i]; } if (cnt > 0) sosuu.pb(make_pair(prime[i], cnt)); if (p == 1) { break; } } assert(p == 1); int ans = 1; for (auto p : sosuu) { ans *= pow(p.first, p.second / n); } cout << ans << endl; // for(pii p:sosuu){ // cout<<p.first<<' '<<p.second<<endl; // } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define chmin(a, b) \ if ((a) > (b)) \ (a) = (b); #define chmax(a, b) \ if ((a) < (b)) \ (a) = (b); #define vi vector<int> #define pii pair<int, int> #define all(v) (v).begin(), (v).end() #define allr(v) (v).rbegin(), (v).rend() #define pb push_back #define pf push_front int gcd(int a, int b) { /*a>=0,b>=0,¬(a=b=0)*/ while (min(a, b) > 0) { if (a < b) swap(a, b); a %= b; } return max(a, b); } int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int MOD = 1e9 + 7; const long long INF = 1e18 + 10; /*--------------------------------------------------------------------*/ bool isprime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } signed main() { int n, p; cin >> n >> p; vi prime; for (int i = 2; i <= min((int)(1e6 + 3e5), p); i++) { if (isprime(i)) { prime.pb(i); } } vector<pii> sosuu; rep(i, prime.size()) { int cnt = 0; while (p % prime[i] == 0) { cnt++; p /= prime[i]; } if (cnt > 0) sosuu.pb(make_pair(prime[i], cnt)); if (p == 1) { break; } } if (isprime(p)) { sosuu.pb(make_pair(p, 1)); p /= p; } assert(p == 1); int ans = 1; for (auto p : sosuu) { ans *= pow(p.first, p.second / n); } cout << ans << endl; // for(pii p:sosuu){ // cout<<p.first<<' '<<p.second<<endl; // } return 0; }
insert
67
67
67
71
0
p03196
C++
Time Limit Exceeded
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> // #include<boost/multiprecision/cpp_dec_float.hpp> // namespace mp=boost::multiprecision; // #define mulint mp::cpp_int // #define mulfloat mp::cpp_dec_float_100 using namespace std; struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) constexpr int MOD = 1000000007; // constexpr int MOD=998244353; #define INF (1 << 30) #define LINF (lint)(1LL << 56) #define endl "\n" #define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++) #define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--) #define Flag(x) (1 << (x)) #define Flagcount(x) __builtin_popcountll(x) #define pint pair<int, int> #define pdouble pair<double, double> #define plint pair<lint, lint> #define fi first #define se second typedef long long lint; int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int MAX_N = 2e5 + 5; // struct edge{lint to,num;}; multiset<lint> decomp(lint N) { multiset<lint> res; lint num = N; for (int i = 2; i * i <= num; i++) { while (N % i == 0) N /= i, res.insert(i); if (N == 1) break; } if (N != 1) res.insert(N); return res; } int main(void) { lint N, P; cin >> N >> P; multiset<lint> res = decomp(P); lint ans = 1; while (!res.empty()) { auto itr = res.begin(); lint cnt = res.count(*itr); while (cnt >= N) cnt -= N, ans *= *itr; res.erase(*itr); } cout << ans << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> // #include<boost/multiprecision/cpp_dec_float.hpp> // namespace mp=boost::multiprecision; // #define mulint mp::cpp_int // #define mulfloat mp::cpp_dec_float_100 using namespace std; struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) constexpr int MOD = 1000000007; // constexpr int MOD=998244353; #define INF (1 << 30) #define LINF (lint)(1LL << 56) #define endl "\n" #define rep(i, n) for (lint(i) = 0; (i) < (n); (i)++) #define reprev(i, n) for (lint(i) = (n - 1); (i) >= 0; (i)--) #define Flag(x) (1 << (x)) #define Flagcount(x) __builtin_popcountll(x) #define pint pair<int, int> #define pdouble pair<double, double> #define plint pair<lint, lint> #define fi first #define se second typedef long long lint; int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int MAX_N = 2e5 + 5; // struct edge{lint to,num;}; multiset<lint> decomp(lint N) { multiset<lint> res; lint num = N; for (lint i = 2; i * i <= num; i++) { while (N % i == 0) N /= i, res.insert(i); if (N == 1) break; } if (N != 1) res.insert(N); return res; } int main(void) { lint N, P; cin >> N >> P; multiset<lint> res = decomp(P); lint ans = 1; while (!res.empty()) { auto itr = res.begin(); lint cnt = res.count(*itr); while (cnt >= N) cnt -= N, ans *= *itr; res.erase(*itr); } cout << ans << endl; }
replace
40
41
40
41
TLE
p03196
C++
Time Limit Exceeded
#pragma region header #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for (int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; /* ----------------よく使う数字や配列----------------- */ int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr ll mod = 1e9 + 7; constexpr ll inf = INT32_MAX / 2; constexpr ll INF = LLONG_MAX / 2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; /* ----------------------end----------------------- */ /* --------------------テンプレート------------------ */ 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; } /* ----------------------end----------------------- */ /* --------------------ライブラリ-------------------- */ ll fact(int i) { // 階乗 if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { // 最大公約数 if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { // 最小公倍数 return a * b / gcd(a, b); } int keta(ll n) { // 桁数を求める if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { // 各桁の和 ll sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } /* ----------------------end----------------------- */ #pragma endregion vector<P> prime_div(int p) { vector<P> prime; int P = p; for (int i = 2; i <= P; i++) { if (p % i == 0) { int count = 0; while (p % i == 0) { p /= i; count++; } prime.pb({i, count}); } } return prime; } signed main() { /*int n,p;cin >> n >> p; vector<P> prime = prime_div(p); for(auto p:prime)cout << p.first << ' ' << p.second << endl; int ma = -1; int ans = 1; rep(i, prime.size()) { if(chmax(ma,prime[i].second/n)){ ans *= prime[i].first; } } // int ans = 1; // rep(i, prime.size()) { // ans*=prime[i].first*mi; // } cout << ans << endl;*/ int n, p; cin >> n >> p; int ma = -1; // int ans = 1; for (int i = 2; i <= p; i++) { if (pow(i, n) > p || pow(i, n) <= 0) break; if (p % (int)pow(i, n) == 0) { chmax(ma, i); // cout << i << endl; // p/=i; // cout << ans << endl; } // cout << ans << endl; } cout << max(ma, 1LL) << endl; // cout << 24%(int)pow(2,3) << endl; // cout << pow(42436,n) << endl; return 0; }
#pragma region header #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for (int i = (int)(n); i > 0; i--) #define pb push_back #define all(v) (v).begin(), (v).end() #define resort(v) sort((v).rbegin(), (v).rend()) #define vi vector<int> #define vvi vector<vector<int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> using ll = long long; using P = pair<int, int>; /* ----------------よく使う数字や配列----------------- */ int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr ll mod = 1e9 + 7; constexpr ll inf = INT32_MAX / 2; constexpr ll INF = LLONG_MAX / 2; constexpr long double eps = DBL_EPSILON; constexpr long double pi = 3.141592653589793238462643383279; /* ----------------------end----------------------- */ /* --------------------テンプレート------------------ */ 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; } /* ----------------------end----------------------- */ /* --------------------ライブラリ-------------------- */ ll fact(int i) { // 階乗 if (i == 0) return 1; return (fact(i - 1)) * i % mod; } ll gcd(ll a, ll b) { // 最大公約数 if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { // 最小公倍数 return a * b / gcd(a, b); } int keta(ll n) { // 桁数を求める if (n == 0) return 1; int count = 0; while (n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { // 各桁の和 ll sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } /* ----------------------end----------------------- */ #pragma endregion vector<P> prime_div(int p) { vector<P> prime; int P = p; for (int i = 2; i <= P; i++) { if (p % i == 0) { int count = 0; while (p % i == 0) { p /= i; count++; } prime.pb({i, count}); } } return prime; } signed main() { /*int n,p;cin >> n >> p; vector<P> prime = prime_div(p); for(auto p:prime)cout << p.first << ' ' << p.second << endl; int ma = -1; int ans = 1; rep(i, prime.size()) { if(chmax(ma,prime[i].second/n)){ ans *= prime[i].first; } } // int ans = 1; // rep(i, prime.size()) { // ans*=prime[i].first*mi; // } cout << ans << endl;*/ int n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } int ma = -1; // int ans = 1; for (int i = 2; i <= p; i++) { if (pow(i, n) > p || pow(i, n) <= 0) break; if (p % (int)pow(i, n) == 0) { chmax(ma, i); // cout << i << endl; // p/=i; // cout << ans << endl; } // cout << ans << endl; } cout << max(ma, 1LL) << endl; // cout << 24%(int)pow(2,3) << endl; // cout << pow(42436,n) << endl; return 0; }
insert
114
114
114
118
TLE
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n, p; cin >> n >> p; ll tmp_num = p; vector<pair<ll, ll>> v_cnt; ll cnt_max = 0; if (n == 1) { cout << p << endl; return 0; } for (ll i = 2; i <= p; ++i) { if (tmp_num <= 1) { break; } ll cnt = 0; while (1) { if (tmp_num % i != 0) { break; } tmp_num /= i; ++cnt; } if (cnt < n) { continue; } v_cnt.emplace_back(i, cnt / n); } // for ( auto tmp_num : v_cnt ) { // cout << tmp_num.first << " " << tmp_num.second << " " << endl;; // } // cout << endl; if (v_cnt.empty()) { cout << 1 << endl; return 0; } ll ans = 1; for (auto tmp_num : v_cnt) { ll tmp_ans = 1; rep(ri, tmp_num.second) { tmp_ans *= tmp_num.first; } // cout << tmp_ans << " " << loop_num << endl; ans *= tmp_ans; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n, p; cin >> n >> p; ll tmp_num = p; vector<pair<ll, ll>> v_cnt; ll cnt_max = 0; if (n == 1) { cout << p << endl; return 0; } for (ll i = 2; i * i <= p; ++i) { if (tmp_num <= 1) { break; } ll cnt = 0; while (1) { if (tmp_num % i != 0) { break; } tmp_num /= i; ++cnt; } if (cnt < n) { continue; } v_cnt.emplace_back(i, cnt / n); } // for ( auto tmp_num : v_cnt ) { // cout << tmp_num.first << " " << tmp_num.second << " " << endl;; // } // cout << endl; if (v_cnt.empty()) { cout << 1 << endl; return 0; } ll ans = 1; for (auto tmp_num : v_cnt) { ll tmp_ans = 1; rep(ri, tmp_num.second) { tmp_ans *= tmp_num.first; } // cout << tmp_ans << " " << loop_num << endl; ans *= tmp_ans; } cout << ans << endl; return 0; }
replace
25
26
25
26
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll power(ll x, ll y) { if (x == 1) return 1; if (y == 1) return x; if (x > 1000000) return 1000000000001; if (y > 40) return 1000000000001; ll res = 1; for (ll i = 0; i < y; i++) { if (res > 1000000000000) { res = 1000000000001; break; } res *= x; } return res; } int main() { ll N, P; cin >> N >> P; ll ans = 1; for (ll i = 1; power(i, N) <= P; i++) { if (P % power(i, N)) continue; ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll power(ll x, ll y) { if (x == 1) return 1; if (y == 1) return x; if (x > 1000000) return 1000000000001; if (y > 40) return 1000000000001; ll res = 1; for (ll i = 0; i < y; i++) { if (res > 1000000000000) { res = 1000000000001; break; } res *= x; } return res; } int main() { ll N, P; cin >> N >> P; ll ans = 1; if (N == 1) ans = P; else { for (ll i = 1; power(i, N) <= P; i++) { if (P % power(i, N)) continue; ans = i; } } cout << ans << endl; return 0; }
replace
28
32
28
36
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <unistd.h> #define fi first #define se second #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n)-1; i >= 0; --i) #define ALL(a) a.begin(), a.end() #define pb push_back #define dame \ { \ puts("-1"); \ return 0; \ } #define show(x) cerr << #x << " = " << x << endl; using namespace std; using ll = long long; using ld = long double; using pl = pair<ll, ll>; ll LINF = 1000000000000000000; typedef vector<ll> vl; typedef vector<pl> vp; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } struct edge { ll to, cost; }; struct dijkstra { ll V; vector<vector<edge>> G; vector<ll> d; dijkstra(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = LINF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void run(ll s) { rep(i, V) { d[i] = LINF; } d[s] = 0; priority_queue<pl, vector<pl>, greater<pl>> que; que.push(pl(0, s)); while (!que.empty()) { pl p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(pl(d[e.to], e.to)); } } } } }; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const ll mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } } c(200005); // Sieve of Eratosthenes // https://youtu.be/UTVg7wzMWQc?t=2774 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<pl> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<pl> res(1, pl(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } vector<pair<ll, int>> factor(ll x) { vector<pair<ll, int>> res; for (int p : primes) { int y = 0; while (x % p == 0) x /= p, ++y; if (y != 0) res.emplace_back(p, y); } if (x != 1) res.emplace_back(x, 1); return res; } }; using data = pair<ll, vector<ll>>; int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } map<ll, ll> m; ll c = p; ll ans = 1; for (int i = 2; i * i <= p; i++) { ll idx = 0; while (c % i == 0) { c /= i; m[i]++; idx++; if (idx == n) { ans *= i; idx = 0; } } if (c == 1) break; } // if(c>1) m[c]++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <unistd.h> #define fi first #define se second #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n)-1; i >= 0; --i) #define ALL(a) a.begin(), a.end() #define pb push_back #define dame \ { \ puts("-1"); \ return 0; \ } #define show(x) cerr << #x << " = " << x << endl; using namespace std; using ll = long long; using ld = long double; using pl = pair<ll, ll>; ll LINF = 1000000000000000000; typedef vector<ll> vl; typedef vector<pl> vp; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } struct edge { ll to, cost; }; struct dijkstra { ll V; vector<vector<edge>> G; vector<ll> d; dijkstra(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = LINF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void run(ll s) { rep(i, V) { d[i] = LINF; } d[s] = 0; priority_queue<pl, vector<pl>, greater<pl>> que; que.push(pl(0, s)); while (!que.empty()) { pl p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(pl(d[e.to], e.to)); } } } } }; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const ll mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } } c(200005); // Sieve of Eratosthenes // https://youtu.be/UTVg7wzMWQc?t=2774 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<pl> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<pl> res(1, pl(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } vector<pair<ll, int>> factor(ll x) { vector<pair<ll, int>> res; for (int p : primes) { int y = 0; while (x % p == 0) x /= p, ++y; if (y != 0) res.emplace_back(p, y); } if (x != 1) res.emplace_back(x, 1); return res; } }; using data = pair<ll, vector<ll>>; int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p << endl; return 0; } map<ll, ll> m; ll c = p; ll ans = 1; for (ll i = 2; pow(i, n) <= p; i++) { ll pp = pow(i, n); while (c % pp == 0) { c /= pp; ans *= i; } } // if(c>1) m[c]++; cout << ans << endl; return 0; }
replace
217
230
217
223
TLE
p03196
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <sys/time.h> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; long long sqr(long long n) { return static_cast<long long>(n) * n; } long long bipow(long long c, long long n) { if (n == 0) { return 1; } else if (n == 1) { return c; } else if (n % 2 == 0) { return sqr(bipow(c, n / 2)); } else { return (static_cast<long long>(c) * sqr(bipow(c, (n - 1) / 2))); } } void solve(long long N, long long P) { if (N >= 40) { std::cout << 1 << std::endl; return; } long long ans = 1; long long x = 1; while (true) { long long y = bipow(x, N); if (P < y) { break; } if (P % y == 0) { ans = x; } x++; } std::cout << ans << std::endl; return; } int main() { long long N; long long P; scanf("%lld", &N); scanf("%lld", &P); solve(N, P); return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <sys/time.h> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; long long sqr(long long n) { return static_cast<long long>(n) * n; } long long bipow(long long c, long long n) { if (n == 0) { return 1; } else if (n == 1) { return c; } else if (n % 2 == 0) { return sqr(bipow(c, n / 2)); } else { return (static_cast<long long>(c) * sqr(bipow(c, (n - 1) / 2))); } } void solve(long long N, long long P) { if (N >= 40) { std::cout << 1 << std::endl; return; } if (N == 1) { std::cout << P << std::endl; return; } long long ans = 1; long long x = 1; while (true) { long long y = bipow(x, N); if (P < y) { break; } if (P % y == 0) { ans = x; } x++; } std::cout << ans << std::endl; return; } int main() { long long N; long long P; scanf("%lld", &N); scanf("%lld", &P); solve(N, P); return 0; }
insert
35
35
35
39
TLE
p03196
C++
Time Limit Exceeded
/*input 1 8 */ #include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <utility> #include <vector> using namespace std; #define pb push_back #define pp pop_back #define pf pop_front #define nl cout << "\n" #define MIN(con) (*min_element(ALL(con))) #define MAX(con) (*max_element(ALL(con))) #define ALL(cont) (cont).begin(), (cont).end() #define NX(cont) next_permutation(ALL(cont)) #define PX(cont) prev_permutation(ALL(cont)) #define prec(n) cout << fixed << setprecision(n) #define PI 3.14159265358979323846264338327951 #define FH(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ff first #define ss second #define all(c) c.begin(), c.end() #define fill(a, v) memset(a, v, sizeof a) #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i >= b; i--) #define srep(i, s) for (ll i = 0; s[i] != '\0'; i++) #define nn cout << "\n" #define sp cout << " " #define mod 1000000007 // 9 #define ifalse ios_base::sync_with_stdio(false), cin.tie(NULL) using ll = long long; typedef vector<ll> vll; typedef vector<char> vc; typedef vector<string> vst; typedef pair<ll, ll> pll; typedef pair<char, ll> pcl; typedef pair<string, ll> psl; typedef set<ll> sll; typedef set<char> sc; typedef set<string> sst; typedef map<char, ll> mcl; typedef map<ll, ll> mll; typedef map<string, ll> msl; using ld = long double; template <typename T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } template <typename T> inline T GCD(T a, T b) { ll t; while (a) { t = a; a = b % a; b = t; } return b; } template <typename T> inline string toString(T a) { return to_string(a); } // Convert int to string template <typename T> inline void toInt(string s, T &x) { stringstream str(s); str >> x; } // Convert string to int inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; } inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x; } inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; } inline ll powr(ll a, ll b) { ll x = 1LL; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; } return x; } inline ll inv(ll a) { return powr(a, mod - 2); } const int inv2 = (mod + 1) >> 1; const ll INF = 999999999999999999; const int inf = 999999999; bool check(ll n) { if (n == 1) return 0; if (n == 2 or n == 3) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (ll i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; return 1; } /*********************************************START**************************************************************/ int main() { ifalse; ll n, p; cin >> n >> p; ll ans = 1; for (int i = 2; i * i <= p; i++) { ll cnt = 0; while (p % i == 0) { p /= i; cnt++; } ans = ans * pow(i, cnt / n); } if (p > 1 and n == 1) { ans = ans * p; } cout << ans; return 0; }
/*input 1 8 */ #include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <utility> #include <vector> using namespace std; #define pb push_back #define pp pop_back #define pf pop_front #define nl cout << "\n" #define MIN(con) (*min_element(ALL(con))) #define MAX(con) (*max_element(ALL(con))) #define ALL(cont) (cont).begin(), (cont).end() #define NX(cont) next_permutation(ALL(cont)) #define PX(cont) prev_permutation(ALL(cont)) #define prec(n) cout << fixed << setprecision(n) #define PI 3.14159265358979323846264338327951 #define FH(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ff first #define ss second #define all(c) c.begin(), c.end() #define fill(a, v) memset(a, v, sizeof a) #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i >= b; i--) #define srep(i, s) for (ll i = 0; s[i] != '\0'; i++) #define nn cout << "\n" #define sp cout << " " #define mod 1000000007 // 9 #define ifalse ios_base::sync_with_stdio(false), cin.tie(NULL) using ll = long long; typedef vector<ll> vll; typedef vector<char> vc; typedef vector<string> vst; typedef pair<ll, ll> pll; typedef pair<char, ll> pcl; typedef pair<string, ll> psl; typedef set<ll> sll; typedef set<char> sc; typedef set<string> sst; typedef map<char, ll> mcl; typedef map<ll, ll> mll; typedef map<string, ll> msl; using ld = long double; template <typename T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } template <typename T> inline T GCD(T a, T b) { ll t; while (a) { t = a; a = b % a; b = t; } return b; } template <typename T> inline string toString(T a) { return to_string(a); } // Convert int to string template <typename T> inline void toInt(string s, T &x) { stringstream str(s); str >> x; } // Convert string to int inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; } inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x; } inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; } inline ll powr(ll a, ll b) { ll x = 1LL; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; } return x; } inline ll inv(ll a) { return powr(a, mod - 2); } const int inv2 = (mod + 1) >> 1; const ll INF = 999999999999999999; const int inf = 999999999; bool check(ll n) { if (n == 1) return 0; if (n == 2 or n == 3) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (ll i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; return 1; } /*********************************************START**************************************************************/ int main() { ifalse; ll n, p; cin >> n >> p; ll ans = 1; for (ll i = 2; i * i <= p; i++) { ll cnt = 0; while (p % i == 0) { p /= i; cnt++; } ans = ans * pow(i, cnt / n); } if (p > 1 and n == 1) { ans = ans * p; } cout << ans; return 0; }
replace
130
131
130
131
TLE
p03196
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, p, g = 1; int main() { cin >> n >> p; if (n == 1) return cout << p, 0; for (int i = 2; i * i <= p; i++) if (p % i == 0) { int c = 0; while (p % i == 0) p /= i, c++; for (int j = 0; j < (c / n); j++) g *= i; } cout << g; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, p, g = 1; int main() { cin >> n >> p; if (n == 1) return cout << p, 0; for (ll i = 2; i * i <= p; i++) if (p % i == 0) { int c = 0; while (p % i == 0) p /= i, c++; for (int j = 0; j < (c / n); j++) g *= i; } cout << g; return 0; }
replace
12
13
12
13
TLE
p03196
C++
Runtime Error
// submitted by Himj #include <bits/stdc++.h> #define ll long long #define mod 1000000007 #define pb push_back #define fi first #define se second #define fr(i, s, e) for (i = s; i < e; i++) #define ms(arr, val) memset(arr, val, sizeof(arr)) using namespace std; const int mxn = 2e5 + 1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin>>t; while (t--) { ll n, p, i, j, ans = 1; cin >> n >> p; j = 2; while (j * j <= p) { ll cnt = 0; while (p % j == 0) { p /= j; cnt++; } ans *= pow(j, cnt / n); j++; } if (n == 1) ans *= p; cout << ans; } return 0; }
// submitted by Himj #include <bits/stdc++.h> #define ll long long #define mod 1000000007 #define pb push_back #define fi first #define se second #define fr(i, s, e) for (i = s; i < e; i++) #define ms(arr, val) memset(arr, val, sizeof(arr)) using namespace std; const int mxn = 2e5 + 1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { ll n, p, i, j, ans = 1; cin >> n >> p; j = 2; while (j * j <= p) { ll cnt = 0; while (p % j == 0) { p /= j; cnt++; } ans *= pow(j, cnt / n); j++; } if (n == 1) ans *= p; cout << ans; } return 0; }
replace
17
21
17
18
0
p03197
C++
Runtime Error
// 各ターンで、各色のリンゴは高々1個までしか減らせない // リンゴの数が偶数なら、ルンルンは"あなた"が直前に食べた場合に食べるようにすることで、 // かならず最後にその種類のリンゴを食べることができる。 // リンゴの数が1より大きい奇数なら、ルンルンは"あなた"が最初に食べたあと、そのリンゴを食べないようにして、 // あなたのターンが回ってきた時にそのリンゴの数が偶数個になるようにして、あとは偶数個の場合の戦略で、 // 最後にそのリンゴを食べることができる。 // →だれが先にそのリンゴを食べるかによって戦略が変わるのか? #include <bits/stdc++.h> using namespace std; int N; int a[10]; int tesuu[310000]; // cur := 現在の手数(1,2,3,...) void rec(int cur) { /* for (int i = 0; i < N; ++i) { cout << a[i] << " "; } cout << endl; cout << cur << endl; */ bool flg = true; for (int i = 0; i < N; ++i) { if (a[i] > 0) { flg = false; break; } } if (flg) { // 結果を出力 cout << "cur: " << cur << endl; for (int i = 1; i < cur; ++i) { if (i % 2) cout << "You :"; else cout << "LnLn :"; for (int j = 0; j < N; ++j) { if ((tesuu[i] >> j) & 1) cout << 1 << " "; else cout << 0 << " "; } cout << endl; } if ((cur - 1) % 2) cout << "winner: You" << endl; else cout << "winner: LnLn" << endl; cout << endl; return; } for (int bits = 1; bits < (1 << N); ++bits) { flg = true; for (int i = 0; i < N; ++i) { if (((bits >> i) & 1) && a[i] <= 0) { flg = false; break; } } if (!flg) continue; for (int i = 0; i < N; ++i) { if ((bits >> i) & 1) --a[i]; } tesuu[cur] = bits; rec(cur + 1); // 元に戻す for (int i = 0; i < N; ++i) { if ((bits >> i) & 1) ++a[i]; } } } int main() { cin >> N; for (int i = 0; i < N; ++i) { cin >> a[i]; } // rec(1); for (int i = 0; i < N; ++i) { if (a[i] % 2) { cout << "first" << endl; return 0; } } cout << "second" << endl; return 0; }
// 各ターンで、各色のリンゴは高々1個までしか減らせない // リンゴの数が偶数なら、ルンルンは"あなた"が直前に食べた場合に食べるようにすることで、 // かならず最後にその種類のリンゴを食べることができる。 // リンゴの数が1より大きい奇数なら、ルンルンは"あなた"が最初に食べたあと、そのリンゴを食べないようにして、 // あなたのターンが回ってきた時にそのリンゴの数が偶数個になるようにして、あとは偶数個の場合の戦略で、 // 最後にそのリンゴを食べることができる。 // →だれが先にそのリンゴを食べるかによって戦略が変わるのか? #include <bits/stdc++.h> using namespace std; int N; int a[200000]; int tesuu[310000]; // cur := 現在の手数(1,2,3,...) void rec(int cur) { /* for (int i = 0; i < N; ++i) { cout << a[i] << " "; } cout << endl; cout << cur << endl; */ bool flg = true; for (int i = 0; i < N; ++i) { if (a[i] > 0) { flg = false; break; } } if (flg) { // 結果を出力 cout << "cur: " << cur << endl; for (int i = 1; i < cur; ++i) { if (i % 2) cout << "You :"; else cout << "LnLn :"; for (int j = 0; j < N; ++j) { if ((tesuu[i] >> j) & 1) cout << 1 << " "; else cout << 0 << " "; } cout << endl; } if ((cur - 1) % 2) cout << "winner: You" << endl; else cout << "winner: LnLn" << endl; cout << endl; return; } for (int bits = 1; bits < (1 << N); ++bits) { flg = true; for (int i = 0; i < N; ++i) { if (((bits >> i) & 1) && a[i] <= 0) { flg = false; break; } } if (!flg) continue; for (int i = 0; i < N; ++i) { if ((bits >> i) & 1) --a[i]; } tesuu[cur] = bits; rec(cur + 1); // 元に戻す for (int i = 0; i < N; ++i) { if ((bits >> i) & 1) ++a[i]; } } } int main() { cin >> N; for (int i = 0; i < N; ++i) { cin >> a[i]; } // rec(1); for (int i = 0; i < N; ++i) { if (a[i] % 2) { cout << "first" << endl; return 0; } } cout << "second" << endl; return 0; }
replace
11
12
11
12
0
p03197
Python
Runtime Error
print("second" if all([int(input()) % 2 == 0 for i in range(input())]) else "first")
print( "second" if all([int(input()) % 2 == 0 for i in range(int(input()))]) else "first" )
replace
0
1
0
3
TypeError: 'str' object cannot be interpreted as an integer
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03197/Python/s329085131.py", line 1, in <module> print("second" if all([int(input()) % 2 == 0 for i in range(input())]) else "first") TypeError: 'str' object cannot be interpreted as an integer
p03197
Python
Runtime Error
n = int(input()) A = list(map(int, input().split())) print("second" if all(A[i] % 2 == 0 for i in range(n)) else "first")
n = int(input()) A = [int(input()) for i in range(n)] print("second" if all(A[i] % 2 == 0 for i in range(n)) else "first")
replace
1
2
1
2
0
p03197
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int a[100005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", a + i); if (a[i] % 2) return puts("first"); } puts("second"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int a[100005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { scanf("%d", a + i); if (a[i] % 2) { puts("first"); return 0; } } puts("second"); return 0; }
replace
9
11
9
13
6
p03198
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sqr(x) ((x) * (x)) #define mp make_pair #define ld long double #define PI pair<int, int> inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } #define gc getchar inline ll read() { ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a) { if (a < 0) { a = -a; putchar('-'); } if (a >= 10) write(a / 10); putchar('0' + a % 10); } inline void writeln(ll a) { write(a); puts(""); } inline void wri(ll a) { write(a); putchar(' '); } const int N = 100005; int a[N], q[N], top, A[N]; ll f[N], g[N]; int cmp(ll a, ll b, int c) { if (a > b) { while (a > b) { b <<= 2; c += 2; } return c; } else { while (a <= b) { a <<= 2; c -= 2; } return c + 2; } } int main() { int n = read(); for (int i = 1; i <= n; i++) a[i] = read(); q[0] = n + 1; ll dq = 0; for (int i = n; i; i--) { int t = 0; while (top) { int jb = cmp(a[q[top] - 1], a[q[top]], t); if (jb > 0) { dq += (ll)jb * (q[top - 1] - q[top]); t = jb + A[top]; top--; } else break; } q[++top] = i; A[top] = t; f[i] = dq; } dq = top = q[0] = 0; for (int i = 1; i <= n; i++) { int t = 0; a[i] *= 2; while (top) { int jb = cmp(a[q[top] + 1], a[q[top]], t); if (jb > 0) { dq += (ll)jb * (q[top] - q[top - 1]); t = jb + A[top]; top--; } else break; } q[++top] = i; A[top] = t; g[i] = dq; // cout<<g[i]<<" fjzzq "<<f[i]<<endl; } ll ans = 1e18; for (int i = 0; i <= n; i++) { ans = min(ans, g[i] + f[i + 1] + i); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sqr(x) ((x) * (x)) #define mp make_pair #define ld long double #define PI pair<int, int> inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } #define gc getchar inline ll read() { ll x = 0; char ch = gc(); bool positive = 1; for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0'; return positive ? x : -x; } inline void write(ll a) { if (a < 0) { a = -a; putchar('-'); } if (a >= 10) write(a / 10); putchar('0' + a % 10); } inline void writeln(ll a) { write(a); puts(""); } inline void wri(ll a) { write(a); putchar(' '); } const int N = 200005; int a[N], q[N], top, A[N]; ll f[N], g[N]; int cmp(ll a, ll b, int c) { if (a > b) { while (a > b) { b <<= 2; c += 2; } return c; } else { while (a <= b) { a <<= 2; c -= 2; } return c + 2; } } int main() { int n = read(); for (int i = 1; i <= n; i++) a[i] = read(); q[0] = n + 1; ll dq = 0; for (int i = n; i; i--) { int t = 0; while (top) { int jb = cmp(a[q[top] - 1], a[q[top]], t); if (jb > 0) { dq += (ll)jb * (q[top - 1] - q[top]); t = jb + A[top]; top--; } else break; } q[++top] = i; A[top] = t; f[i] = dq; } dq = top = q[0] = 0; for (int i = 1; i <= n; i++) { int t = 0; a[i] *= 2; while (top) { int jb = cmp(a[q[top] + 1], a[q[top]], t); if (jb > 0) { dq += (ll)jb * (q[top] - q[top - 1]); t = jb + A[top]; top--; } else break; } q[++top] = i; A[top] = t; g[i] = dq; // cout<<g[i]<<" fjzzq "<<f[i]<<endl; } ll ans = 1e18; for (int i = 0; i <= n; i++) { ans = min(ans, g[i] + f[i + 1] + i); } cout << ans << endl; }
replace
42
43
42
43
0
p03198
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; vector<long long> solve(vector<int> A) { int N = A.size(); vector<long long> dp(N); vector<double> diff(N - 1); set<int> four; for (int i = N - 2; i >= 0; --i) { dp[i] = dp[i + 1]; diff[i] = double(A[i + 1]) / A[i]; for (int j = i; j < N - 1; ++j) { while (diff[j] < 0.9999999999) { diff[j] *= 4; dp[i] += (N - j - 1) * 2; if (!four.empty()) { int ptr = *four.begin(); dp[i] -= (N - ptr - 1) * 2; diff[ptr] /= 4; if (diff[ptr] < 3.9999999999) four.erase(ptr); } } } if (diff[i] >= 3.9999999999) four.insert(i); } return dp; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } vector<long long> ldp = solve(A); reverse(A.begin(), A.end()); vector<long long> rdp = solve(A); reverse(rdp.begin(), rdp.end()); long long ans = min(ldp[0], rdp[N - 1] + N); for (int i = 0; i < N - 1; ++i) { ans = min(ans, ldp[i + 1] + rdp[i] + i + 1); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; vector<long long> solve(vector<int> A) { int N = A.size(); vector<long long> dp(N); vector<double> diff(N - 1); set<int> four; for (int i = N - 2; i >= 0; --i) { dp[i] = dp[i + 1]; diff[i] = double(A[i + 1]) / A[i]; while (diff[i] < 0.9999999999) { diff[i] *= 4; dp[i] += (N - i - 1) * 2; if (!four.empty()) { int ptr = *four.begin(); dp[i] -= (N - ptr - 1) * 2; diff[ptr] /= 4; if (diff[ptr] < 3.9999999999) four.erase(ptr); } } if (diff[i] >= 3.9999999999) four.insert(i); } return dp; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } vector<long long> ldp = solve(A); reverse(A.begin(), A.end()); vector<long long> rdp = solve(A); reverse(rdp.begin(), rdp.end()); long long ans = min(ldp[0], rdp[N - 1] + N); for (int i = 0; i < N - 1; ++i) { ans = min(ans, ldp[i + 1] + rdp[i] + i + 1); } cout << ans << endl; return 0; }
replace
13
24
13
22
TLE
p03198
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #define rg register #define ll long long #define LDB long double #define ull unsigned long long #define view(i, x) for (rg int i = hd[x]; i != -1; i = e[i].nt) #define go(i, x, a) for (rg int i = a; i < x; i++) #define inf 0x3f3f3f3f #define INF 0x7fffffff using namespace std; const int maxn = 2 * 1e5 + 5; ll n, dp[2][maxn], la[maxn]; ll q[maxn], tl; ll p4[20], a[maxn]; inline ll rd() { ll ret = 0, af = 1; char gc = getchar(); while (gc < '0' || gc > '9') { if (gc == '-') af = -af; gc = getchar(); } while (gc >= '0' && gc <= '9') ret = ret * 10 + gc - '0', gc = getchar(); return ret * af; } inline int find(ll x, ll y) { if (x == y) return -1; int l = 0, r = 15; while (l < r) { int mid = (l + r + 1) / 2; if ((ull)p4[mid] * x < y) l = mid; else r = mid - 1; } return l; } inline int get(ll x, ll y) { int l = 0, r = 15; while (l < r) { int mid = (l + r + 1) / 2; if ((ull)p4[mid] * x <= y) l = mid; else r = mid - 1; } return l; } int main() { freopen("data.in", "r", stdin); freopen("me.out", "w", stdout); p4[0] = 1; go(i, 16, 1) p4[i] = 4 * p4[i - 1]; n = rd(); go(i, n + 1, 1) a[i] = rd(); dp[1][n] = 0; la[n] = 0; for (rg int i = n - 1; i >= 1; i--) { dp[1][i] = dp[1][i + 1]; if (a[i] <= a[i + 1]) la[i] = get(a[i], a[i + 1]), q[++tl] = i; else { int qs = find(a[i + 1], a[i]) + 1; while (qs > 0) { if (tl == 0) break; int pos = q[tl], tt = 0; if (la[pos] > qs) tt = qs, la[pos] -= qs, qs = 0; else tt = la[pos], qs -= la[pos], la[pos] = 0, tl--; dp[1][i] += (ll)tt * (ll)(pos - i); } dp[1][i] += qs * (ll)(n - i); } } tl = 0; memset(la, 0, sizeof(la)); dp[0][1] = 0; la[1] = 0; go(i, n + 1, 1) a[i] *= 2; for (rg int i = 2; i <= n; i++) { dp[0][i] = dp[0][i - 1]; if (a[i] < a[i - 1]) la[i] = get(a[i], a[i - 1]), q[++tl] = i; else { int qs = find(a[i - 1], a[i]) + 1; while (qs > 0) { if (tl == 0) break; int pos = q[tl], tt = 0; if (la[pos] > qs) tt = qs, la[pos] -= qs, qs = 0; else tt = la[pos], qs -= la[pos], la[pos] = 0, tl--; dp[0][i] += (ll)tt * (ll)(i - pos); } dp[0][i] += qs * (ll)(i - 1); } } for (rg int i = n; i >= 1; i--) dp[0][i] = dp[0][i - 1]; go(i, n + 1, 1) dp[0][i] *= 2, dp[1][i] *= 2; go(i, n + 1, 1) dp[0][i] += i - 1; ll ans = 1e18; int pos = 0; go(i, n + 1, 1) if (dp[1][i] + dp[0][i] < ans) ans = dp[1][i] + dp[0][i]; printf("%lld", ans); return 0; } // Faze
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #define rg register #define ll long long #define LDB long double #define ull unsigned long long #define view(i, x) for (rg int i = hd[x]; i != -1; i = e[i].nt) #define go(i, x, a) for (rg int i = a; i < x; i++) #define inf 0x3f3f3f3f #define INF 0x7fffffff using namespace std; const int maxn = 2 * 1e5 + 5; ll n, dp[2][maxn], la[maxn]; ll q[maxn], tl; ll p4[20], a[maxn]; inline ll rd() { ll ret = 0, af = 1; char gc = getchar(); while (gc < '0' || gc > '9') { if (gc == '-') af = -af; gc = getchar(); } while (gc >= '0' && gc <= '9') ret = ret * 10 + gc - '0', gc = getchar(); return ret * af; } inline int find(ll x, ll y) { if (x == y) return -1; int l = 0, r = 15; while (l < r) { int mid = (l + r + 1) / 2; if ((ull)p4[mid] * x < y) l = mid; else r = mid - 1; } return l; } inline int get(ll x, ll y) { int l = 0, r = 15; while (l < r) { int mid = (l + r + 1) / 2; if ((ull)p4[mid] * x <= y) l = mid; else r = mid - 1; } return l; } int main() { p4[0] = 1; go(i, 16, 1) p4[i] = 4 * p4[i - 1]; n = rd(); go(i, n + 1, 1) a[i] = rd(); dp[1][n] = 0; la[n] = 0; for (rg int i = n - 1; i >= 1; i--) { dp[1][i] = dp[1][i + 1]; if (a[i] <= a[i + 1]) la[i] = get(a[i], a[i + 1]), q[++tl] = i; else { int qs = find(a[i + 1], a[i]) + 1; while (qs > 0) { if (tl == 0) break; int pos = q[tl], tt = 0; if (la[pos] > qs) tt = qs, la[pos] -= qs, qs = 0; else tt = la[pos], qs -= la[pos], la[pos] = 0, tl--; dp[1][i] += (ll)tt * (ll)(pos - i); } dp[1][i] += qs * (ll)(n - i); } } tl = 0; memset(la, 0, sizeof(la)); dp[0][1] = 0; la[1] = 0; go(i, n + 1, 1) a[i] *= 2; for (rg int i = 2; i <= n; i++) { dp[0][i] = dp[0][i - 1]; if (a[i] < a[i - 1]) la[i] = get(a[i], a[i - 1]), q[++tl] = i; else { int qs = find(a[i - 1], a[i]) + 1; while (qs > 0) { if (tl == 0) break; int pos = q[tl], tt = 0; if (la[pos] > qs) tt = qs, la[pos] -= qs, qs = 0; else tt = la[pos], qs -= la[pos], la[pos] = 0, tl--; dp[0][i] += (ll)tt * (ll)(i - pos); } dp[0][i] += qs * (ll)(i - 1); } } for (rg int i = n; i >= 1; i--) dp[0][i] = dp[0][i - 1]; go(i, n + 1, 1) dp[0][i] *= 2, dp[1][i] *= 2; go(i, n + 1, 1) dp[0][i] += i - 1; ll ans = 1e18; int pos = 0; go(i, n + 1, 1) if (dp[1][i] + dp[0][i] < ans) ans = dp[1][i] + dp[0][i]; printf("%lld", ans); return 0; } // Faze
delete
62
64
62
62
TLE
p03198
C++
Time Limit Exceeded
#include <bits/stdc++.h> clock_t t = clock(); namespace my_std { using namespace std; #define pii pair<int, int> #define fir first #define sec second #define MP make_pair #define rep(i, x, y) for (int i = (x); i <= (y); i++) #define drep(i, x, y) for (int i = (x); i >= (y); i--) #define go(x) for (int i = head[x]; i; i = edge[i].nxt) #define templ template <typename T> #define sz 101010 typedef long long ll; typedef double db; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); templ inline T rnd(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } templ inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } templ inline bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } templ inline void read(T &t) { t = 0; char f = 0, ch = getchar(); double d = 0.1; while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar(); while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar(); if (ch == '.') { ch = getchar(); while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar(); } t = (f ? -t : t); } template <typename T, typename... Args> inline void read(T &t, Args &...args) { read(t); read(args...); } char __sr[1 << 21], __z[20]; int __C = -1, __zz = 0; inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; } inline void print(register int x) { if (__C > 1 << 20) Ot(); if (x < 0) __sr[++__C] = '-', x = -x; while (__z[++__zz] = x % 10 + 48, x /= 10) ; while (__sr[++__C] = __z[__zz], --__zz) ; __sr[++__C] = '\n'; } void file() { #ifdef NTFOrz freopen("a.in", "r", stdin); #endif } inline void chktime() { #ifdef NTFOrz cout << (clock() - t) / 1000.0 << '\n'; #endif } #ifdef mod ll ksm(ll x, int y) { ll ret = 1; for (; y; y >>= 1, x = x * x % mod) if (y & 1) ret = ret * x % mod; return ret; } ll inv(ll x) { return ksm(x, mod - 2); } #else ll ksm(ll x, int y) { ll ret = 1; for (; y; y >>= 1, x = x * x) if (y & 1) ret = ret * x; return ret; } #endif // inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll //ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;} } // namespace my_std using namespace my_std; int n; ll a[sz]; ll f[sz], g[sz]; int w[sz], sum[sz]; ll S[sz]; void work(ll *f) { rep(i, 1, n - 1) { ll x = a[i], y = a[i + 1], w = 0; while (x < a[i + 1]) x *= 4, ++w; while (a[i] >= y * 4) y *= 4, --w; ::w[i] = w; sum[i] = sum[i - 1] + w; S[i] = S[i - 1] + w * i; } stack<pii> s; s.push(MP(-1, INT_MAX)); s.push(MP(0, 0)); rep(i, 1, n - 1) { while (sum[i] >= s.top().sec) s.pop(); int j = s.top().fir; f[i] = S[i] - S[j + 1] - 1ll * (j + 1) * (sum[i] - sum[j + 1]); if (j > 0) f[i] += f[j]; s.push(MP(i, sum[i])); } } int main() { file(); read(n); rep(i, 1, n) read(a[i]); work(f); reverse(a + 1, a + n + 1); work(g); reverse(g + 1, g + n + 1); ll ans = 1e18; rep(i, 0, n) chkmin(ans, i + 2 * (g[i + 2] + (i ? f[i - 1] : 0))); cout << ans; return 0; }
#include <bits/stdc++.h> clock_t t = clock(); namespace my_std { using namespace std; #define pii pair<int, int> #define fir first #define sec second #define MP make_pair #define rep(i, x, y) for (int i = (x); i <= (y); i++) #define drep(i, x, y) for (int i = (x); i >= (y); i--) #define go(x) for (int i = head[x]; i; i = edge[i].nxt) #define templ template <typename T> #define sz 201010 typedef long long ll; typedef double db; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); templ inline T rnd(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } templ inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } templ inline bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } templ inline void read(T &t) { t = 0; char f = 0, ch = getchar(); double d = 0.1; while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar(); while (ch <= '9' && ch >= '0') t = t * 10 + ch - 48, ch = getchar(); if (ch == '.') { ch = getchar(); while (ch <= '9' && ch >= '0') t += d * (ch ^ 48), d *= 0.1, ch = getchar(); } t = (f ? -t : t); } template <typename T, typename... Args> inline void read(T &t, Args &...args) { read(t); read(args...); } char __sr[1 << 21], __z[20]; int __C = -1, __zz = 0; inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; } inline void print(register int x) { if (__C > 1 << 20) Ot(); if (x < 0) __sr[++__C] = '-', x = -x; while (__z[++__zz] = x % 10 + 48, x /= 10) ; while (__sr[++__C] = __z[__zz], --__zz) ; __sr[++__C] = '\n'; } void file() { #ifdef NTFOrz freopen("a.in", "r", stdin); #endif } inline void chktime() { #ifdef NTFOrz cout << (clock() - t) / 1000.0 << '\n'; #endif } #ifdef mod ll ksm(ll x, int y) { ll ret = 1; for (; y; y >>= 1, x = x * x % mod) if (y & 1) ret = ret * x % mod; return ret; } ll inv(ll x) { return ksm(x, mod - 2); } #else ll ksm(ll x, int y) { ll ret = 1; for (; y; y >>= 1, x = x * x) if (y & 1) ret = ret * x; return ret; } #endif // inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll //ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;} } // namespace my_std using namespace my_std; int n; ll a[sz]; ll f[sz], g[sz]; int w[sz], sum[sz]; ll S[sz]; void work(ll *f) { rep(i, 1, n - 1) { ll x = a[i], y = a[i + 1], w = 0; while (x < a[i + 1]) x *= 4, ++w; while (a[i] >= y * 4) y *= 4, --w; ::w[i] = w; sum[i] = sum[i - 1] + w; S[i] = S[i - 1] + w * i; } stack<pii> s; s.push(MP(-1, INT_MAX)); s.push(MP(0, 0)); rep(i, 1, n - 1) { while (sum[i] >= s.top().sec) s.pop(); int j = s.top().fir; f[i] = S[i] - S[j + 1] - 1ll * (j + 1) * (sum[i] - sum[j + 1]); if (j > 0) f[i] += f[j]; s.push(MP(i, sum[i])); } } int main() { file(); read(n); rep(i, 1, n) read(a[i]); work(f); reverse(a + 1, a + n + 1); work(g); reverse(g + 1, g + n + 1); ll ans = 1e18; rep(i, 0, n) chkmin(ans, i + 2 * (g[i + 2] + (i ? f[i - 1] : 0))); cout << ans; return 0; }
replace
12
13
12
13
TLE
p03198
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <ciso646> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define inf 0x3f3f3f3f3f3f3f3f #define ALL(a) (a).begin(), (a).end() #define DEBUG(x) // cerr<<#x<<": "<<x<<endl #define ll long long #define ull unsigned long long using pii = pair<ll, ll>; #define eps 1e-14 #define SETUP \ cin.tie(0), ios::sync_with_stdio(false), \ cout << setprecision(15) << std::fixed; template <class T> using vec2 = std::vector<vector<T>>; namespace { struct input_returnner { ll N; input_returnner(ll N_ = 0) : N(N_) {} template <typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); } template <typename T> operator T() const { T res; cin >> res; return res; } template <typename T> T operator-(T right) { return T(input_returnner()) - right; } template <typename T> T operator+(T right) { return T(input_returnner()) + right; } template <typename T> T operator*(T right) { return T(input_returnner()) * right; } template <typename T> T operator/(T right) { return T(input_returnner()) / right; } template <typename T> T operator<<(T right) { return T(input_returnner()) << right; } template <typename T> T operator>>(T right) { return T(input_returnner()) >> right; } }; template <typename T> input_returnner in() { return in<T>(); } input_returnner in() { return input_returnner(); } input_returnner in(ll N) { return std::move(input_returnner(N)); } } // namespace template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> struct is_vector : std::false_type {}; template <typename T> struct is_vector<std::vector<T>> : std::true_type {}; template <typename T> constexpr bool is_vector_v = is_vector<T>::value; template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { if (!v.empty()) { for (int i = 0; i < v.size(); ++i) { out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", ")); } } return out; } namespace std { // ref: // https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set template <class T> inline void hash_combine(std::size_t &seed, T const &v) { seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } // Recursive template code derived from Matthieu M. template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1> struct HashValueImpl { static void apply(size_t &seed, Tuple const &tuple) { HashValueImpl<Tuple, Index - 1>::apply(seed, tuple); hash_combine(seed, std::get<Index>(tuple)); } }; template <class Tuple> struct HashValueImpl<Tuple, 0> { static void apply(size_t &seed, Tuple const &tuple) { hash_combine(seed, std::get<0>(tuple)); } }; template <typename... TT> struct hash<std::tuple<TT...>> { size_t operator()(std::tuple<TT...> const &tt) const { size_t seed = 0; HashValueImpl<std::tuple<TT...>>::apply(seed, tt); return seed; } }; template <class T, class U> class hash<std::pair<T, U>> { public: size_t operator()(const std::pair<T, U> &x) const { return hash<std::tuple<T, U>>()(std::tie(x.first, x.second)); } }; } // namespace std // ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple namespace aux { template <std::size_t...> struct seq {}; template <std::size_t N, std::size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Ch, class Tr, class Tuple, std::size_t... Is> void print_tuple(std::basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) { using swallow = int[]; (void)swallow{0, (void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...}; } } // namespace aux template <class Ch, class Tr, class... Args> auto operator<<(std::basic_ostream<Ch, Tr> &os, std::tuple<Args...> const &t) -> std::basic_ostream<Ch, Tr> & { os << "("; aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>()); return os << ")"; } template <class S, class T> std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } // ref: // https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp template <typename T> struct reversion_wrapper { T &iterable; }; template <typename T> auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); } template <typename T> auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); } template <typename T> reversion_wrapper<T> REV(T &&iterable) { return {iterable}; } template <class T> bool inside(T left, T val, T right) { return left <= val and val < right; } template <class T> T bitCount(T num) { T res = 0; while (num > 0) { if (num & 1) ++res; num >>= 1; } return res; } ll MOD = 1e9 + 7; void solve(); signed main() { SETUP; #ifdef _DEBUG while (true) { #endif solve(); #ifdef _DEBUG cout << "-------" << endl; } #endif #ifdef _DEBUG system("pause"); #endif return 0; } #define int ll // template vector<int> solve(vector<int> A) { stack<int> st; int N = A.size(); st.push(A.size() - 1); vector<int> res(N); RFOR(i, 0, N - 1) { int &left = A[i]; int &right = A[i + 1]; int cnt = 0; while (left > right) { right *= 4; int index = st.top(); st.pop(); cnt += (index - i); if (index != i + 1) { A[index] *= 4; } if (index + 1 == N or A[index] * 4 <= A[index + 1]) st.push(index); } if (left * 4 <= right) st.push(left); res[i] = cnt; } RFOR(i, 0, N - 2) { res[i] += res[i + 1]; } return res; } void solve() { int N; cin >> N; vector<int> A(N); for (auto &a : A) cin >> a; vector<int> right = solve(A); reverse(ALL(A)); vector<int> left = solve(A); reverse(ALL(left)); int res = min(left.back() * 2 + N, right.front() * 2); REP(i, N - 1) { res = min(res, (left[i] + right[i + 1]) * 2 + i + 1); } cout << res << endl; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <ciso646> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define inf 0x3f3f3f3f3f3f3f3f #define ALL(a) (a).begin(), (a).end() #define DEBUG(x) // cerr<<#x<<": "<<x<<endl #define ll long long #define ull unsigned long long using pii = pair<ll, ll>; #define eps 1e-14 #define SETUP \ cin.tie(0), ios::sync_with_stdio(false), \ cout << setprecision(15) << std::fixed; template <class T> using vec2 = std::vector<vector<T>>; namespace { struct input_returnner { ll N; input_returnner(ll N_ = 0) : N(N_) {} template <typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); } template <typename T> operator T() const { T res; cin >> res; return res; } template <typename T> T operator-(T right) { return T(input_returnner()) - right; } template <typename T> T operator+(T right) { return T(input_returnner()) + right; } template <typename T> T operator*(T right) { return T(input_returnner()) * right; } template <typename T> T operator/(T right) { return T(input_returnner()) / right; } template <typename T> T operator<<(T right) { return T(input_returnner()) << right; } template <typename T> T operator>>(T right) { return T(input_returnner()) >> right; } }; template <typename T> input_returnner in() { return in<T>(); } input_returnner in() { return input_returnner(); } input_returnner in(ll N) { return std::move(input_returnner(N)); } } // namespace template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> struct is_vector : std::false_type {}; template <typename T> struct is_vector<std::vector<T>> : std::true_type {}; template <typename T> constexpr bool is_vector_v = is_vector<T>::value; template <typename T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { if (!v.empty()) { for (int i = 0; i < v.size(); ++i) { out << v[i] << (i == v.size() - 1 ? "\n" : (is_vector_v<T> ? "" : ", ")); } } return out; } namespace std { // ref: // https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set template <class T> inline void hash_combine(std::size_t &seed, T const &v) { seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } // Recursive template code derived from Matthieu M. template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1> struct HashValueImpl { static void apply(size_t &seed, Tuple const &tuple) { HashValueImpl<Tuple, Index - 1>::apply(seed, tuple); hash_combine(seed, std::get<Index>(tuple)); } }; template <class Tuple> struct HashValueImpl<Tuple, 0> { static void apply(size_t &seed, Tuple const &tuple) { hash_combine(seed, std::get<0>(tuple)); } }; template <typename... TT> struct hash<std::tuple<TT...>> { size_t operator()(std::tuple<TT...> const &tt) const { size_t seed = 0; HashValueImpl<std::tuple<TT...>>::apply(seed, tt); return seed; } }; template <class T, class U> class hash<std::pair<T, U>> { public: size_t operator()(const std::pair<T, U> &x) const { return hash<std::tuple<T, U>>()(std::tie(x.first, x.second)); } }; } // namespace std // ref: https://stackoverflow.com/questions/6245735/pretty-print-stdtuple namespace aux { template <std::size_t...> struct seq {}; template <std::size_t N, std::size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <std::size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Ch, class Tr, class Tuple, std::size_t... Is> void print_tuple(std::basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) { using swallow = int[]; (void)swallow{0, (void(os << (Is == 0 ? "" : ", ") << std::get<Is>(t)), 0)...}; } } // namespace aux template <class Ch, class Tr, class... Args> auto operator<<(std::basic_ostream<Ch, Tr> &os, std::tuple<Args...> const &t) -> std::basic_ostream<Ch, Tr> & { os << "("; aux::print_tuple(os, t, aux::gen_seq<sizeof...(Args)>()); return os << ")"; } template <class S, class T> std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } // ref: // https://stackoverflow.com/questions/8542591/c11-reverse-range-based-for-loo�Fp template <typename T> struct reversion_wrapper { T &iterable; }; template <typename T> auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); } template <typename T> auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); } template <typename T> reversion_wrapper<T> REV(T &&iterable) { return {iterable}; } template <class T> bool inside(T left, T val, T right) { return left <= val and val < right; } template <class T> T bitCount(T num) { T res = 0; while (num > 0) { if (num & 1) ++res; num >>= 1; } return res; } ll MOD = 1e9 + 7; void solve(); signed main() { SETUP; #ifdef _DEBUG while (true) { #endif solve(); #ifdef _DEBUG cout << "-------" << endl; } #endif #ifdef _DEBUG system("pause"); #endif return 0; } #define int ll // template vector<int> solve(vector<int> A) { stack<int> st; int N = A.size(); st.push(A.size() - 1); vector<int> res(N); RFOR(i, 0, N - 1) { int &left = A[i]; int &right = A[i + 1]; int cnt = 0; while (left > right) { right *= 4; int index = st.top(); st.pop(); cnt += (index - i); if (index != i + 1) { A[index] *= 4; } if (index + 1 == N or A[index] * 4 <= A[index + 1]) st.push(index); } if (left * 4 <= right) st.push(i); res[i] = cnt; } RFOR(i, 0, N - 2) { res[i] += res[i + 1]; } return res; } void solve() { int N; cin >> N; vector<int> A(N); for (auto &a : A) cin >> a; vector<int> right = solve(A); reverse(ALL(A)); vector<int> left = solve(A); reverse(ALL(left)); int res = min(left.back() * 2 + N, right.front() * 2); REP(i, N - 1) { res = min(res, (left[i] + right[i + 1]) * 2 + i + 1); } cout << res << endl; }
replace
254
255
254
255
0
p03198
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; int read() { char ch = getchar(); int f = 0, x = 1; while (ch < '0' || ch > '9') { if (ch == '-') x = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { f = (f << 1) + (f << 3) + ch - '0'; ch = getchar(); } return f * x; } ll f[200005][19], g[200005][19]; int n; ll a[200005], pow1[17]; const ll inf = 1000000000000000000LL; int main() { freopen("1.in", "r", stdin); memset(f, 0x3f3f3f3f, sizeof(f)); memset(g, 0x3f3f3f3f, sizeof(g)); for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= 15; j++) f[i][j] = g[i][j] = inf; } n = read(); pow1[0] = 1; for (int i = 1; i <= 15; i++) pow1[i] = pow1[i - 1] * 4; for (int i = 1; i <= n; i++) { a[i] = read(); } for (int i = 0; i <= 15; i++) f[1][i] = i; for (int i = 2; i <= n; i++) { for (int j = 0; j <= 15; j++) { for (int k = 15; k >= 0; k--) { if (a[i - 1] * pow1[k] >= a[i] * pow1[j]) { f[i][j] = min(f[i][j], f[i - 1][k] + j); // cout<<k<<endl; } // else break; } if (f[i][j] == 4557430888798830399LL) f[i][j] = f[i][j - 1] + i; // cout<<f[i][j]<<' '; } // cout<<endl; } for (int i = 0; i <= 15; i++) g[n][i] = i; for (int i = n - 1; i; i--) { for (int j = 0; j <= 15; j++) { for (int k = 15; k >= 0; k--) { if (a[i + 1] * pow1[k] >= a[i] * pow1[j]) { g[i][j] = min(g[i][j], g[i + 1][k] + j); } // else break; } if (g[i][j] == 4557430888798830399LL) g[i][j] = g[i][j - 1] + (n - i + 1); } } ll ans = inf; f[0][0] = g[0][0] = f[n + 1][0] = g[n + 1][0] = 0; for (int i = 0; i <= n; i++) { // cout<<f[i][0]<<" "<<g[i][0]<<endl; ll num1, num2; num1 = num2 = inf; for (int j = 0; j <= 15; j++) { num1 = min(num1, f[i][j]); num2 = min(num2, g[i + 1][j]); } ans = min(ans, 1LL * num1 * 2 + 1LL * num2 * 2 + 1LL * i); // cout<<i<<" "<<num1<<" "<<num2<<endl; } cout << ans; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; int read() { char ch = getchar(); int f = 0, x = 1; while (ch < '0' || ch > '9') { if (ch == '-') x = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { f = (f << 1) + (f << 3) + ch - '0'; ch = getchar(); } return f * x; } ll f[200005][19], g[200005][19]; int n; ll a[200005], pow1[17]; const ll inf = 1000000000000000000LL; int main() { // freopen("1.in","r",stdin); memset(f, 0x3f3f3f3f, sizeof(f)); memset(g, 0x3f3f3f3f, sizeof(g)); for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= 15; j++) f[i][j] = g[i][j] = inf; } n = read(); pow1[0] = 1; for (int i = 1; i <= 15; i++) pow1[i] = pow1[i - 1] * 4; for (int i = 1; i <= n; i++) { a[i] = read(); } for (int i = 0; i <= 15; i++) f[1][i] = i; for (int i = 2; i <= n; i++) { for (int j = 0; j <= 15; j++) { for (int k = 15; k >= 0; k--) { if (a[i - 1] * pow1[k] >= a[i] * pow1[j]) { f[i][j] = min(f[i][j], f[i - 1][k] + j); // cout<<k<<endl; } // else break; } if (f[i][j] == 4557430888798830399LL) f[i][j] = f[i][j - 1] + i; // cout<<f[i][j]<<' '; } // cout<<endl; } for (int i = 0; i <= 15; i++) g[n][i] = i; for (int i = n - 1; i; i--) { for (int j = 0; j <= 15; j++) { for (int k = 15; k >= 0; k--) { if (a[i + 1] * pow1[k] >= a[i] * pow1[j]) { g[i][j] = min(g[i][j], g[i + 1][k] + j); } // else break; } if (g[i][j] == 4557430888798830399LL) g[i][j] = g[i][j - 1] + (n - i + 1); } } ll ans = inf; f[0][0] = g[0][0] = f[n + 1][0] = g[n + 1][0] = 0; for (int i = 0; i <= n; i++) { // cout<<f[i][0]<<" "<<g[i][0]<<endl; ll num1, num2; num1 = num2 = inf; for (int j = 0; j <= 15; j++) { num1 = min(num1, f[i][j]); num2 = min(num2, g[i + 1][j]); } ans = min(ans, 1LL * num1 * 2 + 1LL * num2 * 2 + 1LL * i); // cout<<i<<" "<<num1<<" "<<num2<<endl; } cout << ans; }
replace
26
27
26
27
TLE
p03198
C++
Runtime Error
#include <bits/stdc++.h> #define inf (long long)(1e18) using namespace std; long long n; vector<long long> a, pre, suf; long long solve(); int main() { cin >> n; a.resize(n); for (auto &p : a) cin >> p; cout << solve() << endl; return 0; } long long solve() { auto calc = [](vector<long long> &v) { int len = 16; vector<long long> res(n + 1, inf); vector<vector<long long>> dp(n + 1, vector<long long>(len + 1, inf)); res[n] = res[n - 1] = 0; for (int i = 0; i <= len; ++i) dp[n - 1][i] = i; for (int i = n - 2; i >= 0; --i) { long long now = v[i]; for (int j = 0; j <= len; ++j) { long long nxt = v[i + 1]; for (int k = 0; k <= 60; ++k) { if (now <= nxt) { if (k <= len) dp[i][j] = dp[i + 1][k] + j; else dp[i][j] = dp[i + 1][len] + (k - len) * (n - 1 - i) + j; break; } nxt <<= 2; } assert(dp[i][j] != inf); now <<= 2; } res[i] = dp[i][0] << 1; } return res; }; suf = calc(a); reverse(a.begin(), a.end()); for (auto &p : a) p *= 2; pre = calc(a); reverse(pre.begin(), pre.end()); for (int i = 0; i <= n; ++i) pre[i] += i; long long res = inf; for (int i = 0; i <= n; ++i) res = min(res, pre[i] + suf[i]); return res; }
#include <bits/stdc++.h> #define inf (long long)(1e18) using namespace std; long long n; vector<long long> a, pre, suf; long long solve(); int main() { cin >> n; a.resize(n); for (auto &p : a) cin >> p; cout << solve() << endl; return 0; } long long solve() { auto calc = [](vector<long long> &v) { int len = 15; vector<long long> res(n + 1, inf); vector<vector<long long>> dp(n + 1, vector<long long>(len + 1, inf)); res[n] = res[n - 1] = 0; for (int i = 0; i <= len; ++i) dp[n - 1][i] = i; for (int i = n - 2; i >= 0; --i) { long long now = v[i]; for (int j = 0; j <= len; ++j) { long long nxt = v[i + 1]; for (int k = 0; k <= 60; ++k) { if (now <= nxt) { if (k <= len) dp[i][j] = dp[i + 1][k] + j; else dp[i][j] = dp[i + 1][len] + (k - len) * (n - 1 - i) + j; break; } nxt <<= 2; } assert(dp[i][j] != inf); now <<= 2; } res[i] = dp[i][0] << 1; } return res; }; suf = calc(a); reverse(a.begin(), a.end()); for (auto &p : a) p *= 2; pre = calc(a); reverse(pre.begin(), pre.end()); for (int i = 0; i <= n; ++i) pre[i] += i; long long res = inf; for (int i = 0; i <= n; ++i) res = min(res, pre[i] + suf[i]); return res; }
replace
20
21
20
21
0
p03198
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fr(i, n) for (int i = 0; i < (n); ++i) #define foor(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, n) for (int i = (n); i--;) #define roof(i, b, a) for (int i = (b); i >= (a); --i) #define elsif else if #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define Reverse(x) reverse(all(x)) #define PQ priority_queue #define NP(x) next_permutation(all(x)) #define M_PI 3.14159265358979323846 #define popcount __builtin_popcount using namespace std; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef unsigned long long ull; typedef vector<ull> vu; typedef vector<vu> vvu; typedef double dbl; typedef vector<dbl> vd; typedef vector<vd> vvd; typedef string str; typedef vector<str> vs; typedef vector<vs> vvs; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef map<int, int> mii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef map<ll, ll> mll; typedef pair<dbl, dbl> pdd; typedef vector<pdd> vpdd; typedef map<dbl, dbl> mdd; typedef pair<str, str> pss; typedef vector<pss> vpss; typedef map<str, str> mss; typedef pair<int, ll> pil; typedef vector<pil> vpil; typedef map<int, ll> mil; typedef pair<ll, int> pli; typedef vector<pli> vpli; typedef map<ll, int> mli; typedef pair<dbl, int> pdi; typedef vector<pdi> vpdi; typedef map<dbl, int> mdi; template <typename T> vector<T> &operator<<(vector<T> &v, const T t) { v.push_back(t); return v; } template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) { m.insert(t); return m; } template <typename T> set<T> &operator<<(set<T> &s, const T t) { s.insert(t); return s; } template <typename T> stack<T> &operator<<(stack<T> &s, const T t) { s.push(t); return s; } template <typename T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } template <typename T> queue<T> &operator<<(queue<T> &q, const T t) { q.push(t); return q; } template <typename T> queue<T> &operator>>(queue<T> &q, T &t) { t = q.front(); q.pop(); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) { q.push(t); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) { t = q.top(); q.pop(); return q; } template <typename T, typename U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } istream &operator>>(istream &s, _Bit_reference b) { int a; s >> a; assert(a == 0 || a == 1); b = a; return s; } template <typename T> istream &operator>>(istream &s, vector<T> &v) { fr(i, v.size()) { s >> v[i]; } return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } // template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto // a:v){s<<a<<"\n";}return s;} template <typename T> ostream &operator<<(ostream &s, const vector<T> v) { fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; } return s; } template <typename T> ostream &operator<<(ostream &s, const deque<T> d) { fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; } return s; } template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) { return b = b & t; } template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) { return b = b ^ t; } template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) { return b = b | t; } template <typename T, typename U> pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename U> pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { return {a.first - b.first, a.second - b.second}; } template <typename T, typename U> pair<T, U> &operator+=(pair<T, U> &a, pair<T, U> b) { return a = a + b; } template <typename T, typename U> pair<T, U> &operator-=(pair<T, U> &a, pair<T, U> b) { return a = a - b; } void print(void) { cout << "\n"; } void Print(void) { cout << endl; } template <typename T> void print(T t) { cout << t << "\n"; } template <typename T> void Print(T t) { cout << t << endl; } template <typename T, typename... U> void print(T &&t, U &&...u) { cout << t << " "; print(forward<U>(u)...); } template <typename T, typename... U> void Print(T &&t, U &&...u) { cout << t << " "; Print(forward<U>(u)...); } bool YN(bool b) { print(b ? "YES" : "NO"); return b; } bool PI(bool b) { print(b ? "POSSIBLE" : "IMPOSSIBLE"); return b; } bool Yn(bool b) { print(b ? "Yes" : "No"); return b; } bool Pi(bool b) { print(b ? "Possible" : "Impossible"); return b; } bool yn(bool b) { print(b ? "yes" : "no"); return b; } bool pi(bool b) { print(b ? "possible" : "impossible"); return b; } const int e5 = 1e5; const int e9 = 1e9; const int MD = 1e9 + 7; const ll e18 = 1e18; template <typename T> str to_string(const T &n) { ostringstream s; s << n; return s.str(); } template <typename T> T &chmax(T &a, T b) { return a = max(a, b); } template <typename T> T &chmin(T &a, T b) { return a = min(a, b); } template <typename T, typename U> vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s, const T inf) { using P = pair<T, U>; vector<P> d; fr(i, E.size()) { d << P{inf, i}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } template <typename T, typename U> map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s, const T inf) { using P = pair<T, U>; map<U, P> d; for (pair<U, vector<P>> e : E) { d[e.first] = P{inf, e.first}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } ll maxflow(vector<mil> &E, int s, int t) { ll z = 0; vi b(E.size(), -1); for (int i = 0;; ++i) { static auto dfs = [&](int v, ll f, auto &dfs) -> ll { if (v == t) return f; b[v] = i; for (auto &p : E[v]) { if (b[p.first] < i && p.second) { if (ll r = dfs(p.first, min(f, p.second), dfs)) { p.second -= r; E[p.first][v] += r; return r; } } } return 0; }; ll x = dfs(s, ll(1e18), dfs); z += x; if (x == 0) return z; } } template <typename T> T distsq(pair<T, T> a, pair<T, T> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } template <typename T> T max(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = max(m, e); } return m; } template <typename T> T min(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = min(m, e); } return m; } template <typename T> T gcd(const T a, const T b) { return a ? gcd(b % a, a) : b; } template <typename T> T gcd(const vector<T> a) { T g = a[0]; for (T e : a) { g = gcd(g, e); } return g; } template <typename T> vector<T> LIS(const vector<T> A) { vector<T> B; for (T a : A) { auto it = lower_bound(all(B), a); if (it == B.end()) { B << a; } else { *it = a; } } return B; } template <typename T> vector<T> LCS(vector<T> A, vector<T> B) { int N = A.size(), M = B.size(); vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1)); fr(i, N) { fr(j, M) { if (A[i] == B[j]) { d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}}; } else { d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]); } } } vector<T> r; for (pii p = {N, M}; d[p.first][p.second].first; p = d[p.first][p.second].second) { r << A[d[p.first][p.second].second.first]; } Reverse(r); return r; } str LCS(str S, str T) { vector<char> s = LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end())); return str(s.begin(), s.end()); } template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) { if (V.size() <= 3) { return V; } Sort(V); rf(i, V.size() - 1) V << V[i]; vector<pair<T, T>> r; for (pair<T, T> p : V) { int s = r.size(); while (s >= 2 && (p.second - r[s - 1].second) * (p.first - r[s - 2].first) < (p.second - r[s - 2].second) * (p.first - r[s - 1].first)) { r.pop_back(); --s; } r << p; } r.pop_back(); return r; } class UnionFind { vi p, s; void extend(int N) { foor(i, p.size(), N) { p << i; s << 1; } } public: UnionFind(void) {} UnionFind(int N) { extend(N - 1); } int find(int i) { extend(i); return p[i] = p[i] == i ? i : find(p[i]); } void unite(int a, int b) { extend(a); extend(b); if ((a = find(a)) != (b = find(b))) { if (s[a] > s[b]) { swap(a, b); } s[b] += s[a]; p[a] = b; } } void unite(pii p) { return unite(p.first, p.second); } bool same(int a, int b) { extend(a); extend(b); return find(a) == find(b); } bool same(pii p) { return same(p.first, p.second); } int size(int x) { extend(x); return s[find(x)]; } }; ll MST(vector<pair<ll, pii>> &E) { Sort(E); UnionFind uf; ll z = 0; for (auto &e : E) { if (!uf.same(e.second)) { z += e.first; uf.unite(e.second); } } return z; } ll strmod(const str &s, const int m) { ll x = 0; fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; } return x; } vvl mul(const vvl &A, const vvl &B, const int m) { vvl C; fr(y, A.size()) { C << vl(B[y].size()); } fr(y, C.size()) { fr(x, C[y].size()) { fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; } } } return C; } vvl pow(const vvl &A, const ll n, const int m) { vvl B; fr(y, A.size()) { B << vl(A.size()); } if (n == 0) { fr(i, B.size()) { B[i][i] = 1; } } elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); } else { vvl C = pow(A, n / 2, m); B = mul(C, C, m); } return B; } ll pow(const ll a, const ll n, const int m) { ll t; return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) * (t = pow(a, n >> 1, m), t * t % m) % m : !!a; } ll inv(const ll x, const int p) { assert(x != 0); return pow(x, p - 2, p); } ll inv(const ll x) { return inv(x, MD); } vpll fact(const int n, const int p) { assert(n < p); vpll v(n + 1); v[0].first = 1; foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; } v[n].second = inv(v[n].first, p); roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; } return v; } class Combination { const vpll f; const int M; public: Combination(int n, int m) : f(fact(n, m)), M(m) {} Combination(int n) : Combination(n, MD) {} ll P(int n, int k) { return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M; } ll C(int n, int k) { return k < 0 ? 0 : P(n, k) * f[k].second % M; } ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); } ll F(int n) { return n < 0 ? 0 : f[n].first; } }; ll C2(const int n) { return (ll)n * ~-n / 2; } ll sum(const vi a) { ll s = 0; for (int e : a) { s += e; } return s; } ll sum(const vl a) { ll s = 0; for (ll e : a) { s += e; } return s; } template <typename T> int MSB(T N) { int r = -1; for (; N > 0; N /= 2) { ++r; } return r; } template <typename T> class SegmentTree { vector<T> S; T (*const op)(T a, T b); const T zero; const int B; public: SegmentTree(int N, T (*f)(T a, T b), const T zero) : S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero), B(1 << MSB(N - 1) + 1) {} SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero) : SegmentTree(v.size(), f, zero) { fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; } roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); } } T calc(int l, int r) { l += B; r += B; if (l > r) { return zero; } if (l == r) { return S[l]; } T L = S[l], R = S[r]; for (; l / 2 < r / 2; l /= 2, r /= 2) { if (l % 2 == 0) { L = op(L, S[l + 1]); } if (r % 2 == 1) { R = op(S[r - 1], R); } } return op(L, R); } void replace(int i, T x) { for (S[i += B] = x; i != 1; i /= 2) { if (i % 2) { S[i / 2] = op(S[i - 1], S[i]); } else { S[i / 2] = op(S[i], S[i + 1]); } } } void add(int i, T x) { replace(i, op(S[B + i], x)); } T top() { return S[1]; } T get(int i) { return S[i + B]; } }; ll BITsum(vl &B, int i) { ll z = 0; while (i > 0) { z += B[i]; i -= i & -i; } return z; } void BITadd(vl &B, int i, ll x) { while (i < B.size()) { B[i] += x; i += i & -i; } } ll fib(const ll n, const int m) { ll a, b, c, d, A, B, C, D; a = 1; b = 0; c = 0; d = 1; rf(i, 63) { A = a * a + b * c; B = a * b + b * d; C = c * a + d * c; D = c * b + d * d; if (n >> i & 1) { a = A; b = B; c = C; d = D; A = a + b; B = a; C = c + d; D = c; } a = A % m; b = B % m; c = C % m; d = D % m; } return b; } vi primes(int n) { vb b(n + 1); vi p; foor(i, 2, n) { if (!b[i]) { p << i; for (int j = 2 * i; j <= n; j += i) { b[j] = true; } } } return p; } vb isprime(const int n) { vb v(n + 1, true); v[0] = v[1] = false; foor(i, 2, n) { if (v[i]) { for (int j = 2 * i; j <= n; j += i) { v[j] = false; } } } return v; } class LCA { vvi par; vi dep; public: LCA(vvi &E, int root) : par(MSB(E.size()) + 1, vi(E.size())), dep(E.size()) { function<void(int, int)> dfs = [&](int i, int p) { for (int j : E[i]) if (j != p) { par[0][j] = i; dep[j] = dep[i] + 1; dfs(j, i); } }; par[0][root] = root; dfs(root, root); fr(i, par.size() - 1) { fr(j, par[0].size()) { par[i + 1][j] = par[i][par[i][j]]; } } } int operator()(int a, int b) { if (dep[a] > dep[b]) swap(a, b); for (int t = dep[b] - dep[a], i = 0; t; t >>= 1, ++i) { if (t & 1) { b = par[i][b]; } } if (a == b) return a; rf(i, par.size()) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } }; vpii factor(int N) { vpii r; for (int i = 2; i * i <= N; ++i) { if (N % i == 0) { r << pii{i, 0}; while (N % i == 0) { N /= i; ++r.back().second; } } } if (N > 1) { r << pii{N, 1}; } return r; } vl divisors(ll n) { vl r; ll m = sqrt(n); foor(i, 1, m) if (n % i == 0) r << ll(i); rf(i, r.size() - (m * m == n)) r << n / r[i]; return r; } vi SuffixArray(str S) { int N = S.size(); vi rank(N + 1), tmp(N + 1), sa(N + 1); fr(i, N) { sa[i] = i; rank[i] = S[i]; } sa[N] = N; rank[N] = -1; int k; auto cmp = [&](int &a, int &b) -> bool { if (rank[a] != rank[b]) return rank[a] < rank[b]; return (a + k <= N ? rank[a + k] : -1) < (b + k <= N ? rank[b + k] : -1); }; for (k = 1; k <= N; k *= 2) { sort(all(sa), cmp); tmp[sa[0]] = 0; foor(i, 1, N) { tmp[sa[i]] = tmp[sa[i - 1]] + cmp(sa[i - 1], sa[i]); } rank = tmp; } return sa; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vpii A(N); fr(i, N) { A[i].first = 29; for (cin >> A[i].second; A[i].second < 1 << 29; A[i].second *= 2) { --A[i].first; } } vi L(N + 1), R(N + 1); vpii B = A; R[N] = 0; R[N - 1] = 0; roof(i, N - 2, 0) { R[i] = R[i + 1]; int j = i; while (B[j] > B[j + 1] || ++j + 1 < N && B[j] > B[j + 1]) { B[j + 1].first += 2; R[i] += 2; } } L[0] = 0; L[1] = 1; foor(i, 2, N) { L[i] = L[i - 1] + 1; int j = i; while (A[j - 2] < A[j - 1] || --j - 2 >= 0 && A[j - 2] < A[j - 1]) { A[j - 2].first += 2; L[i] += 2; } } int z = e9; foor(i, 0, N) { chmin(z, L[i] + R[i]); } print(z); return 0; }
#include <bits/stdc++.h> #define fr(i, n) for (int i = 0; i < (n); ++i) #define foor(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, n) for (int i = (n); i--;) #define roof(i, b, a) for (int i = (b); i >= (a); --i) #define elsif else if #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define Reverse(x) reverse(all(x)) #define PQ priority_queue #define NP(x) next_permutation(all(x)) #define M_PI 3.14159265358979323846 #define popcount __builtin_popcount using namespace std; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef unsigned long long ull; typedef vector<ull> vu; typedef vector<vu> vvu; typedef double dbl; typedef vector<dbl> vd; typedef vector<vd> vvd; typedef string str; typedef vector<str> vs; typedef vector<vs> vvs; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef map<int, int> mii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef map<ll, ll> mll; typedef pair<dbl, dbl> pdd; typedef vector<pdd> vpdd; typedef map<dbl, dbl> mdd; typedef pair<str, str> pss; typedef vector<pss> vpss; typedef map<str, str> mss; typedef pair<int, ll> pil; typedef vector<pil> vpil; typedef map<int, ll> mil; typedef pair<ll, int> pli; typedef vector<pli> vpli; typedef map<ll, int> mli; typedef pair<dbl, int> pdi; typedef vector<pdi> vpdi; typedef map<dbl, int> mdi; template <typename T> vector<T> &operator<<(vector<T> &v, const T t) { v.push_back(t); return v; } template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) { m.insert(t); return m; } template <typename T> set<T> &operator<<(set<T> &s, const T t) { s.insert(t); return s; } template <typename T> stack<T> &operator<<(stack<T> &s, const T t) { s.push(t); return s; } template <typename T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } template <typename T> queue<T> &operator<<(queue<T> &q, const T t) { q.push(t); return q; } template <typename T> queue<T> &operator>>(queue<T> &q, T &t) { t = q.front(); q.pop(); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) { q.push(t); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) { t = q.top(); q.pop(); return q; } template <typename T, typename U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } istream &operator>>(istream &s, _Bit_reference b) { int a; s >> a; assert(a == 0 || a == 1); b = a; return s; } template <typename T> istream &operator>>(istream &s, vector<T> &v) { fr(i, v.size()) { s >> v[i]; } return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } // template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto // a:v){s<<a<<"\n";}return s;} template <typename T> ostream &operator<<(ostream &s, const vector<T> v) { fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; } return s; } template <typename T> ostream &operator<<(ostream &s, const deque<T> d) { fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; } return s; } template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) { return b = b & t; } template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) { return b = b ^ t; } template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) { return b = b | t; } template <typename T, typename U> pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename U> pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { return {a.first - b.first, a.second - b.second}; } template <typename T, typename U> pair<T, U> &operator+=(pair<T, U> &a, pair<T, U> b) { return a = a + b; } template <typename T, typename U> pair<T, U> &operator-=(pair<T, U> &a, pair<T, U> b) { return a = a - b; } void print(void) { cout << "\n"; } void Print(void) { cout << endl; } template <typename T> void print(T t) { cout << t << "\n"; } template <typename T> void Print(T t) { cout << t << endl; } template <typename T, typename... U> void print(T &&t, U &&...u) { cout << t << " "; print(forward<U>(u)...); } template <typename T, typename... U> void Print(T &&t, U &&...u) { cout << t << " "; Print(forward<U>(u)...); } bool YN(bool b) { print(b ? "YES" : "NO"); return b; } bool PI(bool b) { print(b ? "POSSIBLE" : "IMPOSSIBLE"); return b; } bool Yn(bool b) { print(b ? "Yes" : "No"); return b; } bool Pi(bool b) { print(b ? "Possible" : "Impossible"); return b; } bool yn(bool b) { print(b ? "yes" : "no"); return b; } bool pi(bool b) { print(b ? "possible" : "impossible"); return b; } const int e5 = 1e5; const int e9 = 1e9; const int MD = 1e9 + 7; const ll e18 = 1e18; template <typename T> str to_string(const T &n) { ostringstream s; s << n; return s.str(); } template <typename T> T &chmax(T &a, T b) { return a = max(a, b); } template <typename T> T &chmin(T &a, T b) { return a = min(a, b); } template <typename T, typename U> vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s, const T inf) { using P = pair<T, U>; vector<P> d; fr(i, E.size()) { d << P{inf, i}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } template <typename T, typename U> map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s, const T inf) { using P = pair<T, U>; map<U, P> d; for (pair<U, vector<P>> e : E) { d[e.first] = P{inf, e.first}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } ll maxflow(vector<mil> &E, int s, int t) { ll z = 0; vi b(E.size(), -1); for (int i = 0;; ++i) { static auto dfs = [&](int v, ll f, auto &dfs) -> ll { if (v == t) return f; b[v] = i; for (auto &p : E[v]) { if (b[p.first] < i && p.second) { if (ll r = dfs(p.first, min(f, p.second), dfs)) { p.second -= r; E[p.first][v] += r; return r; } } } return 0; }; ll x = dfs(s, ll(1e18), dfs); z += x; if (x == 0) return z; } } template <typename T> T distsq(pair<T, T> a, pair<T, T> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } template <typename T> T max(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = max(m, e); } return m; } template <typename T> T min(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = min(m, e); } return m; } template <typename T> T gcd(const T a, const T b) { return a ? gcd(b % a, a) : b; } template <typename T> T gcd(const vector<T> a) { T g = a[0]; for (T e : a) { g = gcd(g, e); } return g; } template <typename T> vector<T> LIS(const vector<T> A) { vector<T> B; for (T a : A) { auto it = lower_bound(all(B), a); if (it == B.end()) { B << a; } else { *it = a; } } return B; } template <typename T> vector<T> LCS(vector<T> A, vector<T> B) { int N = A.size(), M = B.size(); vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1)); fr(i, N) { fr(j, M) { if (A[i] == B[j]) { d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}}; } else { d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]); } } } vector<T> r; for (pii p = {N, M}; d[p.first][p.second].first; p = d[p.first][p.second].second) { r << A[d[p.first][p.second].second.first]; } Reverse(r); return r; } str LCS(str S, str T) { vector<char> s = LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end())); return str(s.begin(), s.end()); } template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) { if (V.size() <= 3) { return V; } Sort(V); rf(i, V.size() - 1) V << V[i]; vector<pair<T, T>> r; for (pair<T, T> p : V) { int s = r.size(); while (s >= 2 && (p.second - r[s - 1].second) * (p.first - r[s - 2].first) < (p.second - r[s - 2].second) * (p.first - r[s - 1].first)) { r.pop_back(); --s; } r << p; } r.pop_back(); return r; } class UnionFind { vi p, s; void extend(int N) { foor(i, p.size(), N) { p << i; s << 1; } } public: UnionFind(void) {} UnionFind(int N) { extend(N - 1); } int find(int i) { extend(i); return p[i] = p[i] == i ? i : find(p[i]); } void unite(int a, int b) { extend(a); extend(b); if ((a = find(a)) != (b = find(b))) { if (s[a] > s[b]) { swap(a, b); } s[b] += s[a]; p[a] = b; } } void unite(pii p) { return unite(p.first, p.second); } bool same(int a, int b) { extend(a); extend(b); return find(a) == find(b); } bool same(pii p) { return same(p.first, p.second); } int size(int x) { extend(x); return s[find(x)]; } }; ll MST(vector<pair<ll, pii>> &E) { Sort(E); UnionFind uf; ll z = 0; for (auto &e : E) { if (!uf.same(e.second)) { z += e.first; uf.unite(e.second); } } return z; } ll strmod(const str &s, const int m) { ll x = 0; fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; } return x; } vvl mul(const vvl &A, const vvl &B, const int m) { vvl C; fr(y, A.size()) { C << vl(B[y].size()); } fr(y, C.size()) { fr(x, C[y].size()) { fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; } } } return C; } vvl pow(const vvl &A, const ll n, const int m) { vvl B; fr(y, A.size()) { B << vl(A.size()); } if (n == 0) { fr(i, B.size()) { B[i][i] = 1; } } elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); } else { vvl C = pow(A, n / 2, m); B = mul(C, C, m); } return B; } ll pow(const ll a, const ll n, const int m) { ll t; return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) * (t = pow(a, n >> 1, m), t * t % m) % m : !!a; } ll inv(const ll x, const int p) { assert(x != 0); return pow(x, p - 2, p); } ll inv(const ll x) { return inv(x, MD); } vpll fact(const int n, const int p) { assert(n < p); vpll v(n + 1); v[0].first = 1; foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; } v[n].second = inv(v[n].first, p); roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; } return v; } class Combination { const vpll f; const int M; public: Combination(int n, int m) : f(fact(n, m)), M(m) {} Combination(int n) : Combination(n, MD) {} ll P(int n, int k) { return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M; } ll C(int n, int k) { return k < 0 ? 0 : P(n, k) * f[k].second % M; } ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); } ll F(int n) { return n < 0 ? 0 : f[n].first; } }; ll C2(const int n) { return (ll)n * ~-n / 2; } ll sum(const vi a) { ll s = 0; for (int e : a) { s += e; } return s; } ll sum(const vl a) { ll s = 0; for (ll e : a) { s += e; } return s; } template <typename T> int MSB(T N) { int r = -1; for (; N > 0; N /= 2) { ++r; } return r; } template <typename T> class SegmentTree { vector<T> S; T (*const op)(T a, T b); const T zero; const int B; public: SegmentTree(int N, T (*f)(T a, T b), const T zero) : S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero), B(1 << MSB(N - 1) + 1) {} SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero) : SegmentTree(v.size(), f, zero) { fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; } roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); } } T calc(int l, int r) { l += B; r += B; if (l > r) { return zero; } if (l == r) { return S[l]; } T L = S[l], R = S[r]; for (; l / 2 < r / 2; l /= 2, r /= 2) { if (l % 2 == 0) { L = op(L, S[l + 1]); } if (r % 2 == 1) { R = op(S[r - 1], R); } } return op(L, R); } void replace(int i, T x) { for (S[i += B] = x; i != 1; i /= 2) { if (i % 2) { S[i / 2] = op(S[i - 1], S[i]); } else { S[i / 2] = op(S[i], S[i + 1]); } } } void add(int i, T x) { replace(i, op(S[B + i], x)); } T top() { return S[1]; } T get(int i) { return S[i + B]; } }; ll BITsum(vl &B, int i) { ll z = 0; while (i > 0) { z += B[i]; i -= i & -i; } return z; } void BITadd(vl &B, int i, ll x) { while (i < B.size()) { B[i] += x; i += i & -i; } } ll fib(const ll n, const int m) { ll a, b, c, d, A, B, C, D; a = 1; b = 0; c = 0; d = 1; rf(i, 63) { A = a * a + b * c; B = a * b + b * d; C = c * a + d * c; D = c * b + d * d; if (n >> i & 1) { a = A; b = B; c = C; d = D; A = a + b; B = a; C = c + d; D = c; } a = A % m; b = B % m; c = C % m; d = D % m; } return b; } vi primes(int n) { vb b(n + 1); vi p; foor(i, 2, n) { if (!b[i]) { p << i; for (int j = 2 * i; j <= n; j += i) { b[j] = true; } } } return p; } vb isprime(const int n) { vb v(n + 1, true); v[0] = v[1] = false; foor(i, 2, n) { if (v[i]) { for (int j = 2 * i; j <= n; j += i) { v[j] = false; } } } return v; } class LCA { vvi par; vi dep; public: LCA(vvi &E, int root) : par(MSB(E.size()) + 1, vi(E.size())), dep(E.size()) { function<void(int, int)> dfs = [&](int i, int p) { for (int j : E[i]) if (j != p) { par[0][j] = i; dep[j] = dep[i] + 1; dfs(j, i); } }; par[0][root] = root; dfs(root, root); fr(i, par.size() - 1) { fr(j, par[0].size()) { par[i + 1][j] = par[i][par[i][j]]; } } } int operator()(int a, int b) { if (dep[a] > dep[b]) swap(a, b); for (int t = dep[b] - dep[a], i = 0; t; t >>= 1, ++i) { if (t & 1) { b = par[i][b]; } } if (a == b) return a; rf(i, par.size()) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } }; vpii factor(int N) { vpii r; for (int i = 2; i * i <= N; ++i) { if (N % i == 0) { r << pii{i, 0}; while (N % i == 0) { N /= i; ++r.back().second; } } } if (N > 1) { r << pii{N, 1}; } return r; } vl divisors(ll n) { vl r; ll m = sqrt(n); foor(i, 1, m) if (n % i == 0) r << ll(i); rf(i, r.size() - (m * m == n)) r << n / r[i]; return r; } vi SuffixArray(str S) { int N = S.size(); vi rank(N + 1), tmp(N + 1), sa(N + 1); fr(i, N) { sa[i] = i; rank[i] = S[i]; } sa[N] = N; rank[N] = -1; int k; auto cmp = [&](int &a, int &b) -> bool { if (rank[a] != rank[b]) return rank[a] < rank[b]; return (a + k <= N ? rank[a + k] : -1) < (b + k <= N ? rank[b + k] : -1); }; for (k = 1; k <= N; k *= 2) { sort(all(sa), cmp); tmp[sa[0]] = 0; foor(i, 1, N) { tmp[sa[i]] = tmp[sa[i - 1]] + cmp(sa[i - 1], sa[i]); } rank = tmp; } return sa; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vpii A(N); fr(i, N) { A[i].first = 29; for (cin >> A[i].second; A[i].second < 1 << 29; A[i].second *= 2) { --A[i].first; } } auto g = [&](pii a, pii b) -> ll { if (a <= b) { return 0; } else { int t = a.first - b.first; if (t % 2) { return (t + 1) / 2 * 2; } else { return (t / 2 + (a.second > b.second)) * 2; } } }; auto f = [&](vpii A) -> vl { vl d(N + 1); d[N] = 0; d[N - 1] = 0; stack<pii> s; s << pii{N - 1, N - 1}; roof(i, N - 2, 0) { d[i] = d[i + 1]; s << pii{i, i}; while (s.size() >= 2) { pii a, b; s >> a >> b; ll x = g(A[a.second], A[b.first]); if (x) { A[b.first].first += x; if (b.first != b.second) { A[b.second].first += x; } d[i] += x * (b.second - b.first + 1); s << pii{a.first, b.second}; } else { if (A[a.second] + pii{2, 0} <= A[b.first]) { s << b << a; } else { s << pii{a.first, b.second}; } break; } } } return d; }; vl R = f(A); Reverse(A); vl L = f(A); ll z = e18; foor(i, 0, N) { chmin(z, L[N - i] + R[i] + i); } print(z); return 0; }
replace
701
725
701
750
TLE
p03198
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef long double lb; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int dx[] = {0, 0, 1, -1}; constexpr int dy[] = {1, -1, 0, 0}; ll div_up(ll a, ll b) { return (a + b - 1) / b; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, a[212345], dp1[1123][16], dp2[1123][16]; cin >> n; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= 15; i++) { dp1[n - 1][i] = i; dp2[0][i] = i; } for (int i = n - 2; i >= 0; i--) { ll tmp = a[i]; for (int j = 0; j <= 15; j++) { if (tmp <= a[i + 1]) dp1[i][j] = j + dp1[i + 1][0]; else { int x = ceil(log(div_up(tmp, a[i + 1])) / log(4)); dp1[i][j] = j + dp1[i + 1][min(x, 15)]; if (x >= 15) { dp1[i][j] += (x - 15) * (n - i - 1); } } tmp *= 4; } } for (int i = 1; i < n; i++) { ll tmp = a[i]; for (int j = 0; j <= 15; j++) { if (tmp <= a[i - 1]) dp2[i][j] = j + dp2[i - 1][0]; else { int x = ceil(log(div_up(tmp, a[i - 1])) / log(4)); dp2[i][j] = j + dp2[i - 1][min(x, 15)]; if (x >= 15) { dp2[i][j] += (x - 15) * i; } } tmp *= 4; } } ll res = min(dp1[0][0] * 2, dp2[n - 1][0] * 2 + n); for (int i = 1; i < n; i++) { res = min(res, dp1[i][0] * 2 + dp2[i - 1][0] * 2 + i); } cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef long double lb; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int dx[] = {0, 0, 1, -1}; constexpr int dy[] = {1, -1, 0, 0}; ll div_up(ll a, ll b) { return (a + b - 1) / b; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, a[212345], dp1[212345][16], dp2[212345][16]; cin >> n; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= 15; i++) { dp1[n - 1][i] = i; dp2[0][i] = i; } for (int i = n - 2; i >= 0; i--) { ll tmp = a[i]; for (int j = 0; j <= 15; j++) { if (tmp <= a[i + 1]) dp1[i][j] = j + dp1[i + 1][0]; else { int x = ceil(log(div_up(tmp, a[i + 1])) / log(4)); dp1[i][j] = j + dp1[i + 1][min(x, 15)]; if (x >= 15) { dp1[i][j] += (x - 15) * (n - i - 1); } } tmp *= 4; } } for (int i = 1; i < n; i++) { ll tmp = a[i]; for (int j = 0; j <= 15; j++) { if (tmp <= a[i - 1]) dp2[i][j] = j + dp2[i - 1][0]; else { int x = ceil(log(div_up(tmp, a[i - 1])) / log(4)); dp2[i][j] = j + dp2[i - 1][min(x, 15)]; if (x >= 15) { dp2[i][j] += (x - 15) * i; } } tmp *= 4; } } ll res = min(dp1[0][0] * 2, dp2[n - 1][0] * 2 + n); for (int i = 1; i < n; i++) { res = min(res, dp1[i][0] * 2 + dp2[i - 1][0] * 2 + i); } cout << res << endl; return 0; }
replace
40
41
40
41
0
p03198
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; ll cnt[2][101010]; int main() { int n; cin >> n; ll a[n + 1]; rep(i, n) cin >> a[i]; rep(j, 2) { vector<pint> st; st.push_back({inf, 0}); rep(i, n - 1) { int ret = 0; ll res = a[i]; while (a[i + 1] > res) { res *= 4; ++ret; } cnt[j][i + 2] = cnt[j][i + 1]; while (ret) { cnt[j][i + 2] += 2 * (i + 1 - st.back().second); if (--st.back().first == 0) { st.pop_back(); } --ret; } res = a[i + 1]; while (4 * res < a[i]) { res *= 4; ++ret; } if (ret) st.push_back({ret, i + 1}); } reverse(a, a + n); } ll ans = longinf; rep(i, n + 1) { ans = min(ans, cnt[0][i] + cnt[1][n - i] + i); } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; ll cnt[2][202020]; int main() { int n; cin >> n; ll a[n + 1]; rep(i, n) cin >> a[i]; rep(j, 2) { vector<pint> st; st.push_back({inf, 0}); rep(i, n - 1) { int ret = 0; ll res = a[i]; while (a[i + 1] > res) { res *= 4; ++ret; } cnt[j][i + 2] = cnt[j][i + 1]; while (ret) { cnt[j][i + 2] += 2 * (i + 1 - st.back().second); if (--st.back().first == 0) { st.pop_back(); } --ret; } res = a[i + 1]; while (4 * res < a[i]) { res *= 4; ++ret; } if (ret) st.push_back({ret, i + 1}); } reverse(a, a + n); } ll ans = longinf; rep(i, n + 1) { ans = min(ans, cnt[0][i] + cnt[1][n - i] + i); } cout << ans << endl; return 0; }
replace
24
25
24
25
0
p03199
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <ccomplex> #include <clocale> #include <cmath> #include <complex> #include <ctype.h> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <locale> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <unordered_map> #include <utility> #include <valarray> #include <vector> #include <wchar.h> using namespace std; typedef long long int LL; typedef long long int ll; typedef pair<long long int, long long int> pii; typedef pair<double, double> pdd; #define SORT(c) sort((c).begin(), (c).end()) #define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>()) #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) LL mod = 998244353; bool find(map<pair<LL, LL>, bool> &dic, LL a, LL b) { auto iter = dic.find(make_pair(a, b)); return iter != end(dic); } bool is1(map<pair<LL, LL>, bool> &dic, LL a, LL b) { auto iter = dic.find(make_pair(a, b)); return iter->second; } int main() { cin.tie(0); ios::sync_with_stdio(false); LL N, M; cin >> N >> M; map<pair<LL, LL>, bool> dic; REP(i, M) { LL a, b, c; cin >> a >> b >> c; dic.insert(make_pair(make_pair(a, b), c == 1)); } LL now1 = 1; LL now0 = 1; if (find(dic, 1, 1)) { if (is1(dic, 1, 1)) { now0 = 0; } else { now1 = 0; } } REP(i, N - 1) { // i+2,i+2 ->i+3,i+1 bool flag1 = true; bool flag0 = true; LL next1 = 0; LL next0 = 0; if (find(dic, i + 3, i + 1) && find(dic, i + 1, i + 3)) { if ((is1(dic, i + 3, i + 1) && is1(dic, i + 1, i + 3)) || ((!is1(dic, i + 3, i + 1)) && (!is1(dic, i + 1, i + 3)))) { // kanarazu 0 flag1 = false; } else { flag0 = false; } } LL notuse = 0; LL cnt = 0; if (find(dic, i + 2, i + 1)) { if (is1(dic, i + 2, i + 1)) { cnt++; } } else { notuse++; } if (find(dic, i + 1, i + 2)) { if (is1(dic, i + 1, i + 2)) { cnt++; } } else { notuse++; } if (flag0) { if (notuse == 0) { if (cnt % 2 == 0) { next0 += now0; } else { next0 += now1; } } else { next0 += (now0 + now1) * notuse; } } if (flag1) { if (notuse == 0) { if (cnt % 2 == 0) { next1 += now1; } else { next1 += now0; } } else { next1 += (now0 + now1) * notuse; } } if (i != N - 2) { if ((!find(dic, i + 3, i + 1)) && (!find(dic, i + 1, i + 3))) { next1 *= 2; next0 *= 2; } } if (find(dic, i + 2, i + 2)) { if (is1(dic, i + 2, i + 2)) { next0 = 0; } else { next1 = 0; } } next1 %= mod; next0 %= mod; now1 = next1; now0 = next0; } LL sum = (now1 + now0) % mod; LL c = 0; for (auto i = dic.begin(); i != dic.end(); ++i) { auto key = i->first; if (abs(key.first - key.second) >= 3) { if (find(dic, key.second, key.first)) { if (is1(dic, key.first, key.second) != is1(dic, key.second, key.first)) { sum = 0; } if (key.first > key.second) { c++; } } else { c++; } } } LL a = -c; REP(i, N - 3) { a += i + 1; } while (a > 0) { if (a > 30) { a -= 30; sum *= 75497471; sum %= mod; } else { a--; sum *= 2; sum %= mod; } } cout << sum << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <ccomplex> #include <clocale> #include <cmath> #include <complex> #include <ctype.h> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <locale> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <unordered_map> #include <utility> #include <valarray> #include <vector> #include <wchar.h> using namespace std; typedef long long int LL; typedef long long int ll; typedef pair<long long int, long long int> pii; typedef pair<double, double> pdd; #define SORT(c) sort((c).begin(), (c).end()) #define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>()) #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) LL mod = 998244353; bool find(map<pair<LL, LL>, bool> &dic, LL a, LL b) { auto iter = dic.find(make_pair(a, b)); return iter != end(dic); } bool is1(map<pair<LL, LL>, bool> &dic, LL a, LL b) { auto iter = dic.find(make_pair(a, b)); return iter->second; } int main() { cin.tie(0); ios::sync_with_stdio(false); LL N, M; cin >> N >> M; map<pair<LL, LL>, bool> dic; REP(i, M) { LL a, b, c; cin >> a >> b >> c; dic.insert(make_pair(make_pair(a, b), c == 1)); } LL now1 = 1; LL now0 = 1; if (find(dic, 1, 1)) { if (is1(dic, 1, 1)) { now0 = 0; } else { now1 = 0; } } REP(i, N - 1) { // i+2,i+2 ->i+3,i+1 bool flag1 = true; bool flag0 = true; LL next1 = 0; LL next0 = 0; if (find(dic, i + 3, i + 1) && find(dic, i + 1, i + 3)) { if ((is1(dic, i + 3, i + 1) && is1(dic, i + 1, i + 3)) || ((!is1(dic, i + 3, i + 1)) && (!is1(dic, i + 1, i + 3)))) { // kanarazu 0 flag1 = false; } else { flag0 = false; } } LL notuse = 0; LL cnt = 0; if (find(dic, i + 2, i + 1)) { if (is1(dic, i + 2, i + 1)) { cnt++; } } else { notuse++; } if (find(dic, i + 1, i + 2)) { if (is1(dic, i + 1, i + 2)) { cnt++; } } else { notuse++; } if (flag0) { if (notuse == 0) { if (cnt % 2 == 0) { next0 += now0; } else { next0 += now1; } } else { next0 += (now0 + now1) * notuse; } } if (flag1) { if (notuse == 0) { if (cnt % 2 == 0) { next1 += now1; } else { next1 += now0; } } else { next1 += (now0 + now1) * notuse; } } if (i != N - 2) { if ((!find(dic, i + 3, i + 1)) && (!find(dic, i + 1, i + 3))) { next1 *= 2; next0 *= 2; } } if (find(dic, i + 2, i + 2)) { if (is1(dic, i + 2, i + 2)) { next0 = 0; } else { next1 = 0; } } next1 %= mod; next0 %= mod; now1 = next1; now0 = next0; } LL sum = (now1 + now0) % mod; LL c = 0; for (auto i = dic.begin(); i != dic.end(); ++i) { auto key = i->first; if (abs(key.first - key.second) >= 3) { if (find(dic, key.second, key.first)) { if (is1(dic, key.first, key.second) != is1(dic, key.second, key.first)) { sum = 0; } if (key.first > key.second) { c++; } } else { c++; } } } LL a = -c; REP(i, N - 3) { a += i + 1; } while (a > 0) { if (a > 1000) { a -= 1000; sum *= 23226277; sum %= mod; } else { a--; sum *= 2; sum %= mod; } } cout << sum << endl; }
replace
178
181
178
181
TLE
p03199
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; const int MOD = 998244353; long long power(long long a, long long b) { long long ret = 1; long long tmp = a; while (b > 0) { if (b & 1) { ret *= tmp; ret %= MOD; } tmp *= tmp; tmp %= MOD; b >>= 1; } return ret; } long long solve(int n, const map<pair<int, int>, int> &cell) { long long cnt = n * (long long)n - (5 * n - 6); for (const auto &p : cell) { pair<int, int> tmp; int a, b, c; tie(tmp, c) = p; tie(a, b) = tmp; if (abs(a - b) > 2) { auto it = cell.find(make_pair(b, a)); if (it == cell.end()) cnt -= 2; else if (c != it->second) return 0; else --cnt; } } cnt /= 2; vector<long long> dp(2, 0); dp[0] = power(2, cnt); for (int i = 0; i < n; ++i) { vector<long long> nextDp(2, 0); for (int a = 0; a < 2; ++a) { for (int b = 0; b < 2; ++b) { auto it = cell.find(make_pair(i, i)); if (it != cell.end() && b != it->second) continue; long long tmp = 1; if (i > 0) { auto it1 = cell.find(make_pair(i - 1, i)); auto it2 = cell.find(make_pair(i, i - 1)); if (it1 == cell.end() && it2 == cell.end()) tmp *= 2; else if (it1 != cell.end() && it2 != cell.end() && (it1->second + it2->second + a + b) % 2 != 0) continue; } if (i > 0 && i < n - 1) { auto it1 = cell.find(make_pair(i - 1, i + 1)); auto it2 = cell.find(make_pair(i + 1, i - 1)); if (it1 == cell.end() && it2 == cell.end()) tmp *= 2; else if (it1 != cell.end() && it2 != cell.end() && (it1->second + it2->second + b) % 2 != 0) continue; } nextDp[b] += dp[a] * tmp; nextDp[b] %= MOD; } } dp = move(nextDp); } return (dp[0] + dp[1]) % MOD; } int main() { for (;;) { int n = 4; int m = rand() % (n * n + 1); map<pair<int, int>, int> cell1, cell2; while (cell1.size() != m) { int a = rand() % n; int b = rand() % n; if (cell1.find(make_pair(a, b)) != cell1.end()) continue; int c = rand() % 2; cell1[make_pair(a, b)] = c; cell2[make_pair(b, a)] = c; } if (solve(n, cell1) != solve(n, cell2)) return 0; } int n, m; cin >> n >> m; map<pair<int, int>, int> cell; for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a; --b; cell[make_pair(a, b)] = c; } cout << solve(n, cell) << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; const int MOD = 998244353; long long power(long long a, long long b) { long long ret = 1; long long tmp = a; while (b > 0) { if (b & 1) { ret *= tmp; ret %= MOD; } tmp *= tmp; tmp %= MOD; b >>= 1; } return ret; } long long solve(int n, const map<pair<int, int>, int> &cell) { long long cnt = n * (long long)n - (5 * n - 6); for (const auto &p : cell) { pair<int, int> tmp; int a, b, c; tie(tmp, c) = p; tie(a, b) = tmp; if (abs(a - b) > 2) { auto it = cell.find(make_pair(b, a)); if (it == cell.end()) cnt -= 2; else if (c != it->second) return 0; else --cnt; } } cnt /= 2; vector<long long> dp(2, 0); dp[0] = power(2, cnt); for (int i = 0; i < n; ++i) { vector<long long> nextDp(2, 0); for (int a = 0; a < 2; ++a) { for (int b = 0; b < 2; ++b) { auto it = cell.find(make_pair(i, i)); if (it != cell.end() && b != it->second) continue; long long tmp = 1; if (i > 0) { auto it1 = cell.find(make_pair(i - 1, i)); auto it2 = cell.find(make_pair(i, i - 1)); if (it1 == cell.end() && it2 == cell.end()) tmp *= 2; else if (it1 != cell.end() && it2 != cell.end() && (it1->second + it2->second + a + b) % 2 != 0) continue; } if (i > 0 && i < n - 1) { auto it1 = cell.find(make_pair(i - 1, i + 1)); auto it2 = cell.find(make_pair(i + 1, i - 1)); if (it1 == cell.end() && it2 == cell.end()) tmp *= 2; else if (it1 != cell.end() && it2 != cell.end() && (it1->second + it2->second + b) % 2 != 0) continue; } nextDp[b] += dp[a] * tmp; nextDp[b] %= MOD; } } dp = move(nextDp); } return (dp[0] + dp[1]) % MOD; } int main() { int n, m; cin >> n >> m; map<pair<int, int>, int> cell; for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a; --b; cell[make_pair(a, b)] = c; } cout << solve(n, cell) << endl; return 0; }
delete
105
124
105
105
TLE
p03200
C++
Time Limit Exceeded
// #include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, x, y) for (int i = x; i < y; i++) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) a / __gcd(a, b) * b #define range(a) (a).begin(), (a).end() const int inf = 2147483647; int main() { string s; cin >> s; ll ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B' && s[i + 1] == 'W') { swap(s[i], s[i + 1]); i = -1; ans++; } } cout << ans << endl; return 0; }
// #include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, x, y) for (int i = x; i < y; i++) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) a / __gcd(a, b) * b #define range(a) (a).begin(), (a).end() const int inf = 2147483647; int main() { string s; cin >> s; ll ans = 0; /* for(int i = 0;i<s.size();i++){ if(s[i]=='B'&&s[i+1]=='W'){ swap(s[i],s[i+1]); i=-1; ans++; } } */ int o = 0; rep(i, 0, s.size()) { if (s.at(i) == 'W') { ans += i - o; o++; } } cout << ans << endl; return 0; }
replace
15
20
15
28
TLE
p03200
C++
Runtime Error
#include <algorithm> #include <complex> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define pn(s) cout << (#s) << " " << (s) << endl const ll mod = 1e9 + 7; const ll inf = 1e18; void pV(vector<ll> A) { cout << "[vector]"; for (int i = 0; i < A.size(); i++) { cout << A[i] << " "; } cout << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); // input string S; cin >> S; // 後端のBを切り取る(終端はWとする) int L = S.size(); for (int i = S.size() - 1; i >= 0; i--) { if (S[i] == 'B') { L--; } else { break; } } if (L == -1) { // Bしかないやん p(0); return 0; } int whiteIndex = L - 1; int blackIndex = L - 1; ll answer = 0; // search white while (true) { while (S[whiteIndex] != 'W') { whiteIndex--; if (whiteIndex == -1) { p(answer); return 0; } } while (S[blackIndex] != 'B') { blackIndex--; if (blackIndex == -1) { p(answer); return 0; } } swap(S[whiteIndex], S[blackIndex]); answer += (whiteIndex - blackIndex); } return 0; }
#include <algorithm> #include <complex> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define pn(s) cout << (#s) << " " << (s) << endl const ll mod = 1e9 + 7; const ll inf = 1e18; void pV(vector<ll> A) { cout << "[vector]"; for (int i = 0; i < A.size(); i++) { cout << A[i] << " "; } cout << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); // input string S; cin >> S; // 後端のBを切り取る(終端はWとする) int L = S.size(); for (int i = S.size() - 1; i >= 0; i--) { if (S[i] == 'B') { L--; } else { break; } } if (L <= 0) { // Bしかないやん p(0); return 0; } int whiteIndex = L - 1; int blackIndex = L - 1; ll answer = 0; // search white while (true) { while (S[whiteIndex] != 'W') { whiteIndex--; if (whiteIndex == -1) { p(answer); return 0; } } while (S[blackIndex] != 'B') { blackIndex--; if (blackIndex == -1) { p(answer); return 0; } } swap(S[whiteIndex], S[blackIndex]); answer += (whiteIndex - blackIndex); } return 0; }
replace
54
55
54
55
0
p03200
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { string S; cin >> S; // string S = "BWBWBW"; int ret = 0; bool isMoreFound = true; while (isMoreFound) { string newS = S; bool isAtLeastFound = false; for (int idx = 0; idx < S.size() - 1; idx++) { if (S[idx] == 'B' && S[idx + 1] == 'W') { newS[idx] = 'W'; // flip newS[idx + 1] = 'B'; // flip ret++; idx++; // skip idx + 1 isAtLeastFound = true; } } isMoreFound = isAtLeastFound; S = newS; } cout << ret; return 0; }
#include <iostream> using namespace std; int main() { string S; cin >> S; // string S = "BWBWBW"; long long ret = 0; long long leftB = 0; for (int idx = 0; idx < S.size(); idx++) { if (S[idx] == 'B') leftB++; else if (S[idx] == 'W') ret += leftB; } cout << ret; return 0; }
replace
7
23
7
14
TLE
p03200
C++
Runtime Error
#include <bits/stdc++.h> #define inc(l, i, r) for (int i = l; i <= r; i++) #define dec(r, i, l) for (int i = r; i >= l; i--) #define mid ((l + r) >> 1) #define mp make_pair #define pb push_back #define fi first #define se second #define pii pair<int, int> #define ___ putchar(10); #define N 100100 using namespace std; typedef long long ll; ll ans; int n, tmp; char s[N]; int main() { scanf("%s", s + 1); n = strlen(s + 1); inc(1, i, n) { if (s[i] == 'B') ++tmp; else ans += tmp; } printf("%lld\n", ans); }
#include <bits/stdc++.h> #define inc(l, i, r) for (int i = l; i <= r; i++) #define dec(r, i, l) for (int i = r; i >= l; i--) #define mid ((l + r) >> 1) #define mp make_pair #define pb push_back #define fi first #define se second #define pii pair<int, int> #define ___ putchar(10); #define N 200200 using namespace std; typedef long long ll; ll ans; int n, tmp; char s[N]; int main() { scanf("%s", s + 1); n = strlen(s + 1); inc(1, i, n) { if (s[i] == 'B') ++tmp; else ans += tmp; } printf("%lld\n", ans); }
replace
10
11
10
11
0
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int count = 0; bool flag = true; while (flag) { flag = false; for (int i = 0; i < S.length() - 1; i++) { if (S[i] == 'B' && S[i + 1] == 'W') { S[i] = 'W'; S[i + 1] = 'B'; flag = true; count++; break; } } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; long long count = 0; int left = 0; for (int i = 0; i < S.length(); i++) { if (S[i] == 'W') { count += i - left; left++; } } cout << count << endl; return 0; }
replace
8
20
8
14
TLE
p03200
C++
Runtime Error
#include <cstdio> // #include <cstdlib> #include <cstring> // #include <map> // #include <set> // #include <queue> // #include <string> // #include <vector> // #include <iostream> #include <algorithm> using namespace std; typedef long long LL; typedef unsigned long long ULL; const int MAXN = 100005; const int P = 1000000007; const int INF = 1000000007; const double eps = 1e-6; inline int getint() { int r = 0; bool b = true; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') b = false; c = getchar(); } while (c >= '0' && c <= '9') { r = (r << 1) + (r << 3) + c - '0'; c = getchar(); } return b ? r : -r; } char str[MAXN]; int n, cnt; LL ans; int main() { scanf("%s", str + 1); n = strlen(str + 1); for (int i = n; i >= 1; --i) { if (str[i] == 'B') ans += cnt; else ++cnt; } printf("%lld", ans); }
#include <cstdio> // #include <cstdlib> #include <cstring> // #include <map> // #include <set> // #include <queue> // #include <string> // #include <vector> // #include <iostream> #include <algorithm> using namespace std; typedef long long LL; typedef unsigned long long ULL; const int MAXN = 200005; const int P = 1000000007; const int INF = 1000000007; const double eps = 1e-6; inline int getint() { int r = 0; bool b = true; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') b = false; c = getchar(); } while (c >= '0' && c <= '9') { r = (r << 1) + (r << 3) + c - '0'; c = getchar(); } return b ? r : -r; } char str[MAXN]; int n, cnt; LL ans; int main() { scanf("%s", str + 1); n = strlen(str + 1); for (int i = n; i >= 1; --i) { if (str[i] == 'B') ans += cnt; else ++cnt; } printf("%lld", ans); }
replace
17
18
17
18
0
p03200
C++
Time Limit Exceeded
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // main code int main(int argc, char const *argv[]) { string s; cin >> s; int ans = 0; for (int i = s.size() - 2; i >= 0; i--) { if (i == s.size() - 1) continue; if (s[i] == 'B' and s[i + 1] == 'W') { s[i] = 'W'; s[i + 1] = 'B'; ans++; i += 2; } } cout << ans << endl; return 0; }
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // main code int main(int argc, char const *argv[]) { string s; cin >> s; LL ans = 0; LL count = 0; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'W') { count++; } else { ans += count; } } cout << ans << endl; return 0; }
replace
42
51
42
49
TLE
p03200
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <numeric> // accumulate(v.begin(), v.end(), 0) #include <vector> using namespace std; #define ll long long int main() { string S; cin >> S; int N = (int)S.size(); int ans = 0; for (int i = 0; i < N - 1; i++) { if (S[i] == 'B' && S[i + 1] == 'W') { S[i] = 'W'; S[i + 1] = 'B'; ans++; i -= 2; } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <numeric> // accumulate(v.begin(), v.end(), 0) #include <vector> using namespace std; #define ll long long int main() { string S; cin >> S; int N = (int)S.size(); ll ans = 0; int end = N - 1; for (int i = N - 1; i >= 0; i--) { if (S[i] == 'B') { ans += end - i; end--; } } cout << ans << endl; return 0; }
replace
14
21
14
20
TLE
p03200
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; typedef long long ll; #define rep(i, a, b) for (int i = a; i < b; i++) int main() { ll c = 0, ans = 0; char *str = new char[20005]; scanf("%s", str); int len = strlen(str); rep(i, 0, len) { if (str[i] == 'B') c++; else ans += c; } printf("%lld", ans); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <functional> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector> using namespace std; typedef long long ll; #define rep(i, a, b) for (int i = a; i < b; i++) int main() { ll c = 0, ans = 0; char *str = new char[200005]; scanf("%s", str); int len = strlen(str); rep(i, 0, len) { if (str[i] == 'B') c++; else ans += c; } printf("%lld", ans); return 0; }
replace
12
13
12
13
0
p03200
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 100010 char s[N]; int main() { scanf("%s", s); int n = strlen(s); long long ans = 0, c = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'B') ++c; else ans += c; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define N 200010 char s[N]; int main() { scanf("%s", s); int n = strlen(s); long long ans = 0, c = 0; for (int i = 0; i < n; ++i) { if (s[i] == 'B') ++c; else ans += c; } cout << ans << endl; return 0; }
replace
3
4
3
4
0
p03200
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { string str; long long wn = 0; long long ans = 0; cin >> str; for (int i = str.length() - 1; i >= 0; i++) { if (str[i] == 'W') wn++; else ans += wn; } cout << ans << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { string str; long long wn = 0; long long ans = 0; cin >> str; for (int i = str.length() - 1; i >= 0; i--) { if (str[i] == 'W') wn++; else ans += wn; } cout << ans << endl; return 0; }
replace
20
21
20
21
-11
p03200
C++
Runtime Error
#include <iostream> using namespace std; int main() { string s; cin >> s; int r = 0; for (int i = s.size() - 1; i >= 0; i++) { if (s[i] == 'W') { r = i; break; } } int ans = 0; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == 'B') { ans += r - i; r--; } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { string s; cin >> s; long long cnt = 0, ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B') cnt++; else ans += cnt; } cout << ans << endl; }
replace
6
19
6
12
0
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long #define ld long double // 217 // 44 using namespace std; string str; int main() { // ifstream cin("A.in"); // ofstream cout("A.out"); // int ; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> str; int n = str.size(); int ans = 0; int pos = 0; while (pos < n - 1) { if (str[pos] == 'B' && str[pos + 1] == 'W') { str[pos] = 'W', str[pos + 1] = 'B'; ans++; } if (pos > 0 && str[pos - 1] == 'B' && str[pos] == 'W') { pos--; } else { pos++; } } cout << ans; // cin.close(); // cout.close(); return 0; }
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long #define ld long double // 217 // 44 using namespace std; string str; int main() { // ifstream cin("A.in"); // ofstream cout("A.out"); // int ; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> str; ll ans = 0, cnt = 0; for (auto it : str) { cnt += (it == 'B'); ans += cnt * (it == 'W'); } cout << ans; // cin.close(); // cout.close(); return 0; }
replace
19
32
19
23
TLE
p03200
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <utility> #include <vector> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < (int)(n); i++) int main() { char s[200005] = {}; long int ans = 0; scanf("%s\n", s); for (int i = strlen(s) - 2; i >= 0; i--) { int j = i; while (s[j] == 'B' && s[j + 1] == 'W') { s[j] = 'W'; s[j + 1] = 'B'; j++; ans++; } } printf("%ld\n", ans); return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <string.h> #include <utility> #include <vector> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < (int)(n); i++) int main() { char s[200005] = {}; long int ans = 0; scanf("%s\n", s); int j = strlen(s) - 1; for (int i = strlen(s) - 1; i >= 0; i--) { if (s[i] == 'B') { ans += j - i; j--; } } printf("%ld\n", ans); return 0; }
replace
18
25
18
23
TLE
p03200
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; const int mod = 1000000007; const int INF = 1 << 28; const double EPS = 1e-10; // cout << fixed << std::setprecision(9) // memset(a, 0, sizeof(a)); //-------------------------- string s; int B[20005]; int main() { cin >> s; if (s[0] == 'B') B[0] = 1; for (int i = 1; i < s.size(); i++) { B[i] = B[i - 1]; if (s[i] == 'B') B[i]++; } ll ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'W') { ans += B[i]; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; const int mod = 1000000007; const int INF = 1 << 28; const double EPS = 1e-10; // cout << fixed << std::setprecision(9) // memset(a, 0, sizeof(a)); //-------------------------- string s; int B[200005]; int main() { cin >> s; if (s[0] == 'B') B[0] = 1; for (int i = 1; i < s.size(); i++) { B[i] = B[i - 1]; if (s[i] == 'B') B[i]++; } ll ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'W') { ans += B[i]; } } cout << ans << endl; return 0; }
replace
25
26
25
26
0
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef long double ld; #define pb push_back #define all(c) c.begin(), c.end() #define allr(c) c.rbegin(), c.rend() #define mod 1000000007 #define PI 3.14159265 #define endl '\n' #define MAX int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; int n = str.size(); int ans = 0; string temp = str; sort(allr(temp)); while (str != temp) { for (int i = n - 2; i >= 0; i--) { if (str[i] == 'B' && str[i + 1] == 'W') { ans++; swap(str[i], str[i + 1]); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef long double ld; #define pb push_back #define all(c) c.begin(), c.end() #define allr(c) c.rbegin(), c.rend() #define mod 1000000007 #define PI 3.14159265 #define endl '\n' #define MAX int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; ll ans = 0, c = 0; for (auto it : str) { if (it == 'W') { ans += c; } else { c++; } } cout << ans << endl; return 0; }
replace
24
34
24
30
TLE
p03200
C++
Time Limit Exceeded
#ifndef LOCAL #pragma GCC optimize("O3") #include <bits/stdc++.h> #else #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #endif using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, // rb_tree_tag,tree_order_statistics_node_update> template <typename T> void setmax(T &x, T y) { x = max(x, y); } template <typename T> void setmin(T &x, T y) { x = min(x, y); } #define fix(a) fixed << setprecision(a) #define forn(i, n) for (int i = 0; i < int(n); i++) #define rep(i, a, b) for (int i = int(a); i < int(b); i++) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() #define len(V) (int)V.size() #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define endl '\n' void solve() { string s; cin >> s; int n = len(s); int ans = 0; forn(i, n) forn(j, n - 1) { if (s[j] < s[j + 1]) ans++, swap(s[j], s[j + 1]); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); int t = 1; // cin >> t; forn(i, t) { solve(); } } /* 6 1 1 7 1 2 2 6 2 1 3 7 3 0 < 2 > 1 > 0 */
#ifndef LOCAL #pragma GCC optimize("O3") #include <bits/stdc++.h> #else #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #endif using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, // rb_tree_tag,tree_order_statistics_node_update> template <typename T> void setmax(T &x, T y) { x = max(x, y); } template <typename T> void setmin(T &x, T y) { x = min(x, y); } #define fix(a) fixed << setprecision(a) #define forn(i, n) for (int i = 0; i < int(n); i++) #define rep(i, a, b) for (int i = int(a); i < int(b); i++) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() #define len(V) (int)V.size() #define ll long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define endl '\n' void solve() { string s; cin >> s; int n = len(s); ll ans = 0; int l = 0; forn(i, n) { if (s[i] == 'W') { ans += (ll)(i - l); l++; } } cout << ans << endl; } int main() { ios::sync_with_stdio(false); int t = 1; // cin >> t; forn(i, t) { solve(); } } /* 6 1 1 7 1 2 2 6 2 1 3 7 3 0 < 2 > 1 > 0 */
replace
87
91
87
94
TLE
p03200
C++
Runtime Error
#include <cmath> #include <cstdlib> #include <iostream> #include <string> using namespace std; #define ll long long #define int ll int ans; string S; int a[30000]; int len; int Count; signed main() { cin >> S; len = S.size(); for (int i = 0; i < len; i++) { if (S[i] == 'B') { a[i + 1] = 1; } } for (int i = len; i != 0; i--) { if (a[i] == 1) { ans += Count; } else { Count++; } } cout << ans << endl; // system("pause"); return 0; }
#include <cmath> #include <cstdlib> #include <iostream> #include <string> using namespace std; #define ll long long #define int ll int ans; string S; int a[300000]; int len; int Count; signed main() { cin >> S; len = S.size(); for (int i = 0; i < len; i++) { if (S[i] == 'B') { a[i + 1] = 1; } } for (int i = len; i != 0; i--) { if (a[i] == 1) { ans += Count; } else { Count++; } } cout << ans << endl; // system("pause"); return 0; }
replace
12
13
12
13
0
p03200
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; long long f = 0; int d = 0; long long sum = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 'B' && s[i + 1] == 'W') { sum++; s[i] = 'W'; s[i + 1] = 'B'; if (i > 0) i -= 2; } } cout << sum << endl; return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; long long f = 0; int d = 0; long long sum = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 'W') { sum += f; } else { f++; } } cout << sum << endl; return 0; }
replace
12
18
12
16
TLE
p03200
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n, m) for (int i = (n); i < (m); i++) #define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--) using namespace std; using ll = long long; int main() { string s; cin >> s; vector<int> cum_cnt(s.size(), 0); rep(i, 0, s.size() + 1) cum_cnt[i + 1] = cum_cnt[i] + int(s[i] == 'B'); int ans = 0; rep(i, 0, s.size()) if (s[i] == 'W') ans += cum_cnt[i]; cout << ans << endl; 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--) using namespace std; using ll = long long; int main() { string s; cin >> s; int cnt = 0; ll ans = 0; for (auto c : s) if (c == 'B') ++cnt; else ans += cnt; cout << ans << endl; return 0; }
replace
10
16
10
17
0
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const long long INF = 1e18; #define len(x) ((int)(x).size()) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define foreps(i, m, n) for (int i = m; i < n; i++) #define ALL(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() 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; } int main() { string S; cin >> S; ll ans = 0; for (int i = 0; i < len(S) - 1;) { if (S[i] == 'B' && S[i + 1] == 'W') { swap(S[i], S[i + 1]); ++ans, i = 0; } else i++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const long long INF = 1e18; #define len(x) ((int)(x).size()) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define foreps(i, m, n) for (int i = m; i < n; i++) #define ALL(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() 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; } int main() { string S; cin >> S; ll ans = 0, num = 0; rep(i, len(S)) { if (S[i] == 'W') ans += num; else ++num; } cout << ans << endl; }
replace
31
39
31
37
TLE
p03200
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #define LL long long using namespace std; char s[100010]; int n, num = 0; LL ans = 0; int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = n; i >= 1; i--) { if (s[i] == 'B') { ans += (n - i - num); num++; } } printf("%lld", ans); }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #define LL long long using namespace std; char s[200010]; int n, num = 0; LL ans = 0; int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = n; i >= 1; i--) { if (s[i] == 'B') { ans += (n - i - num); num++; } } printf("%lld", ans); }
replace
6
7
6
7
0
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for (int i = x; i < n; i++) int main() { string s; cin >> s; int ans = 0; int i = 0; while (1) { if (s[i] == 'B' && s[i + 1] == 'W') { ans++; swap(s[i], s[i + 1]); i = 0; } else { i++; } if (i == s.length()) break; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef pair<int, int> pint; #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for (int i = x; i < n; i++) int main() { string s; cin >> s; ll ans = 0; int n = s.size(); int cnt = 0; rep(i, n) { if (s[i] == 'B') cnt++; else ans += cnt; } cout << ans << endl; }
replace
13
25
13
21
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ulli = unsigned long long int; #define debug(x) cerr << #x << " : " << x << endl namespace atcoder { void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") { if (judge_exp) { cout << ok << endl; } else { cout << ng << endl; } } template <typename T> T ncr(T left, T right) { right = min(left - right, right); T ans = 1; for (T i = 1; i <= right; i++) { ans = ans * (left - right + i) / i; } return ans; } const int LIMIT = 1000000007; const int tenfive = 100000; } // namespace atcoder using namespace atcoder; int main() { string s; cin >> s; lli ans = 0; for (int i = s.size() - 1; i > 0; i--) { for (int j = i; j > 0; j--) { if (s.substr(j - 1, 2) == "BW") { ans++; swap(s[j], s[j - 1]); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ulli = unsigned long long int; #define debug(x) cerr << #x << " : " << x << endl namespace atcoder { void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") { if (judge_exp) { cout << ok << endl; } else { cout << ng << endl; } } template <typename T> T ncr(T left, T right) { right = min(left - right, right); T ans = 1; for (T i = 1; i <= right; i++) { ans = ans * (left - right + i) / i; } return ans; } const int LIMIT = 1000000007; const int tenfive = 100000; } // namespace atcoder using namespace atcoder; int main() { string s; cin >> s; lli ans = 0; int b_count = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B') b_count++; else ans += b_count; } cout << ans << endl; return 0; }
replace
35
43
35
41
TLE
p03200
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1e9; #define put(n) cout << (n) << endl #define rep(i, N) for (int(i) = 0; (i) < (N); ++(i)) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define pb(n) push_back(n) int main() { string S; cin >> S; int ans = 0; bool ok = true; while (ok) { bool p = false; rep(i, S.size() - 1) { if (S[i] == 'B' && S[i + 1] == 'W') { S[i] = 'W'; S[i + 1] = 'B'; ++ans; p = true; } } if (!p) ok = false; } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1e9; #define put(n) cout << (n) << endl #define rep(i, N) for (int(i) = 0; (i) < (N); ++(i)) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define pb(n) push_back(n) int main() { string S; cin >> S; long long ans = 0; long long cnt = 0; for (int i = 0; i < S.size(); ++i) { if (S[i] == 'B') ++cnt; if (S[i] == 'W') ans += cnt; } cout << ans << endl; }
replace
17
32
17
24
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int64_t ans = 0; while (true) { bool flag = false; for (int i = 0; i < S.size() - 1; i++) { if (S.substr(i, 2) == "BW") { ans++; flag = true; S.at(i) = 'W'; S.at(i + 1) = 'B'; } } if (!flag) { break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int64_t ans = 0; int count = 0; for (int i = 0; i < S.size(); i++) { if (S.at(i) == 'B') { count++; } else { ans += count; } } cout << ans << endl; return 0; }
replace
7
19
7
13
TLE
p03200
C++
Time Limit Exceeded
#include <algorithm> #include <iomanip> #include <iostream> #include <list> #include <map> #include <random> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { string S; cin >> S; // bool flag = 0; int ans = 0; int k = 0; for (int i = 0; i < S.size() - 1; i++) { if (S.at(i) == 'B' && S.at(i + 1) == 'W') { S.at(i) = 'W'; S.at(i + 1) = 'B'; ans++; if (i != 0) { k = i - 1; while (1) { if (S.at(k) == 'B' && S.at(k + 1) == 'W') { S.at(k) = 'W'; S.at(k + 1) = 'B'; ans++; if (k != 0) { k--; } else { break; } } else { break; } } } } } cout << ans << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <list> #include <map> #include <random> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { string S; cin >> S; ll n = 0; ll ans = 0; for (ll i = 0; i < S.size(); i++) { if (S.at(i) == 'W') { ans += i - n; n++; } } cout << ans << endl; }
replace
17
42
17
23
TLE
p03200
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { string s; cin >> s; int n = s.size(); long long ans = 0; for (int i = 0; i < n - 1; i++) { if (s.substr(i, 2) == "BW") { s[i] = 'W'; s[i + 1] = 'B'; ans++; for (int k = 1;; k++) { if (i != 0 && s[i - k] == 'B') { ans++; s[i - k] = 'W'; s[i - k + 1] = 'B'; } else { break; } } } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { string s; cin >> s; int n = s.size(); long long ans = 0, ans1 = 0; for (int i = 0; i < n; i++) { if (s[i] == 'B') { ans1++; } else { ans += ans1; } } cout << ans << endl; }
replace
19
34
19
25
TLE
p03200
C++
Time Limit Exceeded
// A - Irreversible operation #include <bits/stdc++.h> using namespace std; typedef long long ll; // const int INF = 2147483647; // const ll INF = 9223372036854775807; // const ll MOD = 1e9 + 7; int main() { string S; cin >> S; if (S.size() == 1) { cout << 0 << endl; return 0; } int ans = 0; if (S[0] == 'B' && S[1] == 'W') { S[0] = 'W'; S[1] = 'B'; ans++; } int i = 1; while (i < S.size() - 1) { if (S[i] == 'B' && S[i + 1] == 'W') { S[i] = 'W'; S[i + 1] = 'B'; ans++; if (S[i - 1] == 'B') i--; else i++; } else { i++; } } cout << ans << endl; return 0; }
// A - Irreversible operation #include <bits/stdc++.h> using namespace std; typedef long long ll; // const int INF = 2147483647; // const ll INF = 9223372036854775807; // const ll MOD = 1e9 + 7; int main() { string S; cin >> S; if (S.size() == 1) { cout << 0 << endl; return 0; } ll ans = 0; ll cnt = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == 'B') cnt++; else ans += cnt; } cout << ans << endl; return 0; }
replace
19
40
19
26
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int res = 0, d = 1; while (d > 0) { d = 0; for (int i = s.size() - 1; i > 0; i--) { if (s[i] == 'W' && s[i - 1] == 'B') { d++, swap(s[i], s[i - 1]); } } res += d; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long res = 0; int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B') cnt++; else res += cnt; } cout << res << endl; return 0; }
replace
7
16
7
14
TLE
p03200
C++
Runtime Error
#include <cstdio> #include <cstring> #include <iostream> using namespace std; long long n, a[100001], b[100001], ans = 0; string s; void gb(int l, int r) { if (l == r) return; int mid = (l + r) >> 1; gb(l, mid); gb(mid + 1, r); int i = l, j = mid + 1, top = l - 1, k; while (i <= mid && j <= r) { if (a[i] > a[j]) { b[++top] = a[j]; ans += mid - i + 1; j++; } else { b[++top] = a[i]; i++; } } for (k = i; k <= mid; k++) b[++top] = a[k]; for (k = j; k <= r; k++) b[++top] = a[k]; for (k = l; k <= r; k++) a[k] = b[k]; return; } int main() { cin >> s; n = s.length(); for (int k = 1; k <= n; k++) a[k] = (s[k - 1] == 'B'); gb(1, n); cout << ans << endl; return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; long long n, a[250001], b[250001], ans = 0; string s; void gb(int l, int r) { if (l == r) return; int mid = (l + r) >> 1; gb(l, mid); gb(mid + 1, r); int i = l, j = mid + 1, top = l - 1, k; while (i <= mid && j <= r) { if (a[i] > a[j]) { b[++top] = a[j]; ans += mid - i + 1; j++; } else { b[++top] = a[i]; i++; } } for (k = i; k <= mid; k++) b[++top] = a[k]; for (k = j; k <= r; k++) b[++top] = a[k]; for (k = l; k <= r; k++) a[k] = b[k]; return; } int main() { cin >> s; n = s.length(); for (int k = 1; k <= n; k++) a[k] = (s[k - 1] == 'B'); gb(1, n); cout << ans << endl; return 0; }
replace
4
5
4
5
0
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, ini, n) for (int i = ini; i < n; i++) #define _rep(i, ini, n) for (int i = ini; i >= n; i--) #define ToEnd(a) a.begin(), a.end() uint64_t MOD = 1000000007; int main() { string S; cin >> S; uint64_t ans = 0; while (1) { int idx = S.find("BW"); if (idx == string::npos) break; S.replace(idx, 2, "WB"); ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, ini, n) for (int i = ini; i < n; i++) #define _rep(i, ini, n) for (int i = ini; i >= n; i--) #define ToEnd(a) a.begin(), a.end() uint64_t MOD = 1000000007; int main() { string S; cin >> S; uint64_t ans = 0, wCnt = 0; ; for (auto s : S) { if (s == 'B') wCnt++; else ans += wCnt; } cout << ans << endl; }
replace
11
18
11
18
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int LCM(int a, int b) { return (a * b) / GCD(a, b); } int abs(int x) { return x > 0 ? x : -x; } // const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; // const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int main() { string s; cin >> s; int sum = 0; int len; while (1) { len = (int)s.size(); if (len == 0) break; auto pos = s.rfind("B"); if (pos != -1) { sum += len - ((int)pos + 1); s[pos] = 'W'; } s.pop_back(); } cout << sum << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } int LCM(int a, int b) { return (a * b) / GCD(a, b); } int abs(int x) { return x > 0 ? x : -x; } // const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; // const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; int main() { string s; cin >> s; ll sum = 0; int len = (int)s.size(); vector<int> index_b; for (int i = 0; i < len; i++) { if (s[i] == 'B') index_b.push_back(i); } reverse(ALL(index_b)); len--; for (auto x : index_b) { sum += (len--) - x; } cout << sum << endl; }
replace
18
30
18
30
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { string s; std::cin >> s; uint64_t count = 0; rep(i, s.size() - 1) { if (s[i] == 'B' && s[i + 1] == 'W') { s[i] = 'W'; s[i + 1] = 'B'; count++; while (s[i - 1] == 'B') { s[i - 1] = 'W'; s[i] = 'B'; count++; --i; } } } std::cout << count << std::endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { string s; std::cin >> s; uint64_t count = 0; uint64_t black = 0; rep(i, s.size()) { if (s[i] == 'W') { count += black; } else { black++; } } std::cout << count << std::endl; return 0; }
replace
11
22
11
17
TLE
p03200
C++
Time Limit Exceeded
#include <iostream> int main() { std::string s; std::cin >> s; int cnt = 0; size_t p = 0; while ((p = s.find("BW")) != std::string::npos) { s.replace(p, 2, "WB", 2); cnt++; } std::cout << cnt << std::endl; return 0; }
#include <iostream> int main() { std::string s; std::cin >> s; unsigned long long cnt = 0; int b = 0; for (auto &c : s) { if (c == 'W') { cnt += b; } else { // 'B' b++; } } std::cout << cnt << std::endl; return 0; }
replace
5
10
5
14
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); int cnt = 0; for (int j = 0;; j++) { bool bw = true; for (int i = 0; i < n - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'W') { cnt++; s[i] = 'W'; s[i + 1] = 'B'; bw = false; } } if (bw) break; } cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); long long int cnt = 0, w[n] = {}; if (s[0] == 'W') w[0]++; for (int i = 1; i < n; i++) { if (s[i] == 'W') w[i] = w[i - 1] + 1; else w[i] = w[i - 1]; } for (int i = 0; i < n; i++) { if (s[i] == 'B') cnt += w[n - 1] - w[i]; } cout << cnt; }
replace
7
20
7
20
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; typedef vector<ll> vll; typedef vector<int> vi; const int maxn = 100 + 10; int main() { string s; cin >> s; int ans = 0; int left = 0; int right = 0; while (left < s.length() && right < s.length()) { while (left < s.length() && s[left] == 'W') ++left; if (left >= s.length()) break; right = left + 1; while (right < s.length() && s[right] == 'B') ++right; if (right >= s.length()) break; ans += right - left; swap(s[left], s[right]); ++left; ++right; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 7; typedef vector<ll> vll; typedef vector<int> vi; const int maxn = 100 + 10; int main() { string s; cin >> s; ll ans = 0; ll cnt = 0; for (auto c : s) { if (c == 'B') ++cnt; else ans += cnt; } cout << ans << endl; return 0; }
replace
12
29
12
19
TLE
p03200
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, n) for (int i = 1; i <= (n); i++) #define lol long long #define SUM(n) ((n) + 1) * (n) / 2 // 1〜nまでの総和を求める式 #define mp make_pair #define fi first #define se second #define pu push_back #define SYOU(x) fixed << setprecision(x + 1) // 小数点桁数を指定する #define abs(x, y) max(x, y) - min(x, y) #define all(v) v.begin(), v.end() #define UPDight(a, b) (a + b - 1) / b // 小数点切り上げ const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int MOD = int(1e9) + 7; using namespace std; using pii = pair<int, int>; typedef vector<int> vit; // 最大公約数 lol gcd(lol x, lol y) { if (x < y) swap(x, y); lol r = x % y; while (r != 0) { x = y; y = r; r = x % y; } return y; } // 最小公倍数 lol lcm(lol x, lol y) { lol a = x * y; return (a / gcd(x, y)); } signed main(void) { cin.tie(nullptr); ios_base::sync_with_stdio(false); string s; cin >> s; lol ans = 0; while (true) { bool nasu = false; for (int i = s.size() - 1; i > 0; i--) { if (s[i] == 'W' && s[i - 1] == 'B') { ans++; swap(s[i], s[i - 1]); nasu = true; } } // cout << s << '\n'; if (!nasu) { break; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, n) for (int i = 1; i <= (n); i++) #define lol long long #define SUM(n) ((n) + 1) * (n) / 2 // 1〜nまでの総和を求める式 #define mp make_pair #define fi first #define se second #define pu push_back #define SYOU(x) fixed << setprecision(x + 1) // 小数点桁数を指定する #define abs(x, y) max(x, y) - min(x, y) #define all(v) v.begin(), v.end() #define UPDight(a, b) (a + b - 1) / b // 小数点切り上げ const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int MOD = int(1e9) + 7; using namespace std; using pii = pair<int, int>; typedef vector<int> vit; // 最大公約数 lol gcd(lol x, lol y) { if (x < y) swap(x, y); lol r = x % y; while (r != 0) { x = y; y = r; r = x % y; } return y; } // 最小公倍数 lol lcm(lol x, lol y) { lol a = x * y; return (a / gcd(x, y)); } signed main(void) { cin.tie(nullptr); ios_base::sync_with_stdio(false); string s; cin >> s; lol ans = 0, nasu = 0; rep(i, s.size()) { if (s[i] == 'W') { ans += nasu; } else { nasu++; } } cout << ans << '\n'; return 0; }
replace
46
59
46
52
TLE