답안 #51845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51845 2018-06-21T16:16:34 Z mareksom Bowling (BOI15_bow) C++17
100 / 100
97 ms 6220 KB
#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

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);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5756 KB Output is correct
2 Correct 18 ms 5756 KB Output is correct
3 Correct 19 ms 5756 KB Output is correct
4 Correct 22 ms 5860 KB Output is correct
5 Correct 22 ms 6048 KB Output is correct
6 Correct 25 ms 6048 KB Output is correct
7 Correct 26 ms 6048 KB Output is correct
8 Correct 23 ms 6048 KB Output is correct
9 Correct 21 ms 6048 KB Output is correct
10 Correct 23 ms 6124 KB Output is correct
11 Correct 33 ms 6124 KB Output is correct
12 Correct 10 ms 6124 KB Output is correct
13 Correct 4 ms 6124 KB Output is correct
14 Correct 10 ms 6124 KB Output is correct
15 Correct 5 ms 6124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6140 KB Output is correct
2 Correct 29 ms 6140 KB Output is correct
3 Correct 29 ms 6140 KB Output is correct
4 Correct 33 ms 6160 KB Output is correct
5 Correct 24 ms 6160 KB Output is correct
6 Correct 42 ms 6160 KB Output is correct
7 Correct 35 ms 6160 KB Output is correct
8 Correct 34 ms 6160 KB Output is correct
9 Correct 33 ms 6160 KB Output is correct
10 Correct 35 ms 6160 KB Output is correct
11 Correct 33 ms 6160 KB Output is correct
12 Correct 31 ms 6160 KB Output is correct
13 Correct 32 ms 6160 KB Output is correct
14 Correct 31 ms 6160 KB Output is correct
15 Correct 33 ms 6160 KB Output is correct
16 Correct 35 ms 6160 KB Output is correct
17 Correct 32 ms 6160 KB Output is correct
18 Correct 53 ms 6160 KB Output is correct
19 Correct 39 ms 6160 KB Output is correct
20 Correct 36 ms 6160 KB Output is correct
21 Correct 37 ms 6160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6160 KB Output is correct
2 Correct 24 ms 6160 KB Output is correct
3 Correct 25 ms 6160 KB Output is correct
4 Correct 23 ms 6160 KB Output is correct
5 Correct 25 ms 6160 KB Output is correct
6 Correct 31 ms 6160 KB Output is correct
7 Correct 33 ms 6160 KB Output is correct
8 Correct 31 ms 6160 KB Output is correct
9 Correct 37 ms 6160 KB Output is correct
10 Correct 34 ms 6160 KB Output is correct
11 Correct 35 ms 6160 KB Output is correct
12 Correct 45 ms 6160 KB Output is correct
13 Correct 36 ms 6160 KB Output is correct
14 Correct 31 ms 6160 KB Output is correct
15 Correct 35 ms 6160 KB Output is correct
16 Correct 52 ms 6160 KB Output is correct
17 Correct 45 ms 6160 KB Output is correct
18 Correct 34 ms 6160 KB Output is correct
19 Correct 35 ms 6160 KB Output is correct
20 Correct 34 ms 6160 KB Output is correct
21 Correct 36 ms 6160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6160 KB Output is correct
2 Correct 21 ms 6160 KB Output is correct
3 Correct 29 ms 6160 KB Output is correct
4 Correct 22 ms 6160 KB Output is correct
5 Correct 24 ms 6160 KB Output is correct
6 Correct 26 ms 6160 KB Output is correct
7 Correct 23 ms 6160 KB Output is correct
8 Correct 21 ms 6160 KB Output is correct
9 Correct 31 ms 6160 KB Output is correct
10 Correct 30 ms 6160 KB Output is correct
11 Correct 30 ms 6160 KB Output is correct
12 Correct 31 ms 6160 KB Output is correct
13 Correct 39 ms 6160 KB Output is correct
14 Correct 34 ms 6160 KB Output is correct
15 Correct 37 ms 6160 KB Output is correct
16 Correct 37 ms 6160 KB Output is correct
17 Correct 49 ms 6160 KB Output is correct
18 Correct 34 ms 6160 KB Output is correct
19 Correct 39 ms 6160 KB Output is correct
20 Correct 33 ms 6160 KB Output is correct
21 Correct 32 ms 6160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 5756 KB Output is correct
2 Correct 18 ms 5756 KB Output is correct
3 Correct 19 ms 5756 KB Output is correct
4 Correct 22 ms 5860 KB Output is correct
5 Correct 22 ms 6048 KB Output is correct
6 Correct 25 ms 6048 KB Output is correct
7 Correct 26 ms 6048 KB Output is correct
8 Correct 23 ms 6048 KB Output is correct
9 Correct 21 ms 6048 KB Output is correct
10 Correct 23 ms 6124 KB Output is correct
11 Correct 33 ms 6124 KB Output is correct
12 Correct 10 ms 6124 KB Output is correct
13 Correct 4 ms 6124 KB Output is correct
14 Correct 10 ms 6124 KB Output is correct
15 Correct 5 ms 6124 KB Output is correct
16 Correct 21 ms 6140 KB Output is correct
17 Correct 29 ms 6140 KB Output is correct
18 Correct 29 ms 6140 KB Output is correct
19 Correct 33 ms 6160 KB Output is correct
20 Correct 24 ms 6160 KB Output is correct
21 Correct 42 ms 6160 KB Output is correct
22 Correct 35 ms 6160 KB Output is correct
23 Correct 34 ms 6160 KB Output is correct
24 Correct 33 ms 6160 KB Output is correct
25 Correct 35 ms 6160 KB Output is correct
26 Correct 33 ms 6160 KB Output is correct
27 Correct 31 ms 6160 KB Output is correct
28 Correct 32 ms 6160 KB Output is correct
29 Correct 31 ms 6160 KB Output is correct
30 Correct 33 ms 6160 KB Output is correct
31 Correct 35 ms 6160 KB Output is correct
32 Correct 32 ms 6160 KB Output is correct
33 Correct 53 ms 6160 KB Output is correct
34 Correct 39 ms 6160 KB Output is correct
35 Correct 36 ms 6160 KB Output is correct
36 Correct 37 ms 6160 KB Output is correct
37 Correct 13 ms 6160 KB Output is correct
38 Correct 24 ms 6160 KB Output is correct
39 Correct 25 ms 6160 KB Output is correct
40 Correct 23 ms 6160 KB Output is correct
41 Correct 25 ms 6160 KB Output is correct
42 Correct 31 ms 6160 KB Output is correct
43 Correct 33 ms 6160 KB Output is correct
44 Correct 31 ms 6160 KB Output is correct
45 Correct 37 ms 6160 KB Output is correct
46 Correct 34 ms 6160 KB Output is correct
47 Correct 35 ms 6160 KB Output is correct
48 Correct 45 ms 6160 KB Output is correct
49 Correct 36 ms 6160 KB Output is correct
50 Correct 31 ms 6160 KB Output is correct
51 Correct 35 ms 6160 KB Output is correct
52 Correct 52 ms 6160 KB Output is correct
53 Correct 45 ms 6160 KB Output is correct
54 Correct 34 ms 6160 KB Output is correct
55 Correct 35 ms 6160 KB Output is correct
56 Correct 34 ms 6160 KB Output is correct
57 Correct 36 ms 6160 KB Output is correct
58 Correct 22 ms 6160 KB Output is correct
59 Correct 21 ms 6160 KB Output is correct
60 Correct 29 ms 6160 KB Output is correct
61 Correct 22 ms 6160 KB Output is correct
62 Correct 24 ms 6160 KB Output is correct
63 Correct 26 ms 6160 KB Output is correct
64 Correct 23 ms 6160 KB Output is correct
65 Correct 21 ms 6160 KB Output is correct
66 Correct 31 ms 6160 KB Output is correct
67 Correct 30 ms 6160 KB Output is correct
68 Correct 30 ms 6160 KB Output is correct
69 Correct 31 ms 6160 KB Output is correct
70 Correct 39 ms 6160 KB Output is correct
71 Correct 34 ms 6160 KB Output is correct
72 Correct 37 ms 6160 KB Output is correct
73 Correct 37 ms 6160 KB Output is correct
74 Correct 49 ms 6160 KB Output is correct
75 Correct 34 ms 6160 KB Output is correct
76 Correct 39 ms 6160 KB Output is correct
77 Correct 33 ms 6160 KB Output is correct
78 Correct 32 ms 6160 KB Output is correct
79 Correct 17 ms 6160 KB Output is correct
80 Correct 25 ms 6160 KB Output is correct
81 Correct 25 ms 6160 KB Output is correct
82 Correct 25 ms 6160 KB Output is correct
83 Correct 25 ms 6160 KB Output is correct
84 Correct 44 ms 6160 KB Output is correct
85 Correct 32 ms 6160 KB Output is correct
86 Correct 30 ms 6160 KB Output is correct
87 Correct 33 ms 6160 KB Output is correct
88 Correct 33 ms 6160 KB Output is correct
89 Correct 41 ms 6160 KB Output is correct
90 Correct 35 ms 6160 KB Output is correct
91 Correct 37 ms 6160 KB Output is correct
92 Correct 35 ms 6160 KB Output is correct
93 Correct 60 ms 6160 KB Output is correct
94 Correct 60 ms 6160 KB Output is correct
95 Correct 53 ms 6176 KB Output is correct
96 Correct 59 ms 6176 KB Output is correct
97 Correct 56 ms 6176 KB Output is correct
98 Correct 57 ms 6220 KB Output is correct
99 Correct 97 ms 6220 KB Output is correct
100 Correct 54 ms 6220 KB Output is correct