QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#288289 | #5446. 琪露诺的符卡交换 | catagory | 40 | 6ms | 8160kb | C++23 | 9.0kb | 2023-12-22 13:50:55 | 2023-12-22 13:50:56 |
Judging History
answer
#include<bits/stdc++.h>
#define LL int
#define SZ(x) ((LL)(x.size()))
using namespace std;
inline int read(){
int q=0,w=1;
char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
return q*w;
}
void write(LL x){
if(x<0){putchar('-');x=(-x);}
if(x>9)write(x/10);
putchar('0'+x%10);
}
inline void writeln(LL x){write(x);puts("");}
inline void writecs(LL x){write(x);putchar(' ');}
void lsh(vector<LL>&vc){
sort(vc.begin(),vc.end(),[&](LL x,LL y){return x<y;});
vc.erase(unique(vc.begin(),vc.end()),vc.end());
return ;
}
namespace dinic{
const int N = 100000+95 , M = 500000+95;
LL n,s,t;
struct Edge{
LL to,nxt,w;
}e[M<<1];LL head[N],tot=1,cur[N];
inline void add(LL u,LL v,LL w){
e[++tot].to=v;e[tot].nxt=head[u];
e[tot].w=w;head[u]=tot;return ;
}
inline void add_e(LL u,LL v,LL w){
add(u,v,w);add(v,u,0);
}
inline void clear(){
for(LL i=1;i<=n;i++)head[i]=cur[i]=0;
n=s=t=0;tot=1;return ;
}
LL dep[N];
inline bool bfs(){
for(LL i=1;i<=n;i++){dep[i]=-1;cur[i]=head[i];}
queue<LL>q;q.push(s);dep[s]=0;
while(!q.empty()){
LL x=q.front();q.pop();
for(LL i=head[x];i;i=e[i].nxt){
if(dep[e[i].to]==-1&&e[i].w){
dep[e[i].to]=dep[x]+1;
q.push(e[i].to);
}
}
}
return (dep[t]!=-1);
}
inline LL dfs(LL x,LL flow){
if(x==t)return flow;
LL lastflow=flow;
for(LL i=cur[x];i&&flow;i=e[cur[x]].nxt){
cur[x]=i;
if(dep[e[i].to]==dep[x]+1&&e[i].w){
LL d=dfs(e[i].to,min(flow,e[i].w));
if(d){e[i].w-=d;e[i^1].w+=d;flow-=d;}
}
}
if(lastflow==flow)dep[x]=-1;
return lastflow-flow;
}
inline LL solve(){
LL maxflow=0;
while(bfs())maxflow+=dfs(s,(LL)(1e18));
return maxflow;
}
}
namespace TP{
const long long N = 200+95;
LL lim;vector<LL>E[N];LL matchL[N],matchR[N];
void clear(){
for(LL i=1;i<=lim;i++){E[i].clear();matchL[i]=matchR[i]=0;}
return ;
}
void add_e(LL x,LL y){E[x].push_back(y);return ;}
bool vis[N];
bool dfs(LL x){
if(vis[x])return 0;
vis[x]=1;
for(auto y:E[x]){
if(!matchR[y]){matchL[x]=y;matchR[y]=x;return 1;}
if(dfs(matchR[y])){matchL[x]=y;matchR[y]=x;return 1;}
}
return 0;
}
void solve(LL CNT=-1){
LL cnt=0;
for(LL t=1;t<=lim;t++){
for(LL x=1;x<=lim;x++)vis[x]=0;
cnt+=dfs(t);
}
if(CNT!=-1)assert(CNT==cnt);
return ;
}
}
#define x1 x_tmp_1
#define y1 y_tmp_1
struct pt{LL x,y;};
const int N = 200+5;
int T,n;vector<pt>a[N][N];bool b[N][N];vector<vector<LL>>ans;LL __c[N][N];
void make(LL x0,LL y0,LL x1,LL y1){
// cout<<" x0 = "<<x0<<" y0 = "<<y0<<" x1 = "<<x1<<" y1 = "<<y1<<endl;
if(x0==x1&&y0==y1){
assert(SZ(a[x0][y0])&&!b[x0][y0]);
a[x0][y0].pop_back();
b[x0][y0]=1;return ;
}
// cout<<" SZ(a[x0][y0]) = "<<SZ(a[x0][y0])<<endl;
// cout<<" SZ(a[x1][y1]) = "<<SZ(a[x1][y1])<<endl;
// cout<<" b[x0][y1] = "<<b[x0][y1]<<" b[x1][y0] = "<<b[x1][y0]<<endl;
assert(SZ(a[x0][y0])&&SZ(a[x1][y1])&&!b[x0][y1]&&!b[x1][y0]);
pt X=a[x0][y0].back();a[x0][y0].pop_back();
pt Y=a[x1][y1].back();a[x1][y1].pop_back();
b[x0][y1]=b[x1][y0]=1;
ans.push_back({X.x,X.y,Y.x,Y.y});
return ;
}
#define PLL pair<LL,LL>
#define mp(a,b) make_pair(a,b)
#define fir first
#define sec second
#define random(a,b) (rand()%(b-a+1)+a)
namespace sub{
LL __cnt[N];
bool check(){
ans.clear();
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++){a[i][j].clear();b[i][j]=0;}
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++){a[i][__c[i][j]].push_back((pt){i,j});}
for(LL i=1;i<=n;i++){
LL mx=0;
for(LL j=1;j<=n;j++)mx=max(mx,SZ(a[i][j]));
if(mx<(n-1))return false;
}
return true;
}
void solve(){
TP::lim=n;
{
vector<LL>ord(n+2);vector<LL>vis(n+2);for(LL i=1;i<=n;i++)vis[i]=0;
for(LL v=1;v<=n;v++)
for(LL i=1;i<=n;i++)
if(!vis[i]&&SZ(a[i][v])>=(n-1)){ord[v]=i;vis[i]=1;break;}
vector<pt>tmp[n+2][n+2];
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)tmp[i][j]=a[i][j];
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)a[i][j]=tmp[ord[i]][j];
}
for(LL t=1;t<=n;t++){
vector<LL>visL(n+2),visR(n+2);
for(LL i=t+1;i<=n;i++)
if(SZ(a[t][i])){make(t,i,t,i);visR[i]=1;}
for(LL i=t+1;i<=n;i++)
if(SZ(a[i][t])){make(i,t,i,t);visL[i]=1;}
LL cnt=0;
for(LL i=t+1;i<=n;i++)
if(!b[t][i])cnt++;
TP::clear();
for(LL i=t+1;i<=n;i++)
for(LL j=t+1;j<=n;j++)
if(!b[t][i]&&!b[j][t]&&SZ(a[j][i]))TP::add_e(i,j);
TP::solve(cnt);
for(LL i=t+1;i<=n;i++){
if(b[t][i])continue;
LL j=TP::matchL[i];
make(t,t,j,i);
}
}
writeln(SZ(ans));
for(LL t=0;t<SZ(ans);t++){
for(LL i=0;i<SZ(ans[t]);i++)writecs(ans[t][i]);
puts("");
}
for(LL t=0;t<SZ(ans);t++){
LL x0=ans[t][0],y0=ans[t][1],x1=ans[t][2],y1=ans[t][3];
swap(__c[x0][y0],__c[x1][y1]);
}
for(LL t=1;t<=n;t++){
vector<LL>vec(n);
for(LL i=1;i<=n;i++)vec[i-1]=__c[t][i];
lsh(vec);assert(SZ(vec)==n);
}
return ;
}
}
int main(){
random_device seed;srand(seed());
T=read();
while(T--){
/* n=random(1,5);
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)__c[i][j]=i;
while(true){
LL v=random(0,10);
cerr<<" v = "<<v<<endl;
if(v==0)break;
LL x0=random(1,n),y0=random(1,n);
LL x1=random(1,n),y1=random(1,n);
swap(__c[x0][y0],__c[x1][y1]);
}
cout<<n<<endl;
for(LL i=1;i<=n;i++){
for(LL j=1;j<=n;j++)cout<<__c[i][j]<<" ";
cout<<endl;
}*/
n=read();
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)__c[i][j]=read();
if(sub::check()){
sub::solve();
continue;
}
/* while(true){
LL v=random(0,1000);
cerr<<" v = "<<v<<endl;
if(v==0)break;
LL x0=random(1,n),y0=random(1,n);
LL x1=random(1,n),y1=random(1,n);
swap(__c[x0][y0],__c[x1][y1]);
}*/
/* for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)__c[i][j]=i;
for(LL i=1;i<=n;i++)
swap(__c[i][n],__c[random(1,n)][n]);*/
/* for(LL i=1;i<=n;i++){
for(LL j=1;j<=n;j++)cout<<__c[i][j]<<" ";
cout<<endl;
}*/
LL fl=0;
while(!fl){
fl=1;
ans.clear();
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++){a[i][j].clear();b[i][j]=0;}
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++){a[i][__c[i][j]].push_back((pt){i,j});}
{
vector<LL>ord(n+2);vector<LL>vis(n+2);for(LL i=1;i<=n;i++)vis[i]=0;
for(LL i=1;i<=n;i++)ord[i]=i;
for(LL i=1;i<=n;i++)
swap(ord[i],ord[random(1,n)]);
vector<pt>tmp[n+2][n+2];
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)tmp[i][j]=a[i][j];
for(LL i=1;i<=n;i++)
for(LL j=1;j<=n;j++)a[i][j]=tmp[ord[i]][j];
}
vector<LL>idxL(n+2),idxR(n+2);LL Id=0,S=0,T=0;
vector<vector<LL>>idL(n+2),idR(n+2);
S=++Id;T=++Id;
for(LL i=1;i<=n;i++)idxL[i]=++Id;
for(LL i=1;i<=n;i++)idxR[i]=++Id;
for(LL i=1;i<=n;i++){idL[i].resize(n+2);idR[i].resize(n+2);}
for(LL t=1;t<=n;t++){
dinic::clear();dinic::n=Id;dinic::s=S;dinic::t=T;LL Idx=Id;
for(LL i=1;i<=n;i++){
if(!SZ(a[i][t]))continue;
dinic::add_e(S,idxL[i],SZ(a[i][t]));
}
for(LL j=1;j<=n;j++){
if(b[j][t])continue;
dinic::add_e(idxR[j],T,1);
}
vector<vector<LL>>vec;
for(LL i=1;i<=n;i++){
vec.push_back({dinic::tot+1,i,i,t});
dinic::add_e(idxL[i],idxR[i],1);
}
LL cnt=0;
for(LL i=1;i<=n;i++)
if(!b[i][t])cnt++;
cnt-=dinic::solve();
for(LL K=(t+1);K<=n;K+=2){
for(LL k=K;k<=min(K+1,n);k++){
for(LL i=1;i<=n;i++){
if(!SZ(a[i][t]))continue;
idL[i][k]=++Idx;
if((!b[i][k]))dinic::add_e(idxL[i],idL[i][k],1);
}
for(LL j=1;j<=n;j++){
if(b[j][t])continue;
idR[j][k]=++Idx;
if(SZ(a[j][k])>=1)dinic::add_e(idR[j][k],idxR[j],1);
}
dinic::n=Idx;
for(LL i=1;i<=n;i++)
if(SZ(a[i][t]))
for(LL j=1;j<=n;j++)
if((!b[j][t])&&(!b[i][k])&&SZ(a[j][k])>=1){
vec.push_back({dinic::tot+1,i,j,k});
dinic::add_e(idL[i][k],idR[j][k],1);
}
}
cnt-=dinic::solve();
}
if(cnt>0){fl=0;break;}
for(LL i=0;i<SZ(vec);i++)
if(!dinic::e[vec[i][0]].w)
make(vec[i][1],t,vec[i][2],vec[i][3]);
dinic::clear();
}
if(!fl)continue;
writeln(SZ(ans));
for(LL t=0;t<SZ(ans);t++){
for(LL i=0;i<SZ(ans[t]);i++)writecs(ans[t][i]);
puts("");
}
for(LL t=0;t<SZ(ans);t++){
LL x0=ans[t][0],y0=ans[t][1],x1=ans[t][2],y1=ans[t][3];
swap(__c[x0][y0],__c[x1][y1]);
}
for(LL t=1;t<=n;t++){
vector<LL>vec(n);
for(LL i=1;i<=n;i++)vec[i-1]=__c[t][i];
lsh(vec);assert(SZ(vec)==n);
}
break;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 4ms
memory: 7840kb
input:
7 132 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...
output:
8646 59 132 75 132 59 131 100 132 59 130 106 132 59 129 40 132 59 128 29 132 59 127 103 132 59 126 125 132 59 125 80 132 59 124 49 132 59 123 17 132 59 122 120 132 59 121 33 132 59 120 13 132 59 119 42 132 59 118 68 132 59 117 61 132 59 116 76 132 59 115 73 132 59 114 21 132 59 11...
result:
ok your solution is correct.
Test #2:
score: 0
Accepted
time: 2ms
memory: 5332kb
input:
8 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 14 14 14 14 14 14 14 14 14 14 14 14 14 14 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 2 2 2 2 2 2 2 2 2 2 2 2 2 2 9...
output:
91 7 14 9 14 7 13 13 14 7 12 6 14 7 11 5 14 7 10 11 14 7 9 2 14 7 8 3 14 7 7 10 14 7 6 8 14 7 5 14 14 7 4 12 14 7 3 1 14 7 2 4 14 9 13 13 13 9 12 6 13 9 11 5 13 9 10 11 13 9 9 2 13 9 8 3 13 9 7 10 13 9 6 8 13 9 5 14 13 9 4 12 13 9 3 1 13 9 2 4 13 13 12 6 12 13 11 5 12 13 1...
result:
ok your solution is correct.
Test #3:
score: 0
Accepted
time: 3ms
memory: 7432kb
input:
4 82 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...
output:
3321 56 82 35 82 56 81 39 82 56 80 77 82 56 79 33 82 56 78 12 82 56 77 67 82 56 76 26 82 56 75 70 82 56 74 2 82 56 73 50 82 56 72 4 82 56 71 34 82 56 70 66 82 56 69 41 82 56 68 21 82 56 67 51 82 56 66 72 82 56 65 61 82 56 64 1 82 56 63 9 82 56 62 65 82 56 61 46 82 56 60 27 82 ...
result:
ok your solution is correct.
Test #4:
score: 0
Accepted
time: 3ms
memory: 7712kb
input:
8 3 1 1 1 3 3 3 2 2 2 3 1 1 1 3 3 3 2 2 2 1 1 11 5 5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 9 9 9 9 4 4 4 4 4 4 4 4 4 4 4 11 11 11 11 11 11 11 11 11 11 11 2 2 2 2 2 2 2 2 2 2 2 6 6 6 6 6 6 6 6 6 6 6 8 8 8 8 8 8 8 8 8 8 8 10 10 10 10 10 10 10 10 10 10 10 7 7 7 7 7...
output:
3 1 3 3 3 1 2 2 3 3 2 2 2 3 1 3 3 3 1 2 2 3 3 2 2 2 0 55 3 11 7 11 3 10 2 11 3 9 5 11 3 8 1 11 3 7 8 11 3 6 11 11 3 5 9 11 3 4 4 11 3 3 10 11 3 2 6 11 7 10 2 10 7 9 5 10 7 8 1 10 7 7 8 10 7 6 11 10 7 5 9 10 7 4 4 10 7 3 10 10 7 2 6 10 2 9 5 9 2 8 1 9 2 7 8 9 2 6 11 9 2 5...
result:
ok your solution is correct.
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #5:
score: 20
Accepted
time: 5ms
memory: 7836kb
input:
5 17 9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 9 9 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 2 2 2 2 2 2 2 2 2 2 2 2 11 2 2 2 2 4 4 4 4 4 4 10 4 4 4 4 4 4 4 4 4 4 10 10 10 10 10 10 8 10 10 10 10 10 10 10 10 10 10 12 12 12 12 12 12 12 12 12 12 12 12 14 12 12 12 12 14 14 14 14 14 14 14 14 14 14 14 12 14 14 14 14 14 16 16...
output:
135 12 17 1 14 12 16 15 8 12 15 14 17 12 14 8 3 12 13 2 17 12 12 17 9 12 11 5 7 12 10 11 2 12 9 4 7 12 8 3 13 12 7 7 12 12 6 16 14 12 5 6 13 12 4 9 2 12 3 10 9 3 17 10 17 3 16 4 17 3 15 2 16 3 14 13 17 3 12 14 16 3 11 9 17 3 10 1 17 3 9 5 17 3 8 16 17 3 7 6 17 3 6 17 17 3 5...
result:
ok your solution is correct.
Test #6:
score: 0
Accepted
time: 4ms
memory: 8160kb
input:
9 1 1 28 2 2 2 2 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 24 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 8 13 13 13 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 16 8 8 8 8 8 8 8 8 8 8 8 8 17 24 24 24 24 24 24 24 24 24 24 24 24...
output:
0 377 11 28 9 3 11 27 28 10 11 26 17 14 11 25 1 5 11 24 20 10 11 23 7 1 11 22 3 25 11 21 13 4 11 20 27 28 11 19 8 11 11 18 6 9 11 17 22 2 11 16 26 24 11 15 4 16 11 14 5 1 11 13 10 19 11 12 18 26 11 11 14 17 11 10 21 28 11 9 25 15 11 8 15 21 11 7 2 2 11 6 12 21 11 5 23 4 11 4 ...
result:
ok your solution is correct.
Test #7:
score: 0
Accepted
time: 0ms
memory: 5688kb
input:
9 22 19 19 19 19 19 19 19 19 19 10 19 19 19 19 19 19 19 19 19 19 19 19 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 8 21 21 21 21 21 21 21 21 5 21 21 21 21 21 21 21 21 21 21 21 21 21 12 12 12 12 12 12 12 22 12 12 12 12 12 12 12 12 12 12 12 12 12 12 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...
output:
230 20 22 18 21 20 21 11 11 20 20 17 3 20 19 3 9 20 18 13 2 20 17 7 2 20 16 2 22 20 15 6 3 20 14 1 10 20 12 15 18 20 11 8 21 20 10 10 13 20 9 9 22 20 8 19 22 20 7 14 9 20 6 22 19 20 5 16 16 20 4 21 15 20 3 12 9 20 2 4 8 12 22 5 22 12 21 16 22 12 20 17 22 12 19 11 22 12 18 14 ...
result:
ok your solution is correct.
Test #8:
score: 0
Accepted
time: 2ms
memory: 7060kb
input:
8 29 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 3 3 3 3 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 3 11 11 11 11 11 11 11 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 1 1 1 1 1 1 1 20 20 20 20 20 20 20 20 20 20 20 25 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 26 26...
output:
405 3 29 19 24 3 28 2 21 3 27 10 13 3 26 15 29 3 25 1 25 3 24 12 11 3 23 8 9 3 21 17 25 3 20 18 3 3 19 29 16 3 18 26 23 3 17 28 14 3 16 25 7 3 15 13 18 3 14 9 29 3 13 5 20 3 12 20 25 3 11 27 28 3 10 14 14 3 9 7 11 3 8 22 23 3 7 16 13 3 6 4 12 3 5 23 8 3 4 6 7 3 3 21 20 3 2 ...
result:
ok your solution is correct.
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #9:
score: 60
Accepted
time: 6ms
memory: 7952kb
input:
19 1 1 2 1 2 1 2 3 1 3 2 2 3 1 2 1 3 4 1 4 3 4 3 2 2 1 3 1 2 3 4 4 1 2 5 4 2 1 5 4 4 5 4 4 1 5 3 2 3 2 3 1 3 2 1 3 1 2 5 5 6 6 2 2 1 6 6 2 5 5 3 4 6 1 2 4 2 6 1 4 4 1 4 5 1 1 2 6 5 3 5 5 3 3 3 3 4 7 5 2 3 6 4 2 7 2 1 6 1 1 5 2 1 6 7 7 5 1 2 6 6 3 4 4 7 1 3 6 5 7 3 2 7 3 2 5 1 4 5 4 5 3 3 7 4 4 6 8 1...
output:
0 0 0 2 2 2 1 4 3 1 4 2 5 4 2 3 4 3 3 2 4 4 3 2 3 4 1 1 4 1 1 5 5 9 3 1 6 5 4 3 2 4 3 2 4 4 1 2 6 6 6 3 2 3 6 2 1 6 3 3 6 1 4 1 5 3 5 4 1 5 13 2 4 5 6 3 1 7 3 2 2 1 3 2 7 7 6 1 2 4 5 2 1 5 2 5 1 1 1 6 5 5 3 1 5 3 2 6 6 4 2 6 3 1 7 2 3 3 4 1 4 5 7 18 1 4 5 6 1 3 4 6 1 1...
result:
ok your solution is correct.
Test #10:
score: 0
Accepted
time: 6ms
memory: 7200kb
input:
19 1 1 2 2 1 1 2 3 2 1 2 3 3 3 1 2 1 4 1 2 3 4 1 2 3 4 2 3 1 4 4 1 2 3 5 1 2 3 3 3 4 4 1 2 3 5 2 4 5 1 1 4 5 5 2 5 2 1 4 3 6 1 3 6 6 4 4 5 2 4 6 5 2 3 6 5 6 5 2 1 5 1 4 2 4 3 1 6 3 3 2 3 2 1 4 5 1 7 4 4 1 6 6 7 6 3 7 3 4 5 2 7 6 2 7 6 2 1 3 2 2 5 3 1 2 1 7 3 7 4 2 1 4 5 3 6 3 1 5 5 7 5 6 5 1 4 4 8 6...
output:
0 0 2 3 3 2 3 1 3 2 2 0 3 1 4 3 3 1 3 4 4 2 1 3 4 8 6 3 2 6 4 1 3 1 6 2 1 6 5 4 2 3 5 1 3 5 6 4 2 4 4 4 3 4 2 1 1 4 12 4 5 2 3 4 2 1 2 3 2 7 7 4 1 6 3 6 4 1 1 4 4 6 7 6 2 7 4 5 4 1 7 6 6 1 5 4 3 3 3 6 1 5 3 3 1 2 7 17 6 1 1 7 5 1 2 6 4 3 3 8 2 1 1 4 7 1 8 7 6 2 3 5 4 5...
result:
ok your solution is correct.
Test #11:
score: 0
Accepted
time: 6ms
memory: 6880kb
input:
19 1 1 2 2 1 1 2 3 3 3 2 1 1 2 2 1 3 4 4 1 1 3 4 4 1 2 1 2 2 3 3 2 4 3 5 3 1 5 5 5 4 2 2 5 2 1 5 4 3 4 1 1 3 4 4 3 1 2 3 2 6 1 5 5 3 2 1 5 5 2 3 4 3 2 6 2 3 1 4 6 6 6 4 6 1 4 5 1 2 3 4 6 3 2 4 5 1 7 5 1 1 3 3 7 7 5 4 1 4 4 3 6 4 4 2 7 1 3 2 1 3 5 6 5 3 5 6 4 2 7 6 2 3 7 2 6 2 1 6 2 5 7 4 5 7 1 6 8 1...
output:
0 0 1 2 1 1 2 3 1 2 4 4 3 2 1 1 1 4 2 2 8 4 1 2 5 5 3 1 1 2 2 3 5 5 4 3 3 5 1 2 4 3 4 1 5 4 4 1 4 2 1 3 2 6 1 1 2 6 3 1 4 4 1 4 4 5 3 6 1 3 5 1 4 3 2 1 4 2 13 1 2 5 7 3 3 1 5 6 4 4 6 6 2 7 3 5 3 2 5 1 4 5 2 3 6 7 4 3 1 7 7 2 2 4 4 4 5 6 6 4 3 5 4 5 1 1 7 2 7 7 5 15 5 4...
result:
ok your solution is correct.
Test #12:
score: 0
Accepted
time: 6ms
memory: 6348kb
input:
19 1 1 2 2 2 1 1 3 1 1 2 2 1 3 3 2 3 4 2 1 2 3 2 1 3 3 4 4 4 4 2 3 1 1 5 3 5 5 5 4 1 4 4 5 2 1 1 3 1 5 2 4 3 2 3 2 3 4 1 2 6 5 5 4 3 1 1 3 4 1 6 6 6 6 2 2 1 4 4 2 2 6 5 3 3 1 5 6 2 3 3 5 4 1 2 4 5 7 6 4 4 7 7 5 6 1 1 2 1 4 2 7 5 2 5 3 1 1 2 3 4 2 7 6 7 6 5 6 1 2 7 6 4 5 6 5 3 3 7 3 5 4 2 1 3 4 3 8 2...
output:
0 1 2 2 1 2 1 1 1 3 3 3 4 3 3 4 1 1 3 3 2 3 3 2 7 3 2 4 4 3 1 1 1 5 1 1 5 3 3 1 4 4 3 2 4 5 3 3 5 2 2 1 3 9 1 5 4 6 3 2 1 3 4 1 2 2 1 4 3 6 5 5 6 6 6 2 2 6 3 5 5 3 1 1 3 1 5 2 2 5 15 2 2 6 7 3 5 4 1 2 1 1 6 4 3 6 5 2 3 4 2 3 2 1 3 7 5 1 2 3 4 5 1 7 6 6 3 2 5 4 7 7 2 1 ...
result:
ok your solution is correct.
Test #13:
score: -60
Time Limit Exceeded
input:
5 156 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 95 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 34 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 130 1 42 1 1 1 1 1 1 1 1 1 1 1 1 90 1 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...