QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#547050 | #7900. Gifts from Knowledge | xueman | WA | 14ms | 60372kb | C++17 | 4.6kb | 2024-09-04 17:33:16 | 2024-09-04 17:33:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const int N = 1000 + 10;
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
ll qpow(ll a, ll n)
{
ll res = 1;
while (n)
{
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
string s[maxn];
int vis[maxn];
vector<int> pos[maxn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
int n, m;
cin >> n >> m;
int cur = 0, ok = 1;
if (n == 1)
{
cout << 2 << endl;
continue;
}
map<string, vector<int>> mp;
for (int i = 1; i <= n; i++)
{
cin >> s[i];
s[i] = ' ' + s[i];
auto &v = mp[s[i]];
if (!v.empty())
{
pos[v.back()].push_back(i);
continue;
}
for (int j = 0; j <= m; j++)
vis[j] = 0;
for (int j = 1; j <= m; j++)
{
if (s[i][j] == '1')
{
if (!vis[j])
v.push_back(j), vis[j] = 1;
if (!vis[m - j + 1])
v.push_back(m - j + 1), vis[m - j + 1] = 1;
}
}
if (!v.empty())
{
sort(v.begin(), v.end(), greater<int>());
pos[v.back()].push_back(i);
}
else
cur++;
}
for (int i = 1; i <= m; i++)
{
if (pos[i].size() > 1)
{
auto &p = pos[i].back();
auto &x = s[p];
pos[i].pop_back();
for (auto t : pos[i])
{
auto &y = s[t];
bool flag = 0;
for (int j = 1; j <= m; j++)
{
if (x[j] == '1' && y[j] == '1')
{
flag = 1;
break;
}
}
if (flag)
{
reverse(y.begin() + 1, y.end());
for (int j = 1; j <= m; j++)
{
if (x[j] == '1' && y[j] == '1')
{
ok = 0;
goto end;
}
x[j] = max(x[j], y[j]);
}
}
else
{
for (int j = 1; j <= m; j++)
{
if (x[j] == '1' && y[j] == '1')
{
ok = 0;
goto end;
}
x[j] = max(x[j], y[j]);
}
}
}
for (int j = i + 1; j <= m; j++)
{
vis[j] = 0;
}
mp[x].clear();
for (int j = i + 1; j <= m; j++)
{
if (x[j] == '1')
{
if (!vis[j])
mp[x].push_back(j), vis[j] = 1;
if (m - j + 1 >= i + 1 && !vis[m - j + 1])
mp[x].push_back(m - j + 1), vis[m - j + 1] = 1;
}
}
if (!mp[x].empty())
{
sort(mp[x].begin(), mp[x].end(), greater<int>());
pos[mp[x].back()].push_back(p);
}
}
else if (pos[i].size() == 1)
{
auto p = pos[i].back();
auto &x = s[p];
pos[i].pop_back();
auto &v = mp[x];
v.pop_back();
if (v.empty())
cur++;
else
{
pos[v.back()].push_back(p);
}
}
}
end:
if (!ok)
{
cout << 0 << endl;
}
else
{
cout << qpow(2, cur) << endl;
}
for (int i = 0; i <= m; i++)
pos[i].clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 60048kb
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
Wrong Answer
time: 14ms
memory: 60372kb
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 1 512 1 1 1 1 1 1 128 32 16 16 2 1 2048 1 16384 128 128 32768 8192 128 64 16384 2 1 8192 1 1 1 8192 1 1 1024 32768 32768 16384 8 128 2 1 16384 1 1 256 1 1 32768 8192 8192 16 16384 16384 256 128 8 256 8 4096 512 2 1 4096 1 1 32768 1 1 1024 32768 32768 2 1 512 1 1 1 1 1 1 16 8192 16 256 1...
result:
wrong answer 4th numbers differ - expected: '32', found: '1'