Submission #51844

#TimeUsernameProblemLanguageResultExecution timeMemory
51844mareksomBowling (BOI15_bow)C++17
82 / 100
1029 ms6676 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 Matches(const string& a, const string& b) { if (a.size() != b.size()) return false; for (int i = 0; i < (int) a.size(); i++) { if (a[i] != '?' and b[i] != '?' and a[i] != b[i]) { return false; } } return true; } 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; auto Dorzuc = [](int i, const string& what, 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 (Matches(what, napis[i])) { dp[i][s][jed][dwa] += ile; } } }; for (int i = 1; i < n; i++) { 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(i, "x-", s + 10 + dwa + trzy, dwa, trzy, ile); } } // A/ if (jed < 10 and jed + dwa == 10) { for (int trzy = 0; trzy <= 10; trzy++) { Dorzuc(i, to_string(jed) + "/", s + 10 + trzy, trzy, empty, ile); } } // AB if (jed + dwa < 10) { Dorzuc(i, to_string(jed) + to_string(dwa), s + jed + dwa, empty, empty, ile); } } } } } ull wynik = 0; auto DorzucN = [&wynik](string what, int s, ull ile) -> void { assert(0 < ile); assert(0 <= s and s < MaxScore); if (Matches(what, napis[n])) { 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("xxx", s + 30, ile); } // xxA" if (jed == 10 and dwa == 10) { for (int a = 0; a <= 9; a++) { DorzucN("xx" + to_string(a), s + 20 + a, ile); } } // xA/" if (jed == 10 and dwa < 10) { DorzucN("x" + to_string(dwa) + "/", s + 20, ile); } // xAB" if (jed == 10 and dwa < 10) { for (int trzy = 0; dwa + trzy < 10; trzy++) { DorzucN("x" + to_string(dwa) + to_string(trzy), s + 10 + dwa + trzy, ile); } } // A/x if (jed < 10 and jed + dwa == 10) { DorzucN(to_string(jed) + "/x", s + 20, ile); } // A/B if (jed < 10 and jed + dwa == 10) { for (int trzy = 0; trzy < 10; trzy++) { DorzucN(to_string(jed) + "/" + to_string(trzy), s + 10 + trzy, ile); } } // AB-" if (jed + dwa < 10) { DorzucN(to_string(jed) + to_string(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:190:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
bow.cpp:193: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:194:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     else scanf("%c", &c);
          ~~~~~^~~~~~~~~~
bow.cpp:197:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%c", &c);
     ~~~~~^~~~~~~~~~
bow.cpp:200:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%c", &c);
       ~~~~~^~~~~~~~~~
bow.cpp:205: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:212: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...