12516 - Cinema-cola

All about problems in Volume 125. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
piyukr
New poster
Posts: 17
Joined: Sun Jan 26, 2014 10:35 am

12516-RE

Post by piyukr » Wed Feb 05, 2014 12:33 pm

My code for 12516 gave all the correct outputs on my machine but on submission,got Runtime Error at 0 sec( does that mean the program did not even run on the online compiler? ). Could someone tell me where is the code incorrect ?

Code: Select all

//package pkg12516_java;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;

class friend implements Comparable<friend> {

    int r;
    int c;

    friend(int x, int y) {
	r = x;
	c = y;
    }

    @Override
    public int compareTo(friend x) {
	if (x.r < r) {
	    return 1;
	} else if (x.r < r) {
	    return -1;
	} else if (x.c < c) {
	    return 1;
	} else {
	    return -1;
	}
    }
}

public class Main {

    public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	while (true) {
	    String[] s = br.readLine().split(" ");
	    int x = Integer.parseInt(s[0]);
	    int y = Integer.parseInt(s[1]);
	    if (x == 0) {
		break;
	    }
	    char[][] c = new char[x][y];
	    int spec = Integer.parseInt(br.readLine());
	    while (spec-- > 0) {
		String each_spec = br.readLine();
		int row = each_spec.charAt(0) - 'A';
		int col = Integer.parseInt(each_spec.substring(1, 2)) - 1;
		c[row][col] = each_spec.charAt(3);
	    }
	    int nof = Integer.parseInt(br.readLine());
	    ArrayList<friend> al = new ArrayList<friend>();
	    while (nof-- > 0) {
		String each_friend = br.readLine();
		int row = each_friend.charAt(0) - 'A';
		int col = Integer.parseInt(each_friend.substring(1, 2));
		al.add(new friend(row, col));
	    }
	    Collections.sort(al);
	    Boolean check = true;
	    for (int i = 0; i < al.size(); i++) {
		int row = al.get(i).r;
		int col = al.get(i).c - 1;
		if (col != 0 && col != y - 1) {
		    if (c[row][col - 1] == '+' && c[row][col + 1] == '-') {
			check = false;
			break;
		    } else if (c[row][col - 1] != '+') {
			c[row][col] = '-';
		    } else {
			c[row][col] = '+';
		    }
		}
	    }
	    if (check) {
		bw.write("YES" + "\n");
	    } else {
		bw.write("NO" + "\n");
	    }
	}
	bw.close();
    }
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12516-RE

Post by brianfry713 » Wed Feb 05, 2014 9:30 pm

Fix compareTo
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12516-RE

Post by brianfry713 » Thu Feb 06, 2014 9:55 pm

Try input:

Code: Select all

1 10
2
A8 +
A10 -
1
A9
0 0
Check input and AC output for thousands of problems on uDebug!

piyukr
New poster
Posts: 17
Joined: Sun Jan 26, 2014 10:35 am

Re: 12516-RE

Post by piyukr » Fri Feb 07, 2014 9:56 pm

I have rectified that problem ,it gives the correct answer to cases like you suggested but the OJ gives a RE .Is there something wrong in the logic of the program? Here's the code :

Code: Select all

//package pkg12516_java;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class friend implements Comparable<friend> {

    int r;
    int c;

    friend(int x, int y) {
	r = x;
	c = y;
    }

    @Override
    public int compareTo(friend x) {
	if (x.r < r) {
	    return 1;
	} else if (x.r > r) {
	    return -1;
	}
	if (x.c < c) {
	    return 1;
	} else if (x.c > c) {
	    return -1;
	}
	return 0;
    }
}

class Main {

    public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	char[][] c=new char[26][100];
	ArrayList<friend> al = new ArrayList<friend>();
	while (true) {
	    String[] s = br.readLine().split(" ");
	    int x = Integer.parseInt(s[0]);
	    int y = Integer.parseInt(s[1]);
	    if (x == 0 && y == 0) {
		break;
	    }
	    int spec = Integer.parseInt(br.readLine());
	    while (spec-- > 0) {
		String each_spec = br.readLine();
		int row = each_spec.charAt(0) - 'A';//taking the row number
		String[] st = each_spec.substring(1).split(" ");
		int col = Integer.parseInt(st[0]) - 1;// taking the column number
		c[row][col] = st[1].charAt(0);// taking the choice as left support or the right support
	    }
	    int nof = Integer.parseInt(br.readLine());
	    while (nof-- > 0) {
		String each_friend = br.readLine();
		int row = each_friend.charAt(0) - 'A';
		int col = Integer.parseInt(each_friend.substring(1)) - 1;
		al.add(new friend(row, col));
	    }
	    Collections.sort(al);
	    Boolean check = true;
	    for (int i = 0; i < al.size(); i++) {
		int row = al.get(i).r;
		int col = al.get(i).c - 1;
		if (col != 0 && col != y - 1) {
		    if (c[row][col - 1] == '+' && c[row][col + 1] == '-') {
			check = false;
			break;
		    } else if (c[row][col - 1] != '+') {
			c[row][col] = '-';
		    } else {
			c[row][col] = '+';
		    }
		}
	    }
	    if (check) {
		bw.write("YES" + "\n");
	    } else {
		bw.write("NO" + "\n");
	    }
	    al.removeAll(al);
	    Arrays.fill(c,null);
	}
	bw.close();
	br.close();
    }
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 12516-RE

Post by brianfry713 » Mon Feb 10, 2014 11:15 pm

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 125 (12500-12599)”