結果
問題 | No.1845 Long Substrings |
ユーザー | Ngọc Hưng Nguyễn |
提出日時 | 2024-11-19 19:04:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 5,425 bytes |
コンパイル時間 | 1,503 ms |
コンパイル使用メモリ | 142,824 KB |
実行使用メモリ | 53,240 KB |
最終ジャッジ日時 | 2024-11-19 19:04:50 |
合計ジャッジ時間 | 4,949 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
51,396 KB |
testcase_01 | AC | 72 ms
51,196 KB |
testcase_02 | AC | 83 ms
53,240 KB |
testcase_03 | AC | 86 ms
51,548 KB |
testcase_04 | AC | 75 ms
51,200 KB |
testcase_05 | AC | 76 ms
48,872 KB |
testcase_06 | AC | 82 ms
51,804 KB |
testcase_07 | AC | 71 ms
51,208 KB |
testcase_08 | AC | 78 ms
51,100 KB |
testcase_09 | AC | 80 ms
51,832 KB |
testcase_10 | AC | 72 ms
52,912 KB |
testcase_11 | AC | 74 ms
45,028 KB |
testcase_12 | AC | 76 ms
50,292 KB |
testcase_13 | AC | 70 ms
49,868 KB |
testcase_14 | AC | 88 ms
48,612 KB |
testcase_15 | AC | 4 ms
7,548 KB |
testcase_16 | AC | 3 ms
7,804 KB |
testcase_17 | AC | 3 ms
7,544 KB |
testcase_18 | AC | 3 ms
7,668 KB |
testcase_19 | AC | 3 ms
7,688 KB |
testcase_20 | AC | 2 ms
7,644 KB |
testcase_21 | AC | 2 ms
7,652 KB |
testcase_22 | AC | 2 ms
7,648 KB |
testcase_23 | AC | 2 ms
7,648 KB |
testcase_24 | AC | 2 ms
7,648 KB |
testcase_25 | AC | 2 ms
7,648 KB |
testcase_26 | AC | 3 ms
7,652 KB |
testcase_27 | AC | 3 ms
7,772 KB |
testcase_28 | AC | 2 ms
7,648 KB |
testcase_29 | AC | 3 ms
7,648 KB |
testcase_30 | AC | 2 ms
7,648 KB |
testcase_31 | AC | 3 ms
7,648 KB |
testcase_32 | AC | 2 ms
7,516 KB |
testcase_33 | AC | 2 ms
7,776 KB |
ソースコード
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx2,tune=native") #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <locale> #include <map> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <unordered_set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <utility> #include <valarray> #include <vector> #include <cstring> #include <unordered_map> #include <cmath> #include <array> #include <cassert> #include <random> #include <chrono> using namespace std; #define BIT(i,j) (((i)>>(j))&1LL) #define MASK(i) (1LL<<(i)) #define ALL(x) (x).begin(),(x).end() #define SZ(x) (int)(x).size() #define fi first #define se second #define ull ungsigned long long #define ll long long #define ld long double #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define REPDIS(i,be,en,j) for(int i = (be); i<=(en); i+=j) #define REPD(i,be,en) for(int i = (be); i>=(en); i--) #define REP(i,be,en) for(int i = (be); i<=(en); i++) #define endl "\n" #define MP make_pair #define int ll //-----------------------------------------------------------------------------------------------// inline void scan(){} template<typename F, typename... R> inline void scan(F &f,R&... r){cin>>f;scan(r...);} inline void print(){} template<typename F, typename... R> inline void print(F f,R... r){cout<<f;print(r...);} //-----------------------------------------------------------------------------------------------// void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif //------------------------------------------------------------------------------------------------// const ll LINF = 1e18; const int INF = 1e9; const int LOG = 20; const int MAXN = 5e5+7; const int N = 1e2+3; const int MOD = 1e9+7; const int BASE = 1e5; const ld EPS = 1e-9; const ld PI = acos(-1); const int OFFSET = 1e3; //------------------------------------------------------------------------------------------------// template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;} template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;} template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; } template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; } //------------------------------------------------------------------------------------------------// /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- */ void add(int &a, int b){ a += b; if(a>=MOD) a -= MOD; } int dp[MAXN][27],a[MAXN],s[MAXN]; void solve(){ int n; cin >> n; for(int i = 1; i<=n; i++) cin >> a[i]; for(int i = 1; i<=n; i++){ char c; cin >> c; s[i] = c-'a'; } dp[0][26] = 1; for(int i = 1; i<=n; i++){ int now = s[i]; for(int j = 0; j<=26; j++){ add(dp[i][j],dp[i-1][j]); if(j!=now){ add(dp[i][now],1LL*dp[i-1][j]*a[i]%MOD); } } } int res = 0; for(int i = 0; i<=25; i++){ add(res,dp[n][i]); } cout << res << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "test" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } #define task1 "nothing" if(fopen(task1".inp","r")){ freopen(task1".inp","r",stdin); freopen(task1".out","w",stdout); } int test = 1; while(test--){ solve(); } cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n"; return 0; } /** /\_/\ * (= ._.) * / >TL \>AC **/