Submission #929493


Source Code Expand

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final char[] chs = sc.next().toCharArray();
		
		long answer = 0;
		int rest_p = 0, rest_g = 0;
		for(final char ch : chs){
			if(ch == 'g'){
				rest_g++;
			}else if(ch == 'p'){
				rest_p++;
			}
		}
		
		//System.out.println(rest_g + " " + rest_p);
		final int plus  = rest_g / 2;
		final int minus = rest_p / 2;
		final int g_mod = rest_g % 2;
		final int p_mod = rest_p % 2;
		
		System.out.println((plus - minus) + Math.min(0, g_mod - p_mod));
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}	
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Submission Info

Submission Time
Task D - AtCoDeer and Rock-Paper
User mondatto
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2081 Byte
Status AC
Exec Time 121 ms
Memory 11092 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 96 ms 8020 KB
0_001.txt AC 96 ms 8144 KB
1_002.txt AC 115 ms 11092 KB
1_003.txt AC 103 ms 8656 KB
1_004.txt AC 114 ms 11088 KB
1_005.txt AC 101 ms 8532 KB
1_006.txt AC 113 ms 10964 KB
1_007.txt AC 95 ms 8144 KB
1_008.txt AC 111 ms 11092 KB
1_009.txt AC 114 ms 11088 KB
1_010.txt AC 116 ms 11088 KB
1_011.txt AC 101 ms 8788 KB
1_012.txt AC 111 ms 10960 KB
1_013.txt AC 97 ms 8272 KB
1_014.txt AC 113 ms 10964 KB
1_015.txt AC 121 ms 10960 KB
1_016.txt AC 113 ms 10964 KB
1_017.txt AC 111 ms 10964 KB
1_018.txt AC 113 ms 10964 KB
1_019.txt AC 93 ms 8144 KB
1_020.txt AC 112 ms 10964 KB
1_021.txt AC 121 ms 10960 KB
1_022.txt AC 113 ms 11088 KB
1_023.txt AC 111 ms 10964 KB
1_024.txt AC 112 ms 10964 KB