QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606456#5275. Joking?ship2077AC ✓177ms4076kbC++231.9kb2024-10-03 08:50:392024-10-03 08:50:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 08:50:39]
  • 评测
  • 测评结果:AC
  • 用时:177ms
  • 内存:4076kb
  • [2024-10-03 08:50:39]
  • 提交

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],tmp[255];
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;
}
int main(){
    scanf("%d",&n); 
    k=120;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;}
    double res=query();int Case=0;
    while (res>=0.002){
        if (++Case==10000) cerr<<res<<"?"<<endl,Case=0;
        int xl=rnd(1,n),yl=rnd(1,k),xr=rnd(1,n),yr=rnd(1,k);
        if (xl==xr) continue;
        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][yl]);swap(ans[xl][yr],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 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4076kb

input:

2

output:

120
1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 17...

result:

ok n = 2, max_relative_diff = 0.000%

Test #2:

score: 0
Accepted
time: 1ms
memory: 4064kb

input:

3

output:

120
1 6 7 12 13 18 19 24 25 30 31 36 37 42 43 48 49 54 55 60 61 66 67 72 73 78 79 84 85 90 91 96 97 102 103 108 109 114 115 120 121 126 127 132 133 138 139 144 145 150 151 156 157 162 163 168 169 174 175 180 181 186 187 192 193 198 199 204 205 210 211 216 217 222 223 228 229 234 235 240 241 246 247 ...

result:

ok n = 3, max_relative_diff = 0.042%

Test #3:

score: 0
Accepted
time: 1ms
memory: 4008kb

input:

4

output:

120
1 8 9 16 17 24 25 32 33 40 41 48 49 56 57 64 65 72 73 80 81 88 89 96 97 104 105 112 113 120 121 128 129 136 137 144 145 152 153 160 161 168 169 176 177 184 185 192 193 200 201 208 209 216 217 224 225 232 233 240 241 248 249 256 257 264 265 272 273 280 281 288 289 296 297 304 305 312 313 320 321 ...

result:

ok n = 4, max_relative_diff = 0.083%

Test #4:

score: 0
Accepted
time: 177ms
memory: 4012kb

input:

5

output:

120
1 10 11 20 21 30 31 40 41 50 51 60 63 70 71 80 81 90 91 100 101 110 111 120 121 130 131 140 141 150 151 160 161 170 171 178 181 190 191 200 201 210 211 220 221 230 231 240 241 250 251 260 261 270 272 280 281 290 291 300 304 307 311 320 321 330 331 340 341 350 351 360 361 370 371 380 384 387 391 ...

result:

ok n = 5, max_relative_diff = 0.197%