結果

問題 No.1845 Long Substrings
ユーザー KKT89KKT89
提出日時 2022-02-18 22:20:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,020 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 136,104 KB
実行使用メモリ 6,736 KB
最終ジャッジ日時 2023-09-11 19:26:14
合計ジャッジ時間 3,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 34 ms
6,568 KB
testcase_02 AC 45 ms
6,616 KB
testcase_03 AC 46 ms
6,516 KB
testcase_04 WA -
testcase_05 AC 41 ms
6,128 KB
testcase_06 AC 44 ms
6,196 KB
testcase_07 AC 35 ms
6,736 KB
testcase_08 AC 44 ms
6,260 KB
testcase_09 AC 45 ms
6,336 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 33 ms
6,628 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 3 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

constexpr ll mod = 1e9+7;

// 0-indexed
struct BIT{
    vector<ll> s;
    BIT(int n): s(n){}
    void update(int pos,ll dif){
        for(;pos<s.size();pos|=pos+1)(s[pos]+=dif)%=mod;
    }
    ll query(int pos){ // sum of values in [0,pos)
        ll res=0;
        for(;pos>0;pos&=pos-1)(res+=s[pos-1])%=mod;
        return res;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<int> last(26,-1);
    vector<ll> lastdp(26,1);
    string s; cin >> s;
    BIT bit(n);
    for(int i=0;i<n;i++){
        ll u,nx,ad;
        if(last[s[i]-'a'] == -1){
            u = bit.query(i);
            nx = (u+lastdp[s[i]-'a'])%mod;
            ad = nx * a[i] % mod;
            bit.update(i, ad);
            lastdp[s[i]-'a'] = nx;
        }
        else{
            u = bit.query(i) - bit.query(last[s[i]-'a']+1);
            nx = (u+lastdp[s[i]-'a'])%mod;
            ad = nx * a[i] % mod;
            bit.update(i, ad);
            lastdp[s[i]-'a'] = nx;
        }
        last[s[i]-'a'] = i;
        // cout << u << " " << nx << " " << ad << endl;
    }
    cout << bit.query(n) << endl;
}

0