exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
βŒ€
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
βŒ€
difficulty
int64
-1
3.5k
βŒ€
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
d92d76e57a46a969183d89fd634b543a
train_001.jsonl
1520583000
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.
512 megabytes
// package CF; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; import java.util.TreeSet; public class B { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); char [] c = sc.next().toCharArray(); TreeSet<Integer> z = new TreeSet<>(); TreeSet<Integer> o = new TreeSet<>(); for (int i = 0; i < c.length; i++) { if(c[i] == '0') z.add(i); else o.add(i); } StringBuilder sb = new StringBuilder(); int num = 0; while(!z.isEmpty()){ ArrayList<Integer> tmp = new ArrayList<>(); int x = z.first(); z.remove(x); tmp.add(x); while(true){ Integer i = o.higher(x); if(i == null) break; Integer j = z.higher(i); if(j == null) break; o.remove(i); z.remove(j); tmp.add(i); tmp.add(j); x = j; } num++; sb.append(tmp.size()); for(int ii:tmp){ sb.append(" ").append(ii+1); } sb.append("\n"); } out.println(o.isEmpty()?num+"\n"+sb:-1); out.flush(); out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader fileReader) { br = new BufferedReader(fileReader); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["0010100", "111"]
1 second
["3\n3 1 3 4\n3 2 5 6\n1 7", "-1"]
null
Java 8
standard input
[ "greedy" ]
37b34461876af7f2e845417268b55ffa
In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.
1,600
If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≀ li ≀ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.
standard output
PASSED
aa092d669b00437ed24685c8837b5b66
train_001.jsonl
1588775700
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)You have completed many programming projects. In fact, there are exactly $$$n$$$ types of programming projects, and you have completed $$$a_i$$$ projects of type $$$i$$$. Your rΓ©sumΓ© has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:$$$$$$ f(b_1,\ldots,b_n)=\sum\limits_{i=1}^n b_i(a_i-b_i^2). $$$$$$Here, $$$b_i$$$ denotes the number of projects of type $$$i$$$ you include in your rΓ©sumΓ©. Of course, you cannot include more projects than you have completed, so you require $$$0\le b_i \le a_i$$$ for all $$$i$$$.Your rΓ©sumΓ© only has enough room for $$$k$$$ projects, and you will absolutely not be hired if your rΓ©sumΓ© has empty space, so you require $$$\sum\limits_{i=1}^n b_i=k$$$.Find values for $$$b_1,\ldots, b_n$$$ that maximize the value of $$$f(b_1,\ldots,b_n)$$$ while satisfying the above two constraints.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); DSostavlenieRezyume solver = new DSostavlenieRezyume(); solver.solve(1, in, out); out.close(); } static class DSostavlenieRezyume { public void solve(int testNumber, FastScanner in, PrintWriter out) { int n = in.nextInt(); long k = in.nextLong(); int[] a = in.nextIntArray(n); long left = (long) -4e18, right = (long) (4e18 + 1); while (left < right - 1) { long mid = (left + right) / 2; long take = 0; for (int i = 0; i < n; i++) { if (a[i] <= mid) { continue; } take += get(a[i], mid); } if (take > k) { left = mid; } else { right = mid; } } long rem = k; long[] b = new long[n]; for (int i = 0; i < n; i++) { if (a[i] <= right) { continue; } b[i] = get(a[i], right); rem -= b[i]; } right--; for (int i = 0; i < n; i++) { if (a[i] <= right) { continue; } long newTake = get(a[i], right); if (newTake > b[i] && rem > 0) { if (newTake > b[i] + 1) { throw new AssertionError(); } rem--; b[i] = newTake; } } for (long i : b) { out.print(i + " "); } out.println(); } private long get(int ai, long mid) { if (1 + mid - ai > 0) { return 0; } double d = 9 - 12.0 * (1 + mid - ai); double res = (-3 + Math.sqrt(d)) / 6; long longRes = (long) res; while (3 * (longRes + 1) * (longRes + 2) + 1 + mid - ai <= 0) { longRes++; } while (longRes > 0 && 3 * (longRes + 1) * (longRes) + 1 + mid - ai > 0) { longRes--; } return Math.min(longRes, ai); } } static class FastScanner { public BufferedReader br; public StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } public FastScanner(String fileName) { try { br = new BufferedReader(new FileReader(fileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public int nextInt() { return Integer.parseInt(next()); } public String next() { while (st == null || !st.hasMoreElements()) { String line = null; try { line = br.readLine(); } catch (IOException e) { } st = new StringTokenizer(line); } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int[] nextIntArray(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) { ret[i] = nextInt(); } return ret; } } }
Java
["10 32\n1 2 3 4 5 5 5 5 5 5", "5 8\n4 4 8 2 1"]
4 seconds
["1 2 3 3 3 4 4 4 4 4", "2 2 2 1 1"]
NoteFor the first test, the optimal answer is $$$f=-269$$$. Note that a larger $$$f$$$ value is possible if we ignored the constraint $$$\sum\limits_{i=1}^n b_i=k$$$.For the second test, the optimal answer is $$$f=9$$$.
Java 11
standard input
[ "binary search", "greedy", "math" ]
5c17e01d02df26148e87dcba60ddf499
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\le n\le 10^5$$$, $$$1\le k\le \sum\limits_{i=1}^n a_i$$$)Β β€” the number of types of programming projects and the rΓ©sumΓ© size, respectively. The next line contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$)Β β€” $$$a_i$$$ is equal to the number of completed projects of type $$$i$$$.
2,700
In a single line, output $$$n$$$ integers $$$b_1,\ldots, b_n$$$ that achieve the maximum value of $$$f(b_1,\ldots,b_n)$$$, while satisfying the requirements $$$0\le b_i\le a_i$$$ and $$$\sum\limits_{i=1}^n b_i=k$$$. If there are multiple solutions, output any. Note that you do not have to output the value $$$f(b_1,\ldots,b_n)$$$.
standard output
PASSED
b7a619b1a53782fb4dfa0ed7cfc192cb
train_001.jsonl
1588775700
Uh oh! Applications to tech companies are due soon, and you've been procrastinating by doing contests instead! (Let's pretend for now that it is actually possible to get a job in these uncertain times.)You have completed many programming projects. In fact, there are exactly $$$n$$$ types of programming projects, and you have completed $$$a_i$$$ projects of type $$$i$$$. Your rΓ©sumΓ© has limited space, but you want to carefully choose them in such a way that maximizes your chances of getting hired.You want to include several projects of the same type to emphasize your expertise, but you also don't want to include so many that the low-quality projects start slipping in. Specifically, you determine the following quantity to be a good indicator of your chances of getting hired:$$$$$$ f(b_1,\ldots,b_n)=\sum\limits_{i=1}^n b_i(a_i-b_i^2). $$$$$$Here, $$$b_i$$$ denotes the number of projects of type $$$i$$$ you include in your rΓ©sumΓ©. Of course, you cannot include more projects than you have completed, so you require $$$0\le b_i \le a_i$$$ for all $$$i$$$.Your rΓ©sumΓ© only has enough room for $$$k$$$ projects, and you will absolutely not be hired if your rΓ©sumΓ© has empty space, so you require $$$\sum\limits_{i=1}^n b_i=k$$$.Find values for $$$b_1,\ldots, b_n$$$ that maximize the value of $$$f(b_1,\ldots,b_n)$$$ while satisfying the above two constraints.
256 megabytes
//package round639; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.util.PriorityQueue; public class D2 { InputStream is; PrintWriter out; String INPUT = ""; // a-3b^2-3b-1 >= t // 3b^2+3b+1+t-a // void solve() { int n = ni(); long K = nl(); int[] a = na(n); long low = -(long)4e18, high = 1000000001; while(high - low > 1){ long h = high+low>>1; long s = 0; for(int i = 0;i < n;i++){ long llow = 0, lhigh = a[i]+1; while(lhigh - llow > 1){ long b = lhigh+llow>>1; if(a[i]-(3*b*b+3*b+1) >= h){ llow = b; }else{ lhigh = b; } } s += llow; } if(s > K){ low = h; }else{ high = h; } } long h = high; long s = 0; long[] bb = new long[n]; for(int i = 0;i < n;i++){ long llow = 0, lhigh = a[i]+1; while(lhigh - llow > 1){ long b = lhigh+llow>>1; if(a[i]-(3*b*b+3*b+1) >= h){ llow = b; }else{ lhigh = b; } } s += llow; bb[i] = llow; } long rem = K-s; assert rem >= 0; PriorityQueue<long[]> pq = new PriorityQueue<>((x, y) -> -Long.compare(x[0], y[0]) ); for(int i = 0;i < n;i++){ if(bb[i] < a[i]){ pq.add(new long[]{f(a[i], bb[i]+1) - f(a[i], bb[i]), i}); } } while(rem > 0){ long[] cur = pq.poll(); int i = (int)cur[1]; bb[i]++; rem--; if(bb[i] < a[i]){ pq.add(new long[]{f(a[i], bb[i]+1) - f(a[i], bb[i]), i}); } } for(long v : bb){ out.print(v + " "); } out.println(); } long f(long a, long b) { return b*(a-b*b); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new D2().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
Java
["10 32\n1 2 3 4 5 5 5 5 5 5", "5 8\n4 4 8 2 1"]
4 seconds
["1 2 3 3 3 4 4 4 4 4", "2 2 2 1 1"]
NoteFor the first test, the optimal answer is $$$f=-269$$$. Note that a larger $$$f$$$ value is possible if we ignored the constraint $$$\sum\limits_{i=1}^n b_i=k$$$.For the second test, the optimal answer is $$$f=9$$$.
Java 11
standard input
[ "binary search", "greedy", "math" ]
5c17e01d02df26148e87dcba60ddf499
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\le n\le 10^5$$$, $$$1\le k\le \sum\limits_{i=1}^n a_i$$$)Β β€” the number of types of programming projects and the rΓ©sumΓ© size, respectively. The next line contains $$$n$$$ integers $$$a_1,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$)Β β€” $$$a_i$$$ is equal to the number of completed projects of type $$$i$$$.
2,700
In a single line, output $$$n$$$ integers $$$b_1,\ldots, b_n$$$ that achieve the maximum value of $$$f(b_1,\ldots,b_n)$$$, while satisfying the requirements $$$0\le b_i\le a_i$$$ and $$$\sum\limits_{i=1}^n b_i=k$$$. If there are multiple solutions, output any. Note that you do not have to output the value $$$f(b_1,\ldots,b_n)$$$.
standard output
PASSED
aaae317cc30cf8f7ffc16f87cb018424
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.util.*; import java.io.*; public class Solution { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); int m = in.nextInt(); long s = in.nextLong(); long[][] a = new long[n + 1][m + 1]; for (int w = 1; w <= n; w++) for (int h = 1; h <= m; h++) { long sum = 0; if (w * h == s) sum += 2 * (w / 2 + 1) * (h / 2 + 1) - 1; for (int dx = 1; dx <= (w - 1) / 2; dx++) { if (((w * h - s) % (4 * dx)) == 0 && w * h > s) { int dy = (w * h - (int)s) / 4 / dx; if (dy > 0 && dy <= (h - 1) / 2 && w * h - 4 * dx * dy == s) sum+= 2; } } a[w][h] = sum; } //out.println(a[500][500]); long[][] dp = new long[n + 1][m + 1]; for (int i = 1; i <= n; i+= 2) for (int j = 1; j <= m; j+=2) dp[i][j] = a[i][j]; for (int i = 1; i <= n; i+= 2) for (int j = 1; j <= m; j+=2) { if (i != 1) dp[i][j] += dp[i - 2][j]; if (j != 1) dp[i][j] += dp[i][j - 2]; if (i != 1 && j != 1) dp[i][j] -= dp[i - 2][j - 2]; } long ans = 0; for (int x = 1; x <= n; x++) for (int y = 1; y <= m; y++) { int w = 1 + 2 * Math.min(x - 1, n - x); int h = 1 + 2 * Math.min(y - 1, m - y); ans += dp[w][h]; } out.println(ans); } public void run() { try { //in = new FastScanner(new File("input.txt")); //out = new PrintWriter(new File("output.txt")); in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } } public static void main(String[] arg) { new Solution().run(); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
48d39914bce03ddfb69922c793b07867
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.*; import java.util.*; import java.math.BigInteger; public class main { public static void main(String[] args) { Scanner r = new Scanner(System.in); int N = r.nextInt(); int M = r.nextInt(); int S = r.nextInt(); long ans = 0; for(int a = 1 ;a<=N; a+=2) for(int b = 1 ;b<=M; b+=2) { //System.out.println(a+" "+b+" "+(N-a+1)*(M-b+1)*((a-1)/2 + 1)*((b-1)/2 + 1)); if(a*b == S) ans+=((a+1)*(b+1)/2 - 1)* (N-a+1)*(M-b+1); else if(a*b<S) { for(int c = 1 ;c<a; c+=2) { //System.out.println(a+" ::: "+b +" "+a*b); //if(2*c + 1 > N)continue; int d = S - a*b + c*b; if(d%c!=0)continue; d /= c; if(d>M || d%2 ==0)continue; // System.out.println(a+" "+b+" "+c+" "+d); ans += (N - a + 1) * (M - d + 1) * 2; } } } System.out.println(ans); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
ac5200244c147578668f3ce8025d0554
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class B3 { public static StreamTokenizer in = new StreamTokenizer(System.in); public static boolean bg = true; public static int ni() throws Exception { in.nextToken(); return (int)in.nval; } public static int[] intl(int n) throws Exception { int[] l1 = new int[n]; for (int i=0;i<n;i++){ in.nextToken(); l1[i] = (int)in.nval; } return l1; } public static void main(String[] args) throws Exception { int n = ni(); int m = ni(); int tar = ni(); int total = n*m; BigInteger fin = bi(0); for (int i = 0;i<=(n-1)/2; i++){ for (int j = 0;j<=(m-1)/2; j++){ int t1 = (1+2*i)*(1+2*j); long k1 = 0; if (t1<tar) continue; else if (t1 == tar){ k1 += (i+1)*(j+1); k1 += (i+1)*(j+1)-1; } else { int rest = t1-tar; if (rest%4==0){ rest /= 4; for (int k = 1; k<=i;k++){ if (rest % k == 0){ if (rest/k<=j){ k1+=2; } } } } } int rx = n - (1 + 2 * i) + 1; int cx = m - (1 + 2 * j) + 1; long xx = rx*cx; fin = fin.add(bi(xx).multiply(bi(k1)) ); } } System.out.println(fin); } public static BigInteger bi(long n1){ return new BigInteger(n1+""); } public static int[] factor2(int n1){ ArrayList<Integer> l1 = new ArrayList(); ArrayList<Integer> l2 = new ArrayList(); for (int i=1;i<=Math.sqrt(n1);i++){ if (n1%i==0){ l1.add(i); if (i!=n1/i) l2.add(n1/i); } } int[] fin = new int[l1.size()+l2.size()]; for (int i=0;i<l1.size();i++){ fin[i] = l1.get(i); } for (int i=l1.size();i<l1.size()+l2.size();i++){ fin[i] = l2.get(l2.size()-1- (i-l1.size() ) ); } return fin; } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
c39036ff8b6893b8c7b4b0a5117c5f50
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Locale; import java.util.StringTokenizer; public class Solution { /** * @param args */ BufferedReader in; PrintWriter out; StringTokenizer st; String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } void solve() throws NumberFormatException, IOException { int n = nextInt(); int m = nextInt(); int s = nextInt(); long ans = 0; for (int a = 0; 2 * a + 1 <= n; a++) { for (int b = 0; 2 * b + 1 <= m; b++) { if ((2 * a + 1) * (2 * b + 1) > s) break; if ((2 * a + 1) * (2 * b + 1) == s) { ans += (long)(2 * (a + 1) * (b + 1) - 1) * (n - 2 * a) * (m - 2 * b); // out.println(a + " " + b + " " + (long)(2 * (a + 1) * (b + 1) - 1) * (n - 2 * a) * (m - 2 * b)); continue; } int s1 = s - (2 * a + 1) * (2 * b + 1); for (int c = 0; c < a; c++) { if (s1 % (2 * (2 * c + 1)) == 0) { int d = s1 / (2 * (2 * c + 1)) + b; if (2 * d + 1 <= m) { ans += (n - 2 * a) * (m - 2 * d); // out.println(a + " " + b + " " + c + " " + d + "!" + (n - 2 * a) * (m - 2 * d)); } } } for (int d = 0; d < b; d++) { if (s1 % (2 * (2 * d + 1)) == 0) { int c = s1 / (2 * (2 * d + 1)) + a; if (2 * c + 1 <= n) { ans += (n - 2 * c) * (m - 2 * b); // out.println(a + " " + b + " " + c + " " + d + "?" + (n - 2 * c) * (m - 2 * b)); } } } } } out.println(ans); } public void run() { try { Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { out.close(); } } public static void main(String[] args) { (new Solution()).run(); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
194a3344dd3a0508d12699e469639877
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner r = new Scanner(System.in); int N = r.nextInt(); int M = r.nextInt(); int S = r.nextInt(); int[][] L = new int[N + 10][M + 10]; for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) L[1 + 2 * Math.min(i, N - i - 1)][1 + 2 * Math.min(j, M - j - 1)]++; int[][] C = new int[N + 10][M + 10]; for(int i = N; i >= 1; i--) for(int j = M; j >= 1; j--) C[i][j] = L[i][j] + (i + 1 <= N? C[i + 1][j] : 0) + (j + 1 <= M ? C[i][j + 1] : 0) - (i + 1 <= N && j + 1 <= M ? C[i + 1][j + 1] : 0); long ret = 0; for(int i = 1; i <= N; i += 2) for(int j = 1; j <= M; j += 2) for(int h = 1; h <= M; h += 2){ if(i * h > S)continue; if(h >= j){ if(i * h == S)ret += C[i][h] * ((i + 1) / 2); else if((S - i * h) % (2 * j) == 0 && (S - i * h) / j + i <= N) ret += C[i + (S - i * h) / j][h]; }else{ if(i * h + (j - h) == S)ret += C[i][j]; else if(S > (i * h + (j - h)) && (S - (i * h + (j - h))) % (2 * (j - h)) == 0 && (S - (i * h + (j - h))) / (j - h) + 1 <= i) ret += C[i][j]; else if(S > i * j && (S - i * j) % (2 * j) == 0 && (S - i * j) / j + i <= N) ret += C[i + (S - i * j) / j][j]; } } System.out.println(ret); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
d5bcce2d25319bd9330b94b774b5a075
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.StringTokenizer; public class Main { private BufferedReader br; private StringTokenizer tokenizer; private PrintWriter pw; private void solve() throws IOException { long n = nextLong(); long m = nextLong(); long s =nextLong(); long res = 0; if (s % 2 == 0) { pw.print(0); return; } for (int i = 1; i <= m; i += 2) { for (int j = 1; j <= n; j += 2) { if (i * j == s) { if (i == j) res += (n - j + 1)*(m - i + 1)*((i+1)/2 * (j+1)/2 * 2 - 1); else res += (n - j + 1)*(m - i + 1)*((i+1)/2 * (j+1)/2 * 2 - 1); } else if (i*j < s) { for (int t = 1; t < j; t += 2) { if ((s - i*j) % t == 0) { long tp = (s - i*j) / t; if (m >= i+tp) res += 2*(n - j + 1)*(m - (i+tp) + 1); } } } } } pw.print(res); } public static void main(String[] args) { new Main().run(); } public void run() { try { pw = new PrintWriter(System.out); br = new BufferedReader(new InputStreamReader(System.in)); solve(); pw.close(); br.close(); } catch (IOException e) { System.err.println("IO Error"); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(br.readLine()); } return tokenizer.nextToken(); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
96e650987d1947a5a5aa477fad6701a6
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.IOException; import java.io.OutputStreamWriter; import java.math.BigDecimal; import java.io.BufferedWriter; import java.util.Locale; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Jacob Jiang */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int m = in.nextInt(); int s = in.nextInt(); long answer = solve1(n, m, s) + solve2(n, m, s); out.println(answer); } private long solve2(int n, int m, int s) { long result = 0; for (int a = 1; a <= n; a++) { for (int d = 1; d <= m; d++) { int count = 0; for (int c = 0; c <= n; c++) { if (a <= c) continue; int rhs = s - 1 - 2 * (a + d) - 4 * c * d; int lhs = 4 * (a - c); if (rhs < 0 || rhs % lhs != 0) continue; int b = rhs / lhs; if (b < 0 || b > m) continue; if (d <= b) continue; count++; } long times = 1l * Math.max(n - 2 * a, 0) * Math.max(m - 2 * d, 0); result += times * count; } } return result * 2; } private long solve1(int n, int m, int s) { long result = 0; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if ((2 * i + 1) * (2 * j + 1) != s) continue; long cur = 2l * (i + 1) * (j + 1) - 1; long times = 1l * Math.max(n - 2 * i, 0) * Math.max(m - 2 * j, 0); result += cur * times; } } return result; } } class InputReader { private InputStream stream; private byte[] buf = new byte[1 << 20]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c & 15; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } class OutputWriter { private PrintWriter writer; public OutputWriter(OutputStream stream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void println(long x) { writer.println(x); } public void close() { writer.close(); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
327ecc1130acb18c3228bd9a5962eea3
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.util.*; public class Crosses { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int m = cin.nextInt(); int s = cin.nextInt(); cin.close(); long ans = 0; for (int a = 1; a <= n; a += 2) { for (int b = 1; b <= m; b += 2) { if (a * b == s) { ans += ((a + 1) * (b + 1) / 2 - 1) * (n - a + 1) * (m - b + 1); } else if (a * b < s) { for (int c = 1; c < a; c += 2) { int d = s - a * b + c * b; if (d % c != 0) { continue; } d /= c; if (d > m || d % 2 == 0) { continue; } ans += (n - a + 1) * (m - d + 1) * 2; } } } } System.out.println(ans); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
5d61b40bb59c406167a4fea5af1c1abf
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.*; import java.util.*; public class C { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; void solve() throws IOException { int n = nextInt(); int m = nextInt(); int s = nextInt(); long ret = 0; for (int x1 = 1; x1 <= n && x1 <= s; x1 += 2) { for (int y1 = 1; y1 <= m && x1 * y1 <= s; y1 += 2) { if (x1 * y1 == s) { ret += (n - x1 + 1) * (m - y1 + 1) * (x1 == 1 && y1 == 1 ? 1 : ((x1 + 1) / 2) * ((y1 + 1) / 2) * 2 - 1); } else { for (int x2 = 1; x2 < x1 && x1 * y1 + 2 * x2 <= s; x2 += 2) { int y2 = (s - x1 * y1) / x2; if (y2 % 2 == 0 && x1 * y1 + x2 * y2 == s && y2 + y1 <= m) { ret += (n - x1 + 1) * (m - y1 - y2 + 1) * 2; } } } } } out.println(ret); } void inp() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } public static void main(String[] args) throws IOException { new C().inp(); } String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return "0"; } } return st.nextToken(); } String nextString() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return "0"; } } return st.nextToken("\n"); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
7941c4d2d209a648a1fa27e4975d13d6
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.*; import java.util.*; public class C { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; void solve() throws IOException { int n = nextInt(); int m = nextInt(); int s = nextInt(); long ans = 0; // rectangles for (int h = 1; h <= n; h += 2) { if (s % h != 0) continue; int w = s / h; if (((w & 1) == 0) || (w > m)) continue; long pos = (long)(n - h + 1) * (m - w + 1); long sz = 2L * (h / 2 + 1) * (w / 2 + 1) - 1; ans += pos * sz; } // crosses for (int h = 3; h <= n; h += 2) { for (int w = 3; w <= m; w += 2) { if (w * h <= s) continue; int leftArea = w * h - s; long pos = (long)(n - h + 1) * (m - w + 1); long sz = 0; for (int rH = 1; 2 * rH + 1 <= h; rH++) { // h * w - 4 * rH * rW = s if (leftArea % (4 * rH) != 0) continue; int rW = leftArea / (4 * rH); if (rW < 1 || 2 * rW + 1 > w) continue; sz += 2; } ans += pos * sz; } } out.println(ans); } void inp() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } public static void main(String[] args) throws IOException { new C().inp(); } String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return "0"; } } return st.nextToken(); } String nextString() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { eof = true; return "0"; } } return st.nextToken("\n"); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
1fbf1f6d6110a6050aaf4462c26f28c5
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.*; import java.util.*; public class P215C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int s = sc.nextInt(); for (int i = 0; i < memo.length; i++) Arrays.fill(memo[i], -1); if (s % 2 == 0) { System.out.println("0"); return; } long sum = 0; for (int i = 1; i <= n; i+=2) { for (int j = 1; j <= m; j+=2) { if (i * j < s) continue; int diff = (i * j) - s; if (diff % 4 != 0) continue; long vol = (n-i+1) * (m-j+1); long con = 0; if (diff == 0) { long cd = ((i/2+1) * (j/2+1) * 2) - 1; con = cd * vol; } else { int quart = diff / 4; long cd = count(quart, i/2, j/2); con = cd * vol * 2; } sum += con; //System.out.printf("Contribution to %dx%d is %d\n", i, j, con); } } System.out.println(sum); } static long[][] memo = new long[501][501]; public static long countInside(int h, int w) { if (memo[h][w] != -1) return memo[h][w]; if (memo[w][h] != -1) return memo[w][h]; long sum = 0; for (int i = 1; i <= h; i+=2) { for (int j = 1; j <= w; j+=2) { } } return sum; } public static long count(int size, int h, int w) { if (size == 0 || h == 0 || w == 0) return 0; if (h * w < size) return 0; int max = (int)Math.floor(Math.sqrt(size)); int mind = Math.min(h, w); int maxd = Math.max(h, w); max = Math.min(max, maxd); int count = 0; for (int i = 1; i <= max; i++) { if (size % i != 0) continue; int k = size / i; if (Math.max(i, k) > maxd || Math.min(i, k) > mind) continue; if (i == k) { count++; } else if (Math.max(i, k) <= mind) { count+=2; } else { count++; } } //System.out.printf("In %dx%d space there are %d of size %d\n", h, w, count, size); return count; } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
ce9bdd666f86954860dd839ecceb5e22
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.*; import java.util.*; public class Main { public Scanner sc; public void run() { int n = sc.nextInt(); int m = sc.nextInt(); int s = sc.nextInt(); long ans = 0; for (int n1 = 0; n1 * 2 + 1 <= n; n1++) for (int m1 = 0; m1 * 2 + 1 <= m; m1++) { int cnt = 0; if ((n1*2+1) * (m1*2+1) == s) { cnt = 2*(n1+1)*(m1+1)-1; } else if ((n1*2+1) * (m1*2+1) > s) { if (((n1*2+1)*(m1*2+1)-s) % 4 != 0) continue; int t = ((n1*2+1)*(m1*2+1)-s) / 4; for (int w = 1; w <= n1; w++) { if (t % w != 0) continue; int h = t / w; if (1 <= h && h <= m1) cnt += 2; } } ans += (n-2*n1)*(m-2*m1)*cnt; } System.out.println(ans); } public static void main(String[] args) { Main main = new Main(); try { main.sc = new Scanner(new FileInputStream("test.in")); } catch (FileNotFoundException e) { main.sc = new Scanner(System.in); } main.run(); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
78fb6a350b27c09e9654a59e9aab2df0
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author George Marcus */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, Scanner in, PrintWriter out) { int N = in.nextInt(); int M = in.nextInt(); int S = in.nextInt(); long res = 0; for(int height = 1; height <= N; height += 2) for(int width = 1; width <= M; width += 2) if(height * width == S) { int places = (N - height + 1) * (M - width + 1); int pairs = 2 * (height / 2 + 1) * (width / 2 + 1) - 1; res += (long)places * pairs; } else if(height * width > S) { int areaLeft = height * width - S; int cutWidth; int places = (N - height + 1) * (M - width + 1); int crt = 0; for(int cutHeight = 1; 2 * cutHeight < height; cutHeight++) if(areaLeft % (4 * cutHeight) == 0) { cutWidth = areaLeft / (4 * cutHeight); if(cutWidth > 0 && 2 * cutWidth < width) { crt += 2; } } res += (long)crt * places; } out.print(res); } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
e56d8dc5f4efa504a1ab3125fc6ba698
train_001.jsonl
1344267000
There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).A group of six numbers (a, b, c, d, x0, y0), where 0 ≀ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled: |x0 - x| ≀ a and |y0 - y| ≀ b |x0 - x| ≀ c and |y0 - y| ≀ d The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4. Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x, y) of the cross 1 ≀ x ≀ n;Β 1 ≀ y ≀ m holds). The area of the cross is the number of cells it has.Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author RiaD */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Reader in = new Reader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, Reader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int s = in.nextInt(); long ans = 0; for(int ac = 0; ac<= n/2; ++ac){ for(int bd = 0; bd <= m/2; ++bd){ int curS = (2 * ac + 1) * (2* bd + 1); if(curS < s) continue; if(curS == s){ ans += (n - 2 * ac) * (m - 2 * bd) * (2L * (ac + 1) * (bd + 1) - 1); } else{ int toDrop = curS - s; if(toDrop%4 !=0) continue; toDrop/=4; for(int i = 1; i<=ac; ++i){ if(toDrop % i == 0 && toDrop/i <= bd){ ans +=2 * (n - 2 * ac) * (m - 2 * bd); } } } } } out.print(ans); } } class Reader { private BufferedReader reader; private StringTokenizer tokenizer; public Reader(BufferedReader reader) { this.reader = reader; } public Reader(InputStream stream) { this(new BufferedReader(new InputStreamReader(stream))); } public String nextString() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(nextString()); } private String readLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } }
Java
["2 2 1", "3 4 5"]
2 seconds
["4", "4"]
NoteIn the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2).In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).
Java 7
standard input
[ "implementation", "brute force" ]
4aae1c6f52e2ca7029b5a003cf307795
The input consists of a single line containing three integers n, m and s (1 ≀ n, m ≀ 500, 1 ≀ s ≀ nΒ·m). The integers are separated by a space.
2,100
Print a single integer β€” the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
f5765431834cf4351f5765df600728c1
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedReader; import java.io.Reader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; /** * Built using CHelper plug-in * Actual solution is at the top * @author Denis Nedelyaev */ public class Main { public static void main(String[] args) throws Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(in, out); solver.solve(1); out.close(); } } class TaskD { private final FastScanner in; private final PrintWriter out; public TaskD(FastScanner in, PrintWriter out) { this.in = in; this.out = out; } public void solve(int testNumber) throws IOException { int n = in.nextInt(); int m = in.nextInt(); String[] map = new String[n]; for (int i = 0; i < n; i++) { map[i] = in.next(); } long[][] value = new long[n][m]; int count = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { long a = value[i][j]; int b = map[i].charAt(j) == 'W' ? 1 : -1; if (a != b) { count++; long c = b - a; for (int k = 0; k <= i; k++) { for (int l = 0; l <= j; l++) { value[k][l] += c; } } } } } out.println(count); } } class FastScanner { private BufferedReader br; private String line = ""; private int pos; public FastScanner(InputStream is) { this(new BufferedReader(new InputStreamReader(is))); } public FastScanner(Reader reader) { br = new BufferedReader(reader); } public String next() throws IOException { if (!goToNextToken()) { return null; } return readString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } private boolean goToNextToken() throws IOException { if (br == null) { return false; } while (pos == line.length()) { line = br.readLine(); if (line == null) { br = null; return true; } pos = 0; skipWhitespace(); } return true; } private String readString() { int start = pos; while (pos < line.length()) { char c = line.charAt(pos); if (c == ' ' || c == '\t') { break; } pos++; } String result = line.substring(start, pos); skipWhitespace(); return result; } private void skipWhitespace() { while (pos < line.length()) { char c = line.charAt(pos); if (c != ' ' && c != '\t') { break; } pos++; } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
028896e2a9e2b091d4b19fdf7c5e2581
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class Main { private static PrintWriter out; private static FastReader in; private static class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; public FastReader(InputStream inputStream) { reader = new BufferedReader( new InputStreamReader(inputStream), 1 << 16); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException ex) { throw new RuntimeException(ex); } } return tokenizer.nextToken(); } public String nextLine() { try { return reader.readLine(); } catch (IOException ex) { throw new RuntimeException(ex); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(in.next()); } public int[] nextArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = in.nextInt(); } return res; } } public static void main(String[] args) throws FileNotFoundException { //in = new FastReader(new FileInputStream("input.txt")); //out = new PrintWriter(new FileOutputStream("output.txt")); in = new FastReader(System.in); out = new PrintWriter(System.out); int n = in.nextInt(), m = in.nextInt(); int[][] target = new int[n][m]; for (int i = 0; i < n; i++) { char[] S = in.next().toCharArray(); for (int j = 0; j < m; j++) { if (S[j] == 'W') target[i][j] = +1; else target[i][j] = -1; } } int[][] current = new int[n][m]; int count = 0; for (int i = n-1; i >= 0; --i) { for (int j = m-1; j >= 0; --j) { if (current[i][j] != target[i][j]) { int coeff = target[i][j] - current[i][j]; for (int x = 0; x <= i; ++x) { for (int y = 0; y <= j; ++y) { current[x][y] += coeff; } } ++count; } } } out.println(count); out.flush(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
82489f416c632ed5b9c46ac0cb697a62
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
/* username: leandro92 */ import java.util.*; import java.io.*; import java.math.*; public class Main implements Runnable { public void solve() throws IOException { int n = nextInt(); int m = nextInt(); String[] feature = new String[n]; for (int i = 0; i < n; i++) feature[i] = nextToken(); int[][] matrix = new int[n][m]; int operations = 0; for (int i = n - 1; i >= 0; i--) for (int j = m - 1; j >= 0; j--) { int value = 0; if (i != n - 1) value += matrix[i + 1][j]; if (j != m - 1) value += matrix[i][j + 1]; if (i != n - 1 && j != m - 1) value -= matrix[i + 1][j + 1]; if (feature[i].charAt(j) == 'B') { if (value != -1) { operations = operations + 1; } matrix[i][j] = -1; } else { if (value != +1) { operations = operations + 1; } matrix[i][j] = +1; } } System.out.println(operations); } public static void main(String[] args) { new Main().run(); } BufferedReader reader; StringTokenizer tokenizer; public void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; solve(); reader.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } BigInteger nextBigInteger() throws IOException { return new BigInteger(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
3cfa5cd51007b1d89ee668d52f259104
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.Scanner; public class TaskD { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[][] xaar = new int[n][m]; sc.nextLine(); for (int i = 0; i < xaar.length; i++) { String s = sc.nextLine(); for (int j = 0; j < s.length(); j++) { xaar[i][j] = ('B' == s.charAt(j))? -1 : 1; } } int result = 0; for (int i = xaar.length - 1; i >= 0; i--) { for (int j = xaar[0].length - 1; j >= 0 ; j--) { if (xaar[i][j] != 0){ //System.out.println(xaar[0][0]); result++; //System.out.println(i + " " + j); for (int j2 = 0; j2 <= i; j2++) { for (int k = 0; k <= j; k++) { xaar[j2][k] -= xaar[i][j]; } } } } } System.out.println(result); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
f783e7b195e5bd4783864ffbbf2bbfa0
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.Reader; import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author Yakutov Dmitry */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, FastReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] s = new char[n][]; for (int i = 0; i < n; i++) { s[i] = in.nextToken().toCharArray(); } int[][] cnt = new int[n][m]; int ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { int need = s[i][j] == 'B' ? -1 : 1; if (need != cnt[i][j]) { ans++; int diff = need - cnt[i][j]; for (int i1 = 0; i1 <= i; i1++) { for (int j1 = 0; j1 <= j; j1++) { cnt[i1][j1] += diff; } } } } } out.println(ans); } } class FastReader extends BufferedReader { private StringTokenizer st; public FastReader(InputStream is) { super(new InputStreamReader(is)); } public String nextToken() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(readLine()); } return st.nextToken(); } catch (IOException e) { return null; } } public int nextInt() { return Integer.parseInt(nextToken()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
388e2d0865fe4983065cd90fc7ff6537
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.*; public class D { private static final int mod = (int)1e9+7; final Random random = new Random(0); final IOFast io = new IOFast(); /// MAIN CODE public void run() throws IOException { // int TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim()); int TEST_CASE = 1; while(TEST_CASE-- != 0) { int h = io.nextInt(); int w = io.nextInt(); char[][] cs = new char[h][]; for(int y = 0; y < h; y++) { cs[y] = io.next(); } long[][] val2 = new long[h][w]; long[][] val = new long[h][w]; for(int y = h - 1; y >= 0; y--) { for(int x = w - 1; x >= 0; x--) { val2[y][x] = cs[y][x] == 'W' ? 1 : -1; } } int ans = 0; for(int y = h - 1; y >= 0; y--) { for(int x = w - 1; x >= 0; x--) { if(val[y][x] != val2[y][x]) { ans++; final long v = val2[y][x] - val[y][x]; for(int yy = y; yy >= 0; yy--) { for(int xx = x; xx >= 0; xx--) { val[yy][xx] += v; } } // System.err.println(); } } } io.out.println(ans); } } /// TEMPLATE static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); } static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); } static <T> void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; } static void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; } void main() throws IOException { // IOFast.setFileIO("rle-size.in", "rle-size.out"); try { run(); } catch (EndOfFileRuntimeException e) { } io.out.flush(); } public static void main(String[] args) throws IOException { new D().main(); } static class EndOfFileRuntimeException extends RuntimeException { private static final long serialVersionUID = -8565341110209207657L; } static public class IOFast { private BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private PrintWriter out = new PrintWriter(System.out); void setFileIn(String ins) throws IOException { in.close(); in = new BufferedReader(new FileReader(ins)); } void setFileOut(String outs) throws IOException { out.flush(); out.close(); out = new PrintWriter(new FileWriter(outs)); } void setFileIO(String ins, String outs) throws IOException { setFileIn(ins); setFileOut(outs); } private static int pos, readLen; private static final char[] buffer = new char[1024 * 8]; private static char[] str = new char[500*8*2]; private static boolean[] isDigit = new boolean[256]; private static boolean[] isSpace = new boolean[256]; private static boolean[] isLineSep = new boolean[256]; static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; } public int read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; } public int nextInt() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; } public long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; } public char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } } int reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; } int reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; } public char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isLineSep); try { if(str[len-1] == '\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); } public String nextString() throws IOException { return new String(next()); } public char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); } public int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; } public double nextDouble() throws IOException { return Double.parseDouble(nextString()); } public long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } public int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } public int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; } public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; } public double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
db99aee89169865cd300095a76cf2f54
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.math.BigDecimal; import java.util.*; public class A { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); char [][] _map = new char[n][m]; for(int i = 0 ; i < n ; i++) _map[i] = in.next().toCharArray(); int [][] map = new int[n][m]; for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < m ; j++) map[i][j] = _map[i][j] == 'W' ? 1 : -1; int res = 0; for(int i = n-1 ; i >= 0 ; i--) for(int j = m-1 ; j >= 0 ; j--) if(map[i][j] != 0) { res++; for(int x = 0 ; x <= i ; x++) for(int y = 0 ; y <= j ; y++) map[x][y] += -map[i][j]; } System.out.println(res); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
c92eb5fe05fafb5a8ad91ebf7bb59794
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.*; public class cf_66_04 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int h=sc.nextInt(); int w=sc.nextInt(); String[] s=new String[h]; int[][] num=new int[h][w]; for(int i=0;i<h;i++){ s[i]=sc.next(); for(int j=0;j<w;j++) num[i][j]= (s[i].charAt(j)=='W' ? 1:-1); } int res=0; for(int i=h-1;i>=0;i--) for(int j=w-1;j>=0;j--){ if(num[i][j]!=0){ res++; int a=-num[i][j]; for(int ii=0;ii<=i;ii++) for(int jj=0;jj<=j;jj++) num[ii][jj]+=a; } } System.out.println(res); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
6f88ee6b2ef0fa725b8c7125aaea1219
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.StringTokenizer; public class a { public static void main(String[] args) throws Exception { FastScanner in = new FastScanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int[][] grid = new int[n][m]; for(int i=0;i<n;i++) { String s = in.next(); for(int j=0;j<m;j++) { grid[i][j] = s.charAt(j) == 'W' ? 1 : -1; } } int ans = 0; while(true) { int si = -1, sj = -1; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(grid[i][j] != 0) { si = i; sj = j; } } } if(si == -1) break; ans++; int d = -grid[si][sj]; for(int i=0;i<=si;i++) for(int j=0;j<=sj;j++) grid[i][j] += d; } System.out.println(ans); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = null; } public String next() throws IOException { while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
6df5948281c5d5505b56bbf13f3e99c6
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class D{ static InputReader in; static PrintWriter out; static long[][] ar; static int n,m; static int count=0; static boolean[][] isWhite; public static void apply(int a, int b,long c){ for(int i=1; i<=a; i++){ for(int j=1;j<=b; j++){ ar[i][j]+=c; } } /*for(int i=1; i<= n; i++){ for(int j=1; j<=m; j++){ out.print(ar[i][j] + " "); } out.println(); } out.println("Done apply");*/ } public static void update(int a, int b){ for(int i=b; i>=1; i--){ if( isWhite[a][i]){ if(ar[a][i] != 1){ apply(a,i, 1-ar[a][i]); count++; } }else{ if(ar[a][i] != -1){ apply(a,i, -1-ar[a][i]); count++; } } } for(int i=a-1; i>=1; i--){ if( isWhite[i][b]){ if(ar[i][b] != 1){ apply(i,b,1-ar[i][b]); count++; } }else{ if(ar[i][b] != -1){ apply(i,b, -1-ar[i][b]); count++; } } } } public static void main(String[] args) { in= new InputReader(System.in); out= new PrintWriter(System.out,true); n= in.nextInt(); m= in.nextInt(); ar= new long[n+1][m+1]; isWhite= new boolean[n+1][m+1]; for(int i=1; i<=n; i++){ String s= in.next(); for(int j=1; j<=m; j++){ long c=0; char l = s.charAt(j-1); if(l=='B'){ }else{ isWhite[i][j]=true; } } } int i=n; int j=m; while(i>=1 && j>=1){ update(i,j); i--; j--; } out.println(count); out.close(); System.exit(0); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
8065ea0d4240c781b41df6b8f147eb0e
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int value = 0; int row = sc.nextInt(); int column = sc.nextInt(); int[][] goal = new int[row][column]; int[][] operator = new int[row][column]; for (int i = 0; i < row; i++) for (int j = 0; j < column; j++) operator[i][j] = 0; sc.nextLine(); for (int i = 0; i < row; i++) { String tmp = sc.nextLine(); for (int j = 0; j < tmp.length(); j++) { if (tmp.charAt(j) == 'B') { goal[i][j] = -1; } else { goal[i][j] = 1; } } } sc.close(); for (int i = row - 1; i >= 0; i--) { for (int j = column - 1; j >= 0; j--) { if (goal[i][j] != operator[i][j]) { value++; int tmp = goal[i][j] - operator[i][j]; for (int m = 0; m <= i; m++) { for (int n = 0; n <= j; n++) { operator[m][n] += tmp; } } } } } System.out.println(value); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
7ce12a6a03176a4fb9c8fc2433b12bf4
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Rene */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] map = new char[n][m]; for ( int i = 0; i < n; i++) map[i] = in.next().toCharArray(); int[] weight = new int[n]; int current = 0; int result = 0; for ( int c = m-1; c >= 0; c--) { current = 0; for (int r = n - 1; r >= 0; r--) { current += weight[r]; int target = map[r][c] == 'W' ? 1 : -1; if ( current != target) { result++; int delta = target - current; current += delta; weight[r] += delta; } } } out.println(result); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
99e69d7156d697b17d44b0f0f454a339
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class CF { FastScanner in; PrintWriter out; void solve() { int n = in.nextInt(); int m = in.nextInt(); char[][] a = new char[n][]; for (int i = 0; i < n; i++) { a[i] = in.next().toCharArray(); } long[][] cur = new long[n][m]; int res = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { long need = a[i][j] == 'W' ? 1 : -1; long add = need - cur[i][j]; if (add == 0) { continue; } res++; for (int i1 = 0; i1 <= i; i1++) { for (int j1 = 0; j1 <= j; j1++) { cur[i1][j1] += add; } } } } out.println(res); } void runIO() { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } void run() { try { in = new FastScanner(new File("test.in")); out = new PrintWriter(new File("test.out")); solve(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] args) { new CF().runIO(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
f8134dcc44f82ab65a2b440db0287e2d
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.OutputStreamWriter; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author ilyakor */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] a = new char[n][]; for (int i = 0; i < n; ++i) a[i] = in.nextToken().toCharArray(); int[][] d = new int[n + 1][m + 1]; int res = 0; for (int i = n - 1; i >= 0; --i) { int sum = 0; for (int j = m - 1; j >= 0; --j) { d[i][j] = sum + d[i + 1][j]; int s; if (a[i][j] == 'W') s = +1; else s = -1; if (d[i][j] + s == 0) continue; sum += -s - d[i][j]; d[i][j] = -s; ++res; } } out.printLine(res); } } class InputReader { private InputStream stream; private byte[] buffer = new byte[10000]; private int cur; private int count; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isSpace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (count == -1) { throw new InputMismatchException(); } try { if (cur >= count) { cur = 0; count = stream.read(buffer); if (count <= 0) return -1; } } catch (IOException e) { throw new InputMismatchException(); } return buffer[cur++]; } public int readSkipSpace() { int c; do { c = read(); } while (isSpace(c)); return c; } public String nextToken() { int c = readSkipSpace(); StringBuilder sb = new StringBuilder(); while (!isSpace(c)) { sb.append((char) c); c = read(); } return sb.toString(); } public int nextInt() { int sgn = 1; int c = readSkipSpace(); if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = res * 10 + c - '0'; c = read(); } while (!isSpace(c)); res *= sgn; return res; } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
76a4fc93abfb3969ab88053e40dcb71f
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author PM */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, PrintWriter out) { int nrows = in.nextInt(); int ncols = in.nextInt(); char[][] B = new char[nrows][ncols]; for (int i = 0; i < nrows; i++) { String s = in.next(); for (int j = 0; j < ncols; j++) B[i][j] = s.charAt(j); } int[] colScore = new int[ncols]; int ops = 0; for(int row=nrows-1; row>=0; --row) for(int col=ncols-1; col>=0;--col) { int need = (B[row][col]=='W'?1:-1); int tochange = colScore[col] - need; if (tochange!=0) { ++ops; for(int c = col; c>=0; --c) colScore[c] -= tochange; } } out.println(ops); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
efe7f384af757dbb0e6b40ff58aa1026
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author Aldo Culquicondor */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { int n, m; int[][] map; public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); m = in.nextInt(); map = new int[n+1][m+1]; for (int i = 0; i < n; ++i) { String s = in.next(); for (int j = 0; j < m; ++j) map[i][j] = s.charAt(j) == 'B' ? -1 : 1; } int ans = 0; for (int i = n - 1; i >= 0; --i) for (int j = m - 1; j >= 0; --j) if (map[i+1][j] + map[i][j+1] - map[i+1][j+1] - map[i][j] != 0) ++ans; out.println(ans); } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
7c00dec16c08861a9f8cf08c1a6a8b96
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author Aldo Culquicondor */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { int n, m; int[][] map; public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); m = in.nextInt(); map = new int[n][m]; for (int i = 0; i < n; ++i) { String s = in.next(); for (int j = 0; j < m; ++j) map[i][j] = s.charAt(j) == 'B' ? -1 : 1; } int ans = 0; for (int i = n - 1; i >= 0; --i) { for (int j = m - 1; j >= 0; --j) { int sum = 0; if (i + 1 < n) sum += map[i+1][j]; if (j + 1 < m) sum += map[i][j+1]; if (i + 1 < n && j + 1 < m) sum -= map[i+1][j+1]; if (sum - map[i][j] != 0) ++ans; } } out.println(ans); } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
a3863803a11012cc34a4eb2f53580adf
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author Aldo Culquicondor */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { int n, m; int[][] map; public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); m = in.nextInt(); map = new int[n][m]; for (int i = 0; i < n; ++i) { String s = in.next(); for (int j = 0; j < m; ++j) map[i][j] = s.charAt(j) == 'B' ? -1 : 1; } int ans = 0; for (int i = n - 1; i >= 0; --i) { for (int j = m - 1; j >= 0; --j) { int sum = 0; for (int r = i; r < n; ++r) for (int c = j; c < m; ++c) sum += map[r][c]; sum -= 2 * map[i][j]; if (sum != 0) ++ans; map[i][j] = -sum; } } out.println(ans); } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
74e54280178ce55600379aeea1c0018b
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class B{ public static boolean DEBUG = false; public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st; st = getst(br); int n = nextInt(st); int m = nextInt(st); long[][] vals = new long[n][m]; int[][] feat = new int[n][m]; for(int i = 0; i < n; i++){ String str = br.readLine(); for(int j = 0; j < m; j++){ if(str.charAt(j) == 'B'){ feat[i][j] = -1; } else { feat[i][j] = 1; } } } if(DEBUG){ for(int x = 0; x < n; x++){ debug(Arrays.toString(feat[x])); } debug(""); } int ans = 0; for(int i = n-1; i >= 0; i--){ for(int j = m-1; j >= 0; j--){ if(vals[i][j] != feat[i][j]){ ans++; long k = (long)(feat[i][j]) - vals[i][j]; for(int x = 0; x <= i; x++){ for(int y = 0; y <= j; y++){ vals[x][y] += k; } } if(DEBUG){ for(int x = 0; x < n; x++){ debug(Arrays.toString(vals[x])); } debug(""); } } } } pw.println(ans); br.close(); pw.close(); } public static void debug(Object o){ if(DEBUG){ System.out.println("~" + o); } } public static StringTokenizer getst(BufferedReader br) throws Exception{ return new StringTokenizer(br.readLine(), " "); } public static int nextInt(BufferedReader br) throws Exception{ return Integer.parseInt(br.readLine()); } public static int nextInt(StringTokenizer st) throws Exception{ return Integer.parseInt(st.nextToken()); } public static long nextLong(BufferedReader br) throws Exception{ return Long.parseLong(br.readLine()); } public static long nextLong(StringTokenizer st) throws Exception{ return Long.parseLong(st.nextToken()); } public static double nextDouble(BufferedReader br) throws Exception{ return Double.parseDouble(br.readLine()); } public static double nextDouble(StringTokenizer st) throws Exception{ return Double.parseDouble(st.nextToken()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
24a4213c3c7b81efa2797a2225c850af
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class D { BufferedReader in; StringTokenizer st; PrintWriter out; String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws Exception { return Integer.parseInt(next()); } long nextLong() throws Exception { return Long.parseLong(next()); } double nextDouble() throws Exception { return Double.parseDouble(next()); } void solve() throws Exception { int n = nextInt(), m = nextInt(); int c[][] = new int[n][m]; for (int i = 0; i < n; i++) { String s = next(); for (int j = 0; j < m; j++) { c[i][j] = (s.charAt(j) == 'W') ? -1 : 1; } } int ans = 0; while (true) { int maxi = -1, maxj = -1; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { if (c[i][j] != 0) { maxi = i; maxj = j; } } if (maxi == -1) { out.println(ans); return; } int v = c[maxi][maxj]; for (int i = 0; i <= maxi; i++) for (int j = 0; j <= maxj; j++) { c[i][j] -= v; } ans++; } } void run() { try { Locale.setDefault(Locale.US); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } public static void main(String[] args) { new D().run(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
60ee89cbfb2fe9d09f8e4202744a355a
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import java.util.InputMismatchException; public class Main { static String s[] = new String[200]; static int val[][] = new int[200][200]; public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); int n = in.nextInt(); int m = in.nextInt(); for (int i = 0; i < n; i++) { s[i] = in.next(); } int count = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { int tmp = (s[i].charAt(j) == 'W') ? 1 : -1; if (val[i][j] != tmp) { f(i, j, tmp); count++; } } } sopln(count); } static void f(int n, int m, int v) { int valToAdd = v - val[n][m]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { val[i][j] += valToAdd; } } } static void sopln() { System.out.println(); } static void sopln(Object o) { System.out.println(o); } static void sopln(String o) { System.out.println(o); } static void sop(Object o) { System.out.print(o); } static void sop(String o) { System.out.print(o); } private static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return nextString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } } class Pair<K, V> implements Serializable { private K key; public K getKey() { return key; } private V value; public V getValue() { return value; } public Pair(K key, V value) { this.key = key; this.value = value; } @Override public String toString() { return key + "=" + value; } @Override public int hashCode() { return key.hashCode() * 13 + (value == null ? 0 : value.hashCode()); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o instanceof Pair) { Pair pair = (Pair) o; if (key != null ? !key.equals(pair.key) : pair.key != null) { return false; } if (value != null ? !value.equals(pair.value) : pair.value != null) { return false; } return true; } return false; } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
2af7ea8251b5201ecfa55cc5b1a0b5df
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
// practice with rainboy import java.io.*; import java.util.*; public class CF549D extends PrintWriter { CF549D() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF549D o = new CF549D(); o.main(); o.flush(); } void main() { int n = sc.nextInt(); int m = sc.nextInt(); byte[][] cc = new byte[n][]; for (int i = 0; i < n; i++) { cc[i] = sc.next().getBytes(); for (int j = 0; j < m; j++) cc[i][j] = (byte) (cc[i][j] == 'W' ? 1 : -1); } int cnt = 0; for (int i = n - 1; i >= 0; i--) for (int j = m - 1; j >= 0; j--) { int c = 0; if (i + 1 < n) c += cc[i + 1][j]; if (j + 1 < m) c += cc[i][j + 1]; if (i + 1 < n && j + 1 < m) c -= cc[i + 1][j + 1]; if (c != cc[i][j]) cnt++; } println(cnt); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
168c27f5c09b2f4a14ca5c153a67f239
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
//package codeforces.looksery_cup_2015; import java.util.Scanner; /** * Created by shaolin on 4/28/17. */ public class B { static Scanner scanner; static int [][] grid; static int[][] feature; static int row, col; public static void main(String[] args) { scanner = new Scanner(System.in); row = scanner.nextInt(); col = scanner.nextInt(); grid = new int[row][col]; feature = new int[row][col]; for (int i = 0; i < row; i++) { String s = scanner.next(); for (int j = 0; j < col; j++) { grid[i][j] = 0; char c = s.charAt(j); if(c=='B') feature[i][j] = -1; else feature[i][j] = 1; } } int x = row-1, y = col-1; int count = 0; while(x>=0 && y>=0) { if(!isMatched(x,y)) { int value; value = feature[x][y] - grid[x][y]; fillWith(x, y, value); count++; } if(y>0) {y--;} else { x--; y = col-1; } // printGrid(); // System.out.println("-----------------"); } System.out.println(count); } private static void printGrid() { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { System.out.print(grid[i][j]+" "); } System.out.println(); } } public static boolean isMatched(int x, int y) { return grid[x][y] == feature[x][y]; } public static void fillWith(int x, int y, int value) { for (int i = 0; i <= x; i++) { for (int j = 0; j <= y; j++) { grid[i][j] += value; } } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
c3faa8de34ece6831d5c01009d28ac2d
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class D { void solve() throws IOException { in = new InputReader("__std"); out = new OutputWriter("__std"); int n = in.readInt(); int m = in.readInt(); char[][] p = new char[n][]; for (int i = 0; i < n; ++i) { p[i] = in.readToken().toCharArray(); } int cnt = 0; int[][] v = new int[n][m]; for (int i = n - 1; i >= 0; --i) { for (int j = m - 1; j >= 0; --j) { int val = (p[i][j] == 'W' ? 1 : -1) - v[i][j]; if (val != 0) { ++cnt; for (int ii = 0; ii <= i; ++ii) { for (int jj = 0; jj <= j; ++jj) { v[ii][jj] += val; } } } } } out.println(cnt); exit(); } void exit() { //System.err.println((System.currentTimeMillis() - startTime) + " ms"); out.close(); System.exit(0); } InputReader in; OutputWriter out; //long startTime = System.currentTimeMillis(); public static void main(String[] args) throws IOException { new D().solve(); } class InputReader { private InputStream stream; private byte[] buffer = new byte[1024]; private int pos, len; private int cur; private StringBuilder sb = new StringBuilder(32); InputReader(String name) throws IOException { if (name.equals("__std")) { stream = System.in; } else { stream = new FileInputStream(name); } cur = read(); } private int read() throws IOException { if (len == -1) { throw new EOFException(); } if (pos >= len) { pos = 0; len = stream.read(buffer); if (len == -1) return -1; } return buffer[pos++]; } private boolean whitespace() { return cur == ' ' || cur == '\t' || cur == '\r' || cur == '\n' || cur == -1; } char readChar() throws IOException { if (cur == -1) { throw new EOFException(); } char res = (char) cur; cur = read(); return res; } int readInt() throws IOException { if (cur == -1) { throw new EOFException(); } while (whitespace()) { cur = read(); } if (cur == -1) { throw new EOFException(); } int sign = 1; if (cur == '-') { sign = -1; cur = read(); } int res = 0; while (!whitespace()) { if (cur < '0' || cur > '9') { throw new NumberFormatException(); } res *= 10; res += cur - '0'; cur = read(); } return res * sign; } long readLong() throws IOException { if (cur == -1) { throw new EOFException(); } return Long.parseLong(readToken()); } double readDouble() throws IOException { if (cur == -1) { throw new EOFException(); } return Double.parseDouble(readToken()); } String readLine() throws IOException { if (cur == -1) { throw new EOFException(); } sb.setLength(0); while (cur != -1 && cur != '\r' && cur != '\n') { sb.append((char) cur); cur = read(); } if (cur == '\r') { cur = read(); } if (cur == '\n') { cur = read(); } return sb.toString(); } String readToken() throws IOException { if (cur == -1) { throw new EOFException(); } while (whitespace()) { cur = read(); } if (cur == -1) { throw new EOFException(); } sb.setLength(0); while (!whitespace()) { sb.append((char) cur); cur = read(); } return sb.toString(); } boolean eof() { return cur == -1; } } class OutputWriter { private PrintWriter writer; OutputWriter(String name) throws IOException { if (name.equals("__std")) { writer = new PrintWriter(System.out); } else { writer = new PrintWriter(name); } } void print(String format, Object ... args) { writer.print(new Formatter(Locale.US).format(format, args)); } void println(String format, Object ... args) { writer.println(new Formatter(Locale.US).format(format, args)); } void print(Object value) { writer.print(value); } void println(Object value) { writer.println(value); } void println() { writer.println(); } void close() { writer.close(); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
90c35005fcbd8088ac40c2f1fd38b927
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int R = nextInt(); int C = nextInt(); //Goal to make all the points zero int[][] map = new int[R][C]; for(int i = 0; i < R; i++){ String s = nextToken(); for(int j = 0; j < s.length(); j++){ if(s.charAt(j) == 'W') map[i][j] = 1; else map[i][j] = -1; } } // print2Int(map); int opCount = 0; for(int i = R-1; i >= 0; i--){ for(int j = C-1; j >= 0; j--){ if(map[i][j] != 0){ int add = -map[i][j]; opCount++; //now make change in map; for(int ii = 0; ii <= i; ii++){ for(int jj = 0; jj <= j; jj++){ map[ii][jj] += add; } } } } } // print2Int(map); out.println(opCount); } //----------------------------------------------------------- public static void main(String[] args) { new Main().run(); } public void debug(Object... arr){ System.out.println(Arrays.deepToString(arr)); } public void print1Int(int[] a){ for(int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } public void print2Int(int[][] a){ for(int i = 0; i < a.length; i++){ for(int j = 0; j < a[0].length; j++){ System.out.print(a[i][j] + " "); } System.out.println(); } } public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); tok = null; solve(); in.close(); out.close(); } catch (IOException e) { System.exit(0); } } public String nextToken() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } PrintWriter out; BufferedReader in; StringTokenizer tok; }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
bbce8ee24274c6958e6542229338e3ee
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.InputMismatchException; import java.util.ArrayList; import java.io.InputStream; import java.util.List; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Collections; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, PrintWriter out) { int R = in.nextInt(); int C = in.nextInt(); List<Point> points = new ArrayList<>(); for (int r = 0; r < R; r++) { String s = in.next(); for (int c = 0; c < C; c++) { points.add(new Point(r, c, s.charAt(c) == 'W' ? 1 : -1)); } } Collections.sort(points); int res = 0; int[][] b = new int[R][C]; for (Point p : points) { int d = p.v - b[p.r][p.c]; if (d != 0) { ++res; for (int r = 0; r <= p.r; r++) { for (int c = 0; c <= p.c; c++) { b[r][c] += d; } } } } out.println(res); } static class Point implements Comparable<Point> { final int r; final int c; final int v; public Point(int r, int c, int v) { this.r = r; this.c = c; this.v = v; } public int compareTo(Point o) { return o.r + o.c - r - c; } } } class InputReader { final InputStream is; final byte[] buf = new byte[1024]; int pos; int size; public InputReader(InputStream is) { this.is = is; } public int nextInt() { int c = read(); while (isWhitespace(c)) c = read(); int sign = 1; if (c == '-') { sign = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = read(); } while (!isWhitespace(c)); return res * sign; } public String next() { int c = read(); while (isWhitespace(c)) c = read(); StringBuilder sb = new StringBuilder(); do { sb.append((char) c); c = read(); } while (!isWhitespace(c)); return sb.toString(); } int read() { if (size == -1) throw new InputMismatchException(); if (pos >= size) { pos = 0; try { size = is.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (size <= 0) return -1; } return buf[pos++] & 255; } static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
cf26946787df5ccee7b749a95a8e6c3e
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Reader in = new Reader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, Reader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] a = new char[n][m]; for (int i = 0; i < n; i++) { a[i] = in.next().toCharArray(); } int[][] b = new int[n][m]; int ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { if (a[i][j] == 'W' && b[i][j] != 1 || a[i][j] == 'B' && b[i][j] != -1) { ans++; int q = a[i][j] == 'W' ? 1 - b[i][j] : -1 - b[i][j]; for (int ii = 0; ii <= i; ii++) { for (int jj = 0; jj <= j; jj++) { b[ii][jj] += q; } } } } } out.println(ans); } } class Reader { private BufferedReader in; private StringTokenizer st; public Reader(InputStream is) { in = new BufferedReader(new InputStreamReader(is)); } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } catch (IOException e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
0e9fd89d4e0728cdae617397b8950288
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main extends PrintWriter { final Random rand = new Random(31); final int inf = (int) 1e9; final long linf = (long) 1e18; final static String IO_NAME = "_std"; int[][] t; int n, m; int sum(int x, int y) { int res = 0; for (int i = 0; i <= x; i++) { for (int j = 0; j <= y; j++) { res += t[i][j]; } } return res; } void inc(int x, int y, int delta) { for (int i = 0; i <= x; i++) { for (int j = 0; j <= y; j++) { t[i][j] += delta; } } } void solve() throws IOException { n = nextInt(); m = nextInt(); t = new int[n][m]; char[][] a = new char[n][]; for (int i = 0; i < n; i++) { a[i] = next().toCharArray(); } int ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { int x = t[i][j]; int y = a[i][j] == 'B' ? -1 : 1; if (x != y) { inc(i, j, y - x); ans++; } } } println(ans); } void run() { try { solve(); } catch (Exception e) { e.printStackTrace(); System.exit(abs(-1)); } finally { close(); } } BufferedReader in; StringTokenizer stok; String next() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = in.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } int[] nextIntArray(int len) throws IOException { int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = nextInt(); } return res; } void shuffle(int[] a) { for (int i = 1; i < a.length; i++) { int x = rand.nextInt(i + 1); int _ = a[i]; a[i] = a[x]; a[x] = _; } } boolean nextPerm(int[] p) { for (int a = p.length - 2; a >= 0; --a) if (p[a] < p[a + 1]) for (int b = p.length - 1; ; --b) if (p[b] > p[a]) { int t = p[a]; p[a] = p[b]; p[b] = t; for (++a, b = p.length - 1; a < b; ++a, --b) { t = p[a]; p[a] = p[b]; p[b] = t; } return true; } return false; } <T> List<T>[] createAdjacencyList(int countVertex) { List<T>[] res = new List[countVertex]; for (int i = 0; i < countVertex; i++) { res[i] = new ArrayList<T>(); } return res; } class Pair<A extends Comparable<A>, B extends Comparable<B>> implements Comparable<Pair<A, B>> { A a; B b; public Pair(A a, B b) { this.a = a; this.b = b; } @Override public int compareTo(Pair<A, B> o) { int aa = a.compareTo(o.a); return aa == 0 ? b.compareTo(o.b) : aa; } } Main(String filename) throws IOException { super(getOutputStream(filename)); in = new BufferedReader(new InputStreamReader(getInputStream(filename))); } public static void main(String[] args) throws IOException { new Main(IO_NAME).run(); } static InputStream getInputStream(String filename) throws IOException { if ("_std".equals(filename)) { return System.in; } if ("_iotxt".equals(filename)) { return new FileInputStream("input.txt"); } return new FileInputStream(filename + ".in"); } static OutputStream getOutputStream(String filename) throws IOException { if ("_std".equals(filename)) { return System.out; } if ("_iotxt".equals(filename)) { return new FileOutputStream("output.txt"); } return new FileOutputStream(filename + ".out"); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
8677d11abc2da40796dd5dfb87f7bcee
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(), m = sc.nextInt(); int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) { char[] g = sc.next().toCharArray(); for (int j = 0; j < m; j++) arr[i][j] = g[j] == 'W' ? 1 : -1; } int res = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { if (arr[i][j] != 0) { int tmp = arr[i][j]; res++; for (int k = i; k >= 0; k--) for (int z = j; z >= 0; z--) { arr[k][z] += -tmp; } } } } out.println(res); out.flush(); out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
6cb27dd0dc996997049bef81382b09c3
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.InputStream; import java.util.NoSuchElementException; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top * @author Egor Kulikov ([email protected]) */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, OutputWriter out) { int rowCount = in.readInt(); int columnCount = in.readInt(); char[][] table = IOUtils.readTable(in, rowCount, columnCount); int answer = 0; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { if (i == rowCount - 1) { if (j == columnCount - 1) { answer++; } else { if (table[i][j] != table[i][j + 1]) { answer++; } } } else { if (j == columnCount - 1) { if (table[i][j] != table[i + 1][j]) { answer++; } } else { if (table[i][j] == table[i + 1][j]) { if (table[i][j + 1] != table[i + 1][j + 1]) { answer++; } } else { if (table[i][j] != table[i][j + 1] || table[i + 1][j] != table[i + 1][j + 1]) { answer++; } } } } } } out.printLine(answer); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } class IOUtils { public static char[] readCharArray(InputReader in, int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) array[i] = in.readCharacter(); return array; } public static char[][] readTable(InputReader in, int rowCount, int columnCount) { char[][] table = new char[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readCharArray(in, columnCount); return table; } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
5f4614580f957be2f41577f1af06d049
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); d549 solver = new d549(); solver.solve(1, in, out); out.close(); } static class d549 { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] field = new char[n][]; for (int i = 0; i < n; i++) { field[i] = in.next().toCharArray(); } ArrayList<op> ops = new ArrayList<>(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (field[i][j] == 'W') { op o1 = new op(); o1.x = j; o1.y = i; o1.k = 1; ops.add(o1); op o2 = new op(); o2.x = j - 1; o2.y = i; o2.k = -1; ops.add(o2); op o3 = new op(); o3.x = j; o3.y = i - 1; o3.k = -1; ops.add(o3); op o4 = new op(); o4.x = j - 1; o4.y = i - 1; o4.k = 1; ops.add(o4); } else { op o1 = new op(); o1.x = j; o1.y = i; o1.k = -1; ops.add(o1); op o2 = new op(); o2.x = j - 1; o2.y = i; o2.k = 1; ops.add(o2); op o3 = new op(); o3.x = j; o3.y = i - 1; o3.k = 1; ops.add(o3); op o4 = new op(); o4.x = j - 1; o4.y = i - 1; o4.k = -1; ops.add(o4); } } } ops.sort((op f, op s) -> (f.y == s.y) ? (f.x - s.x) : (f.y - s.y)); ArrayList<op> newOps = new ArrayList<>(); op cur = new op(); cur.x = ops.get(0).x; cur.y = ops.get(0).y; cur.k = 0; for (op o : ops) { if (cur.x == o.x && cur.y == o.y) { cur.k += o.k; } else { if (cur.x >= 0 && cur.y >= 0 && cur.k != 0) { newOps.add(cur); } cur = new op(); cur.x = o.x; cur.y = o.y; cur.k = o.k; } } if (cur.k != 0) { newOps.add(cur); } out.println(newOps.size()); } class op { int x; int y; int k; } } static class InputReader { private BufferedReader reader; private StringTokenizer stt; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { return null; } } public String next() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
ee13c0af17393ed33ee03dba6d5ed1bd
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); d549 solver = new d549(); solver.solve(1, in, out); out.close(); } static class d549 { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] field = new char[n][]; for (int i = 0; i < n; i++) { field[i] = in.next().toCharArray(); } int[][] coef = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (field[i][j] == 'W') { coef[i][j]++; if (j > 0) coef[i][j - 1]--; if (i > 0) coef[i - 1][j]--; if (j > 0 && i > 0) coef[i - 1][j - 1]++; } else { coef[i][j]--; if (j > 0) coef[i][j - 1]++; if (i > 0) coef[i - 1][j]++; if (j > 0 && i > 0) coef[i - 1][j - 1]--; } } } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (coef[i][j] != 0) { ans++; } } } out.println(ans); } } static class InputReader { private BufferedReader reader; private StringTokenizer stt; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { return null; } } public String next() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
3ecca353942f1f833f06fc988ed0c1f6
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class D { public static void main(String[] args) throws Exception { FinalScanner sc = new FinalScanner(); PrintWriter out = new PrintWriter(System.out); int H = sc.nextInt(); int W = sc.nextInt(); char[][] grid = new char[H][W]; int[][] magic = new int[H][W]; for(int a=0;a<H;a++)grid[a]=sc.next().toCharArray(); int count = 0; for(int a=H-1;a>=0;a--){ for(int b=W-1;b>=0;b--){ int target = 0; if(grid[a][b]=='W')target =1; if(grid[a][b]=='B')target = -1; if(magic[a][b]!=target){ count++; int change = target-magic[a][b]; for(int c=0;c<=a;c++){ for(int d=0;d<=b;d++){ magic[c][d]+=change; } } // System.out.println(a+" "+b); // print(magic); } } } out.println(count); out.close(); } private static void print(int[][] magic) { for(int a=0;a<magic.length;a++){ System.out.println(Arrays.toString(magic[a])); } System.out.println(); } static class FinalScanner{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FinalScanner(){ stream = System.in; //stream = new FileInputStream(new File("dec.in")); } int read(){ if(numChars==-1) throw new InputMismatchException(); if(curChar>=numChars){ curChar = 0; try{ numChars = stream.read(buf); } catch (IOException e){ throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c){ return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1; } boolean isEndline(int c){ return c=='\n'||c=='\r'||c==-1; } int nextInt(){ return Integer.parseInt(next()); } int[] nextInt(int v){ int[] temp = new int[v]; for(int a=0;a<v;a++)temp[a]=nextInt(); return temp; } long nextLong(){ return Long.parseLong(next()); } long[] nextLong(int v){ long[] temp = new long[v]; for(int a=0;a<v;a++)temp[a]=nextLong(); return temp; } double nextDouble(){ return Double.parseDouble(next()); } double[] nextDouble(int v){ double[] temp = new double[v]; for(int a=0;a<v;a++)temp[a]=nextDouble(); return temp; } String next(){ int c = read(); while(isSpaceChar(c)) c=read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c=read(); } while(!isSpaceChar(c)); return res.toString(); } String[] next(int v){ String[] temp = new String[v]; for(int a=0;a<v;a++)temp[a]=next(); return temp; } String nextLine(){ int c = read(); while(isEndline(c)) c=read(); StringBuilder res = new StringBuilder(); do{ res.appendCodePoint(c); c = read(); }while(!isEndline(c)); return res.toString(); } String[] nextLine(int v){ String[] temp = new String[v]; for(int a=0;a<v;a++)temp[a]=nextLine(); return temp; } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
8c55a2d8198b1ecb87e5d0c41a69f6d5
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.InputStream; import java.util.NoSuchElementException; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, OutputWriter out) { int n=in.readInt(), m=in.readInt(); char[][] table=IOUtils.readTable(in, n, m); int[][] arr=new int[n][m]; int ret=0; for (int i=n-1; i>=0; i--) for (int j=m-1; j>=0; j--) { int v=table[i][j]=='W'?-1:1; if (arr[i][j]!=v) { ret++; v-=arr[i][j]; for (int k=0; k<=i; k++) for (int l=0; l<=j; l++) arr[k][l]+=v; } } out.printLine(ret); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } class IOUtils { public static char[] readCharArray(InputReader in, int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) array[i] = in.readCharacter(); return array; } public static char[][] readTable(InputReader in, int rowCount, int columnCount) { char[][] table = new char[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readCharArray(in, columnCount); return table; } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
a83073823c7d497da7efe7199741813d
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.util.*; import java.io.*; public class PrD { public static void main(String[] args) throws IOException { new PrD().run(); } FastScanner in; PrintWriter out; void run() throws IOException { in = new FastScanner(System.in); out = new PrintWriter(System.out, true); solve(); out.close(); } void solve() throws IOException { int n = in.nextInt(); int m = in.nextInt(); String matrix[] = new String[n]; for (int i = 0; i < n; i++) matrix[i] = in.next(); int cnt = 1; for (int i = 0; i < n - 1; i++) if (matrix[i].charAt(m - 1) != matrix[i + 1].charAt(m - 1)) cnt++; for (int i = 0; i < m - 1; i++) if (matrix[n - 1].charAt(i) != matrix[n - 1].charAt(i + 1)) cnt++; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m - 1; j++) { char a = matrix[i].charAt(j); char b = matrix[i].charAt(j + 1); char c = matrix[i + 1].charAt(j); char d = matrix[i + 1].charAt(j + 1); if (a == b && a == c && a != d) cnt++; if (a != b && a != c) cnt++; if (a == b && a != c && a == d || a != b && a == c && a == d) cnt++; } } out.println(cnt); } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = null; } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { if (st == null || !st.hasMoreTokens()) return br.readLine(); StringBuilder result = new StringBuilder(st.nextToken()); while (st.hasMoreTokens()) { result.append(" "); result.append(st.nextToken()); } return result.toString(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
68238fd76472e91c647cc54db68e2273
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] c = new char[n][]; for (int i = 0; i < n; i++) { c[i] = in.next().toCharArray(); } int w = 1; int b = -1; int[][] p = new int[n][m]; int ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { if (c[i][j] == 'W' && p[i][j] != 1) { for (int k = 0; k <= i; k++) { for (int l = 0; l <= j; l++) { if (p[i][j] > 1) { p[k][l] -= p[i][j] - 1; } else { p[k][l] += 1 - p[i][j]; } } } ans++; } if (c[i][j] == 'B' && p[i][j] != -1) { for (int k = 0; k <= i; k++) { for (int l = 0; l <= j; l++) { if (p[i][j] > -1) { p[k][l] -= p[i][j] + 1; } else { p[k][l] += -1 - p[i][j]; } } } ans++; } } } out.println(ans); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
f35bc60cf505b658185a896df9f8bcc6
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import static java.lang.Double.parseDouble; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class D { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; static void solve() throws Exception { int n = nextInt(); int m = nextInt(); int v[][] = new int[n][m]; for (int i = 0; i < n; i++) { String l = next(); for (int j = 0; j < m; j++) { v[i][j] = l.charAt(j) == 'W' ? 1 : -1; } } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m; j++) { v[i][j] -= v[i + 1][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m - 1; j++) { v[i][j] -= v[i][j + 1]; } } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (v[i][j] != 0) { ++ans; } } } out.print(ans); } static int nextInt() throws IOException { return parseInt(next()); } static long nextLong() throws IOException { return parseLong(next()); } static double nextDouble() throws IOException { return parseDouble(next()); } static String next() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } public static void main(String[] args) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); exit(1); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
082accf89fc3bde1e4712eebdb943c10
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class d1 { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); String s[] = new String[n]; for (int i = 0; i < n; i++) { s[i] = in.next(); } long ans = 0; int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { Arrays.fill(a[i], 0); } for (int i = n - 1; i > -1; i--) { for (int j = m - 1; j > -1; j--) { if ((s[i].charAt(j) == 'W' && a[i][j] != 1) || (s[i].charAt(j) == 'B' && a[i][j] != -1)){ ans++; int need = 0; if (s[i].charAt(j) == 'B'){ need = -1; } else{ need = 1; } for (int j2 = 0; j2 <= i; j2++) { for (int k = 0; k <= j; k++) { a[j2][k] += need - a[i][j]; } } } } } out.println(ans); out.close(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
f98ec2585643d5ed6a039acaefcf8830
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class D { void solve() throws IOException { int n = nextInt(); int m = nextInt(); int[][] mustGet = new int[n][m]; int[][] cur = new int[n][m]; for (int i = 0; i < n; i++) { String str = next(); for (int j = 0; j < str.length(); j++) { mustGet[i][j] = (str.charAt(j) == 'B') ? -1 : 1; } } int cnt = 0; for (int i = n-1; i>=0; i--) { for (int j = m-1; j>=0; j--) { if (cur[i][j] != mustGet[i][j]) { cnt++; int diff = mustGet[i][j] - cur[i][j]; for (int i1=0; i1 <= i; i1++) { for (int j1 = 0; j1 <= j; j1++) { cur[i1][j1] += diff; } } } } } out.println(cnt); } void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } public static void main(String[] args) throws IOException { new D().run(); } BufferedReader in; PrintWriter out; StringTokenizer st; String next() throws IOException { while (st == null || !st.hasMoreTokens()) { String temp = in.readLine(); if (temp == null) { return null; } st = new StringTokenizer(temp); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
0ac98df01608015286b6d008fc89c96f
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class Main { private FastScanner in; private PrintWriter out; public static void main(String[] args) { new Main().submit(); } public Main() { if (true) { in = new FastScanner(System.in); out = new PrintWriter(System.out); } else { try { in = new FastScanner(new File("input.txt")); out = new PrintWriter(new File("output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } } private void submit() { if (true) { read(); solve(); out.close(); } else { stress(); } } private void printTest() { } private void stressError() { printTest(); System.exit(0); } private void stupid() { } private void stress() { } private void read() { } private void solve() { int n = in.nextInt(); int m = in.nextInt(); int[][] a = new int[n][m]; int[][] b = new int[n][m]; for (int i = 0; i < n; i++) { String s = in.next(); for (int j = 0; j < s.length(); j++) { if (s.charAt(j) == 'W') { a[i][j] = 1; } else { a[i][j] = -1; } } } // System.arraycopy(a, 0, b, 0, n); int answer = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { if (a[i][j] != b[i][j]) { int c = b[i][j]; int x = a[i][j]; answer++; for (int k = i; k >= 0; k--) { for (int l = j; l >= 0; l--) { b[k][l] += x - c; } } } } } out.print(answer); } } class FastScanner { private BufferedReader reader; private StringTokenizer tokenizer; public FastScanner(File file) { try { reader = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
19c1bde22e4eda2e128d6b02ad680a5b
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Vadim Semenov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(final int testNumber, final InputReader in, final PrintWriter out) { int rows = in.nextInt(); int columns = in.nextInt(); char[][] table = new char[rows][]; for (int i = 0; i < rows; ++i) { table[i] = in.next().toCharArray(); } boolean[][] bad = new boolean[rows + 1][columns + 1]; bad[rows][columns] = true; for (int i = 0; i < rows; ++i) { for (int j = 0; j < columns; ++j) { int cnt = 0; if (i + 1 == rows || table[i][j] != table[i + 1][j]) ++cnt; if (j + 1 == columns || table[i][j] != table[i][j + 1]) ++cnt; if (cnt == 0 && table[i][j] != table[i + 1][j + 1]) cnt = 2; if (cnt == 1 && i + 1 < rows && j + 1 < columns && table[i][j] == table[i + 1][j + 1]) ++cnt; if (cnt == 2) bad[i + 1][j + 1] = true; } } int answer = 0; for (boolean[] b : bad) for (boolean bb : b) { if (bb) ++answer; } out.println(answer); } } class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public int nextInt() { return Integer.parseInt(next()); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } public String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
cfa47dab0d5252a1ad656ac2a36464d5
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; import java.io.InputStream; import java.io.InputStreamReader; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { char grid[][]; int feature[][]; public void solve(int testNumber, InputReader in, PrintWriter out) { int N = in.nextInt(); int M = in.nextInt(); grid = new char[N][M]; feature = new int[N][M]; for (int i = 0; i < N; i++) { char row[] = in.next().toCharArray(); for (int j = 0; j < M; j++) { grid[i][j] = row[j]; } } int ans = 0; for (int i = N - 1; i >= 0; i--) { for (int j = M - 1; j >= 0; j--) { if (grid[i][j] == 'W') { if (feature[i][j] == 1) continue; int x = 1 - feature[i][j]; apply(i, j, x); ans++; } else { if (feature[i][j] == -1) continue; int x = -1 - feature[i][j]; apply(i, j, x); ans++; } } } out.println(ans); } private void apply(int i, int j, int x) { for (int a = 0; a <= i; a++) { for (int b = 0; b <= j; b++) { feature[a][b] += x; } } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
4d31f04154da5f78a56933c7a711ceee
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } static class TaskD { public void solve(int testNumber, InputReader in, OutputWriter out) { int rows = in.readInt(), cols = in.readInt(); int[][] tab = new int[rows][cols]; for (int row = 0; row < rows; row++) { String s = in.next(); for (int col = 0; col < cols; col++) { if (s.charAt(col) == 'B') tab[row][col] = 1; else tab[row][col] = -1; } } int res = 0; for (int row = rows - 1; row >= 0; row--) { for (int col = cols - 1; col >= 0; col--) { if (tab[row][col] != 0) { int sub = tab[row][col]; for (int r = 0; r <= row; r++) { for (int c = 0; c <= col; c++) { tab[r][c] -= sub; } } res++; } } } out.printLine(res); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
c983690711dc730a2a961fa4e8680302
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.Reader; import java.util.InputMismatchException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top * @author Niyaz Nigmatullin */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, FastScanner in, FastPrinter out) { int n = in.nextInt(); int m = in.nextInt(); char[][] c = in.readCharacterFieldTokens(n, m); long[][] ans = new long[n][m]; int ansC = 0; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { long need = c[i][j] == 'W' ? 1 : -1; need = need - ans[i][j]; if (need != 0) { for (int x = i; x >= 0; x--) for (int y = j; y >= 0; y--) { ans[x][y] += need; } ++ansC; } } } out.println(ansC); } } class FastScanner extends BufferedReader { public FastScanner(InputStream is) { super(new InputStreamReader(is)); } public int read() { try { int ret = super.read(); // if (isEOF && ret < 0) { // throw new InputMismatchException(); // } // isEOF = ret == -1; return ret; } catch (IOException e) { throw new InputMismatchException(); } } public String next() { StringBuilder sb = new StringBuilder(); int c = read(); while (isWhiteSpace(c)) { c = read(); } if (c < 0) { return null; } while (c >= 0 && !isWhiteSpace(c)) { sb.appendCodePoint(c); c = read(); } return sb.toString(); } static boolean isWhiteSpace(int c) { return c >= 0 && c <= 32; } public int nextInt() { int c = read(); while (isWhiteSpace(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int ret = 0; while (c >= 0 && !isWhiteSpace(c)) { if (c < '0' || c > '9') { throw new NumberFormatException("digit expected " + (char) c + " found"); } ret = ret * 10 + c - '0'; c = read(); } return ret * sgn; } public String readLine() { try { return super.readLine(); } catch (IOException e) { return null; } } public char[][] readCharacterFieldTokens(int n, int m) { char[][] ret = new char[n][]; for (int i = 0; i < n; i++) { ret[i] = next().toCharArray(); if (ret[i].length != m) { throw new AssertionError("length expected " + m + ", found " + ret[i].length); } } return ret; } } class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
613f0f687efa7eb42a88dbc50aaf0a63
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
//package codeforcespractice; import java.io.*; import java.util.*; public class HaarFeatures { public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); int m=Integer.parseInt(st.nextToken()); int[][] a=new int[n][m]; int[][] b=new int[n][m]; for(int i=0;i<n;i++) { char[] ar=br.readLine().toCharArray(); for(int j=0;j<m;j++) { if(ar[j]=='W') { a[i][j]=1; } else { a[i][j]=-1; } } } int ans=0; for(int i=n-1;i>=0;i--) { for(int j=m-1;j>=0;j--) { if(b[i][j]!=a[i][j]) { ans++; int x=a[i][j]-b[i][j]; for(int d=0;d<=i;d++) { for(int k=0;k<=j;k++) { b[d][k]+=x; } } } } } System.out.println(ans); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
5e1c9b00615db05ce5fdb10797d97f47
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.awt.Point; import java.io.*; import java.util.*; public class D { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/T"; FastScanner in; PrintWriter out; public void solve() { int n = in.nextInt(), m = in.nextInt(); int[][] map = new int[n][m]; for (int i = 0; i < n; i++) { String s = in.next(); for (int j = 0; j < m; j++) { map[i][j] = s.charAt(j) == 'W' ? 1 : -1; } } int res = 0; Queue<Point> q = new LinkedList<Point>(); q.add(new Point(m - 1, n - 1)); int[][] a = new int[n][m]; boolean[][] vis = new boolean[n][m]; while (!q.isEmpty()) { Point p = q.poll(); int x = p.x, y = p.y; if (vis[y][x]) continue; vis[y][x] = true; if (a[y][x] != map[y][x]) { res++; int dif = map[y][x] - a[y][x]; for (int i = 0; i <= y; i++) { for (int j = 0; j <= x; j++) { a[i][j] += dif; } } } if (y > 0) { q.add(new Point(x, y - 1)); } if (x > 0) { q.add(new Point(x - 1, y)); } } System.out.println(res); } public void run() { if (__FILE_DEBUG_FLAG__ == __t__) { try { is = new FileInputStream(__DEBUG_FILE_NAME__); } catch (FileNotFoundException e) { // TODO θ‡ͺε‹•η”Ÿζˆγ•γ‚ŒγŸ catch ブロック e.printStackTrace(); } System.out.println("FILE_INPUT!"); } else { is = System.in; } in = new FastScanner(is); out = new PrintWriter(System.out); solve(); } public static void main(String[] args) { new D().run(); } public void mapDebug(int[][] a) { System.out.println("--------map display---------"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.printf("%3d ", a[i][j]); } System.out.println(); } System.out.println("----------------------------"); System.out.println(); } public void debug(Object... obj) { System.out.println(Arrays.deepToString(obj)); } class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; //stream = new FileInputStream(new File("dec.in")); } int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } int[][] nextIntMap(int n, int m) { int[][] map = new int[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextIntArray(m); } return map; } long nextLong() { return Long.parseLong(next()); } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } long[][] nextLongMap(int n, int m) { long[][] map = new long[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextLongArray(m); } return map; } double nextDouble() { return Double.parseDouble(next()); } double[] nextDoubleArray(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } double[][] nextDoubleMap(int n, int m) { double[][] map = new double[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextDoubleArray(m); } return map; } String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) array[i] = next(); return array; } String nextLine() { int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
4d6235a43b7273623373d0eb7572929f
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.*; import java.util.*; public class D { FastScanner in; PrintWriter out; void solve() { int n = in.nextInt(), m = in.nextInt(); int[][] cnt = new int[n][m]; for (int i = 0; i < n; i++) { String s = in.nextToken(); for (int j = 0; j < m; j++) { if (s.charAt(j) == 'W') { cnt[i][j] = 1; } else { cnt[i][j] = -1; } } } int ans = 0; while (true) { int ni = -1, nj = -1; for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { if (cnt[i][j] != 0) { ni = i; nj = j; break; } } if (ni != -1) { break; } } if (ni == -1) { break; } ans++; int val = cnt[ni][nj]; for (int i = 0; i <= ni; i++) { for (int j = 0; j <= nj; j++) { cnt[i][j] -= val; } } } out.println(ans); } void run() { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { e.printStackTrace(); } } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } public static void main(String[] args) { new D().run(); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
81c454134fb042f9824b1251b784ea8c
train_001.jsonl
1433595600
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
256 megabytes
import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.InputStream; import java.util.NoSuchElementException; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** * Built using CHelper plug-in * Actual solution is at the top * @author Stanislav Pak */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskD solver = new TaskD(); solver.solve(1, in, out); out.close(); } } class TaskD { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); int m = in.readInt(); char[][] a = new char[n][]; for (int i = 0;i < n; ++i) { a[i] = in.readString().toCharArray(); } long[][] s = new long[n][m]; int ans = 0; for (int i = n - 1; i >= 0; --i) { for (int j = m - 1; j >= 0; --j) { long c = 0; if (a[i][j] == 'B') { if (s[i][j] != 1) { c = 1 - s[i][j]; } } else { if (s[i][j] != -1) { c = -1 - s[i][j]; } } if (c != 0) { for (int x = 0; x <= i; ++x) for (int y = 0; y <= j; ++y) { s[x][y] += c; } ++ans; } } } out.printLine(ans); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } }
Java
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
1 second
["2", "4", "3", "4"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
Java 8
standard input
[ "implementation", "greedy" ]
ce6b65ca755d2d860fb76688b3d775db
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
1,900
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
standard output
PASSED
693f90a465ceacfc22538332202abd56
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.InputMismatchException; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { String str=in.readLine(); int count[]=new int[27]; for (int i=0;i<str.length();i++) count[str.charAt(i)-'a']++; int odd=0; for (int i=0;i<count.length;i++) if(count[i]%2==1) odd++; if(odd<=1) out.println("First"); else if(odd%2==1) out.println("First"); else out.println("Second"); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
73d23f19e76111ceeb08f977ba2fb334
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.HashMap; import java.util.Scanner; import java.util.Vector; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author KHALED */ public class LittleGirlandGame { public static void main(String[] args) { Scanner scan=new Scanner(System.in); String s=scan.next(); Vector<Character>vec=new Vector<Character>(); for (int i = 97; i <= 122; i++) { vec.add((char)i); } Vector<Character>str=new Vector<Character>(); for (int i = 0; i < s.length(); i++) { str.add(s.charAt(i)); } int play=0; while(str.size()!=0) { play++; int[]arr=new int[26]; for (int i = 0; i < str.size(); i++) { arr[vec.indexOf(str.get(i))]++; } int odd=0; int index=0; char c='l'; for (int i = 0; i < 26; i++) { if(arr[i]%2==1) { odd++; index=i; c=(char)vec.get(index); } } if(odd>1) { int dex=str.indexOf(c); str.remove(dex); } else { if(play%2==1) System.out.println("First"); else System.out.println("Second"); return; } } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
7642c57b96c7d6fea91c25e14b32a01d
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.IOException; import java.io.OutputStreamWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Nguyen Trung Hieu - [email protected] */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { char[] words = in.readString().toCharArray(); Arrays.sort(words); int[] letterCount = new int[200]; for (char c : words) letterCount[c]++; int le = 0; for (char c = 'a'; c <= 'z'; c++) { if (letterCount[c] % 2 == 1) le++; } if (le % 2 == 1 || le == 0) out.printLine("First"); else out.printLine("Second"); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
ae77a5f7e9ca4d3ebbfb073062bede20
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.*; public class lgg169 { public static void main(String ar[]) { Scanner obj=new Scanner(System.in); String s=obj.nextLine(); int a[]=new int[26]; Arrays.fill(a,0); for(int i=0;i<s.length();i++) a[s.charAt(i)-97]++; int count=0; for(int i=0;i<26;i++) { if(a[i]%2!=0) count+=1; } if(count<=1) System.out.println("First"); else if(count%2!=0) System.out.println("First"); else System.out.println("Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
89eaf5f7e21b74bf4ada4bf15d03d20e
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); boolean isPalindrome; Map<Character, Integer> counts = new HashMap<Character, Integer>(); for (char c : s.toCharArray()) { if (counts.containsKey(c)) { counts.put(c, counts.get(c) + 1); } else { counts.put(c, 1); } } int count = 0; for (int i : counts.values()) { count += i % 2; } isPalindrome = count <= 1; System.out.println(isPalindrome || s.length() % 2 == 1 ? "First" : "Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
40cc1a870e55eb44b03379274e35bc33
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); boolean isPalindrome; int counts[] = new int[26]; for (char c : s.toCharArray()) { counts[c - 'a']++; } int count = 0; for (int i : counts) { count += i % 2; } isPalindrome = count <= 1; System.out.println(isPalindrome || s.length() % 2 == 1 ? "First" : "Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
86c87142981482bc195aa62be061906c
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B276 { static FastScanner in; static FastPrinter out; public static void main(String[] args) throws IOException { in = new FastScanner(System.in); out = new FastPrinter(System.out); char[] arr = in.next().toCharArray(); int[] cnt = new int[26]; for (char c : arr) { cnt[(int) (c - 'a')]++; } int cntOdd = 0; for (int i : cnt) cntOdd += i % 2; if (cntOdd <= 1) { out.println("First"); } else if (cntOdd % 2 == 0) { out.println("Second"); } else { out.println("First"); } out.close(); } static class FastPrinter extends PrintWriter { public FastPrinter(File f) throws IOException { super(new BufferedWriter(new FileWriter(f))); } public FastPrinter(OutputStream out) throws IOException { super(new BufferedWriter(new OutputStreamWriter(out))); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } 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 String next() throws IOException { if (st.hasMoreTokens()) return st.nextToken(); st = new StringTokenizer(br.readLine()); return next(); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
66be412a792db0ae8105644992a3f253
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Task task = new Task(); task.getData(); task.solve(); task.printAnswer(); } } class Task { String data; StringBuilder answer = new StringBuilder(); public void getData() { Scanner console = new Scanner(System.in); data = console.next(); console.close(); } public void solve() { int[] alphaOccurrence = new int[26]; for (int i = 0; i < data.length(); ++i) { ++alphaOccurrence[data.charAt(i) - 'a']; } int countOddAlpha = 0; for (int x : alphaOccurrence) { countOddAlpha += x % 2; } if (countOddAlpha == 0 || countOddAlpha % 2 == 1) { answer.append("First"); return; } else { answer.append("Second"); } } public void printAnswer() { System.out.print(answer); } } class Pair<T> { T left; T right; Pair(T left, T right) { this.left = left; this.right = right; } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
0dd2bc33b0887c86ee3d0b6df3a11192
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.*; //PrintWriter import java.math.*; //BigInteger, BigDecimal import java.util.*; //StringTokenizer, ArrayList public class R169_Div2_B //Name: Little Girl and Game { FastReader in; PrintWriter out; public static void main(String[] args) { new R169_Div2_B().run(); } void run() { in = new FastReader(System.in); out = new PrintWriter(System.out); solve(); out.close(); } void solve() { String s = in.next(); int n = s.length(); int[] a = new int[26]; for (int i = 0; i < n; i++) a[s.charAt(i) -'a']++; int odd = 0; for (int i = 0; i < 26; i++) if (a[i] > 0) if (a[i] % 2 == 1) odd++; if (odd % 2 == 1 || odd == 0) out.println("First"); else out.println("Second"); } //----------------------------------------------------- void runWithFiles() { in = new FastReader(new File("input.txt")); try { out = new PrintWriter(new File("output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } solve(); out.close(); } class FastReader { BufferedReader br; StringTokenizer tokenizer; public FastReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public FastReader(File f) { try { br = new BufferedReader(new FileReader(f)); tokenizer = null; } catch (FileNotFoundException e) { e.printStackTrace(); } } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) try { tokenizer = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } return tokenizer.nextToken(); } public String nextLine() { try { return br.readLine(); } catch(Exception e) { throw(new RuntimeException()); } } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(next()); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
1d708d8d72c17d943caf52f75c4f3dd5
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class B { static class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String nextLine() { try { return br.readLine(); } catch(Exception e) { throw(new RuntimeException()); } } public String next() { while(!st.hasMoreTokens()) { String l = nextLine(); if(l == null) return null; st = new StringTokenizer(l); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] res = new int[n]; for(int i = 0; i < res.length; i++) res[i] = nextInt(); return res; } public long[] nextLongArray(int n) { long[] res = new long[n]; for(int i = 0; i < res.length; i++) res[i] = nextLong(); return res; } public double[] nextDoubleArray(int n) { double[] res = new double[n]; for(int i = 0; i < res.length; i++) res[i] = nextLong(); return res; } public void sortIntArray(int[] array) { Integer[] vals = new Integer[array.length]; for(int i = 0; i < array.length; i++) vals[i] = array[i]; Arrays.sort(vals); for(int i = 0; i < array.length; i++) array[i] = vals[i]; } public void sortLongArray(long[] array) { Long[] vals = new Long[array.length]; for(int i = 0; i < array.length; i++) vals[i] = array[i]; Arrays.sort(vals); for(int i = 0; i < array.length; i++) array[i] = vals[i]; } public void sortDoubleArray(double[] array) { Double[] vals = new Double[array.length]; for(int i = 0; i < array.length; i++) vals[i] = array[i]; Arrays.sort(vals); for(int i = 0; i < array.length; i++) array[i] = vals[i]; } } public static void main(String[] args) { Scanner sc = new Scanner(); int[] cuantos = new int[26]; for(char c : sc.next().toCharArray()) cuantos[c - 'a']++; int paridad = 0; for(int i = 0; i < 26; i++) paridad += cuantos[i] & 1; if(((paridad & 1) == 1) || (paridad == 0)) System.out.println("First"); else System.out.println("Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
444686e0dc558e044848bfc82d1270bc
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class Girl { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); int[] chars = new int[26]; for(int i = 0; i<a.length();i++){ chars[a.charAt(i)-'a']++; } int total = 0; for(int i:chars){ if (i%2!=0){ total++; } } if (total%2!=0 || total==0){ System.out.println("First"); } else { System.out.println("Second"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
4d38b6debf74f43e0808a9fe01f592f4
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class Prob276B { public static void main(String[] Args) { Scanner scan = new Scanner(System.in); int[] array = new int[26]; String s = scan.next(); for (int i = 0; i < s.length(); i++) array[s.charAt(i) - 'a']++; int odds = 0; for (int i = 0; i < array.length; i++) if (array[i] % 2 == 1) odds++; if (odds == 0 || odds % 2 == 1) System.out.println("First"); else System.out.println("Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
cad104e4dd75e59b3953107c411f570c
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author vadimmm */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int[] letters = new int[26]; String s = in.next(); for (int i = 0; i < s.length(); ++i) ++letters[s.charAt(i) - 'a']; int a = 0, b = 0; for (int i = 0; i < 26; ++i) if (letters[i] % 2 == 0) ++a; else ++b; if (b % 2 == 1 || b == 0) { out.println("First"); return; } out.println("Second"); } } class InputReader { private static BufferedReader bufferedReader; private static StringTokenizer stringTokenizer; public InputReader(InputStream inputStream) { bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); stringTokenizer = null; } public String next() { while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { try { stringTokenizer = new StringTokenizer(bufferedReader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return stringTokenizer.nextToken(); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
372622e7f73555d7466a64ba015d43b5
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int[] mem = new int[26]; char[] input = in.next().toCharArray(); for (int i = 0; i < input.length; i++) mem[input[i]-'a']++; int odds = 0; for (int i = 0; i < mem.length; i++) if (mem[i] % 2 == 1) odds++; if (odds % 2 == 1 || odds == 0) out.print("First"); else out.print("Second"); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void close() { writer.close(); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
7fbdab04ed8292627fc09bc3688615ce
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class CodeForces276B { public static void main(String args[]){ Scanner scan = new Scanner(System.in); String s =scan.nextLine(); char a[]=s.toCharArray(); int count[]=new int[26]; for(int i = 0;i<a.length;i++){ count[(int)a[i]-97]++; } int flag=0; boolean bool = true; for(int i =0;i<26;i++){ if(count[i]%2!=0) flag++; if(flag>1){ bool =false; break; } } if(bool) System.out.println("First"); else{ if(a.length%2==0) System.out.println("Second"); else System.out.println("First"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
2c9e0d9b947a4de34580e01708f59323
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class Little_Girl_and_Game { public static void main(String args[]){ Scanner in = new Scanner(System.in); String s = in.next(); int k[] = new int[26]; int odd = 0; for(int i = 0 ; i < s.length() ; i++){ k[s.charAt(i)-'a']++; } for(int i = 0 ; i < 26 ; i++) if(k[i]%2!=0) odd++; if(odd==0) System.out.println("First"); else{ if((odd+1)%2==0) System.out.println("First"); else System.out.println("Second"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
5932bd96e9480f79704f9bbba7f22b55
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; public class B { public static BufferedReader in; public static PrintWriter out; public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); boolean showLineError = true; if (showLineError) { solve(); out.close(); } else { try { solve(); } catch (Exception e) { } finally { out.close(); } } } static void debug(Object... os) { out.println(Arrays.deepToString(os)); } private static void solve() throws IOException { String s = in.readLine(); char[] alph = new char[26]; for (int i = 0; i < s.length(); i++) alph[s.charAt(i) - 'a']++; int imp = 0; int par = 0; for (int a : alph) if (a > 0) if (a % 2 == 1) { imp++; } else { par++; } if(imp==0 || imp==1){ out.println("First"); return; } if(imp%2==0){ out.println("Second"); }else{ out.println("First"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
1bd26e9982629d778ae94d4bd4b0f1ef
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { private String tokens[]; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String ar[]) throws IOException { Main demo = new Main(); demo.solve(); } public void solve() throws IOException { int count[] = new int[27]; String s = br.readLine(); for (int i = 0; i < s.length(); i++) { count[s.charAt(i) - 'a']++; } int k = 0; for (int i = 0; i < count.length; i++) { k += (count[i] & 1) != 0 ? 1 : 0; } if (k == 0 || k == 1 || (k & 1) != 0) { System.out.println("First"); } else { System.out.println("Second"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
00a4eb8c00550d03b44502566929d10b
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.*; import java.util.*; public class LittleGirlAndGame { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); String str = f.readLine(); int[] a = new int[26]; for (int i = 0; i < str.length(); i++) a[str.charAt(i)-'a']++; int odd = 0; for (int i = 0; i < a.length; i++) if (a[i] % 2 == 1) odd++; if (odd == 0 || odd % 2 == 1) System.out.println("First"); else System.out.println("Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
435697f990927915acfe83975cbd6ef9
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class P276B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); sc.close(); char[] ch = new char[26]; for (int i = 0; i < s.length(); i++) ch[s.charAt(i) - 'a']++; int num = 0; for (int i = 0; i < 26; i++) if (ch[i]%2==1) num++; if (num == 0) System.out.println("First"); else if (num%2 ==0) System.out.println("Second"); else System.out.println("First"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
89900d687c3223a55fcc9e2718beec89
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner s = new Scanner(System.in); String input = s.next(); int[] a = new int[26]; Arrays.fill(a, 0); for(char ch: input.toCharArray()) a[ch - 'a']++; int count_odd = 0; for(int i : a) if(i%2 == 1)count_odd++; if(count_odd == 0 || count_odd == 1) System.out.println("First"); else{ if(count_odd%2 == 0) System.out.println("Second"); else System.out.println("First"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
10b19b73413e40a6aaf5a05cf9e4fbd8
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
//package codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class B { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter(System.out); StringTokenizer stringTokenizer; B() throws IOException { // reader = new BufferedReader(new FileReader("cycle2.in")); // writer = new PrintWriter(new FileWriter("cycle2.out")); } String next() throws IOException { while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { stringTokenizer = new StringTokenizer(reader.readLine()); } return stringTokenizer.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } int[][] mul(int[][] a, int[][] b) { int[][] result = new int[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { result[i][j] = sum(result[i][j], product(a[i][k], b[k][j])); } } } return result; } int[][] pow(int[][] a, int k) { int[][] result = {{1, 0}, {0, 1}}; while (k > 0) { if (k % 2 == 1) { result = mul(result, a); } a = mul(a, a); k /= 2; } return result; } final int MOD = 1000 * 1000 * 1000 + 9; int sum(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } int product(int a, int b) { return (int) (1l * a * b % MOD); } @SuppressWarnings("unchecked") void solve() throws IOException { char[] s = next().toCharArray(); int[] f = new int[26]; for (char c : s) { f[c - 'a']++; } int odd = 0; for (int i : f) { if(i % 2 == 1) { odd++; } } if(odd <= 1) { writer.println("First"); } else { writer.println(s.length % 2 == 0 ? "Second" : "First"); } writer.close(); } public static void main(String[] args) throws IOException { new B().solve(); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
9e9cac33fb1d075717f463e3a1867302
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Oreste */ public class Conejos { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { BufferedReader entrada=new BufferedReader(new InputStreamReader(System.in)); String line=entrada.readLine(); int par=0; int impar=0; int[] arr=new int[30]; for(int i=0;i<line.length();i++){ arr[line.charAt(i)-48-48]++; } for(int i=0;i<30;i++){ if(arr[i]!=0){ if(arr[i]%2==0)par++;else impar++; } } if(impar==1){ System.out.println("First"); }else if(impar==0){ System.out.println("First"); }else if(impar%2==0) System.out.println("Second");else System.out.println("First"); }}
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
e50da26e4daa249a9820828c67994664
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.StringTokenizer; public class Solution { static class Escanner { BufferedReader in; StringTokenizer st; Escanner() throws Throwable { in = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } Escanner(FileReader file) throws Throwable { in = new BufferedReader(file); st = new StringTokenizer(""); } int nextInt() throws Throwable { if (st.hasMoreTokens()) return Integer.parseInt(st.nextToken()); st = new StringTokenizer(in.readLine()); return nextInt(); } long nextLong() throws Throwable { if (st.hasMoreTokens()) return Long.parseLong(st.nextToken()); st = new StringTokenizer(in.readLine()); return nextLong(); } BigInteger nextBigInt() throws Throwable { if (st.hasMoreTokens()) return new BigInteger(st.nextToken()); st = new StringTokenizer(in.readLine()); return nextBigInt(); } double nextDouble() throws Throwable { if (st.hasMoreTokens()) return Double.parseDouble(st.nextToken()); st = new StringTokenizer(in.readLine()); return nextDouble(); } String nextStr() throws Throwable { if (st.hasMoreTokens()) return st.nextToken(); st = new StringTokenizer(in.readLine()); return nextStr(); } } public static void main(String[] args) throws Throwable { Escanner sc = new Escanner(); char[] s = sc.nextStr().toCharArray(); int[] c = new int[26]; for(int i=0; i<s.length; i++) c[s[i]-'a']++; int odds = 0; for(int i=0; i<26; i++) if((c[i]&1)==1) odds++; if(odds<=1) System.out.println("First"); else { int sum = 0; odds = 0; for(int i=0; i<26; i++) if((c[i]&1)==1 && ++odds<=2) continue; else sum+=c[i]; if((sum&1)==1) System.out.println("First"); else System.out.println("Second"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
59459e7b0b71387076318b0733dbf665
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; public class Main { private static final InputStreamReader standardInput = new InputStreamReader(System.in); private static final BufferedReader bufferedReader = new BufferedReader(standardInput); private static final Scanner scanner = new Scanner(bufferedReader); private static final OutputStreamWriter standardOutput = new OutputStreamWriter(System.out); private static final BufferedWriter bufferedWriter = new BufferedWriter(standardOutput); private static final PrintWriter printWriter = new PrintWriter(bufferedWriter); public static void main(String[] args) { String s = scanner.nextLine(); if (firstWins(s)) { printWriter.println("First"); } else { printWriter.println("Second"); } printWriter.flush(); scanner.close(); } private static boolean firstWins(String s) { int[] freq = new int[26]; int len = s.length(); for (int i = 0; i < len; i++) { freq[s.charAt(i) - 'a']++; } int oddOnes = 0; for (int i = 0; i < 26; i++) { if (freq[i] % 2 != 0) { oddOnes++; } } if (oddOnes > 0 && oddOnes % 2 == 0) { return false; } else { return true; } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
4a9d18d4aa55e74c097e2d35b9baf9ad
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.*; public class CF276B { public static void main(String... args) { String s = new Scanner(System.in).next(); int[] a = new int[26]; for (int i = 0, n = s.length(); i < n; i++) { a[s.charAt(i) - 'a']++; } int odds = 0; for (int i = 0; i < a.length; i++) { if (a[i] % 2 != 0) { odds++; } } System.out.println(odds < 2 || odds % 2 == 1 ? "First" : "Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
9ce09c2993470a63a9a6189ad123d8e5
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Created with IntelliJ IDEA. * User: dima * Date: 24.02.13 * Time: 19:10 * To change this template use File | Settings | File Templates. */ public class TaskB { static BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); static StringTokenizer str; static String SK; static String next() throws IOException { while ((str == null) || (!str.hasMoreTokens())) { SK = in.readLine(); if (SK == null) return null; str = new StringTokenizer(SK); } return str.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } public static void main(String[] args) throws IOException { char[] in = next().toCharArray(); int[] hh = new int[3000]; for (int i = 0; i < in.length; i++) { hh[in[i]]++; } int cnt = 0; for (int i = 0; i < hh.length; i++) { if (hh[i] != 0 && hh[i] % 2 == 1) cnt++; } if (cnt == 1||cnt ==0) { System.out.print("First"); return; } if ((cnt-1) % 2 == 0) System.out.print("First"); else { System.out.print("Second"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
ebc69a8af90fbfb8374ae1c2a25b5e56
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String... args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); boolean[] b = new boolean['z'-'a'+1]; for (char ch : s.toCharArray()){ b[ch-'a']=!b[ch-'a']; } int c = 0; for (int i=0; i<='z'-'a'; i++){ if (b[i]) c++; } System.out.println(c==0 || (c&1)!=0 ? "First":"Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
df64dbdf865db05898ff38f87c938301
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.StringTokenizer; import java.util.Scanner; public class CodeForces { public static void main(String[] args){ Scanner sin = new Scanner(System.in); String word = sin.next(); int chs[] = new int[26]; for(int i = 0; i < word.length(); i++){ chs[word.charAt(i) - 'a']++; } int odd = 0; for(int i = 0; i < 26; i++){ if(chs[i] % 2 == 1) odd++; } if(odd == 0 || (odd-1)%2 == 0) System.out.println("First"); else System.out.println("Second"); } } class sin { static BufferedReader reader; static StringTokenizer tokenizer; /** * call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } /** * get next word */ static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static byte nextByte() throws IOException { return Byte.parseByte(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
cce65751f8adcfddb02320ce411ff981
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class B276 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String s = input.next(); int[] stats = new int[26]; for (int i=0; i<s.length(); i++) { stats[s.charAt(i)-'a']++; } int odd = 0; for (int value : stats) { if ((value&1)==1) { odd++; } } boolean first = (odd == 0) || (odd%2 == 1); System.out.println(first ? "First" : "Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
df3e3d4e5ecbe52be7d38fe4944060f2
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package acm.prepare; import java.io.IOException; import java.util.Scanner; /** * * @author Rock */ public class Kolo { public static void main(String[] args) throws IOException { int a[]=new int[26]; int r,c=0; char[] tokens = new Scanner(System.in).next().toCharArray(); for(int i=0;i<tokens.length;i++) { int cc = ((int)tokens[i])-97; // System.out.println(cc); //if(cc+97>=0) break; a[cc]++; } for(int x=0;x<a.length;x++) { // System.out.println(a[x]); if(a[x]%2==1) c++; } if(c==0 || c%2==1) System.out.println("First"); else System.out.println("Second"); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
718340bbf5e937c06a5fd01a48439f1d
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Vaibhav Mittal */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { String s = in.readString(); int[] cnt = new int[26]; for (int i = 0; i < s.length(); ++i) ++cnt[s.charAt(i) - 'a']; int res = 0; for (int x : cnt) res += x % 2; out.println(res == 0 || res % 2 == 1 ? "First" : "Second"); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } private int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
32616024f9dc7a06652c6c3d3191affd
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; /** * * @author sousnake */ public class dp3 { static int arr[] ; public static void main(String args[]) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); arr = new int[26]; for(int i=0;i<26;i++) arr[i]=0; String s = br.readLine(); if(checkpalin(s)){ System.out.println("First"); return; } else{ if(s.length()%2==0){ System.out.println("Second"); } else{ System.out.println("First"); } } } public static boolean checkpalin(String s){ for(int i=0;i<s.length();i++){ char c = s.charAt(i); int k =(int)c; arr[k-97] +=1; } boolean ans =true; int count=0; for(int i=0;i<26;i++){ if(arr[i]%2!=0){ if(count>=1){ ans = false; } else count++; } } return ans; } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
8f2e85b7432665d10cdf4e1269bd15f5
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class A { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan=new Scanner(System.in); String s=scan.next(); boolean [] array= new boolean[s.length()]; for(int i=0; i<s.length();i++){ array[i]=false; } for(int i=0;i<s.length();i++){ for(int j=i+1;j<s.length();j++){ if(array[i]!=true){ if(s.charAt(i)==s.charAt(j)){ array[i]=true; array[j]=true; break; } } } } int count=0; for(int i=0;i<s.length();i++){ if(array[i]==false) count++; } if(count ==0 ) System.out.print("First"); else{ if(count%2==0) System.out.print("Second"); else System.out.print("First"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output
PASSED
b546ebfdc65cccff07ec2e44dc6d5485
train_001.jsonl
1361719800
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well β€” the one who moves first or the one who moves second.
256 megabytes
import java.util.Scanner; public class A { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan=new Scanner(System.in); String s=scan.next(); boolean [] array= new boolean[s.length()]; for(int i=0; i<s.length();i++){ array[i]=false; } for(int i=0;i<s.length();i++){ for(int j=i+1;j<s.length();j++){ if(array[i]!=true){ if(s.charAt(i)==s.charAt(j)){ array[i]=true; array[j]=true; break; } } } } int count=0; for(int i=0;i<s.length();i++){ if(array[i]==false) count++; } if(count ==0||count%2==1 ) System.out.print("First"); else{ System.out.print("Second"); } } }
Java
["aba", "abca"]
2 seconds
["First", "Second"]
null
Java 7
standard input
[ "greedy", "games" ]
bbf2dbdea6dd3aa45250ab5a86833558
The input contains a single line, containing string s (1 ≀ |s|  ≀  103). String s consists of lowercase English letters.
1,300
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
standard output