QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235326 | #3030. Fantastic Compression | TlenekWodoru | AC ✓ | 499ms | 22096kb | C++14 | 2.2kb | 2023-11-02 17:15:13 | 2023-11-02 17:15:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int S[25009];
int n,k;
vector<int>U;
bool ZAJ[10];
vector<vector<int>>ODP;
vector<vector<int>>V;
vector<int>KROL;
void Generuj()
{
vector<int>odp(n+1);
vector<bool>zaj(n+1);
int h=1;
for(int u : U)
{
while(zaj[h]==1)
{
h++;
}
for(int i=0;i<V[u].size();i++)
{
const int temp=h+V[u][i];
odp[u+k*i]=temp;
if(temp<1||n<temp||zaj[temp]==1){return;}
zaj[temp]=1;
}
}
for(int i=k;i<=n;i+=k)
{
int xd=S[i-k+1];
for(int j=i-k+1;j<=i;j++)
{
xd-=odp[j];
}
if(xd!=0){return;}
}
ODP.push_back(odp);
}
void F(int v)
{
if(v==k+1)
{
Generuj();
return;
}
for(int i=1;i<=k;i++)
{
if(ZAJ[i]==0)
{
ZAJ[i]=1;
U.push_back(i);
F(v+1);
U.pop_back();
ZAJ[i]=0;
}
}
}
int main()
{ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N;
cin>>N;
for(int I=1;I<=N;I++)
{
ODP.clear();
V.clear();
KROL.clear();
cin>>n>>k;
for(int i=1;i<=n-k+1;i++)
{
cin>>S[i];
}
V.resize(k+1);
KROL.resize(k+1);
bool cv=0;
for(int i=1;i<=k;i++)
{
int suma=0;
set<int>SS;
for(int j=i;j<=n;j+=k)
{
V[i].push_back(suma);
suma+=S[j+1]-S[j];
if(j+k>n){continue;}
if(suma<-n||n<suma||SS.count(suma)){cv=1;}
SS.insert(suma);
}
for(int j=0;j<V[i].size();j++)
{
if(V[i][j]<V[i][KROL[i]])
{
KROL[i]=j;
}
}
int kopia=V[i][KROL[i]];
for(int j=0;j<V[i].size();j++)
{
V[i][j]-=kopia;
}
}
if(cv==1){cout<<0<<'\n';continue;}
F(1);
cout<<ODP.size()<<'\n';
sort(ODP.begin(),ODP.end());
for(vector<int>XD : ODP)
{
for(int i=1;i<=n;i++)
{
cout<<XD[i]<<" ";
}
cout<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 3716kb
input:
964 5 4 10 11 5 3 9 8 10 5 2 9 6 5 4 4 4 9 4 4 9 5 4 13 11 5 3 11 10 10 4 2 4 6 3 5 4 12 13 5 3 9 12 9 5 2 9 8 6 3 5 3 10 8 7 5 3 7 10 9 5 4 13 14 5 3 7 8 11 4 2 6 7 4 4 4 11 4 3 8 6 5 3 7 6 6 5 3 10 9 11 5 4 10 11 5 3 12 9 8 5 5 15 5 3 9 10 7 5 5 15 4 2 4 7 6 5 2 4 5 9 7 5 2 6 3 6 7 5 3 7 6 9 4 2 3...
output:
6 4 1 2 3 5 4 1 3 2 5 4 2 1 3 5 4 2 3 1 5 4 3 1 2 5 4 3 2 1 5 1 2 3 4 1 5 1 5 4 2 3 1 0 0 6 4 1 3 5 2 4 1 5 3 2 4 3 1 5 2 4 3 5 1 2 4 5 1 3 2 4 5 3 1 2 0 0 6 2 1 4 5 3 2 1 5 4 3 2 4 1 5 3 2 4 5 1 3 2 5 1 4 3 2 5 4 1 3 2 1 5 3 4 2 2 4 3 5 1 0 1 3 5 2 1 4 1 2 4 1 5 3 6 1 3 4 5 ...
result:
ok 21593 lines
Test #2:
score: 0
Accepted
time: 66ms
memory: 4268kb
input:
11 23853 5 56129 66231 66759 74651 77738 77157 85513 66445 73648 57593 74488 61493 64993 60263 75748 73267 81681 86675 92728 73438 57233 47483 52402 42838 42284 58984 70785 56245 55687 58425 43712 34748 37286 34598 31262 36760 48165 57037 66885 67122 67572 62188 51356 32408 33791 44793 45602 58279 6...
output:
1 1955 20238 7208 20162 6566 12057 20766 15100 23249 5985 20413 1698 22303 7194 22880 7418 5198 17573 22679 20399 15832 10192 23626 3389 4194 6082 15111 14062 2835 20894 17883 571 13504 5573 6181 8919 3109 10816 2237 11679 20324 11981 20664 2474 12129 14940 1149 1716 3857 23131 15749 13826 5377 8992...
result:
ok 16 lines
Test #3:
score: 0
Accepted
time: 499ms
memory: 22096kb
input:
7 6666 6 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 16690 16691 16692 16693 16694 16695 16696 16697 16698 16699 16700 16701 16702 16703 16704 16705 16706 16707 16708 16709 16710 16711 16712 16713 16714 16715 16716 16717 16718 167...
output:
720 1 1112 2223 3334 4445 5556 2 1113 2224 3335 4446 5557 3 1114 2225 3336 4447 5558 4 1115 2226 3337 4448 5559 5 1116 2227 3338 4449 5560 6 1117 2228 3339 4450 5561 7 1118 2229 3340 4451 5562 8 1119 2230 3341 4452 5563 9 1120 2231 3342 4453 5564 10 1121 2232 3343 4454 5565 11 1122 2233 3344 4455 55...
result:
ok 971 lines