結果

問題 No.385 カップ麺生活
ユーザー jjjj
提出日時 2016-08-04 23:36:47
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 33,892 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:35:36
合計ジャッジ時間 1,315 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

subroutine get_prime(isPrime, N)
  implicit none
  integer::i,j,N
  integer,parameter::prime=1,nonprime=0
  integer,allocatable::isPrime(:)

  isPrime=prime
  isPrime(1)=nonprime

  do i=2, FLOOR(SQRT(REAL(N)))
     if(isPrime(i).eq.prime) then
        do j=i+i, N, i
           isPrime(j) = nonprime
        end do
     end if
  end do

end subroutine get_prime

program main
  implicit none
  interface
     subroutine get_prime(isPrime, N)
       integer::N
       integer,allocatable::isPrime(:)
     end subroutine get_prime
  end interface

  integer::M,N,i,j,sum
  integer,allocatable::C(:),isPrime(:)
  integer::memo(-1000:10000)
  data memo/11001*0/

  read *,M, N
  allocate(C(N))
  allocate(isPrime(2:M))
  read *, C

  memo(M) = 1

  do i=M, 1, -1
     if(memo(i).eq.0) cycle
     do j=1, N
        memo(i-C(j)) = MAX(memo(i-C(j)),memo(i) + 1)
     end do
  end do

  call get_prime(isPrime, M)

  sum = M/MINVAL(C)
  do i=2, M
     if(isPrime(i).eq.0) cycle
     if(memo(i).eq.0) cycle
     sum = sum + (memo(i)-1)
  end do
  print '(i0)', sum
end program main
0