QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650969 | #7894. Many Many Heads | absabs | WA | 0ms | 3824kb | C++23 | 3.9kb | 2024-10-18 17:13:42 | 2024-10-18 17:13:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
int x = 0, f = 1;
char ch = nc();
while (ch < 48 || ch > 57)
{
if (ch == '-')
f = -1;
ch = nc();
}
while (ch >= 48 && ch <= 57)
x = x * 10 + ch - 48, ch = nc();
return x * f;
}
void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
int n,m;
int qmi(int a,int b)
{
int res = 1;
while(b)
{
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int pa[N];
bool st[N];
int find(int x)
{
if(x != pa[x])
return pa[x] = find(pa[x]);
return pa[x];
}
void merge(int a,int b)
{
int fa = find(a),fb = find(b);
if(fa == fb) return ;
pa[fa] = fb;
return ;
}
void solve()
{
cin >> n >> m;
vector<vector<int>> g(n + 1,vector<int>(m + 1));
map<int,int> mp;
int f = 0,tp = 0,ans = 1,res = 0;
vector<int> ve;
int now = n;
pre(i,1,n) pa[i] = i , st[i] = 0;
pre(i,1,n)
{
int cnt = 0,ff = 0;
map<int,int> res;
pre(j,1,m)
{
char c;
cin >> c;
g[i][j] = c - '0';
if(g[i][j] == 0) continue;
cnt ++ ;
res[j] = 1;
}
for(auto [L,c] : res)//自己全部对称住
{
if(res[m - L + 1]) continue ;
else ff = 1;
}
if((!ff || cnt == 0) && m != 1)
{
// ve.push_back(i);
st[i] = 1;
continue;
}
//不是自己全部对称住
pre(j,1,m)
{
if(g[i][j] == 0) continue;
if(mp[j])
{
if(mp[m - j + 1])
f = 1;
else
// mp[m - j + 1] = 1,now ++ ;//这两个组同步交换
{
// pa[i] = mp[j];
mp[m - j + 1] = i;
}
}
else mp[j] = i;
}
}
pre(i,1,n)
{
if(st[i]) continue;
pre(j,1,m)
{
if(g[i][j] == 0) continue;
if(mp[m - j + 1])
{
merge(i,mp[m - j + 1]);
// pa[i] = mp[m - j + 1];
// if(mp[m - j + 1])
// f = 1;
// else
// // mp[m - j + 1] = 1,now ++ ;//这两个组同步交换
// {
// // cout << i << " " << mp[j] << endl;
// pa[i] = mp[j];
// mp[m - j + 1] = i;
// }
}
// else if()
// else mp[j] = 1;
}
}
int cnt = 0;
pre(i,1,n)
if(pa[i] == i) cnt ++;
// cout << endl;
if(f) cout << 0 << endl;
else
{
cout << qmi(2,cnt) % mod << endl;
}
}
// #define LOCAL
signed main()
{
ios
// fre
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
#endif
int t = 1;
cin >> t;
while (t--)
solve();
#ifdef LOCAL
auto end = std::chrono::high_resolution_clock::now();
cout << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << '\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3824kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
1 1 1 1 1 1
result:
wrong output format YES or NO expected, but 1 found [1st token]