Submission #3607874


Source Code Expand

#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*---------------------------------------*/

const int MOD = 1000000007;

const int MAX_NM = 100;
const int MAX_KILL = 1000;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;

  vector<int> a(1, 1), b(1, 1);
  int killa = 0, killb = 0;

  int temp1; cin >> temp1;
  killa += temp1;
  int a_index = 0;
  FOR(i, 1, n) {
    int temp2; cin >> temp2;
    killa += temp2;
    if (temp1 == temp2) ++a[a_index];
    else {
      a.push_back(1);
      ++a_index;
    }
    temp1 = temp2;
  }

  cin >> temp1;
  killb += temp1;
  int b_index = 0;
  FOR(i, 1, m) {
    int temp2; cin >> temp2;
    killb += temp2;
    if (temp1 == temp2) ++b[b_index];
    else {
      b.push_back(1);
      ++b_index;
    }
    temp1 = temp2;
  }

  vector<vector<long long> > dp(MAX_NM+1, vector<long long>(MAX_KILL+1, 0)); // 1-based & 0-based
  FOR(i, 1, MAX_NM+1) dp[i][0] = 1;
  REP(j, MAX_KILL+1) dp[1][j] = 1;
  FOR(i, 2, MAX_NM+1) {
    FOR(j, 1, MAX_KILL+1) {
      if (j-i >= 0) {
        dp[i][j] = (dp[i][j-i] % MOD) + (dp[i-1][j] % MOD);
        dp[i][j] %= MOD;
      } else dp[i][j] = dp[i-1][j];
    }
  }

  vector<vector<long long> > dpa(a_index+2, vector<long long>(MAX_KILL+1, 0)); // 1-based & 0-based
  FOR(i, 1, a_index+2) dpa[i][0] = 1;
  REP(j, MAX_KILL+1) dpa[1][j] = dp[a[0]][j];
  FOR(i, 2, a_index+2) {
    FOR(j, 1, MAX_KILL+1) {
      REP(k, j+1) {
        dpa[i][j] += (dpa[i-1][j-k] % MOD) * (dp[a[i-1]][k] % MOD);
        dpa[i][j] %= MOD;
      }
    }
  }

  vector<vector<long long> > dpb(b_index+2, vector<long long>(MAX_KILL+1, 0)); // 1-based & 0-based
  FOR(i, 1, b_index+2) dpb[i][0] = 1;
  REP(j, MAX_KILL+1) dpb[1][j] = dp[b[0]][j];
  FOR(i, 2, b_index+2) {
    FOR(j, 1, MAX_KILL+1) {
      REP(k, j+1) {
        dpb[i][j] += (dpb[i-1][j-k] % MOD) * (dp[b[i-1]][k] % MOD);
        dpb[i][j] %= MOD;
      }
    }
  }

  cout << (dpa[a_index+1][killb] * dpb[b_index+1][killa]) % MOD << "\n";
  return 0;
}

Submission Info

Submission Time
Task C - Kill/Death
User emthrm
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2394 Byte
Status AC
Exec Time 138 ms
Memory 1536 KB

Judge Result

