QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630974 | #7900. Gifts from Knowledge | Pepinot | TL | 3ms | 12348kb | C++20 | 1.9kb | 2024-10-11 21:11:51 | 2024-10-11 21:11:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pii pair<int,int>
const int mod=1e9+7;
const int N=1e6+5;
bool iss;
bool is_c[N];
int cnt_c[N];
int len;
int n,m;
int power(int a, int b, int mod) {
int res = 1; // 初始结果为 1,因为任何数的 0 次方都是 1
while (b > 0) {
// 如果当前指数 b 是奇数,则需要把当前的 a 乘入结果
if (b & 1) res = (res * a) % mod;
// 将底数 a 平方,指数 b 减半
a = (a * a) % mod;
b >>= 1; // 相当于 b = b / 2,指数减半
}
return res; // 返回计算的结果
}
bool is(string s){
string w=s;
reverse(s.begin(),s.end());
if(w==s) return true;
return false;
}
void solve(){
iss=false;
memset(is_c,false,sizeof is_c);
memset(cnt_c,0,sizeof cnt_c);
cin>>n>>m;
len=m/2-(m%2==0?1:0);
vector<string> v(n);
int cnt1=0;
vector<string> vr;
for(int i=0; i<n; i++)
{
cin>>v[i];
if(is(v[i])) vr.push_back(v[i]);
if(m%2&&v[i][m/2]=='1'){
if(!is_c[m/2]) is_c[m/2]=true;
else iss=true;
}
}
for(auto j:vr){
for(int i=0; i<=len; i++)
if(j[i]=='1'){
if(!is_c[i])
is_c[i]=is_c[m-i-1]=true;
else iss=true;
}
}
for(auto i:v)
for(int j=0; j<m; j++)
if(i[j]=='1'){
cnt1++;
cnt_c[j]++;
if(cnt_c[j]>=3) iss=true;
}
if(cnt1>m||iss) cout<<0<<endl;
else{
bool ww=false;
for(int i=0; i<m; i++)
if(cnt_c[i]>1) ww=true;
int cnt_1=0,cnt_02=0;
for(int i=0; i<=len; i++){
if(!is_c[i]){
if(cnt_c[i]==1) cnt_1++;
else cnt_02++;
}
}
int cntr=vr.size();
int ans=cnt_02+(ww?0:1);
ans%=mod;
ans+=power(2,cnt_1+cntr,mod)-1;
cout<<ans%mod<<endl;
}
}
signed main() {
ios::sync_with_stdio(false),cin.tie(nullptr);
int t; cin>>t;
while(t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12348kb
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: -100
Time Limit Exceeded
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:
1029 32772 5 37 32769 130 36 24 23 6 16390 16389 130 130 32773 8193 132 67 16387 4 11 4 4101 23 4098 1032 32774 32776 16385 13 130 10 23 4099 8196 32776 8193 8193 20 16387 16387 262 129 16 262 14 4102 516 4 10 37 33 10 70 516 1026 32772 32775 7 69 16388 21 8197 19 262 23 68 8199 8199 72 1027 8 32770...