結果

問題 No.2738 CPC To F
ユーザー koufu193koufu193
提出日時 2024-04-21 14:30:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,589 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 77,492 KB
実行使用メモリ 51,768 KB
最終ジャッジ日時 2024-04-21 14:30:23
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
36,808 KB
testcase_01 AC 44 ms
36,828 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
public class Main {
    static int len;
    static int read;

    static final char[] chars="CPCT".toCharArray();
    static final char[] CPC="CPC".toCharArray();
    static int last=0;
    public static void main(String[] args) {
        FastScanner scanner=new FastScanner();

        len=scanner.readInt();
        int o=0;
        while (read<len){
            skipTillCPCT(last,scanner);
            if(ableToBeF(scanner)) o++;
        }
        System.out.println(o);
    }
    private static boolean ableToBeF(FastScanner scanner){
        int c=read(scanner);
        if(c=='F') return true;
        if(c!='C') return false;
        if((last=read(scanner))!='P') return false;
        if((last=read(scanner))!='C') return false;
        last=0;
        return true;
    }
    private static void skipTillCPCT(int last,FastScanner scanner){
        int c;
        int index=0;
        if(last=='C') index++;
        last=0;
        while ((c=read(scanner))!=-1&&index!=3){
            if(c!=chars[index]){
                index=0;
                continue;
            }
            index++;
        }
    }
    private static int read(FastScanner scanner){
        if(len<=read) return -1;
        read++;
        return scanner.readByte();
    }
    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return buflen > 0;
            }
        }
        private int readByte() {
            if (hasNextByte()){
            return buffer[ptr++];
        } else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}

        public int readInt(){
            int b = readByte();
            int n=0;
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}
0