Set Name All
Score / Max Score 500 / 500
Status
AC × 71
Set Name Test Cases
All 01_sample00, 01_sample01, 01_sample02, 01_sample03, 01_sample04, 02_minimal00, 02_minimal01, 02_minimal02, 02_minimal03, 03_maximal00, 03_maximal01, 04_random-easy00, 04_random-easy01, 04_random-easy02, 04_random-easy03, 04_random-easy04, 04_random-easy05, 04_random-easy06, 04_random-easy07, 04_random-easy08, 04_random-easy09, 04_random-easy10, 04_random-easy11, 04_random-easy12, 04_random-easy13, 04_random-easy14, 04_random-easy15, 04_random-easy16, 04_random-easy17, 04_random-easy18, 04_random-easy19, 05_random-large00, 05_random-large01, 05_random-large02, 05_random-large03, 05_random-large04, 05_random-large05, 05_random-large06, 05_random-large07, 05_random-large08, 05_random-large09, 05_random-large10, 05_random-large11, 05_random-large12, 05_random-large13, 05_random-large14, 05_random-large15, 05_random-large16, 05_random-large17, 05_random-large18, 05_random-large19, 06_random00, 06_random01, 06_random02, 06_random03, 06_random04, 06_random05, 06_random06, 06_random07, 06_random08, 06_random09, 06_random10, 06_random11, 06_random12, 06_random13, 06_random14, 06_random15, 06_random16, 06_random17, 06_random18, 06_random19
Case Name Status Exec Time Memory
01_sample00 AC 2 ms 1024 KB
01_sample01 AC 9 ms 1152 KB
01_sample02 AC 4 ms 1152 KB
01_sample03 AC 11 ms 1152 KB
01_sample04 AC 2 ms 1152 KB
02_minimal00 AC 2 ms 1152 KB
02_minimal01 AC 2 ms 1152 KB
02_minimal02 AC 2 ms 1024 KB
02_minimal03 AC 2 ms 1152 KB
03_maximal00 AC 7 ms 1152 KB
03_maximal01 AC 2 ms 1024 KB
04_random-easy00 AC 4 ms 1152 KB
04_random-easy01 AC 11 ms 1152 KB
04_random-easy02 AC 7 ms 1152 KB
04_random-easy03 AC 11 ms 1152 KB
04_random-easy04 AC 9 ms 1152 KB
04_random-easy05 AC 4 ms 1152 KB
04_random-easy06 AC 11 ms 1152 KB
04_random-easy07 AC 4 ms 1152 KB
04_random-easy08 AC 4 ms 1152 KB
04_random-easy09 AC 7 ms 1152 KB
04_random-easy10 AC 9 ms 1152 KB
04_random-easy11 AC 11 ms 1152 KB
04_random-easy12 AC 9 ms 1152 KB
04_random-easy13 AC 11 ms 1152 KB
04_random-easy14 AC 9 ms 1152 KB
04_random-easy15 AC 9 ms 1152 KB
04_random-easy16 AC 7 ms 1152 KB
04_random-easy17 AC 11 ms 1152 KB
04_random-easy18 AC 11 ms 1152 KB
04_random-easy19 AC 11 ms 1152 KB
05_random-large00 AC 125 ms 1536 KB
05_random-large01 AC 136 ms 1536 KB
05_random-large02 AC 134 ms 1536 KB
05_random-large03 AC 125 ms 1536 KB
05_random-large04 AC 129 ms 1536 KB
05_random-large05 AC 129 ms 1536 KB
05_random-large06 AC 129 ms 1536 KB
05_random-large07 AC 131 ms 1536 KB
05_random-large08 AC 131 ms 1536 KB
05_random-large09 AC 122 ms 1536 KB
05_random-large10 AC 129 ms 1536 KB
05_random-large11 AC 129 ms 1536 KB
05_random-large12 AC 125 ms 1536 KB
05_random-large13 AC 138 ms 1536 KB
05_random-large14 AC 133 ms 1536 KB
05_random-large15 AC 122 ms 1536 KB
05_random-large16 AC 127 ms 1536 KB
05_random-large17 AC 133 ms 1536 KB
05_random-large18 AC 129 ms 1536 KB
05_random-large19 AC 122 ms 1536 KB
06_random00 AC 113 ms 1536 KB
06_random01 AC 42 ms 1280 KB
06_random02 AC 58 ms 1280 KB
06_random03 AC 89 ms 1408 KB
06_random04 AC 36 ms 1152 KB
06_random05 AC 100 ms 1408 KB
06_random06 AC 78 ms 1408 KB
06_random07 AC 80 ms 1408 KB
06_random08 AC 78 ms 1408 KB
06_random09 AC 89 ms 1408 KB
06_random10 AC 53 ms 1280 KB
06_random11 AC 62 ms 1280 KB
06_random12 AC 98 ms 1408 KB
06_random13 AC 82 ms 1408 KB
06_random14 AC 76 ms 1408 KB
06_random15 AC 22 ms 1152 KB
06_random16 AC 107 ms 1408 KB
06_random17 AC 87 ms 1408 KB
06_random18 AC 73 ms 1280 KB
06_random19 AC 73 ms 1280 KB