結果

問題 No.719 Coprime
ユーザー butsurizukibutsurizuki
提出日時 2018-06-06 22:50:14
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 109 ms / 3,000 ms
コード長 1,826 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 31,160 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 22:54:14
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 5 ms
4,380 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 9 ms
4,380 KB
testcase_44 AC 10 ms
4,376 KB
testcase_45 AC 11 ms
4,380 KB
testcase_46 AC 15 ms
4,376 KB
testcase_47 AC 15 ms
4,376 KB
testcase_48 AC 15 ms
4,380 KB
testcase_49 AC 17 ms
4,376 KB
testcase_50 AC 17 ms
4,376 KB
testcase_51 AC 17 ms
4,376 KB
testcase_52 AC 29 ms
4,376 KB
testcase_53 AC 44 ms
4,376 KB
testcase_54 AC 70 ms
4,380 KB
testcase_55 AC 72 ms
4,376 KB
testcase_56 AC 87 ms
4,380 KB
testcase_57 AC 86 ms
4,380 KB
testcase_58 AC 106 ms
4,376 KB
testcase_59 AC 109 ms
4,376 KB
testcase_60 AC 108 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

int p[16]={2,3,5,7,11,13,17,19,23,29,31};
int max(int a,int b){if(a>b){return a;}return b;}

typedef struct{
    long long st;
    long long fi;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

rs g[2048];
mkj x[2048];

void befrun(int n){
  int i,j,w,r;
  for(i=2;i<=n;i++){w=i;r=0;
    for(j=0;j<11;j++){
      if(w%p[j]==0){
        r=max(r,p[j]);
        while(w%p[j]==0){w/=p[j];}
      }
    }
    r=max(r,w);
    g[i-2].st=r;
    g[i-2].fi=i;
  }
  qsort(g,n-1,sizeof(rs),sortfnc);
  makemkj(g,x,n-1);
}

int main(){
  int n;
  int m,i,j,k,dp[2048]={0},ndp[2048]={0},f[16]={0},q,r=0,rx[16]={0},ufl;
  int fl;
  int ni,xi;
  scanf("%d",&n);
  befrun(n);
  for(i=2;i<=n;i++){ufl=0;
    for(xi=x[i].st;xi<x[i].st+x[i].kz;xi++){
    ni=g[xi].fi;ufl=1;
    //printf("<%d>\n",ni);
    for(j=0;j<11;j++){if(ni%p[j]==0){f[j]=1;}else{f[j]=0;}}
    for(j=0;j<2048;j++){fl=1;m=j;q=0;
      for(k=0;k<11;k++){if(m%2==0 && f[k]==1){fl=0;break;}m/=2;}
      ndp[j]=max(dp[j],ndp[j]);
      if(fl){m=j;
        for(k=0;k<11;k++){if(m%2){rx[k]=1;}else{rx[k]=0;}m/=2;}
        m=0;
        for(k=10;k>=0;k--){m*=2;if(rx[k]==1 && f[k]==0){m++;}}
        ndp[m]=max(ndp[m],dp[j]+ni);
        //printf("%d\n",ndp[m]);
      }
    }
    }
    if(ufl){for(j=0;j<2048;j++){dp[j]=ndp[j];ndp[j]=0;}}
  }
  for(j=0;j<2048;j++){r=max(r,dp[j]);}
  printf("%d\n",r);
  return 0;
}
0