QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#799453 | #9735. Japanese Bands | ucup-team073 | RE | 0ms | 3600kb | C++20 | 3.7kb | 2024-12-05 14:22:41 | 2024-12-05 14:22:49 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef LOCAL
#define debug(...) printf(__VA_ARGS__)
#define edebug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define edebug(...)
#endif
#define int ll
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define nrep(i, x, y) for(int i = x; i >= y; --i)
#define ll long long
#define pii std::pair<int,int>
#define pb emplace_back
#define fi first
#define se second
template <class T>
inline void ckmax(T &a, T b) {
if(a < b) a = b;
}
template <class T>
inline void ckmin(T &a, T b) {
if(a > b) a = b;
}
auto rt_YES = []{puts("YES");};
auto rt_Yes = []{puts("Yes");};
auto rt_NO = []{puts("NO");};
auto rt_No = []{puts("No");};
namespace IO {
#define isdigit(x) (x >= '0' && x <= '9')
inline char gc() {
return getchar();
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline void read(T &x) {
double tmp = 1;
bool sign = 0;
x = 0;
char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc())
x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
inline void read(char *s) {
char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc())
*s++ = ch;
*s = 0;
}
inline void read(char &c) {
for(c = gc(); blank(c); c = gc());
}
inline void push(const char &c) {
putchar(c);
}
template <class T>
inline void print(T x) {
if(x < 0) {
x = -x;
push('-');
}
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top)
push(sta[--top] + '0');
}
template <class T>
inline void print(T x, char lastChar) {
print(x);
push(lastChar);
}
}
using namespace IO;
constexpr int mod=1e9+7;
int qpow(int a,int b=mod-2){
int ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int fac[100],faci[100];
int C(int n,int m){
if(n<m||n<0)return 0;
int ans=faci[m];
rep(i,1,m)ans=ans*(n-i+1)%mod;
return ans;
}
int solve(int N,int S,int T){
return C(N+T-1,S+T-1);
}
int N1,N2,m,k;
int vis[100],x[500],y[500],F[500];
int G[1000010];
void solve(){
read(N1),read(N2),read(m),read(k);
rep(i,0,m-1)vis[i]=0,F[i]=0;
rep(i,1,k){
read(x[i]),read(y[i]);
--x[i],--y[i];
vis[x[i]]=vis[y[i]]=1;
if(x[i]>y[i])std::swap(x[i],y[i]);
F[y[i]]|=(1<<x[i]);
}
int S=0,Z=0;
rep(i,0,m-1)S+=1-vis[i];
rep(i,0,m-1)if(vis[i])Z|=(1<<i);
std::vector<int>A;
rep(i,0,(1<<m)-1){
int flag=0;
G[i]=0;
rep(j,0,m-1)if(((i>>j)&1)&&((i&F[j])||!vis[j]))flag=1;
if(!flag){
G[i]=solve(N2,m-S-__builtin_popcount(i),S),A.pb(Z-i);
debug("%lld %lld\n",i,G[i]);
}
}
rep(i,0,m-1)rep(j,0,(1<<m)-1)if((j>>i)&1)
G[j]=(G[j]+G[j^(1<<i)])%mod;
int ans=0;
for(int i:A){
ans+=solve(N1,__builtin_popcount(i),S)*G[i];
debug("%lld %lld %lld\n",i,solve(N1,__builtin_popcount(i),S),G[i]);
ans%=mod;
}
print(ans,'\n');
}
signed main() {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//------------------------------------------------------------------
fac[0]=faci[0]=1;
rep(i,1,50)fac[i]=fac[i-1]*i%mod,faci[i]=qpow(fac[i]);
int t;read(t);while(t--)solve();
//------------------------------------------------------------------
end:
std::cerr << "Time : " << clock() - c1 << " ms" << std::endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
3 2 3 3 3 2 3 1 1 2 3 2 2 2 1 1 1 1 1 10 2 1 2 1 3
output:
6 4 0
result:
ok 3 lines
Test #2:
score: -100
Runtime Error
input:
500 481199252 336470888 8 58 4 7 7 6 4 7 2 6 2 6 2 7 8 3 8 7 8 1 2 6 2 6 1 2 1 5 3 1 6 4 2 4 4 7 2 6 2 3 7 1 4 4 5 1 2 7 6 7 8 1 8 7 5 6 4 2 4 2 8 5 5 4 6 8 5 6 3 8 1 7 1 6 7 1 5 6 6 3 1 1 2 7 3 3 1 5 5 5 8 7 3 4 6 3 8 8 7 4 1 6 2 1 8 7 4 5 2 7 3 5 2 6 4 5 4 3 2 6 2 2 2 1 1 1 500330171 987581927 10 ...