QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#762277 | #7900. Gifts from Knowledge | rsy_ | WA | 21ms | 64216kb | C++14 | 4.4kb | 2024-11-19 14:24:35 | 2024-11-19 14:24:35 |
Judging History
answer
#include <bits/stdc++.h>
#define lb(x) (x&-x)
#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)
#define swap(a,b) (a^=b^=a^=b)
using namespace std;
using i64 = long long;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
void chmin(int &x, int c) {
x = min(x, c);
}
void chmax(int &x, int c) {
x = max(x, c);
}
namespace fast_IO{
#define IOSIZE 100000
int precision=3,POW[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};char ibuf[IOSIZE],obuf[IOSIZE],*p1=ibuf,*p2=ibuf,*p3=obuf;
#ifdef ONLINE_JUDGE
#define getchar()((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x)((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#define isdigit(ch)(ch>47&&ch<58)
#define isspace(ch)(ch<33)
#endif
template<typename T>inline T read(){T s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)&&(ch!=EOF))if(ch==45)w=-1;if(ch==EOF)return 0;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*w;}template<typename T>inline bool read(T&s){s=0;int w=1;char ch;while(ch=getchar(),!isdigit(ch)&&(ch!=EOF))if(ch==45)w=-1;if(ch==EOF)return 0;while(isdigit(ch))s=s*10+ch-48,ch=getchar();return s*=w,1;}inline bool read(char&s){while(s=getchar(),isspace(s));return 1;}inline bool read(char*s){char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return 0;while(!isspace(ch))*s++=ch,ch=getchar();*s='\000';return 1;}template<typename T>inline void print(T x){if(x<0)putchar(45),x=-x;if(x>9)print(x/10);putchar(x%10+48);}inline void print(char x){putchar(x);}inline void print(char*x){while(*x)putchar(*x++);}inline void print(const char*x){for(int i=0;x[i];i++)putchar(x[i]);}inline bool read(std::string&s){s="";char ch;while(ch=getchar(),isspace(ch));if(ch==EOF)return 0;while(!isspace(ch))s+=ch,ch=getchar();return 1;}inline void print(std::string x){for(int i=0,n=x.size();i<n;i++)putchar(x[i]);}inline bool read(bool&b){char ch;while(ch=getchar(),isspace(ch));b=ch^48;return 1;}inline void print(bool b){putchar(b+48);}inline bool read(double&x){int a=0,b=0;char ch=getchar();bool f=0;while(ch<48||ch>57){if(ch==45)f=1;ch=getchar();}while(47<ch&&ch<58){a=(a<<1)+(a<<3)+(ch^48);ch=getchar();}if(ch!=46){x=f?-a:a;return 1;}ch=getchar();while(47<ch&&ch<58){b=(b<<1)+(b<<3)+(ch^48),ch=getchar();}x=b;while(x>1)x/=10;x=f?-a-x:a+x;return 1;}inline void print(double x){if(x<0){putchar(45),x=-x;}x=round((long double)x*POW[precision])/POW[precision],print((long long)x),putchar(46),x-=(long long)(x);for(int i=1;i<=precision;i++)x*=10,putchar(x+48),x-=(int)x;}template<typename T,typename...T1>inline int read(T&a,T1&...other){return read(a)+read(other...);}template<typename T,typename...T1>inline void print(T a,T1...other){print(a),print(other...);}struct Fast_IO{~Fast_IO(){fwrite(obuf,p3-obuf,1,stdout);}}io;template<typename T>Fast_IO&operator>>(Fast_IO&io,T&b){return read(b),io;}template<typename T>Fast_IO&operator<<(Fast_IO&io,T b){return print(b),io;}
#define cout io
#define cin io
#define endl '\n'
}using namespace fast_IO;
const int maxn = 1e6 + 10, mod = 1e9 + 7;
int N, M, p[maxn], f[maxn << 1];
int sz[maxn];
string S[maxn];
vector<int> cnt[maxn];
int gf (int x) {
return p[x] == x ? x : p[x] = gf(p[x]);
}
void mg (int x, int y) {
int px = gf (x);
int py = gf (y);
if (px != py) {
p[px] = py, sz[py] += sz[px];
}
}
int qmi (int a, int b) {
int res = 1;
while (b) {
if (b & 1) {
res = 1ll * res * a % mod;
}
a = 1ll * a * a % mod;
b >>= 1;
}
return res;
}
void solve() {
cin >> N >> M;
L (i, 1, N * 2) p[i] = i, sz[i] = 1, f[i] = 0;
L (i, 1, M) cnt[i].clear();
L (i, 1, N) cin >> S[i], S[i] = ' ' + S[i];
L (i, 1, N) {
L (j, 1, M) {
if (S[i][j] == '0') continue;
cnt[j].push_back(i);
cnt[M - j + 1].push_back(i);
}
}
L (i, 1, M) {
if (cnt[i].size() > 2) {
cout << "0\n";
return ;
}
}
L (i, 1, M) {
if (cnt[i].size() < 2) continue;
int x = cnt[i][0];
int y = cnt[i][1];
if (x == y) continue;
mg (x, y + N);
mg (x + N, y);
// cout << x + N << ' ' << y << '\n';
}
L (i, 1, N) {
if (gf(i) == gf(i + N)) {
cout << "0\n";
return ;
}
}
int c = 0;
L (i, 1, N * 2) {
c += gf(i) == i;
}
cout << qmi(2, c / 2) << '\n';
}
signed main() {
int T = 1;
cin >> T;
while (T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 64216kb
input:
3 3 5 01100 10001 00010 2 1 1 1 2 3 001 001
output:
4 0 2
result:
ok 3 number(s): "4 0 2"
Test #2:
score: 0
Accepted
time: 21ms
memory: 63992kb
input:
15613 10 10 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 15 8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 1 5 00000 5 9 000000000 000000000 0000...
output:
1024 32768 2 32 32768 128 32 16 16 2 16384 16384 128 128 32768 8192 128 64 16384 2 4 2 4096 16 4096 1024 32768 32768 16384 8 128 2 16 4096 8192 32768 8192 8192 16 16384 16384 256 128 8 256 8 4096 512 2 4 32 32 2 64 512 1024 32768 32768 2 64 16384 16 8192 16 256 16 64 8192 8192 64 1024 2 32768 2 4 51...
result:
ok 15613 numbers
Test #3:
score: -100
Wrong Answer
time: 11ms
memory: 63116kb
input:
15759 9 6 000000 000000 000000 000000 000000 000000 000000 000000 000000 5 15 010000000000000 000000000000000 000000000000000 000100000000000 000100000000000 14 12 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000...
output:
512 16 16384 512 1024 4096 32768 4 2 512 512 512 512 8 2 256 16 4096 512 64 16 4096 512 32 32768 8192 32 2048 128 16 4096 64 32768 256 32 16384 8 512 32 2048 8 16 1024 2048 128 64 32 8 512 8 8192 256 8192 32768 2 8 512 512 256 32 2 2048 8192 8 64 8 2 16384 32768 32768 1024 4096 16384 16384 128 256 4...
result:
wrong answer 2380th numbers differ - expected: '0', found: '4'