CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:Septicuss
Submission time:2022-10-31 02:28:29 +0200
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.07 s1, 2details
#2ACCEPTED0.07 s1, 2details
#3ACCEPTED0.07 s1, 2details
#40.07 s1, 2details
#5ACCEPTED0.07 s1, 2details
#60.07 s2details
#70.07 s2details
#80.07 s2details
#90.07 s2details

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class B430 {

	public static void main(String[] args) {
		FastReader reader = new FastReader();
		PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

		int n = reader.nextInt();
		int m = reader.nextInt();

		int cows = 0;
		boolean inside = false;

		for (int i = 0; i < n; i++) {
			String row = reader.nextLine();

			for (int j = 0; j < m; j++) {
				char prev = j == 0 ? 'x' : row.charAt(j - 1);
				char c = row.charAt(j);
				char next = j + 1 == m ? 'x' : row.charAt(j + 1);

				if (c == '@' && !inside) {
					cows++;
					continue;
				}
				if (c == '*') {
					if (prev == '.' && (next == '.' || next == '@'))
						inside = true;
					else
						inside = false;
				}
			}
		}

		reader.close();

		writer.println(cows);
		writer.flush();
		writer.close();
	}

	static class FastReader {

		private BufferedReader br;
		private StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			st = null;
			br = null;
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String str = "";

			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

	}

}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
3 3
***
*.*
***

correct output
0

user output
0

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
3 3
***
*@*
***

correct output
1

user output
1

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
5 10
...@......
..******..
@.*@@@@*.@
..******..
...

correct output
4

user output
4

Test 4

Group: 1, 2

Verdict:

input
10 10
@@...@.@@@
..@@.@@..@
@.*******@
..*@....*.
...

correct output
11

user output
22

Test 5

Group: 1, 2

Verdict: ACCEPTED

input
10 10
**********
*@@@@@@@@*
*@@@@@@@@*
*@@@@@@@@*
...

correct output
64

user output
64

Test 6

Group: 2

Verdict:

input
100 100
.........................@.......

correct output
60

user output
17

Test 7

Group: 2

Verdict:

input
100 100
..@@..........@......@....@@.....

correct output
1507

user output
640

Test 8

Group: 2

Verdict:

input
100 100
.@..@@..@@.@..@..@..@@..@..@.....

correct output
3348

user output
2696

Test 9

Group: 2

Verdict:

input
100 100
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...

correct output
7225

user output
9656