QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#494529 | #3025. Assimilation | PetroTarnavskyi# | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-07-27 16:03:49 | 2024-07-27 16:03:51 |
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;
bool check(int n, int k, VI& p, VI& a)
{
int s = 0;
FOR (i, 0, k)
s += a[i];
if (s != p[0])
return 0;
FOR (i, k, n)
{
s += a[k];
s -= a[i - k];
if (s != p[i - k + 1])
return 0;
}
return 1;
}
void solve()
{
int n, k;
cin >> n >> k;
VI a(n - k + 1);
FOR (i, 0, n - k + 1)
cin >> a[i];
VI mnK(k);
VI d(k);
FOR (i, 0, n - k + 1 - k)
{
d[k] += a[i + k] - a[i];
mnK[k] = min(mnK[k], d[k]);
}
VI p(k);
iota(ALL(p), 0);
vector<VI> ans;
do
{
VI cnt(n);
VI b(n);
bool ok = true;
FOR (j, 0, k)
{
int mn = -1;
FOR (i, 0, n)
{
if (cnt[i] == 0)
{
mn = i;
break;
}
}
int i = p[j];
int el = mn - mnK[j];
while (i < n)
{
b[i] = el;
if (cnt[el])
{
ok = false;
break;
}
cnt[el]++;
int i2 = i + k;
if (i2 < SZ(a))
{
el += a[i2];
el -= a[i];
}
i = i2;
}
if (!ok)
break;
}
if (!ok)
continue;
if (check(n, k, a, b))
ans.PB(b);
} while (next_permutation(ALL(p)));
cout << SZ(ans) << '\n';
for (auto v : ans)
{
FOR (i, 0, n)
{
if (i)
cout << ' ';
cout << v[i];
}
cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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...