제출 #381545

#제출 시각아이디문제언어결과실행 시간메모리
381545topovikSemafor (COI20_semafor)C++14
0 / 100
5 ms620 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define len(x) x.size() #define debug(x) cout << #x << " is " << x << endl using namespace std; typedef long long ll; typedef long double ld; const ll N = 32; const ll oo = 1e9 + 7; const ll k = 10; const int valid[10] = {8 + 2, 2, 8 + 1, 1 + 2 + 4, 2 + 16, 1 + 4 + 16, 8 + 4, 1 + 2, 1 + 4 + 8 + 16, 1 + 2 + 4 + 16}; vector <vector <int> > b; vector <vector <int> > a; int sum(int x, int y) { return (x + y) % oo; } int mult(int x, int y) { return (x * y) % oo; } vector <vector <int> > mult(vector <vector <int> > a, vector <vector <int> > b) { vector <vector <int> > c; c.resize(N); for (int i = 0; i < N; i++) c[i].resize(N); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { for (int c1 = 0; c1 < N; c1++) c[i][j] = sum(c[i][j], mult(a[i][c1], b[c1][j])); } return c; } vector <vector <int> > binpow(vector <vector <int> > c, int k) { if (k == 1) return c; if (k & 1) return mult(c, binpow(c, k - 1)); else { vector <vector <int> > c1 = binpow(c, k / 2); return mult(c1, c1); } } int main() { int m, n, k, x; cin >> m >> n >> k >> x; b.resize(N); for (int i = 0; i < N; i++) b[i].resize(N); for (int i = 0; i < N; i++) for (int j = 0; (1 << j) < N; j++) b[i][i ^ (1 << j)] = 1, b[i ^ (1 << j)][i] = 1; a = binpow(b, k); vector <vector <int> > c; c.resize(N); for (int i = 0; i < N; i++) c[i].resize(N); for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) c[valid[i]][valid[j]] = a[valid[i]][valid[j]]; a = c; a = binpow(a, n / k); if (n % k != 0) a = mult(binpow(b, n % k), a); for (int i = 0; i < 10; i++) cout << a[valid[x]][valid[i]] << "\n"; }
#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...