QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#651670 | #7900. Gifts from Knowledge | absabs | WA | 23ms | 7756kb | C++23 | 4.3kb | 2024-10-18 17:55:22 | 2024-10-18 17:55:45 |
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;
vector<int> ve;
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)
{
for(auto [L,c] : res)
{
if(mp[L] != i && mp[L])
{
if(mp[m - L + 1] != i && mp[m - L + 1])
f = 1;
else
// mp[m - L + 1] = 1,now ++ ;//这两个组同步交换
{
// pa[i] = mp[L];
mp[m - L + 1] = i;
}
}
else mp[L] = i;
}
}
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] != i && mp[j])
{
if(mp[m - j + 1] != i && 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] != i && mp[m - j + 1])
{
merge(i,mp[m - j + 1]);
}
}
}
map<int,int> hang;
pre(i,1,n)
{
pre(j,1,m)
{
if(g[i][j] == 0) continue;
hang[min(j,m-j+1)] ++ ;
}
}
for(auto [x,y] : hang)
{
if(y > 2)
{
cout << 0 << endl;
return ;
}
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7756kb
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: 18ms
memory: 3612kb
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: 23ms
memory: 3616kb
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'