Rezultati

Up. imeNalogaJezikRezultatČas oddaje
sts-koper-2019 Biodiverziteta Java 100/100OK 09. maj '19 @ 19:46

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 20/20 77,215 MiB 0,000 s OK
#2 [več] 20/20 85,535 MiB 0,000 s OK
#3 [več] 20/20 88,164 MiB 0,000 s OK
#4 [več] 20/20 86,723 MiB 0,000 s OK
#5 [več] 20/20 86,984 MiB 0,000 s OK

Ocenjevani program (Biodiversity.java):
import java.io.*;

public class Biodiversity {
	
	/**
	 * Reads input at console.
	 */
	public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	
	// Data variables: //
	public static String B, D, data[];
	public static int n, m, q;
	public static int l1, l2, d1, d2;
	public static int r;
	public static int bArray[][], dArray[][];
	// End of data variables. //
	
	/**
	 * Reading of the input data.
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {	
		data = reader.readLine().split(" ");
		n = Integer.parseInt(data[0]); m = Integer.parseInt(data[1]); q = Integer.parseInt(data[2]);
		B = reader.readLine(); D = reader.readLine();
		
		bArray = new int[B.length()][4]; dArray = new int[D.length()][4];
		
		for (int i = 0; i < Math.max(B.length(), D.length()); i++) {
			if (i == 0) {
				if (B.charAt(i) == 'A')	bArray[i][0]++;
				else if (B.charAt(i) == 'C') bArray[i][1]++;
				else if (B.charAt(i) == 'G') bArray[i][2]++;
				else if (B.charAt(i) == 'T') bArray[i][3]++;
				
				if (D.charAt(i) == 'A')	dArray[i][0]++;
				else if (D.charAt(i) == 'C') dArray[i][1]++;
				else if (D.charAt(i) == 'G') dArray[i][2]++;
				else if (D.charAt(i) == 'T') dArray[i][3]++;
			}
			else {
				if (i < B.length()) {
					if (B.charAt(i) == 'A') {
						bArray[i][0] = bArray[i-1][0] + 1;
						bArray[i][1] = bArray[i-1][1];
						bArray[i][2] = bArray[i-1][2];
						bArray[i][3] = bArray[i-1][3];
					} 
					else if (B.charAt(i) == 'C') {
						bArray[i][0] = bArray[i-1][0];
						bArray[i][1] = bArray[i-1][1] + 1;
						bArray[i][2] = bArray[i-1][2];
						bArray[i][3] = bArray[i-1][3];
					}
					else if (B.charAt(i) == 'G') {
						bArray[i][0] = bArray[i-1][0];
						bArray[i][1] = bArray[i-1][1];
						bArray[i][2] = bArray[i-1][2] + 1;
						bArray[i][3] = bArray[i-1][3];
					}
					else if (B.charAt(i) == 'T') {
						bArray[i][0] = bArray[i-1][0];
						bArray[i][1] = bArray[i-1][1];
						bArray[i][2] = bArray[i-1][2];
						bArray[i][3] = bArray[i-1][3] + 1;
					}
				}
				if (i < D.length()) {
					if (D.charAt(i) == 'A')	{
						dArray[i][0] = dArray[i-1][0] + 1;
						dArray[i][1] = dArray[i-1][1];
						dArray[i][2] = dArray[i-1][2];
						dArray[i][3] = dArray[i-1][3];
					}
					else if (D.charAt(i) == 'C') {
						dArray[i][0] = dArray[i-1][0];
						dArray[i][1] = dArray[i-1][1] + 1;
						dArray[i][2] = dArray[i-1][2];
						dArray[i][3] = dArray[i-1][3];
					}
					else if (D.charAt(i) == 'G') {
						dArray[i][0] = dArray[i-1][0];
						dArray[i][1] = dArray[i-1][1];
						dArray[i][2] = dArray[i-1][2] + 1;
						dArray[i][3] = dArray[i-1][3];
					}
					else if (D.charAt(i) == 'T') {
						dArray[i][0] = dArray[i-1][0];
						dArray[i][1] = dArray[i-1][1];
						dArray[i][2] = dArray[i-1][2];
						dArray[i][3] = dArray[i-1][3] + 1;
					}
				}
			}
			
		}
		
		for (int i = 0; i < q; i++) {
			data = reader.readLine().split(" ");
			l1 = Integer.parseInt(data[0]); l2 = Integer.parseInt(data[1]); d1 = Integer.parseInt(data[2]); d2 = Integer.parseInt(data[3]);
			solve();
		}
		reader.close();
	}
	
	/**
	 * Solves the problem and prints the result.
	 */
	public static void solve() {
		int Ab = 0, Cb = 0, Gb = 0, Tb = 0;
		int Ad = 0, Cd = 0, Gd = 0, Td = 0;
		
		if (l1 == 1) {
			Ab = bArray[l2 - 1][0];
			Cb = bArray[l2 - 1][1];
			Gb = bArray[l2 - 1][2];
			Tb = bArray[l2 - 1][3];
		} else {
			Ab = bArray[l2 - 1][0] - bArray[l1 - 2][0];
			Cb = bArray[l2 - 1][1] - bArray[l1 - 2][1];
			Gb = bArray[l2 - 1][2] - bArray[l1 - 2][2];
			Tb = bArray[l2 - 1][3] - bArray[l1 - 2][3];
		}
		if (d1 == 1) {
			Ad = dArray[d2 - 1][0];
			Cd = dArray[d2 - 1][1];
			Gd = dArray[d2 - 1][2];
			Td = dArray[d2 - 1][3];
		} else {
			Ad = dArray[d2 - 1][0] - dArray[d1 - 2][0];
			Cd = dArray[d2 - 1][1] - dArray[d1 - 2][1];
			Gd = dArray[d2 - 1][2] - dArray[d1 - 2][2];
			Td = dArray[d2 - 1][3] - dArray[d1 - 2][3];
		}
		r = Math.abs(Ab - Ad) + Math.abs(Cb - Cd) + Math.abs(Gb - Gd) + Math.abs(Tb -Td);
		System.out.println(r);
	}
	
}

//===== Input: =====//
/*
10 12 5
ACAGTTGCAA
AAACCCGGGTTT
1 10 1 12
1 1 1 1
7 10 7 12
1 3 2 4
3 7 5 11

*/

//===== Output: =====//
/*
4
0
8
0
4
*/