QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#92240 | #6132. Repair the Artwork | ksunhokim | TL | 60ms | 6532kb | C++17 | 2.6kb | 2023-03-30 14:35:16 | 2023-03-30 14:35:19 |
Judging History
answer
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using ll = long long;
#define dbg(x) "(" << #x <<": " << (x) << ") "
template<typename Ostream, typename Cont>
enable_if_t<is_same_v<Ostream,ostream>, Ostream&>
operator<<(Ostream& os, const Cont& v){
os<<"[";
for(auto& x:v){os<<x<<", ";}
return os<<"]";
}
template<typename ...Ts>
ostream& operator<<(ostream& os, const pair<Ts...>& p){
return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// Modular Integer
// does arithmetics (mod P) automatically
const int MOD = 1000000007; // 998244353
struct mint {
int v=0;
int val() { return v; }
mint() = default;
mint(ll v) : v(v % MOD) { v += (v < 0) * MOD; }
};
mint& operator+=(mint& a, mint b) { if ((a.v += b.v) >= MOD) a.v -= MOD; return a; }
mint& operator-=(mint& a, mint b) { if ((a.v -= b.v) < 0) a.v += MOD; return a; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return mint((ll) a.v * b.v); }
mint& operator*=(mint& a, mint b) { return a = a * b; }
mint pow(mint a, ll p) { return p == 0 ? 1 : pow(a * a, p / 2) * (p & 1 ? a : 1); }
mint inv(mint a) { return pow(a, MOD - 2); }
mint operator/(mint a, mint b) { return a * inv(b); }
ostream& operator<<(ostream& os, mint p){
return os<<p.val();
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> A(n);
for (int i=0;i<n;i++)
cin >> A[i];
const int MK = 5050;
int K = n*(n+1)/2;
vector dp(n+1, array<array<mint,2>, MK>{});
dp[0][0][0] = 1;
int max_k = 0;
for (int i=0;i<n;i++){
vector next(n+1, array<array<mint,2>, MK>{});
max_k = min(K, max_k+i+1);
for (int last=0;last<=i;last++){
for (int k=0;k<=max_k;k++){
for (int z=0;z<2;z++){
if (A[i] == 2) {
if (k+(i-last+1) <= K) {
next[last][k+(i-last+1)][z] += dp[last][k][z];
}
next[i+1][k][z^1] += dp[last][k][z];
} else if (A[i] == 1) {
next[i+1][k][z] += dp[last][k][z];
} else {
if (k+(i-last+1) <= K) {
next[last][k+(i-last+1)][z] += dp[last][k][z];
}
}
}
}
}
dp = move(next);
}
mint ans = 0;
for (int j=0;j<=K;j++){
mint ddd = pow(mint(j),m);
for (int i=0;i<=n;i++){
mint nd = ddd * (dp[i][j][0] - dp[i][j][1]);
ans += nd;
}
}
cout << ans.v << "\n";
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3676kb
input:
3 2 2 2 0 3 2 2 1 0 3 1 2 1 0
output:
8 3 1
result:
ok 3 number(s): "8 3 1"
Test #2:
score: 0
Accepted
time: 60ms
memory: 6532kb
input:
100 2 1 0 1 2 1 2 1 2 1 1 1 1 6 2 1 14 2 3 12 2 2 2 6 13 2 2 0 2 0 2 7 14 0 0 0 0 2 2 0 5 8 2 2 0 0 0 5 5 2 2 0 0 0 12 3 0 2 0 2 2 0 1 2 2 2 2 0 7 11 2 2 0 1 0 1 0 4 4 2 1 2 2 7 5 1 1 0 0 1 0 0 2 14 2 1 15 17 2 2 1 2 0 0 0 0 2 0 1 0 0 0 0 15 11 1 1 2 0 1 2 0 0 1 0 2 1 1 1 1 15 18 1 0 1 0 2 2 1 2 0 1...
output:
1 1 0 1 1 175715347 833406719 467966815 458805426 650344 2208 537089254 146 7776 1 703335050 123067364 355668256 487954758 53774922 544070885 436748805 369291507 760487845 513270785 501075264 487417783 464534262 979007529 137956839 143317512 648268264 851188473 702545117 946416372 595191705 35054850...
result:
ok 100 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
1000 20 673037423 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 774964932 2 2 2 17 730319736 2 2 1 1 2 2 2 2 2 2 2 2 2 1 2 2 1 11 893285699 2 2 2 1 2 1 2 2 2 1 2 16 98149251 1 2 1 2 1 2 1 1 2 1 2 2 2 2 1 2 7 556953277 1 2 2 1 2 2 2 3 228111342 1 1 1 11 640995044 2 2 1 1 2 2 1 1 1 1 1 19 741419324 1 1 2 ...
output:
447486147 204414804 452414918 684654914 763978130 805973365 0 922180033 214948715 401017738 0 201368027 752718484 611006275 848004989 391560729 950934074 202096866 443534870 24665646 482580424 321199514 922369975 152629767 5546104 1 194145234 1 1 1 562381239 648246425 497517379 217016206 961507095 4...