QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92227#6132. Repair the ArtworkksunhokimWA 1ms3864kbC++172.6kb2023-03-30 14:29:402023-03-30 14:29:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 14:29:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2023-03-30 14:29:40]
  • 提交

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<ll,2>, MK>{});
  dp[0][0][0] = 1;
  int max_k = 0;
  for (int i=0;i<n;i++){
    vector next(n+1, array<array<ll,2>, MK>{});
    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) {
              max_k = max(max_k, k+(i-last+1));
              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) {
              max_k = max(max_k, k+(i-last+1));
              next[last][k+(i-last+1)][z] += dp[last][k][z];
            }
          }
        }
      }
    }
    dp = move(next);
  }

  mint ans = 0;
  for (int i=0;i<=n;i++){
    for (int j=0;j<=K;j++){
      mint nd = pow(mint(j),m) * (-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: 0
Wrong Answer
time: 1ms
memory: 3864kb

input:

3
2 2
2 0
3 2
2 1 0
3 1
2 1 0

output:

-8
-3
-1

result:

wrong answer 1st numbers differ - expected: '8', found: '-8'