QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606446 | #5275. Joking? | ship2077 | WA | 1ms | 3992kb | C++23 | 2.4kb | 2024-10-03 08:30:43 | 2024-10-03 08:30:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
mt19937 mt(time(NULL));
int rnd(int l,int r){return mt()%(r-l+1)+l;}
int n,k,ans[6][125],tmpxl[125],tmpxr[125];
long long dp[6][125];bool vis[6];
double query(){
long long Min=1ll<<60,Max=0;
auto dfs=[&](auto self,auto x,auto lst){
if (x>n){
Min=min(Min,dp[n][k]);
Max=max(Max,dp[n][k]);
return;
}
for (int p=1;p<=n;p++)
if (!vis[p]){
vis[p]=1;
for (int i=1,j=1;i<=k;i++){
while (j<=k&&ans[lst][j]<=ans[p][i])
j++;
dp[x][i]=dp[x-1][j-1];
}
for (int i=1;i<=k;i++) dp[x][i]+=dp[x][i-1];
self(self,x+1,p);
vis[p]=0;
}
};
for (int i=0;i<=k;i++) dp[0][i]=1;
dfs(dfs,1,0); return 1.*(Max-Min)/Max;
}
void solve(){
k=16;int idx=0;
for (int j=1;j<=k;j++) if (j&1)
{ for (int i=1;i<=n;i++) ans[i][j]=++idx;}
else{ for (int i=n;i;i--) ans[i][j]=++idx;}
swap(ans[1][1],ans[2][1]);
double res=query();
while (res>=0.0001&&0){
cerr<<res<<"?"<<endl;
int xl=rnd(1,n),yl=rnd(1,k),xr=rnd(1,n),yr=rnd(1,k);
for (int i=1;i<=k;i++) tmpxl[i]=ans[xl][i];
for (int i=1;i<=k;i++) tmpxr[i]=ans[xr][i];
swap(ans[xl][yl],ans[xr][yr]);
sort(ans[xl]+1,ans[xl]+k+1);
sort(ans[xr]+1,ans[xr]+k+1);
double tmp=query();
if (res>tmp) {res=tmp;continue;}
for (int i=1;i<=k;i++) ans[xl][i]=tmpxl[i];
for (int i=1;i<=k;i++) ans[xr][i]=tmpxr[i];
}
cerr<<res<<"!"<<endl;
printf("%d\n",k);
for (int i=1;i<=n;i++)
for (int j=1;j<=k;j++)
printf("%d%c",ans[i][j]," \n"[j==k]);
return;
for (int i=1;i<=n;i++){
for (int j=1;j<k;j++)
printf("%d ",ans[i][j]);
printf("%d\\n",ans[i][k]);
}
}
int main(){
scanf("%d",&n);
solve();return 0;
if (n==2) return puts("2\n1 4\n2 3"),0;
if (n==3) return puts("6\n1 5 10 11 13 17\n3 4 7 12 15 16\n2 6 8 9 14 18"),0;
if (n==4) return puts("12\n1 8 11 14 19 22 27 30 35 38 41 48\n2 7 10 15 18 23 26 31 34 39 42 47\n3 6 12 13 17 24 25 32 36 37 43 46\n4 5 9 16 20 21 28 29 33 40 44 45"),0;
if (n==5) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3992kb
input:
2
output:
16 2 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 1 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31
result:
wrong answer n = 2, max_relative_diff = 1.550%