Submission #381520

#TimeUsernameProblemLanguageResultExecution timeMemory
381520ne4eHbKaSemafor (COI20_semafor)C++17
12 / 100
44 ms620 KiB
#include <bits/stdc++.h> using namespace std; #ifndef _LOCAL //#pragma GCC optimize("O3,Ofast") #else #pragma GCC optimize("O0") #endif template<typename t> inline void umin(t &a, const t b) {a = min(a, b);} template<typename t> inline void umax(t &a, const t b) {a = max(a, b);} typedef pair<int, int> pii; typedef long long ll; typedef long double ld; typedef int8_t byte; ll time() {return chrono::system_clock().now().time_since_epoch().count();} mt19937 rnd(time()); #define ft first #define sd second #define len(f) int((f).size()) #define bnd(f) (f).begin(), (f).end() #define _ <<' '<< #define pc __builtin_popcount const int inf = 1e9 + 5; const ll inf64 = 4e18 + 5; const int md = 1e9 + 7; namespace MD { void add(int &a, const int b) {if((a += b) >= md) a -= md;} void sub(int &a, const int b) {if((a -= b) < 0) a += md;} int prod(const int a, const int b) {return ll(a) * b % md;} }; int m, x; ll n, k; const string I[10] = { " # # ", " # ", "# # ", "### ", " # #", "# # #", " ## ", "## ", "# ###", "### #" }; int ms[10]; int dif[10][10]; const int N = 11; const int M = 100; template<int n> struct mat { int f[n][n]; mat operator* (const mat &o) const { mat res; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { res.f[i][j] = 0; for(int t = 0; t < n; ++t) MD::add(res.f[i][j], MD::prod(f[i][t], o.f[t][j])); } } return res; } void e() { memset(f, 0, sizeof f); for(int i = 0; i < n; ++i) f[i][i] = 1; } void c() { memset(f, 0, sizeof f); } }; template<int n> mat<n> power(mat<n> f, ll p) { mat<n> res; res.e(); for(ll i = 1; p; i <<= 1) { if(i > 1) f = f * f; if(i & p) res = res * f, p ^= i; } return res; } mat<M> make(ll n) { mat<N> a; a.c(); for(int i = 0, p = m * 5; p; --p, ++i) { int j = i + 1; a.f[i][j] += j; a.f[j][i] += p; } a = power(a, n); if(m == 1) for(int i = 5; i <= 10; ++i) a.f[i][i] = 0; mat<M> res; res.c(); if(m == 2) { for(int i = 0, fi = 0; i < 10; ++i) for(int j = 0; j < 10; ++j, ++fi) for(int x = 0, se = 0; x < 10; ++x) for(int y = 0; y < 10; ++y, ++se) res.f[fi][se] = a.f[0][dif[i][x] + dif[j][y]]; } else { for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j) res.f[i][j] = a.f[0][dif[i][j]]; } return res; } void solve() { for(int i = 0; i < 10; ++i) for(int j = 0; j < 5; ++j) if(I[i][j] == '#') ms[i] |= 1 << j; for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j) dif[i][j] = pc(ms[i] ^ ms[j]); cin >> m >> n >> k >> x; mat<M> a = power(make(k), n / k) * make(n % k); int u = m == 1 ? 10 : 100; for(int i = 0; i < u; ++i) cout << a.f[i][x] << '\n'; #ifdef KEK cerr << endl; #endif // KEK } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef _LOCAL // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); #else system("color a"); freopen("in.txt", "r", stdin); int t; cin >> t; while(t--) #endif solve(); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...