結果

問題 No.78 クジ付きアイスバー
ユーザー jj
提出日時 2016-10-04 23:13:13
言語 Fortran
(gFortran 14.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 833 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 32,128 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-21 16:58:41
合計ジャッジ時間 1,199 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::N,K,atari,buy,total
  character*50::S
  integer::i
  data atari/0/,buy/0/
  read *,N,K
  read *,S(1:N)

  do i=1,MIN(N,K)
     if(atari.eq.0) then
        buy   = buy   + 1
     else
        atari = atari - 1
     end if
     atari = atari + ICHAR(S(i:i))-ICHAR('0')
  end do

  if(N.gt.K .or. atari.ge.buy) then
     print '(i0)', buy
     return
  end if

!  print *,"first:", buy, atari

  if((K-N-1)/N.ge.1) then
     total = buy + (buy - atari) * ((K-N-1)/N)
  else
     total = buy
  end if

!  print *,"second:", total, (K-N-1)/N

  buy = 0
  do i=1,(K-((K-N-1)/N+1)*N)
     if(atari.eq.0) then
        buy   = buy   + 1
     else
        atari = atari - 1
     end if
     atari = atari + ICHAR(S(i:i))-ICHAR('0')
  end do
  total = total + buy
  print '(i0)', total
end program main
0