NC201928. Xor on Figures
描述
输入描述
The first line contains one integer .Each of the following lines contains a binary string of length . A cell is in the figure if and only if the -th character in the -th line is .
输出描述
Output one integer - the answer.
示例1
输入:
2 0101 0000 0101 0000
输出:
16
C++14(g++5.4) 解法, 执行用时: 49ms, 内存消耗: 616K, 提交时间: 2020-01-31 17:04:18
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1024+100; const ll mod=1e9+7; char mp[50][50]; ll n,m,cnt; bitset<N>p[N],xx; void upnode() { for(int i=n*n-1;i>=0;i--) if((xx[i]==1)){ if(!p[i].count()) { p[i]=xx;cnt++; break; } xx^=p[i]; } } ll fast(ll x,ll n) { ll ans=1; for(;n;n>>=1,x=x*x%mod) if(n&1) ans=ans*x%mod; return ans; } int main() { int k;cin>>k; n=(1<<k); for(int i=1;i<=n;i++) scanf("%s",mp[i]+1); for(int x=0;x<n;x++) for(int y=0;y<n;y++) { xx.reset(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { xx[((i+x-1)%n+1-1)*n+(j+y-1)%n]=mp[i][j]-'0'; } upnode(); } cout<<fast(2,cnt); return 0; }
C++11(clang++ 3.9) 解法, 执行用时: 22ms, 内存消耗: 604K, 提交时间: 2020-02-12 16:03:49
#include<bits/stdc++.h> #define pf printf #define sc(x) scanf("%d", &x) #define scs(x) scanf("%s", x) #define scl(x) scanf("%lld", &x) #define mst(a,x) memset(a, x, sizeof(a)) #define rep(i,s,e) for(int i=s; i<e; ++i) #define dep(i,e,s) for(int i=e; i>=s; --i) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 2e5 + 5; char s[50][50]; bitset<1050>p[1050],q; int n,cnt,ans=1,mod=1e9+7; void change(int x,int y){ rep(i,0,n) rep(j,0,n) q[(i+x)%n*n+(j+y)%n]=s[i][j]-'0'; rep(i,0,n*n) if(q[i]==1){ if(!p[i].count()){ p[i]=q; cnt++; break; } q^=p[i]; } } int main(){ sc(n); n=1<<n; rep(i,0,n) scs(s[i]); rep(i,0,n) rep(j,0,n) change(i,j); rep(i,0,cnt) ans=2ll*ans%mod; pf("%d\n",ans); }