QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#668632#4224. 串Starrykiller0 0ms0kbC++237.2kb2024-10-23 15:19:292024-10-23 15:19:36

Judging History

你现在查看的是最新测评结果

  • [2024-10-23 15:19:36]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-23 15:19:29]
  • 提交

answer

// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever! 
#include <bits/stdc++.h>

using namespace std;

template<typename L, typename R>
auto range(L l, R r) { return views::iota(l,r); }
auto rev=views::reverse;

template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmax(T &a, T b) { a=max(a,b); }
template<typename T>
_GLIBCXX_ALWAYS_INLINE void chmin(T &a, T b) { a=min(a,b); }

namespace sk {
    // modint: https://www.cnblogs.com/hzy1/p/16344746.html
    // Edited by Starrykiller.
    using i64=int64_t;
    using i128=__int128;
    using u128=unsigned __int128;
    using u64=uint64_t;
    using i32=int32_t;
    using u32=uint32_t;
    struct barrett { // From Atcoder Library.
        u32 _m;
        u64 im;
        explicit barrett(u32 m) : _m(m), im((u64)(-1)/m+1) {}
        u32 umod() const { return _m; }
        u32 mul(u32 a, u32 b) const {
            u64 z=a; z*=b;
            u64 x=(u64)((u128(z)*im) >> 64);
            u64 y = x * _m;
            return (u32)(z-y+(z<y?_m:0));
        }
    };
    constexpr i32 inverse(i32 a, i32 m) { i32 r=1;
        while (a>1) { i32 t=m/a; r=i64(r)*(m-t)%m; a=m-t*a; }
        return r;
    }
    template<i32 p>
    struct static_modint { 
        using mi=static_modint;
        public:
        constexpr static_modint(i64 x) : x(normal(x%p)) {}
        constexpr static_modint(i32 x, std::nullptr_t) : x(x) {}
        constexpr static_modint(): x(0) {}
        constexpr i32 normal(i32 x) { 
            if (x>=p) x-=p;
            return x+((x>>31)&p); 
        }
        constexpr i32 val() const { return x; }
        constexpr static i32 mod() { return p; }
        constexpr explicit operator bool() const { return x; }
        constexpr mi inv() const { assert(x!=0); return mi(inverse(x,p),nullptr); }
        constexpr mi pow(i64 x) const { assert(x>=0); mi a=*this, res=1;
            while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
        constexpr mi operator-() const { return mi(p-x); }
        constexpr mi& operator+=(const mi &rhs) { x=normal(x+rhs.x); return *this; }
        constexpr mi& operator-=(const mi &rhs) { x=normal(x-rhs.x); return *this; }
        constexpr mi& operator++() { return (*this)+=1; }
        constexpr mi& operator--() { return (*this)-=1; }
        constexpr mi& operator*=(const mi &rhs) { x=i64(x)*rhs.x%p; return *this; }
        constexpr mi& operator/=(const mi &rhs) { return *this *= rhs.inv(); }
        constexpr friend mi operator+(const mi &lhs, const mi &rhs) { auto res=lhs; res+=rhs; return res; }
        constexpr friend mi operator-(const mi &lhs, const mi &rhs) { auto res=lhs; res-=rhs; return res; }
        constexpr friend mi operator*(const mi &lhs, const mi &rhs) { auto res=lhs; res*=rhs; return res; }
        constexpr friend mi operator/(const mi &lhs, const mi &rhs) { auto res=lhs; res/=rhs; return res; }
        constexpr friend mi operator++(mi &x, i32) { auto tmp=x; x+=1; return tmp; }
        constexpr friend mi operator--(mi &x, i32) { auto tmp=x; x-=1; return tmp; }
        constexpr friend std::istream& operator>>(std::istream &is, mi &a) { i64 v; is>>v; a=v; return is; }
        constexpr friend std::ostream& operator<<(std::ostream &os, const mi &a) { os<<a.val(); return os; }
        constexpr bool operator==(const mi& rhs) const { return val()==rhs.val(); }
        constexpr bool operator!=(const mi& rhs) const { return val()!=rhs.val(); }
        private:
        i32 x;
    };
    template<i32 id>
    struct dynamic_modint { 
        using mi=dynamic_modint;
        public:
        constexpr dynamic_modint(i64 x) : x(normal(x%mod())) {}
        constexpr dynamic_modint(i32 x, std::nullptr_t) : x(x) {}
        constexpr dynamic_modint(): x(0) {}
        constexpr i32 normal(i32 x) { 
            auto p=mod();
            if (x>=p) x-=p;
            return x+((x>>31)&p); 
        }
        constexpr i32 val() const { return x; }
        constexpr static void set_mod(i32 m) { assert(m>=1); bt=barrett((u32)m); }
        constexpr static i32 mod() { return bt.umod(); }
        constexpr explicit operator bool() const { return x; }
        constexpr mi inv() const { assert(x!=0); return mi(inverse(x,mod()),nullptr); }
        constexpr mi pow(i64 x) const { assert(x>=0); mi a=*this, res=1;
            while (x) { if (x&1) res*=a; a*=a; x>>=1; } return res; }
        constexpr mi operator-() const { return mi(mod()-x); }
        constexpr mi& operator+=(const mi &rhs) { x=normal(x+rhs.x); return *this; }
        constexpr mi& operator-=(const mi &rhs) { x=normal(x-rhs.x); return *this; }
        constexpr mi& operator++() { return (*this)+=1; }
        constexpr mi& operator--() { return (*this)-=1; }
        constexpr mi& operator*=(const mi &rhs) { x=bt.mul(val(),rhs.val()); return *this; }
        constexpr mi& operator/=(const mi &rhs) { return *this *= rhs.inv(); }
        constexpr friend mi operator+(const mi &lhs, const mi &rhs) { auto res=lhs; res+=rhs; return res; }
        constexpr friend mi operator-(const mi &lhs, const mi &rhs) { auto res=lhs; res-=rhs; return res; }
        constexpr friend mi operator*(const mi &lhs, const mi &rhs) { auto res=lhs; res*=rhs; return res; }
        constexpr friend mi operator/(const mi &lhs, const mi &rhs) { auto res=lhs; res/=rhs; return res; }
        constexpr friend mi operator++(mi &x, i32) { auto tmp=x; x+=1; return tmp; }
        constexpr friend mi operator--(mi &x, i32) { auto tmp=x; x-=1; return tmp; }
        constexpr friend std::istream& operator>>(std::istream &is, mi &a) { i64 v; is>>v; a=v; return is; }
        constexpr friend std::ostream& operator<<(std::ostream &os, const mi &a) { os<<a.val(); return os; }
        constexpr bool operator==(const mi& rhs) const { return val()==rhs.val(); }
        constexpr bool operator!=(const mi& rhs) const { return val()!=rhs.val(); }
        private:
        i32 x; 
        static barrett bt;
    };
    template<i32 id> barrett dynamic_modint<id>::bt(998244353);
    using modint998244353=static_modint<998244353>;
    using modint1000000007=static_modint<1000000007>;
    using mint=dynamic_modint<-1>; 
};
using ll=sk::modint998244353;

template<int N>
constexpr auto get_fac() {
    vector<ll> fac(N+1), ifac(N+1);
    fac[0]=ifac[0]=1;
    for (int i=1; i<=N; ++i)
        fac[i]=fac[i-1]*i, ifac[i]=ifac[i-1]/i;
    return make_pair(fac,ifac);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
int T; cin>>T;
// int T=1;
    constexpr int N=2e5;
    auto fac=get_fac<N>().first, ifac=get_fac<N>().second; 
    auto C=[&](int n, int m)->ll {
        if (n<m || m<0) return 0;
        return fac[n]*ifac[n-m]*ifac[m];
    };
    // ifac=get_fac(N).second;

while (T--) [&]{
    int n; cin>>n;
    vector<int> a(n);
    for (int sum=0; auto &i: a) cin>>i, i=(sum+=i);
    int s=a.back(); 
    vector<int> val(n-1); for (auto &i: val) cin>>i;
    --n;
    vector<ll> f(s+1);
    for (auto i: range(0,n)) {
        vector<ll> g(s+1);
        for (ll sum=0; auto j: range(0,s+1)) {
            sum+=f[j];
            g[j]=sum+C(j+i,i)*abs(j-a[i])*val[i];
        }
        swap(f,g);
    }
    cerr<<s<<'\n';
    cout<<accumulate(begin(f),end(f),ll(0))<<'\n';
}();
}

详细


Pretests


Final Tests

Test #1:

score: 0
Runtime Error

input:

5
wwgpdvdwwgpdvdwwgpdvdwwwvdwdww
imeoqomeomqomeommeoqomeomqomem
blmjcxblmjcxlmjlmjcxjcxblmjcxl
exzhdyzhddyzhdedyzhyzhddydyyzd
tsbosqtsbosqtsbossbosqtssqtsbb

output:


result:


Test #2:

score: 0
Runtime Error

input:

5
rmgmlkgmlkllklmlkgmgmlklklmlkm
fstnttfttfnttfttfttfttfttttftt
hxiykziykzixiykziyykzixiyiyyky
fbtnfwbtnffwbfbtnfwbtnffwwbtnw
yhdizazyhdidihdidihdizzazyyhdi

output:


result:


Test #3:

score: 0
Runtime Error

input:

4
skjnitkwybtcsfagbpslfxtijbwjqvskibxqwjmukwybtcsfagbbpslfxtijbwjqvskibxqwjmukwybtcsfagbpslfxtijbwjqvskibxqwjmukwybtcsfagbbpslfxtijbwjqvskibxqwjmukwybtcsfagbbpslukwybtcsfagbbpslfxtijbbbpslukwybtcsfaslfc
ssrpyzpwiydtayxmoddtqksdrhcavtsonldnmujuyzpwiydtayxmoddtqksdrhcavtsoniydtayxmoddtqksdrhwiydtayxmo...

output:


result:


Test #4:

score: 0
Runtime Error

input:

4
oupltnlcbcgntpnkbvktcbcpltnlcbcgpltnlcgpltngntpnlcbcgntpnkbvktcbcpltnlcbcgpltnlnlcbcgpltnlcgpltngntpnlcbcgntpnktngntpnlcbcgntpnkbvktcbcpltnlcbcgpltnlnlcbcgpltnlcgpltngntpnlcbcgntpnlcbcgntlcbcgntpnkbvn
nzmyzhhsoehahmorxpahsoehahmororxpahsoehahmhsoehahmmyzhhsoehahmhahsoehahmororxpahsoehahmhsoehahmmy...

output:


result:


Test #5:

score: 0
Runtime Error

input:

4
wwsqbwicfggaflmvdvegdkclrnybwwsqbwicfggafgdkclrnyaflmvdvegdkclrnybwwsqbwlrnybwwsqbwicfggafgdkclrnyaflmvdvegdkclrnybwwegdknybwwsqybwwsqbwlrnybwwsqbwicfggafgdkclrnyaflmvdvegdkclrnybqbwicfggafgdkclrnyafg
tgloxggsznuxqxggszxggszsznuxqxggszxggszggsznuxqxggsggsznuxqxggszxggszsznuxqxggszxggszggsznuxqxggs...

output:


result:


Test #6:

score: 0
Runtime Error

input:

3
ikcblmcsjillvojwymeimbaeipbhobwwnyaakcsvkghhusduehctjexrtaakewiruishkmewsleodhikrnfaternerxiqhamqutaiazbldrrmaddpidimwxsqwbgedswzowhovibaauncxsthwdvudokzpsfulbtbaapxlexrtaakewiruishkmewsleodhikrnfaternerxiqhamqutaiazbldrrmaddpidimwxsqwbgedswzowhovibaauncxsthwdvudokzpsfulbtbaapxlidimwxsqwbgedswzowh...

output:


result:


Test #7:

score: 0
Runtime Error

input:

3
gsxasrisfpretvfhxlwnysaarwkvizqrrntjecdltvqmsvvqgsdgkggdcszmtrfkfzwldzxnysgsxasrisfpretvfhxlwgsxasrisfpretvfhqrrntjecdltvqmsvvqgsdgkggdcszmtrfkfzwarwkvizqrrntjecdltvqmsvvqgsdgkggdcszmtrfkfzwldzxnysgsxasrisfpretvjecdltvqmsvvqgsdgkggdcszmtrfkfzwldzxnfkfzwldzxnysgsxasrisfpretvjecdltvqmsvvqgsdgkggdcsz...

output:


result:


Test #8:

score: 0
Runtime Error

input:

3
aekaabidsppfvwzguexdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjcqqcxdmycjcqqycjcqevwzguexdmycjcqqcxdmyabidsppfvwzguexdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjcqqcxdmycjcqqycjcqezguexdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjcqqcxdmycjcqqycjcqevwzguexdmycjcqqcxdmyxdmycjcqqcxdmycjcqqycjcqexdmycjcqqcxdmycjc...

output:


result:


Test #9:

score: 0
Runtime Error

input:

4
fqbsybwtrauafctwxtzxmhmelxssvxxapauncqgvqcwxfptcktzyanenlxfguejjhdzjufgmicmptfrfasgcgkqrjxzfcipjoqukvawffkuaqniqgotoylhiignmrevhwrruupzzawbqljitxdhyooixxxlqejxaaouufwvfuzxhigbilkiazqzypkovtnwwbssiqookpnsxvvhhfpjghkezwuushsoilgtbwholuilqdszikiptsvuoqpgxhwisfbwbkkpesawxuvhgfycxuwoklwjvtrpaulbexqlrsh...

output:


result:


Test #10:

score: 0
Runtime Error

input:

105
iiqnrmmdztbfxwmieuflzvuqveboseucomrfagkbzohyktiqnnbpkyhgciuwoqacerjgxthwjqxtkfjzvnqfnxlpfhnvznxfeglecvcllzhxhszcfphsnvjuewqelnlswxwauylfaufhnejutsngnybuxtaiglaekyeexsmxmrezvpuohjxxjatgttrbetirsmvrehqtawuvlqmuzltllmtgfmjmgrdagytkijfkfagsqumsfidsuyyclhotbrvhrotbzzmgbuyromlvuqnrpntauhvxaqereyvfzjla...

output:


result:


Test #11:

score: 0
Runtime Error

input:

1000001
s
o
k
g
r
z
l
d
z
i
n
u
d
j
i
o
k
b
o
s
h
y
w
y
u
k
v
p
d
f
e
x
v
q
d
o
p
r
s
o
z
f
i
e
r
q
s
b
u
i
w
b
g
u
b
a
e
w
p
j
e
v
g
z
l
l
o
c
c
i
q
b
n
b
h
g
t
z
i
p
h
e
s
q
a
u
s
e
s
i
n
w
f
t
y
t
g
o
v
j
w
o
m
l
r
u
s
k
t
c
c
d
i
u
t
i
q
l
m
j
v
b
f
d
w
f
w
c
t
r
l
p
h
y
b
y
u
v
l
n
x
n
s
f
j
n
...

output:


result:


Test #12:

score: 0
Runtime Error

input:

110
rxxioshkbndigoxntdcejhvoskbndigoxntdcejgoxntdcejhvoskbndigoxbndigoxntdcejhvoskbndigoxntdccejhvoskbndigogoxntdcejgoxntdcejhvoskbndigoxbnejgoxntdcejhvoskbndigoxbndigoxntdcejhvoskbndigoxntdccejhvoskbndigogoxntdcejgoxntdcejhvosxntdcejhvoskbndigoxbndigoxntdcejhvoskbndigoxntdccejhvoskbndigogoxntdcejgo...

output:


result:


Test #13:

score: 0
Runtime Error

input:

105
jlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizovzbjlugzbdizo...

output:


result:


Test #14:

score: 0
Runtime Error

input:

5
xsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmnxsolriymnoxsmn...

output:


result:


Test #15:

score: 0
Runtime Error

input:

30
qqgcvqshumzfapruaztsztbkdhknlqmegsgekylgmkmobfjceeuezxqcebpqrduyxccjcpqqbefdlqfpubvvymxfnovetrestidxxvnbzsekilcemxbmjaryqofjfjdashxrclsefyqqjswxsykbydcrshczqgaknzermwvsvmkgegeygqahteynlandipovosnbqkvnwfudnabuqddlhbzsdowmfmjtgywwjtmhaikoimkapplzsmrxcpjhdvdjtbievwmxewlokxocobbgoueqkpypkdzgejmzfyxjx...

output:


result:


Test #16:

score: 0
Runtime Error

input:

3
pounzdtkokaonqyllykjhhycqxdmmwndkjqlnlxbwzqlpqwcpjnysncilfxzdkenuwbjhakfacsptrukajksxnbksyjykplglopupccpgugzlcllmwgjjhtdhebttpcgfrcuvelczudmyrakngvypqdyufrpwtxbnaykelodhusglsqayoypebnzigqgcokrokbuvsadmsjzkbzkpzzucovnwltyzdrpnvmlnmqbezaqazcsybmcrhpnsjouofleczrplhqrgqhirjarmoudvjtqsjmjqzptzgimnbetrl...

output:


result:


Test #17:

score: 0
Runtime Error

input:

36
bqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrgxpbqsaqunccgyiarpeaezrg...

output:


result:


Test #18:

score: 0
Runtime Error

input:

36
ueuhiuuxbkqmcjrkbkknbuogliigucooglvofroicgveqoqtacgcwukjfuszwgpermvydlhfreljsdcuhkwdfgpmbhlznaefmbfrmmzdsmpmqrhxcddjmsvpziookuvyvbpjpqnideuvvbuzhxktrhkspahzvczsdpcvfrdkvxfszauizebrmljdlsfixedavhxbyalvyrpztjhsqkleljsdcuhkwdfgpfreljsdcuhkwdfgpmbhlznaefmbfrmmzdsmpmqrhxcddjmsvpziookuvyvbpjpqnideuvvbu...

output:


result:


Test #19:

score: 0
Runtime Error

input:

400001
ggg
eee
hhh
ppp
eee
nnn
hhh
aaa
nnn
uuu
xxx
ddd
ttt
sss
jjj
fff
ccc
ddd
aaa
xxx
vvv
mmm
qqq
bbb
qqq
uuu
bbb
ggg
mmm
qqq
ccc
hhh
nnn
yyy
hhh
qqq
fff
www
xxx
uuu
iii
ggg
nnn
rrr
sss
aaa
eee
vvv
iii
eee
vvv
www
qqq
ddd
qqq
rrr
qqq
xxx
ppp
yyy
nnn
bbb
uuu
bbb
yyy
aaa
ttt
www
mmm
lll
qqq
ggg
zzz
b...

output:


result:


Test #20:

score: 0
Runtime Error

input:

27
xtahmwzugvrelqyihbryeggyvqgliwxirxrdvtxbopgahekrhbpnixmfpuryqqiipznksnljetllzvehwvugsimiffivvsfktvumihxmdixcdelbziiuquevzotugagzvcndjkposprxtczumhoddsacivyowgqridxtqmikdbiyfhtsqhxtczxkvxbtfrknwjiowszbthabqtticsbgratmzufenstlbbczubdpkdqcylkcdnjvnejoarsplnaoocqkftcpwstwgdyjqhgfnstnjncuafkrhadptfgra...

output:


result: