QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471429 | #6698. Flipping Game | chenxinyang2006 | AC ✓ | 3ms | 3880kb | C++20 | 4.0kb | 2024-07-10 21:07:45 | 2024-07-10 21:07:45 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
template <int P>
class mod_int
{
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const
{
Z res = 1, t = *this;
while (k)
{
if (k & 1)
res *= t;
if (k >>= 1)
t *= t;
}
return res;
}
Z &operator++()
{
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--()
{
x ? --x : x = P - 1;
return *this;
}
Z operator++(int)
{
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int)
{
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs)
{
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs)
{
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z operator-()
{
return -x;
}
Z &operator*=(const Z &rhs)
{
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) \
{ \
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
friend istream& operator>>(istream& is, mod_int& x)
{
long long tmp;
is >> tmp;
x = tmp;
return is;
}
friend ostream& operator<<(ostream& os, const mod_int& x)
{
os << x.val();
return os;
}
};
using Z = mod_int<mod>;
Z power(Z p,ll k){
Z ans = 1;
while(k){
if(k % 2 == 1) ans *= p;
p *= p;
k /= 2;
}
return ans;
}
Z C[105][105];
int T;
int n,k,m,inst;
char s[105],t[105];
void solve(){
scanf("%d%d%d",&n,&k,&m);
scanf("%s",s + 1);
scanf("%s",t + 1);
inst = 0;
rep(i,1,n) inst += s[i] != t[i];
Z answer = 0,cur,sum;
rep(i,0,n){
cur = sum = 0;
rep(j,0,min(m,i)){
if(j & 1) cur -= C[i][j] * C[n - i][m - j];
else cur += C[i][j] * C[n - i][m - j];
}
rep(j,0,min(inst,i)){
if(j & 1) sum -= C[inst][j] * C[n - inst][i - j];
else sum += C[inst][j] * C[n - inst][i - j];
}
answer += power(cur,k) * sum;
}
answer /= power(2,n);
printf("%d\n",answer.val());
}
int main(){
// freopen("test.in","r",stdin);
rep(i,0,100){
C[i][0] = 1;
rep(j,1,i) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
scanf("%d",&T);
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
3 3 2 1 001 100 3 1 2 001 100 3 3 2 001 100
output:
2 1 7
result:
ok 3 number(s): "2 1 7"
Test #2:
score: 0
Accepted
time: 3ms
memory: 3808kb
input:
1000 8 50 2 11111001 01100001 13 4 5 0010011001101 0000001010010 15 58 12 011111110110100 011010000101000 15 30 2 000101100111101 100010100110000 16 99 15 0111011010111101 1000100101011100 7 73 1 0010010 1010111 1 45 1 1 1 15 64 4 111000001000100 111000110011011 13 16 6 0000001101000 0101001010111 5...
output:
0 0 0 0 0 565123576 0 671397628 866048220 0 0 0 934159397 0 0 0 657964873 0 0 0 297620792 518284447 16636231 1 294524820 259008109 0 0 0 0 0 0 990349196 899244686 0 0 497963164 0 49814547 0 0 0 0 0 529815127 411739397 562040211 0 0 0 0 0 0 0 531433326 0 77531359 703399699 0 0 0 1 0 896329183 0 0 0 0...
result:
ok 1000 numbers