結果

問題 No.154 市バス
ユーザー jjjj
提出日時 2016-09-11 15:05:40
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,228 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 26,716 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 12:00:40
合計ジャッジ時間 1,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
4,380 KB
testcase_01 AC 20 ms
4,380 KB
testcase_02 AC 21 ms
4,380 KB
testcase_03 AC 15 ms
4,380 KB
testcase_04 AC 20 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer::T,i
  character*1000::S
  read *,T
  do i=1,T
     read *,S
     call analyze(S)
  end do
contains
  subroutine analyze(S)
    integer::j,len,w,g,r,keitou
    character*1000::S

    len = LEN_TRIM(S)
    w = 0
    g = 0
    r = 0
    do j=1,len
       if(S(j:j).eq.'R') then
          r = r + 1
          if(r.gt.g.or.r.gt.w) then
             print '(a)',"impossible"
             return
          end if
       else if(S(j:j).eq.'G') then
          g = g + 1
          if(g.gt.w) then
             print '(a)',"impossible"
             return
          end if
       else
          w = w + 1
       end if
    end do
    if(g.ne.r) then
       print '(a)',"impossible"
       return
    end if
    w = 0
    g = 0
    r = 0
    do j=len,1,-1
       if(S(j:j).eq.'R') then
          r = r + 1
       else if(S(j:j).eq.'G') then
          g = g + 1
          if(r.eq.0) then
             print '(a)',"impossible"
             return
          end if
       else
          w = w + 1
          if(r.eq.0.or.g.eq.0) then
             print '(a)',"impossible"
             return
          end if
       end if
    end do
    print '(a)',"possible"
  end subroutine analyze

end program main
0