結果

問題 No.2738 CPC To F
ユーザー koufu193koufu193
提出日時 2024-04-21 14:23:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,635 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 76,880 KB
実行使用メモリ 38,068 KB
最終ジャッジ日時 2024-04-21 14:23:25
合計ジャッジ時間 4,458 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
36,788 KB
testcase_01 AC 46 ms
36,464 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 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();
        int len=scanner.readInt();
        scanner.read=0;
        int o=0;
        scanner.max=len;
        while (scanner.hasNextByte()){
            skipTillCPCT(o,scanner);
            if(ableToBeF(scanner)) o++;
        }
        System.out.println(o);
    }
    private static boolean ableToBeF(FastScanner scanner){
        last=0;
        int c=scanner.readByte();
        if(c=='F') return true;
        for(int i=0;i<3;i++){
            if(c!=CPC[i]){
                last=c;
                return false;
            }
            if(i!=2) c=scanner.readByte();
        }
        last=0;
        return true;
    }
    private static void skipTillCPCT(int last,FastScanner scanner){
        int c;
        int index=0;
        if(last=='C') index++;
        while ((c=scanner.readByte())!=-1&&index!=3){
            if(c!=chars[index]){
                index=0;
                continue;
            }
            index++;
        }
    }

    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;
        public int read=0;
        public int max=20;
        private boolean hasNextByte() {
            if(max<=read) return false;
            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()){
            read++;
            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