Submission #1306104


Source Code Expand

import java.util.*;
 
public class Main {
    public static void main(String args[]) {
        FastScanner cin = new FastScanner();
        String s = cin.next();
        StringBuilder p = new StringBuilder(s);
        int numG = 0, numP = 0, score = 0;
 
        for (int i = 0, j = 0; i < s.length(); ++i) {
            if (p.charAt(i) == 'p') {
                ++numP;
 
                if (numP > numG) {
                    while (s.charAt(j) == p.charAt(j))
                        ++j;
 
                    p.setCharAt(j, 'g');
                    --numP;
                    --score;
                    ++numG;
                    ++j;
                }
            } else {
                if (numP < numG) {
                    ++score;
                    ++numP;
                    p.setCharAt(i, 'p');
                } else {
                    ++numG;
                }
            }
        }
 
        System.out.println(score);
    }
 
    static class FastScanner {
        StringTokenizer tokenizer;
        Scanner scanner;
 
        FastScanner() {
            tokenizer = null;
            scanner = new Scanner(System.in);
        }
 
        int nextInt() {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(scanner.nextLine());
 
            return Integer.parseInt(tokenizer.nextToken());
        }
 
        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens())
                tokenizer = new StringTokenizer(scanner.nextLine());
 
            return tokenizer.nextToken();
        }
    }
}

Submission Info

Submission Time
Task D - AtCoDeer and Rock-Paper
User pnnb
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 1680 Byte
Status AC
Exec Time 171 ms
Memory 28228 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 25
Set Name Test Cases
Sample 0_000.txt, 0_001.txt
All 0_000.txt, 0_001.txt, 1_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt
Case Name Status Exec Time Memory
0_000.txt AC 89 ms 21076 KB
0_001.txt AC 91 ms 19284 KB
1_002.txt AC 163 ms 23604 KB
1_003.txt AC 139 ms 19280 KB
1_004.txt AC 155 ms 26180 KB
1_005.txt AC 133 ms 18508 KB
1_006.txt AC 162 ms 23868 KB
1_007.txt AC 113 ms 22100 KB
1_008.txt AC 160 ms 26196 KB
1_009.txt AC 171 ms 25920 KB
1_010.txt AC 164 ms 28228 KB
1_011.txt AC 137 ms 24000 KB
1_012.txt AC 167 ms 26308 KB
1_013.txt AC 118 ms 22464 KB
1_014.txt AC 161 ms 26060 KB
1_015.txt AC 163 ms 24000 KB
1_016.txt AC 157 ms 26188 KB
1_017.txt AC 160 ms 23628 KB
1_018.txt AC 161 ms 24260 KB
1_019.txt AC 116 ms 21572 KB
1_020.txt AC 159 ms 24240 KB
1_021.txt AC 156 ms 24264 KB
1_022.txt AC 168 ms 26060 KB
1_023.txt AC 167 ms 26872 KB
1_024.txt AC 161 ms 26176 KB