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
p03092
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define ph push #define f first #define s second #define cbr cerr << "hi\n" #define mmst(x, v) memset((x), v, sizeof((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return (rng() % (y + 1 - x)) + x; } // inclusivesss string inline to_string(char c) { string s(1, c); return s; } template <typename T> inline T gcd(T a, T b) { return a == 0 ? llabs(b) : gcd(b % a, a); } typedef long long ll; typedef long double ld; #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) typedef pair<ll, ll> pi; typedef pair<ll, pi> spi; typedef pair<pi, pi> dpi; #define LLINF ((long long)1e18) // 1234567890987654321 #define INF 1234567890ll // #define cerr if(0)cout #define MAXN (5006) ll n, a, b, A[MAXN], dp[2][MAXN], pos[MAXN], co[MAXN]; // dp(i, j) = dp(val i, at pos j -> 0 all the elements are in // order); int main() { // can be proven that each element moves once FAST cin >> n >> a >> b; FOR(i, 1, n) cin >> A[i], pos[A[i]] = i; FOR(i, 1, n) { mmst(dp[i % 2], 0); ll x = pos[i]; FOR(j, 1, x - 1) dp[i % 2][j] = dp[i % 2 ^ 1][j]; // storing history values (won't be changed), but // might be referenced in the future FOR(j, x, n) { // legit ones dp[i % 2][j] = min((j == x ? LLINF : dp[i % 2 ^ 1][j] + a), dp[i % 2 ^ 1][x - 1] + b * (co[j] - co[x])); // move all blocking elements to correct // position, u'll end up at position i // (cos i-p-1 items just got moved) } FOR(i, x, n)++ co[i]; FOR(j, 1, n) cerr << dp[i % 2][j] << ' '; cerr << '\n'; } cout << dp[n % 2][n] << '\n'; }
#include "bits/stdc++.h" using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define ph push #define f first #define s second #define cbr cerr << "hi\n" #define mmst(x, v) memset((x), v, sizeof((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return (rng() % (y + 1 - x)) + x; } // inclusivesss string inline to_string(char c) { string s(1, c); return s; } template <typename T> inline T gcd(T a, T b) { return a == 0 ? llabs(b) : gcd(b % a, a); } typedef long long ll; typedef long double ld; #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) typedef pair<ll, ll> pi; typedef pair<ll, pi> spi; typedef pair<pi, pi> dpi; #define LLINF ((long long)1e18) // 1234567890987654321 #define INF 1234567890ll // #define cerr if(0)cout #define MAXN (5006) ll n, a, b, A[MAXN], dp[2][MAXN], pos[MAXN], co[MAXN]; // dp(i, j) = dp(val i, at pos j -> 0 all the elements are in // order); int main() { // can be proven that each element moves once FAST cin >> n >> a >> b; FOR(i, 1, n) cin >> A[i], pos[A[i]] = i; FOR(i, 1, n) { mmst(dp[i % 2], 0); ll x = pos[i]; FOR(j, 1, x - 1) dp[i % 2][j] = dp[i % 2 ^ 1][j]; // storing history values (won't be changed), but // might be referenced in the future FOR(j, x, n) { // legit ones dp[i % 2][j] = min((j == x ? LLINF : dp[i % 2 ^ 1][j] + a), dp[i % 2 ^ 1][x - 1] + b * (co[j] - co[x])); // move all blocking elements to correct // position, u'll end up at position i // (cos i-p-1 items just got moved) } FOR(i, x, n)++ co[i]; // FOR(j,1,n)cerr<<dp[i%2][j]<<' '; cerr<<'\n'; } cout << dp[n % 2][n] << '\n'; }
replace
67
69
67
68
TLE
p03092
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> using namespace std; typedef unsigned int uint; typedef long long LL; typedef unsigned long long ULL; typedef pair<LL, LL> PP; #define REP(i, a, n) for (LL i = (a), i##_max = (n); i < i##_max; ++i) #define REM(i, a, n) for (LL i = (LL)(n)-1, i##min = (a); i >= i##min; --i) #define ALL(arr) (arr).begin(), (arr).end() #define FLOAT fixed << setprecision(16) #define SPEEDUP \ { \ cin.tie(NULL); \ ios::sync_with_stdio(false); \ } const int INF = 0x3FFFFFFF; const LL INFLL = 0x3FFFFFFF3FFFFFFF; const double INFD = 1.0e+308; const string INFSTR = "\x7f"; const double EPS = 1.0e-9; void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T, class U> istream &operator>>(istream &ist, pair<T, U> &right) { return ist >> right.first >> right.second; } template <class T, class U> ostream &operator<<(ostream &ost, const pair<T, U> &right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T (&dest)[N], const TCompatible &val) { fill(dest, dest + N, val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T (&dest)[M][N], const TCompatible &val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } template <class T> T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); } istream &Ignore(istream &ist) { string s; ist >> s; return ist; } bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } template <class T> T Next() { T buf; cin >> buf; return buf; } #ifdef ONLY_MY_ENVIR #include "BIT.h" #include "Factorization.h" #include "FlowSolver.h" #include "Global.h" #include "Graph.h" #include "IntMod.h" #include "LazySegmentTree.h" #include "Math.h" #include "Matrix.h" #include "Position.h" #include "Range.h" #include "Rational.h" #include "SegmentTree.h" #include "SegmentTree2D.h" #include "SuffixArray.h" #include "Tree.h" #include "UnionFind.h" #endif #ifdef __GNUC__ typedef __int128 LLL; istream &operator>>(istream &ist, __int128 &val) { LL tmp; ist >> tmp; val = tmp; return ist; } ostream &operator<<(ostream &ost, __int128 val) { LL tmp = val; ost << tmp; return ost; } #endif #if 1234567891 #include <array> #include <random> #include <unordered_map> #include <unordered_set> template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T>>; // template <class T> // auto Is(const T& value) { return [value](const auto& comparand) -> bool { // return comparand == value; }; } #endif LL N, X, Y; vector<int> A; int P[5002][5002]; int Q[5003][5003]; int R[5003][5003]; void pre() { REP(i, 0, N + 1) { REP(j, 0, N) { Q[i][j + 1] = Q[i][j] + P[i][j]; } } REP(j, 0, N + 1) { REP(i, 0, N) { R[i + 1][j] = R[i][j] + Q[i][j]; } } } int rect(int li, int lj, int ri, int rj) { return R[li][lj] - R[li][rj] - R[ri][lj] + R[ri][rj]; } LL DP[5002][5002]; int main() { cin >> N >> X >> Y; A.push_back(0); REP(i, 0, N) A.push_back(Next<int>()); A.push_back(N + 1); N += 2; REP(i, 0, N) { ++P[i][A[i]]; } pre(); Fill(DP, INFLL); DP[0][0] = 0; REP(i, 1, N) { REP(j, 0, N) { if (j == A[i]) { LL mn = INFLL; REP(li, 0, i) { if (A[li] > A[i]) continue; int lj = A[li]; int L = rect(li, lj, i, N) - 1; int R = rect(i, lj, N, j); mn = min(mn, DP[i - 1][lj] + L * X + R * Y); } DP[i][j] = mn; } else { DP[i][j] = DP[i - 1][j]; } } } cout << DP[N - 1][N - 1] << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> using namespace std; typedef unsigned int uint; typedef long long LL; typedef unsigned long long ULL; typedef pair<LL, LL> PP; #define REP(i, a, n) for (LL i = (a), i##_max = (n); i < i##_max; ++i) #define REM(i, a, n) for (LL i = (LL)(n)-1, i##min = (a); i >= i##min; --i) #define ALL(arr) (arr).begin(), (arr).end() #define FLOAT fixed << setprecision(16) #define SPEEDUP \ { \ cin.tie(NULL); \ ios::sync_with_stdio(false); \ } const int INF = 0x3FFFFFFF; const LL INFLL = 0x3FFFFFFF3FFFFFFF; const double INFD = 1.0e+308; const string INFSTR = "\x7f"; const double EPS = 1.0e-9; void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T, class U> istream &operator>>(istream &ist, pair<T, U> &right) { return ist >> right.first >> right.second; } template <class T, class U> ostream &operator<<(ostream &ost, const pair<T, U> &right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T (&dest)[N], const TCompatible &val) { fill(dest, dest + N, val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T (&dest)[M][N], const TCompatible &val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } template <class T> T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); } istream &Ignore(istream &ist) { string s; ist >> s; return ist; } bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } template <class T> T Next() { T buf; cin >> buf; return buf; } #ifdef ONLY_MY_ENVIR #include "BIT.h" #include "Factorization.h" #include "FlowSolver.h" #include "Global.h" #include "Graph.h" #include "IntMod.h" #include "LazySegmentTree.h" #include "Math.h" #include "Matrix.h" #include "Position.h" #include "Range.h" #include "Rational.h" #include "SegmentTree.h" #include "SegmentTree2D.h" #include "SuffixArray.h" #include "Tree.h" #include "UnionFind.h" #endif #ifdef __GNUC__ typedef __int128 LLL; istream &operator>>(istream &ist, __int128 &val) { LL tmp; ist >> tmp; val = tmp; return ist; } ostream &operator<<(ostream &ost, __int128 val) { LL tmp = val; ost << tmp; return ost; } #endif #if 1234567891 #include <array> #include <random> #include <unordered_map> #include <unordered_set> template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T>>; // template <class T> // auto Is(const T& value) { return [value](const auto& comparand) -> bool { // return comparand == value; }; } #endif LL N, X, Y; vector<int> A; int P[5003][5003]; int Q[5003][5003]; int R[5003][5003]; void pre() { REP(i, 0, N + 1) { REP(j, 0, N) { Q[i][j + 1] = Q[i][j] + P[i][j]; } } REP(j, 0, N + 1) { REP(i, 0, N) { R[i + 1][j] = R[i][j] + Q[i][j]; } } } int rect(int li, int lj, int ri, int rj) { return R[li][lj] - R[li][rj] - R[ri][lj] + R[ri][rj]; } LL DP[5002][5002]; int main() { cin >> N >> X >> Y; A.push_back(0); REP(i, 0, N) A.push_back(Next<int>()); A.push_back(N + 1); N += 2; REP(i, 0, N) { ++P[i][A[i]]; } pre(); Fill(DP, INFLL); DP[0][0] = 0; REP(i, 1, N) { REP(j, 0, N) { if (j == A[i]) { LL mn = INFLL; REP(li, 0, i) { if (A[li] > A[i]) continue; int lj = A[li]; int L = rect(li, lj, i, N) - 1; int R = rect(i, lj, N, j); mn = min(mn, DP[i - 1][lj] + L * X + R * Y); } DP[i][j] = mn; } else { DP[i][j] = DP[i - 1][j]; } } } cout << DP[N - 1][N - 1] << endl; return 0; }
replace
131
132
131
132
-11
p03093
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_set> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) (int)x.size() #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) x.begin(), x.end() typedef tuple<int, int, int> t3; int n, m, a[100010]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n * 2; i++) scanf("%d", a + i); sort(a + 1, a + 1 + 2 * n); int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, (a[i] + a[2 * n + 1 - i]) % m); int low = 0, high = n; while (low <= high) { int mid = (low + high) >> 1; int lmx = 0; for (int i = 1; i <= mid; i++) { lmx = max(lmx, a[i] + a[mid * 2 + 1 - i]); } if (lmx >= m) { high = mid - 1; continue; } int rmn = 2e9; for (int i = 2 * n; i > 2 * n - (n - mid); i--) { int j = 2 * n + 2 * mid + 1 - i; rmn = min(rmn, a[i] + a[j]); } if (rmn < m) { low = mid + 1; continue; } int lv = 0, rv = 0; for (int i = 1; i <= mid; i++) { lv = max(lv, a[i] + a[mid * 2 + 1 - i]); } for (int i = 2 * n; i > 2 * n - (n - mid); i--) { int j = 2 * n + 2 * mid + 1 - i; rv = max(rv, a[i] + a[j] - m); } if (lv >= rv) { ans = min(ans, lv); high = mid - 1; } else { ans = min(ans, rv); high = mid - 1; } } printf("%d\n", ans); return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_set> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) (int)x.size() #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) x.begin(), x.end() typedef tuple<int, int, int> t3; int n, m, a[200010]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n * 2; i++) scanf("%d", a + i); sort(a + 1, a + 1 + 2 * n); int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, (a[i] + a[2 * n + 1 - i]) % m); int low = 0, high = n; while (low <= high) { int mid = (low + high) >> 1; int lmx = 0; for (int i = 1; i <= mid; i++) { lmx = max(lmx, a[i] + a[mid * 2 + 1 - i]); } if (lmx >= m) { high = mid - 1; continue; } int rmn = 2e9; for (int i = 2 * n; i > 2 * n - (n - mid); i--) { int j = 2 * n + 2 * mid + 1 - i; rmn = min(rmn, a[i] + a[j]); } if (rmn < m) { low = mid + 1; continue; } int lv = 0, rv = 0; for (int i = 1; i <= mid; i++) { lv = max(lv, a[i] + a[mid * 2 + 1 - i]); } for (int i = 2 * n; i > 2 * n - (n - mid); i--) { int j = 2 * n + 2 * mid + 1 - i; rv = max(rv, a[i] + a[j] - m); } if (lv >= rv) { ans = min(ans, lv); high = mid - 1; } else { ans = min(ans, rv); high = mid - 1; } } printf("%d\n", ans); return 0; }
replace
31
32
31
32
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair<int, int> #define F first #define S second #define endl '\n' #define int long long #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout << x << '\n', 0; using namespace std; const int N = 1e5 + 100; ll a[N]; int32_t main() { ll n, m; cin >> n >> m; for (int i = 1; i <= 2 * n; i++) { cin >> a[i]; } sort(a + 1, a + 2 * n + 1); ll l = -1, r = n; while (r - l > 1) { ll mid = (r + l) / 2; ll p1 = 0, ma = 0; for (int i = 1; i <= mid; i++) { ll z = 2 * mid - i + 1; if (a[z] + a[i] >= m) p1 = 1; ma = max(ma, a[z] + a[i]); } if (p1) { r = mid; continue; } ll t = 2 * mid + 2 * n; t /= 2; for (int j = 2 * mid + 1; j <= t; j++) { ll z = 2 * n - j + 2 * mid + 1; if (a[z] + a[j] < m) p1 = 1; ma = max(ma, (a[z] + a[j]) % m); } if (!p1) r = mid; else l = mid; } ll mid = r; ll ma = 0; for (int i = 1; i <= mid; i++) { ll z = 2 * mid - i + 1; ma = max(ma, a[z] + a[i]); } ll t = 2 * mid + 2 * n; t /= 2; for (int j = 2 * mid + 1; j <= t; j++) { ll z = 2 * n - j + 2 * mid + 1; ma = max(ma, (a[z] + a[j]) % m); } cout << ma << endl; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair<int, int> #define F first #define S second #define endl '\n' #define int long long #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout << x << '\n', 0; using namespace std; const int N = 2e5 + 100; ll a[N]; int32_t main() { ll n, m; cin >> n >> m; for (int i = 1; i <= 2 * n; i++) { cin >> a[i]; } sort(a + 1, a + 2 * n + 1); ll l = -1, r = n; while (r - l > 1) { ll mid = (r + l) / 2; ll p1 = 0, ma = 0; for (int i = 1; i <= mid; i++) { ll z = 2 * mid - i + 1; if (a[z] + a[i] >= m) p1 = 1; ma = max(ma, a[z] + a[i]); } if (p1) { r = mid; continue; } ll t = 2 * mid + 2 * n; t /= 2; for (int j = 2 * mid + 1; j <= t; j++) { ll z = 2 * n - j + 2 * mid + 1; if (a[z] + a[j] < m) p1 = 1; ma = max(ma, (a[z] + a[j]) % m); } if (!p1) r = mid; else l = mid; } ll mid = r; ll ma = 0; for (int i = 1; i <= mid; i++) { ll z = 2 * mid - i + 1; ma = max(ma, a[z] + a[i]); } ll t = 2 * mid + 2 * n; t /= 2; for (int j = 2 * mid + 1; j <= t; j++) { ll z = 2 * n - j + 2 * mid + 1; ma = max(ma, (a[z] + a[j]) % m); } cout << ma << endl; }
replace
16
17
16
17
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } const int maxn = 200005; int n, a[maxn], p; bool check(int t) { for (int i = 2 * t + 1; i <= (n << 1); ++i) if (a[i] + a[((n + t) << 1) - i + i] < p) return 0; return 1; } int main() { n = gi(); p = gi(); for (int i = 1; i <= (n << 1); ++i) a[i] = gi(); sort(a + 1, a + n + n + 1); int l = 0, r = n, mid; while (l < r) { mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } int ans = 0; for (int i = 1; i <= (l << 1); ++i) ans = max(ans, a[i] + a[(l << 1) - i + 1]); for (int i = (l << 1) + 1; i <= (n << 1); ++i) ans = max(ans, a[i] + a[((n + l) << 1) - i + 1] - p); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } const int maxn = 200005; int n, a[maxn], p; bool check(int t) { for (int i = 2 * t + 1; i <= (n << 1); ++i) if (a[i] + a[((n + t) << 1) - i + 1] < p) return 0; return 1; } int main() { n = gi(); p = gi(); for (int i = 1; i <= (n << 1); ++i) a[i] = gi(); sort(a + 1, a + n + n + 1); int l = 0, r = n, mid; while (l < r) { mid = (l + r) >> 1; if (check(mid)) r = mid; else l = mid + 1; } int ans = 0; for (int i = 1; i <= (l << 1); ++i) ans = max(ans, a[i] + a[(l << 1) - i + 1]); for (int i = (l << 1) + 1; i <= (n << 1); ++i) ans = max(ans, a[i] + a[((n + l) << 1) - i + 1] - p); printf("%d\n", ans); return 0; }
replace
19
20
19
20
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 100005 int n, m; int a[N << 1]; int main() { scanf("%d %d", &n, &m); int nn = n << 1; for (int i = 1; i <= nn; i++) scanf("%d", &a[i]); sort(a + 1, a + nn + 1); int st = 0, en = n + 1; while (en - st > 1) { int mid = en + st >> 1; int len = mid * 2; int pos = nn - len; bool flag = 0; for (int i = 1; i <= pos && !flag; i++) { if (a[i] + a[pos + 1 - i] >= m) flag = 1; } for (int i = pos + 1; i <= nn && !flag; i++) { if (a[i] + a[nn + pos + 1 - i] < m) flag = 1; } if (flag) en = mid; else st = mid; } int len = st * 2; int mx = 0, pos = nn - len; for (int i = 1; i <= pos; i++) { mx = max(mx, a[i] + a[pos + 1 - i]); if (a[i] + a[pos + 1 - i] >= m) assert(0), assert(st == 0 && a[nn] + a[nn - 1] >= m); // assert(a[i]+a[pos+1-i]<m); } for (int i = pos + 1; i <= nn; i++) { mx = max(mx, a[i] + a[nn + pos + 1 - i] - m); assert(a[i] + a[nn + pos + 1 - i] >= m); } printf("%d\n", mx); return 0; }
#include <bits/stdc++.h> using namespace std; #define N 100005 int n, m; int a[N << 1]; int main() { scanf("%d %d", &n, &m); int nn = n << 1; for (int i = 1; i <= nn; i++) scanf("%d", &a[i]); sort(a + 1, a + nn + 1); int st = 0, en = n + 1; while (en - st > 1) { int mid = en + st >> 1; int len = mid * 2; int pos = nn - len; bool flag = 0; // for (int i = 1; i <= pos && !flag; i ++) { // if (a[i] + a[pos+1-i] >= m) flag = 1; // } for (int i = pos + 1; i <= nn && !flag; i++) { if (a[i] + a[nn + pos + 1 - i] < m) flag = 1; } if (flag) en = mid; else st = mid; } int len = st * 2; int mx = 0, pos = nn - len; for (int i = 1; i <= pos; i++) { mx = max(mx, a[i] + a[pos + 1 - i]); if (a[i] + a[pos + 1 - i] >= m) assert(0), assert(st == 0 && a[nn] + a[nn - 1] >= m); // assert(a[i]+a[pos+1-i]<m); } for (int i = pos + 1; i <= nn; i++) { mx = max(mx, a[i] + a[nn + pos + 1 - i] - m); assert(a[i] + a[nn + pos + 1 - i] >= m); } printf("%d\n", mx); return 0; }
replace
20
24
20
23
0
p03093
C++
Runtime Error
// This amazing code is by Eric Sunli Chen. #include <bits/stdc++.h> using namespace std; template <typename T> bool get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar()) ; if (t == '-') neg = true, t = getchar(); if (t == EOF) return false; for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0'; if (neg) x = -x; return true; } template <typename T> void print_int(T x) { if (x < 0) putchar('-'), x = -x; short a[20] = {}, sz = 0; while (x > 0) a[sz++] = x % 10, x /= 10; if (sz == 0) putchar('0'); for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]); } #define ff first #define ss second #define pb push_back #define mp make_pair #define get1(a) get_int(a) #define get2(a, b) (get1(a) && get1(b)) #define get3(a, b, c) (get1(a) && get2(b, c)) #define printendl(a) print_int(a), puts("") typedef long long LL; typedef unsigned long long uLL; typedef pair<int, int> pii; typedef vector<int> vi; const int inf = 0x3f3f3f3f; const LL Linf = 1ll << 61; const double pi = acos(-1.0); const int maxn = 100111; int n, m, a[maxn]; bool check(int v) { for (int i = v; i <= n; i++) if (a[i] + a[v + n - i] < m) return false; return true; } int main() { get2(n, m); n *= 2; for (int i = 1; i <= n; i++) get1(a[i]); sort(a + 1, a + n + 1); int lb = 0, rb = n + 1, mid; while (lb < rb - 1) { mid = (lb + rb) >> 1; if (check(mid)) rb = mid; else lb = mid; } if (rb % 2 == 0) rb++; int ans = 0; for (int i = 1; i < rb; i++) ans = max(ans, a[i] + a[rb - i]); for (int i = rb; i <= n; i++) ans = max(ans, a[i] + a[rb + n - i] - m); printendl(ans); return 0; }
// This amazing code is by Eric Sunli Chen. #include <bits/stdc++.h> using namespace std; template <typename T> bool get_int(T &x) { char t = getchar(); bool neg = false; x = 0; for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar()) ; if (t == '-') neg = true, t = getchar(); if (t == EOF) return false; for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0'; if (neg) x = -x; return true; } template <typename T> void print_int(T x) { if (x < 0) putchar('-'), x = -x; short a[20] = {}, sz = 0; while (x > 0) a[sz++] = x % 10, x /= 10; if (sz == 0) putchar('0'); for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]); } #define ff first #define ss second #define pb push_back #define mp make_pair #define get1(a) get_int(a) #define get2(a, b) (get1(a) && get1(b)) #define get3(a, b, c) (get1(a) && get2(b, c)) #define printendl(a) print_int(a), puts("") typedef long long LL; typedef unsigned long long uLL; typedef pair<int, int> pii; typedef vector<int> vi; const int inf = 0x3f3f3f3f; const LL Linf = 1ll << 61; const double pi = acos(-1.0); const int maxn = 200111; int n, m, a[maxn]; bool check(int v) { for (int i = v; i <= n; i++) if (a[i] + a[v + n - i] < m) return false; return true; } int main() { get2(n, m); n *= 2; for (int i = 1; i <= n; i++) get1(a[i]); sort(a + 1, a + n + 1); int lb = 0, rb = n + 1, mid; while (lb < rb - 1) { mid = (lb + rb) >> 1; if (check(mid)) rb = mid; else lb = mid; } if (rb % 2 == 0) rb++; int ans = 0; for (int i = 1; i < rb; i++) ans = max(ans, a[i] + a[rb - i]); for (int i = rb; i <= n; i++) ans = max(ans, a[i] + a[rb + n - i] - m); printendl(ans); return 0; }
replace
46
47
46
47
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m, a[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n * 2 + 1); int l = 0, r = n; while (l < r) { int mid = (l + r) >> 1; bool flag = 1; for (int i = 1; i <= n - mid; ++i) if (a[mid * 2 + i] + a[2 * n - i + 1] < m) flag = 0; if (!flag) l = mid + 1; else r = mid; } int ans = 0; for (int i = 1; i <= l; ++i) ans = max(ans, (a[i] + a[l * 2 - i + 1]) % m); for (int i = 1; i <= n - l; ++i) ans = max(ans, (a[l * 2 + i] + a[2 * n - i + 1]) % m); printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int n, m, a[N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n * 2 + 1); int l = 0, r = n; while (l < r) { int mid = (l + r) >> 1; bool flag = 1; for (int i = 1; i <= n - mid; ++i) if (a[mid * 2 + i] + a[2 * n - i + 1] < m) flag = 0; if (!flag) l = mid + 1; else r = mid; } int ans = 0; for (int i = 1; i <= l; ++i) ans = max(ans, (a[i] + a[l * 2 - i + 1]) % m); for (int i = 1; i <= n - l; ++i) ans = max(ans, (a[l * 2 + i] + a[2 * n - i + 1]) % m); printf("%d", ans); return 0; }
replace
2
3
2
3
0
p03093
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; int n, m, a[100100], Ans, ans; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]); sort(a + 1, a + 2 * n + 1); int L = 0, R = n, ans; while (L <= R) { int mid = (L + R) / 2; bool bo = true; for (int i = mid + 1; i <= n; i++) if (a[mid + i] + a[2 * n - i + mid + 1] < m) { bo = false; break; } if (bo) ans = mid, R = mid - 1; else L = mid + 1; } for (int i = 1; i <= ans; i++) Ans = max(Ans, a[i] + a[ans * 2 - i + 1]); for (int i = ans + 1; i <= n; i++) Ans = max(Ans, a[ans + i] + a[2 * n - i + ans + 1] - m); printf("%d\n", Ans); }
#include <algorithm> #include <cstdio> using namespace std; int n, m, a[200100], Ans, ans; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]); sort(a + 1, a + 2 * n + 1); int L = 0, R = n, ans; while (L <= R) { int mid = (L + R) / 2; bool bo = true; for (int i = mid + 1; i <= n; i++) if (a[mid + i] + a[2 * n - i + mid + 1] < m) { bo = false; break; } if (bo) ans = mid, R = mid - 1; else L = mid + 1; } for (int i = 1; i <= ans; i++) Ans = max(Ans, a[i] + a[ans * 2 - i + 1]); for (int i = ans + 1; i <= n; i++) Ans = max(Ans, a[ans + i] + a[2 * n - i + ans + 1] - m); printf("%d\n", Ans); }
replace
3
4
3
4
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, m, a[120000], ans; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n * 2; ++i) scanf("%d", a + i); sort(a + 1, a + n * 2 + 1); int l = 0, r = n; while (l <= r) { int mid = (l + r) >> 1; bool fl = 1; int tmp = 0; for (int i = 1; i <= mid; ++i) { fl &= a[i] + a[mid * 2 - i + 1] < m; tmp = max(tmp, a[i] + a[mid * 2 - i + 1]); } if (!fl) { r = mid - 1; continue; } for (int i = 1; i <= n - mid; ++i) { fl &= a[mid * 2 + i] + a[n * 2 - i + 1] >= m; tmp = max(tmp, a[mid * 2 + i] + a[n * 2 - i + 1] - m); } if (!fl) { l = mid + 1; continue; } ans = tmp; r = mid - 1; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, a[300000], ans; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n * 2; ++i) scanf("%d", a + i); sort(a + 1, a + n * 2 + 1); int l = 0, r = n; while (l <= r) { int mid = (l + r) >> 1; bool fl = 1; int tmp = 0; for (int i = 1; i <= mid; ++i) { fl &= a[i] + a[mid * 2 - i + 1] < m; tmp = max(tmp, a[i] + a[mid * 2 - i + 1]); } if (!fl) { r = mid - 1; continue; } for (int i = 1; i <= n - mid; ++i) { fl &= a[mid * 2 + i] + a[n * 2 - i + 1] >= m; tmp = max(tmp, a[mid * 2 + i] + a[n * 2 - i + 1] - m); } if (!fl) { l = mid + 1; continue; } ans = tmp; r = mid - 1; } printf("%d\n", ans); return 0; }
replace
4
5
4
5
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> #define ci const int & using namespace std; int n, m, a[100010], l, r, mid, ans; bool Check(int x) { if (!(x & 1)) --x; for (int i = x, j = (n << 1); i < j; ++i, --j) if (a[i] + a[j] < m) return 0; return 1; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= (n << 1); ++i) scanf("%d", &a[i]); sort(a + 1, a + (n << 1) + 1); l = 1, r = (n << 1) + 1; while (l < r) mid = l + r >> 1, Check(mid) ? r = mid : l = mid + 1; ans = 0; for (int i = 1, j = l - 1; i < j; ++i, --j) ans = max(ans, a[i] + a[j]); for (int i = l, j = (n << 1); i < j; ++i, --j) ans = max(ans, a[i] + a[j] - m); printf("%d", ans); return 0; }
#include <bits/stdc++.h> #define ci const int & using namespace std; int n, m, a[200010], l, r, mid, ans; bool Check(int x) { if (!(x & 1)) --x; for (int i = x, j = (n << 1); i < j; ++i, --j) if (a[i] + a[j] < m) return 0; return 1; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= (n << 1); ++i) scanf("%d", &a[i]); sort(a + 1, a + (n << 1) + 1); l = 1, r = (n << 1) + 1; while (l < r) mid = l + r >> 1, Check(mid) ? r = mid : l = mid + 1; ans = 0; for (int i = 1, j = l - 1; i < j; ++i, --j) ans = max(ans, a[i] + a[j]); for (int i = l, j = (n << 1); i < j; ++i, --j) ans = max(ans, a[i] + a[j] - m); printf("%d", ans); return 0; }
replace
3
4
3
4
0
p03093
C++
Runtime Error
#pragma GCC optimize(3) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MAXN 100005 #define INF 1000000000 #define MOD 1000000007 #define F first #define S second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> P; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq; int n, m, a[MAXN]; bool check(int x) { int sum = 2 * n + 2 * x + 1; for (int i = 2 * x + 1; i <= sum - i; i++) if (a[i] + a[sum - i] < m) return false; return true; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]); sort(a + 1, a + 2 * n + 1); int l = -1, r = n; while (r - l > 1) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } int ans = 0; int sum1 = 2 * r + 1, sum2 = 2 * n + 2 * r + 1; for (int i = 1; i <= sum1 - i; i++) ans = max(ans, (a[i] + a[sum1 - i]) % m); for (int i = 2 * r + 1; i <= sum2 - i; i++) ans = max(ans, (a[i] + a[sum2 - i]) % m); printf("%d\n", ans); return 0; }
#pragma GCC optimize(3) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MAXN 200005 #define INF 1000000000 #define MOD 1000000007 #define F first #define S second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> P; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq; int n, m, a[MAXN]; bool check(int x) { int sum = 2 * n + 2 * x + 1; for (int i = 2 * x + 1; i <= sum - i; i++) if (a[i] + a[sum - i] < m) return false; return true; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]); sort(a + 1, a + 2 * n + 1); int l = -1, r = n; while (r - l > 1) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid; } int ans = 0; int sum1 = 2 * r + 1, sum2 = 2 * n + 2 * r + 1; for (int i = 1; i <= sum1 - i; i++) ans = max(ans, (a[i] + a[sum1 - i]) % m); for (int i = 2 * r + 1; i <= sum2 - i; i++) ans = max(ans, (a[i] + a[sum2 - i]) % m); printf("%d\n", ans); return 0; }
replace
5
6
5
6
0
p03093
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; int a[100000]; int main() { int n, m, l, r, mid, ans = 0, i, j; scanf("%d %d", &n, &m); for (i = 0; i < n * 2; i++) scanf("%d", &a[i]); sort(a, a + n * 2); l = -1, r = n, mid = (l + r) / 2; while (r - l > 1) { for (i = mid * 2, j = n * 2 - 1; i < j; i++, j--) { if (a[i] + a[j] < m) break; } if (i < j) { l = mid; mid = (l + r) / 2; } else { r = mid; mid = (l + r) / 2; } } for (i = 0, j = r * 2 - 1; i < j; i++, j--) ans = max(ans, a[i] + a[j]); for (i = r * 2, j = n * 2 - 1; i < j; i++, j--) ans = max(ans, a[i] + a[j] - m); printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> using namespace std; int a[200000]; int main() { int n, m, l, r, mid, ans = 0, i, j; scanf("%d %d", &n, &m); for (i = 0; i < n * 2; i++) scanf("%d", &a[i]); sort(a, a + n * 2); l = -1, r = n, mid = (l + r) / 2; while (r - l > 1) { for (i = mid * 2, j = n * 2 - 1; i < j; i++, j--) { if (a[i] + a[j] < m) break; } if (i < j) { l = mid; mid = (l + r) / 2; } else { r = mid; mid = (l + r) / 2; } } for (i = 0, j = r * 2 - 1; i < j; i++, j--) ans = max(ans, a[i] + a[j]); for (i = r * 2, j = n * 2 - 1; i < j; i++, j--) ans = max(ans, a[i] + a[j] - m); printf("%d\n", ans); return 0; }
replace
5
6
5
6
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> PII; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORD(i, a, b) for (int i = (a)-1; i >= (b); --i) #define pb push_back #define mp make_pair #define st first #define nd second const int MOD = 1000000007; int A[111111]; int main() { // ios_base::sync_with_stdio(0); int N, M; scanf("%d%d", &N, &M); N *= 2; REP(i, N) { scanf("%d", &A[i]); } sort(A, A + N); int S = 0; FORD(i, N, 0) { int K = lower_bound(A, A + N, M - A[i]) - A; S = max(S, K - (N - 1 - i)); } S += S % 2; int Z = 0; REP(i, S) Z = max(Z, A[i] + A[S - 1 - i]); FOR(i, S, N) Z = max(Z, A[i] + A[N - 1 - (i - S)] - M); printf("%d\n", Z); }
#include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> PII; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORD(i, a, b) for (int i = (a)-1; i >= (b); --i) #define pb push_back #define mp make_pair #define st first #define nd second const int MOD = 1000000007; int A[211111]; int main() { // ios_base::sync_with_stdio(0); int N, M; scanf("%d%d", &N, &M); N *= 2; REP(i, N) { scanf("%d", &A[i]); } sort(A, A + N); int S = 0; FORD(i, N, 0) { int K = lower_bound(A, A + N, M - A[i]) - A; S = max(S, K - (N - 1 - i)); } S += S % 2; int Z = 0; REP(i, S) Z = max(Z, A[i] + A[S - 1 - i]); FOR(i, S, N) Z = max(Z, A[i] + A[N - 1 - (i - S)] - M); printf("%d\n", Z); }
replace
20
21
20
21
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define eps 1e-5 #define M 100010 #define fi first #define se second #define pb push_back #define LL long long #define MOD 1000000007 #define pii pair<int, int> #define rep(i, x, y) for (int i = (x); i <= (y); ++i) inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline LL llread() { char ch = getchar(); LL x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int a[M], ans, b[M], c[M]; int n, m; inline bool check(int x) { int tot = 0; rep(i, x, n) b[++tot] = a[i] - m; int i1 = 1, i2 = 1; rep(i, 1, n) { if (i1 <= x - 1 && i2 <= tot) { if (a[i1] < b[i2]) c[i] = a[i1], ++i1; else c[i] = b[i2], ++i2; } else if (i1 == x) { c[i] = b[i2], ++i2; } else c[i] = a[i1], ++i1; } ans = 0; rep(i, 1, n / 2) { int x = c[i] + c[n - i + 1]; if (x < 0) return false; ans = max(ans, x); } return true; } int main() { // freopen("a.in","r",stdin); n = read() * 2, m = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); int l = 1, r = n + 1, t = 0; // check(6); while (l <= r) { int mid = (l + r) / 2; if (check(mid)) r = (t = mid) - 1; else l = mid + 1; } check(t); // cerr<<t<<endl; printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; #define eps 1e-5 #define M 200010 #define fi first #define se second #define pb push_back #define LL long long #define MOD 1000000007 #define pii pair<int, int> #define rep(i, x, y) for (int i = (x); i <= (y); ++i) inline int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline LL llread() { char ch = getchar(); LL x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int a[M], ans, b[M], c[M]; int n, m; inline bool check(int x) { int tot = 0; rep(i, x, n) b[++tot] = a[i] - m; int i1 = 1, i2 = 1; rep(i, 1, n) { if (i1 <= x - 1 && i2 <= tot) { if (a[i1] < b[i2]) c[i] = a[i1], ++i1; else c[i] = b[i2], ++i2; } else if (i1 == x) { c[i] = b[i2], ++i2; } else c[i] = a[i1], ++i1; } ans = 0; rep(i, 1, n / 2) { int x = c[i] + c[n - i + 1]; if (x < 0) return false; ans = max(ans, x); } return true; } int main() { // freopen("a.in","r",stdin); n = read() * 2, m = read(); rep(i, 1, n) a[i] = read(); sort(a + 1, a + n + 1); int l = 1, r = n + 1, t = 0; // check(6); while (l <= r) { int mid = (l + r) / 2; if (check(mid)) r = (t = mid) - 1; else l = mid + 1; } check(t); // cerr<<t<<endl; printf("%d\n", ans); }
replace
3
4
3
4
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200005; const ll inf = 0x3f3f3f3f3f3f3f3fll; int read() { int f = 1, g = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) g = g * 10 + ch - '0'; return f * g; } int n, m, a[N]; int check(int mid) { int t = 0; for (int i = 1; i <= mid; i++) t = max(t, a[i] + a[mid * 2 - i + 1]); for (int i = 1; i + mid <= n; i++) if (a[i + mid * 2] + a[n * 2 - i + 1] < m) return -1; else t = max(t, a[i] + a[mid * 2 - i + 1] - m); return t; } int main() { n = read(); m = read(); for (int i = 1; i <= n * 2; i++) a[i] = read(); sort(a + 1, a + n * 2 + 1); int l = 0, r = n, mid; while (l != r) { mid = (l + r) >> 1; if (check(mid) >= 0) r = mid; else l = mid + 1; } printf("%d\n", check(l)); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200005; const ll inf = 0x3f3f3f3f3f3f3f3fll; int read() { int f = 1, g = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) g = g * 10 + ch - '0'; return f * g; } int n, m, a[N]; int check(int mid) { int t = 0; for (int i = 1; i <= mid; i++) t = max(t, a[i] + a[mid * 2 - i + 1]); for (int i = 1; i + mid <= n; i++) if (a[i + mid * 2] + a[n * 2 - i + 1] < m) return -1; else t = max(t, a[i + mid * 2] + a[n * 2 - i + 1] - m); return t; } int main() { n = read(); m = read(); for (int i = 1; i <= n * 2; i++) a[i] = read(); sort(a + 1, a + n * 2 + 1); int l = 0, r = n, mid; while (l != r) { mid = (l + r) >> 1; if (check(mid) >= 0) r = mid; else l = mid + 1; } printf("%d\n", check(l)); return 0; }
replace
24
25
24
25
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> a; int n, M; int Q(int k) { int f = -1; for (int i = 0; i < k; i++) { f = max(f, a[i] + a[2 * k - 1 - i]); } for (int i = 0; i < (n - k); i++) { int r = a[2 * k + i] + a[2 * n - 1 - i]; if (r < M) return -1; f = max(f, r - M); } assert(f < M); return f; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> M; a.resize(2 * n); for (int i = 0; i < 2 * n; i++) cin >> a[i]; sort(a.begin(), a.end()); int s = -1; // not int e = n; // fine while (s + 1 < e) { int m = (s + e) / 2; if (Q(m) == -1) { s = m; } else { e = m; } } s++; e = n; int ans = M; ans = min(ans, Q(e)); ans = min(ans, Q(s)); while (s + 3 < e) { int m1 = (s + s + e) / 3; int m2 = (s + e + e) / 3; if (Q(m1) <= Q(m2)) { e = m2; } else { s = m1; } } for (int m = s; m <= e; m++) { ans = min(Q(m), ans); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> a; int n, M; int Q(int k) { int f = -1; for (int i = 0; i < k; i++) { f = max(f, (a[i] + a[2 * k - 1 - i]) % M); } for (int i = 0; i < (n - k); i++) { int r = a[2 * k + i] + a[2 * n - 1 - i]; if (r < M) return -1; f = max(f, r - M); } assert(f < M); return f; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> M; a.resize(2 * n); for (int i = 0; i < 2 * n; i++) cin >> a[i]; sort(a.begin(), a.end()); int s = -1; // not int e = n; // fine while (s + 1 < e) { int m = (s + e) / 2; if (Q(m) == -1) { s = m; } else { e = m; } } s++; e = n; int ans = M; ans = min(ans, Q(e)); ans = min(ans, Q(s)); while (s + 3 < e) { int m1 = (s + s + e) / 3; int m2 = (s + e + e) / 3; if (Q(m1) <= Q(m2)) { e = m2; } else { s = m1; } } for (int m = s; m <= e; m++) { ans = min(Q(m), ans); } cout << ans << endl; }
replace
10
11
10
11
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for ((i) = 1; (i) <= (n); (i)++) using namespace std; int n, m, i, j, a[100005], l, r, mid, ans, res; bool check(int x) { int i, j; for (i = 2 * x + 1, j = n * 2; i <= j; i++, j--) { if (a[i] + a[j] < m) return 0; } return 1; } int main() { cin >> n >> m; rep(i, n + n) cin >> a[i]; sort(a + 1, a + n + n + 1); l = -1; r = n; ans = n + 1; while (l < r) { mid = (l + r + 1) / 2; if (check(mid)) { r = mid - 1; ans = mid; } else { l = mid; } } for (i = 1, j = ans * 2; i <= j; i++, j--) { res = max(res, a[i] + a[j]); } for (i = ans * 2 + 1, j = n * 2; i <= j; i++, j--) { res = max(res, a[i] + a[j] - m); } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for ((i) = 1; (i) <= (n); (i)++) using namespace std; int n, m, i, j, a[200005], l, r, mid, ans, res; bool check(int x) { int i, j; for (i = 2 * x + 1, j = n * 2; i <= j; i++, j--) { if (a[i] + a[j] < m) return 0; } return 1; } int main() { cin >> n >> m; rep(i, n + n) cin >> a[i]; sort(a + 1, a + n + n + 1); l = -1; r = n; ans = n + 1; while (l < r) { mid = (l + r + 1) / 2; if (check(mid)) { r = mid - 1; ans = mid; } else { l = mid; } } for (i = 1, j = ans * 2; i <= j; i++, j--) { res = max(res, a[i] + a[j]); } for (i = ans * 2 + 1, j = n * 2; i <= j; i++, j--) { res = max(res, a[i] + a[j] - m); } cout << res << endl; return 0; }
replace
3
4
3
4
0
p03093
C++
Runtime Error
// E.cpp #include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 200; int n, m, ai[MAX_N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &ai[i]); sort(ai + 1, ai + 1 + 2 * n); int l = 0, r = n, res; while (l <= r) { int mid = (l + r) >> 1; bool valid = true; for (int i = 2 * mid + 1; i <= (n << 1); i++) if (ai[i] + ai[2 * n + 2 * mid + 1 - i] < m) { valid = false; break; } if (valid) r = mid - 1, res = mid; else l = mid + 1; } int pos = res << 1; int ans = 0; for (int i = 1; i <= pos; i++) ans = max(ans, ai[i] + ai[pos - i + 1]); for (int i = pos + 1; i <= (n << 1); i++) ans = max(ans, (ai[i] + ai[(n << 1) + pos - i + 1]) % m); printf("%lld\n", ans); return 0; }
// E.cpp #include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 200; int n, m, ai[MAX_N]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &ai[i]); sort(ai + 1, ai + 1 + 2 * n); int l = 0, r = n, res; while (l <= r) { int mid = (l + r) >> 1; bool valid = true; for (int i = 2 * mid + 1; i <= (n << 1); i++) if (ai[i] + ai[2 * n + 2 * mid + 1 - i] < m) { valid = false; break; } if (valid) r = mid - 1, res = mid; else l = mid + 1; } int pos = res << 1; int ans = 0; for (int i = 1; i <= pos; i++) ans = max(ans, ai[i] + ai[pos - i + 1]); for (int i = pos + 1; i <= (n << 1); i++) ans = max(ans, (ai[i] + ai[(n << 1) + pos - i + 1]) % m); printf("%lld\n", ans); return 0; }
replace
5
6
5
6
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11; int n, mod; int a[N]; bool check(int pos) { int l = pos + 1, r = 2 * n; while (l <= r) { if (a[l] + a[r] < mod) return 0; l++; r--; } return 1; } int main() { cin >> n >> mod; for (int i = 1; i <= n + n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + 1 + n + n); int l = 0, r = n, ans = n; while (l <= r) { int mid = l + r >> 1; if (check(mid << 1)) r = mid - 1, ans = min(ans, mid); else l = mid + 1; } l = 1, r = 2 * ans; int Z = 0; while (l <= r) { Z = max(Z, a[l] + a[r]); l++; r--; } l = 2 * ans + 1; r = 2 * n; while (l <= r) { Z = max(Z, a[l] + a[r] - mod); l++; r--; } // printf("ans=%d Z=%d\n", ans * 2, Z); cout << Z << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 11; int n, mod; int a[N]; bool check(int pos) { int l = pos + 1, r = 2 * n; while (l <= r) { if (a[l] + a[r] < mod) return 0; l++; r--; } return 1; } int main() { cin >> n >> mod; for (int i = 1; i <= n + n; i++) { scanf("%d", &a[i]); } sort(a + 1, a + 1 + n + n); int l = 0, r = n, ans = n; while (l <= r) { int mid = l + r >> 1; if (check(mid << 1)) r = mid - 1, ans = min(ans, mid); else l = mid + 1; } l = 1, r = 2 * ans; int Z = 0; while (l <= r) { Z = max(Z, a[l] + a[r]); l++; r--; } l = 2 * ans + 1; r = 2 * n; while (l <= r) { Z = max(Z, a[l] + a[r] - mod); l++; r--; } // printf("ans=%d Z=%d\n", ans * 2, Z); cout << Z << endl; return 0; }
replace
2
3
2
3
0
p03093
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define LL long long #define fgx cerr << "--------------" << endl; #define dgx cerr << "==============" << endl; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 100010; const int INF = 2147483600; int N, M; int a[MAXN + 1]; inline bool check(int x) { for (int i = 1; i <= N - x; i++) { if (a[i + x] + a[N - i + 1] < M) return 0; } return 1; } inline int calc(int x) { int ans = 0; for (int i = 1; i <= x; i++) { if (a[i] + a[x - i + 1] >= M) return INF; ans = max(ans, a[i] + a[x - i + 1]); } for (int i = 1; i <= N - x; i++) { if (a[x + i] + a[N - i + 1] < M) return INF; ans = max(ans, a[x + i] + a[N - i + 1] - M); } return ans; } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); N = read(); M = read(); N <<= 1; for (int i = 1; i <= N; i++) a[i] = read(); sort(a + 1, a + N + 1); int l = 0, r = N / 2, pos = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid * 2)) pos = mid * 2, r = mid - 1; else l = mid + 1; } printf("%d\n", min(calc(pos), min(calc(0), calc(N)))); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define LL long long #define fgx cerr << "--------------" << endl; #define dgx cerr << "==============" << endl; inline int read() { int x = 0, f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return x * f; } const int MAXN = 300010; const int INF = 2147483600; int N, M; int a[MAXN + 1]; inline bool check(int x) { for (int i = 1; i <= N - x; i++) { if (a[i + x] + a[N - i + 1] < M) return 0; } return 1; } inline int calc(int x) { int ans = 0; for (int i = 1; i <= x; i++) { if (a[i] + a[x - i + 1] >= M) return INF; ans = max(ans, a[i] + a[x - i + 1]); } for (int i = 1; i <= N - x; i++) { if (a[x + i] + a[N - i + 1] < M) return INF; ans = max(ans, a[x + i] + a[N - i + 1] - M); } return ans; } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); N = read(); M = read(); N <<= 1; for (int i = 1; i <= N; i++) a[i] = read(); sort(a + 1, a + N + 1); int l = 0, r = N / 2, pos = 0; while (l <= r) { int mid = (l + r) >> 1; if (check(mid * 2)) pos = mid * 2, r = mid - 1; else l = mid + 1; } printf("%d\n", min(calc(pos), min(calc(0), calc(N)))); return 0; }
replace
22
23
22
23
0
p03093
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #define FOF(i, a, b) for (int i = a; i < b; i++) using namespace std; const int N = 100100; int n, m, w, T, L, R, mi, mx, a[N]; int cal(int x, int y) { return a[x] - (x >= y) * m; } bool chk(int x) { int y = x + n; x <<= 1; mx = 0; mi = m; FOF(i, 0, T) { w = cal(i, y) + cal((x - 1 - i + T) % T, y); mx = max(mx, w); mi = min(mi, w); } return mi >= 0; } int main() { // freopen("1.in","r",stdin); scanf("%d%d", &n, &m); T = n << 1; FOF(i, 0, T) scanf("%d", &a[i]); sort(a, a + T); L = 0, R = n; while (L < R) { int md = (L + R) >> 1; chk(md) ? R = md : L = md + 1; } chk(L); cout << mx << '\n'; }
#include <algorithm> #include <cstdio> #include <iostream> #define FOF(i, a, b) for (int i = a; i < b; i++) using namespace std; const int N = 200200; int n, m, w, T, L, R, mi, mx, a[N]; int cal(int x, int y) { return a[x] - (x >= y) * m; } bool chk(int x) { int y = x + n; x <<= 1; mx = 0; mi = m; FOF(i, 0, T) { w = cal(i, y) + cal((x - 1 - i + T) % T, y); mx = max(mx, w); mi = min(mi, w); } return mi >= 0; } int main() { // freopen("1.in","r",stdin); scanf("%d%d", &n, &m); T = n << 1; FOF(i, 0, T) scanf("%d", &a[i]); sort(a, a + T); L = 0, R = n; while (L < R) { int md = (L + R) >> 1; chk(md) ? R = md : L = md + 1; } chk(L); cout << mx << '\n'; }
replace
5
6
5
6
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mp make_pair #define Fast_IO ios::sync_with_stdio(false); #define DEBUG \ fprintf(stderr, "Running on Line %d in Function %s\n", __LINE__, __FUNCTION__) // mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define fir first #define sec second #define mod 998244353 #define ll long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans; } typedef pair<int, int> pii; void print(vector<int> x) { for (int i = 0; i < (int)x.size(); i++) printf("%d%c", x[i], " \n"[i == (int)x.size() - 1]); } #define N 100005 int a[N], b[N], n, m; bool chk(int mid) { for (int i = 1; i <= mid; i++) b[i] = a[i]; for (int i = mid + 1; i <= n; i++) b[i] = a[i] - m; sort(b + 1, b + n + 1); for (int i = 1; i <= n / 2; i++) { if (b[i] + b[n - i + 1] < 0) return 0; } return 1; } signed main() { cin >> n >> m; n *= 2; for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); int l = 1, r = n + 1, ans; while (l <= r) { int mid = (l + r) / 2; if (chk(mid)) ans = mid, r = mid - 1; else l = mid + 1; } for (int i = 1; i <= ans; i++) b[i] = a[i]; for (int i = ans + 1; i <= n; i++) b[i] = a[i] - m; sort(b + 1, b + n + 1); ans = 0; for (int i = 1; i <= n / 2; i++) ans = max(ans, (b[i] + b[n - i + 1]) % m); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mp make_pair #define Fast_IO ios::sync_with_stdio(false); #define DEBUG \ fprintf(stderr, "Running on Line %d in Function %s\n", __LINE__, __FUNCTION__) // mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define fir first #define sec second #define mod 998244353 #define ll long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans; } typedef pair<int, int> pii; void print(vector<int> x) { for (int i = 0; i < (int)x.size(); i++) printf("%d%c", x[i], " \n"[i == (int)x.size() - 1]); } #define N 200005 int a[N], b[N], n, m; bool chk(int mid) { for (int i = 1; i <= mid; i++) b[i] = a[i]; for (int i = mid + 1; i <= n; i++) b[i] = a[i] - m; sort(b + 1, b + n + 1); for (int i = 1; i <= n / 2; i++) { if (b[i] + b[n - i + 1] < 0) return 0; } return 1; } signed main() { cin >> n >> m; n *= 2; for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1); int l = 1, r = n + 1, ans; while (l <= r) { int mid = (l + r) / 2; if (chk(mid)) ans = mid, r = mid - 1; else l = mid + 1; } for (int i = 1; i <= ans; i++) b[i] = a[i]; for (int i = ans + 1; i <= n; i++) b[i] = a[i] - m; sort(b + 1, b + n + 1); ans = 0; for (int i = 1; i <= n / 2; i++) ans = max(ans, (b[i] + b[n - i + 1]) % m); cout << ans << endl; return 0; }
replace
37
38
37
38
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) using namespace std; const int N = 100005, INF = 0X3F3F3F3F; int n, P, a[N], b[N], ans = INF; bool chk(int mid) { rep(i, 1, n) b[i] = a[i] - (i >= n - mid + 1) * P; inplace_merge(b + 1, b + n - mid + 1, b + 1 + n); int mx = 0; rep(i, 1, (n + 1) / 2) { if (b[i] + b[n + 1 - i] < 0) return 0; mx = max(mx, b[i] + b[n + 1 - i]); } /*printf("%d:",mid); rep(i,1,n)printf("%d ",b[i]); puts("");*/ ans = min(ans, mx); return 1; } int main() { scanf("%d%d", &n, &P); n *= 2; rep(i, 1, n) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int l = 0, r = n; while (l <= r) { int mid = (l + r) >> 1; if (chk(mid)) l = mid + 1; else r = mid - 1; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) using namespace std; const int N = 200005, INF = 0X3F3F3F3F; int n, P, a[N], b[N], ans = INF; bool chk(int mid) { rep(i, 1, n) b[i] = a[i] - (i >= n - mid + 1) * P; inplace_merge(b + 1, b + n - mid + 1, b + 1 + n); int mx = 0; rep(i, 1, (n + 1) / 2) { if (b[i] + b[n + 1 - i] < 0) return 0; mx = max(mx, b[i] + b[n + 1 - i]); } /*printf("%d:",mid); rep(i,1,n)printf("%d ",b[i]); puts("");*/ ans = min(ans, mx); return 1; } int main() { scanf("%d%d", &n, &P); n *= 2; rep(i, 1, n) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int l = 0, r = n; while (l <= r) { int mid = (l + r) >> 1; if (chk(mid)) l = mid + 1; else r = mid - 1; } printf("%d\n", ans); return 0; }
replace
3
4
3
4
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int N, M; int a[500005]; bool check1(int Now) { int L = 1, R = Now; while (a[L] + a[R] < M && L < R) L++, R--; if (a[L] + a[R] >= M) return false; return true; } bool check2(int Now) { int L = Now + 1, R = N; while (a[L] + a[R] >= M && L < R) L++, R--; if (a[L] + a[R] < M) return false; return true; } int main() { scanf("%d%d", &N, &M); N *= 2; for (int i = 1; i <= N; i++) scanf("%d", &a[i]); sort(a + 1, a + N + 1); int l = 0, r = N, ans; while (l <= r) { int mid = (l + r) >> 1; if (check2(mid) && check1(mid)) r = mid - 1, ans = mid; else if (!check1(mid)) r = mid - 1; else l = mid + 1; } if (ans % 2) ans++; int L = ans + 1, R = N, anss = 0; while (L <= R) anss = max((a[L] + a[R]) % M, anss), L++, R--; L = 1, R = anss; while (L <= R) anss = max((a[L] + a[R]) % M, anss), L++, R--; printf("%d", anss); return 0; }
#include <bits/stdc++.h> using namespace std; int N, M; int a[500005]; bool check1(int Now) { int L = 1, R = Now; while (a[L] + a[R] < M && L < R) L++, R--; if (a[L] + a[R] >= M) return false; return true; } bool check2(int Now) { int L = Now + 1, R = N; while (a[L] + a[R] >= M && L < R) L++, R--; if (a[L] + a[R] < M) return false; return true; } int main() { scanf("%d%d", &N, &M); N *= 2; for (int i = 1; i <= N; i++) scanf("%d", &a[i]); sort(a + 1, a + N + 1); int l = 0, r = N, ans; while (l <= r) { int mid = (l + r) >> 1; if (check2(mid) && check1(mid)) r = mid - 1, ans = mid; else if (!check1(mid)) r = mid - 1; else l = mid + 1; } if (ans % 2) ans++; int L = ans + 1, R = N, anss = 0; while (L <= R) anss = max((a[L] + a[R]) % M, anss), L++, R--; L = 1, R = ans; while (L <= R) anss = max((a[L] + a[R]) % M, anss), L++, R--; printf("%d", anss); return 0; }
replace
41
42
41
42
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> #include <stdio.h> #define maxn 100005 using namespace std; int n, m, a[maxn]; int judge(int x) { for (int i = 2 * x + 1, j = 1; i <= 2 * n; i++, j++) if (a[i] + a[2 * n - j + 1] < m) return 0; return 1; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]); sort(a + 1, a + 2 * n + 1); int l = 0, r = n, pos; while (l <= r) { int mid = (l + r) >> 1; if (judge(mid)) pos = mid, r = mid - 1; else l = mid + 1; } int ans = 0; for (int i = 1; i <= pos; i++) ans = max(ans, a[i] + a[2 * pos - i + 1]); for (int i = 2 * pos + 1, j = 1; i <= 2 * n; i++, j++) ans = max(ans, a[i] + a[2 * n - j + 1] - m); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #include <stdio.h> #define maxn 200005 using namespace std; int n, m, a[maxn]; int judge(int x) { for (int i = 2 * x + 1, j = 1; i <= 2 * n; i++, j++) if (a[i] + a[2 * n - j + 1] < m) return 0; return 1; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= 2 * n; i++) scanf("%d", &a[i]); sort(a + 1, a + 2 * n + 1); int l = 0, r = n, pos; while (l <= r) { int mid = (l + r) >> 1; if (judge(mid)) pos = mid, r = mid - 1; else l = mid + 1; } int ans = 0; for (int i = 1; i <= pos; i++) ans = max(ans, a[i] + a[2 * pos - i + 1]); for (int i = 2 * pos + 1, j = 1; i <= 2 * n; i++, j++) ans = max(ans, a[i] + a[2 * n - j + 1] - m); printf("%d\n", ans); return 0; }
replace
2
3
2
3
0
p03093
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, mod, a[N]; int calcmin(int l, int r) { int Min = mod << 1; for (int _l = l, _r = r; _l <= _r; _l++, _r--) { // printf("__ %d %d %d [%d\n",_l,_r,a[_l]+a[_r],Min); Min = min(Min, a[_l] + a[_r]); } return Min; } int main() { scanf("%d%d", &n, &mod); n <<= 1; for (int i = 1; i <= n; i++) { scanf("%d", a + i); } sort(a + 1, a + 1 + n); int l = 0, r = (n >> 1) - 1, pos = n << 1 | 1; // pos - n while (l <= r) { int mid = l + r >> 1; // printf("[] %d %d\n",mid<<1|1,calcmin(mid<<1|1,n)); if (calcmin(mid << 1 | 1, n) >= mod) { pos = mid << 1 | 1; r = mid - 1; } else { l = mid + 1; } } // printf("__ %d\n",pos); int res = 0; for (int i = 1; i <= pos - 1; i++) { res = max(res, a[i] + a[pos - i]); } for (int i = pos; i <= n; i++) { // printf("%d %d %d\n",n+pos,i,n+pos-i); res = max(res, (a[i] + a[n + pos - i]) % mod); } cout << res; return 0; } /* 3 10 0 2 3 4 5 9 */
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, mod, a[N]; int calcmin(int l, int r) { int Min = mod << 1; for (int _l = l, _r = r; _l <= _r; _l++, _r--) { // printf("__ %d %d %d [%d\n",_l,_r,a[_l]+a[_r],Min); Min = min(Min, a[_l] + a[_r]); } return Min; } int main() { scanf("%d%d", &n, &mod); n <<= 1; for (int i = 1; i <= n; i++) { scanf("%d", a + i); } sort(a + 1, a + 1 + n); int l = 0, r = (n >> 1) - 1, pos = n | 1; // pos - n while (l <= r) { int mid = l + r >> 1; // printf("[] %d %d\n",mid<<1|1,calcmin(mid<<1|1,n)); if (calcmin(mid << 1 | 1, n) >= mod) { pos = mid << 1 | 1; r = mid - 1; } else { l = mid + 1; } } // printf("__ %d\n",pos); int res = 0; for (int i = 1; i <= pos - 1; i++) { res = max(res, a[i] + a[pos - i]); } for (int i = pos; i <= n; i++) { // printf("%d %d %d\n",n+pos,i,n+pos-i); res = max(res, (a[i] + a[n + pos - i]) % mod); } cout << res; return 0; } /* 3 10 0 2 3 4 5 9 */
replace
24
25
24
25
0
p03093
C++
Runtime Error
#include <algorithm> #include <cstdio> const int MN = 100005; int N, M, A[MN], Ans; inline bool check(int pos) { int Now = 0; for (int i = 1; i <= pos; ++i) Now = std::max(Now, A[i] + A[2 * pos - i + 1]); for (int i = 1; i <= N - pos; ++i) { int v = A[2 * pos + i] + A[2 * N - i + 1]; if (v < M) return 0; Now = std::max(Now, v - M); } Ans = std::min(Ans, Now); return 1; } int main() { scanf("%d%d", &N, &M), Ans = M; for (int i = 1; i <= 2 * N; ++i) scanf("%d", &A[i]); std::sort(A + 1, A + 2 * N + 1); int l = 0, r = N, mid; while (l <= r) { mid = (l + r) >> 1; if (check(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n", Ans); return 0; }
#include <algorithm> #include <cstdio> const int MN = 200005; int N, M, A[MN], Ans; inline bool check(int pos) { int Now = 0; for (int i = 1; i <= pos; ++i) Now = std::max(Now, A[i] + A[2 * pos - i + 1]); for (int i = 1; i <= N - pos; ++i) { int v = A[2 * pos + i] + A[2 * N - i + 1]; if (v < M) return 0; Now = std::max(Now, v - M); } Ans = std::min(Ans, Now); return 1; } int main() { scanf("%d%d", &N, &M), Ans = M; for (int i = 1; i <= 2 * N; ++i) scanf("%d", &A[i]); std::sort(A + 1, A + 2 * N + 1); int l = 0, r = N, mid; while (l <= r) { mid = (l + r) >> 1; if (check(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n", Ans); return 0; }
replace
3
4
3
4
0
p03094
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <vector> #define LL long long #define LD long double using namespace std; const int NN = 1000000 + 117; const int MM = 1000000 + 117; int read() { int fl = 1, x; char c; for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar()) ; if (c == '-') { fl = -1; c = getchar(); } for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0'; return x * fl; } void open() { freopen("a.in", "r", stdin); // freopen("a.out","w",stdout); } void close() { fclose(stdin); fclose(stdout); } LL n; const int mod = 1e9 + 7; LL ksm(LL a, LL b) { LL ret = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ret = ret * a % mod; return ret; } LL p[NN] = {}; LL fact[2 * NN] = {}; LL rev[2 * NN] = {}; LL comp(int n, int m) { return fact[n] * rev[m] % mod * rev[n - m] % mod; } LL prefact(int n) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i % mod; rev[n] = ksm(fact[n], mod - 2); for (int i = n; i >= 1; --i) rev[i - 1] = rev[i] * i % mod; } int main() { open(); n = read(); prefact(n); LL ans = 0; LL di = ksm(3, n - 1); di = ksm(di, mod - 2); LL len = ksm(3 * n, mod - 2); for (int i = 2; i <= n + 1; ++i) { if (i == 2) p[i] = di; else p[i] = (p[i - 1] + p[i - 2] * 2) % mod; LL res = p[i] * comp(n, i - 1) % mod; res = res * len % mod * fact[i - 2] % mod * rev[i - 1] % mod; ans = (ans + res) % mod; } printf("%lld\n", ans); close(); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <vector> #define LL long long #define LD long double using namespace std; const int NN = 1000000 + 117; const int MM = 1000000 + 117; int read() { int fl = 1, x; char c; for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar()) ; if (c == '-') { fl = -1; c = getchar(); } for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0'; return x * fl; } void open() { freopen("a.in", "r", stdin); // freopen("a.out","w",stdout); } void close() { fclose(stdin); fclose(stdout); } LL n; const int mod = 1e9 + 7; LL ksm(LL a, LL b) { LL ret = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) ret = ret * a % mod; return ret; } LL p[NN] = {}; LL fact[2 * NN] = {}; LL rev[2 * NN] = {}; LL comp(int n, int m) { return fact[n] * rev[m] % mod * rev[n - m] % mod; } LL prefact(int n) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i % mod; rev[n] = ksm(fact[n], mod - 2); for (int i = n; i >= 1; --i) rev[i - 1] = rev[i] * i % mod; } int main() { // open(); n = read(); prefact(n); LL ans = 0; LL di = ksm(3, n - 1); di = ksm(di, mod - 2); LL len = ksm(3 * n, mod - 2); for (int i = 2; i <= n + 1; ++i) { if (i == 2) p[i] = di; else p[i] = (p[i - 1] + p[i - 2] * 2) % mod; LL res = p[i] * comp(n, i - 1) % mod; res = res * len % mod * fact[i - 2] % mod * rev[i - 1] % mod; ans = (ans + res) % mod; } printf("%lld\n", ans); close(); return 0; }
replace
57
58
57
58
TLE
p03094
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long template <class T> inline void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } const int N = 1e5 + 10, mod = 1e9 + 7; int n, ans, f[N], g[N][3], fc[N], fi[N], vi[N]; inline int inc(int a, int b) { return (a += b) >= mod ? a - mod : a; } inline int binom(int n, int m) { return (ll)fc[n] * fi[m] % mod * fi[n - m] % mod; } inline int fpow(int a, int b) { int s = 1; for (; b; b >>= 1, a = (ll)a * a % mod) if (b & 1) s = (ll)s * a % mod; return s; } int main() { std::cin >> n; g[1][0] = fi[0] = fi[1] = vi[0] = vi[1] = fc[0] = fc[1] = 1; for (int i = 2; i <= n; i++) fc[i] = (ll)fc[i - 1] * i % mod; for (int i = 2; i <= n; i++) vi[i] = (ll)(mod - mod / i) * vi[mod % i] % mod; for (int i = 2; i <= n; i++) fi[i] = (ll)fi[i - 1] * vi[i] % mod; for (int i = 2; i <= n + 1; i++) { g[i][0] = inc(g[i - 1][1], g[i - 1][2]); g[i][1] = inc(g[i - 1][0], g[i - 1][2]); g[i][2] = inc(g[i - 1][0], g[i - 1][1]); // printf("> %d %d %d\n",g[i][0],g[i][1],g[i][2]); } for (int i = 1; i <= n; i++) f[i] = (ll)g[i + 1][1] * binom(n, i) % mod; for (int i = 1; i <= n; i++) ans = (ans + (ll)f[i] * vi[i]) % mod; // for(int i=1;i<=n;i++)std::cout<<f[i]<<" \n"[i==n]; // std::cout<<ans<<std::endl; std::cout << (ll)ans * fpow((ll)n * fpow(3, n) % mod, mod - 2) % mod << std::endl; }
#include <bits/stdc++.h> #define ll long long template <class T> inline void read(T &x) { x = 0; register char c = getchar(); register bool f = 0; while (!isdigit(c)) f ^= c == '-', c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); if (f) x = -x; } const int N = 1e6 + 10, mod = 1e9 + 7; int n, ans, f[N], g[N][3], fc[N], fi[N], vi[N]; inline int inc(int a, int b) { return (a += b) >= mod ? a - mod : a; } inline int binom(int n, int m) { return (ll)fc[n] * fi[m] % mod * fi[n - m] % mod; } inline int fpow(int a, int b) { int s = 1; for (; b; b >>= 1, a = (ll)a * a % mod) if (b & 1) s = (ll)s * a % mod; return s; } int main() { std::cin >> n; g[1][0] = fi[0] = fi[1] = vi[0] = vi[1] = fc[0] = fc[1] = 1; for (int i = 2; i <= n; i++) fc[i] = (ll)fc[i - 1] * i % mod; for (int i = 2; i <= n; i++) vi[i] = (ll)(mod - mod / i) * vi[mod % i] % mod; for (int i = 2; i <= n; i++) fi[i] = (ll)fi[i - 1] * vi[i] % mod; for (int i = 2; i <= n + 1; i++) { g[i][0] = inc(g[i - 1][1], g[i - 1][2]); g[i][1] = inc(g[i - 1][0], g[i - 1][2]); g[i][2] = inc(g[i - 1][0], g[i - 1][1]); // printf("> %d %d %d\n",g[i][0],g[i][1],g[i][2]); } for (int i = 1; i <= n; i++) f[i] = (ll)g[i + 1][1] * binom(n, i) % mod; for (int i = 1; i <= n; i++) ans = (ans + (ll)f[i] * vi[i]) % mod; // for(int i=1;i<=n;i++)std::cout<<f[i]<<" \n"[i==n]; // std::cout<<ans<<std::endl; std::cout << (ll)ans * fpow((ll)n * fpow(3, n) % mod, mod - 2) % mod << std::endl; }
replace
13
14
13
14
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; int count[26] = {}; cin >> N; cin >> S; for (int i = 0; i < N; i++) { count[S[i] - 'a']++; } long long int ans = 1; for (int i = 0; i < N; i++) { ans *= count[i] + 1; ans %= 1000000007; } cout << ans - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; int count[26] = {}; cin >> N; cin >> S; for (int i = 0; i < N; i++) { count[S[i] - 'a']++; } long long int ans = 1; for (int i = 0; i < 26; i++) { ans *= count[i] + 1; ans %= 1000000007; } cout << ans - 1 << endl; return 0; }
replace
16
17
16
17
0
p03095
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; const long long mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i < n; i++) #define rep2(i, x, n) for (int i = x; i < n; i++) #define all(v) v.begin(), v.end() #define nepe(v) next_permutation(all(v)) #define F first #define S second #define PB push_back #define MP make_pair using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<long long>; using vvl = vector<vl>; using vp = vector<pair<int, int>>; typedef pair<int, int> P; string s; int k; ll INF = 10000000000000000; int main() { int N; string S; cin >> N >> S; vi abc(26, 0); rep(i, N) { abc[S[i] - 'a']++; } ll ans = 1; rep(i, N) { ans = ans * (abc[i] + 1); ans %= mod; } cout << ans - 1 << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; const long long mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i < n; i++) #define rep2(i, x, n) for (int i = x; i < n; i++) #define all(v) v.begin(), v.end() #define nepe(v) next_permutation(all(v)) #define F first #define S second #define PB push_back #define MP make_pair using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<long long>; using vvl = vector<vl>; using vp = vector<pair<int, int>>; typedef pair<int, int> P; string s; int k; ll INF = 10000000000000000; int main() { int N; string S; cin >> N >> S; vi abc(26, 0); rep(i, N) { abc[S[i] - 'a']++; } ll ans = 1; rep(i, 26) { ans *= abc[i] + 1; ans %= mod; } cout << ans - 1 << endl; }
replace
42
44
42
44
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; int main() { int n; string s; cin >> n >> s; ll ans = 1; vector<ll> al(26, 0); for (int i = 0; i < n; i++) { al[s[i] - 'a']++; } for (int i = 0; i < n; i++) { ans *= (al[i] + 1); ans %= MOD; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1e9 + 7; int main() { int n; string s; cin >> n >> s; ll ans = 1; vector<ll> al(26, 0); for (int i = 0; i < n; i++) { al[s[i] - 'a']++; } for (int i = 0; i < 26; i++) { ans *= (al[i] + 1); ans %= MOD; } cout << ans - 1 << endl; }
replace
14
15
14
15
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; string S; cin >> N >> S; vector<int> count(26); for (int i = 0; i < N; i++) { count.at((int)(S.at(i) - 'a'))++; } ll ans = 1; int div = 1000000007; for (int i = 0; i < N; i++) { ans *= count.at(i) + 1; ans %= div; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; string S; cin >> N >> S; vector<int> count(26); for (int i = 0; i < N; i++) { count.at((int)(S.at(i) - 'a'))++; } ll ans = 1; int div = 1000000007; for (int i = 0; i < 26; i++) { ans *= count.at(i) + 1; ans %= div; } cout << ans - 1 << endl; }
replace
20
21
20
21
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const ll Mod = 1e9 + 7; ll Cnt[26]; int main() { ll n; cin >> n; string s; cin >> s; for (ll i = 0; i < n; i++) Cnt[s[i] - 'a']++; ll Ans = 1; for (ll i = 0; i < n; i++) Ans = (Ans * (Cnt[i] + 1)) % Mod; cout << (Ans - 1 + Mod) % Mod; }
#include <bits/stdc++.h> #define ll long long using namespace std; const ll Mod = 1e9 + 7; ll Cnt[26]; int main() { ll n; cin >> n; string s; cin >> s; for (ll i = 0; i < n; i++) Cnt[s[i] - 'a']++; ll Ans = 1; for (ll i = 0; i < 26; i++) Ans = (Ans * (Cnt[i] + 1)) % Mod; cout << (Ans - 1 + Mod) % Mod; }
replace
20
21
20
21
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define llong long long #define mkpr make_pair #define riterator reverse_iterator using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') f = -1; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + ch - 48; } return x * f; } const int N = 1e5; const int S = 26; const int P = 1e9 + 7; char a[N + 3]; int cnt[S + 3]; int n; int main() { scanf("%d%s", &n, a + 1); for (int i = 1; i <= n; i++) cnt[a[i] - 96]++; llong ans = 1ll; for (int i = 1; i <= n; i++) ans = ans * (cnt[i] + 1ll) % P; ans = (ans - 1 + P) % P; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define llong long long #define mkpr make_pair #define riterator reverse_iterator using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == '-') f = -1; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + ch - 48; } return x * f; } const int N = 1e5; const int S = 26; const int P = 1e9 + 7; char a[N + 3]; int cnt[S + 3]; int n; int main() { scanf("%d%s", &n, a + 1); for (int i = 1; i <= n; i++) cnt[a[i] - 96]++; llong ans = 1ll; for (int i = 1; i <= S; i++) ans = ans * (cnt[i] + 1ll) % P; ans = (ans - 1 + P) % P; printf("%lld\n", ans); return 0; }
replace
31
32
31
32
0
p03095
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #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; long long co[30] = {0}; long long ans = 1; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n; i++) { co[int(s[i] - 'a')]++; } for (int i = 0; i < n; i++) { ans = ans * (co[i] + 1) % 1000000007; } ans--; if (ans < 0) { ans += 1000000007; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cctype> #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; long long co[30] = {0}; long long ans = 1; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n; i++) { co[int(s[i] - 'a')]++; } for (int i = 0; i < 26; i++) { ans = ans * (co[i] + 1) % 1000000007; } ans--; if (ans < 0) { ans += 1000000007; } cout << ans << endl; }
replace
25
26
25
26
0
p03095
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <cstring> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define rep(i, m, n) for (int i = int(m); i < int(n); i++) #define all(c) begin(c), end(c) template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } // 改造 typedef long long int ll; using namespace std; #define INF (1 << 30) - 1 #define INFl (ll)5e15 #define DEBUG 0 // デバッグする時1にしてね #define dump(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 // ここから編集する class Solve { public: void input() {} void solve() { input(); int N; cin >> N; string S; cin >> S; vector<ll> cnt(26); for (int i = 0; i < N; ++i) { cnt[S[i] - 'a']++; } ll ans = 1ll; for (int i = 0; i < N; ++i) { ans *= (cnt[i] + 1); ans %= MOD; } ans--; cout << ans << endl; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); Solve().solve(); return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <cstring> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define rep(i, m, n) for (int i = int(m); i < int(n); i++) #define all(c) begin(c), end(c) template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } // 改造 typedef long long int ll; using namespace std; #define INF (1 << 30) - 1 #define INFl (ll)5e15 #define DEBUG 0 // デバッグする時1にしてね #define dump(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 // ここから編集する class Solve { public: void input() {} void solve() { input(); int N; cin >> N; string S; cin >> S; vector<ll> cnt(26); for (int i = 0; i < N; ++i) { cnt[S[i] - 'a']++; } ll ans = 1ll; for (int i = 0; i < 26; ++i) { ans *= (cnt[i] + 1); ans %= MOD; } ans--; cout << ans << endl; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); Solve().solve(); return 0; }
replace
75
76
75
76
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int mod = 1'000'000'007; int main() { int n; cin >> n; string s; cin >> s; vector<int> num(26, 0); for (int i = 0; i < n; i++) num[s[i] - 'a']++; long long ans = 1; for (int i = 0; i < n; i++) { ans *= num[i] + 1; ans %= mod; } cout << (ans + mod - 1) % mod << endl; }
#include <bits/stdc++.h> using namespace std; int mod = 1'000'000'007; int main() { int n; cin >> n; string s; cin >> s; vector<int> num(26, 0); for (int i = 0; i < n; i++) num[s[i] - 'a']++; long long ans = 1; for (int i = 0; i < 26; i++) { ans *= num[i] + 1; ans %= mod; } cout << (ans + mod - 1) % mod << endl; }
replace
14
15
14
15
0
p03095
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, mod = 1000000007; string s; cin >> n >> s; vector<int64_t> cnt(26, 0); for (auto &c : s) { cnt[c - 'a']++; } int64_t ans = 0; for (int i = 1; i < (1 << 26); i++) { int64_t tmp = 0; for (int j = 0; j < 26; j++) { if ((i >> j) & 1) { if (tmp == 0) { tmp = cnt[j]; } else { (tmp *= cnt[j]) %= mod; } } } (ans += tmp) %= mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, mod = 1000000007; string s; cin >> n >> s; vector<int64_t> cnt(26, 0); for (auto &c : s) { cnt[c - 'a']++; } int64_t ans = 0; for (int i = 0; i < 26; i++) { int64_t tmp = cnt[i]; for (int j = i + 1; j < 26; j++) { (tmp *= cnt[j] + 1) %= mod; } (ans += tmp) %= mod; } cout << ans << endl; return 0; }
replace
15
25
15
19
TLE
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(), (a).end() #define rALL(a) (a).rbegin(), (a).rend() typedef pair<int, int> Pint; typedef pair<int64_t, int64_t> Pll; int main() { int64_t N, ans = 1; string S; cin >> N >> S; vector<int64_t> A(26); for (int i = 0; i < N; i++) { A.at(S.at(i) - 'a')++; } for (int i = 0; i < N; i++) { ans = ans * (A.at(i) + 1) % 1000000007; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(), (a).end() #define rALL(a) (a).rbegin(), (a).rend() typedef pair<int, int> Pint; typedef pair<int64_t, int64_t> Pll; int main() { int64_t N, ans = 1; string S; cin >> N >> S; vector<int64_t> A(26); for (int i = 0; i < N; i++) { A.at(S.at(i) - 'a')++; } for (int i = 0; i < 26; i++) { ans = ans * (A.at(i) + 1) % 1000000007; } cout << ans - 1 << endl; }
replace
16
17
16
17
0
p03095
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (int i = (a); i >= (b); i--) #define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define LLONG_MAXs 9223372036854775800 #include <cmath> #include <iostream> using namespace std; bool isPrimeNum(ll x) { // 素数である場合 true を返す if (x <= 1) { // 1以下である場合は素数でないことがすぐにわかる return false; } // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト int n = (int)sqrt((double)x); for (int i = 2; i <= n; i++) { if (x % i == 0) { // 割り切る整数がある場合、即判定終了 return false; } } return true; // 割り切る整数がない場合、素数である } constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll abs(ll a, ll b) { if (a >= b) return a - b; if (a < b) return b - a; } constexpr ll min(ll a, ll b) { if (a >= b) return b; if (a < b) return a; } constexpr ll max(ll a, ll b) { if (a >= b) return a; if (a < b) return b; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { ll N; cin >> N; string S; ll p[26]; FOR(i, 0, 25) { p[i] = 1; } FOR(i, 0, N - 1) { cin >> S[i]; } FOR(i, 0, N - 1) { if (S[i] == 'a') { p[0]++; } if (S[i] == 'b') { p[1]++; } if (S[i] == 'c') { p[2]++; } if (S[i] == 'd') { p[3]++; } if (S[i] == 'e') { p[4]++; } if (S[i] == 'f') { p[5]++; } if (S[i] == 'g') { p[6]++; } if (S[i] == 'h') { p[7]++; } if (S[i] == 'i') { p[8]++; } if (S[i] == 'j') { p[9]++; } if (S[i] == 'k') { p[10]++; } if (S[i] == 'l') { p[11]++; } if (S[i] == 'm') { p[12]++; } if (S[i] == 'n') { p[13]++; } if (S[i] == 'o') { p[14]++; } if (S[i] == 'p') { p[15]++; } if (S[i] == 'q') { p[16]++; } if (S[i] == 'r') { p[17]++; } if (S[i] == 's') { p[18]++; } if (S[i] == 't') { p[19]++; } if (S[i] == 'u') { p[20]++; } if (S[i] == 'v') { p[21]++; } if (S[i] == 'w') { p[22]++; } if (S[i] == 'x') { p[23]++; } if (S[i] == 'y') { p[24]++; } if (S[i] == 'z') { p[25]++; } } ll ans = 1; FOR(i, 0, 25) { ans = ans * p[i] % MOD; } cout << ans - 1 << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (int i = (a); i >= (b); i--) #define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define LLONG_MAXs 9223372036854775800 #include <cmath> #include <iostream> using namespace std; bool isPrimeNum(ll x) { // 素数である場合 true を返す if (x <= 1) { // 1以下である場合は素数でないことがすぐにわかる return false; } // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト int n = (int)sqrt((double)x); for (int i = 2; i <= n; i++) { if (x % i == 0) { // 割り切る整数がある場合、即判定終了 return false; } } return true; // 割り切る整数がない場合、素数である } constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll abs(ll a, ll b) { if (a >= b) return a - b; if (a < b) return b - a; } constexpr ll min(ll a, ll b) { if (a >= b) return b; if (a < b) return a; } constexpr ll max(ll a, ll b) { if (a >= b) return a; if (a < b) return b; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int main() { ll N; cin >> N; string S; ll p[26]; FOR(i, 0, 25) { p[i] = 1; } cin >> S; FOR(i, 0, N - 1) { if (S[i] == 'a') { p[0]++; } if (S[i] == 'b') { p[1]++; } if (S[i] == 'c') { p[2]++; } if (S[i] == 'd') { p[3]++; } if (S[i] == 'e') { p[4]++; } if (S[i] == 'f') { p[5]++; } if (S[i] == 'g') { p[6]++; } if (S[i] == 'h') { p[7]++; } if (S[i] == 'i') { p[8]++; } if (S[i] == 'j') { p[9]++; } if (S[i] == 'k') { p[10]++; } if (S[i] == 'l') { p[11]++; } if (S[i] == 'm') { p[12]++; } if (S[i] == 'n') { p[13]++; } if (S[i] == 'o') { p[14]++; } if (S[i] == 'p') { p[15]++; } if (S[i] == 'q') { p[16]++; } if (S[i] == 'r') { p[17]++; } if (S[i] == 's') { p[18]++; } if (S[i] == 't') { p[19]++; } if (S[i] == 'u') { p[20]++; } if (S[i] == 'v') { p[21]++; } if (S[i] == 'w') { p[22]++; } if (S[i] == 'x') { p[23]++; } if (S[i] == 'y') { p[24]++; } if (S[i] == 'z') { p[25]++; } } ll ans = 1; FOR(i, 0, 25) { ans = ans * p[i] % MOD; } cout << ans - 1 << endl; return 0; }
replace
82
83
82
85
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int a[300005]; char s[100005]; int cnt[30]; ll mod = 1e9 + 7; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin >> n; cin >> s; int len = strlen(s); ll ans = 1; for (int i = 0; i < len; i++) cnt[s[i] - 'a']++; for (int i = 0; i <= 25; i++) { ans = (ans * (cnt[i] + 1)) % mod; } ans = (ans - 1 + mod) % mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; int a[300005]; char s[100005]; int cnt[30]; ll mod = 1e9 + 7; int main() { #ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); #endif ios::sync_with_stdio(false); cin >> n; cin >> s; int len = strlen(s); ll ans = 1; for (int i = 0; i < len; i++) cnt[s[i] - 'a']++; for (int i = 0; i <= 25; i++) { ans = (ans * (cnt[i] + 1)) % mod; } ans = (ans - 1 + mod) % mod; cout << ans << endl; return 0; }
replace
10
11
10
11
0
p03095
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class T, class U> using P = pair<T, U>; template <class S, class T, class U> using TUP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using ld = long double; using str = string; using vll = V<ll>; using vll2 = VV<ll>; using vll3 = VVV<ll>; using pll = P<ll, ll>; using tll = TUP<ll, ll, ll>; using vpll = V<pll>; using tpll = V<tll>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpll = queue<pll>; using mapll = map<ll, ll>; using setll = set<ll>; #define int ll #define fst first #define snd second #define PQ priority_queue #define mp make_pair #define mt make_tuple #define pb push_back #define popb pop_back() #define sz size() #define bn begin() #define ed end() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, n) FOR(i, 0, (n)-1) #define REP1(i, n) FOR(i, 1, (n)) #define VFOR(i, v) for (auto &(i) : v) #define IOTA(a, n) \ vll(a)((n)); \ iota((a).bn, (a).ed, (0)); #define fixed_echo(x) echo(fixed, setprecision(20), x) #define SORT_ASC(a) sort((a).bn, (a).ed) #define SORT_DESC(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bn, (a).ed), (a).ed) #define PREVP(a) prev_permutation((a).bn, (a).ed) #define NEXTP(a) next_permutation((a).bn, (a).ed) #define BINS(a, target) binary_search((a).bn, (a).ed, target) #define LB(a, target) lower_bound((a).bn, (a).ed, target) #define FIND(a, target) find((a).bn, (a).ed, target) #define UB(a, target) upper_bound((a).bn, (a).ed, target) #define ARG(a, itr) distance((a).begin(), itr) #define CNT(a, target) count((a).bn, (a).ed, target) #define SUM(a) accumulate((a).bn, (a).ed, 0) #define DEBUG(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__) #define Dig2(a, b) ((a) >> (b)&1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (dbl)(b))))) % 10) #define DigN2(a) ((llabs(a) == 0) ? 1 : ((ll)log2((dbl)llabs(a)) + 1)) #define DigN10(a) ((llabs(a) == 0) ? 1 : ((ll)log10((dbl)llabs(a)) + 1)) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & -(a)) #define llin(n) \ ll n; \ cin >> n; #define strin(n) \ str n; \ cin >> n; #define vin(v) \ VFOR(i, v) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vpllin(vp, N) \ vpll vp; \ REP(i, N) { \ ll a, b; \ cin >> a >> b; \ vp.pb(mp(a, b)); \ } #define vll2in(vv, col, row) \ vll2(vv); \ (vv).resize((col)); \ for (ll i = 0; i < col; i++) { \ vv[i].resize(row); \ } \ REP(y, col) { \ REP(x, row) { cin >> (vv)[y][x]; } \ } #define vl4in(v1, v2, N) \ vll(v1)(N), (v2)(N); \ REP(i, N) { cin >> (v1)[i] >> (v2)[i]; }; #define vl6in(v1, v2, v3, N) \ vll(v1)(N), (v2)(N), (v3)(N); \ REP(i, N) { cin >> (v1)[i] >> (v2)[i] >> (v3)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define sort_asc_pair_by_second(vp) \ std::sort(vp.begin(), vp.end(), [](auto &left, auto &right) { \ return left.second < right.second; \ }); #define sort_desc_pair_by_second(vp) \ std::sort(vp.begin(), vp.end(), [](auto &left, auto &right) { \ return left.second > right.second; \ }); #define min(...) Min(__VA_ARGS__) #define max(...) Max(__VA_ARGS__) #define emin(a, ...) ((a) = Min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = Max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define tf(cond, t, f) \ if (cond) { \ echo(t); \ } else { \ echo(f); \ } #define yn(cond) tf(cond, "yes", "no") #define Yn(cond) tf(cond, "Yes", "No") #define YN(cond) tf(cond, "YES", "NO") static const ll MOD = (ll)1e9 + 7; static const ll INF = (1LL << 62) - 1; // 4.611E+18 static const dbl PI = acos(-1.0); void Input(){}; template <class T, class... Args> void Input(T &t, Args &...args) { cin >> t; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.resize(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size); REP(i, size) { vInputNum(i, args...); } } template <class S, class T> ostream &operator<<(ostream &o, const P<S, T> &p) { return o << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &o, const V<T> &v) { if (v.empty()) { return o << "[]"; } else { auto itr = v.bn; o << "[" << *itr; itr++; while (itr != v.ed) { o << ", " << *itr; itr++; } o << "]"; return o; } } template <class T> ostream &operator<<(ostream &o, queue<T> q) { if (q.empty()) { return o << "| |"; } else { while (!q.empty()) { o << "| " << q.front() << " "; q.pop(); } o << "|"; return o; } } template <class S, class T> ostream &operator<<(ostream &o, const map<S, T> &m) { if (m.empty()) { return o << "[]"; } else { auto itr = m.bn; o << "{" << itr->first << ": " << itr->second; itr++; while (itr != m.ed) { o << "} {" << itr->first << ": " << itr->second; itr++; } o << "}"; return o; } } template <class T> ostream &operator<<(ostream &o, const set<T> &s) { if (s.empty()) { return o << "<>"; } else { auto itr = s.bn; o << "<" << *itr; itr++; while (itr != s.ed) { o << ", " << *itr; itr++; } o << ">"; return o; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head h, Body... b) { cout << h; say(b...); } void puts() {} template <class T> void puts(T t) { cout << t; } template <class Head, class... Body> void puts(Head h, Body... b) { cout << h << " "; puts(b...); } void echo() { cout << "\n"; } template <class... Args> void echo(Args... args) { say(args...); cout << "\n"; } void print() { cout << "\n"; } template <class... Args> void print(Args... args) { puts(args...); cout << "\n"; } void dbgsay() {} template <class T> void dbgsay(T t) { cout << t; } template <class Head, class... Body> void dbgsay(Head h, Body... b) { cerr << h << " "; dbgsay(b...); } void dbgecho() { cout << "\n"; } template <class... Args> void dbgecho(Args... args) { dbgsay(args...); cerr << "\n"; } void echovv() {} template <class T> void echovv(VV<T> v) { if (v.empty()) { echo(); } else { VFOR(i, v) echo(v); } } template <class T, class... Args> void echovv(VV<T> v, Args... args) { echovv(v); echovv(args...); } template <class Head> Head Min(Head head) { return head; } template <class Head, class... Body> Head Min(Head h, Body... b) { auto t = Min(b...); return (h < t) ? h : t; } template <class Head> Head Max(Head head) { return head; } template <class Head, class... Body> Head Max(Head h, Body... b) { auto t = Max(b...); return (h > t) ? h : t; } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } template <class... Body> ll gcd(ll h, Body... b) { return gcd(h, gcd(b...)); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class... Body> ll lcm(ll h, Body... b) { return lcm(h, lcm(b...)); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } ll sumOfRange(ll N) { return N * (N - 1) / 2; } struct UF { public: ll tsize; ll mode; ll connect = 0; vll nodeSize; vll par; vll rank; UF(){}; UF(const UF &uf) {} UF(ll _size, ll _mode = 0) { tsize = _size; mode = _mode; par.assign(tsize, -1); if (!mode) rank.resize(tsize, 0); nodeSize.resize(tsize, 1); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return root(x) == x; } void unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] += x; } else { connect -= sumOfRange(nodeSize[x]) + sumOfRange(nodeSize[y]); connect += sumOfRange(nodeSize[x] + nodeSize[y]); if (rank[x] < rank[y]) { nodeSize[y] += nodeSize[x]; par[y] += par[x]; par[x] = y; } else { nodeSize[x] += nodeSize[y]; par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return -par[root(x)]; } }; class Vertex { public: ll idx; ll param = -1; ll dist = INF; vector<pair<Vertex *, ll> /**/> e; ll size() { return e.size(); } bool operator==(const Vertex *o) { return dist == o->dist; } bool operator!=(const Vertex *o) { return dist != o->dist; } bool operator>(const Vertex *o) { return dist > o->dist; } bool operator<(const Vertex *o) { return dist < o->dist; } bool operator>=(const Vertex *o) { return dist >= o->dist; } bool operator<=(const Vertex *o) { return dist <= o->dist; } }; class Graph { public: vector<Vertex *> V; vll order; typedef tuple<Vertex *, Vertex *, ll> Edge; vector<Edge> E; Graph(ll siz) { REP(i, siz) { auto v = new Vertex(); v->idx = i; V.pb(v); } } static bool comp(const Edge &e1, const Edge &e2) { return get<2>(e1) < get<2>(e2); } Vertex *getVertex(ll idx) { return V[idx]; } void unite(ll from, ll to, ll w = 1, bool digraph = true) { E.push_back(make_tuple(V[from], V[to], w)); V[from]->e.pb(make_pair(V[to], w)); if (!digraph) { E.push_back(make_tuple(V[to], V[from], w)); V[to]->e.pb(make_pair(V[from], w)); } } void dijkstra(ll start) { PQ<Vertex *, vector<Vertex *>, greater<Vertex *> /**/> pq; Vertex *s = getVertex(start); s->dist = 0; pq.push(s); while (!pq.empty()) { Vertex *v = pq.top(); pq.pop(); for (auto &u : v->e) { if (u.first->dist > v->dist + u.second) { u.first->dist = v->dist + u.second; pq.push(u.first); } } } } bool sort() { for (auto &v : V) { if (v->param == -1 && !sort_visit(v->idx)) { return false; } } reverse(order.bn, order.ed); return true; } bool sort_visit(int v) { Vertex *_v = getVertex(v); _v->param = 1; if (!_v->e.empty()) { for (auto &u : _v->e) { if (u.first->param == 2) continue; if (u.first->param == 1) return false; if (!sort_visit(u.first->idx)) return false; } } order.push_back(v); _v->param = 2; return true; } }; ll isPrime(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n)) { if (n % i == 0) return 0; } return 1; } ll DigS10(ll n) { ll m = 0; REP(i, DigN10(n)) { m += (ll)((llabs(n) % Pow10(i + 1))) / Pow10(i); } return m; } ll PowMod(ll a, ll b) { ll ans = 1, x = a % MOD; REP(i, DigN2(b)) { if (Dig2(b, i) == 1) { ans = (ans * x) % MOD; } if (i != (DigN2(b) - 1)) { x = (x * x) % MOD; } } return ans; } vll FactMod(1, 1); vll FactModInv(1, 1); ll Mod(ll n) { n %= MOD; n = (n + MOD) % MOD; return n; } ll InvM(ll n) { n = Mod(n); n = PowMod(n, MOD - 2); return n; } void CFactMod(ll n) { if (FactMod.size() <= n) { FOR(i, FactMod.size(), n) { FactMod.pb((FactMod[i - 1] * (i % MOD)) % MOD); } } } void CFactModInv(ll n) { CFactMod(n); if (FactModInv.size() < (n + 1)) { FactModInv.resize(n + 1, -1); } if (FactModInv[n] == -1) { FactModInv[n] = PowMod(FactMod[n], MOD - 2); } for (int i = n - 1; i >= 1; i--) { if (FactModInv[i] != -1) break; FactModInv[i] = ((FactModInv[i + 1] * ((i + 1) % MOD)) % MOD); } } ll CombMod(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; if (n + 1 > FactModInv.size()) CFactModInv(n); return ((((FactModInv[k] * FactModInv[n - k]) % MOD) * FactMod[n]) % MOD); } pll factor_sub(ll n, ll m) { ll i = 0; while (n % m == 0) { i++; n /= m; } return mp(i, n); } vpll factrization(ll n) { vpll a; ll c, m; tie(c, m) = factor_sub(n, 2); if (c > 0) a.pb(mp(2, c)); for (ll i = 3; m >= i * i; i += 2) { tie(c, m) = factor_sub(m, i); if (c > 0) a.pb(mp(i, c)); } if (m > 1) a.pb(mp(m, 1)); return a; } vll countSameNeighbour(vll v) { ll prev, pres; vll ctr; ctr.pb(1); FOR(i, 1, v.size() - 1) { prev = v[i - 1]; pres = v[i]; if (pres != prev) { ctr.pb(1); } else { ctr[ctr.size() - 1]++; } } return ctr; } vll countSameNeighbour(str s) { ll prev, pres; vll ctr; ctr.pb(1); FOR(i, 1, s.size() - 1) { prev = s[i - 1]; pres = s[i]; if (pres != prev) { ctr.pb(1); } else { ctr[ctr.size() - 1]++; } } return ctr; } ll sumDigit(ll N) { ll sum = 0; for (ll i = 1; i <= N; i *= 10) { sum += (N % (i * 10)) / i; } return sum; } ll dot(vll a, vll b) { ll ans = 0; REP(i, a.size()) { ans += a[i] * b[i]; } return ans; } ll dot(vpll p) { ll ans = 0; REP(i, p.size()) { ans += p[i].first * p[i].second; } return ans; } ll xorSum(ll n) { if (n <= 0) return 0; switch (n % 4) { case 0: return n; break; case 1: return 1; break; case 2: return n + 1; break; default: return 0; break; } } signed main() { llin(n); strin(s); SORT_ASC(s); vll ctr = countSameNeighbour(s); ll ans = 1; REP(i, n) { ans *= (ctr[i] + 1) % MOD; } echo(ans - 1); }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class T, class U> using P = pair<T, U>; template <class S, class T, class U> using TUP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using ld = long double; using str = string; using vll = V<ll>; using vll2 = VV<ll>; using vll3 = VVV<ll>; using pll = P<ll, ll>; using tll = TUP<ll, ll, ll>; using vpll = V<pll>; using tpll = V<tll>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpll = queue<pll>; using mapll = map<ll, ll>; using setll = set<ll>; #define int ll #define fst first #define snd second #define PQ priority_queue #define mp make_pair #define mt make_tuple #define pb push_back #define popb pop_back() #define sz size() #define bn begin() #define ed end() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, n) FOR(i, 0, (n)-1) #define REP1(i, n) FOR(i, 1, (n)) #define VFOR(i, v) for (auto &(i) : v) #define IOTA(a, n) \ vll(a)((n)); \ iota((a).bn, (a).ed, (0)); #define fixed_echo(x) echo(fixed, setprecision(20), x) #define SORT_ASC(a) sort((a).bn, (a).ed) #define SORT_DESC(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bn, (a).ed), (a).ed) #define PREVP(a) prev_permutation((a).bn, (a).ed) #define NEXTP(a) next_permutation((a).bn, (a).ed) #define BINS(a, target) binary_search((a).bn, (a).ed, target) #define LB(a, target) lower_bound((a).bn, (a).ed, target) #define FIND(a, target) find((a).bn, (a).ed, target) #define UB(a, target) upper_bound((a).bn, (a).ed, target) #define ARG(a, itr) distance((a).begin(), itr) #define CNT(a, target) count((a).bn, (a).ed, target) #define SUM(a) accumulate((a).bn, (a).ed, 0) #define DEBUG(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__) #define Dig2(a, b) ((a) >> (b)&1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (dbl)(b))))) % 10) #define DigN2(a) ((llabs(a) == 0) ? 1 : ((ll)log2((dbl)llabs(a)) + 1)) #define DigN10(a) ((llabs(a) == 0) ? 1 : ((ll)log10((dbl)llabs(a)) + 1)) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & -(a)) #define llin(n) \ ll n; \ cin >> n; #define strin(n) \ str n; \ cin >> n; #define vin(v) \ VFOR(i, v) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vpllin(vp, N) \ vpll vp; \ REP(i, N) { \ ll a, b; \ cin >> a >> b; \ vp.pb(mp(a, b)); \ } #define vll2in(vv, col, row) \ vll2(vv); \ (vv).resize((col)); \ for (ll i = 0; i < col; i++) { \ vv[i].resize(row); \ } \ REP(y, col) { \ REP(x, row) { cin >> (vv)[y][x]; } \ } #define vl4in(v1, v2, N) \ vll(v1)(N), (v2)(N); \ REP(i, N) { cin >> (v1)[i] >> (v2)[i]; }; #define vl6in(v1, v2, v3, N) \ vll(v1)(N), (v2)(N), (v3)(N); \ REP(i, N) { cin >> (v1)[i] >> (v2)[i] >> (v3)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define sort_asc_pair_by_second(vp) \ std::sort(vp.begin(), vp.end(), [](auto &left, auto &right) { \ return left.second < right.second; \ }); #define sort_desc_pair_by_second(vp) \ std::sort(vp.begin(), vp.end(), [](auto &left, auto &right) { \ return left.second > right.second; \ }); #define min(...) Min(__VA_ARGS__) #define max(...) Max(__VA_ARGS__) #define emin(a, ...) ((a) = Min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = Max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define tf(cond, t, f) \ if (cond) { \ echo(t); \ } else { \ echo(f); \ } #define yn(cond) tf(cond, "yes", "no") #define Yn(cond) tf(cond, "Yes", "No") #define YN(cond) tf(cond, "YES", "NO") static const ll MOD = (ll)1e9 + 7; static const ll INF = (1LL << 62) - 1; // 4.611E+18 static const dbl PI = acos(-1.0); void Input(){}; template <class T, class... Args> void Input(T &t, Args &...args) { cin >> t; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.resize(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size); REP(i, size) { vInputNum(i, args...); } } template <class S, class T> ostream &operator<<(ostream &o, const P<S, T> &p) { return o << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &o, const V<T> &v) { if (v.empty()) { return o << "[]"; } else { auto itr = v.bn; o << "[" << *itr; itr++; while (itr != v.ed) { o << ", " << *itr; itr++; } o << "]"; return o; } } template <class T> ostream &operator<<(ostream &o, queue<T> q) { if (q.empty()) { return o << "| |"; } else { while (!q.empty()) { o << "| " << q.front() << " "; q.pop(); } o << "|"; return o; } } template <class S, class T> ostream &operator<<(ostream &o, const map<S, T> &m) { if (m.empty()) { return o << "[]"; } else { auto itr = m.bn; o << "{" << itr->first << ": " << itr->second; itr++; while (itr != m.ed) { o << "} {" << itr->first << ": " << itr->second; itr++; } o << "}"; return o; } } template <class T> ostream &operator<<(ostream &o, const set<T> &s) { if (s.empty()) { return o << "<>"; } else { auto itr = s.bn; o << "<" << *itr; itr++; while (itr != s.ed) { o << ", " << *itr; itr++; } o << ">"; return o; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head h, Body... b) { cout << h; say(b...); } void puts() {} template <class T> void puts(T t) { cout << t; } template <class Head, class... Body> void puts(Head h, Body... b) { cout << h << " "; puts(b...); } void echo() { cout << "\n"; } template <class... Args> void echo(Args... args) { say(args...); cout << "\n"; } void print() { cout << "\n"; } template <class... Args> void print(Args... args) { puts(args...); cout << "\n"; } void dbgsay() {} template <class T> void dbgsay(T t) { cout << t; } template <class Head, class... Body> void dbgsay(Head h, Body... b) { cerr << h << " "; dbgsay(b...); } void dbgecho() { cout << "\n"; } template <class... Args> void dbgecho(Args... args) { dbgsay(args...); cerr << "\n"; } void echovv() {} template <class T> void echovv(VV<T> v) { if (v.empty()) { echo(); } else { VFOR(i, v) echo(v); } } template <class T, class... Args> void echovv(VV<T> v, Args... args) { echovv(v); echovv(args...); } template <class Head> Head Min(Head head) { return head; } template <class Head, class... Body> Head Min(Head h, Body... b) { auto t = Min(b...); return (h < t) ? h : t; } template <class Head> Head Max(Head head) { return head; } template <class Head, class... Body> Head Max(Head h, Body... b) { auto t = Max(b...); return (h > t) ? h : t; } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } template <class... Body> ll gcd(ll h, Body... b) { return gcd(h, gcd(b...)); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class... Body> ll lcm(ll h, Body... b) { return lcm(h, lcm(b...)); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } ll sumOfRange(ll N) { return N * (N - 1) / 2; } struct UF { public: ll tsize; ll mode; ll connect = 0; vll nodeSize; vll par; vll rank; UF(){}; UF(const UF &uf) {} UF(ll _size, ll _mode = 0) { tsize = _size; mode = _mode; par.assign(tsize, -1); if (!mode) rank.resize(tsize, 0); nodeSize.resize(tsize, 1); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return root(x) == x; } void unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] += x; } else { connect -= sumOfRange(nodeSize[x]) + sumOfRange(nodeSize[y]); connect += sumOfRange(nodeSize[x] + nodeSize[y]); if (rank[x] < rank[y]) { nodeSize[y] += nodeSize[x]; par[y] += par[x]; par[x] = y; } else { nodeSize[x] += nodeSize[y]; par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return -par[root(x)]; } }; class Vertex { public: ll idx; ll param = -1; ll dist = INF; vector<pair<Vertex *, ll> /**/> e; ll size() { return e.size(); } bool operator==(const Vertex *o) { return dist == o->dist; } bool operator!=(const Vertex *o) { return dist != o->dist; } bool operator>(const Vertex *o) { return dist > o->dist; } bool operator<(const Vertex *o) { return dist < o->dist; } bool operator>=(const Vertex *o) { return dist >= o->dist; } bool operator<=(const Vertex *o) { return dist <= o->dist; } }; class Graph { public: vector<Vertex *> V; vll order; typedef tuple<Vertex *, Vertex *, ll> Edge; vector<Edge> E; Graph(ll siz) { REP(i, siz) { auto v = new Vertex(); v->idx = i; V.pb(v); } } static bool comp(const Edge &e1, const Edge &e2) { return get<2>(e1) < get<2>(e2); } Vertex *getVertex(ll idx) { return V[idx]; } void unite(ll from, ll to, ll w = 1, bool digraph = true) { E.push_back(make_tuple(V[from], V[to], w)); V[from]->e.pb(make_pair(V[to], w)); if (!digraph) { E.push_back(make_tuple(V[to], V[from], w)); V[to]->e.pb(make_pair(V[from], w)); } } void dijkstra(ll start) { PQ<Vertex *, vector<Vertex *>, greater<Vertex *> /**/> pq; Vertex *s = getVertex(start); s->dist = 0; pq.push(s); while (!pq.empty()) { Vertex *v = pq.top(); pq.pop(); for (auto &u : v->e) { if (u.first->dist > v->dist + u.second) { u.first->dist = v->dist + u.second; pq.push(u.first); } } } } bool sort() { for (auto &v : V) { if (v->param == -1 && !sort_visit(v->idx)) { return false; } } reverse(order.bn, order.ed); return true; } bool sort_visit(int v) { Vertex *_v = getVertex(v); _v->param = 1; if (!_v->e.empty()) { for (auto &u : _v->e) { if (u.first->param == 2) continue; if (u.first->param == 1) return false; if (!sort_visit(u.first->idx)) return false; } } order.push_back(v); _v->param = 2; return true; } }; ll isPrime(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n)) { if (n % i == 0) return 0; } return 1; } ll DigS10(ll n) { ll m = 0; REP(i, DigN10(n)) { m += (ll)((llabs(n) % Pow10(i + 1))) / Pow10(i); } return m; } ll PowMod(ll a, ll b) { ll ans = 1, x = a % MOD; REP(i, DigN2(b)) { if (Dig2(b, i) == 1) { ans = (ans * x) % MOD; } if (i != (DigN2(b) - 1)) { x = (x * x) % MOD; } } return ans; } vll FactMod(1, 1); vll FactModInv(1, 1); ll Mod(ll n) { n %= MOD; n = (n + MOD) % MOD; return n; } ll InvM(ll n) { n = Mod(n); n = PowMod(n, MOD - 2); return n; } void CFactMod(ll n) { if (FactMod.size() <= n) { FOR(i, FactMod.size(), n) { FactMod.pb((FactMod[i - 1] * (i % MOD)) % MOD); } } } void CFactModInv(ll n) { CFactMod(n); if (FactModInv.size() < (n + 1)) { FactModInv.resize(n + 1, -1); } if (FactModInv[n] == -1) { FactModInv[n] = PowMod(FactMod[n], MOD - 2); } for (int i = n - 1; i >= 1; i--) { if (FactModInv[i] != -1) break; FactModInv[i] = ((FactModInv[i + 1] * ((i + 1) % MOD)) % MOD); } } ll CombMod(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; if (n + 1 > FactModInv.size()) CFactModInv(n); return ((((FactModInv[k] * FactModInv[n - k]) % MOD) * FactMod[n]) % MOD); } pll factor_sub(ll n, ll m) { ll i = 0; while (n % m == 0) { i++; n /= m; } return mp(i, n); } vpll factrization(ll n) { vpll a; ll c, m; tie(c, m) = factor_sub(n, 2); if (c > 0) a.pb(mp(2, c)); for (ll i = 3; m >= i * i; i += 2) { tie(c, m) = factor_sub(m, i); if (c > 0) a.pb(mp(i, c)); } if (m > 1) a.pb(mp(m, 1)); return a; } vll countSameNeighbour(vll v) { ll prev, pres; vll ctr; ctr.pb(1); FOR(i, 1, v.size() - 1) { prev = v[i - 1]; pres = v[i]; if (pres != prev) { ctr.pb(1); } else { ctr[ctr.size() - 1]++; } } return ctr; } vll countSameNeighbour(str s) { ll prev, pres; vll ctr; ctr.pb(1); FOR(i, 1, s.size() - 1) { prev = s[i - 1]; pres = s[i]; if (pres != prev) { ctr.pb(1); } else { ctr[ctr.size() - 1]++; } } return ctr; } ll sumDigit(ll N) { ll sum = 0; for (ll i = 1; i <= N; i *= 10) { sum += (N % (i * 10)) / i; } return sum; } ll dot(vll a, vll b) { ll ans = 0; REP(i, a.size()) { ans += a[i] * b[i]; } return ans; } ll dot(vpll p) { ll ans = 0; REP(i, p.size()) { ans += p[i].first * p[i].second; } return ans; } ll xorSum(ll n) { if (n <= 0) return 0; switch (n % 4) { case 0: return n; break; case 1: return 1; break; case 2: return n + 1; break; default: return 0; break; } } signed main() { llin(n); strin(s); SORT_ASC(s); vll ctr = countSameNeighbour(s); ll ans = 1; REP(i, ctr.sz) { ans *= (ctr[i] + 1); ans %= MOD; } echo(ans - 1); }
replace
626
627
626
630
0
p03095
C++
Runtime Error
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> #define rep(i, s, n) for (int i = (s); (n) > i; i++) #define REP(i, n) rep(i, 0, n) #define RANGE(x, a, b) ((a) <= (x) && (x) < (b)) #define DUPLE(a, b, c, d) \ (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b)) #define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d)) #define PW(x) ((x) * (x)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MODU 1000000007LL #define bitcheck(a, b) ((a >> b) & 1) #define bitset(a, b) (a |= (1 << b)) #define bitunset(a, b) (a &= ~(1 << b)) #define MP(a, b) make_pair((a), (b)) #define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #define izryt bool using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } pll Dir[8] = { // 移動 {0, 1}, {-1, 0}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; //[a, b) #define Getsum(ar, a, b) (ar[b] - ar[a]) #define INF 10000000000000000LL struct Edge { ll from, to; ll w; }; typedef vector<vector<Edge>> Graph; template <typename T> // Tのデフォルトコンストラクタが単位元となる class ScapegoatTree_Leaf { public: struct Node { int range[2]; // [range[0], range[1]) T val; Node *p = NULL, *l = NULL, *r = NULL; bool removed = false, leaf; int sz = 1, dc = 0, coin = 0; Node(Node *par, int rangel, int ranger, Node *left, Node *right) : leaf(false), val(T()), p(par), l(left), r(right) { range[0] = rangel, range[1] = ranger; } Node(Node *par, int t, T _val) : leaf(true), val(_val), p(par) { range[0] = t, range[1] = t + 1; } void upd() { if (!leaf) { sz = 1 + l->sz + r->sz; dc = removed + l->dc + r->dc; range[0] = l->range[0]; range[1] = r->range[1]; val = l->val + r->val; } else { dc = removed; } } int size() { return sz - dc; } }; #define MAXPOOLSIZE 3000000 mt19937 engine; Node *root = NULL; int poolcou = 0; Node *nodepool[MAXPOOLSIZE] = {}; void updpath(Node *node) { Node *cur = node; while (cur != NULL) { cur->upd(); cur = cur->p; } } int depth(Node *node) { Node *cur = node; int c = 0; while (cur != root) { cur = cur->p; c++; } return c; } void DeleteNode(Node *node) { nodepool[poolcou] = node; poolcou++; } Node *NewNode(Node *par, int rangel, int ranger, Node *left, Node *right) { Node *ret; if (poolcou) { ret = nodepool[poolcou - 1], poolcou--; ret->removed = false, ret->sz = 1, ret->dc = 0, ret->val = T(), ret->leaf = false, ret->p = par, ret->range[0] = rangel, ret->range[1] = ranger, ret->l = left, ret->r = right; } else ret = new Node(par, rangel, ranger, left, right); return ret; } Node *NewNode(Node *par, int t, T _val) { Node *ret; if (poolcou) { ret = nodepool[poolcou - 1], poolcou--; ret->removed = false, ret->sz = 1, ret->dc = 0, ret->leaf = true, ret->p = par, ret->range[0] = t, ret->range[1] = t + 1, ret->val = _val; } else ret = new Node(par, t, _val); return ret; } void getarray(vector<Node *> &ar, Node *node, bool rem) { if (node->leaf) { if (node->removed && rem) DeleteNode(node); else ar.push_back(node); } else { getarray(ar, node->l, rem); getarray(ar, node->r, rem); DeleteNode(node); } } Node *makeBST(vector<vector<Node *>> &ar, Node *p, int l, int r) { if (r - l == 1) { if (ar[l].size() == 1) { ar[l][0]->p = p; return ar[l][0]; } else { Node *lleaf = ar[l][0], *rleaf = ar[l][1], *inter = NewNode(p, lleaf->range[0], rleaf->range[1], lleaf, rleaf); lleaf->p = inter; rleaf->p = inter; inter->upd(); return inter; } } int mid = (l + r) / 2; Node *cur = NewNode(p, -1, -1, NULL, NULL); // updで範囲決定 cur->l = makeBST(ar, cur, l, mid); cur->r = makeBST(ar, cur, mid, r); cur->upd(); return cur; } Node *rebuild(Node *node, bool rem = false) { vector<Node *> ar; vector<vector<Node *>> f; Node *nodep = node->p; bool which = false; // T->r F->l if (node->p) { which = node->range[1] == node->p->range[1]; } ar.reserve(node->sz); getarray(ar, node, rem); if (ar.size() == 0) { root = NULL; return NULL; } int fc = 1; while (fc * 2 <= ar.size()) fc *= 2; vector<int> db(fc), dbb(fc); REP(i, fc) db[i] = i; shuffle(ALL(db), engine); REP(i, ar.size() - fc) dbb[db[i]] = 1; for (int i = 0; ar.size() > i; i++) { f.push_back(vector<Node *>()); f[f.size() - 1].push_back(ar[i]); if (dbb[f.size() - 1]) { i++; f[f.size() - 1].push_back(ar[i]); } } Node *nn = makeBST(f, nodep, 0, f.size()); if (nodep) { if (which) nodep->r = nn; else nodep->l = nn; } else root = nn; updpath(nn); return nn; } void remove(Node *node) { if (node == NULL) return; node->removed = true; node->val = T(); updpath(node); if (root->dc * 4 > root->sz) { rebuild(root, true); } } void remove(int t) { remove(search(t)); } Node *search(int t, bool b = false) { if (root == NULL) return NULL; Node *cur = root; while (!cur->leaf) { if (cur->l->range[1] > t) { cur = cur->l; } else if (cur->l->range[1] <= t) { cur = cur->r; } } if (cur->range[0] == t) return cur; else return b ? cur : NULL; } Node *insert(int t, T val) { if (root == NULL) { return root = NewNode(NULL, t, val); } Node *node = search(t, true), *l, *r, *newleaf; if (node->range[0] == t) { node->removed = false, node->val = val; updpath(node); return node; } if (node->range[0] > t) { r = node, newleaf = l = NewNode(NULL, t, val); } if (node->range[0] < t) { newleaf = r = NewNode(NULL, t, val); l = node; } Node *inter = NewNode(node->p, l->range[0], r->range[1], l, r); if (node->p) { if (node->range[1] == node->p->range[1]) node->p->r = inter; else node->p->l = inter; } else root = inter; l->p = inter; r->p = inter; updpath(inter); // printf("bef %d:", depth(newleaf)); if (depth(newleaf) > (log(root->sz) / log(3.0 / 2))) { Node *cur = newleaf, *last = NULL; while (cur->p != NULL) { if (cur->sz * 3 > cur->p->sz * 2) last = cur->p; cur = cur->p; } if (last != NULL) rebuild(last); } return newleaf; } T rangequery(int l, int r, Node *node = NULL) { // [l.r) if (root == NULL) return T(); if (node == NULL) node = root; l = max(l, node->range[0]); r = min(r, node->range[1]); if (l == node->range[0] && r == node->range[1]) return node->val; if (l >= r) return T(); T ret = T(); ret = ret + rangequery(l, min(r, node->l->range[1]), node->l); ret = ret + rangequery(max(l, node->r->range[0]), r, node->r); return ret; } }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll factorial(ll n) { // 階乗 static ll memo[400000] = {}; if (n > 0) { if (memo[n] != 0) return memo[n]; return memo[n] = n * factorial(n - 1) % MODU; } else { return memo[0] = 1; } } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll divmod(ll a, ll b, ll m) { // a/b(mod m) // a/b (mod m) // a*b^-1 // b^-1 * b = 1 // b^(m-1) = 1 // b^(m-2) * b = 1 // b^-1 = b^(m-2) // a/b = a * b^(m-2) return (a * 1LL * mod_pow(b, m - 2, m)) % m; } ll ncr(ll n, ll r) { if (n < r) return 0; return divmod(factorial(n), (factorial(r) * (factorial(n - r)) % MODU), MODU); } signed main(void) { int n; string s; cin >> n >> s; int cou[26] = {}; for (auto itr : s) { cou[itr - 'a']++; } ll dp[27][27] = {}; dp[0][0] = 1; REP(i, 27) { REP(j, 26) { dp[i + 1][j + 1] += dp[i][j] * cou[i]; dp[i + 1][j] += dp[i][j]; dp[i + 1][j + 1] %= MODU; dp[i + 1][j] %= MODU; } } int ans = 0; rep(i, 1, 27) ans += dp[26][i], ans %= MODU; cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> #define rep(i, s, n) for (int i = (s); (n) > i; i++) #define REP(i, n) rep(i, 0, n) #define RANGE(x, a, b) ((a) <= (x) && (x) < (b)) #define DUPLE(a, b, c, d) \ (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b)) #define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d)) #define PW(x) ((x) * (x)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MODU 1000000007LL #define bitcheck(a, b) ((a >> b) & 1) #define bitset(a, b) (a |= (1 << b)) #define bitunset(a, b) (a &= ~(1 << b)) #define MP(a, b) make_pair((a), (b)) #define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #define izryt bool using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } pll Dir[8] = { // 移動 {0, 1}, {-1, 0}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; //[a, b) #define Getsum(ar, a, b) (ar[b] - ar[a]) #define INF 10000000000000000LL struct Edge { ll from, to; ll w; }; typedef vector<vector<Edge>> Graph; template <typename T> // Tのデフォルトコンストラクタが単位元となる class ScapegoatTree_Leaf { public: struct Node { int range[2]; // [range[0], range[1]) T val; Node *p = NULL, *l = NULL, *r = NULL; bool removed = false, leaf; int sz = 1, dc = 0, coin = 0; Node(Node *par, int rangel, int ranger, Node *left, Node *right) : leaf(false), val(T()), p(par), l(left), r(right) { range[0] = rangel, range[1] = ranger; } Node(Node *par, int t, T _val) : leaf(true), val(_val), p(par) { range[0] = t, range[1] = t + 1; } void upd() { if (!leaf) { sz = 1 + l->sz + r->sz; dc = removed + l->dc + r->dc; range[0] = l->range[0]; range[1] = r->range[1]; val = l->val + r->val; } else { dc = removed; } } int size() { return sz - dc; } }; #define MAXPOOLSIZE 3000000 mt19937 engine; Node *root = NULL; int poolcou = 0; Node *nodepool[MAXPOOLSIZE] = {}; void updpath(Node *node) { Node *cur = node; while (cur != NULL) { cur->upd(); cur = cur->p; } } int depth(Node *node) { Node *cur = node; int c = 0; while (cur != root) { cur = cur->p; c++; } return c; } void DeleteNode(Node *node) { nodepool[poolcou] = node; poolcou++; } Node *NewNode(Node *par, int rangel, int ranger, Node *left, Node *right) { Node *ret; if (poolcou) { ret = nodepool[poolcou - 1], poolcou--; ret->removed = false, ret->sz = 1, ret->dc = 0, ret->val = T(), ret->leaf = false, ret->p = par, ret->range[0] = rangel, ret->range[1] = ranger, ret->l = left, ret->r = right; } else ret = new Node(par, rangel, ranger, left, right); return ret; } Node *NewNode(Node *par, int t, T _val) { Node *ret; if (poolcou) { ret = nodepool[poolcou - 1], poolcou--; ret->removed = false, ret->sz = 1, ret->dc = 0, ret->leaf = true, ret->p = par, ret->range[0] = t, ret->range[1] = t + 1, ret->val = _val; } else ret = new Node(par, t, _val); return ret; } void getarray(vector<Node *> &ar, Node *node, bool rem) { if (node->leaf) { if (node->removed && rem) DeleteNode(node); else ar.push_back(node); } else { getarray(ar, node->l, rem); getarray(ar, node->r, rem); DeleteNode(node); } } Node *makeBST(vector<vector<Node *>> &ar, Node *p, int l, int r) { if (r - l == 1) { if (ar[l].size() == 1) { ar[l][0]->p = p; return ar[l][0]; } else { Node *lleaf = ar[l][0], *rleaf = ar[l][1], *inter = NewNode(p, lleaf->range[0], rleaf->range[1], lleaf, rleaf); lleaf->p = inter; rleaf->p = inter; inter->upd(); return inter; } } int mid = (l + r) / 2; Node *cur = NewNode(p, -1, -1, NULL, NULL); // updで範囲決定 cur->l = makeBST(ar, cur, l, mid); cur->r = makeBST(ar, cur, mid, r); cur->upd(); return cur; } Node *rebuild(Node *node, bool rem = false) { vector<Node *> ar; vector<vector<Node *>> f; Node *nodep = node->p; bool which = false; // T->r F->l if (node->p) { which = node->range[1] == node->p->range[1]; } ar.reserve(node->sz); getarray(ar, node, rem); if (ar.size() == 0) { root = NULL; return NULL; } int fc = 1; while (fc * 2 <= ar.size()) fc *= 2; vector<int> db(fc), dbb(fc); REP(i, fc) db[i] = i; shuffle(ALL(db), engine); REP(i, ar.size() - fc) dbb[db[i]] = 1; for (int i = 0; ar.size() > i; i++) { f.push_back(vector<Node *>()); f[f.size() - 1].push_back(ar[i]); if (dbb[f.size() - 1]) { i++; f[f.size() - 1].push_back(ar[i]); } } Node *nn = makeBST(f, nodep, 0, f.size()); if (nodep) { if (which) nodep->r = nn; else nodep->l = nn; } else root = nn; updpath(nn); return nn; } void remove(Node *node) { if (node == NULL) return; node->removed = true; node->val = T(); updpath(node); if (root->dc * 4 > root->sz) { rebuild(root, true); } } void remove(int t) { remove(search(t)); } Node *search(int t, bool b = false) { if (root == NULL) return NULL; Node *cur = root; while (!cur->leaf) { if (cur->l->range[1] > t) { cur = cur->l; } else if (cur->l->range[1] <= t) { cur = cur->r; } } if (cur->range[0] == t) return cur; else return b ? cur : NULL; } Node *insert(int t, T val) { if (root == NULL) { return root = NewNode(NULL, t, val); } Node *node = search(t, true), *l, *r, *newleaf; if (node->range[0] == t) { node->removed = false, node->val = val; updpath(node); return node; } if (node->range[0] > t) { r = node, newleaf = l = NewNode(NULL, t, val); } if (node->range[0] < t) { newleaf = r = NewNode(NULL, t, val); l = node; } Node *inter = NewNode(node->p, l->range[0], r->range[1], l, r); if (node->p) { if (node->range[1] == node->p->range[1]) node->p->r = inter; else node->p->l = inter; } else root = inter; l->p = inter; r->p = inter; updpath(inter); // printf("bef %d:", depth(newleaf)); if (depth(newleaf) > (log(root->sz) / log(3.0 / 2))) { Node *cur = newleaf, *last = NULL; while (cur->p != NULL) { if (cur->sz * 3 > cur->p->sz * 2) last = cur->p; cur = cur->p; } if (last != NULL) rebuild(last); } return newleaf; } T rangequery(int l, int r, Node *node = NULL) { // [l.r) if (root == NULL) return T(); if (node == NULL) node = root; l = max(l, node->range[0]); r = min(r, node->range[1]); if (l == node->range[0] && r == node->range[1]) return node->val; if (l >= r) return T(); T ret = T(); ret = ret + rangequery(l, min(r, node->l->range[1]), node->l); ret = ret + rangequery(max(l, node->r->range[0]), r, node->r); return ret; } }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll factorial(ll n) { // 階乗 static ll memo[400000] = {}; if (n > 0) { if (memo[n] != 0) return memo[n]; return memo[n] = n * factorial(n - 1) % MODU; } else { return memo[0] = 1; } } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll divmod(ll a, ll b, ll m) { // a/b(mod m) // a/b (mod m) // a*b^-1 // b^-1 * b = 1 // b^(m-1) = 1 // b^(m-2) * b = 1 // b^-1 = b^(m-2) // a/b = a * b^(m-2) return (a * 1LL * mod_pow(b, m - 2, m)) % m; } ll ncr(ll n, ll r) { if (n < r) return 0; return divmod(factorial(n), (factorial(r) * (factorial(n - r)) % MODU), MODU); } signed main(void) { int n; string s; cin >> n >> s; int cou[26] = {}; for (auto itr : s) { cou[itr - 'a']++; } ll dp[27][27] = {}; dp[0][0] = 1; REP(i, 26) { REP(j, 26) { dp[i + 1][j + 1] += dp[i][j] * cou[i]; dp[i + 1][j] += dp[i][j]; dp[i + 1][j + 1] %= MODU; dp[i + 1][j] %= MODU; } } int ans = 0; rep(i, 1, 27) ans += dp[26][i], ans %= MODU; cout << ans << endl; return 0; }
replace
394
395
394
395
-6
*** stack smashing detected ***: terminated
p03095
C++
Runtime Error
// Miss Me?? #include <bits/stdc++.h> using namespace std; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long int #define pb push_back #define endl "\n" #define ff first #define ss second #define N 200009 #define mod 1000000007 #define cn continue #define bre break #define pr pair<int, int> int n; string s; int see[26]; signed main() { boost; cin >> n >> s; for (int i = 0; i < 26; i++) { see[i] = 1; } for (int i = 0; i < s.length(); i++) { see[s[i] - 'a']++; } int ans = 1; for (int i = 0; i < n; i++) { ans *= see[i]; ans %= mod; } cout << ((ans - 1) + mod) % mod << endl; }
// Miss Me?? #include <bits/stdc++.h> using namespace std; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long int #define pb push_back #define endl "\n" #define ff first #define ss second #define N 200009 #define mod 1000000007 #define cn continue #define bre break #define pr pair<int, int> int n; string s; int see[26]; signed main() { boost; cin >> n >> s; for (int i = 0; i < 26; i++) { see[i] = 1; } for (int i = 0; i < s.length(); i++) { see[s[i] - 'a']++; } int ans = 1; for (int i = 0; i < 26; i++) { ans *= see[i]; ans %= mod; } cout << ((ans - 1) + mod) % mod << endl; }
replace
33
34
33
34
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil = pair<int, long>; using pll = pair<long, long>; using vc = vector<char>; #define fix20 cout << fixed << setprecision(20) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, t) for (int i = s; i < t; i++) #define RNG(i, s, t, u) for (int i = s; i < t; i += u) #define MOD 1000000007 #define all(vec) vec.begin(), vec.end() int main() { int n; string s; cin >> n >> s; vector<long> cnt(26, 0); rep(i, n) { cnt.at(s.at(i) - '0')++; } long ans = 1; rep(i, 26) { ans *= cnt.at(i) + 1; ans %= MOD; } cout << (ans + MOD - 1) % MOD << endl; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vb = vector<bool>; using vl = vector<long>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvb = vector<vector<bool>>; using vvc = vector<vector<char>>; using vvl = vector<vector<long>>; using pii = pair<int, int>; using pil = pair<int, long>; using pll = pair<long, long>; using vc = vector<char>; #define fix20 cout << fixed << setprecision(20) #define YES cout << "Yes" << endl #define NO cout << "No" << endl #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, s, t) for (int i = s; i < t; i++) #define RNG(i, s, t, u) for (int i = s; i < t; i += u) #define MOD 1000000007 #define all(vec) vec.begin(), vec.end() int main() { int n; string s; cin >> n >> s; vector<long> cnt(26, 0); rep(i, n) { cnt.at(s.at(i) - 'a')++; } long ans = 1; rep(i, 26) { ans *= cnt.at(i) + 1; ans %= MOD; } cout << (ans + MOD - 1) % MOD << endl; }
replace
28
29
28
29
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 49) >= this->size() (which is 26)
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) const double PI = acos(-1); const double EPS = 1e-15; long long INF = (long long)1E17; #define i_7 (long long)(1E9 + 7) long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } using namespace std; bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } class UnionFind { public: // 各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。 vector<int> Parent; // クラスを作るときは、Parentの値を全て-1にする。 // 以下のようにすると全てバラバラの頂点として解釈できる。 UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } // 自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; // 先祖をrootで取っておきたい。 } // AとBをくっ付ける bool connect(int A, int B) { // AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { // すでにくっついてるからくっ付けない return false; } // 大きい方(A)に小さいほう(B)をくっ付けたい // 大小が逆だったらAとBをひっくり返す。 if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { long long n; string s; cin >> n; cin >> s; long long cnt[26] = {}; int c; REP(i, n) { c = s[i] - 'a'; cnt[c]++; } long long ans = 1; REP(i, n) { if (cnt[i]) { ans *= 1 + cnt[i]; ans = mod(ans); } } ans -= 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) const double PI = acos(-1); const double EPS = 1e-15; long long INF = (long long)1E17; #define i_7 (long long)(1E9 + 7) long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } using namespace std; bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } class UnionFind { public: // 各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。 vector<int> Parent; // クラスを作るときは、Parentの値を全て-1にする。 // 以下のようにすると全てバラバラの頂点として解釈できる。 UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } // 自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; // 先祖をrootで取っておきたい。 } // AとBをくっ付ける bool connect(int A, int B) { // AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { // すでにくっついてるからくっ付けない return false; } // 大きい方(A)に小さいほう(B)をくっ付けたい // 大小が逆だったらAとBをひっくり返す。 if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { long long n; string s; cin >> n; cin >> s; long long cnt[26] = {}; int c; REP(i, n) { c = s[i] - 'a'; cnt[c]++; } long long ans = 1; REP(i, 26) { if (cnt[i]) { ans *= 1 + cnt[i]; ans = mod(ans); } } ans -= 1; cout << ans << endl; return 0; }
replace
101
102
101
102
0
p03095
C++
Runtime Error
#include <iostream> using namespace std; int c[26]; const long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { c[s[i] - 'a']++; } long long ans = 1; for (int i = 0; i < n; i++) { ans *= (c[i] + 1); ans %= MOD; } cout << ans - 1 << '\n'; return 0; }
#include <iostream> using namespace std; int c[26]; const long long MOD = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { c[s[i] - 'a']++; } long long ans = 1; for (int i = 0; i < 26; i++) { ans *= (c[i] + 1LL); ans %= MOD; } cout << ans - 1 << '\n'; return 0; }
replace
21
23
21
23
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define pii pair<int, int> #define int long long #define MOD 1000000007 using namespace std; int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; string s; cin >> s; int v[26] = {}; for (int i = 0; i < n; i++) { ++v[s[i] - 'a']; } vector<int> p; for (int i = 0; i < 26; i++) { if (v[i] != 0) p.push_back(v[i]); } int ans = 0, prev = 0; for (auto i : p) { ans = (ans + (i * ((1 + prev) % MOD)) % MOD) % MOD; prev = ans; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define pb push_back #define pii pair<int, int> #define int long long #define MOD 1000000007 using namespace std; int32_t main() { int n; cin >> n; string s; cin >> s; int v[26] = {}; for (int i = 0; i < n; i++) { ++v[s[i] - 'a']; } vector<int> p; for (int i = 0; i < 26; i++) { if (v[i] != 0) p.push_back(v[i]); } int ans = 0, prev = 0; for (auto i : p) { ans = (ans + (i * ((1 + prev) % MOD)) % MOD) % MOD; prev = ans; } cout << ans << '\n'; return 0; }
delete
8
12
8
8
0
p03095
C++
Runtime Error
// finish date: 2019/2/28 #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++) #define rep(i, n) FOR(i, 0, n) typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<double> vd; typedef vector<vector<double>> vvd; typedef vector<vector<vector<double>>> vvvd; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, pair<int, int>> plii; const int bigmod = 1000000007; const int INF = 1050000000; const long long INFll = 100000000000000000; // 足し算 int add(int a, int b) { return (int)(((ll)a + b + bigmod) % bigmod); } // 引き算 int sub(int a, int b) { return (int)(((ll)a - b + bigmod) % bigmod); } // 掛け算 int mul(int a, int b) { return (int)(((ll)(a % bigmod) * (b % bigmod)) % bigmod); } int main() { int N; string S; cin >> N >> S; vi cnt(26, 0); rep(i, N) { cnt[S[i] - 'a']++; } int ans = 0; rep(i, N) { if (cnt[i] == 0) continue; ans = add(ans, mul(ans, cnt[i])); ans = add(ans, cnt[i]); } cout << ans << endl; return 0; }
// finish date: 2019/2/28 #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++) #define rep(i, n) FOR(i, 0, n) typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<double> vd; typedef vector<vector<double>> vvd; typedef vector<vector<vector<double>>> vvvd; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<ll, pair<int, int>> plii; const int bigmod = 1000000007; const int INF = 1050000000; const long long INFll = 100000000000000000; // 足し算 int add(int a, int b) { return (int)(((ll)a + b + bigmod) % bigmod); } // 引き算 int sub(int a, int b) { return (int)(((ll)a - b + bigmod) % bigmod); } // 掛け算 int mul(int a, int b) { return (int)(((ll)(a % bigmod) * (b % bigmod)) % bigmod); } int main() { int N; string S; cin >> N >> S; vi cnt(26, 0); rep(i, N) { cnt[S[i] - 'a']++; } int ans = 0; rep(i, 26) { if (cnt[i] == 0) continue; ans = add(ans, mul(ans, cnt[i])); ans = add(ans, cnt[i]); } cout << ans << endl; return 0; }
replace
48
49
48
49
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll mod = 1e9 + 7; int n; string s; string a = "abcdefghijklmnopqrstuvwxyz"; cin >> n >> s; ll ans = 1; ll vec[26] = {}; for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { if (s[i] == a[j]) { vec[j]++; } } } for (int i = 0; i < n; i++) { ans *= vec[i] + 1; ans %= mod; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll mod = 1e9 + 7; int n; string s; string a = "abcdefghijklmnopqrstuvwxyz"; cin >> n >> s; ll ans = 1; ll vec[26] = {}; for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { if (s[i] == a[j]) { vec[j]++; } } } for (int i = 0; i < 26; i++) { ans *= vec[i] + 1; ans %= mod; } cout << ans - 1 << endl; }
replace
19
20
19
20
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF (((ll)1 << 31) - 1) #define eps LDBL_EPSILON #define moder (1000000007) #define pie 3.141592653589793238462643383279 #define P std::pair<int, int> #define prique priority_queue #define ggr \ getchar(); \ getchar(); \ return 0; using namespace std; int n; string s; int a[26]; int dp[26]; signed main() { cin >> n >> s; rep(i, n) { a[s[i] - 'a']++; } int ans = 1; rep(i, n) { ans *= (a[i] + 1); ans %= moder; } cout << ans - 1 << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF (((ll)1 << 31) - 1) #define eps LDBL_EPSILON #define moder (1000000007) #define pie 3.141592653589793238462643383279 #define P std::pair<int, int> #define prique priority_queue #define ggr \ getchar(); \ getchar(); \ return 0; using namespace std; int n; string s; int a[26]; int dp[26]; signed main() { cin >> n >> s; rep(i, n) { a[s[i] - 'a']++; } int ans = 1; rep(i, 26) { ans *= (a[i] + 1); ans %= moder; } cout << ans - 1 << endl; return 0; }
replace
23
24
23
24
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int cnt[256]; void solve() { int n; string s; cin >> n >> s; for (int i = 0; i < n; i++) cnt[s[i]]++; ll ret = 1; for (int i = 0; i < 256; i++) { ret *= ++s[i]; ret %= 1000000007; } ret--; cout << ret << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int cnt[256]; void solve() { int n; string s; cin >> n >> s; for (int i = 0; i < n; i++) cnt[s[i]]++; ll ret = 1; for (int i = 0; i < 256; i++) { ret *= ++cnt[i]; ret %= 1000000007; } ret--; cout << ret << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
replace
17
18
17
18
-6
*** stack smashing detected ***: terminated
p03095
C++
Runtime Error
// スタックサイズ: 100MB #include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef int64_t ll; const ll INF = 1000000000000000000; #define fori(i, a, b) for (ll i = (a); i < (b); ++i) #define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i) #define rep(i, n) fori(i, 0, n) #define vll vector<ll> #define all(v) (v).begin(), (v).end() // mod演算ライブラリ (factset以降に関しては, modは素数限定) ll mod = 1000000007; ll mul_mod(ll a, ll b) { // a * b return ((a % mod) * (b % mod)) % mod; } int main() { ll N; string S; cin >> N; cin >> S; vll alfa(26, 0); rep(i, N) { alfa[S[i] - 'a'] += 1; } ll ans = 1; rep(i, N) { ans = mul_mod(alfa[i] + 1, ans); } cout << ans - 1 << endl; }
// スタックサイズ: 100MB #include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef int64_t ll; const ll INF = 1000000000000000000; #define fori(i, a, b) for (ll i = (a); i < (b); ++i) #define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i) #define rep(i, n) fori(i, 0, n) #define vll vector<ll> #define all(v) (v).begin(), (v).end() // mod演算ライブラリ (factset以降に関しては, modは素数限定) ll mod = 1000000007; ll mul_mod(ll a, ll b) { // a * b return ((a % mod) * (b % mod)) % mod; } int main() { ll N; string S; cin >> N; cin >> S; vll alfa(26, 0); rep(i, N) { alfa[S[i] - 'a'] += 1; } ll ans = 1; rep(i, 26) { ans = mul_mod(alfa[i] + 1, ans); } cout << ans - 1 << endl; }
replace
42
43
42
43
0
p03095
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define ll long long #define rep(i, s, n) for (int i = s; i < n; i++) #define MOD 1000000007; int main() { int n; cin >> n; string s; cin >> s; ll ans = 1; vector<int> count(26, 0); for (int i = 0; i < n; i++) { count[s[i] - 'a']++; } rep(i, 0, n) { if (count[i] == 0) { continue; } ans *= count[i] + 1; ans %= MOD; } cout << ans - 1 << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define ll long long #define rep(i, s, n) for (int i = s; i < n; i++) #define MOD 1000000007; int main() { int n; cin >> n; string s; cin >> s; ll ans = 1; vector<int> count(26, 0); for (int i = 0; i < n; i++) { count[s[i] - 'a']++; } rep(i, 0, count.size()) { if (count[i] == 0) { continue; } ans *= count[i] + 1; ans %= MOD; } cout << ans - 1 << endl; }
replace
23
24
23
24
0
p03095
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) 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; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } const lint MOD = 1e9 + 7, INF = 1e18; template <std::int_fast64_t Modulus> class modint { using u64 = std::int_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; typedef modint<MOD> ModInt; ModInt mod_pow(ModInt x, ModInt n) { ModInt ret = 1; while (n.a > 0) { if (n.a & 1) (ret *= x); (x *= x); n.a >>= 1; } return ret; } lint N; string s; lint cnt[26]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> s; REP(i, N) { cnt[s[i] - 'a']++; } ModInt ans = 0; REP(i, 1 << 26) { if (i == 0) continue; ModInt sum = 1; REP(j, 26) { if ((i >> j) % 2 == 1) { sum *= cnt[j]; } } ans += sum; } cout << ans.a << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (lint i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (lint i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) 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; } template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); } template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); } const lint MOD = 1e9 + 7, INF = 1e18; template <std::int_fast64_t Modulus> class modint { using u64 = std::int_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; typedef modint<MOD> ModInt; ModInt mod_pow(ModInt x, ModInt n) { ModInt ret = 1; while (n.a > 0) { if (n.a & 1) (ret *= x); (x *= x); n.a >>= 1; } return ret; } lint N; string s; lint cnt[26]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> s; REP(i, N) { cnt[s[i] - 'a']++; } ModInt ans = 1; REP(i, 26) ans *= (cnt[i] + 1); cout << ans.a - 1 << endl; }
replace
109
122
109
112
TLE
p03095
C++
Runtime Error
#include <bits/stdc++.h> //{ START using namespace std; #define int int64_t #define rep(i, a, n) for (int i = (a); i < (n); ++i) #define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i) #define arep(i, x) for (auto &&i : (x)) #define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i) #define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i) // 降順はgreater<T>() #define all(x) (x).begin(), (x).end() #define rv(s) reverse((s).begin(), (s).end()) // gcd lcmはそのままok #define gcd(a, b) __gcd(a, b) #define bits(n) (1LL << (n)) #define pcnt(x) __builtin_popcountll(x) // 配列内等要素削除 #define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end()) #define Fixed(n) fixed << setprecision(n) // 総和 #define sowa(n) (((n) * ((n) + 1)) / 2) #define updiv(a, b) ((a + b - 1) / b) #define cauto const auto & using P = pair<int, int>; using Graph = vector<vector<P>>; template <class T> // 昇順 using min_heap = priority_queue<T, vector<T>, greater<T>>; template <class T> // 降順 using max_heap = priority_queue<T>; template <class A, class B> using umap = unordered_map<A, B>; template <class A> using uset = unordered_set<A>; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { // 多次元初期化 std::fill((T *)array, (T *)(array + N), val); } template <class A, class B> bool chmax(A &a, const B &b) { // 最大値更新 返り値はbool if (a < b) { a = b; return 1; } return 0; } template <class A, class B> bool chmin(A &a, const B &b) { // 最小値更新 返り値はbool if (b < a) { a = b; return 1; } return 0; } int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1}; constexpr int INF = 0x3f3f3f3f; constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9 + 7; constexpr int mod2 = 998244353; //} END signed main(void) { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> x(27, 0); string s; cin >> s; int ans = 1; rep(i, 0, n) x[s[i] - 'a']++; rep(i, 0, n) { if (x[i] != 0) { ans *= (x[i] + 1); ans %= mod1; } } cout << ans - 1 << '\n'; return 0; }
#include <bits/stdc++.h> //{ START using namespace std; #define int int64_t #define rep(i, a, n) for (int i = (a); i < (n); ++i) #define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i) #define arep(i, x) for (auto &&i : (x)) #define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i) #define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i) // 降順はgreater<T>() #define all(x) (x).begin(), (x).end() #define rv(s) reverse((s).begin(), (s).end()) // gcd lcmはそのままok #define gcd(a, b) __gcd(a, b) #define bits(n) (1LL << (n)) #define pcnt(x) __builtin_popcountll(x) // 配列内等要素削除 #define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end()) #define Fixed(n) fixed << setprecision(n) // 総和 #define sowa(n) (((n) * ((n) + 1)) / 2) #define updiv(a, b) ((a + b - 1) / b) #define cauto const auto & using P = pair<int, int>; using Graph = vector<vector<P>>; template <class T> // 昇順 using min_heap = priority_queue<T, vector<T>, greater<T>>; template <class T> // 降順 using max_heap = priority_queue<T>; template <class A, class B> using umap = unordered_map<A, B>; template <class A> using uset = unordered_set<A>; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { // 多次元初期化 std::fill((T *)array, (T *)(array + N), val); } template <class A, class B> bool chmax(A &a, const B &b) { // 最大値更新 返り値はbool if (a < b) { a = b; return 1; } return 0; } template <class A, class B> bool chmin(A &a, const B &b) { // 最小値更新 返り値はbool if (b < a) { a = b; return 1; } return 0; } int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1}; constexpr int INF = 0x3f3f3f3f; constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9 + 7; constexpr int mod2 = 998244353; //} END signed main(void) { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> x(27, 0); string s; cin >> s; int ans = 1; rep(i, 0, n) x[s[i] - 'a']++; rep(i, 0, 26) { if (x[i] != 0) { ans *= (x[i] + 1); ans %= mod1; } } cout << ans - 1 << '\n'; return 0; }
replace
72
73
72
73
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll cnt[30]; ll pow_2(ll x) { ll ret = 1; for (int i = 0; i < x; i++) { ret = ret * 2 % 1000000007; } return ret; } int main() { string s; int n; cin >> n >> s; for (int i = 0; i < n; i++) { cnt[s[i] - 'a']++; } ll cnt2 = 0; ll ans = 1; for (int i = 0; i < n; i++) { if (cnt[i] == 1) { cnt2++; } else if (cnt[i] > 1) { ans *= 1 + cnt[i]; } ans %= 1000000007; } if (cnt2 == n) cout << pow_2(cnt2) - 1 << endl; else cout << pow_2(cnt2) * ans % 1000000007 - 1 << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; ll cnt[30]; ll pow_2(ll x) { ll ret = 1; for (int i = 0; i < x; i++) { ret = ret * 2 % 1000000007; } return ret; } int main() { string s; int n; cin >> n >> s; for (int i = 0; i < n; i++) { cnt[s[i] - 'a']++; } ll cnt2 = 0; ll ans = 1; for (int i = 0; i < 26; i++) { if (cnt[i] == 1) { cnt2++; } else if (cnt[i] > 1) { ans *= 1 + cnt[i]; } ans %= 1000000007; } if (cnt2 == n) cout << pow_2(cnt2) - 1 << endl; else cout << pow_2(cnt2) * ans % 1000000007 - 1 << endl; return 0; }
replace
25
26
25
26
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #include <chrono> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repl(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++) int main() { ll N; string S; cin >> N >> S; vector<ll> count(26, 0); rep(i, N) { char s = S[i]; int num = (int)(s - 'a'); count[num]++; } ll ans = 1; rep(i, N) { ans *= (count[i] + 1); ans %= 1000000007; } if (ans == 0) { cout << 1000000006 << endl; } else { cout << ans - 1 << endl; } }
#include <bits/stdc++.h> #include <chrono> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repl(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++) int main() { ll N; string S; cin >> N >> S; vector<ll> count(26, 0); rep(i, N) { char s = S[i]; int num = (int)(s - 'a'); count[num]++; } ll ans = 1; rep(i, 26) { ans *= (count[i] + 1); ans %= 1000000007; } if (ans == 0) { cout << 1000000006 << endl; } else { cout << ans - 1 << endl; } }
replace
21
22
21
22
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; const int dx[4] = {+1, 0, -1, 0}; const int dy[4] = {0, -1, 0, +1}; int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n; cin >> n; string str; cin >> str; ll cnt[26]; for (int i = 0; i < 26; i++) cnt[i] = 0; for (int i = 0; i < n; i++) { cnt[str[i] - 'a']++; } ll ans = 1; for (int i = 0; i < n; i++) { ans = (ans * (cnt[i] + 1)) % MOD; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; const int dx[4] = {+1, 0, -1, 0}; const int dy[4] = {0, -1, 0, +1}; int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n; cin >> n; string str; cin >> str; ll cnt[26]; for (int i = 0; i < 26; i++) cnt[i] = 0; for (int i = 0; i < n; i++) { cnt[str[i] - 'a']++; } ll ans = 1; for (int i = 0; i < 26; i++) { ans = (ans * (cnt[i] + 1)) % MOD; } cout << ans - 1 << endl; }
replace
25
26
25
26
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { int n; string s; cin >> n >> s; vector<ll> l(26, 0); rep(i, n) l.at(s.at(i) - 'a')++; ll ans = 1; rep(i, n) { ans *= (l.at(i) + 1); ans %= 1000000007; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { int n; string s; cin >> n >> s; vector<ll> l(26, 0); rep(i, n) l.at(s.at(i) - 'a')++; ll ans = 1; rep(i, 26) { ans *= (l.at(i) + 1); ans %= 1000000007; } cout << ans - 1 << endl; }
replace
16
17
16
17
0
p03095
C++
Time Limit Exceeded
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> #define _USE_MATH_DEFINES #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> using namespace std; #define EPS 1e-12 #define ull unsigned long long #define ll long long #define VI vector<ll> #define PII pair<ll, ll> #define VVI vector<vector<ll>> #define REP(i, n) for (int i = 0, _n = (n); (i) < (int)_n; ++i) #define RANGE(i, a, b) for (int i = (int)a, _b = (int)(b); (i) < _b; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define ALLR(c) (c).rbegin(), (c).rend() #define PB push_back #define MP(a, b) make_pair(a, b) #define POPCOUNT __builtin_popcount #define POPCOUNTLL __builtin_popcountll #define CLEAR(table, v) memset(table, v, sizeof(table)); #define PRINT1(table, D0) \ REP(d0, D0) cout << table[d0] << " "; \ cout << "\n"; #define PRINT2(table, D0, D1) \ REP(d0, D0) { \ REP(d1, D1) cout << table[d0][d1] << " "; \ cout << "\n"; \ } #define PRINT3(table, D0, D1, D2) \ REP(d0, D0) { \ REP(d1, D1) { \ REP(d2, D2) cout << table[d0][d1][d2] << " "; \ cout << "\n"; \ } \ cout << "\n"; \ } #define UNIFORM_DOUBLE(a, b) \ (((b - a) * (double)rand() / RAND_MAX) + a) // [a, b) #define UNIFORM_LL(a, b) (ll) UNIFORM_DOUBLE(a, b) // [a, b) #define IN(v, lo, hi) ((lo) <= (v) && (v) < (hi)) #define DD(v) cout << #v << ": " << v << endl template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const map<T0, T1> &v) { for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) { os << p->first << ": " << p->second << " "; } return os; } template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const pair<T0, T1> &v) { os << v.first << ": " << v.second << " "; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << " "; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<vector<T>> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << endl; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const set<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const deque<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } #define MOD 1000000007LL #define INF (1LL << 60) struct modll { static const ll MODVAL; ll val; modll() : val(0) {} modll(ll v) : val(v) { normalize(); } void normalize() { val = (val + MODVAL) % MODVAL; } modll operator+(ll v) { return modll(val + v); } modll &operator+=(ll v) { val += v; normalize(); return *this; } modll operator-(ll v) { return modll(val - v); } modll &operator-=(ll v) { val -= v; normalize(); return *this; } modll operator*(ll v) { return modll(val * v); } modll &operator*=(ll v) { val *= v; normalize(); return *this; } modll operator^(ll e) { modll x(val); modll v(1); for (; e; x = x * x, e >>= 1) if (e & 1) v = v * x; return v; } // pow modll inv() { modll x(val); return x ^ (MODVAL - 2); } // MODVAL must be prime number when use this! static modll inv(ll v) { return modll(v).inv(); } operator ll() { return val; } }; const ll modll::MODVAL = 1000000007; std::ostream &operator<<(std::ostream &os, const modll &v) { os << v.val; return os; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; string s; while (cin >> N >> s) { vector<modll> co(26, 0); REP(i, N) co[s[i] - 'a'] += 1; modll ans = 0; RANGE(bi, 1, 1 << 26) { modll lans = 1; REP(ci, 26) { if (bi >> ci & 1) lans *= co[ci]; } ans += lans; } cout << ans << endl; } return 0; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> #define _USE_MATH_DEFINES #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> using namespace std; #define EPS 1e-12 #define ull unsigned long long #define ll long long #define VI vector<ll> #define PII pair<ll, ll> #define VVI vector<vector<ll>> #define REP(i, n) for (int i = 0, _n = (n); (i) < (int)_n; ++i) #define RANGE(i, a, b) for (int i = (int)a, _b = (int)(b); (i) < _b; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define ALLR(c) (c).rbegin(), (c).rend() #define PB push_back #define MP(a, b) make_pair(a, b) #define POPCOUNT __builtin_popcount #define POPCOUNTLL __builtin_popcountll #define CLEAR(table, v) memset(table, v, sizeof(table)); #define PRINT1(table, D0) \ REP(d0, D0) cout << table[d0] << " "; \ cout << "\n"; #define PRINT2(table, D0, D1) \ REP(d0, D0) { \ REP(d1, D1) cout << table[d0][d1] << " "; \ cout << "\n"; \ } #define PRINT3(table, D0, D1, D2) \ REP(d0, D0) { \ REP(d1, D1) { \ REP(d2, D2) cout << table[d0][d1][d2] << " "; \ cout << "\n"; \ } \ cout << "\n"; \ } #define UNIFORM_DOUBLE(a, b) \ (((b - a) * (double)rand() / RAND_MAX) + a) // [a, b) #define UNIFORM_LL(a, b) (ll) UNIFORM_DOUBLE(a, b) // [a, b) #define IN(v, lo, hi) ((lo) <= (v) && (v) < (hi)) #define DD(v) cout << #v << ": " << v << endl template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const map<T0, T1> &v) { for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) { os << p->first << ": " << p->second << " "; } return os; } template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const pair<T0, T1> &v) { os << v.first << ": " << v.second << " "; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << " "; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<vector<T>> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << endl; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const set<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const deque<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } #define MOD 1000000007LL #define INF (1LL << 60) struct modll { static const ll MODVAL; ll val; modll() : val(0) {} modll(ll v) : val(v) { normalize(); } void normalize() { val = (val + MODVAL) % MODVAL; } modll operator+(ll v) { return modll(val + v); } modll &operator+=(ll v) { val += v; normalize(); return *this; } modll operator-(ll v) { return modll(val - v); } modll &operator-=(ll v) { val -= v; normalize(); return *this; } modll operator*(ll v) { return modll(val * v); } modll &operator*=(ll v) { val *= v; normalize(); return *this; } modll operator^(ll e) { modll x(val); modll v(1); for (; e; x = x * x, e >>= 1) if (e & 1) v = v * x; return v; } // pow modll inv() { modll x(val); return x ^ (MODVAL - 2); } // MODVAL must be prime number when use this! static modll inv(ll v) { return modll(v).inv(); } operator ll() { return val; } }; const ll modll::MODVAL = 1000000007; std::ostream &operator<<(std::ostream &os, const modll &v) { os << v.val; return os; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; string s; while (cin >> N >> s) { vector<modll> co(26, 0); REP(i, N) co[s[i] - 'a'] += 1; modll ans = 1; REP(i, 26) ans *= co[i] + 1LL; ans -= 1; cout << ans << endl; } return 0; }
replace
155
164
155
158
TLE
p03095
C++
Runtime Error
/* `-:://:::- `//:-------:/:` .+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .o:--...```..---+/` `/y+o/---....---:+o. `...````-os+/:---:/+o/--.` `-/+++++/:. `...` :h+d+oooo+/+-` ... `/++//:::://++-`....` -.`//````````:` `..` `o+/::------://o/` `-` -. -` `..` `---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..`` `....o+:-++/:--.```..-://s. `-` .- -` `-o: .-//::::/:-` `:s+/:--....-::/+s-` .- `- -` -///:--------:/:` ./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ `+:--........--:/` .:ooo+++++osso-` `.:-...`/` ./::-------:/:` -` :+--..``````.--:+:...-+:-` `.-/+++++/+-.-` -. ``:so:/:--.......--:+` `-```````o+/+--..`````..--:o/-..:s+:. ```````:``.. `-` -` `+:--..`````..--/+-.../.`````..-o:--.......---/o. ` `: `:- -. .o:--..`` ``..--:o` `-` `:o+:--------:+o-` `-`-... .. .o/--...```..--:+/` `-` `oy/so/////++o/.` -/` `-` `- ``+s/o/:---...---:++. `-` .-../d://///:-.` `.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-. ```` `:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `- -++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `- `` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.- -----ss+:++/:--.```..-://s. /. `:: `-:. ./` `````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-` `-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-` `:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-` `./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:. ``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `- `.:--h.``..``` -.-`.- .- `+:--..`````..--//` `- /s-//::::::::. -` `/- .. .o:--..`` ``..--:o.```.- `//:--------://` -` .-`.-` -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+` ..`-. `-. ``:os:o/:---...---:++. `- ``///+:-..``````.--:+-````-.` `.:///////.-` .:-..` -``-+o+/:::::/+o/. `- `:+:-..`````..--:o/:--/ys+- `-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o. `.` `++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-` `````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.` -----syo/o+/:--.```..-://s. .-` `- .- `... ``-:////:-`` .` `/s//:--....-::/+s. -. `-` .- `..` .+o+/:::--:://+s/-..` .::+y ``` .- `..` ./oo++////+oso-` `.... :y-+:::::::/` ... `.:+oooooo/-` `....-. .//:-------:/:-.` ``...`` /+:+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .+/--...```..--:+/` `-o/:---...---:++. `-+o+/:---:/+o/. `.:+oooo+/-.` `````` */ #ifdef aimbot #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #endif #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <limits> #include <list> #include <map> #include <ostream> #include <queue> #include <random> #include <set> #include <string> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <vector> #define random escape__from__random__aetuhoetnuhshe #define mt make_tuple #define x first #define y second #define pb push_back #define ppb pop_back #define mp make_pair #define umap unordered_map #define uset unordered_set #define elif else if #define len(v) ((int)v.size()) #define f(i, n) for (int i = 0; i < (n); i++) #define rof(i, n) for (int i = ((n)-1); i >= 0; i--) #define apply(v, act) \ for (auto &x : v) { \ act; \ } #define log(args...) \ { \ string s = #args; \ deque<string> deq; \ string buf = ""; \ int bal = 0; \ for (char c : s) { \ if (c == '(' || c == '[' || c == '{') { \ bal++; \ } else if (c == ')' || c == ']' || c == '}') { \ bal--; \ } else { \ if (bal == 0) { \ if (c == ',') { \ deq.pb(buf); \ buf = ""; \ } else { \ if (c != ' ') { \ buf += c; \ } \ } \ } \ } \ } \ if (!buf.empty()) { \ deq.pb(buf); \ } \ smart_io::precall_print(); \ smart_io::_print(deq, args); \ } #define print \ smart_io::precall_print(); \ cout, #define scan cin, #ifdef fast_allocator const int MAXMEM = 200 * 1000 * 1024; char _memory[MAXMEM]; size_t _ptr = 0; void *operator new(size_t _x) { _ptr += _x; assert(_ptr < MAXMEM); return _memory + _ptr - _x; } void operator delete(void *) noexcept {} #endif using namespace std; char string_in_buffer[(int)260]; void fast_scan(int &x) { scanf("%d", &x); } void fast_scan(long long &x) { scanf("%lld", &x); } void fast_scan(unsigned long long &x) { scanf("%llu", &x); } void fast_scan(double &x) { scanf("%lf", &x); } void fast_scan(long double &x) { scanf("%Lf", &x); } void fast_scan(char &x) { scanf("%c", &x); if (x == '\n') { fast_scan(x); } } void fast_scan(string &x) { scanf("%s", string_in_buffer); x = string(string_in_buffer); } template <class TFirst, class TSecond> void fast_scan(pair<TFirst, TSecond> &p) { fast_scan(p.first); fast_scan(p.second); } template <class T> void fast_scan(vector<T> &v) { for (auto &x : v) fast_scan(x); } void fast_print(const int &x) { printf("%d", x); } void fast_print(const unsigned int &x) { printf("%u", x); } void fast_print(const long long &x) { printf("%lld", x); } void fast_print(const unsigned long long &x) { printf("%llu", x); } void fast_print(const double &x) { printf("%.15lf", x); } void fast_print(const long double &x) { printf("%.15Lf", x); } void fast_print(const char &x) { printf("%c", x); }; void fast_print(const string &x) { printf("%s", x.c_str()); } void fast_print(const char v[]) { fast_print((string)v); } template <class TFirst, class TSecond> void fast_print(const pair<TFirst, TSecond> &p) { fast_print(p.first); fast_print(' '); fast_print(p.second); } template <class T> void fast_print(const vector<T> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print(' '); fast_print(v[i]); } } template <class T> void fast_print(const vector<vector<T>> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print('\n'); fast_print(v[i]); } } template <class T> void fast_print(const T &v) { for (const auto &x : v) { fast_print(x); fast_print(' '); } } using namespace std; namespace smart_io { string print_start = ""; string sep = " "; bool first_print = false; void precall_print() { fast_print(print_start); print_start = "\n"; first_print = true; } void _print(deque<string>) {} template <class T, class... Args> void _print(deque<string> names, T elem, Args... args) { if (!first_print) { fast_print("\n"); } else { first_print = false; } fast_print(names.front()); fast_print(" = "); fast_print(elem); names.pop_front(); _print(names, args...); } } // namespace smart_io template <class T> ostream &operator,(ostream &os, const T &object) { if (!smart_io::first_print) { fast_print(smart_io::sep); } else { smart_io::first_print = false; } fast_print(object); return os; } template <class T> istream &operator,(istream &is, T &object) { fast_scan(object); return is; } namespace random { using namespace std::chrono; mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch()) .count()); uniform_real_distribution<> prob_dist(0.0, 1.0); }; // namespace random namespace typedefs { typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef long double ld; } // namespace typedefs namespace numbers_operation { template <class T> T floor_mod(T a, T b) { if (a >= 0 && b >= 0) return a % b; if (a <= 0 && b <= 0) return a % b; return abs(b) - (abs(a) % abs(b)); } } // namespace numbers_operation using namespace numbers_operation; using namespace typedefs; using namespace random; const ll MOD = 1e9 + 7; template <ll MOD> struct Ring { ll value = 0; Ring() {} Ring(int _value) { value = _value; value = floor_mod(value, MOD); } Ring(ll _value) { value = _value; value = floor_mod(value, MOD); } Ring pow(ll p) const { if (p == 0) return 1; if (p & 1) { return Ring(value).pow(p - 1) * value; } else { Ring sub = Ring(value).pow(p / 2); return sub * sub; } } Ring inv() const { return pow(MOD - 2); } void operator*=(const Ring<MOD> &b) { value *= b.value; value = floor_mod(value, MOD); } friend Ring operator*(Ring<MOD> a, const Ring<MOD> &b) { a *= b; return a; } void operator+=(const Ring<MOD> &b) { value += b.value; value = floor_mod(value, MOD); } friend Ring operator+(Ring a, const Ring &b) { a += b; return a; } void operator-=(const Ring<MOD> &b) { value -= b.value; value = floor_mod(value, MOD); } friend Ring operator-(Ring a, const Ring &b) { a -= b; return a; } void operator/=(const Ring<MOD> &b) { (*this) *= b.inv(); } friend Ring operator/(Ring a, const Ring &b) { a /= b; return a; } bool operator==(const Ring<MOD> &b) { return value == b.value; } friend void fast_print(const Ring<MOD> &b) { fast_print(b.value); } }; typedef Ring<MOD> num; signed main(signed argc, char *argv[]) { int nn; scan nn; string s; scan s; map<char, int> cnt; for (char c : s) { cnt[c]++; } num rez = 1; for (auto p : cnt) { rez *= (p.y + 1); } print rez - 1; }
/* `-:://:::- `//:-------:/:` .+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .o:--...```..---+/` `/y+o/---....---:+o. `...````-os+/:---:/+o/--.` `-/+++++/:. `...` :h+d+oooo+/+-` ... `/++//:::://++-`....` -.`//````````:` `..` `o+/::------://o/` `-` -. -` `..` `---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..`` `....o+:-++/:--.```..-://s. `-` .- -` `-o: .-//::::/:-` `:s+/:--....-::/+s-` .- `- -` -///:--------:/:` ./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ `+:--........--:/` .:ooo+++++osso-` `.:-...`/` ./::-------:/:` -` :+--..``````.--:+:...-+:-` `.-/+++++/+-.-` -. ``:so:/:--.......--:+` `-```````o+/+--..`````..--:o/-..:s+:. ```````:``.. `-` -` `+:--..`````..--/+-.../.`````..-o:--.......---/o. ` `: `:- -. .o:--..`` ``..--:o` `-` `:o+:--------:+o-` `-`-... .. .o/--...```..--:+/` `-` `oy/so/////++o/.` -/` `-` `- ``+s/o/:---...---:++. `-` .-../d://///:-.` `.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-. ```` `:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `- -++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `- `` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.- -----ss+:++/:--.```..-://s. /. `:: `-:. ./` `````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-` `-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-` `:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-` `./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:. ``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `- `.:--h.``..``` -.-`.- .- `+:--..`````..--//` `- /s-//::::::::. -` `/- .. .o:--..`` ``..--:o.```.- `//:--------://` -` .-`.-` -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+` ..`-. `-. ``:os:o/:---...---:++. `- ``///+:-..``````.--:+-````-.` `.:///////.-` .:-..` -``-+o+/:::::/+o/. `- `:+:-..`````..--:o/:--/ys+- `-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o. `.` `++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-` `````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.` -----syo/o+/:--.```..-://s. .-` `- .- `... ``-:////:-`` .` `/s//:--....-::/+s. -. `-` .- `..` .+o+/:::--:://+s/-..` .::+y ``` .- `..` ./oo++////+oso-` `.... :y-+:::::::/` ... `.:+oooooo/-` `....-. .//:-------:/:-.` ``...`` /+:+:--.......--:+` `+:--..`````..--//` .o:--..`` ``..--:o` .+/--...```..--:+/` `-o/:---...---:++. `-+o+/:---:/+o/. `.:+oooo+/-.` `````` */ #ifdef aimbot #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #endif #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <limits> #include <list> #include <map> #include <ostream> #include <queue> #include <random> #include <set> #include <string> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <vector> #define random escape__from__random__aetuhoetnuhshe #define mt make_tuple #define x first #define y second #define pb push_back #define ppb pop_back #define mp make_pair #define umap unordered_map #define uset unordered_set #define elif else if #define len(v) ((int)v.size()) #define f(i, n) for (int i = 0; i < (n); i++) #define rof(i, n) for (int i = ((n)-1); i >= 0; i--) #define apply(v, act) \ for (auto &x : v) { \ act; \ } #define log(args...) \ { \ string s = #args; \ deque<string> deq; \ string buf = ""; \ int bal = 0; \ for (char c : s) { \ if (c == '(' || c == '[' || c == '{') { \ bal++; \ } else if (c == ')' || c == ']' || c == '}') { \ bal--; \ } else { \ if (bal == 0) { \ if (c == ',') { \ deq.pb(buf); \ buf = ""; \ } else { \ if (c != ' ') { \ buf += c; \ } \ } \ } \ } \ } \ if (!buf.empty()) { \ deq.pb(buf); \ } \ smart_io::precall_print(); \ smart_io::_print(deq, args); \ } #define print \ smart_io::precall_print(); \ cout, #define scan cin, #ifdef fast_allocator const int MAXMEM = 200 * 1000 * 1024; char _memory[MAXMEM]; size_t _ptr = 0; void *operator new(size_t _x) { _ptr += _x; assert(_ptr < MAXMEM); return _memory + _ptr - _x; } void operator delete(void *) noexcept {} #endif using namespace std; char string_in_buffer[(int)2e6]; void fast_scan(int &x) { scanf("%d", &x); } void fast_scan(long long &x) { scanf("%lld", &x); } void fast_scan(unsigned long long &x) { scanf("%llu", &x); } void fast_scan(double &x) { scanf("%lf", &x); } void fast_scan(long double &x) { scanf("%Lf", &x); } void fast_scan(char &x) { scanf("%c", &x); if (x == '\n') { fast_scan(x); } } void fast_scan(string &x) { scanf("%s", string_in_buffer); x = string(string_in_buffer); } template <class TFirst, class TSecond> void fast_scan(pair<TFirst, TSecond> &p) { fast_scan(p.first); fast_scan(p.second); } template <class T> void fast_scan(vector<T> &v) { for (auto &x : v) fast_scan(x); } void fast_print(const int &x) { printf("%d", x); } void fast_print(const unsigned int &x) { printf("%u", x); } void fast_print(const long long &x) { printf("%lld", x); } void fast_print(const unsigned long long &x) { printf("%llu", x); } void fast_print(const double &x) { printf("%.15lf", x); } void fast_print(const long double &x) { printf("%.15Lf", x); } void fast_print(const char &x) { printf("%c", x); }; void fast_print(const string &x) { printf("%s", x.c_str()); } void fast_print(const char v[]) { fast_print((string)v); } template <class TFirst, class TSecond> void fast_print(const pair<TFirst, TSecond> &p) { fast_print(p.first); fast_print(' '); fast_print(p.second); } template <class T> void fast_print(const vector<T> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print(' '); fast_print(v[i]); } } template <class T> void fast_print(const vector<vector<T>> &v) { if (v.empty()) return; fast_print(v[0]); for (int i = 1; i < v.size(); i++) { fast_print('\n'); fast_print(v[i]); } } template <class T> void fast_print(const T &v) { for (const auto &x : v) { fast_print(x); fast_print(' '); } } using namespace std; namespace smart_io { string print_start = ""; string sep = " "; bool first_print = false; void precall_print() { fast_print(print_start); print_start = "\n"; first_print = true; } void _print(deque<string>) {} template <class T, class... Args> void _print(deque<string> names, T elem, Args... args) { if (!first_print) { fast_print("\n"); } else { first_print = false; } fast_print(names.front()); fast_print(" = "); fast_print(elem); names.pop_front(); _print(names, args...); } } // namespace smart_io template <class T> ostream &operator,(ostream &os, const T &object) { if (!smart_io::first_print) { fast_print(smart_io::sep); } else { smart_io::first_print = false; } fast_print(object); return os; } template <class T> istream &operator,(istream &is, T &object) { fast_scan(object); return is; } namespace random { using namespace std::chrono; mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch()) .count()); uniform_real_distribution<> prob_dist(0.0, 1.0); }; // namespace random namespace typedefs { typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef long double ld; } // namespace typedefs namespace numbers_operation { template <class T> T floor_mod(T a, T b) { if (a >= 0 && b >= 0) return a % b; if (a <= 0 && b <= 0) return a % b; return abs(b) - (abs(a) % abs(b)); } } // namespace numbers_operation using namespace numbers_operation; using namespace typedefs; using namespace random; const ll MOD = 1e9 + 7; template <ll MOD> struct Ring { ll value = 0; Ring() {} Ring(int _value) { value = _value; value = floor_mod(value, MOD); } Ring(ll _value) { value = _value; value = floor_mod(value, MOD); } Ring pow(ll p) const { if (p == 0) return 1; if (p & 1) { return Ring(value).pow(p - 1) * value; } else { Ring sub = Ring(value).pow(p / 2); return sub * sub; } } Ring inv() const { return pow(MOD - 2); } void operator*=(const Ring<MOD> &b) { value *= b.value; value = floor_mod(value, MOD); } friend Ring operator*(Ring<MOD> a, const Ring<MOD> &b) { a *= b; return a; } void operator+=(const Ring<MOD> &b) { value += b.value; value = floor_mod(value, MOD); } friend Ring operator+(Ring a, const Ring &b) { a += b; return a; } void operator-=(const Ring<MOD> &b) { value -= b.value; value = floor_mod(value, MOD); } friend Ring operator-(Ring a, const Ring &b) { a -= b; return a; } void operator/=(const Ring<MOD> &b) { (*this) *= b.inv(); } friend Ring operator/(Ring a, const Ring &b) { a /= b; return a; } bool operator==(const Ring<MOD> &b) { return value == b.value; } friend void fast_print(const Ring<MOD> &b) { fast_print(b.value); } }; typedef Ring<MOD> num; signed main(signed argc, char *argv[]) { int nn; scan nn; string s; scan s; map<char, int> cnt; for (char c : s) { cnt[c]++; } num rez = 1; for (auto p : cnt) { rez *= (p.y + 1); } print rez - 1; }
replace
175
176
175
176
0
p03095
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> #include <sstream> #include <string> #include <vector> #define ll long long #define FOR(i, N) for (int i = 0; i < (int)N; i++) #define FORIN(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define LAST(x) (x)[(x).size() - 1] using namespace std; string to_hex(int x) { stringstream ss; ss << hex << x; return ss.str(); } string to_string(string s) { return s; } template <class T> string to_string(vector<T> v) { string ret = "{"; FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; } if (v.size() > 0) { ret += to_string(LAST(v)); } ret += "}"; return ret; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << " " << to_string(head); debug(tail...); } int main() { int N; cin >> N; string S; cin >> S; int list[26] = {}; FOR(i, S.size()) { list[S[i] - 'a']++; } int sm = 0; for (int i = 1; i < (1 << 26); ++i) { ll t = 1; int x; x = 32 - __builtin_clz(i); for (int j = 0; j < x; ++j) { // debug(i,j,t,i&(1<<j),list[j]); if ((i & (1 << j)) != 0) { t = (t * list[j]); if (t == 0) break; } } sm = (sm + t % 1000000007) % 1000000007; } cout << sm << endl; return 0; }
#include <cstdio> #include <iostream> #include <sstream> #include <string> #include <vector> #define ll long long #define FOR(i, N) for (int i = 0; i < (int)N; i++) #define FORIN(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define LAST(x) (x)[(x).size() - 1] using namespace std; string to_hex(int x) { stringstream ss; ss << hex << x; return ss.str(); } string to_string(string s) { return s; } template <class T> string to_string(vector<T> v) { string ret = "{"; FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; } if (v.size() > 0) { ret += to_string(LAST(v)); } ret += "}"; return ret; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << " " << to_string(head); debug(tail...); } int main() { int N; cin >> N; string S; cin >> S; int list[26] = {}; FOR(i, S.size()) { list[S[i] - 'a']++; } ll sm = 0; FOR(i, 26) { if (list[i] > 0) sm = (sm + list[i] * sm + list[i]) % 1000000007; } cout << sm << endl; return 0; }
replace
46
60
46
50
TLE
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int cnt[30]; const int MOD = 1e9 + 7; int main() { string s; int n; cin >> n >> s; for (int i = 0; i < n; i++) { cnt[s[i] - 'a']++; } long long ans = 1; for (int i = 0; i < n; i++) { ans = (ans * (cnt[i] + 1LL)) % MOD; } cout << (ans + MOD - 1) % MOD << endl; }
#include <bits/stdc++.h> using namespace std; int cnt[30]; const int MOD = 1e9 + 7; int main() { string s; int n; cin >> n >> s; for (int i = 0; i < n; i++) { cnt[s[i] - 'a']++; } long long ans = 1; for (int i = 0; i < 28; i++) { ans = (ans * (cnt[i] + 1LL)) % MOD; } cout << (ans + MOD - 1) % MOD << endl; }
replace
12
13
12
13
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using Int = long long; typedef pair<int, int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int, int> MP; const int mod = 1000000007; const Int INF = 1145141919810893931; #define END \ { \ cout << ans << '\n'; \ return 0; \ } template <class T> inline bool cmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool cmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { signed a = x, b = MOD, u = 1, v = 0; while (b) { signed t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } if (u < 0) u += Mod; ModInt res; res.x = (unsigned)u; return res; } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<mod> mint; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; mint ans = 1; int a[26] = {}; for (int i = 0; i < n; i++) a[s[i] - 'a']++; for (int i = 0; i < n; i++) if (a[i]) ans *= a[i] + 1; cout << (ans - 1).get() << '\n'; }
#include <bits/stdc++.h> using namespace std; using Int = long long; typedef pair<int, int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int, int> MP; const int mod = 1000000007; const Int INF = 1145141919810893931; #define END \ { \ cout << ans << '\n'; \ return 0; \ } template <class T> inline bool cmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool cmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { signed a = x, b = MOD, u = 1, v = 0; while (b) { signed t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } if (u < 0) u += Mod; ModInt res; res.x = (unsigned)u; return res; } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<mod> mint; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; mint ans = 1; int a[26] = {}; for (int i = 0; i < n; i++) a[s[i] - 'a']++; for (int i = 0; i < 26; i++) if (a[i]) ans *= a[i] + 1; cout << (ans - 1).get() << '\n'; }
replace
117
118
117
118
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) #define int long long using namespace std; typedef pair<int, int> P; #define F first #define S second int n; string s; int a[28]; unordered_set<int> st; signed main() { cin >> n; cin >> s; r(i, n) { a[s[i] - 'a']++; } int ans = 1, S = 0, sum = 0; r(i, 26) if (a[i]) S++; r(i, 26) { if (a[i]) { int x = a[i]; r(j, n) if (i < j && a[j]) { x *= (a[j] + 1); x %= 1000000007; } x %= 1000000007; ans += x; ans %= 1000000007; S--; } } /*r(i,(1<<26)){ int A=0,p=1; r(j,26){ if(i&(1<<j)){ A|=(1<<j); p*=a[j]; p%=1000000007; } } if(!st.count(A)&&p){ //cout<<A<<endl; st.insert(A); ans+=p; ans%=1000000007; } }*/ cout << ans - 1 << endl; }
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) #define int long long using namespace std; typedef pair<int, int> P; #define F first #define S second int n; string s; int a[28]; unordered_set<int> st; signed main() { cin >> n; cin >> s; r(i, n) { a[s[i] - 'a']++; } int ans = 1, S = 0, sum = 0; r(i, 26) if (a[i]) S++; r(i, 26) { if (a[i]) { int x = a[i]; r(j, 26) if (i < j && a[j]) { x *= (a[j] + 1); x %= 1000000007; } x %= 1000000007; ans += x; ans %= 1000000007; S--; } } /*r(i,(1<<26)){ int A=0,p=1; r(j,26){ if(i&(1<<j)){ A|=(1<<j); p*=a[j]; p%=1000000007; } } if(!st.count(A)&&p){ //cout<<A<<endl; st.insert(A); ans+=p; ans%=1000000007; } }*/ cout << ans - 1 << endl; }
replace
22
23
22
23
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define LOCAL using namespace std; template <typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream &operator<<(ostream &out, const array<T, N> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; #define int long long using P = pair<int, int>; // ######################################### const int mod = 1000000007; signed main() { int n; cin >> n; string s; cin >> s; int ret = 1; vector<int> cnt(24); rep(i, n) { cnt[s[i] - 'a']++; } rep(i, 24) { ret = (ret * (cnt[i] + 1)) % mod; } cout << ret - 1 << endl; return 0; }
#include <bits/stdc++.h> #define LOCAL using namespace std; template <typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream &operator<<(ostream &out, const array<T, N> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; #define int long long using P = pair<int, int>; // ######################################### const int mod = 1000000007; signed main() { int n; cin >> n; string s; cin >> s; int ret = 1; vector<int> cnt(26); rep(i, n) { cnt[(int)(s[i] - 'a')]++; } rep(i, 26) { ret = (ret * (cnt[i] + 1)) % mod; } cout << (ret - 1 + mod) % mod << endl; return 0; }
replace
81
85
81
85
0
p03095
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <vector> typedef char SINT8; typedef unsigned char UINT8; typedef short SINT16; typedef unsigned short UINT16; typedef int SINT32; typedef unsigned int UINT32; typedef long long SINT64; typedef unsigned long long UINT64; typedef double DOUBLE; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define MOD 1000000007 using namespace std; int main() { SINT32 N = 0; string S; SINT64 ANS = 1; cin >> N; cin >> S; vector<SINT32> DATA(26); for (SINT32 i = 0; i < N; i++) { DATA[i] = 0; } for (SINT32 i = 0; i < N; i++) { DATA[S[i] - 'a']++; } for (SINT32 i = 0; i < 26; i++) { ANS = ANS * ((DATA[i] + 1) % MOD); ANS = ANS % MOD; } ANS--; cout << ANS << endl; return 0; } // sort(DATA.begin(),DATA.end()); // sort(DATA.begin(),DATA.end(),std::greater<SINT32>()); // __gcd(ANS,DATA[i]); /* SINT32 M = 3; vector<pair<SINT32,SINT32>> DATA2(M); for (SINT32 i = 0; i < M; i++) { cin >> DATA2[i].first; cin >> DATA2[i].second; } sort(DATA2.begin(),DATA2.end()); cout << DATA2[0].first << endl; cout << DATA2[0].second << endl; */ // APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - //ADATA.begin(); BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - //BDATA.begin();
#include <algorithm> #include <cmath> #include <iostream> #include <vector> typedef char SINT8; typedef unsigned char UINT8; typedef short SINT16; typedef unsigned short UINT16; typedef int SINT32; typedef unsigned int UINT32; typedef long long SINT64; typedef unsigned long long UINT64; typedef double DOUBLE; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define MOD 1000000007 using namespace std; int main() { SINT32 N = 0; string S; SINT64 ANS = 1; cin >> N; cin >> S; vector<SINT32> DATA(26); for (SINT32 i = 0; i < 26; i++) { DATA[i] = 0; } for (SINT32 i = 0; i < N; i++) { DATA[S[i] - 'a']++; } for (SINT32 i = 0; i < 26; i++) { ANS = ANS * ((DATA[i] + 1) % MOD); ANS = ANS % MOD; } ANS--; cout << ANS << endl; return 0; } // sort(DATA.begin(),DATA.end()); // sort(DATA.begin(),DATA.end(),std::greater<SINT32>()); // __gcd(ANS,DATA[i]); /* SINT32 M = 3; vector<pair<SINT32,SINT32>> DATA2(M); for (SINT32 i = 0; i < M; i++) { cin >> DATA2[i].first; cin >> DATA2[i].second; } sort(DATA2.begin(),DATA2.end()); cout << DATA2[0].first << endl; cout << DATA2[0].second << endl; */ // APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - //ADATA.begin(); BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - //BDATA.begin();
replace
34
35
34
35
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double ll mod = 1e9 + 7; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; unordered_map<int, ll> m; for (int i = 0; i < n; i++) { m[s[i]]++; } ll dp[n + 1]; dp[0] = 1; for (int i = 1; i <= n; i++) { dp[i] = (dp[i - 1] * 2) % mod; } ll pre = 0; ll f = 1; ll ans = (dp[n] - 1) % mod; for (auto x : m) { ll a = x.second; ll b = n - a - pre; pre += a; ll d = (dp[a] - a - 1) % mod; ll g = dp[b]; ans = (ans - (((d * g) % mod) * f) % mod + mod) % mod; f = (f * (a + 1)) % mod; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double ll mod = 1e9 + 7; int main() { /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif*/ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; unordered_map<int, ll> m; for (int i = 0; i < n; i++) { m[s[i]]++; } ll dp[n + 1]; dp[0] = 1; for (int i = 1; i <= n; i++) { dp[i] = (dp[i - 1] * 2) % mod; } ll pre = 0; ll f = 1; ll ans = (dp[n] - 1) % mod; for (auto x : m) { ll a = x.second; ll b = n - a - pre; pre += a; ll d = (dp[a] - a - 1) % mod; ll g = dp[b]; ans = (ans - (((d * g) % mod) * f) % mod + mod) % mod; f = (f * (a + 1)) % mod; } cout << ans; }
replace
6
10
6
10
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; vector<char> vec(N); for (int i = 0; i < N; i++) { vec.at(i) = S.at(i); } sort(vec.begin(), vec.end()); long long ans = 1; long long count = 1; for (int j = 0; j < N - 1; j++) { if (vec.at(j) == vec.at(j + 1)) { count++; } else { ans = ans * (count + 1) % 1000000007; count = 1; } } if (vec.at(N - 2) == vec.at(N - 1)) { ans = ans * (count + 1) % 1000000007; } else { ans *= 2; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; vector<char> vec(N); for (int i = 0; i < N; i++) { vec.at(i) = S.at(i); } sort(vec.begin(), vec.end()); long long ans = 1; long long count = 1; for (int j = 0; j < N - 1; j++) { if (vec.at(j) == vec.at(j + 1)) { count++; } else { ans = ans * (count + 1) % 1000000007; count = 1; } } if (N == 1) { ans = 2; } else if (vec.at(N - 2) == vec.at(N - 1)) { ans = ans * (count + 1) % 1000000007; } else { ans *= 2; } cout << ans - 1 << endl; }
replace
22
24
22
25
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> s(26, 1); for (int i = 0; i < n; i++) { char c; cin >> c; s[c - 97]++; } long long ans = 1; for (int i = 0; i < n; i++) { ans *= s[i]; ans %= 1000000007; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> s(26, 1); for (int i = 0; i < n; i++) { char c; cin >> c; s[c - 97]++; } long long ans = 1; for (int i = 0; i < 26; i++) { ans *= s[i]; ans %= 1000000007; } cout << ans - 1 << endl; }
replace
15
16
15
16
0
p03095
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <fstream> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <string> #include <unordered_set> #include <vector> #define MOD_BIG 1000000007 #define MOD_BIG2 998244353 using std::cerr; using std::cin; using std::cout; using std::endl; using std::string; using ll = long long; using pint = std::pair<int, int>; using pll = std::pair<ll, ll>; using std::vector; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) ////////////////////////////////////// ////////////////////////////////////// int main() { int N; cin >> N; string S; cin >> S; vector<int> cnt(26); REP(i, N) { cnt[S[i] - 'a'] += 1; } ll ans = 1; REP(i, N) { ans *= (cnt[i] + 1); ans %= MOD_BIG; } ans -= 1; cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <fstream> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <string> #include <unordered_set> #include <vector> #define MOD_BIG 1000000007 #define MOD_BIG2 998244353 using std::cerr; using std::cin; using std::cout; using std::endl; using std::string; using ll = long long; using pint = std::pair<int, int>; using pll = std::pair<ll, ll>; using std::vector; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) ////////////////////////////////////// ////////////////////////////////////// int main() { int N; cin >> N; string S; cin >> S; vector<int> cnt(26); REP(i, N) { cnt[S[i] - 'a'] += 1; } ll ans = 1; REP(i, 26) { ans *= (cnt[i] + 1); ans %= MOD_BIG; } ans -= 1; cout << ans << endl; return 0; }
replace
45
46
45
46
0
p03095
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int N; string S; long long cnt[26] = {}; long long ans = 1; int main() { cin >> N >> S; for (int i = 0; i < N; i++) cnt[int(S[i] - 'a')]++; for (int i = 0; i < N; i++) ans = (long long)(ans * (cnt[i] + 1)) % (long long)(1e9 + 7); cout << ans - 1 << endl; return 0; }
#include <iostream> #include <string> using namespace std; int N; string S; long long cnt[26] = {}; long long ans = 1; int main() { cin >> N >> S; for (int i = 0; i < N; i++) cnt[int(S[i] - 'a')]++; for (int i = 0; i < 26; i++) ans = (long long)(ans * (cnt[i] + 1)) % (long long)(1e9 + 7); cout << ans - 1 << endl; return 0; }
replace
12
13
12
13
0
p03095
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define endl "\n" #define sz(x) ((ll)(x).size()) #define pb push_back #define all(x) (x).begin(), (x).end() #define prt(x) cout << (x) #define prtl(x) cout << (x) << endl #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 mp(a, b) make_pair(a, b) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define debug(v) cout << #v << ": " << v << endl; using namespace std; using vi = vector<int>; using vll = vector<long long int>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvi = vector<vector<int>>; using vvll = vector<vector<long long int>>; using vvc = vector<vector<char>>; using ll = long long int; using P = pair<long long int, long long int>; using Map = map<long long int, long long int>; ll INF = 1LL << 60; ll M = 1000000007; class Radix { private: const char *s; int a[128]; public: Radix(const char *s = "0123456789ABCDEF") : s(s) { int i; for (i = 0; s[i]; ++i) a[(int)s[i]] = i; } std::string to(long long p, int q) { int i; if (!p) return "0"; char t[64] = {}; for (i = 62; p; --i) { t[i] = s[p % q]; p /= q; } return std::string(t + i + 1); } std::string to(const std::string &t, int p, int q) { return to(to(t, p), q); } long long to(const std::string &t, int p) { int i; long long sm = a[(int)t[0]]; for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]]; return sm; } }; string bist(ll n, ll dig) { Radix r; string p = r.to(n, 2); string q = ""; if (p.size() < dig) { for (int i = 0; i < dig - p.size(); i++) { q += '0'; } p = q + p; } return p; } // [警告]nbaseの呼び出しを先にすること int main() { ll n; string s; cin >> n >> s; map<char, ll> m; rep(i, 0, n) { m[s[i]]++; } ll f = sz(m); ll ans = 0; rep(i, 0, pow(2, f)) { string c = bist(i, f); ll g = 1; ll t = 0; for (auto x : m) { if (c[t] == '1') { g *= x.second; g %= M; } t++; } ans += g; ans %= M; } prtl(ans - 1); }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define endl "\n" #define sz(x) ((ll)(x).size()) #define pb push_back #define all(x) (x).begin(), (x).end() #define prt(x) cout << (x) #define prtl(x) cout << (x) << endl #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 mp(a, b) make_pair(a, b) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define debug(v) cout << #v << ": " << v << endl; using namespace std; using vi = vector<int>; using vll = vector<long long int>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vc = vector<char>; using vvi = vector<vector<int>>; using vvll = vector<vector<long long int>>; using vvc = vector<vector<char>>; using ll = long long int; using P = pair<long long int, long long int>; using Map = map<long long int, long long int>; ll INF = 1LL << 60; ll M = 1000000007; class Radix { private: const char *s; int a[128]; public: Radix(const char *s = "0123456789ABCDEF") : s(s) { int i; for (i = 0; s[i]; ++i) a[(int)s[i]] = i; } std::string to(long long p, int q) { int i; if (!p) return "0"; char t[64] = {}; for (i = 62; p; --i) { t[i] = s[p % q]; p /= q; } return std::string(t + i + 1); } std::string to(const std::string &t, int p, int q) { return to(to(t, p), q); } long long to(const std::string &t, int p) { int i; long long sm = a[(int)t[0]]; for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]]; return sm; } }; string bist(ll n, ll dig) { Radix r; string p = r.to(n, 2); string q = ""; if (p.size() < dig) { for (int i = 0; i < dig - p.size(); i++) { q += '0'; } p = q + p; } return p; } // [警告]nbaseの呼び出しを先にすること int main() { ll n; string s; cin >> n >> s; map<char, ll> m; rep(i, 0, n) { m[s[i]]++; } ll f = sz(m); ll ans = 1; for (auto x : m) { ans *= x.second + 1; ans %= M; } prtl(ans - 1); }
replace
81
94
81
84
TLE
p03095
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> // using namespace boost::multiprecision; using namespace std; typedef long long ll; // typedef unsigned long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) // #define rep(i, n) for (ll i = 0; i < (n); ++i) // #define sz(x) ll(x.size()) typedef pair<int, int> P; // typedef pair<ll, int> P; // typedef pair<ll, ll> P; // const double INF = 1e10; const ll INF = LONG_LONG_MAX / 100; // const ll INF = (1ll << 31) - 1; // const ll INF = 1e15; const ll MINF = LONG_LONG_MIN; // const int INF = INT_MAX / 10; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) // typedef pair<int, int> P; // typedef pair<double, double> P; #define ret() return 0; bool contain(set<char> &s, char a) { return s.find(a) != s.end(); } // ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt"); // ofstream outfile("log.txt"); // outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') // << rank << endl; // std::cout << std::bitset<8>(9); const int mod = 1000000007; // const ll mod = 1e10; typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } friend std::istream &operator>>(std::istream &in, mint &o) { ll a; in >> a; o = a; return in; } friend std::ostream &operator<<(std::ostream &out, const mint &o) { out << o.x; return out; } }; int main() { int n; string s; cin >> n >> s; vector<int> counts(n, 1); for (char c : s) counts[c - 'a']++; mint ans = 1; for (int i : counts) ans *= i; ans = ans - 1; cout << ans << endl; }
#include <bits/stdc++.h> #include <cmath> // using namespace boost::multiprecision; using namespace std; typedef long long ll; // typedef unsigned long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) // #define rep(i, n) for (ll i = 0; i < (n); ++i) // #define sz(x) ll(x.size()) typedef pair<int, int> P; // typedef pair<ll, int> P; // typedef pair<ll, ll> P; // const double INF = 1e10; const ll INF = LONG_LONG_MAX / 100; // const ll INF = (1ll << 31) - 1; // const ll INF = 1e15; const ll MINF = LONG_LONG_MIN; // const int INF = INT_MAX / 10; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) // typedef pair<int, int> P; // typedef pair<double, double> P; #define ret() return 0; bool contain(set<char> &s, char a) { return s.find(a) != s.end(); } // ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt"); // ofstream outfile("log.txt"); // outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') // << rank << endl; // std::cout << std::bitset<8>(9); const int mod = 1000000007; // const ll mod = 1e10; typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } friend std::istream &operator>>(std::istream &in, mint &o) { ll a; in >> a; o = a; return in; } friend std::ostream &operator<<(std::ostream &out, const mint &o) { out << o.x; return out; } }; int main() { int n; string s; cin >> n >> s; vector<int> counts(27, 1); for (char c : s) counts[c - 'a']++; mint ans = 1; for (int i : counts) ans *= i; ans = ans - 1; cout << ans << endl; }
replace
110
111
110
111
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; vector<long long> c(26, 0); int main() { int N; string S; cin >> N >> S; for (int i = 0; i < N; i++) { c[S[i] - 'a']++; } long long ans = 1; for (int i = 0; i < N; i++) { ans *= c[i] + 1; if (ans >= MOD) ans %= MOD; } ans += MOD - 1; ans %= MOD; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; vector<long long> c(26, 0); int main() { int N; string S; cin >> N >> S; for (int i = 0; i < N; i++) { c[S[i] - 'a']++; } long long ans = 1; for (int i = 0; i < 26; i++) { ans *= c[i] + 1; if (ans >= MOD) ans %= MOD; } ans += MOD - 1; ans %= MOD; cout << ans << endl; return 0; }
replace
15
16
15
16
0
p03095
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1e9 + 7; string s; LL a[30], res = 0; int vis[30]; void dfs(int pos, int len, LL val) { if (!len) { res = (res + val) % mod; return; } for (int i = pos; i < 26; ++i) { if (!a[i]) continue; dfs(i + 1, len - 1, val * a[i] % mod); } return; } int main() { int n, k = 0; cin >> n >> s; for (int i = 0; i < n; ++i) { int t = s[i] - 'a'; if (!a[t]) k++; a[t]++; } for (int i = 1; i <= k; ++i) dfs(0, i, 1); cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1e9 + 7; string s; LL a[30], res = 0; int vis[30]; void dfs(int pos, int len, LL val) { if (!len) { res = (res + val) % mod; return; } for (int i = pos; i <= 26 - len; ++i) { if (!a[i]) continue; dfs(i + 1, len - 1, val * a[i] % mod); } return; } int main() { int n, k = 0; cin >> n >> s; for (int i = 0; i < n; ++i) { int t = s[i] - 'a'; if (!a[t]) k++; a[t]++; } for (int i = 1; i <= k; ++i) dfs(0, i, 1); cout << res; return 0; }
replace
13
14
13
14
TLE
p03095
C++
Runtime Error
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define MOD int(1e9 + 7) #define INF (long long)(1e18) int main() { long long N; vector<long long> c(26, 1); cin >> N; for (long long i = 0; i < N; i++) { char t; cin >> t; c[t - 'a']++; } long long total = 1; for (long long i = 0; i < N; i++) { total *= c[i]; total %= MOD; } cout << total - 1 << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define MOD int(1e9 + 7) #define INF (long long)(1e18) int main() { long long N; vector<long long> c(26, 1); cin >> N; for (long long i = 0; i < N; i++) { char t; cin >> t; c[t - 'a']++; } long long total = 1; for (long long i = 0; i < 26; i++) { total *= c[i]; total %= MOD; } cout << total - 1 << endl; }
replace
26
27
26
27
0
p03095
C++
Time Limit Exceeded
// #define DEBUG_IS_VALID #ifdef DEBUG_IS_VALID #define DEB 1 #define _LIBCPP_DEBUG 0 #else #define DEB 0 #define NDEBUG #endif #include "bits/stdc++.h" #define ALL(g) (g).begin(), (g).end() #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, x, n) for (int i = x; i >= n; i--) #define rrep(i, n) RREP(i, n, 0) #define pb push_back #pragma GCC optimize("-O3") using namespace std; #define DUMPOUT cout #define dump(...) \ if (DEB) \ DUMPOUT << " " << #__VA_ARGS__ << " :[" << __LINE__ << ":" \ << __FUNCTION__ << "]" << endl \ << " "; \ if (DEB) \ dump_func(__VA_ARGS__) template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { cout << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &st) { cout << "{"; for (auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr) != st.end() ? ", " : ""); cout << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> mp) { cout << "{"; for (auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr) != mp.end() ? "," : ""); cout << "}"; return os; } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); } template <class T> inline bool chmax(T &a, T const &b) { if (a >= b) return false; a = b; return true; } template <class T> inline bool chmin(T &a, T const &b) { if (a <= b) return false; a = b; return true; } void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); return 0; } using ll = long long; using P = pair<int, int>; using Pl = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int mod = 1e9 + 7, INF = 1 << 29; const double EPS = 1e-5, PI = 3.1415926535897932384626; const ll lmod = 1e9 + 7, LINF = 1LL << 59; template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) { st << a.get(); return st; }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template <typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb() { fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); for (int i = 1; i < FAC_MAX; i++) fac[i] = fac[i - 1] * i; ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; for (int i = FAC_MAX - 2; i >= 1; i--) ifac[i] = ifac[i + 1] * T(i + 1); } T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } }; // nHk = (n+k-1)Ck : n is separator using mint = ModInt<int(1e9 + 7)>; using vm = vector<mint>; void _main() { int N; cin >> N; string s; cin >> s; vm cnt(26); rep(i, N) { int idx = int(s[i] - 'a'); cnt[idx] += mint(1); } mint ans(0); REP(i, 1, 1 << 26) { mint temp(1); rep(j, 26) if ((i >> j) & 1) { temp *= cnt[j]; } ans += temp; } cout << ans << endl; }
// #define DEBUG_IS_VALID #ifdef DEBUG_IS_VALID #define DEB 1 #define _LIBCPP_DEBUG 0 #else #define DEB 0 #define NDEBUG #endif #include "bits/stdc++.h" #define ALL(g) (g).begin(), (g).end() #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, x, n) for (int i = x; i >= n; i--) #define rrep(i, n) RREP(i, n, 0) #define pb push_back #pragma GCC optimize("-O3") using namespace std; #define DUMPOUT cout #define dump(...) \ if (DEB) \ DUMPOUT << " " << #__VA_ARGS__ << " :[" << __LINE__ << ":" \ << __FUNCTION__ << "]" << endl \ << " "; \ if (DEB) \ dump_func(__VA_ARGS__) template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { cout << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &st) { cout << "{"; for (auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr) != st.end() ? ", " : ""); cout << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> mp) { cout << "{"; for (auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr) != mp.end() ? "," : ""); cout << "}"; return os; } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); } template <class T> inline bool chmax(T &a, T const &b) { if (a >= b) return false; a = b; return true; } template <class T> inline bool chmin(T &a, T const &b) { if (a <= b) return false; a = b; return true; } void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); return 0; } using ll = long long; using P = pair<int, int>; using Pl = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int mod = 1e9 + 7, INF = 1 << 29; const double EPS = 1e-5, PI = 3.1415926535897932384626; const ll lmod = 1e9 + 7, LINF = 1LL << 59; template <int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) { st << a.get(); return st; }; template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } template <typename T, int FAC_MAX> struct Comb { vector<T> fac, ifac; Comb() { fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); for (int i = 1; i < FAC_MAX; i++) fac[i] = fac[i - 1] * i; ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; for (int i = FAC_MAX - 2; i >= 1; i--) ifac[i] = ifac[i + 1] * T(i + 1); } T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; } T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; } T nHk(int n, int k) { if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0; return aCb(n + k - 1, k); } }; // nHk = (n+k-1)Ck : n is separator using mint = ModInt<int(1e9 + 7)>; using vm = vector<mint>; void _main() { int N; cin >> N; string s; cin >> s; vm cnt(26); rep(i, N) { int idx = int(s[i] - 'a'); cnt[idx] += mint(1); } mint ans(1); rep(i, 26) ans *= (mint(1) + cnt[i]); cout << ans - mint(1) << endl; }
replace
204
212
204
208
TLE
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define FLASH \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false); #define pb push_back #define int long long #define fr(i, a, b) for (int i = a; i < b; i++) #define mod 1000000007 #define FILEIO \ freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); \ freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout); using namespace std; int n; string s; signed main() { #ifndef ONLINE_JUDGE FILEIO #endif FLASH cin >> n >> s; int cnt[26] = {0}; fr(i, 0, n) { cnt[s[i] - 'a']++; } int ans = 1; fr(i, 0, 26) { ans *= (cnt[i] + 1); ans %= mod; } ans += mod - 1; ans %= mod; cout << ans << '\n'; }
#include <bits/stdc++.h> #define FLASH \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false); #define pb push_back #define int long long #define fr(i, a, b) for (int i = a; i < b; i++) #define mod 1000000007 #define FILEIO \ freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); \ freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout); using namespace std; int n; string s; signed main() { FLASH cin >> n >> s; int cnt[26] = {0}; fr(i, 0, n) { cnt[s[i] - 'a']++; } int ans = 1; fr(i, 0, 26) { ans *= (cnt[i] + 1); ans %= mod; } ans += mod - 1; ans %= mod; cout << ans << '\n'; }
replace
18
21
18
19
0
p03095
C++
Runtime Error
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; vector<int> cnt(26, 0); for (int i = 0; i < n; ++i) { ++cnt[s[i] - 'a']; } const ll mod = 1000000007; ll dp = 1; for (int i = 0; i < n; ++i) { dp = (dp * (ll)(cnt[i] + 1)) % mod; } dp += mod - 1; dp %= mod; cout << dp << endl; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; vector<int> cnt(26, 0); for (int i = 0; i < n; ++i) { ++cnt[s[i] - 'a']; } const ll mod = 1000000007; ll dp = 1; for (int i = 0; i < 26; ++i) { dp = (dp * (ll)(cnt[i] + 1)) % mod; } dp += mod - 1; dp %= mod; cout << dp << endl; }
replace
19
20
19
20
0
p03095
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; /////////////////////////////////////////// const long long int INF = 100000000000; const long long int Mod = 1000000007; using ll = long long int; // long long int は64bit using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int, int>; #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define mt make_tuple #define all(x) (x).begin(), (x).end() #define rep(i, N) for (int i = 0; i < N; i++) #define np nullptr template <class T> bool chmax(T &former, const T &b) { if (former <= b) { former = b; return true; } return false; } template <class T> bool chmin(T &former, const T &b) { if (b < former) { former = b; return true; } return false; } template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根; #define Sort(v) \ std::sort(v.begin(), v.end(), \ std::greater<decltype(v[0])>()) // 降順でVをソート #define fill(x, num) memset(x, num, sizeof(x)); typedef vector<vector<ll>> matrix; // cin.tie(0);ios::sync_with_stdio(false); void cinit() { cin.tie(0); ios::sync_with_stdio(false); } //////////////////////////^^ *Emile ///^^^////////////////////////////////////////////////////// ll n; string s; ll moji[27] = {0}; int main() { cin >> n >> s; rep(i, n) { moji[s[i] - 'a']++; } ll ans = 0; ll tmp = 0; for (ll mask = 1; mask < (1 << 26); mask++) { tmp = 1; rep(i, 26) { if (mask & (1 << i)) { if (tmp == 0) break; tmp *= moji[i]; tmp %= Mod; } } ans += tmp; ans %= Mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /////////////////////////////////////////// const long long int INF = 100000000000; const long long int Mod = 1000000007; using ll = long long int; // long long int は64bit using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int, int>; #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define mt make_tuple #define all(x) (x).begin(), (x).end() #define rep(i, N) for (int i = 0; i < N; i++) #define np nullptr template <class T> bool chmax(T &former, const T &b) { if (former <= b) { former = b; return true; } return false; } template <class T> bool chmin(T &former, const T &b) { if (b < former) { former = b; return true; } return false; } template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根; #define Sort(v) \ std::sort(v.begin(), v.end(), \ std::greater<decltype(v[0])>()) // 降順でVをソート #define fill(x, num) memset(x, num, sizeof(x)); typedef vector<vector<ll>> matrix; // cin.tie(0);ios::sync_with_stdio(false); void cinit() { cin.tie(0); ios::sync_with_stdio(false); } //////////////////////////^^ *Emile ///^^^////////////////////////////////////////////////////// ll n; string s; ll moji[27] = {0}; int main() { cin >> n >> s; rep(i, n) { moji[s[i] - 'a']++; } ll ans = 0; rep(i, 26) { ans += moji[i] * (ans + 1); ans %= Mod; } cout << ans << endl; return 0; }
replace
52
64
52
54
TLE
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; #define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++) #define REPR(i, n) for (ll i = n - 1; i >= 0LL; i--) #define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++) #define PRINT(x) cout << x << endl #define ALL(v) v.begin(), v.end() #define INF (ll)1e18 #define INFD 1e18 #define PI 3.14159265358979 #define MOD 1000000007 #define vl vector<ll> vector<ll> dx = {-1, 1, 0, 0}; vector<ll> dy = {0, 0, 1, -1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { ll N; cin >> N; vector<ll> C(N); REP(i, N) cin >> C[i]; vector<ll> c; c.push_back(0); c.push_back(C[0]); REP(i, N - 1) { if (C[i] != C[i + 1]) { c.push_back(C[i + 1]); } } vector<ll> dp(c.size() + 1); dp[1] = 1; vector<ll> pre(100001); pre[c[1]] = 1; // cout << "dp" << endl; // REP(j, dp.size()) cout << dp[j] << " "; // cout << endl; // cout << "pre" << endl; // REP(j, 10) cout << pre[j] << " "; // cout << endl; FOR(i, 2, dp.size()) { dp[i] = dp[i - 1] + dp[pre[c[i]]]; dp[i] %= MOD; pre[c[i]] = i; // cout << "dp" << endl; // REP(j, dp.size()) cout << dp[j] << " "; // cout << endl; // cout << "pre" << endl; // REP(j, 10) cout << pre[j] << " "; // cout << endl; } PRINT(dp.back()); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; #define REP(i, n) for (ll i = 0LL; i < (ll)(n); i++) #define REPR(i, n) for (ll i = n - 1; i >= 0LL; i--) #define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++) #define PRINT(x) cout << x << endl #define ALL(v) v.begin(), v.end() #define INF (ll)1e18 #define INFD 1e18 #define PI 3.14159265358979 #define MOD 1000000007 #define vl vector<ll> vector<ll> dx = {-1, 1, 0, 0}; vector<ll> dy = {0, 0, 1, -1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { ll N; cin >> N; vector<ll> C(N); REP(i, N) cin >> C[i]; vector<ll> c; c.push_back(0); c.push_back(C[0]); REP(i, N - 1) { if (C[i] != C[i + 1]) { c.push_back(C[i + 1]); } } vector<ll> dp(c.size() + 1); dp[1] = 1; vector<ll> pre(1000000); pre[c[1]] = 1; // cout << "dp" << endl; // REP(j, dp.size()) cout << dp[j] << " "; // cout << endl; // cout << "pre" << endl; // REP(j, 10) cout << pre[j] << " "; // cout << endl; FOR(i, 2, dp.size()) { dp[i] = dp[i - 1] + dp[pre[c[i]]]; dp[i] %= MOD; pre[c[i]] = i; // cout << "dp" << endl; // REP(j, dp.size()) cout << dp[j] << " "; // cout << endl; // cout << "pre" << endl; // REP(j, 10) cout << pre[j] << " "; // cout << endl; } PRINT(dp.back()); return 0; }
replace
39
40
39
40
0
p03096
C++
Runtime Error
#ifdef LOCAL // #define _GLIBCXX_DEBUG // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 #endif // #pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math #include <bits/stdc++.h> using namespace std; #define sq(x) (x) * (x) // square #define FAST_READ \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #ifdef LOCAL #define see(x) cout << "<DBG> " << #x << ": " << (x) << endl #endif #ifndef LOCAL #define see(x) #endif #define LSON(x) ((x)*2) #define RSON(x) ((x)*2 + 1) template <typename A, typename B> void Min(A &a, const B &b) { if (b < a) a = b; } template <typename A, typename B> void Max(A &a, const B &b) { if (b > a) a = b; } #if __cplusplus < 201402L template <class Iterator> std::reverse_iterator<Iterator> make_reverse_iterator(Iterator it) { return std::reverse_iterator<Iterator>(it); } #endif template <typename iter_t> struct iter_pair { iter_t _beg, _end; iter_t begin() { return _beg; } iter_t end() { return _end; } }; template <class cont> iter_pair<reverse_iterator<decltype(begin(declval<cont>()))>> reverse(cont &&r) { return {make_reverse_iterator(end(r)), make_reverse_iterator(begin(r))}; } template <typename T> void dprintln(const T &t) { cout << t << endl; } // for debug use template <typename T, typename... Args> void dprintln(const T &t, const Args &...rest) { cout << t << ' '; dprintln(rest...); } template <typename T> void println(const T &t) { cout << t << '\n'; } template <typename vec_t> void println_vec(const vec_t &vec) { for (const auto &ele : vec) { cout << ele << ' '; } cout << endl; } template <typename T, typename... Args> void println(const T &t, const Args &...rest) { cout << t << ' '; println(rest...); } template <typename T> void println(const vector<T> &vec) { for (const T &x : vec) { cout << x << ' '; } cout << endl; } template <typename T> void print(const T &t) { cout << t << ' '; } template <typename T, typename... Args> void print(const T &t, const Args &...rest) { cout << t << ' '; print(rest...); } // this overload is chosen when there's only one argument template <class T> void scan(T &t) { cin >> t; } template <class T, class... Args> void scan(T &a, Args &...rest) { cin >> a; scan(rest...); } template <typename T> void read(vector<T> &vec) { for (auto &x : vec) cin >> x; } using ull = unsigned long long; using ll = long long; using ul = unsigned long; using vl = vector<ll>; using vi = vector<int>; using pii = pair<int, int>; using vb = vector<bool>; using vpii = vector<pii>; template <typename int_t> inline int_t lowbit(int_t x) { return x & -x; } #define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define up(i, b, a) for (int i = int(b); i <= int(a); ++i) #define down(i, b, a) for (int i = int(b); i >= int(a); i--) #define rep(n) for (int _ = 0, __ = (int)n; _ < __; _++) #define stp(i, a, b, c) for (int i = (a); i < (b); i += (c)) #define FOR(x, cont) for (const auto &x : cont) #define INC(init, x, y) for (init; x <= y; ++x) #define For(x, cont) for (auto &x : cont) #define all(x) begin(x), end(x) #define pb push_back #define mp make_pair #define eb emplace_back #define SZ(x) (int)(x).size() #define UP(i, l, r) for (i = decltype(i)(l); i <= decltype(i)(r); ++i) #define DOWN(i, r, l) for (i = decltype(i)(r); i >= decltype(i)(l); --i) #define Dec(a, b) for (; a >= b; --a) template <typename T, typename Comp = less<T>> using pq = priority_queue<T, vector<T>, Comp>; #define popcnt(x) __builtin_popcountll((x)) #define SET(arr, v) memset(arr, (v), sizeof(arr)) #define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec)) #define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont)) #define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont)) #define AI(name, n, m) vv<int> name(n, vi(m)); #define AL(name, n, m) vv<ll> name(size_t(n), vl(size_t(m))); auto bet = [](const ll x, const ll y, const ll i) { return x <= i && i <= y; }; template <typename T1, typename T2> T1 ceil(T1 x, T2 y) { // y >= 1,是整数。需要注意 x + y - 1 是否会溢出 return (x + y - 1) / y; } inline int h_bit(unsigned long long x) { return sizeof(unsigned long long) * 8 - 1 - __builtin_clzll(x); } int pow2(int x) { // power of 2 return 1 << (h_bit((ull)x) + (x != lowbit(x))); } template <typename T> struct bit { vector<T> a; function<T(T, T)> bin_op; explicit bit(int n, function<T(T, T)> bin_op, T init) : bin_op(bin_op) { a.resize((size_t)n + 1); for (int i = 1; i <= n; ++i) a[i] = init; } T prefix(T x, T init) { while (x) { init = bin_op(a[x], init); x -= x & -x; } return init; } T sum(int l, int r) { if (l > r) return 0; return sum(r) - sum(l - 1); } void modify(int x, T v) { while (x < a.size()) { a[x] = bin_op(a[x], v); x += x & -x; } } void clear() { fill(a.begin(), a.end(), 0); } }; template <typename T> struct r_bit { vector<T> a; function<T(T, T)> bin_op; explicit r_bit(int n, function<T(T, T)> bin_op, T init) : bin_op(move(bin_op)) { a.resize((size_t)n + 1); for (int i = 1; i <= n; ++i) a[i] = init; } T suffix(int x, T init) { while (x < SZ(a)) { init = bin_op(init, a[x]); // res += a[x]; x += x & -x; } return init; } T sum(int l, int r) { if (l > r) return 0; return sum(r) - sum(l - 1); } void modify(int x, T v) { while (x > 0) { a[x] = bin_op(a[x], v); x -= x & -x; } } void clear() { fill(a.begin(), a.end(), 0); } }; vi get_prime(int n) { vi minp((ul)n + 1), p; for (int i = 2; i <= n; i++) { if (!minp[i]) { minp[i] = i; p.pb(i); } FOR(x, p) { if (x <= minp[i] && x * i <= n) minp[x * i] = x; else break; } } return p; } const int mod = 1e9 + 7; // 记住 mod 的行号! inline void mul(int &x, const int y) { x = int(ll(x) * y % mod); } inline int Mul(int x, const int y) { return (int)(ll(x) * y % mod); } template <typename T, typename U> inline void add(T &x, const U y) { x += y; if (x >= mod) x -= mod; } inline int Add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int Sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline ll submod(ll x, ll y) { return x >= y ? x - y : x - y + mod; } inline ll addmod(ll x, ll y) { x += y; return x >= mod ? x - mod : x; } inline void sub_mod(ll &x, const ll y) { x -= y; if (x < 0) x += mod; } // alias templates template <typename T> using vv = vector<vector<T>>; template <typename T1, typename T2 = T1> using vp = vector<pair<T1, T2>>; template <typename T, int n> using va = vector<array<T, n>>; #ifdef __GNUC__ #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> template <typename T> using rank_tree = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; #endif // union-find 并查集 struct UF { vi par, sz; int n_tree; explicit UF(int n) { // 0-indexed par.assign(n, 0); sz.assign(n, 1); rng(i, 0, n) par[i] = i; n_tree = n; } int n_cluster() const { return n_tree; } int size(int x) { return sz[root(x)]; } int root(int x) { return x == par[x] ? x : par[x] = root(par[x]); } bool unite(int x, int y) { int rx = root(x), ry = root(y); if (rx != ry) { par[rx] = ry; --n_tree; sz[ry] += sz[rx]; return true; } return false; } }; int fp(int x, ll n) { // fast power: hat off to quailty if (n < 0) { x = fp(x, mod - 2); n = -n; } int ans = 1; while (n) { if (n & 1) mul(ans, x); n /= 2; mul(x, x); } return ans; } using idx_t = long; template <typename T, typename Compare = std::less<T>> struct ST { size_t n{}; // 0-indexed vv<T> a; ST() = default; template <typename ptr_t> ST(ptr_t beg, ptr_t end) : n(end - beg) { a.resize((size_t)h_bit(n) + 1); // 注意:不能写成 h_bit(n) a[0].assign(beg, end); rng(i, 0, SZ(a) - 1) { a[i + 1].resize(n); rng(j, 0, n - (1 << i)) { a[i + 1][j] = min(a[i][j], a[i][j + (1 << i)], Compare()); } rng(j, n - (1 << i), n) { a[i + 1][j] = a[i][j]; } } } T query(idx_t l, idx_t r) { // l <= r int i = h_bit(r - l + 1ul); return min(a[i][l], a[i][r + 1 - (1 << i)], Compare()); } }; vi get_popcnt(int n) { vi res((ul)n + 1); rng(i, 0, n) { if (i * 2 <= n) res[i * 2] = res[i]; if ((i & 1) == 0) res[i + 1] = res[i] + 1; } return res; } using poly = vector<int>; void bit_reverse_swap(vector<int> &a) { int n = SZ(a); for (int i = 1, j = n >> 1, k; i < n - 1; i++) { if (i < j) swap(a[i], a[j]); // tricky for (k = n >> 1; j >= k; j -= k, k >>= 1) ; // inspect the highest "1" j += k; } } void FFT(vector<int> &a, int type) { bit_reverse_swap(a); int n = SZ(a); for (int i = 2; i <= n; i *= 2) { const auto wi = fp(3, type * (mod - 1) / i); // i次单位根 for (int j = 0; j < n; j += i) { auto w(1); for (int k = j, h = i >> 1; k < j + h; k++) { auto t = Mul(w, a[k + h]), u = a[k]; a[k] = Add(u, t); a[k + h] = Sub(u, t); mul(w, wi); } } } const int inv = fp(n, -1); if (type == -1) for (auto &x : a) mul(x, inv); } void fp(poly &a, const int n) { a.resize((ul)pow2((SZ(a) - 1) * n + 1)); FFT(a, 1); for (auto &x : a) x = fp(x, n); FFT(a, -1); } // DEBUG code by tourist string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // end DEBUG //////////////////*^"^*///////////////////////////////////// struct node { static const int sigma_size = 2; array<int, sigma_size> pos{}; bool is_accept_state = false; int suffix_pos = 0; }; vector<node> trie; void insert(const int *s, int len) { int cur = 0; rng(i, 0, len) { if (!trie[cur].pos[s[i]]) { trie[cur].pos[s[i]] = SZ(trie); trie.pb({}); } cur = trie[cur].pos[s[i]]; } trie[cur].is_accept_state = true; } void build_AC_automata() { queue<int> que; for (int i = 0; i < node::sigma_size; ++i) { if (trie[0].pos[i]) { que.push(trie[0].pos[i]); } } while (!que.empty()) { auto par = que.front(); que.pop(); rng(c, 0, node::sigma_size) { if (!trie[par].pos[c]) { trie[par].pos[c] = trie[trie[par].suffix_pos].pos[c]; } else { int u = trie[par].pos[c]; que.push(u); trie[u].suffix_pos = trie[trie[par].suffix_pos].pos[c]; } } } } int main() { FAST_READ #ifdef LOCAL cout << fixed << setprecision(10); ifstream in("main.in"); cin.rdbuf(in.rdbuf()); #endif int n; scan(n); vi c; rng(i, 0, n) { int x; scan(x); if (c.empty() || x != c.back()) { c.pb(x); } } int m = SZ(c); vl sum(n + 1); sum[c[m - 1]] = 1; down(i, m - 1, 0) { ll t = sum[c[i]]; if (i != 0) { add(sum[c[i - 1]], t); } } println(sum[c[0]]); #ifdef LOCAL cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#ifdef LOCAL // #define _GLIBCXX_DEBUG // #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效 #endif // #pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math #include <bits/stdc++.h> using namespace std; #define sq(x) (x) * (x) // square #define FAST_READ \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #ifdef LOCAL #define see(x) cout << "<DBG> " << #x << ": " << (x) << endl #endif #ifndef LOCAL #define see(x) #endif #define LSON(x) ((x)*2) #define RSON(x) ((x)*2 + 1) template <typename A, typename B> void Min(A &a, const B &b) { if (b < a) a = b; } template <typename A, typename B> void Max(A &a, const B &b) { if (b > a) a = b; } #if __cplusplus < 201402L template <class Iterator> std::reverse_iterator<Iterator> make_reverse_iterator(Iterator it) { return std::reverse_iterator<Iterator>(it); } #endif template <typename iter_t> struct iter_pair { iter_t _beg, _end; iter_t begin() { return _beg; } iter_t end() { return _end; } }; template <class cont> iter_pair<reverse_iterator<decltype(begin(declval<cont>()))>> reverse(cont &&r) { return {make_reverse_iterator(end(r)), make_reverse_iterator(begin(r))}; } template <typename T> void dprintln(const T &t) { cout << t << endl; } // for debug use template <typename T, typename... Args> void dprintln(const T &t, const Args &...rest) { cout << t << ' '; dprintln(rest...); } template <typename T> void println(const T &t) { cout << t << '\n'; } template <typename vec_t> void println_vec(const vec_t &vec) { for (const auto &ele : vec) { cout << ele << ' '; } cout << endl; } template <typename T, typename... Args> void println(const T &t, const Args &...rest) { cout << t << ' '; println(rest...); } template <typename T> void println(const vector<T> &vec) { for (const T &x : vec) { cout << x << ' '; } cout << endl; } template <typename T> void print(const T &t) { cout << t << ' '; } template <typename T, typename... Args> void print(const T &t, const Args &...rest) { cout << t << ' '; print(rest...); } // this overload is chosen when there's only one argument template <class T> void scan(T &t) { cin >> t; } template <class T, class... Args> void scan(T &a, Args &...rest) { cin >> a; scan(rest...); } template <typename T> void read(vector<T> &vec) { for (auto &x : vec) cin >> x; } using ull = unsigned long long; using ll = long long; using ul = unsigned long; using vl = vector<ll>; using vi = vector<int>; using pii = pair<int, int>; using vb = vector<bool>; using vpii = vector<pii>; template <typename int_t> inline int_t lowbit(int_t x) { return x & -x; } #define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define up(i, b, a) for (int i = int(b); i <= int(a); ++i) #define down(i, b, a) for (int i = int(b); i >= int(a); i--) #define rep(n) for (int _ = 0, __ = (int)n; _ < __; _++) #define stp(i, a, b, c) for (int i = (a); i < (b); i += (c)) #define FOR(x, cont) for (const auto &x : cont) #define INC(init, x, y) for (init; x <= y; ++x) #define For(x, cont) for (auto &x : cont) #define all(x) begin(x), end(x) #define pb push_back #define mp make_pair #define eb emplace_back #define SZ(x) (int)(x).size() #define UP(i, l, r) for (i = decltype(i)(l); i <= decltype(i)(r); ++i) #define DOWN(i, r, l) for (i = decltype(i)(r); i >= decltype(i)(l); --i) #define Dec(a, b) for (; a >= b; --a) template <typename T, typename Comp = less<T>> using pq = priority_queue<T, vector<T>, Comp>; #define popcnt(x) __builtin_popcountll((x)) #define SET(arr, v) memset(arr, (v), sizeof(arr)) #define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec)) #define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont)) #define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont)) #define AI(name, n, m) vv<int> name(n, vi(m)); #define AL(name, n, m) vv<ll> name(size_t(n), vl(size_t(m))); auto bet = [](const ll x, const ll y, const ll i) { return x <= i && i <= y; }; template <typename T1, typename T2> T1 ceil(T1 x, T2 y) { // y >= 1,是整数。需要注意 x + y - 1 是否会溢出 return (x + y - 1) / y; } inline int h_bit(unsigned long long x) { return sizeof(unsigned long long) * 8 - 1 - __builtin_clzll(x); } int pow2(int x) { // power of 2 return 1 << (h_bit((ull)x) + (x != lowbit(x))); } template <typename T> struct bit { vector<T> a; function<T(T, T)> bin_op; explicit bit(int n, function<T(T, T)> bin_op, T init) : bin_op(bin_op) { a.resize((size_t)n + 1); for (int i = 1; i <= n; ++i) a[i] = init; } T prefix(T x, T init) { while (x) { init = bin_op(a[x], init); x -= x & -x; } return init; } T sum(int l, int r) { if (l > r) return 0; return sum(r) - sum(l - 1); } void modify(int x, T v) { while (x < a.size()) { a[x] = bin_op(a[x], v); x += x & -x; } } void clear() { fill(a.begin(), a.end(), 0); } }; template <typename T> struct r_bit { vector<T> a; function<T(T, T)> bin_op; explicit r_bit(int n, function<T(T, T)> bin_op, T init) : bin_op(move(bin_op)) { a.resize((size_t)n + 1); for (int i = 1; i <= n; ++i) a[i] = init; } T suffix(int x, T init) { while (x < SZ(a)) { init = bin_op(init, a[x]); // res += a[x]; x += x & -x; } return init; } T sum(int l, int r) { if (l > r) return 0; return sum(r) - sum(l - 1); } void modify(int x, T v) { while (x > 0) { a[x] = bin_op(a[x], v); x -= x & -x; } } void clear() { fill(a.begin(), a.end(), 0); } }; vi get_prime(int n) { vi minp((ul)n + 1), p; for (int i = 2; i <= n; i++) { if (!minp[i]) { minp[i] = i; p.pb(i); } FOR(x, p) { if (x <= minp[i] && x * i <= n) minp[x * i] = x; else break; } } return p; } const int mod = 1e9 + 7; // 记住 mod 的行号! inline void mul(int &x, const int y) { x = int(ll(x) * y % mod); } inline int Mul(int x, const int y) { return (int)(ll(x) * y % mod); } template <typename T, typename U> inline void add(T &x, const U y) { x += y; if (x >= mod) x -= mod; } inline int Add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int Sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; } inline ll submod(ll x, ll y) { return x >= y ? x - y : x - y + mod; } inline ll addmod(ll x, ll y) { x += y; return x >= mod ? x - mod : x; } inline void sub_mod(ll &x, const ll y) { x -= y; if (x < 0) x += mod; } // alias templates template <typename T> using vv = vector<vector<T>>; template <typename T1, typename T2 = T1> using vp = vector<pair<T1, T2>>; template <typename T, int n> using va = vector<array<T, n>>; #ifdef __GNUC__ #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> template <typename T> using rank_tree = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; #endif // union-find 并查集 struct UF { vi par, sz; int n_tree; explicit UF(int n) { // 0-indexed par.assign(n, 0); sz.assign(n, 1); rng(i, 0, n) par[i] = i; n_tree = n; } int n_cluster() const { return n_tree; } int size(int x) { return sz[root(x)]; } int root(int x) { return x == par[x] ? x : par[x] = root(par[x]); } bool unite(int x, int y) { int rx = root(x), ry = root(y); if (rx != ry) { par[rx] = ry; --n_tree; sz[ry] += sz[rx]; return true; } return false; } }; int fp(int x, ll n) { // fast power: hat off to quailty if (n < 0) { x = fp(x, mod - 2); n = -n; } int ans = 1; while (n) { if (n & 1) mul(ans, x); n /= 2; mul(x, x); } return ans; } using idx_t = long; template <typename T, typename Compare = std::less<T>> struct ST { size_t n{}; // 0-indexed vv<T> a; ST() = default; template <typename ptr_t> ST(ptr_t beg, ptr_t end) : n(end - beg) { a.resize((size_t)h_bit(n) + 1); // 注意:不能写成 h_bit(n) a[0].assign(beg, end); rng(i, 0, SZ(a) - 1) { a[i + 1].resize(n); rng(j, 0, n - (1 << i)) { a[i + 1][j] = min(a[i][j], a[i][j + (1 << i)], Compare()); } rng(j, n - (1 << i), n) { a[i + 1][j] = a[i][j]; } } } T query(idx_t l, idx_t r) { // l <= r int i = h_bit(r - l + 1ul); return min(a[i][l], a[i][r + 1 - (1 << i)], Compare()); } }; vi get_popcnt(int n) { vi res((ul)n + 1); rng(i, 0, n) { if (i * 2 <= n) res[i * 2] = res[i]; if ((i & 1) == 0) res[i + 1] = res[i] + 1; } return res; } using poly = vector<int>; void bit_reverse_swap(vector<int> &a) { int n = SZ(a); for (int i = 1, j = n >> 1, k; i < n - 1; i++) { if (i < j) swap(a[i], a[j]); // tricky for (k = n >> 1; j >= k; j -= k, k >>= 1) ; // inspect the highest "1" j += k; } } void FFT(vector<int> &a, int type) { bit_reverse_swap(a); int n = SZ(a); for (int i = 2; i <= n; i *= 2) { const auto wi = fp(3, type * (mod - 1) / i); // i次单位根 for (int j = 0; j < n; j += i) { auto w(1); for (int k = j, h = i >> 1; k < j + h; k++) { auto t = Mul(w, a[k + h]), u = a[k]; a[k] = Add(u, t); a[k + h] = Sub(u, t); mul(w, wi); } } } const int inv = fp(n, -1); if (type == -1) for (auto &x : a) mul(x, inv); } void fp(poly &a, const int n) { a.resize((ul)pow2((SZ(a) - 1) * n + 1)); FFT(a, 1); for (auto &x : a) x = fp(x, n); FFT(a, -1); } // DEBUG code by tourist string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // end DEBUG //////////////////*^"^*///////////////////////////////////// struct node { static const int sigma_size = 2; array<int, sigma_size> pos{}; bool is_accept_state = false; int suffix_pos = 0; }; vector<node> trie; void insert(const int *s, int len) { int cur = 0; rng(i, 0, len) { if (!trie[cur].pos[s[i]]) { trie[cur].pos[s[i]] = SZ(trie); trie.pb({}); } cur = trie[cur].pos[s[i]]; } trie[cur].is_accept_state = true; } void build_AC_automata() { queue<int> que; for (int i = 0; i < node::sigma_size; ++i) { if (trie[0].pos[i]) { que.push(trie[0].pos[i]); } } while (!que.empty()) { auto par = que.front(); que.pop(); rng(c, 0, node::sigma_size) { if (!trie[par].pos[c]) { trie[par].pos[c] = trie[trie[par].suffix_pos].pos[c]; } else { int u = trie[par].pos[c]; que.push(u); trie[u].suffix_pos = trie[trie[par].suffix_pos].pos[c]; } } } } int main() { FAST_READ #ifdef LOCAL cout << fixed << setprecision(10); ifstream in("main.in"); cin.rdbuf(in.rdbuf()); #endif int n; scan(n); vi c; rng(i, 0, n) { int x; scan(x); if (c.empty() || x != c.back()) { c.pb(x); } } int m = SZ(c); vl sum(*max_element(all(c)) + 1); sum[c[m - 1]] = 1; down(i, m - 1, 0) { ll t = sum[c[i]]; if (i != 0) { add(sum[c[i - 1]], t); } } println(sum[c[0]]); #ifdef LOCAL cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
replace
492
493
492
494
0
p03096
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(v) ((int)v.size()) #define pb push_back #define mp make_pair #define mt make_tuple const ll MOD = 1000000007; int main(void) { cin.sync_with_stdio(false); ll N; cin >> N; vector<ll> prev_loc(N + 10, -1); vector<ll> dp(N + 10); dp[0] = 1; FOR(n, 1, N + 1) { ll c; cin >> c; if (n == 1) { dp[n] = 1; } else { dp[n] = dp[n - 1]; if (prev_loc[c] == -1 || prev_loc[c] == n - 1) { // do nothing } else { dp[n] += dp[prev_loc[c]]; dp[n] %= MOD; } } prev_loc[c] = n; } cout << dp[N] << endl; // REP(n, N + 1) cout << dp[n] << ","; cout << endl; return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(v) ((int)v.size()) #define pb push_back #define mp make_pair #define mt make_tuple const ll MOD = 1000000007; int main(void) { cin.sync_with_stdio(false); ll N; cin >> N; vector<ll> prev_loc(2 * 100001, -1); vector<ll> dp(N + 10); dp[0] = 1; FOR(n, 1, N + 1) { ll c; cin >> c; if (n == 1) { dp[n] = 1; } else { dp[n] = dp[n - 1]; if (prev_loc[c] == -1 || prev_loc[c] == n - 1) { // do nothing } else { dp[n] += dp[prev_loc[c]]; dp[n] %= MOD; } } prev_loc[c] = n; } cout << dp[N] << endl; // REP(n, N + 1) cout << dp[n] << ","; cout << endl; return 0; }
replace
40
41
40
41
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 3e4 + 20, maxm = 3e4 + 20; int c[maxn], a[maxn]; ll mod = 1e9 + 7; const ll inf = 1e9; queue<int> q; set<int> s; set<int> s1; int dp[maxn]; int X[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0] = 1; a[0] = a[1]; for (int i = 1; i <= n; i++) { if (a[i] == a[i - 1]) dp[i] = dp[i - 1], c[a[i]] = i; else if (c[a[i]] != 0) dp[i] = (dp[c[a[i]]] + dp[i - 1]) % mod, c[a[i]] = i; else dp[i] = dp[i - 1] % mod, c[a[i]] = i; } cout << dp[n]; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2e5 + 20, maxm = 2e5 + 20; int c[maxn], a[maxn]; ll mod = 1e9 + 7; const ll inf = 1e9; queue<int> q; set<int> s; set<int> s1; int dp[maxn]; int X[] = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0] = 1; a[0] = a[1]; for (int i = 1; i <= n; i++) { if (a[i] == a[i - 1]) dp[i] = dp[i - 1], c[a[i]] = i; else if (c[a[i]] != 0) dp[i] = (dp[c[a[i]]] + dp[i - 1]) % mod, c[a[i]] = i; else dp[i] = dp[i - 1] % mod, c[a[i]] = i; } cout << dp[n]; }
replace
4
5
4
5
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; --c[i]; } const long long mod = 1e9 + 7; vector<long long> dp(n + 1); vector<int> l(n, -1); dp[0] = 1; for (int i = 0; i < n; ++i) { dp[i + 1] = dp[i]; if (l[c[i]] != -1 && l[c[i]] != i) { dp[i + 1] += dp[l[c[i]]]; dp[i + 1] %= mod; } l[c[i]] = i + 1; } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; --c[i]; } const long long mod = 1e9 + 7; vector<long long> dp(n + 1); vector<int> l(*max_element(c.begin(), c.end()) + 1, -1); dp[0] = 1; for (int i = 0; i < n; ++i) { dp[i + 1] = dp[i]; if (l[c[i]] != -1 && l[c[i]] != i) { dp[i + 1] += dp[l[c[i]]]; dp[i + 1] %= mod; } l[c[i]] = i + 1; } cout << dp[n] << endl; return 0; }
replace
15
16
15
16
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x; } const int maxn = 1e5; const int mod = 1e9 + 7; int num[maxn]; int a[maxn], pre[maxn], f[maxn] = {1}; int main() { srand(time(0)); memset(num, -1, sizeof(num)); int n = read(); for (int i = 0; i < n; i++) { a[i] = read() - 1; pre[i] = num[a[i]]; num[a[i]] = i; } for (int i = 1; i < n; i++) { f[i] = f[i - 1]; if (pre[i] >= 0 && pre[i] != i - 1) f[i] = (f[i] + f[pre[i]]) % mod; } printf("%d", f[n - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x; } const int maxn = 2e5; const int mod = 1e9 + 7; int num[maxn]; int a[maxn], pre[maxn], f[maxn] = {1}; int main() { srand(time(0)); memset(num, -1, sizeof(num)); int n = read(); for (int i = 0; i < n; i++) { a[i] = read() - 1; pre[i] = num[a[i]]; num[a[i]] = i; } for (int i = 1; i < n; i++) { f[i] = f[i - 1]; if (pre[i] >= 0 && pre[i] != i - 1) f[i] = (f[i] + f[pre[i]]) % mod; } printf("%d", f[n - 1]); return 0; }
replace
13
14
13
14
0
p03096
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, n) for (int i = 1; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() using namespace std; using ll = long long; constexpr int inf = 1000000000; constexpr ll INF = 1000000000000000000; constexpr int mod = 1000000007; struct ModInt { ll x; ModInt(ll a) : x((a % mod + mod) % mod) {} ModInt operator-() const { return ModInt(-x); } ModInt &operator+=(const ModInt &a) { if ((x += a.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &a) { if ((x -= a.x) < 0) x += mod; return *this; } ModInt &operator*=(const ModInt &a) { (x *= a.x) %= mod; return *this; } ModInt operator+(const ModInt &a) const { ModInt res(*this); return res += a; } ModInt operator-(const ModInt &a) const { ModInt res(*this); return res -= a; } ModInt operator*(const ModInt &a) const { ModInt res(*this); return res *= a; } ModInt pow(ll t) const { if (!t) return 1; ModInt a = pow(t / 2); a *= a; if (t & 1) a *= *this; return a; } ModInt inv() const { return pow(mod - 2); } ModInt &operator/=(const ModInt &a) { return (*this) *= a.inv(); } ModInt operator/(const ModInt &a) const { ModInt res(*this); return res /= a; } friend ostream &operator<<(ostream &os, const ModInt &a) { os << a.x; return os; } }; constexpr int c_max = 100010; int main() { int N; cin >> N; vector<int> C; rep(i, N) { int c; cin >> c; if (i) { if (c != C.back()) { C.push_back(c); } } else { C.push_back(c); } } vector<ModInt> dp; dp.push_back(ModInt{1}); vector<int> MX(c_max, -1); MX[C[0]] = 0; REP(i, SZ(C)) { ModInt res = dp.back(); if (MX[C[i]] != -1) res += dp[MX[C[i]]]; dp.push_back(res); MX[C[i]] = i; } cout << dp.back() << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, n) for (int i = 1; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() using namespace std; using ll = long long; constexpr int inf = 1000000000; constexpr ll INF = 1000000000000000000; constexpr int mod = 1000000007; struct ModInt { ll x; ModInt(ll a) : x((a % mod + mod) % mod) {} ModInt operator-() const { return ModInt(-x); } ModInt &operator+=(const ModInt &a) { if ((x += a.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &a) { if ((x -= a.x) < 0) x += mod; return *this; } ModInt &operator*=(const ModInt &a) { (x *= a.x) %= mod; return *this; } ModInt operator+(const ModInt &a) const { ModInt res(*this); return res += a; } ModInt operator-(const ModInt &a) const { ModInt res(*this); return res -= a; } ModInt operator*(const ModInt &a) const { ModInt res(*this); return res *= a; } ModInt pow(ll t) const { if (!t) return 1; ModInt a = pow(t / 2); a *= a; if (t & 1) a *= *this; return a; } ModInt inv() const { return pow(mod - 2); } ModInt &operator/=(const ModInt &a) { return (*this) *= a.inv(); } ModInt operator/(const ModInt &a) const { ModInt res(*this); return res /= a; } friend ostream &operator<<(ostream &os, const ModInt &a) { os << a.x; return os; } }; constexpr int c_max = 200010; int main() { int N; cin >> N; vector<int> C; rep(i, N) { int c; cin >> c; if (i) { if (c != C.back()) { C.push_back(c); } } else { C.push_back(c); } } vector<ModInt> dp; dp.push_back(ModInt{1}); vector<int> MX(c_max, -1); MX[C[0]] = 0; REP(i, SZ(C)) { ModInt res = dp.back(); if (MX[C[i]] != -1) res += dp[MX[C[i]]]; dp.push_back(res); MX[C[i]] = i; } cout << dp.back() << "\n"; return 0; }
replace
74
75
74
75
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; ll const MOD = 1e9 + 7; int main() { int N; cin >> N; vi C; for (int i = 0; i < N; ++i) { int c; cin >> c; C.push_back(c); } ll dp[N]; ll c_cum[N + 1]; memset(c_cum, 0, sizeof(c_cum)); dp[0] = 1; c_cum[C[0]] = 1; if (N != 1) { for (int i = 1; i < N; ++i) { if (C[i - 1] != C[i]) (c_cum[C[i]] += dp[i - 1]) %= MOD; dp[i] = c_cum[C[i]]; } } cout << dp[N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; ll const MOD = 1e9 + 7; int main() { int N; cin >> N; vi C; for (int i = 0; i < N; ++i) { int c; cin >> c; C.push_back(c); } ll dp[200010]; ll c_cum[200010]; memset(c_cum, 0, sizeof(c_cum)); dp[0] = 1; c_cum[C[0]] = 1; if (N != 1) { for (int i = 1; i < N; ++i) { if (C[i - 1] != C[i]) (c_cum[C[i]] += dp[i - 1]) %= MOD; dp[i] = c_cum[C[i]]; } } cout << dp[N - 1] << endl; return 0; }
replace
16
18
16
18
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define st first #define nd second typedef pair<int, int> pp; const int mod = 1e9 + 7; const int N = 1e5 + 5; int M[N]; signed main() { int n; cin >> n; int pre = 1; int prex = 0; int dp; for (int i = 1; i <= n; i++) { int x; scanf("%lld", &x); if (x == prex) continue; dp = (M[x] + pre) % mod; // cout << i << " " << dp << " ss\n"; M[x] = (M[x] + pre) % mod; pre = dp; prex = x; } cout << dp; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define st first #define nd second typedef pair<int, int> pp; const int mod = 1e9 + 7; const int N = 2e5 + 5; int M[N]; signed main() { int n; cin >> n; int pre = 1; int prex = 0; int dp; for (int i = 1; i <= n; i++) { int x; scanf("%lld", &x); if (x == prex) continue; dp = (M[x] + pre) % mod; // cout << i << " " << dp << " ss\n"; M[x] = (M[x] + pre) % mod; pre = dp; prex = x; } cout << dp; return 0; }
replace
11
12
11
12
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 階乗(MODをとる) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); const double PI = acos(-1); // 多次元vector生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // 素因数分解 vector<pair<ll, int>> factorize(ll n) { vector<pair<ll, int>> res; for (ll i = 2; i * i <= n; ++i) { if (n % i) continue; res.emplace_back(i, 0); while (n % i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n, 1); return res; } // 素数判定(マイナスは素数でないと判定するタイプ) bool primejudge(ll a) { if (a <= 1) return false; for (ll i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int main() { int n; cin >> n; int c[n]; REP(i, n) { cin >> c[i]; } vector<int> left(n, -1); vector<int> dp(n + 1); dp[0] = 1; for (int i = 0; i < n; i++) { dp[i + 1] = (dp[i + 1] + dp[i]) % MOD; int C = c[i]; if (left[C] >= 0 && left[C] < i - 1) dp[i + 1] = (dp[i + 1] + dp[left[C] + 1]) % MOD; left[C] = i; } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // long long using ll = long long; // pair<int, int> using PII = pair<int, int>; // 最大値、mod const int MOD = 1000000007; const int mod = 1000000007; const int INF = 1000000000; const long long LINF = 1e18; const int MAX = 510000; // 出力系 #define print(x) cout << x << endl #define prints(x) cout << fixed << setprecision(20) << x << endl #define printc(x) cout << setw(2) << setfill('0') << x << endl; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl // begin() end() #define all(x) (x).begin(), (x).end() // for #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, a, b) for (int i = (a); i > (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) // 最大公約数 ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } // 最小公倍数 unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; } // a = max(a, b), a = min(a, b) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // 階乗(MODをとる) ll pow_mod(ll num, ll pow, ll mod) { ll prod = 1; num %= mod; while (pow > 0) { if (pow & 1) prod = prod * num % mod; num = num * num % mod; pow >>= 1; } return prod; } // 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度) // COMinit() // COM(x, y) // とコンビで使う // テーブルを作る前処理 long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // UnionFind struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; // modint構造体 struct Mint { int val; Mint inv() const { int tmp, a = val, b = mod, x = 1, y = 0; while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y); return Mint(x); } public: Mint() : val(0) {} Mint(ll x) { if ((val = x % mod) < 0) val += mod; } Mint pow(ll t) { Mint res = 1, b = *this; while (t) { if (t & 1) res *= b; b *= b; t >>= 1; } return res; } Mint &operator+=(const Mint &x) { if ((val += x.val) >= mod) val -= mod; return *this; } Mint &operator-=(const Mint &x) { if ((val += mod - x.val) >= mod) val -= mod; return *this; } Mint &operator*=(const Mint &x) { val = (ll)val * x.val % mod; return *this; } Mint &operator/=(const Mint &x) { return *this *= x.inv(); } bool operator==(const Mint &x) const { return val == x.val; } bool operator!=(const Mint &x) const { return val != x.val; } bool operator<(const Mint &x) const { return val < x.val; } bool operator<=(const Mint &x) const { return val <= x.val; } bool operator>(const Mint &x) const { return val > x.val; } bool operator>=(const Mint &x) const { return val >= x.val; } Mint operator+(const Mint &x) const { return Mint(*this) += x; } Mint operator-(const Mint &x) const { return Mint(*this) -= x; } Mint operator*(const Mint &x) const { return Mint(*this) *= x; } Mint operator/(const Mint &x) const { return Mint(*this) /= x; } }; struct factorial { vector<Mint> Fact, Finv; public: // factorial fact(10000010); // fact.nCr(a, b) // 「fact」の部分は自由に名前変更可能 factorial(int maxx) { Fact.resize(maxx + 1), Finv.resize(maxx + 1); Fact[0] = Mint(1); rep(i, 0, maxx) Fact[i + 1] = Fact[i] * (i + 1); Finv[maxx] = Mint(1) / Fact[maxx]; rrep(i, maxx, 0) Finv[i - 1] = Finv[i] * i; } Mint fact(int n, bool inv = 0) { if (inv) return Finv[n]; else return Fact[n]; } Mint nPr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[n - r]; } Mint nCr(int n, int r) { if (n < 0 || n < r || r < 0) return Mint(0); else return Fact[n] * Finv[r] * Finv[n - r]; } }; // 1 * 2 * 3 .... * n (mod) ll modfact(ll n) { if (n <= 1) return 1; return (n * modfact(n - 1)) % MOD; } // kが角度だった場合:cos(k * (PI / 180)); const double PI = acos(-1); // 多次元vector生成 例: auto dp = make_vec<long long>(N+1, 5, 5, 5); template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } // 素因数分解 vector<pair<ll, int>> factorize(ll n) { vector<pair<ll, int>> res; for (ll i = 2; i * i <= n; ++i) { if (n % i) continue; res.emplace_back(i, 0); while (n % i == 0) { n /= i; res.back().second++; } } if (n != 1) res.emplace_back(n, 1); return res; } // 素数判定(マイナスは素数でないと判定するタイプ) bool primejudge(ll a) { if (a <= 1) return false; for (ll i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int main() { int n; cin >> n; int c[n]; REP(i, n) { cin >> c[i]; } vector<int> left(200010, -1); vector<int> dp(n + 1); dp[0] = 1; for (int i = 0; i < n; i++) { dp[i + 1] = (dp[i + 1] + dp[i]) % MOD; int C = c[i]; if (left[C] >= 0 && left[C] < i - 1) dp[i + 1] = (dp[i + 1] + dp[left[C] + 1]) % MOD; left[C] = i; } cout << dp[n] << endl; return 0; }
replace
275
276
275
276
0
p03096
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define all(x) (x).begin(), (x).end() 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; } typedef long long ll; using namespace std; template <class Abel> class BIT { public: using F = function<Abel(Abel, Abel)>; F f; int l; vector<Abel> bit; Abel m0; BIT(int maxidx, F fu, Abel m0) : f(fu), l(maxidx), m0(m0) { bit.assign(l, m0); } void update(int idx, int val) { while (idx <= l) { bit[idx] = f(bit[idx], val); idx += idx & -idx; } } int query(int idx) { idx--; int res = m0; while (idx > 0) { res = f(bit[idx], res); idx -= idx & -idx; } return res; } }; int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> s(n); rep(i, n) cin >> s[i]; s.erase(unique(all(s)), s.end()); int l = s.size(); map<int, vector<int>> cidx; vector<int> tv; rep(i, l) { if (cidx.count(s[i]) == 0) { cidx[s[i]] = tv; } cidx[s[i]].push_back(i); } BIT<int> bt( l, [](int a, int b) { return (a + b) % mod; }, 0); rep(i, l) { auto nitr = upper_bound(all(cidx[s[i]]), i); if (nitr == cidx[s[i]].end()) continue; bt.update(*nitr, bt.query(i + 1) + 1); } cout << (bt.query(l) + 1) % mod << endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define all(x) (x).begin(), (x).end() 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; } typedef long long ll; using namespace std; template <class Abel> class BIT { public: using F = function<Abel(Abel, Abel)>; F f; int l; vector<Abel> bit; Abel m0; BIT(int maxidx, F fu, Abel m0) : f(fu), l(maxidx), m0(m0) { bit.assign(l, m0); } void update(int idx, int val) { while (idx <= l) { bit[idx] = f(bit[idx], val); idx += idx & -idx; } } int query(int idx) { idx--; int res = m0; while (idx > 0) { res = f(bit[idx], res); idx -= idx & -idx; } return res; } }; int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> s(n); rep(i, n) cin >> s[i]; s.erase(unique(all(s)), s.end()); int l = s.size(); map<int, vector<int>> cidx; vector<int> tv; rep(i, l) { if (cidx.count(s[i]) == 0) { cidx[s[i]] = tv; } cidx[s[i]].push_back(i); } BIT<int> bt( l + 10, [](int a, int b) { return (a + b) % mod; }, 0); rep(i, l) { auto nitr = upper_bound(all(cidx[s[i]]), i); if (nitr == cidx[s[i]].end()) continue; bt.update(*nitr, bt.query(i + 1) + 1); } cout << (bt.query(l) + 1) % mod << endl; return 0; }
replace
85
86
85
86
0
p03096
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI = 3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for (int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y)-1) / (y)) #define MOD 1000000007ULL int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; int c, prev = 0; vs32 pos(n + 1, -1); vs64 dp(n + 1); dp[0] = 1; rep(i, n) { cin >> c; if (c == prev || pos[c] == -1) { dp[i + 1] = dp[i]; } else { dp[i + 1] = (dp[i] + dp[pos[c]]) % MOD; } pos[c] = i + 1; prev = c; } cout << dp[n] << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef uint64_t u64; typedef int64_t s64; typedef uint32_t u32; typedef int32_t s32; typedef vector<s32> vs32; typedef vector<u32> vu32; typedef vector<s64> vs64; typedef vector<u64> vu64; const double PI = 3.14159265358979323846; #define MAX(x, y) ((x) < (y) ? (y) : (x)) #define MIN(x, y) ((x) > (y) ? (y) : (x)) #define rep(i, N) for (int i = 0; i < N; ++i) #define CEIL(x, y) (((x) + (y)-1) / (y)) #define MOD 1000000007ULL int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; int c, prev = 0; vs32 pos(200000 + 1, -1); vs64 dp(n + 1); dp[0] = 1; rep(i, n) { cin >> c; if (c == prev || pos[c] == -1) { dp[i + 1] = dp[i]; } else { dp[i + 1] = (dp[i] + dp[pos[c]]) % MOD; } pos[c] = i + 1; prev = c; } cout << dp[n] << "\n"; return 0; }
replace
43
44
43
44
0
p03096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define double long double typedef pair<int, int> ii; typedef pair<int, long long> il; typedef pair<long long, long long> ll; typedef pair<ll, int> lli; typedef pair<long long, int> li; typedef pair<double, double> dd; typedef pair<ii, int> iii; typedef pair<double, int> di; typedef pair<int, ii> iii2; typedef pair<ii, ii> iiii; long long mod = 1000000007LL; long long large = 2000000000000000000LL; int main() { int n; cin >> n; vector<int> c(n, 0); for (int i = 0; i < n; i++) { scanf("%d", &c[i]); c[i]--; } vector<int> cnt(n, 0); vector<int> dp(n, 0); cnt[c[0]] = 1; for (int i = 0; i < n; i++) { dp[i] = cnt[c[i]]; dp[i] %= mod; if (i + 1 < n && c[i] != c[i + 1]) { cnt[c[i + 1]] += dp[i]; cnt[c[i + 1]] %= mod; } } // for(int i=0;i<n;i++) cout<<i<<" "<<dp[i]<<endl; cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #define double long double typedef pair<int, int> ii; typedef pair<int, long long> il; typedef pair<long long, long long> ll; typedef pair<ll, int> lli; typedef pair<long long, int> li; typedef pair<double, double> dd; typedef pair<ii, int> iii; typedef pair<double, int> di; typedef pair<int, ii> iii2; typedef pair<ii, ii> iiii; long long mod = 1000000007LL; long long large = 2000000000000000000LL; int main() { int n; cin >> n; vector<int> c(n, 0); for (int i = 0; i < n; i++) { scanf("%d", &c[i]); c[i]--; } vector<int> cnt(2000010, 0); vector<int> dp(n, 0); cnt[c[0]] = 1; for (int i = 0; i < n; i++) { dp[i] = cnt[c[i]]; dp[i] %= mod; if (i + 1 < n && c[i] != c[i + 1]) { cnt[c[i + 1]] += dp[i]; cnt[c[i + 1]] %= mod; } } // for(int i=0;i<n;i++) cout<<i<<" "<<dp[i]<<endl; cout << dp[n - 1] << endl; return 0; }
replace
29
30
29
30
0
p03096
C++
Runtime Error
#include <iostream> #include <vector> int main() { long long mod = 1000000007; int n; std::vector<int> aList; std::vector<int> colorList; std::vector<long long> dpList; std::cin >> n; aList.resize(n); colorList.resize(n + 1, -1); dpList.resize(n, 0); for (int i = 0; i < n; i++) std::cin >> aList[i]; dpList[0] = 1; colorList[aList[0]] = 0; for (int i = 1; i < n; i++) { dpList[i] = dpList[i - 1]; if (aList[i] != aList[i - 1]) if (colorList[aList[i]] >= 0) dpList[i] = (dpList[i] + dpList[colorList[aList[i]]]) % mod; colorList[aList[i]] = i; } std::cout << dpList[n - 1] << std::endl; return 0; }
#include <iostream> #include <vector> int main() { long long mod = 1000000007; int n; std::vector<int> aList; std::vector<int> colorList; std::vector<long long> dpList; std::cin >> n; aList.resize(n); colorList.resize(200001, -1); dpList.resize(n, 0); for (int i = 0; i < n; i++) std::cin >> aList[i]; dpList[0] = 1; colorList[aList[0]] = 0; for (int i = 1; i < n; i++) { dpList[i] = dpList[i - 1]; if (aList[i] != aList[i - 1]) if (colorList[aList[i]] >= 0) dpList[i] = (dpList[i] + dpList[colorList[aList[i]]]) % mod; colorList[aList[i]] = i; } std::cout << dpList[n - 1] << std::endl; return 0; }
replace
13
14
13
14
0
p03096
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; const ll M = 1e9 + 7; const int MN = 200100; inline ll mul(ll a, ll b) { return (a * b) % M; } vi fr[MN]; int v[MN]; ll dp[MN]; ll ds(int id) { if (id == 0) return 1; int val = v[id]; int pos = lower_bound(fr[val].begin(), fr[val].end(), id) - fr[val].begin(); ll tot = ds(id - 1); if (pos > 0) { tot += ds(fr[val][pos - 1]); tot %= M; } return dp[id] = tot; } int main() { int n; memset(dp, -1, sizeof(dp)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int la = -1; int id = 0; while (n--) { int t; cin >> t; if (t != la && la > 0) { v[id] = la; fr[la].push_back(id++); } la = t; } v[id] = la; fr[la].push_back(id++); // cout << "SIZE " << id << '\n'; cout << ds(id - 1) << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; const ll M = 1e9 + 7; const int MN = 200100; inline ll mul(ll a, ll b) { return (a * b) % M; } vi fr[MN]; int v[MN]; ll dp[MN]; ll ds(int id) { if (id == 0) return 1; if (dp[id] != -1) return dp[id]; int val = v[id]; int pos = lower_bound(fr[val].begin(), fr[val].end(), id) - fr[val].begin(); ll tot = ds(id - 1); if (pos > 0) { tot += ds(fr[val][pos - 1]); tot %= M; } return dp[id] = tot; } int main() { int n; memset(dp, -1, sizeof(dp)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int la = -1; int id = 0; while (n--) { int t; cin >> t; if (t != la && la > 0) { v[id] = la; fr[la].push_back(id++); } la = t; } v[id] = la; fr[la].push_back(id++); // cout << "SIZE " << id << '\n'; cout << ds(id - 1) << '\n'; }
insert
13
13
13
15
TLE
p03096
C++
Runtime Error
#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second #define mp make_pair #define pb push_back typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; void pre() {} void solve() {} ll dp[100009], c[100009]; int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); pre(); int n; cin >> n; vi v; int lst = -1; rep(i, n) { int x; cin >> x; if (x != lst) v.pb(x); lst = x; } dp[0] = 1; const ll mod = 1e9 + 7; repA(i, 1, sz(v)) { dp[i] = dp[i - 1]; dp[i] += c[v[i - 1]]; dp[i] %= mod; c[v[i - 1]] += dp[i - 1]; c[v[i] - 1] %= mod; } cout << dp[sz(v)]; return 0; }
#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second #define mp make_pair #define pb push_back typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; void pre() {} void solve() {} ll dp[200009], c[200009]; int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); pre(); int n; cin >> n; vi v; int lst = -1; rep(i, n) { int x; cin >> x; if (x != lst) v.pb(x); lst = x; } dp[0] = 1; const ll mod = 1e9 + 7; repA(i, 1, sz(v)) { dp[i] = dp[i - 1]; dp[i] += c[v[i - 1]]; dp[i] %= mod; c[v[i - 1]] += dp[i - 1]; c[v[i] - 1] %= mod; } cout << dp[sz(v)]; return 0; }
replace
42
43
42
43
0