description stringlengths 35 9.39k | solution stringlengths 7 465k |
|---|---|
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
inline long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
return n % MOD;
}
}
long long fp(long long a, long long p) {
long long ans = 1, cur = a;
for (long long i = 0; (1ll << i) ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 110;
long long kOper, n, cnt;
long long c[N];
struct Matrix {
long long x[N][N];
Matrix() {
for (int i = 0; i <= N - 1; ++i)
for (int j = 0; j <= N - 1; ++j) x[i][j] = 0;
}
void show() {
for (int i = 0; i <= cnt; ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long p = (long long)1e9 + 7;
int n, m, k, a[110];
long long f[110][110], C[110][110];
long long qmod(long long base, long long n) {
long long res = 1;
while (n) {
if (n & 1) {
res = res * base % p;
}
base = base * base % p;
n >>= 1;
}
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
vector<ll> v;
vector<vector<ll>> mat;
ll poww(ll x, ll y) {
if (y == 1) return x;
if (y % 2 == 0) {
ll powww = poww(x, y / 2);
return (powww * powww) % 1000000007;
} else {
return (poww(x, y - 1) % 1000000007) ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MOD = 1e9 + 7;
const... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
template <class _Tp>
void ckmax(_Tp &a, _Tp b) {
if (a < b) a = b;
}
template <class _Tp>
void ckmin(_Tp &a, _Tp b) {
if (a > b) a = b;
}
template <class _Tp>
_Tp gcd(_Tp a, _Tp b) {
return (b == 0) ? (a) : (gcd(b, a % b));
}
int read() {
char ch = getchar();
bool... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 101;
const int MOD = 1e9 + 7;
template <typename T>
inline void read(T &AKNOI) {
T x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') flag = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
c... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
using v2d = vector<vector<T>>;
template <class T>
bool uin(T& a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T& a, T b) {
return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_cloc... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline void Add(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }
inline int ksm(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = 1ll * a * a % mod)
if (b & 1) res = 1ll * res * a % mod;
return res;
}
int N, k, n;
struct Mat... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vb = vector<bool>;
using vc = vector<char>;
using vd = vector<double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vlli = vector<lli>;
using vvlli = vector<vlli>;
using pi = pair<int, int>;
using plli = pair<lli, lli>;
void readc(c... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 110;
int n, a[N], k, cnt;
template <typename T>
void gi(T &x) {
x = 0;
register char c = getchar(), pre = 0;
for (; c < '0' || c > '9'; pre = c, c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10ll + (c... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
int n, k, m, nn;
int a[110], dp[110][110];
struct Node {
int t[110][110];
} init, ans;
inline int fpow(int x, int y) {
int cur_ans = 1;
while (y) {
if (y & 1) cur_ans = 1ll * cur_ans * x % 1000000007;
x = 1ll * x * x % 1000000007;
y >>= 1;
}
return cur... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long N = 1e2 + 7;
const long long mod = 1e9 + 7;
long long n, k;
void pr(long long x[N][N]) {
printf("******\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", x[i][j]);
}
printf("\n");
}
printf("******\n");
}... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long n;
long long power(long long x, long long k) {
long long result = 1;
while (k) {
if (k & 1) result = (result * x) % 1000000007;
x = (x * x) % 1000000007;
k = k >> 1;
}
return result;
}
class matrix {
public:
long long a[105][105] = {};
mat... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
inline long long read() {
char c = getchar();
long long x = 0;
bool f = 0;
for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
return x;
}
const long long Mod = 1e9 + 7;
const ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | N, T = map(int, input().split())
A = [int(a) for a in input().split()]
if sum(A) > N//2:
A = [1-a for a in A][::-1]
K = sum(A)
S = sum(A[-K:])
M = K + 1
P = 10**9+7
inv = pow(N*(N-1)//2, P-2, P)
X = [[0]*M for _ in range(M)]
for i in range(M):
if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P
if i < M-1: X[i+1][i] =... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
struct mint {
int n;
mint(int n_ = 0) : n(n_ % MOD) {
if (n < 0) n += MOD;
}
};
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
int n, k, v[102];
int cnt0, cnt1, N;
int m[102][102], Ans[102][102];
int lgPow(int a, int b) {
int ret = 1;
for (int i = 0; (1 << i) <= b; ++i, a = (1LL * a * a) % 1000000007)
if (b & (1 << i)) ret = (1LL * ret * a) % 1000000007;
return ret;
}
void mul(int a[102][... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int p[105];
long long quickpow(long long a, long long x) {
long long res = 1;
while (x) {
if (x & 1) res = (res * a) % mod;
x >>= 1;
a = (a * a) % mod;
}
return res;
}
struct matrix {
long long mat[105][105];
matrix() { memse... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int mo = 1e9 + 7;
int n, K, kai1[N], m;
inline int fix(int x) {
if (x >= mo) return x - mo;
return x < 0 ? x + mo : x;
}
inline int hapow1(int x, int y) {
int daan = 1;
while (y) {
if (y & 1) daan = 1ll * daan * x % mo;
x = 1ll * x *... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
inline int read() {
int res = 0;
bool bo = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
bo = 1;
else
res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
return bo ? ~res + 1 : res... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 109;
const int mod = 1e9 + 7;
int n, a[N], k;
int cnt0, cnt1;
int b[N][N];
void jzc(int a[][N], int b[][N], int c) {
int ans[N][N];
for (int i = 0; i <= cnt0; i++)
for (int j = 0; j <= cnt0; j++) ans[i][j] = 0;
for (int i = 0; i <= cnt0; i++)
for... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
int n, v[104], k, nr0;
int** mat;
int _pow(int a, int b) {
if (b == 0) return 1;
if (b == 1) return a;
if (b % 2 == 0) return _pow(1LL * a * a % 1000000007, b / 2);
return 1LL * _pow(1LL * a * a % 1000000007, b / 2) * a % 1000000007;
}
int** mult(int** A, int** B) {... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 120;
const int mod = 1e9 + 7;
int n, k;
int um = 0;
int a[maxn];
struct Matrix {
int mat[maxn][maxn];
} ans, dt, zz;
void multi(Matrix &k1, Matrix k2) {
for (int i = 0; i <= um; i++)
for (int j = 0; j <= um; j++) zz.mat[i][j] = 0;
for (int k = 0; ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 105;
const int inv2 = 5e8 + 4;
int I[N][N], ans, sum[2], n, k, inv_tot, cnt;
int x[N];
long long fp(long long a, long long b) {
a %= MOD;
long long res = 1;
for (; b; b >>= 1, a = a * a % MOD) {
if (b & 1) res = a * res % MOD... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
template <int mod = MOD>
struct modBase {
modBase(int val = 0) : val((val % mod + mod) % mod) {}
int val;
modBase<mod> operator*(modBase<mod> o) {
return modBase<mod>((lon... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
int N;
struct Mat {
long long n[55][55] = {};
Mat friend operator*(Mat a, Mat b) {
Mat c;
for (int j = 0; j <= N; j++)
for (int i = 0; i <= N; i++)
for (int k = 0; k <= N; k++)
c.n[i][k] = (c.n[i][k] + a.n[i][j] * b.n[j][k]) % 1000000007;... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long powmod(long long a, long long k) {
long long ap = a, ans = 1;
while (k) {
if (k & 1) {
ans *= ap;
ans %= MOD;
}
ap = ap * ap;
ap %= MOD;
k >>= 1;
}
return ans;
}
long long inv(long long a) { re... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
struct MATRIX {
int n;
long long a[105][105];
MATRIX(int n) : n(n) {
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= n; ++j) a[i][j] = 0;
}
MATRIX operator*(const MATRIX &b) {
MATRIX c(n);
for (int i = 0; i <= n; ++i... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int maxN = 110;
const long long mod = 1e9 + 7;
int n;
long long k;
long long x, y;
int a[maxN];
struct SquareMatrix {
SquareMatrix(int _n) : n(_n) { data.assign(_n, vector<long long>(_n, 0)); }
vector<long long> &operator[](int i) { return data[i]; }
const vecto... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
template <class T>
struct Matrix {
struct VirtualVector {
vector<T> &R;
int off;
VirtualVector(vector<T> &R, const int off) : R(R), off(off) {}
T &operator[](int k) { return R[off + k]; }
};
vector<T> MAT;
int N, M;
Matrix(int N, int M) {
this-... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < (MOD << 1))
return n - MOD;
else if (n < (MOD << 1) + MOD)
return n - (MO... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, k, a[105], sum, Q;
struct Mat {
int s[105][105];
Mat() { memset(s, 0, sizeof s); }
Mat operator*(const Mat &B) {
Mat ret;
for (int k = 0; k <= sum; k++)
for (int i = 0; i <= sum; i++)
if (s[i][k])
for (in... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 102;
long long int mod = 1e9 + 7, b[N];
struct matrix {
long long int n, m;
long long int a[N][N];
matrix(int nn, int mm) {
n = nn;
m = mm;
}
void ide() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] =... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int n, k, a[102], now, o, z, t, i;
struct M {
int a[102][102];
friend M operator*(M x, M y) {
M z;
memset(z.a, 0, sizeof(z.a));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++)
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long chu(long long a, long long b) {
long long res = 1, p = 1000000007 - 2;
while (p) {
if (p & 1) {
res = res * b % 1000000007;
}
b = b * b % 1000000007;
p >>= 1;
}
return a * res % 1000000007;
}
int n, x, y, i, j, k, ac, wa, n0, n1, sb[6... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long int n, arr[105], hell = pow(10, 9) + 7;
long long int add(long long int a, long long int b) {
a += b;
if (a > hell) a -= hell;
return a;
}
long long int pw(long long int x, long long int y) {
long long int res = 1;
x %= hell;
while (y > 0) {
if (y ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int n, k, zero, one, cnt;
int a[105];
long long A[105][105], A_k[105][105];
void mult(long long M[105][105], long long N[105][105]) {
long long ret[105][105];
memset(ret, 0, sizeof ret);
for (int i = 0; i <= zero; ++i)
for (int j = 0; j <=... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
const i... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template <class T>
inline bool ckmin(T &a, T b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool ckmax(T &a, T b) {
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const double eps = (double)1e-8;
const int maxn = (int)2e5 + 20;
int n, m;
int a[105];
struct mat {
int n;
int a[105][105];
mat operator*(const mat &t) const {
mat res;
res.n = n;
for (int i = 0; i <= n; i++)
for (int j ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) :... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long n, k;
int arr[100];
long long len = 0;
long long us(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) {
ans *= a;
ans %= 1000000007;
}
b >>= 1;
a *= a;
a %= 1000000007;
}
return ans;
}
long long md(long l... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, k, sum;
int a[105];
struct matrix {
long long a[105][105];
int n;
matrix(int n = 0) : n(n) { memset(a, 0, sizeof(a)); }
void init() {
for (int i = 0; i <= n; ++i) a[i][i] = 1;
}
matrix operator*(matrix b) const {
matrix c(... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T> const& v) {
s << '{';
for (int i = 0; i < int(v.size()); i++) s << (i ? "," : "") << v[i];
return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T> const& p) {
ret... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
struct matrix {
vector<vector<ll>> mat;
matrix() {}
matrix(int n, ll v) : mat(n, vector<ll>(n)) {
for (int i = 0; i < n; ++i) mat[i][i] = v;
}
void resize(int n) {
mat.resize(n);
for (auto &it : mat) it.re... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int MODULO = 1000000007;
int gcd(int a, int b, int& ax, int& bx) {
if (b == 0) {
ax = 1;
bx = 0;
return b;
}
int g = gcd(b, a % b, bx, ax);
bx = (bx - (long long)(a / b) * ax % MODULO + MODULO) % MODULO;
return g;
}
int inv(int x) {
int ax, bx;... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long maxn = (long long)100 + 5;
const long long mod = (long long)1e9 + 7;
struct mat {
long long a[maxn][maxn];
mat() { memset(a, 0, sizeof(a)); }
};
long long n, k;
long long zero = 0, one = 0;
long long now = 0;
long long quick_pow_mod(long long a, long lon... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int INF = 110;
long long zero, size;
struct Matrix {
long long g[INF][INF];
Matrix() { memset(g, 0, sizeof(g)); }
Matrix operator*(const Matrix& a) {
Matrix cur;
for (int k = 0; k < size; k++) {
for (int i = 0; i < si... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f = ch ^ 45, ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? x : -x;
}
int n, m, c, inv;
const int mod = 1e9 + 7;
struct mat {
int... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Codeforces Round #553 (Div. 2)
Problem F. Sonya and Informatics
:author: Kitchen Tong
:mail: kctong529@gmail.com
Please feel free to contact me if you have any question
regarding the implementation below.
"""
__version__ = '1.8'
__date__ = '2019-04-21'
i... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
int NN;
struct mat {
long long a[105][105];
mat() { memset(a, 0, sizeof(a)); }
mat operator*(const mat& m1) const {
mat ret;
for (int i = 0; i <= NN; i++) {
for (int j = 0; j <= NN; j++) {
for (int k = 0; k <= NN; k++) {
ret.a[i][j] = (... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MOD = 1e9 + 7;
const... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, M = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1), EPS = 1e-9;
const int N = 101;
long long b[N];
long long o;
int n, k;
template <class T>
T fm(T a, T b) {
return (-b < a and a < b) ? a : a % b;
}
template <int... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
struct Matrix {
long long ma[110][110];
int n;
Matrix() {}
Matrix(int _n) {
n = _n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) ma[i][j] = 0;
}
Matrix operator*(const Matrix &b) const {
Matrix ret =... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long N = 105;
const long long mod = 1e9 + 7;
long long mul[N][N][35], dp[N], ar[N], dp1[N];
long long binpow(long long x, long long y) {
long long tich = 1;
while (y) {
if (y % 2 == 1) {
tich *= x;
tich %= mod;
}
x *= x;
x %= mod;
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 1e9 + 7;
int n, k, a[N], ze;
struct mat {
int mt[N][N];
mat() { memset(mt, 0, sizeof(mt)); }
mat operator*(const mat &t) const {
mat ans;
for (int i = 0; i <= ze; i++)
for (int j = 0; j <= ze; j++)
for (int k = 0; k <= ze; ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
struct matrix {
int a[105][105];
} b;
int tot, st, a[105], ans[105];
int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 102;
long long int mod = 1e9 + 7, b[N];
struct matrix {
long long int n, m;
long long int a[N][N];
matrix(int nn, int mm) {
n = nn;
m = mm;
}
void ide() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] =... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
namespace debug {
template <class T1, class T2>
void pr(const pair<T1, T2> &x);
template <class T, size_t SZ>
void pr(const array<T, SZ> &x);
template <class T>
void pr(const vector<T> &x);
template <class T>
void pr(const set<T> &x);
template <class T1, class T2>
void pr(c... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const long long MOD = 1e9 + 7;
int a[N];
struct Matrix {
long long a[N][N];
};
long long fpow(long long a, long long b) {
long long rtn = 1;
while (b) {
if (b & 1) rtn = (rtn * a) % MOD;
b >>= 1;
a = (a * a) % MOD;
}
return rtn;
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
new Main().go();
}
PrintWriter out;
Reader in;
BufferedReader br;
Main() throws IOException {
try {
//br = new BufferedReader( new FileReader("in... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < (MOD << 1))
return n - MOD;
else
return n % MOD;
}
}
long long fp(long ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 105, MOD = 1e9 + 7;
struct mat {
int a[N][N];
mat() { memset(a, 0, sizeof(a)); }
};
int n, cnt[2];
mat operator*(const mat &a, const mat &b) {
mat c = mat();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; +... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
const int mod = 1e9 + 7;
struct Matrix {
int val[maxn][maxn];
int height, width;
Matrix(int h, int w) {
height = h;
width = w;
memset(val, 0, sizeof val);
}
Matrix operator*(const Matrix& other) const {
assert(width == oth... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 110;
struct MAT {
long long a[MAXN][MAXN];
MAT() {
for (int i = 0; i < MAXN; i++)
fo... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long maxm = 105;
const long long mod = 1e9 + 7;
long long a[maxm];
struct Node {
long long a[maxm][maxm];
Node operator*(const Node& x) const {
Node ans;
for (long long i = 0; i < maxm; i++)
for (long long j = 0; j < maxm; j++) ans.a[i][j] = 0;
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
struct Matrix {
int size;
long long **a;
Matrix(int sz) {
size = sz;
a = new long long *[sz];
for (int i = 0; i < size; i++) a[i] = new long long[sz];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++) a[i][j] = 0;
}
Matrix operato... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int M = 105;
const int mod = 1000000007;
struct Matrix {
long long int val[M][M];
} I;
Matrix mul(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++) {
C.val[i][j] = 0;
for (int k = 0; k < M; k++) {
C.v... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, k;
int sum0, sum... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int mod = 1e9 + 7, inv2 = ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < 2 * MOD)
return n - MOD;
else
return n % MOD;
}
}
long long fp(long lon... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
struct matrix {
int row, col;
long long v[102][102];
};
matrix mul(matrix mat, matrix mat2) {
matrix r;
r.row = mat.row;
r.col = mat.col;
for (int i = 0; i < r.row; i++) {
for (int j = 0; j < r.col; j++) {
long long sum = 0;
for (int k = 0; k < m... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int a[105], n, K, sn;
struct Mat {
int a[105][105];
Mat() { memset(a, 0, sizeof(a)); }
Mat operator*(const Mat &b) const {
Mat c = Mat();
for (int i = 0; i <= sn; i++)
for (int j = 0; j <= sn; j++)
for (int k = 0; k <=... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 105;
long long m;
struct node {
long long row, col;
long long data[N][N];
node(long long n, long long m) {
row = n;
col = m;
for (long long i = 0; i <= n; i++)
for (long long j = 0; j <= n; j++) data... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> matrix_multiply(vector<vector<long long>> a,
vector<vector<long long>> b) {
long long x = a.size(), y = a[0].size(), z = b[0].size(), i, j, k;
vector<vector<long long>> ans(x, vector<long long>(z, 0));
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | import sys; input=sys.stdin.readline
# print(input())
N, T = map(int, input().split())
A = [int(a) for a in input().split()]
if sum(A) > N//2:
A = [1-a for a in A][::-1]
K = sum(A)
S = sum(A[-K:])
M = K + 1
P = 10**9+7
inv = pow(N*(N-1)//2, P-2, P)
X = [[0]*M for _ in range(M)]
for i in range(M):
if i > 0: X[i-... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | //package round553;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class F {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), K = n... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.TreeSet;
import java.util.function.B... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, typenam... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 105;
long long m;
struct node {
long long data[N][N];
node operator*(node b) {
node t;
for (long long i = 0; i <= m; i++) {
for (long long j = 0; j <= m; j++) {
t.data[i][j] = 0;
}
}
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int M = 105;
const int mod = 1000000007;
struct Matrix {
long long int val[M][M];
} I;
Matrix mul(Matrix A, Matrix B) {
Matrix C;
for (int i = 0; i < M; i++)
for (int j = 0; j < M; j++) {
C.val[i][j] = 0;
for (int k = 0; k < M; k++) {
C.v... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline bool isSquare(T x) {
T y = sqrt(x + 0.5);
return (y * y) == x;
}
template <class T1, class T2>
inline T1 gcd(T1 a, T2 b) {
return b ? gcd(b, a % b) : a;
}
template <class T1, class T2>
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int n, m, t;
int a[105];
long long cnt[2];
long long inv2;
long long inv;
struct matrix {
long long f[51][51];
matrix() { memset(f, 0, sizeof(f)); };
};
matrix e;
matrix f;
matrix h;
matrix add(matrix x, matrix y) {
int i, j;
matrix ret;
f... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
if (n < 0) {
return (n % MOD + MOD) % MOD;
} else {
if (n < MOD)
return n;
else if (n < 2 * MOD)
return n - MOD;
else
return n % MOD;
}
}
long long fp(long lon... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5, MOD = 1e9 + 7;
long long fact[N], fact_inv[N];
long long mul(long long a, long long b) { return a * b % MOD; }
long long add(long long a, long long b) { return (a + b) % MOD; }
long long power(long long a, long long b) {
if (!b) return 1;
long lon... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\t";
err(++it, args...);
}
template <typename T1, type... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long mpow(long long x, long long y, long long m) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x % m;
y = y >> 1;
x = x * x % m;
}
return res;
}
long long sz;
const long long M = 100;
long long mat[100][100], fin[100][100];
void mult1(... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
int n, k, m, t, a[105];
struct mat {
long long d[105][105];
};
mat ans, f, c;
long long fm, fm_ni;
const int p = 1e9 + 7;
inline long long ni(long long x) {
if (x <= 1) return x;
return (p - p / x) * ni(p % x) % p;
}
inline void mul(mat &a, mat &b) {
for (int i = 0; i <= m; i++)
for... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
inline void read(long long &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void print... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long N = 100;
const long long M = 1e4;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long read() {
long long s = 0;
register bool neg = 0;
register char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-');
for (; ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 10;
const long long LNF = 2e18;
int n, k, A[110], st, C[2];
class matrix {
public:
int X[101][101] = {};
matrix operator*(matrix &P) {
matrix R;
for (int i = 0; i <= n; i++)
for (int j = ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | M = 10 ** 9 + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))
z, o = a.count(0), a.count(1)
d = pow(n * (n - 1) // 2, M - 2, M)
if z > o:
o, z = z, o
a = [1 - x for x in a][::-1]
res = [[0] * (z + 1) for i in range(z + 1)]
tf = [[0] * (z + 1) for i in range(z + 1)]
for i in range(z + ... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
int n, i, j, k, z, o;
bool b[105];
long long anti;
struct matrix {
int n, m;
long long mt[55][55];
} a;
matrix operator*(matrix a, matrix b) {
int i, j, k;
matrix ans;
for (i = 0; i < a.n; i++)
for (j = 0; j < b.m; j++)
for (k = ans.mt[i][j] = 0; k < a.m; k++)
ans.mt... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
void add(long long &x, long long y) {
x += y;
if (x >= mo) x -= mo;
}
struct matrix {
long long c[105][105], n, m;
matrix() {
memset(c, 0, sizeof(c));
n = m = 0;
}
matrix operator*(const matrix &rhs) const {
matrix res;
... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
long long n, k;
int a[105];
int N = 100;
long long mod = 1e9 + 7;
struct node {
long long mat[105][105];
friend node operator*(node x, node y) {
node c;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N; j++) {
c.mat[i][j] = 0;
for (int... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 1;
const int md = 1e9 + 7;
void inc(int &x, int y) { x = x + y >= md ? x + y - md : x + y; }
int len;
struct Mat {
int a[maxn][maxn];
Mat() { memset(a, 0, sizeof(a)); }
Mat operator*(const Mat &x) const {
Mat res = Mat();
for (int i = 0;... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
struct matrix {
int a[105][105];
} b;
int tot, st, a[105], ans[105];
int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long N = 110;
const long long Mod = 1e9 + 7;
long long Fact[N];
long long add(long long x, long long y) {
x %= Mod, y %= Mod;
return (x + y) % Mod;
}
long long sub(long long x, long long y) {
x %= Mod, y %= Mod;
return (x - y + Mod) % Mod;
}
long long mul... |
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array a of length n, consisting only of the numbers 0 and 1, and the number k. Exactly k times the following happens:
* Two numbers i and... | #include <bits/stdc++.h>
using namespace std;
const long long N = 107;
const long long MOD = 1000 * 1000 * 1000 + 7;
inline long long mod(long long n) {
if (n < MOD)
return n;
else
return n % MOD;
}
long long fp(long long a, long long p) {
long long ans = 1, cur = a;
for (long long i = 0; (1ll << i) <= ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.