Submission #51845

#TimeUsernameProblemLanguageResultExecution timeMemory
51845mareksomBowling (BOI15_bow)C++17
100 / 100
97 ms6220 KiB
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

using ull = unsigned long long;

constexpr int MaxScore = 400;
constexpr int nax = 15;

bool Cmp(char a, char b) {
  return a == '?' or b == '?' or a == b;
}

int n;
string napis[nax];
int score[nax];

#define empty empty83299832dskjflkdsajfkalkfasfasf
constexpr int empty = 11;
ull dp[nax][MaxScore][12][12];

void algos() {
  debug() << imie(n);
  debug() << range(napis + 1, napis + n + 1);
  debug() << range(score + 1, score + n + 1);
  for (int i = 0; i <= n + 1; i++) {
    for (int s = 0; s < MaxScore; s++) {
      for (int jed = 0; jed <= empty; jed++) {
        for (int dwa = 0; dwa <= empty; dwa++) {
          dp[i][s][jed][dwa] = 0;
        }
      }
    }
  }
  dp[0][0][empty][empty] = 1;
  for (int i = 1; i < n; i++) {
    const char AA = napis[i][0];
    const char BB = napis[i][1];
    auto Dorzuc = [i, AA, BB](char a, char b, int s, int jed, int dwa, ull ile) -> void {
      assert(0 < ile);
      assert(0 <= s and s < MaxScore);
      assert(0 <= jed and jed <= empty);
      assert(0 <= dwa and dwa <= empty);
      if (score[i] == -1 or score[i] == s) {
        if (Cmp(a, AA) and Cmp(b, BB)) {
          dp[i][s][jed][dwa] += ile;
        }
      }
    };
    for (int s = 0; s < MaxScore; s++) {
      for (int jed = 0; jed <= 10; jed++) {
        for (int dwa = 0; dwa <= 10; dwa++) {
          const ull ile = dp[i - 1][s][jed][dwa] + dp[i - 1][s][jed][empty] + dp[i - 1][s][empty][dwa] + dp[i - 1][s][empty][empty];
          if (!ile) continue;
          debug() << "dp[" << i << "][" << s << "][" << jed << "][" << dwa << "] = " << ile;
          // x-
          if (jed == 10) {
            for (int trzy = 0; trzy <= 10; trzy++) {
              Dorzuc('x', '-', s + 10 + dwa + trzy, dwa, trzy, ile);
            }
          }
          // A/
          if (jed < 10 and jed + dwa == 10) {
            for (int trzy = 0; trzy <= 10; trzy++) {
              Dorzuc('0' + jed, '/', s + 10 + trzy, trzy, empty, ile);
            }
          }
          // AB
          if (jed + dwa < 10) {
            Dorzuc('0' + jed, '0' + dwa, s + jed + dwa, empty, empty, ile);
          }
        }
      }
    }
  }
  ull wynik = 0;
  const char AA = napis[n][0];
  const char BB = napis[n][1];
  const char CC = napis[n][2];
  auto DorzucN = [&wynik, AA, BB, CC](char a, char b, char c, int s, ull ile) -> void {
    assert(0 < ile);
    assert(0 <= s and s < MaxScore);
    if (Cmp(a, AA) and Cmp(b, BB) and Cmp(c, CC)) {
      if (score[n] == -1 or score[n] == s) {
        wynik += ile;
      }
    }
  };
  for (int s = 0; s < MaxScore; s++) {
    for (int jed = 0; jed <= 10; jed++) {
      for (int dwa = 0; dwa <= 10; dwa++) {
        const ull ile = dp[n - 1][s][jed][dwa] + dp[n - 1][s][jed][empty] + dp[n - 1][s][empty][dwa] + dp[n - 1][s][empty][empty];
        if (!ile) continue;
        // xxx
        if (jed == 10 and dwa == 10) {
          DorzucN('x', 'x', 'x', s + 30, ile);
        }
        // xxA"
        if (jed == 10 and dwa == 10) {
          for (int a = 0; a <= 9; a++) {
            DorzucN('x', 'x', '0' + a, s + 20 + a, ile);
          }
        }
        // xA/"
        if (jed == 10 and dwa < 10) {
          DorzucN('x', '0' + dwa, '/', s + 20, ile);
        }
        // xAB"
        if (jed == 10 and dwa < 10) {
          for (int trzy = 0; dwa + trzy < 10; trzy++) {
            DorzucN('x', '0' + dwa, '0' + trzy, s + 10 + dwa + trzy, ile);
          }
        }
        // A/x
        if (jed < 10 and jed + dwa == 10) {
          DorzucN('0' + jed, '/', 'x', s + 20, ile);
        }
        // A/B
        if (jed < 10 and jed + dwa == 10) {
          for (int trzy = 0; trzy < 10; trzy++) {
            DorzucN('0' + jed, '/', '0' + trzy, s + 10 + trzy, ile);
          }
        }
        // AB-"
        if (jed + dwa < 10) {
          DorzucN('0' + jed, '0' + dwa, '-', s + jed + dwa, ile);
        }
      }
    }
  }
  printf("%llu\n", wynik);
}

void przyp() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char c;
    if (i == 1) scanf(" %c", &c);
    else scanf("%c", &c);
    napis[i].clear();
    napis[i].push_back(c);
    scanf("%c", &c);
    napis[i].push_back(c);
    if (i == n) {
      scanf("%c", &c);
      napis[i].push_back(c);
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &score[i]);
  }
  algos();
}

int main() {
  int t;
  scanf("%d", &t);
  while (t--) przyp();
  return 0;
}

Compilation message (stderr)

bow.cpp: In function 'void przyp()':
bow.cpp:189:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
bow.cpp:192:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     if (i == 1) scanf(" %c", &c);
                 ~~~~~^~~~~~~~~~~
bow.cpp:193:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     else scanf("%c", &c);
          ~~~~~^~~~~~~~~~
bow.cpp:196:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%c", &c);
     ~~~~~^~~~~~~~~~
bow.cpp:199:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%c", &c);
       ~~~~~^~~~~~~~~~
bow.cpp:204:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &score[i]);
     ~~~~~^~~~~~~~~~~~~~~~~
bow.cpp: In function 'int main()':
bow.cpp:211:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &t);
   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...