QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#494434 | #3025. Assimilation | PetroTarnavskyi# | TL | 0ms | 0kb | C++20 | 2.0kb | 2024-07-27 15:47:19 | 2024-07-27 15:47:20 |
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 1 << 20;
int cntComps;
vector<PII> g[N];
int col[N];
VI comps[6];
string ans;
bool dfs(int v)
{
comps[cntComps].PB(v);
for (auto [to, w] : g[v])
{
if (col[to] == -1)
{
col[to] = col[v] ^ w;
dfs(to);
}
if (col[to] != (col[v] ^ w))
{
return false;
}
}
return true;
}
void solve()
{
int n;
cin >> n;
VI p(n);
FOR(i, 0, n)
{
cin >> p[i];
p[i]++;
}
FOR(i, 0, n)
{
if (i - p[i] + 1 < 0 || i + p[i] - 1 >= n)
{
cout << "0\n";
return;
}
}
FOR(i, 0, n)
g[i].clear();
int l = -1, r = -1;
FOR(i, 0, n)
{
int cur = 0;
if (i <= r)
cur = min(r - i + 1, p[l + (r - i)]);
if (cur > p[i])
{
cout << "0\n";
return;
}
while (cur < p[i])
{
if (cur > 0)
{
g[i - cur].PB({i + cur, 0});
g[i + cur].PB({i - cur, 0});
}
cur++;
}
if (0 <= i - cur && i + cur < n)
{
g[i - cur].PB({i + cur, 1});
g[i + cur].PB({i - cur, 1});
}
if (i + cur - 1 > r)
{
r = i + cur - 1;
l = i - cur + 1;
}
}
fill(col, col + n, -1);
FOR(i, 0, n)
{
if (col[i] == -1)
{
if (cntComps == 6)
{
cout << "0\n";
return;
}
col[i] = 0;
dfs(i);
cntComps++;
}
}
cout << (1 << cntComps) << "\n";
ans.resize(n);
FOR(mask, 0, 1 << cntComps)
{
FOR(i, 0, cntComps)
{
int b = (mask >> (cntComps - 1 - i)) & 1;
for (int v : comps[i])
{
ans[v] = (col[v] ^ b) + '0';
}
}
cout << ans << "\n";
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
29 9 1 1 1 2 1 1 1 1 1 1 4 1 3 2 1 1 5 316660370 269357435 105688553 346785866 295093544 181703417 6 43402885 39947441 27068237 43810814 44913378 40095941 34779892 22 319594 3815194 3056481 6593888 7315914 6593888 4794774 2561877 5256242 4920603 5256242 3606645 864746 1594265 1235578 2361430 2277526...