列表

详情


NC201928. Xor on Figures

描述

It’s always hard to write original problems, right?
Given an integer and a grid, where the cell contains a number initially. The grid is considered to be a torus, that is, the cell to the right of is ,and the cell below the is . There is a lattice figure consisting of cells. Note that doesn’t have to be connected.
In each operation, we can place at some position on the grid (only translations are allowed, rotations and reflections are prohibited) and flip the number in each cell covered by . Here the number will be fliped to and vice versa.
More formally, let be the set of cells , you can choose any x,y with and flip the number in the cell for each .
Now we want to know how many patterns we can achieve with any number of operations from an all-zero board. Since the answer can be very large, you only need to output it modulo .

输入描述

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); 
}

上一题