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 | ed8c8a3889fd5c83235b8916ab5b15e9 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.util.LinkedList;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Collection;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Queue;
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);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
char grid[][];
int n;
int m;
public void solve(int testNumber, InputReader in, PrintWriter out) {
n = in.nextInt();
m = in.nextInt();
grid = new char[n][m];
for (int i = 0; i < n; i++) {
grid[i] = in.next().toCharArray();
}
int cells = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == '.') {
cells++;
}
}
}
Queue<Integer> q = new LinkedList<>();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (degree(i, j) == 1) q.add(toIndex(m, i, j));
}
}
while (!q.isEmpty()) {
int index = q.remove();
int x = index / m;
int y = index % m;
if (grid[x][y] != '.') continue;
int adjIndex = -1;
if (x > 0 && grid[x - 1][y] == '.') {
adjIndex = toIndex(m, x - 1, y);
} else if (x + 1 < n && grid[x + 1][y] == '.') {
adjIndex = toIndex(m, x + 1, y);
} else if (y > 0 && grid[x][y - 1] == '.') {
adjIndex = toIndex(m, x, y - 1);
} else if (y + 1 < m && grid[x][y + 1] == '.') {
adjIndex = toIndex(m, x, y + 1);
} else {
continue;
}
int adjX = adjIndex / m;
int adjY = adjIndex % m;
if (grid[adjX][adjY] != '.') continue;
cover(x, y, adjX, adjY);
for (int dx = -1; dx < 2; dx++) {
for (int dy = -1; dy < 2; dy++) {
if (degree(x + dx, y + dy) == 1) q.add(toIndex(m, x + dx, y + dy));
if (degree(adjX + dx, adjY + dy) == 1) q.add(toIndex(m, adjX + dx, adjY + dy));
}
}
cells -= 2;
}
if (cells > 0) {
out.println("Not unique");
} else {
for (int i = 0; i < n; i++) {
out.println(new String(grid[i]));
}
}
}
private int degree(int i, int j) {
if (i < 0 || i >= n || j < 0 || j >= m) return 0;
if (grid[i][j] != '.') return 0;
int deg = 0;
if (i > 0 && grid[i - 1][j] == '.') {
deg++;
}
if (i + 1 < n && grid[i + 1][j] == '.') {
deg++;
}
if (j > 0 && grid[i][j - 1] == '.') {
deg++;
}
if (j + 1 < m && grid[i][j + 1] == '.') {
deg++;
}
return deg;
}
private void cover(int x1, int y1, int x2, int y2) {
if (x1 == x2) {
grid[x1][Math.min(y1, y2)] = '<';
grid[x2][Math.max(y1, y2)] = '>';
} else {
grid[Math.min(x1, x2)][y1] = '^';
grid[Math.max(x1, x2)][y2] = 'v';
}
}
private int toIndex(int m, int i, int j) {
return i * m + j;
}
}
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 | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | 91f42542e14a3d593f188b7ebc9da9c3 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.util.LinkedList;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Collection;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Queue;
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);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
char grid[][];
int n;
int m;
public void solve(int testNumber, InputReader in, PrintWriter out) {
n = in.nextInt();
m = in.nextInt();
grid = new char[n][m];
for (int i = 0; i < n; i++) {
grid[i] = in.next().toCharArray();
}
int cells = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == '.') {
cells++;
}
}
}
Queue<Pair> q = new LinkedList<>();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (degree(i, j) == 1) q.add(new Pair(i, j));
}
}
while (!q.isEmpty()) {
Pair p1 = q.remove();
if (grid[p1.x][p1.y] != '.') continue;
Pair p2 = adj(p1);
if (p2 == null) continue;
cover(p1.x, p1.y, p2.x, p2.y);
for (int dx = -1; dx < 2; dx++) {
for (int dy = -1; dy < 2; dy++) {
if (degree(p1.x + dx, p1.y + dy) == 1) q.add(new Pair(p1.x + dx, p1.y + dy));
if (degree(p2.x + dx, p2.y + dy) == 1) q.add(new Pair(p2.x + dx, p2.y + dy));
}
}
cells -= 2;
}
if (cells > 0) {
out.println("Not unique");
} else {
for (int i = 0; i < n; i++) {
out.println(new String(grid[i]));
}
}
}
private Pair adj(Pair p1) {
if (p1.x > 0 && grid[p1.x - 1][p1.y] == '.') {
return new Pair(p1.x - 1, p1.y);
} else if (p1.x + 1 < n && grid[p1.x + 1][p1.y] == '.') {
return new Pair(p1.x + 1, p1.y);
} else if (p1.y > 0 && grid[p1.x][p1.y - 1] == '.') {
return new Pair(p1.x, p1.y - 1);
} else if (p1.y + 1 < m && grid[p1.x][p1.y + 1] == '.') {
return new Pair(p1.x, p1.y + 1);
}
return null;
}
private int degree(int i, int j) {
if (i < 0 || i >= n || j < 0 || j >= m) return 0;
if (grid[i][j] != '.') return 0;
int deg = 0;
if (i > 0 && grid[i - 1][j] == '.') {
deg++;
}
if (i + 1 < n && grid[i + 1][j] == '.') {
deg++;
}
if (j > 0 && grid[i][j - 1] == '.') {
deg++;
}
if (j + 1 < m && grid[i][j + 1] == '.') {
deg++;
}
return deg;
}
private void cover(int x1, int y1, int x2, int y2) {
if (x1 == x2) {
grid[x1][Math.min(y1, y2)] = '<';
grid[x2][Math.max(y1, y2)] = '>';
} else {
grid[Math.min(x1, x2)][y1] = '^';
grid[Math.max(x1, x2)][y2] = 'v';
}
}
private class Pair {
private final int x;
private final int y;
public Pair(int i, int j) {
this.x = i;
this.y = j;
}
}
}
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 | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | 946d662e811abd98afda14db5ff0b0ab | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.util.*;
/**
* Created by zephyr on 2/19/15.
*/
public class DrazilandTiles {
static Deque<Integer> deque = new ArrayDeque<>();
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt(), m = cin.nextInt();
grid = new char[n][m];
for (int i = 0; i < n; i++) {
String input = cin.next();
grid[i] = input.toCharArray();
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] != '.') {
continue;
}
idegree(i,j);
}
}
Node node = new Node();
Node neighbour = new Node();
while (!deque.isEmpty()) {
node.y = deque.remove();
node.x = deque.remove();
neighbour.y = deque.remove();
neighbour.x = deque.remove();
if (grid[node.y][node.x] != '.') {
continue;
}
if (grid[neighbour.y][neighbour.x] != '.') {
System.out.println("Not unique");
return;
}
if (neighbour.x > node.x) {
grid[node.y][node.x] = '<';
grid[neighbour.y][neighbour.x] = '>';
} else if (neighbour.x < node.x) {
grid[node.y][node.x] = '>';
grid[neighbour.y][neighbour.x] = '<';
} else if (neighbour.y < node.y) {
grid[node.y][node.x] = 'v';
grid[neighbour.y][neighbour.x] = '^';
} else {
grid[node.y][node.x] = '^';
grid[neighbour.y][neighbour.x] = 'v';
}
// addNeighbours(deque,node,grid);
int i = neighbour.y;
int j = neighbour.x;
for (int k = 0; k < 4; k++) {
int dxi = i + xs[k];
int dyi = j + ys[k];
if (dxi >= 0 && dxi < grid.length) {
if (dyi >= 0 && dyi < grid[0].length) {
if (grid[dxi][dyi] == '.') {
if (grid[dxi][dyi] != '.') {
continue;
}
idegree(dxi,dyi);
}
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == '.') {
System.out.println("Not unique");
return;
}
}
}
for (int i = 0; i < n; i++) {
System.out.println(new String(grid[i]));
}
}
static char[][] grid;
static int[] xs = {-1, 1, 0, 0};
static int[] ys = {0, 0, -1, 1};
private static void idegree(int i, int j) {
int degree = 0;
int dx = 0;
int dy = 0;
for (int k = 0; k < 4; k++) {
int dxi = i + xs[k];
int dyi = j + ys[k];
if (dxi >= 0 && dxi < grid.length && dyi >= 0 && dyi < grid[0].length) {
if (grid[dxi][dyi] == '.') {
degree++;
if (degree == 1) {
dx = dxi; //xs[k];
dy = dyi;//ys[k];
}
}
}
}
if (degree == 1){
deque.add(i);
deque.add(j);
deque.add(dx);
deque.add(dy);
}
}
static class Node {
public int y;
public int x;
public Node neighbour;
public Node() {
}
public Node(int y, int x) {
this.x = x;
this.y = y;
}
}
} | Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | e119043c38c4389021a0dd37e2967dfb | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.util.ArrayDeque;
import java.util.Scanner;
public class Solver {
Solver(){
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
grid = new char[n][m];
for(int i = 0; i<n; i++)
grid[i] = in.next().toCharArray();
q = new ArrayDeque<>();
for(int i = 0; i<n; i++)
for(int j = 0; j<m; j++){
if(grid[i][j] == '*')
continue;
check(i, j);
}
int ci, cj, ni, nj;
while(!q.isEmpty()){
ci = q.remove();
cj = q.remove();
ni = q.remove();
nj = q.remove();
if(grid[ci][cj] == '.' && grid[ni][nj] == '.'){
if(ni == ci){
if(nj > cj){
grid[ci][cj] = '<';
grid[ni][nj] = '>';
}else{
grid[ci][cj] = '>';
grid[ni][nj] = '<';
}
}else{ // nj == j
if(ni > ci){
grid[ci][cj] = '^';
grid[ni][nj] = 'v';
}else{
grid[ci][cj] = 'v';
grid[ni][nj] = '^';
}
}
for(int d = 0; d<4; d++)
if(!isSolid(ni+dx[d], nj+dy[d]))
check(ni+dx[d], nj+dy[d]);
}
}
boolean unique = true;
for(int i = 0; i<n; i++)
for(int j = 0; j<m; j++)
if( grid[i][j] == '.') unique = false;
if(unique){
for(int i = 0; i<n; i++)
System.out.println(new String(grid[i]));
}else System.out.println("Not unique");
}
ArrayDeque<Integer> q;
int[] dx = {0,0,1,-1};
int[] dy = {1,-1,0,0};
int n, m;
char[][] grid;
int ni, nj, sc;
boolean isSolid(int i, int j){
if(i < 0 || j < 0 || i >=n || j>=m)
return true;
return grid[i][j] != '.';
}
void check(int i, int j){
ni = nj = -1;
sc = 4;
for(int d = 0; d<4; d++)
if(!isSolid(i+dx[d], j+dy[d])){
sc--;
ni = i+dx[d];
nj = j+dy[d];
}
if(sc == 3){
q.add(i);
q.add(j);
q.add(ni);
q.add(nj);
}
}
public static void main(String[] args) {
new Solver();
}
} | Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | 9446b8dae052a711890ad5364b3907f6 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.util.*;
/**
* Created by zephyr on 2/19/15.
*/
public class DrazilandTiles {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt(), m = cin.nextInt();
char[][] grid = new char[n][m];
for (int i = 0; i < n; i++) {
String input = cin.next();
grid[i] = input.toCharArray();
}
Deque<Node> deque = new LinkedList<>();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (degree(grid, i, j) == 1){
deque.add(new Node(i, j));
}
}
}
while (!deque.isEmpty()){
Node node = deque.poll();
if (grid[node.y][node.x] != '.'){
continue;
}
List<Node> neighbours = neighbour(node,grid);
if (neighbours.size() != 1){
System.out.println("Not unique");
return;
}
Node neighbour = neighbours.get(0);
if (neighbour.x > node.x) {
grid[node.y][node.x] = '<';
grid[neighbour.y][neighbour.x] = '>';
} else if (neighbour.x < node.x) {
grid[node.y][node.x] = '>';
grid[neighbour.y][neighbour.x] = '<';
} else {
if (neighbour.y < node.y) {
grid[node.y][node.x] = 'v';
grid[neighbour.y][neighbour.x] = '^';
} else {
grid[node.y][node.x] = '^';
grid[neighbour.y][neighbour.x] = 'v';
}
}
addNeighbours(deque,node,grid);
addNeighbours(deque,neighbour, grid);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == '.') {
System.out.println("Not unique");
return;
}
}
}
for (int i = 0; i < n; i++) {
System.out.println(grid[i]);
}
}
private static void addNeighbours(Deque<Node> deque, Node node, char[][] grid) {
List<Node> neigh = neighbour(node, grid);
for (Node neig : neigh){
if (degree(grid,neig.y,neig.x) == 1){
deque.add(neig);
}
}
}
private static List<Node> neighbour(Node node, char[][] grid) {
ArrayList<Node> neigh = new ArrayList<>();
int i = node.y;
int j = node.x;
int[] xs = {-1,1,0,0};
int[] ys = {0,0,-1,1};
for (int k = 0; k < 4; k++) {
if (i+xs[k] >= 0 && i+xs[k] < grid.length){
if (j+ys[k] >= 0 && j + ys[k] < grid[0].length){
if (grid[i+xs[k]][j+ys[k]] == '.'){
neigh.add(new Node(i+xs[k], j+ys[k]));
}
}
}
}
return neigh;
}
private static int degree(char[][] grid, int i, int j) {
int degree = 0;
int[] xs = {-1,1,0,0};
int[] ys = {0,0,-1,1};
for (int k = 0; k < 4; k++) {
if (i+xs[k] >= 0 && i+xs[k] < grid.length){
if (j+ys[k] >= 0 && j + ys[k] < grid[0].length){
if (grid[i+xs[k]][j+ys[k]] == '.'){
degree++;
}
}
}
}
return degree;
}
static class Node {
public final int y;
public final int x;
public Node(int y, int x) {
this.x = x;
this.y = y;
}
}
} | Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | a4c0ac0a575e154f168f2df5d1614075 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.util.*;
import java.io.*;
public class MainClass
{
static int n, m;
static char[][] A;
static int[] dx = {1, -1, 0, 0};
static int[] dy = {0, 0, 1, -1};
public static void main(String[] args) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s1[] = in.readLine().split(" ");
n = Integer.parseInt(s1[0]);
m = Integer.parseInt(s1[1]);
A = new char[n][m];
for (int i=0;i<n;i++) A[i] = in.readLine().toCharArray();
for (int i=0;i<n;i++) for (int j=0;j<m;j++) if (A[i][j] == '.') explore(i, j);
boolean ff = true;
for (int i=0;i<n;i++) for (int j=0;j<m;j++)
{
if (A[i][j] == '.')
{
ff = false;
break;
}
}
if (ff)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++) stringBuilder.append(A[i][j]);
stringBuilder.append("\n");
}
System.out.println(stringBuilder);
}
else
System.out.println("Not unique");
}
public static void explore(int x, int y)
{
int deg = deg(x, y);
if (deg > 1 || deg < 1) return;
int nx = -1;
int ny = -1;
for (int i=0;i<4;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (inBounds(xx, yy))
{
if (A[xx][yy] == '.')
{
nx = xx; ny = yy;
}
}
}
if (nx == x)
{
if (ny == y - 1)
{
A[nx][ny] = '<';
A[x][y] = '>';
}
else
{
A[nx][ny] = '>';
A[x][y] = '<';
}
}
else
{
if (nx == x - 1)
{
A[nx][ny] = '^';
A[x][y] = 'v';
}
else
{
A[nx][ny] = 'v';
A[x][y] = '^';
}
}
for (int i=0;i<4;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (inBounds(xx, yy) && A[xx][yy] == '.')
explore(xx, yy);
}
for (int i=0;i<4;i++)
{
int xx = nx + dx[i];
int yy = ny + dy[i];
if (inBounds(xx, yy) && A[xx][yy] == '.')
explore(xx, yy);
}
}
public static int deg(int x, int y)
{
int count = 0;
for (int i=0;i<4;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (inBounds(xx, yy) && A[xx][yy] == '.')
count++;
}
return count;
}
public static boolean inBounds(int x, int y)
{
return x >= 0 && x < n && y >= 0 && y < m;
}
}
class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
} | Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | 5b32eb8e724e5a59e11ce69c39e2e93e | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* #
* @author pttrung
*/
public class D_Round_292_Div2 {
public static long MOD = 1000000007;
public static void main(String[] args) throws FileNotFoundException {
// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
// "output.txt")));
PrintWriter out = new PrintWriter(System.out);
Scanner in = new Scanner();
int n = in.nextInt();
int m = in.nextInt();
int[] X = {0, 0, 1, -1};
int[] Y = {1, -1, 0, 0};
String A = "<>^v";
String B = "><v^";
String[] data = new String[n];
LinkedList<Point> q = new LinkedList<>();
char[][] re = new char[n][m];
for (int i = 0; i < n; i++) {
data[i] = in.next();
}
int[][] count = new int[n][m];
int total = n * m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (data[i].charAt(j) == '*') {
re[i][j] = '*';
total--;
continue;
}
for (int k = 0; k < 4; k++) {
int x = i + X[k];
int y = j + Y[k];
if (x >= 0 && x < n && y >= 0 && y < m && data[x].charAt(y) != '*') {
count[i][j]++;
}
}
if (count[i][j] == 1) {
q.add(new Point(i, j));
}
}
}
boolean ok = true;
while (!q.isEmpty() && ok) {
Point p = q.poll();
if (re[p.x][p.y] == 0) {
int dir = -1;
for (int k = 0; k < 4; k++) {
int x = p.x + X[k];
int y = p.y + Y[k];
if (x >= 0 && x < n && y >= 0 && y < m && data[x].charAt(y) != '*' && re[x][y] == 0) {
dir = k;
break;
}
}
// System.out.println(p + " " + dir);
if (dir == -1) {
ok = false;
} else {
total -= 2;
int x = p.x + X[dir];
int y = p.y + Y[dir];
re[p.x][p.y] = A.charAt(dir);
re[x][y] = B.charAt(dir);
for (int k = 0; k < 4; k++) {
int nxtX = x + X[k];
int nxtY = y + Y[k];
if (nxtX >= 0 && nxtX < n && nxtY >= 0 && nxtY < m && data[nxtX].charAt(nxtY) != '*') {
count[nxtX][nxtY]--;
if (count[nxtX][nxtY] == 1 && re[nxtX][nxtY] == 0) {
q.add(new Point(nxtX, nxtY));
}
}
}
}
}
}
if (total != 0) {
out.println("Not unique");
} else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
out.print(re[i][j]);
}
out.println();
}
}
out.close();
}
public static int[] KMP(String val) {
int i = 0;
int j = -1;
int[] result = new int[val.length() + 1];
result[0] = -1;
while (i < val.length()) {
while (j >= 0 && val.charAt(j) != val.charAt(i)) {
j = result[j];
}
j++;
i++;
result[i] = j;
}
return result;
}
public static boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
public static int digit(long n) {
int result = 0;
while (n > 0) {
n /= 10;
result++;
}
return result;
}
public static double dist(long a, long b, long x, long y) {
double val = (b - a) * (b - a) + (x - y) * (x - y);
val = Math.sqrt(val);
double other = x * x + a * a;
other = Math.sqrt(other);
return val + other;
}
public static class Point implements Comparable<Point> {
int x, y;
public Point(int start, int end) {
this.x = start;
this.y = end;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.x;
hash = 47 * hash + this.y;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Point other = (Point) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
return true;
}
@Override
public String toString() {
return "Point{" + "x=" + x + ", y=" + y + '}';
}
@Override
public int compareTo(Point o) {
return Integer.compare(x, o.x);
}
}
public static class FT {
long[] data;
FT(int n) {
data = new long[n];
}
public void update(int index, long value) {
while (index < data.length) {
data[index] += value;
index += (index & (-index));
}
}
public long get(int index) {
long result = 0;
while (index > 0) {
result += data[index];
index -= (index & (-index));
}
return result;
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static long pow(long a, long b, long MOD) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2, MOD);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() throws FileNotFoundException {
// System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | 576e6f7b55602d736ac817e5539c0530 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
public class D292 {
static final int[] dr = {-1,0,1,0}, dc = {0,-1,0,1};
static final char[] dir = {'v','>','^','<'};
static int R, C;
static char[][] mat;
public static void main(String[] args) {
Jolty scan = new Jolty(System.in);
R = scan.nextInt();
C = scan.nextInt();
mat = new char[R][C];
int[][] color = new int[R][C];
for(int i=0;i<R;i++)mat[i] = scan.next().toCharArray();
for(int i=0;i<R;i++)Arrays.fill(color[i], -1);
color[0][0] = 0;
ArrayDeque<Integer> q = new ArrayDeque<>();
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
if(i==0&&j==0)continue;
color[i][j] = (j!=0)?color[i][j-1]^1:1^color[i-1][j];
if(mat[i][j]!='.')continue;
if(check(i,j)){
q.add(i);
q.add(j);
}
}
}
while(!q.isEmpty()){
int r = q.poll();
int c = q.poll();
for(int i=0;i<4;i++){
int rr = r+dr[i], cc = c+dc[i];
if(rr<0||rr>=R||cc<0||cc>=C||mat[rr][cc]!='.')continue;
mat[r][c] = dir[i];
mat[rr][cc] = dir[(i+2)%4];
for(int j=0;j<4;j++){
int rrr = rr+dr[j], ccc = cc+dc[j];
if(rrr<0||rrr>=R||ccc<0||ccc>=C||mat[rrr][ccc]!='.')continue;
if(check(rrr,ccc)){
q.add(rrr);
q.add(ccc);
}
}
}
}
boolean done = true;
for(int i=0;i<R;i++)for(int j=0;j<C;j++)done = (mat[i][j]=='.')?false:done;
PrintWriter out = new PrintWriter(System.out);
if(!done){
out.println("Not unique");
}else{
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
out.print(mat[i][j]);
}out.println();
}
}
out.close();
}
private static boolean check(int r, int c) {
int count = 0;
for(int i=0;i<4;i++){
int rr = r+dr[i], cc = c+dc[i];
if(rr<0||rr>=R||cc<0||cc>=C)continue;
if(mat[rr][cc]!='.')continue;
count++;
}
return count==1;
}
private static class Jolty{
static final int BASE_SPEED = 130;
static final int BUFFER_SIZE = 1<<16;
static final char NULL_CHAR = (char)-1;
BufferedInputStream in;
StringBuilder str = new StringBuilder();
byte[] buffer = new byte[BUFFER_SIZE];
char c = NULL_CHAR;
int bufferIdx = 0, size = 0;
public Jolty(InputStream in) {
this.in = new BufferedInputStream(in,BUFFER_SIZE);
}
public int nextInt() {return (int)nextLong();}
public double nextDouble() {return Double.parseDouble(next());}
public long nextLong() {
long negative = 0, res = 0;
if(c==NULL_CHAR)c=nextChar();
for(;(c<'0'||c>'9');c=nextChar())
negative = (c=='-')?1:0;
for(;c>='0'&&c<='9';c=nextChar())
res = (res<<3)+(res<<1)+c-'0';
return negative==1 ? -res : res;
}
public String nextLine() {
str.setLength(0);
for(c = c == NULL_CHAR ? nextChar() : c; c!='\n'; c= nextChar())
str.append(c);
c = NULL_CHAR;
return str.toString();
}
public String next() {
for(c = c == NULL_CHAR ? nextChar() : c; Character.isWhitespace(c);)
c = nextChar();
str.setLength(0);
for(;!Character.isWhitespace(c);c=nextChar())
str.append(c);
return str.toString();
}
public char nextChar() {
while(bufferIdx == size) {
try{
size = in.read(buffer);
if(size == -1)throw new Exception();
} catch (Exception e){}
if(size == -1)size = BUFFER_SIZE;
bufferIdx = 0;
}
return (char) buffer[bufferIdx++];
}
}
}
| Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | f30e003ebad1a6ebc7e2579003cb54db | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
/*
public class _515D {
}
*/
public class _515D {
class ver {
int i;
int j;
int d;
public ver(int i, int j, int d) {
super();
this.i = i;
this.j = j;
this.d = d;
}
}
public void solve() throws FileNotFoundException {
InputStream inputStream = System.in;
InputHelper in = new InputHelper(inputStream);
// actual solution
int n = in.readInteger();
int m = in.readInteger();
String[] mat = new String[n];
for (int i = 0; i < n; i++) {
mat[i] = in.read();
}
boolean[][] vis = new boolean[n][m];
int[][] deg = new int[n][m];
PriorityQueue<ver> pq = new PriorityQueue<ver>((v1, v2) -> v1.d - v2.d);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mat[i].charAt(j) == '*') {
continue;
}
List<ver> cvl = caldeg(mat, i, j, vis, n, m);
deg[i][j] = cvl.size();
if (deg[i][j] == 0) {
System.out.println("Not unique");
return;
}
if (deg[i][j] == 1) {
pq.add(new ver(i, j, 1));
}
}
}
StringBuilder[] ans = new StringBuilder[n];
for (int i = 0; i < n; i++) {
ans[i] = new StringBuilder(mat[i]);
}
while (!pq.isEmpty()) {
ver cv = pq.poll();
if (cv.d != deg[cv.i][cv.j] || vis[cv.i][cv.j]) {
continue;
}
vis[cv.i][cv.j] = true;
List<ver> vl = caldeg(mat, cv.i, cv.j, vis, n, m);
assert vl.size() == 1;
ver nv = vl.get(0);
putans(ans, cv.i, cv.j, nv);
vis[nv.i][nv.j] = true;
List<ver> nvl = caldeg(mat, nv.i, nv.j, vis, n, m);
for (int i = 0; i < nvl.size(); i++) {
ver nv2 = nvl.get(i);
if (!vis[nv2.i][nv2.j]) {
--deg[nv2.i][nv2.j];
if (deg[nv2.i][nv2.j] == 1)
pq.add(new ver(nv2.i, nv2.j, deg[nv2.i][nv2.j]));
}
}
}
StringBuilder fans = new StringBuilder();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!vis[i][j] && mat[i].charAt(j) == '.') {
System.out.println("Not unique");
return;
}
}
}
for (int i = 0; i < n; i++) {
fans.append(ans[i].toString());
fans.append("\n");
}
System.out.println(fans.toString());
// end here
}
void putans(StringBuilder[] ans, int i, int j, ver ver) {
if (ver.i < i) {
ans[ver.i].replace(ver.j, ver.j + 1, "^");
ans[i].replace(j, j + 1, "v");
} else if (ver.i > i) {
ans[ver.i].replace(ver.j, ver.j + 1, "v");
ans[i].replace(j, j + 1, "^");
} else {
if (ver.j < j) {
ans[ver.i].replace(ver.j, ver.j + 1, "<");
ans[i].replace(j, j + 1, ">");
} else {
ans[ver.i].replace(ver.j, ver.j + 1, ">");
ans[i].replace(j, j + 1, "<");
}
}
}
List<ver> caldeg(String[] mat, int i, int j, boolean[][] vis, int n, int m) {
List<ver> vl = new ArrayList<ver>();
if (valid(i - 1, j, mat, vis, n, m)) {
vl.add(new ver(i - 1, j, -1));
}
if (valid(i, j - 1, mat, vis, n, m)) {
vl.add(new ver(i, j - 1, -1));
}
if (valid(i, j + 1, mat, vis, n, m)) {
vl.add(new ver(i, j + 1, -1));
}
if (valid(i + 1, j, mat, vis, n, m)) {
vl.add(new ver(i + 1, j, -1));
}
return vl;
}
boolean valid(int i, int j, String[] mat, boolean[][] vis, int n, int m) {
if (i >= 0 && i < n && j >= 0 && j < m) {
if (mat[i].charAt(j) == '.' && !vis[i][j])
return true;
}
return false;
}
public static void main(String[] args) throws FileNotFoundException {
(new _515D()).solve();
}
class InputHelper {
StringTokenizer tokenizer = null;
private BufferedReader bufferedReader;
public InputHelper(InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
bufferedReader = new BufferedReader(inputStreamReader, 16384);
}
public String read() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
String line = bufferedReader.readLine();
if (line == null) {
return null;
}
tokenizer = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
public Integer readInteger() {
return Integer.parseInt(read());
}
public Long readLong() {
return Long.parseLong(read());
}
}
}
| Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | 18355e3ffa651b1bdc4caf05fec65238 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | //package codeForcesTry;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class D515_DrazilTiles implements Closeable {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
StringTokenizer stringTokenizer;
String next() throws IOException {
while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
stringTokenizer = new StringTokenizer(reader.readLine());
}
return stringTokenizer.nextToken();
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
//char nextChar() throws IOException {
//return (Character) null;
// }
public void solve()throws IOException {
int rows = nextInt();
int cols = nextInt();
board=new char[rows][cols];
for(int i=0;i<rows;i++){
String x=next();
for(int j=0;j<cols;j++){
board[i][j]=x.charAt(j);
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (board[i][j] == '.') {
force(i, j);
}
}
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (board[i][j] == '.') {
writer.println("Not unique");
return;
}
}
}
for (int i = 0; i < rows; i++) {
writer.println(new String(board[i]));
}
}
public void force(int row, int col) {
int mask = 0;
for (int i = 0; i < 4; i++) {
if (empty(row + dr[i], col + dc[i])) {
mask |= (1 << i);
// System.out.println(mask);
}
}
if (Integer.bitCount(mask) != 1) {
return;
}
if (mask == 1) {
board[row][col] = 'v';
row--;
board[row][col] = '^';
}
if (mask == 2) {
board[row][col] = '>';
col--;
board[row][col] = '<';
}
if (mask == 4) {
board[row][col] = '^';
row++;
board[row][col] = 'v';
}
if (mask == 8) {
board[row][col] = '<';
col++;
board[row][col] = '>';
}
for (int i = 0; i < 4; i++) {
if (empty(row + dr[i], col + dc[i])) {
force(row + dr[i], col + dc[i]);
}
}
}
public boolean empty(int row, int col) {
return row > -1 && row < board.length && col > -1 && col < board[0].length && board[row][col] == '.';
}
public final int[] dr = { -1, 0, 1, 0 };
public final int[] dc = { 0, -1, 0, 1 };
public char[][] board;
public static void main(String args[]) throws IOException{
try(D515_DrazilTiles c=new D515_DrazilTiles()){
c.solve();
}
}
public void close() throws IOException {
reader.close();
writer.close();
}
}
| Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | ae1a9bba9529794d89114a80da239210 | train_001.jsonl | 1424190900 | Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".Drazil found that the constraints for this task may be much larger than for the original task!Can you solve this new problem?Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task. | 256 megabytes | import java.io.*;
import java.util.*;
public class D {
public D()
{
Scanner s = new Scanner();
boolean debug = false;
int n = s.nextInt();
int m = s.nextInt();
char [][] chars = new char[n][m];
for (int i = 0; i < n; i++) {
String str = s.next();
for (int j = 0; j < m ;j++) {
chars[i][j] = str.charAt(j);
}
}
Queue<Loc> ones = new ArrayDeque<Loc>();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m ;j++) {
if (degree(chars, i, j) == 1) {
ones.add(new Loc(i,j));
}
}
}
while (!ones.isEmpty()) {
if (debug) {
print(chars);
s.readNextLine();
}
Loc one = ones.poll();
ArrayList<Loc> neigh = neighbors(chars, one.x, one.y);
if (debug) {
System.out.println(one);
}
if (neigh.size() > 0 && chars[one.x][one.y] == '.' && neigh.size() < 2) {
Loc two = neigh.get(0);
if (debug) {
System.out.println(two);
}
if (one.x > two.x) {
chars[one.x][one.y] = 'v';
chars[two.x][two.y] = '^';
}
else if (one.x < two.x) {
chars[one.x][one.y] = '^';
chars[two.x][two.y] = 'v';
}
else if (one.y < two.y) {
chars[one.x][one.y] = '<';
chars[two.x][two.y] = '>';
}
else if (one.y > two.y) {
chars[one.x][one.y] = '>';
chars[two.x][two.y] = '<';
}
ArrayList<Loc> meh = neighbors(chars, two.x, two.y);//*
ones.addAll(meh);
}
}
boolean b = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m ;j++) {
if (chars[i][j] == '.') {
b = false;
}
}
}
StringBuffer sb = new StringBuffer();
if (!b) {
System.out.println("Not unique");
}
else {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m ;j++) {
sb.append(chars[i][j]);
}
sb.append("\n");
}
}
System.out.print(sb);
}
public void print(char[][] grid) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length ;j++) {
sb.append(grid[i][j]);
}
sb.append("\n");
}
System.out.println(sb);
}
public int degree(char[][] grid, int r, int c) {
int count = 0;
if (r > 0 && grid[r-1][c] == '.') {
count++;
}
if (r < grid.length - 1 && grid[r+1][c] == '.') {
count++;
}
if (c < grid[0].length - 1 && grid[r][c + 1] == '.') {
count++;
}
if (c > 0 && grid[r][c - 1] == '.') {
count++;
}
if (grid[r][c] != '.') {
return 0;
}
return count;
}
public ArrayList<Loc> neighbors(char[][] grid, int r, int c) {
ArrayList<Loc> neighbors = new ArrayList<Loc>();
if (r > 0 && grid[r-1][c] == '.') {
neighbors.add(new Loc(r - 1, c));
}
if (r < grid.length - 1 && grid[r+1][c] == '.') {
neighbors.add(new Loc(r + 1, c));
}
if (c < grid[0].length - 1 && grid[r][c + 1] == '.') {
neighbors.add(new Loc(r, c + 1));
}
if (c > 0 && grid[r][c - 1] == '.') {
neighbors.add(new Loc(r, c - 1));
}
// if (grid[r][c] != '.') {
// return new ArrayList<Loc>();
// }
return neighbors;
}
public static void main(String[] args) {
new D();
}
public static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(Reader in) {
br = new BufferedReader(in);
}
public Scanner() {
this(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
// Slightly different from java.util.Scanner.nextLine(),
// which returns any remaining characters in current line,
// if any.
String readNextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] readNextLineInts(int numberOfInts) {
int[] ints = new int[numberOfInts];
for (int i = 0; i < numberOfInts; i++)
ints[i] = nextInt();
return ints;
}
public double[] readNextLineDoubles(int numberOfDoubles) {
double[] doubles = new double[numberOfDoubles];
for (int i = 0; i < numberOfDoubles; i++)
doubles[i] = nextDouble();
return doubles;
}
// --------------------------------------------------------
}
public class Loc implements Comparable<Loc>, Cloneable
{
public int x, y;
public Loc(int x, int y)
{
this.x = x;
this.y = y;
}
public int compareTo(Loc other) {
return this.x - other.x;
}
public boolean equals(Object other)
{
return other instanceof Loc && ((Loc)other).x == this.x
&& ((Loc)other).y == this.y;
}
public Loc clone()
{
return new Loc(this.x, this.y);
}
public String toString()
{
return x + " " + y;
}
}
} | Java | ["3 3\n...\n.*.\n...", "4 4\n..**\n*...\n*.**\n....", "2 4\n*..*\n....", "1 1\n.", "1 1\n*"] | 2 seconds | ["Not unique", "<>**\n*^<>\n*v**\n<><>", "*<>*\n<><>", "Not unique", "*"] | NoteIn the first case, there are indeed two solutions:<>^^*vv<>and^<>v*^<>vso the answer is "Not unique". | Java 8 | standard input | [
"constructive algorithms",
"greedy"
] | 9465c37b6f948da14e71cc96ac24bb2e | The first line contains two integers n and m (1 ≤ n, m ≤ 2000). The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied. | 2,000 | If there is no solution or the solution is not unique, you should print the string "Not unique". Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example. | standard output | |
PASSED | af97b43b1212baaaef1c0eaacfa4a8a9 | train_001.jsonl | 1558884900 | Toad Ivan has $$$m$$$ pairs of integers, each integer is between $$$1$$$ and $$$n$$$, inclusive. The pairs are $$$(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$$$. He asks you to check if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. | 256 megabytes |
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
static class Pair{
int a,b;
Pair(int a,int b){
this.a=a;
this.b=b;
}
}
public static void process()throws IOException
{
int n=ni(),m=ni();
Pair arr[]=new Pair[m+1];
for(int i=1;i<=m;i++)
arr[i]=new Pair(ni(),ni());
int f[]=new int[n+1];
int ans1=arr[1].a;
f[ans1]++;
for(int i=2;i<=m;i++){
if(arr[i].a==ans1 || arr[i].b==ans1)
f[ans1]++;
else{
f[arr[i].a]++;
f[arr[i].b]++;
}
}
for(int i=1;i<=n;i++){
if (ans1==i) {
continue;
}
if(f[i]+f[ans1]>=m){
pn("YES");
return;
}
}
Arrays.fill(f,0);
ans1=arr[1].b;
f[ans1]++;
for(int i=2;i<=m;i++){
if(arr[i].a==ans1 || arr[i].b==ans1)
f[ans1]++;
else{
f[arr[i].a]++;
f[arr[i].b]++;
}
}
for(int i=1;i<=n;i++){
if (ans1==i) {
continue;
}
if(f[i]+f[ans1]>=m){
pn("YES");
return;
}
}
pn("NO");
}
static AnotherReader sc;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj)
sc=new AnotherReader();
else
sc=new AnotherReader(100);
int t=1;
while(t-->0)
process();
System.out.flush();
System.out.close();
}
static void pn(Object o){System.out.println(o);}
static void p(Object o){System.out.print(o);}
static void pni(Object o){System.out.println(o);System.out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
static boolean multipleTC=false;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.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()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
| Java | ["4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 4\n1 2\n2 3\n3 4\n4 5", "300000 5\n1 2\n1 2\n1 2\n1 2\n1 2"] | 2 seconds | ["NO", "YES", "YES"] | NoteIn the first example, you can't choose any $$$x$$$, $$$y$$$ because for each such pair you can find a given pair where both numbers are different from chosen integers.In the second example, you can choose $$$x=2$$$ and $$$y=4$$$.In the third example, you can choose $$$x=1$$$ and $$$y=2$$$. | Java 11 | standard input | [
"implementation",
"graphs"
] | 60af9947ed99256a2820814f1bf1c6c6 | The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq m \leq 300\,000$$$) — the upper bound on the values of integers in the pairs, and the number of given pairs. The next $$$m$$$ lines contain two integers each, the $$$i$$$-th of them contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) — the integers in the $$$i$$$-th pair. | 1,500 | Output "YES" if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 05fb52aea60a44751d7df442d4ea5e68 | train_001.jsonl | 1558884900 | Toad Ivan has $$$m$$$ pairs of integers, each integer is between $$$1$$$ and $$$n$$$, inclusive. The pairs are $$$(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$$$. He asks you to check if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class GFG {
static class edge{
int s,d,w;
public edge(int s,int d,int w)
{
this.s=s;
this.d=d;
this.w=w;
}
}
static class graph{
int v;
LinkedList<edge> li[];
boolean visit[];
boolean visit1[];
int arr[];
public graph(int v)
{
this.v=v;
visit=new boolean[v];
visit1=new boolean[v];
arr=new int[v];
li=new LinkedList[v];
for(int i=0;i<v;i++)
li[i]=new LinkedList<>();
}
public void addedge(int x,int y,int w)
{
edge e=new edge(x,y,w);
li[x].add(e);
edge e1=new edge(y,x,w);
li[y].add(e1);
}
public void removeedge(int x,int y,int w)
{
Iterator<edge> it =li[x].iterator();
while (it.hasNext()) {
if (it.next().d == y) {
it.remove();
break;
}
}
Iterator<edge> it1 =li[y].iterator();
while (it1.hasNext()) {
if (it1.next().d == x) {
it1.remove();
return;
}
}
}
public boolean hasEdge(int i, int j) {
return li[i].contains(j);
}
public int con(int s)
{
return li[s].size();
}
public HashSet<Integer> get(int s)
{
HashSet<Integer> h=new HashSet<Integer>();
Iterator<edge> i=li[s].listIterator();
while(i.hasNext()){
h.add(i.next().d);}
return h;
}
public int bfs(int s,int t,int c)
{
LinkedList<Integer> q=new LinkedList<Integer>();
visit[s]=true;
q.add(s);
while(q.size()!=0){
s=q.poll();
Iterator<edge> i=li[s].listIterator();
Iterator<edge> i1=li[s].listIterator();
while(i.hasNext()&&i1.hasNext()){int n=i.next().d;
int k=i1.next().w;
if(k!=c)
return 0;
if(n==t)
break;
if(!visit[n]){visit[n]=true;c++;q.add(n);}
}
}
return 1;
}
}
public static void main (String[] args)throws IOException {
Reader sc=new Reader();
int n=sc.nextInt();
int m=sc.nextInt();
//int k=sc.nextInt();
//graph g=new graph(n);
HashSet<Integer> h=new HashSet<Integer>();
int arr[][]=new int[m][2];
for(int i=0;i<m;i++)
{
int x=sc.nextInt();
int y=sc.nextInt();
arr[i][0]=x;
arr[i][1]=y;
h.add(x);
h.add(y);
//int w=sc.nextInt();
//g.addedge(x-1,y-1,0);
}
int b[]=new int[2];
for(int i=0;i<2;i++)
{
int k=arr[0][i];
int j=0;
for( j=1;j<m;j++)
{
if(arr[j][0]!=k&&arr[j][1]!=k)
break;
}
int pos=j;
if(j==m){
b[i]=1;continue;}
int f=0;
for(j=0;j<2;j++)
{
int x=arr[pos][j];f=0;
for(int p=pos+1;p<m;p++)
{
if(arr[p][0]!=k&&arr[p][1]!=k&&arr[p][0]!=x&&arr[p][1]!=x){f=1;
break;}
}
if(f==0){
b[i]=1;break;}
}
}
if(b[0]==1||b[1]==1)
System.out.println("YES");
else
System.out.println("NO");
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
} | Java | ["4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 4\n1 2\n2 3\n3 4\n4 5", "300000 5\n1 2\n1 2\n1 2\n1 2\n1 2"] | 2 seconds | ["NO", "YES", "YES"] | NoteIn the first example, you can't choose any $$$x$$$, $$$y$$$ because for each such pair you can find a given pair where both numbers are different from chosen integers.In the second example, you can choose $$$x=2$$$ and $$$y=4$$$.In the third example, you can choose $$$x=1$$$ and $$$y=2$$$. | Java 11 | standard input | [
"implementation",
"graphs"
] | 60af9947ed99256a2820814f1bf1c6c6 | The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq m \leq 300\,000$$$) — the upper bound on the values of integers in the pairs, and the number of given pairs. The next $$$m$$$ lines contain two integers each, the $$$i$$$-th of them contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) — the integers in the $$$i$$$-th pair. | 1,500 | Output "YES" if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 419545118bca3d86896f1c1182aaf562 | train_001.jsonl | 1558884900 | Toad Ivan has $$$m$$$ pairs of integers, each integer is between $$$1$$$ and $$$n$$$, inclusive. The pairs are $$$(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$$$. He asks you to check if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
// printArr() - prints the array
// intList, doubleList, longList
// nextIntArray
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
*/
public class current {
public static void main(String[] args) {
FastReader fr = new FastReader();
// DO NOT FORGET TO REMOVE WHILE LOOP!!!!!!!!!!!!!!!
//while (true) {
int a = fr.getInt(1);
int[][] mat = new int[a][2];
for (int i = 0; i < a; i++) {
int[] arr = fr.nextIntArray();
mat[i][0] = arr[0];
mat[i][1] = arr[1];
}
solve(mat);
//}
}
static void solve(int[][] mat) {
int l = mat.length;
Set<Integer> set = new HashSet<>();
for (int[] arr : mat) {
for (int j : arr) {
set.add(j);
}
}
int s = set.size();
if (s == 1 || s == 2) {
System.out.println("YES");
return;
}
if (s == 3) {
int c = 0;
for (int[] arr : mat) {
if (arr[0] == arr[1] && set.contains(arr[0])) {
c++;
set.remove(arr[0]);
}
}
if (c == 3) {
System.out.println("NO");
} else {
System.out.println("YES");
}
return;
}
// find distinct
// a b
// c d
// tests:
// a b
// a d
// c b
// c d
// runtime: O(n)
// if we cannot find distinct, print out NO
int a, b, c, d;
a = b = c = d = -1;
for (int[] arr : mat) {
if (arr[0] == arr[1]) {
continue;
}
if (a == -1 && b == -1) {
a = arr[0];
b = arr[1];
} else {
if (arr[0] == a || arr[0] == b || arr[1] == a || arr[1] == b) {
continue;
}
c = arr[0];
d = arr[1];
break;
}
}
int e, f, g, h;
e = f = g = h = 0;
// see if any of them have length equal to l
// so that we can do one for loop only
// guaranteed a, b, c, d are all unique
// a c
// b d
// a-c -> e
// a-d -> f
// b-c -> g
// b-d -> h
for (int[] arr : mat) {
int i = arr[0];
int j = arr[1];
if (c != -1) {
if (a == i || c == j || a == j || c == i) {
e++;
}
if (a == i || d == j || a == j || d == i) {
f++;
}
if (c == i || b == j || c == j || b == i) {
g++;
}
if (d == i || b == j || d == j || b == i) {
h++;
}
} else {
if (a == i || b == i || a == j || b == j) {
e++;
}
}
}
if (e == l || f == l || g == l || h == l) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
static class Coord {
public int x;
public int y;
public Coord (int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Coord coord = (Coord) o;
return x == coord.x && y == coord.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}
public static Set<Integer> get(List<Set<Integer>> graph, int i) {
try {
return graph.get(i);
} catch (IndexOutOfBoundsException e) {
return new HashSet<>();
}
}
public static void printArr(int[] a) {
System.out.println(Arrays.toString(a));
}
public static int[] bfs(List<Set<Integer>> graph, int v) {
int l = graph.size();
Deque<Integer> list = new ArrayDeque<>();
list.add(v);
boolean[] seen = new boolean[l];
int distance = 0;
int node = v;
int size = 1;
int index = 0;
// Iterate over every single vertice and edge
// O(V+E) -> O(V) for trees
while (!list.isEmpty()) {
int cur = list.poll();
seen[cur] = true;
node = cur;
index++;
if (index > size) {
distance++;
size = list.size();
index = 0;
}
for (int i : graph.get(cur)) {
if (!seen[i]) {
seen[i] = true;
list.add(i);
}
}
}
return new int[]{node, distance};
}
static class SegTree {
int startIndex, endIndex;
long sum;
SegTree lchild, rchild;
SegTree(int[] arr) {this(0, arr.length-1, arr);}
SegTree(int startIndex, int endIndex, int[] arr) {
this.startIndex = startIndex;
this.endIndex = endIndex;
if (startIndex == endIndex) sum = arr[startIndex];
else {
int mid = (startIndex + endIndex) / 2;
lchild = new SegTree(startIndex, mid, arr);
rchild = new SegTree(mid + 1, endIndex, arr);
sum = lchild.sum + rchild.sum;
recalc();
}
}
void recalc() {
if (startIndex == endIndex) return; sum = lchild.sum + rchild.sum;
}
public void valueUpdate(int index, int value) {
if (startIndex == endIndex) {sum = value; return;}
if (index > lchild.endIndex) rchild.valueUpdate(index, value); else lchild.valueUpdate(index, value); recalc();
}
public long rangeSum(int startIndex, int endIndex) {
if (endIndex < this.startIndex || startIndex > this.endIndex) return 0;
if (startIndex <= this.startIndex && endIndex >= this.endIndex) return sum;
return lchild.rangeSum(startIndex, endIndex) + rchild.rangeSum(startIndex, endIndex);
}
}
public static double sum(List<Long> n) {
double a = 0;
for (long i : n) {
a += i;
}
return a;
}
public static int toInt(String n) {
return Integer.parseInt(n);
}
public static double toDouble(String n) {
return Double.parseDouble(n);
}
public static long toLong(String n) {
return Long.parseLong(n);
}
static class FastReader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() {
while (st == null || !st.hasMoreElements()) {
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());
}
String nextLine() {
String a = "";
try {
a = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return a;
}
int[] nextIntArray() {
return intArray(nextLine().split(" "));
}
long[] nextLongArray() {
return longArray(nextLine().split(" "));
}
double[] nextDoubleArray() {
return doubleArray(nextLine().split(" "));
}
public int getInt(int index) {
String[] arr = nextLine().split(" ");
return Integer.parseInt(arr[index]);
}
public long getLong(int index) {
String[] arr = nextLine().split(" ");
return Long.parseLong(arr[index]);
}
public double getDouble(int index) {
String[] arr = nextLine().split(" ");
return Double.parseDouble(arr[index]);
}
public List<String> stringList() {
String[] arr = nextLine().split(" ");
return Arrays.asList(arr);
}
public List<Integer> intList() {
String[] arr = nextLine().split(" ");
List<Integer> a = new ArrayList<>();
for (String i : arr) {
a.add(Integer.parseInt(i));
}
return a;
}
public List<Double> doubleList() {
String[] arr = nextLine().split(" ");
List<Double> a = new ArrayList<>();
for (String i : arr) {
a.add(Double.parseDouble(i));
}
return a;
}
public List<Long> longList() {
String[] arr = nextLine().split(" ");
List<Long> a = new ArrayList<>();
for (String i : arr) {
a.add(Long.parseLong(i));
}
return a;
}
}
public static int[] intArray(String[] arr) {
int l = arr.length;
int[] a = new int[l];
for (int i = 0; i < l; i++) {
a[i] = Integer.parseInt(arr[i]);
}
return a;
}
public static long[] longArray(String[] arr) {
int l = arr.length;
long[] a = new long[l];
for (int i = 0; i < l; i++) {
a[i] = Long.parseLong(arr[i]);
}
return a;
}
public static double[] doubleArray(String[] arr) {
int l = arr.length;
double[] a = new double[l];
for (int i = 0; i < l; i++) {
a[i] = Double.parseDouble(arr[i]);
}
return a;
}
} | Java | ["4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 4\n1 2\n2 3\n3 4\n4 5", "300000 5\n1 2\n1 2\n1 2\n1 2\n1 2"] | 2 seconds | ["NO", "YES", "YES"] | NoteIn the first example, you can't choose any $$$x$$$, $$$y$$$ because for each such pair you can find a given pair where both numbers are different from chosen integers.In the second example, you can choose $$$x=2$$$ and $$$y=4$$$.In the third example, you can choose $$$x=1$$$ and $$$y=2$$$. | Java 11 | standard input | [
"implementation",
"graphs"
] | 60af9947ed99256a2820814f1bf1c6c6 | The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq m \leq 300\,000$$$) — the upper bound on the values of integers in the pairs, and the number of given pairs. The next $$$m$$$ lines contain two integers each, the $$$i$$$-th of them contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) — the integers in the $$$i$$$-th pair. | 1,500 | Output "YES" if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | d409b62f11a03578c6fa55effdbdda78 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main
{
public static void main(String[] args) {
new Thread(null, new Runnable() {
public void run() {
solve();
}
}, "1", 1 << 26).start();
}
static void solve () {
FastReader fr =new FastReader(); PrintWriter op =new PrintWriter(System.out);
int t =fr.nextInt() ,n ,belt[] ,i ,j ;
boolean mrk[] ;
String s ;
char c ;
while (t-- > 0) {
n =fr.nextInt() ;
belt =new int[n] ;
mrk =new boolean[n] ;
s =fr.next() ;
for (i =0 ; i<n ; ++i) {
c =s.charAt(i) ;
if (c == '-') {
belt[i] =0 ;
mrk[i] =mrk[(i+1)%n] =true ;
}
else if (c == '>')
belt[i] =1 ;
else
belt[i] =-1 ;
}
for (i =0 ; i<n ; ++i) {
if (belt[i] == -1)
break;
}
for (j =n-1 ; j>-1 ; --j) {
if (belt[j] == 1)
break;
}
if (i==n || j==-1)
op.println(n) ;
else {
for (i =j =0 ; i<n ; ++i) {
if (mrk[i]) ++j ;
}
op.println(j) ;
}
}
op.flush(); op.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br =new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st==null || (!st.hasMoreElements()))
{
try
{
st =new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str ="";
try
{
str =br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next()) ;
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 0a31e415d5471214e9f5577b2977b02f | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | /**/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants***********************************/
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static long mod=(long)1e9+7;
static long mod1=998244353;
static ArrayList<Integer> graph[];
static int pptr=0,pptrmax=0;
static String st[];
/*****************************************Solution Begins*********************************/
public static void main(String args[]) throws Exception{
int tt=pi();
while(tt-->0){
int n=pi();
char input[]=ps().toCharArray();
boolean vis[]=new boolean[n];
int ans=0;
for(int i=0;i<n;i++){
int nx=(i+1)%n;
if(input[i]=='-'){
if(!vis[i])ans++;
if(!vis[nx])ans++;
vis[i]=true;
vis[nx]=true;
}
}
boolean flag=true;
for(int i=0;i<n;i++){
if(input[i]=='-' || input[i]=='<')continue;
else flag=false;
}
if(!flag){
flag=true;
for(int i=0;i<n;i++){
if(input[i]=='-' || input[i]=='>')continue;
else flag=false;
}
}
if(flag)ans=n;
out.println(ans);
}
/****************************************Solution Ends*************************************/
clr();
}
static void clr(){
out.flush();
out.close();
}
static void nl() throws Exception{
pptr=0;
st=br.readLine().split(" ");
pptrmax=st.length;
}
static void nls() throws Exception{
pptr=0;
st=br.readLine().split("");
pptrmax=st.length;
}
static int pi() throws Exception{
if(pptr==pptrmax)
nl();
return Integer.parseInt(st[pptr++]);
}
static long pl() throws Exception{
if(pptr==pptrmax)
nl();
return Long.parseLong(st[pptr++]);
}
static double pd() throws Exception{
if(pptr==pptrmax)
nl();
return Double.parseDouble(st[pptr++]);
}
static String ps() throws Exception{
if(pptr==pptrmax)
nl();
return st[pptr++];
}
/***************************************Precision Printing*********************************/
static void printPrecision(double d){
DecimalFormat ft = new DecimalFormat("0.00000000000");
out.println(ft.format(d));
}
/**************************************Bit Count************************************/
static int countBit(long mask){
int ans=0;
while(mask!=0){
mask&=(mask-1);
ans++;
}
return ans;
}
/******************************************Graph******************************************/
static void Makegraph(int n){
graph=new ArrayList[n];
for(int i=0;i<n;i++)
graph[i]=new ArrayList<>();
}
static void addEdge(int a,int b){
graph[a].add(b);
}
// static void addEdge(int a,int b,int c){
// graph[a].add(new Pair(b,c));
// }
/******************************************Pair*****************************************/
static class Pair{
int u;
int v;
public Pair(int u, int v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return u == other.u && v == other.v;
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/*****************************************DEBUG********************************************/
public static void debug(Object... o){
System.err.println(Arrays.deepToString(o));
}
/************************************Modular Exponentiation********************************/
static long modulo(long a,long b,long c){
long x=1,y=a%c;
while(b > 0){
if(b%2 == 1)
x=(x*y)%c;
y = (y*y)%c;
b = b>>1;
}
return x%c;
}
/********************************************GCD*******************************************/
static long gcd(long x, long y){
if(x==0)
return y;
if(y==0)
return x;
long r=0, a, b;
a = (x > y) ? x : y;
b = (x < y) ? x : y;
r = b;
while(a % b != 0){
r = a % b;
a = b;
b = r;
}
return r;
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | e9d10545e6e45099c774eb641b812034 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | // Working program with FastReader
import java.io.*;
import java.util.*;
public class ProblemB
{
static PrintWriter out;
static FastReader sc;
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch(IOException e){
e.printStackTrace();
}
return str;
}
}
public static void runTest(){
int n = sc.nextInt();
String s = sc.next();
//Check reachability
//2 cases:
//Full cycle --> all reachable
//Check if neighbour belts have -
//full cycle check
int i = 0;
int prev = (n + i - 1) % n;
int next = (i + 1) % n;
int nextBelt = i;
int prevBelt = prev;
int reachable = 0;
//Check clockwise
int j = i;
while(next != i){
if(s.charAt(nextBelt) == '>' || s.charAt(nextBelt) == '-'){
j = next;
next = (j + 1) % n;
nextBelt = j;
}
else
break;
}
if(next == i){
if(s.charAt(nextBelt) == '>' || s.charAt(nextBelt) == '-'){
out.println(n);
return;
}
}
//Check anti-clockwise
j = i;
while(prev != i){
if(s.charAt(prevBelt) == '<' || s.charAt(prevBelt) == '-'){
j = prev;
prev = (n + j - 1) % n;
prevBelt = prev;
}
else
break;
}
if(prev == i){
if(s.charAt(prevBelt) == '<' || s.charAt(prevBelt) == '-'){
out.println(n);
return;
}
}
//Count paths with -
for(int k = 0; k < n;k++){
prev = (n + k - 1) % n;
next = (k + 1) % n;
nextBelt = k;
prevBelt = prev;
if(s.charAt(nextBelt) == '-' || s.charAt(prevBelt) == '-'){
reachable++;
}
}
out.println(reachable);
}
public static void main(String args[]){
sc = new FastReader();
out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t > 0){
runTest();
out.flush();
t--;
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 9e85e7d591b312640581841e8b2dc09b | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
while(sc.hasNext())
{
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
String s=sc.next();
boolean hasCW = false;
boolean hasACW = false;
for(int i = 0;i < n;i++)
{
if(s.charAt(i)== '<') hasCW = true;
if(s.charAt(i)== '>') hasACW = true;
}
if(hasCW && hasACW)
{
int ans = 0;
s+=s.charAt(0);
for(int i = 0;i <n;i++)
{
if(s.charAt(i)== '-' ||s.charAt(i+1)=='-') ans++;
}
System.out.println(ans);
}
else
System.out.println(n);
}
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | b290f34573378f89490a6436f7fd1723 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
import java.io.*;
import java.text.*;
public class CF_1428_B{
//SOLUTION BEGIN
void pre() throws Exception{}
void solve(int TC) throws Exception{
int N = ni();
String s = n();
int ans = 0;
int mask = 0;
for(int i = 0; i< N; i++){
if(s.charAt(i) == '-' || s.charAt((i+1)%N) == '-')ans++;
if(s.charAt(i) == '<')mask |= 1;
if(s.charAt(i) == '>')mask |= 2;
}
if(mask != 3)ans = N;
pn(ans);
}
//SOLUTION END
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
void exit(boolean b){if(!b)System.exit(0);}
static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}
final long IINF = (long)1e17;
final int INF = (int)1e9+2;
DecimalFormat df = new DecimalFormat("0.00000000000");
double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
static boolean multipleTC = true, memory = true, fileIO = false;
FastReader in;PrintWriter out;
void run() throws Exception{
long ct = System.currentTimeMillis();
if (fileIO) {
in = new FastReader("");
out = new PrintWriter("");
} else {
in = new FastReader();
out = new PrintWriter(System.out);
}
//Solution Credits: Taranpreet Singh
int T = multipleTC? ni():1;
pre();
for (int t = 1; t <= T; t++) solve(t);
out.flush();
out.close();
System.err.println(System.currentTimeMillis() - ct);
}
public static void main(String[] args) throws Exception{
if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1428_B().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start();
else new CF_1428_B().run();
}
int[][] make(int n, int e, int[] from, int[] to, boolean f){
int[][] g = new int[n][];int[]cnt = new int[n];
for(int i = 0; i< e; i++){
cnt[from[i]]++;
if(f)cnt[to[i]]++;
}
for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
for(int i = 0; i< e; i++){
g[from[i]][--cnt[from[i]]] = to[i];
if(f)g[to[i]][--cnt[to[i]]] = from[i];
}
return g;
}
int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){
int[][][] g = new int[n][][];int[]cnt = new int[n];
for(int i = 0; i< e; i++){
cnt[from[i]]++;
if(f)cnt[to[i]]++;
}
for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
for(int i = 0; i< e; i++){
g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};
if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};
}
return g;
}
int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
void p(Object... o){for(Object oo:o)out.print(oo+" ");}
void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?" ":"\n"));}
void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();}
String n()throws Exception{return in.next();}
String nln()throws Exception{return in.nextLine();}
int ni()throws Exception{return Integer.parseInt(in.next());}
long nl()throws Exception{return Long.parseLong(in.next());}
double nd()throws Exception{return Double.parseDouble(in.next());}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception{
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception{
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}catch (IOException e){
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception{
String str;
try{
str = br.readLine();
}catch (IOException e){
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 9e30f1d45b593e0399031577e69a224d | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | /*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
import java.util.*;
import java.awt.List;
import java.io.*;
public class d {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int ie=0;ie<t;ie++) {
int n=s.nextInt();
char[] arr=s.next().toCharArray();
int ans=0;
HashMap<Integer,Integer> map=new HashMap<>();
for(int i=0;i<n;i++) {
if(arr[i]=='-') {
map.put(i, 1);
map.put((i+1)%n, 1);
}
}
ans=ans+map.size();
int g=0;
int td=0;
for(int i=0;i<n;i++) {
if(arr[i]=='>') {
g++;
}
if(arr[i]=='<') {
td++;
}
}
if(g>=1 && td>=1) {
System.out.println(ans);
}else {
System.out.println(n);
}
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | e3d2d82a7ed489d5686603ce01fce471 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class Codeforces{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
PrintWriter out =new PrintWriter(System.out);
StringTokenizer st =new StringTokenizer("");
String next(){
if(!st.hasMoreTokens()){
try{
st=new StringTokenizer(br.readLine());
}
catch(Exception e){
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
public static void main(String[] args) {
new Codeforces().solve();
}
void solve(){
int t=nextInt();
while(t-->0){
int n=nextInt();
char arr[]=next().toCharArray();
boolean flag=true;
boolean left =false,right=false;
for(int i=0;i<n;i++){
if(arr[i]=='<' && left){
flag=false;
break;
}
if(arr[i]=='>' && right)
{
flag=false;
break;
}
if(arr[i]=='<'){
right=true;
}
if(arr[i]=='>'){
left=true;
}
}
if(flag) out.println(n);
else{
Set<Integer> set =new HashSet<>();
for(int i=0;i<n;i++){
if(arr[i]=='-')
{
set.add(i);
set.add((i+1+n)%n);
}
}
// out.println(set);
out.println(set.size());
}
}
out.close();
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 68f692dcde9bbf6824af2cef86138263 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
public class Beltedroom {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
while (t-->0) {
int n=scan.nextInt();
Set<Integer> set=new HashSet<>();
String s=scan.next();
Set<Character> ch=new HashSet<>();
for(int i=0;i<n;i++) {
if(s.charAt(i)=='-') {
set.add(i);
set.add((i+1) %n);
}else {
ch.add(s.charAt(i));
}
}
if(ch.size()==1) {
System.out.println(n);
}else {
System.out.println(set.size());
}
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 091600290c3895c212e9f6eb3fc22587 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = sc.nextInt();
for(int t = 0; t<T; t++){
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
int cnt = 0;
boolean flag = false;
for(int i = 0; i<n; i++){
if(s.charAt(i) != '<' && s.charAt(i) != '-'){
flag = true;
}
}
boolean flag1 = false;
for(int i = 0; i<n; i++){
if(s.charAt(i) != '>' && s.charAt(i) != '-'){
flag1 = true; break;
}
}
for(int i = 0; i<n; i++){
if(s.charAt(i) == '-' || s.charAt((i + 1) % n) == '-')cnt++;
}
if(!flag || !flag1)out.println(n);
else out.println(cnt);
}
out.flush();
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 2d7b6b3ef0054f43e4b0eca2cc3f3803 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes |
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
for (int g = 0; g < t; g++) {
int n = in.nextInt();
String s = in.next();
int count = 0;
int dir = -1;
boolean f = true;
for (int i = 0; i < n; i++) {
if(s.charAt(i) == '-'){
//debug(dir, count, "--");
count++;
} else if((dir == 0 && s.charAt(i) == '>') || (dir == 1 && s.charAt(i) == '<')){
f = false;
} else if(dir == -1){
dir = (s.charAt(i) == '>')?1:0;
}
if(s.charAt(i) == '>' || s.charAt(i) == '<'){
if(i == 0 && s.charAt(n-1) == '-') count++;
else if(i != 0 && s.charAt(i-1) == '-') count++;
}
}
if(f){
out.println(n);
} else {
out.println(count);
}
//out.println(count);
}
out.flush();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
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());
}
}
static void debug(Object... o) {
System.err.println(Arrays.deepToString(o));
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 57831eecc43cc4bc66f9d32d4671905b | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | // Utilities
import java.io.*;
import java.util.*;
public class Main {
static int T;
static int N;
static char[] ch;
static Boolean[] b;
static int cntAntiClockwise, cntClockwise, cntZ;
static int cnt;
public static void main(String[] args) throws IOException {
T = in.iscan();
while (T-- > 0) {
N = in.iscan();
ch = in.sscan().toCharArray();
b = new Boolean[N];
cntAntiClockwise = 0; cntClockwise = 0; cntZ = 0;
for (int i = 0; i < N; i++) {
if (ch[i] == '-') {
b[i] = true;
b[(i+1)%N] = true;
cntZ++;
}
else if (ch[i] == '>') {
cntClockwise++;
}
else {
cntAntiClockwise++;
}
}
if (cntClockwise == 0 || cntAntiClockwise == 0) {
out.println(N);
}
else {
cnt = 0;
for (int i = 0; i < N; i++) {
if (b[i] != null && b[i] == true) cnt++;
}
out.println(cnt);
}
}
out.close();
}
static INPUT in = new INPUT(System.in);
static PrintWriter out = new PrintWriter(System.out);
private static class INPUT {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar, numChars;
public INPUT (InputStream stream) {
this.stream = stream;
}
public INPUT (String file) throws IOException {
this.stream = new FileInputStream (file);
}
public int cscan () throws IOException {
if (curChar >= numChars) {
curChar = 0;
numChars = stream.read (buf);
}
if (numChars == -1)
return numChars;
return buf[curChar++];
}
public int iscan () throws IOException {
int c = cscan (), sgn = 1;
while (space (c))
c = cscan ();
if (c == '-') {
sgn = -1;
c = cscan ();
}
int res = 0;
do {
res = (res << 1) + (res << 3);
res += c - '0';
c = cscan ();
}
while (!space (c));
return res * sgn;
}
public String sscan () throws IOException {
int c = cscan ();
while (space (c))
c = cscan ();
StringBuilder res = new StringBuilder ();
do {
res.appendCodePoint (c);
c = cscan ();
}
while (!space (c));
return res.toString ();
}
public double dscan () throws IOException {
int c = cscan (), sgn = 1;
while (space (c))
c = cscan ();
if (c == '-') {
sgn = -1;
c = cscan ();
}
double res = 0;
while (!space (c) && c != '.') {
if (c == 'e' || c == 'E')
return res * UTILITIES.fast_pow (10, iscan ());
res *= 10;
res += c - '0';
c = cscan ();
}
if (c == '.') {
c = cscan ();
double m = 1;
while (!space (c)) {
if (c == 'e' || c == 'E')
return res * UTILITIES.fast_pow (10, iscan ());
m /= 10;
res += (c - '0') * m;
c = cscan ();
}
}
return res * sgn;
}
public long lscan () throws IOException {
int c = cscan (), sgn = 1;
while (space (c))
c = cscan ();
if (c == '-') {
sgn = -1;
c = cscan ();
}
long res = 0;
do {
res = (res << 1) + (res << 3);
res += c - '0';
c = cscan ();
}
while (!space (c));
return res * sgn;
}
public boolean space (int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
public static class UTILITIES {
static final double EPS = 10e-6;
public static int lower_bound (int[] arr, int x) {
int low = 0, high = arr.length, mid = -1;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] >= x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int upper_bound (int[] arr, int x) {
int low = 0, high = arr.length, mid = -1;
while (low < high) {
mid = (low + high) / 2;
if (arr[mid] > x)
high = mid;
else
low = mid + 1;
}
return low;
}
public static int gcd (int a, int b) {
return b == 0 ? a : gcd (b, a % b);
}
public static int lcm (int a, int b) {
return a * b / gcd (a, b);
}
public static long fast_pow_mod (long b, long x, int mod) {
if (x == 0) return 1;
if (x == 1) return b;
if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;
return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;
}
public static int fast_pow (int b, int x) {
if (x == 0) return 1;
if (x == 1) return b;
if (x % 2 == 0) return fast_pow (b * b, x / 2);
return b * fast_pow (b * b, x / 2);
}
public static long choose (long n, long k) {
k = Math.min (k, n - k);
long val = 1;
for (int i = 0; i < k; ++i)
val = val * (n - i) / (i + 1);
return val;
}
public static long permute (int n, int k) {
if (n < k) return 0;
long val = 1;
for (int i = 0; i < k; ++i)
val = (val * (n - i));
return val;
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | d5c732821feadf8a473567b0204b1a54 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
import java.io.*;
public class _1428B {
static int[] MODS = {1000000007, 998244353};
static int MOD = MODS[0];
public static void main(String[] args) {
sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String s = sc.next();
boolean clock = false;
boolean cock = false;
for (int i = 0; i < n; i++) {
if (s.charAt(i) == '>') {
clock = true;
}
if (s.charAt(i) == '<') {
cock = true;
}
}
if (clock && cock) {
int ans = 0;
for (int i = 0; i < n; i++) {
if (s.charAt(i) == '-' || s.charAt((i+1)%n) == '-') {
ans++;
}
}
out.println(ans);
}
else {
out.println(n);
}
}
out.close();
}
public static int[] sort(int[] arr) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++) {
list.add(arr[i]);
}
Collections.sort(list);
for (int i = 0; i < arr.length; i++) {
arr[i] = list.get(i);
}
return arr;
}
public static void scan(int[] arr) {
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
}
public static MyScanner sc;
public static PrintWriter out;
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 1f169f683858dbe7130af3a9225fc7ee | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.Scanner;
public class Snake {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
int m[]=new int [t];
int i,j;
for(i=0;i<t;i++)
{
int x=in.nextInt();
int f=0;
int d=0,e=0;
String s=in.next();
int l=s.length();
for(j=0;j<l;j++)
{
if(s.charAt(j)=='>')
d=1;
if(s.charAt(j)=='<')
e=1;
if(d==1&&e==1)
break;
}
if(d==1&&e==0)
m[i]=x;
else if(d==0&&e==1)
m[i]=x;
else{
for(j=0;j<l;j++)
{
if(j==0)
{
if(s.charAt(0)=='-'||s.charAt(l-1)=='-')
f++;
}
else
{
if(s.charAt(j)=='-'||s.charAt(j-1)=='-')
f++;
}
}
m[i]=f;
}}
for(i=0;i<t;i++)
System.out.println(m[i]);
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 72ba0cddfd02bf74825eb8641cde00bb | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.*;
import java.util.*;
public class BeltedRooms {
public static void main(String[] args) {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int n = in.nextInt();
char ch[] = in.next().toCharArray();
char prev = ch[n-1];
int a[] = new int[n];
boolean leftcycle = true, rightcycle = true;
for(int i=0;i<n;i++){
if(ch[i]=='-') continue;
if(ch[i]!='<') leftcycle = false;
if(ch[i]!='>') rightcycle = false;
}
if(leftcycle||rightcycle) out.println(n);
else{
int ans = 0;
for(int i=0;i<n;i++){
if(ch[i]=='-'||ch[(i+1)%n]=='-') ans++;
}
out.println(ans);
}
}
out.flush();
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 8a565f263f871aa1159db637ca379025 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes |
import java.io.*;
import java.util.*;
public class Rough{
static PrintWriter ww = new PrintWriter(System.out);
static boolean check(char arr[]){
for(int i = 1 ; i < arr.length ; i++){
if(arr[i] != arr[i - 1])return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int tt = sc.nextInt();
while(tt -- > 0){
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
char a[] = s.toCharArray();
char b[] = s.toCharArray();
char c[] = s.toCharArray();
for(int i = 0 ; i < n ; i ++){
if(a[i] == '-'){
a[i] = '<';
b[i] = '>';
}
}
if(check(a) || check(b)){
ww.println(n);
}
else{
boolean v[] = new boolean[n];
for(int i = 0 ; i < n ; i ++){
if(c[i] == '-'){
v[i] = true;
v[(i + 1)%n] = true;
}
}
int ans = 0;
for(boolean x : v)if(x)ans++;
ww.println(ans);
}
}
ww.close();
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 6fe699a044a109754d3769b05e49a302 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.math.BigInteger;
public final class codeforces
{
static StringBuilder ans=new StringBuilder();;
static FastReader in=new FastReader();
static ArrayList<ArrayList<Integer>> g=new ArrayList<ArrayList<Integer>>();
static long mod=1000000007;
static boolean set[];
//main method
//main method
//main method
//main method
public static void main(String args[])
{
int T=in.nextInt();
while(T-->0)
{
int N=in.nextInt();
String X=in.next();
if(X.contains(">") && X.contains("<"))
{
if(X.contains("-")==false)System.out.println(0);
else
{
//X=X.charAt(N-1)+X+X.charAt(0);
int count=0;
for(int i=0; i<N; i++)
{
char ch=X.charAt(i);
if(ch=='-')
{
int c=0;
while(X.charAt(i)=='-')
{
i++;
c++;
if(i==N)break;
}
count+=c+1;
//System.out.println(count);
}
}
if(X.charAt(0)==X.charAt(N-1) && X.charAt(0)=='-')count--;
System.out.println(count);
}
}
else System.out.println(N);
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean lucky(long a)
{
String X=a+"";
for(int i=0; i<X.length(); i++)
{
char ch=X.charAt(i);
if(ch!='4' && ch!='7')return false;
}
return true;
}
static long nextLucky(long x)
{
String X=x+"";
String y="";
boolean f=true;
for(int i=X.length()-1; i>=0; i--)
{
char ch=X.charAt(i);
if(ch=='4' && f)
{
y=7+y; f=false;
}
else if(f) y=4+y;
else y=ch+y;
}
if(f)
{
if(X.charAt(0)=='7')
y=4+y;
else y=4+X.substring(1);
}
return Long.parseLong(y);
}
static void setGraph(int N)//intialize graph here
{
for(int i=0; i<=N; i++)
g.add(new ArrayList<Integer>());
}
static void DFS(int N,int d)
{
set[N]=true;
d++;
//max=Math.max(max,d);
for(int i=0; i<g.get(N).size(); i++)
{
int c=g.get(N).get(i);
if(set[c]==false)
{
DFS(c,d);
}
}
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
//fucntions
//fucntions
//fucntions
//fucntions
static int[] input(int A[]) //input of Int Array
{
int N=A.length;
for(int i=0; i<N; i++)
{
A[i]=in.nextInt();
}
return A;
}
static long[] inputLong(int N) //Input of long Array
{
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
static int GCD(int a,int b) //wrong output if a ||b are intially zero
{
if(b==0)
{
return a;
}
else return GCD(b,a%b );
}
static boolean isPrime(int N)
{
for(int i=2; i*i<N; i++)
if(N%i==0)return false;
return true;
}
}
//Code For FastReader
//Code For FastReader
//Code For FastReader
//Code For FastReader
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 2726a271da42e62d42b590ce1ec6b409 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class H {
public static void main(String[] args) {
FastReader scan = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
int t = scan.nextInt();
for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
out.close();
}
static class Task {
public void solve(int testNumber, FastReader scan, PrintWriter out) {
int n = scan.nextInt();
char[] s = scan.next().toCharArray();
boolean onlyLeft = true, onlyRight = true;
for(char c : s) {
if(c == '<') onlyRight = false;
else if(c == '>') onlyLeft = false;
}
if(onlyLeft || onlyRight) {
out.println(n);
return;
}
int ans = 0;
for(int i = 0; i < n; i++) {
if(s[i] == '-' || s[(i + 1) % n] == '-') ans++;
}
out.println(ans);
}
}
static void ruffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
Arrays.sort(a);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws FileNotFoundException {
br = new BufferedReader(new FileReader(new File(s)));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | adcaca86829a491abd8fff5eb2bc1154 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int i=0;i<t;i++)
{
int n=s.nextInt();
String str=s.next();
int l=0;
int r=0;
for(int j=0;j<n;j++)
{
if(str.charAt(j)=='>')
r++;
else if(str.charAt(j)=='<')
l++;
}
if(l==0||r==0)
{
System.out.println(n);
}
else
{
int count=0;
for(int j=0;j<n;j++)
{
if(j==0)
{
if(str.charAt(j)=='-'||str.charAt(n-1)=='-')
count++;
}
else
{
if(str.charAt(j)=='-'||str.charAt(j-1)=='-')
count++;
}
}
System.out.println(count);
}
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 33110f070ade1c9fdf8bd47a0234c2ac | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
import java.io.*;
public class BeltedRooms {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve() throws IOException {
int t= ni();
for(int ii=0;ii<t;ii++)
{
int n= ni();
char[] ch= ns(n);
boolean clock= false, anti_clock= false;
for(char c: ch)
{
if(c== '<')
anti_clock= true;
else if(c== '>')
clock= true;
}
if(clock && anti_clock)
{
int ans=0;
for(int i=0;i<n;i++)
{
if(ch[(i-1+n)%n]=='-')
ans++;
else if(ch[i]=='-')
ans++;
}
out.println(ans);
}
else
out.println(n);
}
}
void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
solve();
out.flush();
}
public static void main(String[] args) throws Exception { new BeltedRooms().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 void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 14e494bc97aa8f1ad5c8b39aa8dbcb76 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
FastScanner sc =new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
int T=sc.nextInt();
while(T-- > 0) {
int n = sc.nextInt();
char[] s = sc.next().toCharArray();
if(cycle(s)) {
pw.println(n);
}else {
int ans = 0;
for(int i = 0; i < n; i++) {
int prev = (i == 0) ? n-1 : i-1;
ans += (s[i] == '-' || s[prev] =='-') ? 1 : 0;
}
pw.println(ans);
}
}
pw.close();
}
private static boolean cycle(char[] s) {
int sign1 = 0, sign2 = 0, sign3 = 0;
for(int i = 0; i < s.length; i++) {
sign1 += (s[i] == '>') ? 1 : 0;
sign2 += (s[i] == '<') ? 1 : 0;
sign3 += (s[i] == '-') ? 1 : 0;
}
if(sign1 > 0 && sign2 > 0) {
return false;
}
return true;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 32d9a527e7779e71ce48cdbe39f01cf6 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static final int mod=1000000007;
public static void main(String[] args) throws IOException {
//File filein = new File("input.txt");
//BufferedReader sc=new BufferedReader(new FileReader(filein));
//PrintWriter out=new PrintWriter(new FileWriter("output.txt"));
//Scanner sc=new Scanner(System.in);
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
int t=Integer.parseInt(sc.readLine());
while(t-->0) {
Map<Integer,Integer> mp=new HashMap<>();
Map<Integer,List<Integer>> g=new HashMap<>();
int n=Integer.parseInt(sc.readLine());
char[] arr=sc.readLine().toCharArray();
// 0 in ----- 1 out
int ac=0,cc=0;
for(char c:arr){
if(c=='>')cc++;
if(c=='<')ac++;
}
if(cc>0 && ac>0){
int cnt=0;
for(int i=1;i<n;i++){
if(arr[i-1]=='-' || arr[i]=='-'){
cnt++;
}
}
if(arr[0]=='-' || arr[n-1]=='-') cnt++;
out.println(cnt);
} else{
out.println(n);
}
out.flush();
}
out.close();
sc.close();
}
static boolean dfs(char[][] g,int i,int j,char sq){
if(i==g.length-1 && j==g.length-1) return true;
if(i>=g.length || j>=g.length || g[i][j]!=sq) return false;
return dfs(g,i+1,j,sq) || dfs(g,i+1,j,sq);
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 6f5be23ec4021a4209feee96ce28bd84 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
public class square{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int p=1;p<=t;p++)
{
int n=sc.nextInt();
String s=sc.next();
int[] a=new int[n];int clock=0,anti=0,off=0;
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='-'){a[i]=0;}
else if(s.charAt(i)=='>'){a[i]=1;clock++;}
else {a[i]=-1;anti++;}
}
if(clock!=0 && anti!=0)
{
if(a[0]==0 || a[n-1]==0)off++;
for(int i=1;i<n;i++)
{
if(a[i]==0 || a[i-1]==0)off++;
}
System.out.println(off);
}
else System.out.println(n);
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 66aed7cd9f63d5adaa3ece5c26db9e0b | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
public class Solution {
public static int beltedRooms(String s, int n) {
int count = 0;
boolean one = true;
boolean two = true;
for (int i=0; i<n; i++) {
if (s.charAt(i) == '<')
one = false;
if (s.charAt(i) == '>')
two = false;
}
if (one || two)
return n;
for (int i=0; i<n; i++) {
if (s.charAt(i) == '-' || s.charAt((i+1)%n) == '-')
count += 1;
}
return count;
}
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
String s = sc.next();
System.out.println(beltedRooms(s, n));
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 21d19fbee2de287c30033ce1707b4656 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes |
import java.util.*;
public class Random {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
while(N>0){
int n = sc.nextInt();
String s = sc.next();
int countDash = 0 ;
int countanti = 0;
int countclock = 0;
int j=0;
while(j<n){
if(s.charAt(j)=='-' && s.charAt((j+1)%n)!='-'){
countDash+=2;
}
else if(s.charAt(j)=='-' && s.charAt((j+1)%n)=='-'){
countDash++;
}
j++;
}
//System.out.println(countDash);
for(int i=0;i<n;i++){
if(s.charAt(i)=='<'){
countanti++;
}
else if(s.charAt(i)=='>'){
countclock++;
}
}
//System.out.println(countanti);
//System.out.println(countclock);
if(countDash>=n){
System.out.println(n);
}
else if(countanti==0 || countclock==0){
System.out.println(n);
}
else{
System.out.println(countDash);
}
N--;
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 02341e35583b4c765d7209c2201f9e13 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
/**
* @author Mubtasim Shahriar
*/
public class BeltRoom {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
int t = sc.nextInt();
// int t = 1;
while (t-- != 0) {
solver.solve(sc, out);
}
out.close();
}
static class Solver {
public void solve(InputReader sc, PrintWriter out) {
int n = sc.nextInt();
char[] arr = sc.next().toCharArray();
boolean right = true, left = true;
for(int i = 0; i < n; i++) {
if(arr[i]=='<') right = false;
else if(arr[i]=='>') left = false;
}
if(right || left) {
out.println(n);
return;
}
int cnt = 0;
for(int i = 0; i < n; i++) {
if(arr[i]=='-' || arr[(i+1)%n]=='-') cnt++;
}
out.println(cnt);
}
}
static void sort(int[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
}
static void sort(long[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
}
static void sortDec(int[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
int l = 0;
int r = n - 1;
while (l < r) {
arr[l] ^= arr[r];
arr[r] ^= arr[l];
arr[l] ^= arr[r];
l++;
r--;
}
}
static void sortDec(long[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
int l = 0;
int r = n - 1;
while (l < r) {
arr[l] ^= arr[r];
arr[r] ^= arr[l];
arr[l] ^= arr[r];
l++;
r--;
}
}
static class InputReader {
private boolean finished = false;
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 peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
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 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 String nextString() {
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;
}
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;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
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 boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public int[] nextSortedIntArray(int n) {
int array[] = nextIntArray(n);
Arrays.sort(array);
return array;
}
public int[] nextSumIntArray(int n) {
int[] array = new int[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; ++i) array[i] = nextLong();
return array;
}
public long[] nextSumLongArray(int n) {
long[] array = new long[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextSortedLongArray(int n) {
long array[] = nextLongArray(n);
Arrays.sort(array);
return array;
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 9d0ea57476157194fe3ca607ed7f7da8 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
/**
* @author Mubtasim Shahriar
*/
public class BeltedRooms {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader sc = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
int t = sc.nextInt();
// int t = 1;
while (t-- != 0) {
solver.solve(sc, out);
}
out.close();
}
static class Solver {
public void solve(InputReader sc, PrintWriter out) {
int n = sc.nextInt();
char[] arr = sc.next().toCharArray();
// boolean dis = false;
// ArrayList<Integer> dises = new ArrayList<>();
// for(int i = 1; i < n; i++) {
// if((arr[i]=='<' && arr[i-1]=='>') || (arr[i]=='>' && arr[i-1]=='<')) {
// dis = true;
// dises.add(i);
// }
// }
// if((arr[0]=='<' && arr[n-1]=='>' || (arr[0]=='>' && arr[n-1]=='<'))) {
// dis = true;
// dises.add(0);
// }
// if(!dis) {
// out.println(n);
// return;
// }
//// ArrayList<ArrayList<Integer>> cmpnts = new ArrayList<>();
// int ans = 0;
//// out.println(dises);
// for(int i = 1; i < dises.size(); i++) {
// int start = dises.get(i-1);
// int end = dises.get(i)-1;
// int cnt = 0;
// for(int j = start; j <= end; j++) {
// if(arr[j]=='-') cnt++;
// else {
// if(cnt>=1)ans += cnt+1;
// cnt = 0;
// }
// }
// if(cnt>=1) ans += cnt+1;
// }
// ArrayList<Integer> last = new ArrayList<>();
//// for(int i = dises.get(dises.size()-1); i < n; i++)
// int start = dises.get(dises.size()-1);
// int end = dises.get(0)-1;
// int cnt = 0;
// for(int i = start; i < n; i++) {
// if(arr[i]=='-') cnt++;
// else {
// if(cnt>=1) ans += cnt+1;
// cnt = 0;
// }
// }
// for(int i = 0; i <=end; i++) {
// if(arr[i]=='-') cnt++;
// else {
// if(cnt>=1) ans += cnt+1;
// cnt = 0;
// }
// }
// if(cnt>=1) ans += cnt+1;
// out.println(ans);
boolean haveLeft = false;
boolean haveRight = false;
for(int i = 0; i < n; i++) {
if(arr[i]=='<') haveLeft = true;
if(arr[i]=='>') haveRight = true;
}
if(haveLeft && haveRight) {
boolean bothFound = false;
for(int i = 0; i < n; i++) if(arr[i]=='-') bothFound = true;
if(!bothFound) {
out.println(0);
} else {
// out.println("HI");
int left = -1;
int right = n;
while(left+1<n && arr[left+1]=='-') left++;
while(right-1 >= 0 && arr[right-1]=='-') right--;
// out.println(left + " " + right);
int cnt = 0;
int ans = 0;
for(int i = left+1; i < right; i++) {
if(arr[i]=='-') cnt++;
else {
if(cnt>=1) ans += cnt+1;
cnt = 0;
}
}
if(cnt>=1) ans += cnt+1;
int start = right%n;
cnt = 0;
while (start!=left+1) {
if(arr[start]=='-') cnt++;
else {
if(cnt>=1) ans += cnt+1;
cnt = 0;
}
start++;
start %= n;
}
if(cnt>=1) ans += cnt+1;
out.println(ans);
}
} else {
out.println(n);
}
}
}
static void sort(int[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
}
static void sort(long[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
}
static void sortDec(int[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
int l = 0;
int r = n - 1;
while (l < r) {
arr[l] ^= arr[r];
arr[r] ^= arr[l];
arr[l] ^= arr[r];
l++;
r--;
}
}
static void sortDec(long[] arr) {
Random rand = new Random();
int n = arr.length;
for (int i = 0; i < n; i++) {
int idx = rand.nextInt(n);
if (idx == i) continue;
arr[i] ^= arr[idx];
arr[idx] ^= arr[i];
arr[i] ^= arr[idx];
}
Arrays.sort(arr);
int l = 0;
int r = n - 1;
while (l < r) {
arr[l] ^= arr[r];
arr[r] ^= arr[l];
arr[l] ^= arr[r];
l++;
r--;
}
}
static class InputReader {
private boolean finished = false;
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 peek() {
if (numChars == -1) {
return -1;
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
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 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 String nextString() {
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;
}
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;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines) {
return readLine();
} else {
return readLine0();
}
}
public BigInteger readBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char nextCharacter() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
return (char) c;
}
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 boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1) {
read();
}
return value == -1;
}
public String next() {
return nextString();
}
public SpaceCharFilter getFilter() {
return filter;
}
public void setFilter(SpaceCharFilter filter) {
this.filter = filter;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; ++i) array[i] = nextInt();
return array;
}
public int[] nextSortedIntArray(int n) {
int array[] = nextIntArray(n);
Arrays.sort(array);
return array;
}
public int[] nextSumIntArray(int n) {
int[] array = new int[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; ++i) array[i] = nextLong();
return array;
}
public long[] nextSumLongArray(int n) {
long[] array = new long[n];
array[0] = nextInt();
for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt();
return array;
}
public long[] nextSortedLongArray(int n) {
long array[] = nextLongArray(n);
Arrays.sort(array);
return array;
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 203314602c6f5276a65f69fd282e85af | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class B {
static boolean found=false;
public static void main(String[] args) throws IOException {
FastScanner fs=new FastScanner();
PrintWriter out = new PrintWriter(System.out);
// int T = 1;
int T=fs.nextInt();
for (int tt=0; tt<T; tt++) {
int n = fs.nextInt();
List<HashSet<Integer>> g = new ArrayList();
for (int i=0; i<n; i++) {
g.add(new HashSet());
}
String s =fs.next();
for (int i=0; i<n; i++) {
if (s.charAt(i)=='-') {
g.get(i).add((i+1)%n);
g.get((i+1)%n).add(i);
}
else if (s.charAt(i)=='>') {
g.get(i).add((i+1)%n);
}
else if (s.charAt(i)=='<') {
g.get((i+1)%n).add(i);
}
}
if ((!s.contains("-") && !s.contains(">")) || (!s.contains("<") && !s.contains(">")) || (!s.contains("-") && !s.contains("<")) || (!s.contains("<")) || (!s.contains(">"))) {
out.println(n);
continue;
}
int ans = 0;
for (int i=0; i<n; i++) {
if ((g.get(i).contains((i+1)%n) && g.get((i+1)%n).contains(i)) || (g.get(i).contains((i-1+n)%n) && g.get((i-1+n)%n).contains(i))){
ans++;
}
}
out.println(ans);
}
out.close();
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 02709219ae449d234c51b1541291e013 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
import java.io.*;
public class b {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
sc.nextLine();
char[] conveyor = sc.nextLine().toCharArray();
boolean[] returnable = new boolean[n];
int numberRight = 0, numberLeft = 0, numberOff = 0;
for (char c : conveyor) {
if (c == '<') numberLeft++;
else if (c == '>') numberRight++;
else numberOff++;
}
if (numberLeft == 0 || numberRight == 0) {
System.out.println(n);
} else {
for (int j = 0; j < n; j++) {
if (conveyor[j] == '-') {
returnable[j] = true;
returnable[(j+1)%n] = true;
}
}
int count = 0;
for (int j = 0; j < n; j++) {
if (returnable[j]) {
count++;
}
}
System.out.println(count);
}
}
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 7f5e78b355fd4b707ec53d929fd7ad86 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes |
import java.util.Scanner;
public class B1428 {
private final static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int groups = scanner.nextInt();
for (int i = 0; i < groups; i++) {
inner();
}
}
private static void inner(){
int rooms = scanner.nextInt();
String beltss = scanner.next();
char[] belts = new char[rooms];
int count = 0;
int leftCount = 0;
int rightCount = 0;
for (int i=0 ; i<rooms ; i++){
belts[i] = beltss.charAt(i);
}
for (int i=0 ; i<rooms ; i++){
if (i != 0 && (belts[i] == '-' || belts[i-1] == '-')){
count++;
}else if (i == 0 && (belts[0] == '-' || belts[rooms-1] == '-')){
count++;
}
if (belts[i] == '>'){
leftCount++;
}else if (belts[i] == '<'){
rightCount++;
}
}
if (leftCount == 0 || rightCount == 0){
count = rooms;
}
System.out.println(count);
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | aa5dbe3d8384317f78ca1e9440f1d927 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes |
import java.util.Scanner;
public class B1428 {
private final static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int groups = scanner.nextInt();
for (int i = 0; i < groups; i++) {
inner();
}
}
private static void inner(){
int rooms = scanner.nextInt();
String beltss = scanner.next();
char[] belts = new char[rooms];
int count = 0;
int leftCount = 0;
int rightCount = 0;
for (int i=0 ; i<rooms ; i++){
belts[i] = beltss.charAt(i);
if (belts[i] == '>'){
leftCount++;
}else if (belts[i] == '<'){
rightCount++;
}
if (i != 0 && (belts[i] == '-' || belts[i-1] == '-')){
count++;
}
}
if (belts[0] == '-' || belts[rooms-1] == '-'){
count++;
}
if (leftCount == 0 || rightCount == 0){
count = rooms;
}
System.out.println(count);
}
} | Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | e7eed7bdd4c0137b1ba8b657ddffdc79 | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.io.IOException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BeltedRooms{
public static void main(String[] args) throws IOException{
Reader.init(System.in);
int t = Reader.nextInt();
for(int j = 0; j < t; j++){
int n = Reader.nextInt();
String s = Reader.next();
int ans = 0;
int ans_g = 0;
int ans_l = 0;
s = "" + s.charAt(n-1) + s;
for(int i = 0; i < n; i++){
if(s.charAt(i%n) == '-' || s.charAt((n + i-1)%n) == '-'){
ans++;
}
if(s.charAt(i) == '>'){
ans_g++;
}else if(s.charAt(i) == '<'){
ans_l++;
}
}
// System.out.println(ans_l + " " + ans_g);
if(ans_g > 0 && ans_l > 0){
System.out.println(ans);
}else{
System.out.println(n);
}
}
}
}
class Reader {
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 double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 0b03d49b813245b052d9ca8b24303f0d | train_001.jsonl | 1602939900 | In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states: If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$. If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$. If it is off, snakes can travel in either direction. Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there? | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String args[])throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int testcase= sc.nextInt();
while(testcase-->0) {
int n=sc.nextInt();
char dir[] = sc.next().toCharArray();
boolean c=false,a=false;
for(int i=0;i<n;i++) {
if(dir[i]=='<')
a=true;
if(dir[i]=='>')
c=true;
}
if(a&&c) {
int count=0;
if(dir[0]=='-' || dir[n-1]=='-')
count=1;
for(int i=1;i<n;i++)
if(dir[i-1]=='-' || dir[i]=='-')
count++;
System.out.println(count);
continue;
}
System.out.println(n);
}
}
}
| Java | ["4\n4\n-><-\n5\n>>>>>\n3\n<--\n2\n<>"] | 1 second | ["3\n5\n3\n0"] | NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts. | Java 8 | standard input | [
"implementation",
"graphs"
] | f82685f41f4ba1146fea8e1eb0c260dc | Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows. The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms. The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'. If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise. If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise. If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off. It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$. | 1,200 | For each test case, output the number of returnable rooms. | standard output | |
PASSED | 460b45a0c49fb691ca7dbb8c667204c8 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.*;
import java.util.*;
public class Simple
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
Stack<Integer> prgIndecis = new Stack<Integer>();
Stack<Integer> mathIndecis = new Stack<Integer>();
Stack<Integer> peIndecis = new Stack<Integer>();
for(int i=0;i<num;i++){
int teamMember = in.nextInt();
if(teamMember == 1)
prgIndecis.push(i+1);
else if(teamMember == 2)
mathIndecis.push(i+1);
else
peIndecis.push(i+1);
}
StringBuilder team = new StringBuilder();
int numberOfTeam = Math.min(Math.min(prgIndecis.size(), mathIndecis.size()), peIndecis.size());
team.append(numberOfTeam).append("\n");
for(int i=0;i<numberOfTeam;i++)
team.append(String.format("%d %d %d\n",prgIndecis.pop(), mathIndecis.pop(), peIndecis.pop()));
System.out.print(team.toString());
in.close();
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | e6fccf9b5eabdc22c7c692e58adabd3b | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class Main
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int w = scan.nextInt();
int[] a = new int[w];
for(int i=0 ; i < w ; i++){
a[i] = scan.nextInt();
}
int l=0,m=0,n=0,p=0,q=0;
for(int i=0 ; i<w;i++){
if(a[i] == 1){
l++;
}
else if(a[i] == 2){
m++;
}
else if(a[i] == 3){
n++;
}
}
if(l==0 || m==0 || n==0){
System.out.println("0");
}
else{
if(l<m){
if(l<n){
p=l;
}
else{
p=n;
}
}
else{
if(m<n){
p=m;
}
else{
p=n;
}
}
System.out.println(p);
int[] b = new int[p];
int[] c = new int[p];
int[] d = new int[p];
int s=0,r=0,t=0;
for(int i=0 ; i < p ; i++ ){
for(int j=s ; j < w ; j++){
if(a[j] == 1){
s=j+1;
b[i]=j+1;
break;
}
}
}
for(int i=0 ; i < p ; i++ ){
for(int j=r ; j < w ; j++){
if(a[j] == 3){
r=j+1;
d[i]=j+1;
break;
}
}
}
for(int i=0 ; i < p ; i++ ){
for(int j=t ; j < w ; j++){
if(a[j] == 2){
t=j+1;
c[i]=j+1;
break;
}
}
}
for(int i=0 ; i < p ;i++){
System.out.printf("%d %d %d\n",b[i],c[i],d[i]);
}
}
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | d803a1cf43902e8e90fc79ddf58ba428 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
public class Olympiad {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int len = sc.nextInt();
int[] arr = new int[len];
ArrayList<Integer> l1 = new ArrayList<>();
ArrayList<Integer> l2 = new ArrayList<>();
ArrayList<Integer> l3 = new ArrayList<>();
for(int i = 0; i < len; i++) {
arr[i] = sc.nextInt();
}
for(int i = 0; i < len; i++) {
if(arr[i] == 1) {
l1.add(i+1);
}
else if(arr[i] == 2) {
l2.add(i+1);
}
else {
l3.add(i+1);
}
}
int min = Math.min(Math.min(l1.size(), l2.size()), Math.min(l2.size(), l3.size()));
System.out.println(min);
for(int i = 0; i < min; i++) {
System.out.println(l1.get(i) + " " + l2.get(i) + " " + l3.get(i));
}
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 16c190303150bbb79985083a0bccd89d | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> a1 = new ArrayList<Integer>();
ArrayList<Integer> a2 = new ArrayList<Integer>();
ArrayList<Integer> a3 = new ArrayList<Integer>();
for(int i=0;i<n;i++){
int x = sc.nextInt();
if(x==1)
a1.add(i+1);
else if(x==2)
a2.add(i+1);
else
a3.add(i+1);
}
int n1 = a1.size(),n2 = a2.size(),n3 = a3.size();
if(n1==0||n2==0||n3==0)
System.out.println(0);
else{
n = Integer.min(n1,n2);
n = Integer.min(n,n3);
System.out.println(n);
for(int i=0;i<n;i++){
System.out.println(a1.get(i)+" "+a2.get(i)+" "+a3.get(i));
}
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | b1b23e0ba5f0f6479a7ff6ff1ee3fcae | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
String[] childs = br.readLine().split(" ");
ArrayList<Integer>[] count = new ArrayList[3];
for (int i = 0; i < childs.length; i++) {
if (count[Integer.parseInt(childs[i])-1] == null) {
count[Integer.parseInt(childs[i])-1] = new ArrayList<>();
}
count[Integer.parseInt(childs[i])-1].add(i + 1);
}
int minLength = Math.min(count[0]==null?0:count[0].size(), Math.min(count[1]==null?0:count[1].size(),count[2]==null?0: count[2].size()));
System.out.println(minLength);
for (int i = 0; i < minLength; i++) {
System.out.println(count[0].get(i) + " " + count[1].get(i) + " " + count[2].get(i));
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 34e23b969bb84d57650b48f933cdedc4 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | /* package codechef; // don't place package name!
https://codeforces.com/problemset/status?my=on
*/
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(),o=0,t=0,th=0,s=100000;
int a[]=new int[n];
int b[]=new int[3];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
//System.out.println(i);
switch(a[i]){
case 1:
b[0]++;break;
case 2:
b[1]++;break;
case 3:
b[2]++;break;
}
}
for(int i=0;i<3;i++)
{
if(s>b[i])
s=b[i];
}
//System.out.println(s+" o"+b[0]+" t"+b[1]+" th"+b[2]);
if(s!=0){
System.out.println(s);
for(int i=0;i<s;i++){
for(int j=0,c=1;(j<n);j++){
//System.out.println((j+1)+" c"+c+" a"+a[j]+" ");
if(c==4)
{ break;}
if(c==a[j]){
System.out.print((j+1)+" ");
a[j]=-1;
j=-1;
c++;}
}System.out.println();
}
}else
System.out.println("0");
// for(int i=0;i<n;i++)
//System.out.print(a[i]+" ");
}
}
/*
System.out.print(n);
test case1
7
1 3 1 3 2 1 2
out--
2
3 5 2
6 7 4
------------2
4
2 1 1 2
out-0
-------------3
60
3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2
ans=
20
3 4 1
6 5 2
8 12 7
9 13 11
10 14 15
17 19 16
23 21 18
28 22 20
32 26 24
35 29 25
36 30 27
39 31 33
40 34 37
41 44 38
43 50 42
45 52 47
46 54 48
57 55 49
58 56 51
59 60 53
-------------
4998
3
2
3
1
3
3
3
1
1
2
1
1
3
3
2
3
1
1
1
3
1
1
1
1
1
1
1
3
3
3
1
1
2
3
2
1
2
2
3
2
2
1
1
2
1
3
1
1
1
3
2
2
2
3
2
2
3
3
1
3
2
2
1
1
1
3
2
1
2
1
2
3
3
1
2
1
3
3
2
1
3
3
1
2
2
2
3
2
1
1
3
1
3
2
3
2
3
2
3
2
3
2
3
3
1
2
3
2
2
3
1
2
1
3
3
3
2
1
3
1
1
2
1
3
3
3
3
2
1
2
1
3
1
1
3
1
3
2
2
3
1
1
1
3
2
2
3
3
1
3
3
1
3
2
2
2
2
2
2
1
2
3
3
1
1
2
1
2
2
2
2
3
3
3
3
1
2
2
2
1
1
1
1
1
2
1
3
1
2
1
1
2
3
1
3
1
2
2
3
1
2
1
1
1
1
2
2
1
2
2
2
3
2
1
3
3
3
2
3
2
1
1
1
2
1
2
3
1
2
3
2
1
3
2
1
1
3
3
2
3
3
1
2
2
2
1
1
2
3
3
1
2
2...
out=-100 100 100 -100
0 -100 0 100
out=200 -100 200 100
0 1 2 3
out---0 3 2 1
-100 100 100 -100
out=-100 -100 100 100
1 0 0 1
out=1 1 0 0
-68 -78 -45 -55
out=-68 -55 -45 -78
68 -92 8 -32
ou=68 -32 8 -92
*/ | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | c87b58c10140ee95ca67eaca0ab93fc9 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
public class file
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[]=new int[n];
int a1[]=new int[n];
int a2[]=new int[n];
int a3[]=new int[n];
int k, l, m; k=l=m=0;
for(int i=0; i<n; i++)
{
a[i]=in.nextInt();
if(a[i]==1)
a1[k++]=i+1;
else if(a[i]==2)
a2[l++]=i+1;
else
a3[m++]=i+1;
}
l=Math.min(k,l);
k=Math.min(l,m);
System.out.println(k);
for (int i=0; i<k; i++)
System.out.println(a1[i]+" "+a2[i]+" "+a3[i]);
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | e7215468dfcdc3819df6f1e41bb5c1ef | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.Scanner;
import java.util.ArrayList;
public class E {
public static void main(String[]args){
Scanner input=new Scanner(System.in) ;
int n=input.nextInt();
// ArrayList<Integer> arr= new ArrayList<>();
// ArrayList<Integer> index= new ArrayList<>();
int arr[]=new int[n];
int n1=0;int n2=0;int n3=0;
int count;
for(int i=0;i<n;i++){
int num=input.nextInt();
if(num==1)
n1++;
else if(num==2)
n2++;
else
n3++;
arr[i]=num;
}
count=Math.min(Math.min(n1, n2), n3);
System.out.println(count);
ArrayList<Integer> arr1= new ArrayList<>();
ArrayList<Integer> arr2= new ArrayList<>();
ArrayList<Integer> arr3= new ArrayList<>();
for(int i=0;i<arr.length;i++){
if(arr[i]==1){
arr1.add(i);
}
if(arr[i]==2){
arr2.add(i);
}
if(arr[i]==3){
arr3.add(i);
}
}
for(int i=0;i<count;i++){
int a=(int)(Math.random()*arr1.size());
int b=(int)(Math.random()*arr2.size());
int c=(int)(Math.random()*arr3.size());
System.out.println((arr1.get(a)+1)+" "+(arr2.get(b)+1)+" "+(arr3.get(c)+1));
arr1.remove(a);
arr2.remove(b);
arr3.remove(c);
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 7dae6c41673e60346086e1b7c9d5b599 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
public class A490 {
public static void main(String [] args) {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
public void solve(InputReader ir, PrintWriter pw) {
int n = ir.nextInt();
int [] t = new int[n];
int count1 = 0;
int count2 = 0;
int count3 = 0;
for (int i = 0; i < n; i++) t[i] = ir.nextInt();
for (int i = 0; i < n; i++) {
if (t[i] == 1) {
count1++;
} else if (t[i] == 2) {
count2++;
} else {
count3++;
}
}
int min = Math.min(count1, Math.min(count2, count3));
if (min == 0) {
pw.print("0");
} else {
pw.println(min);
int[][] p = new int[min][3];
for (int j = 0; j < min; j++) {
int count = 1;
for (int i = 0; i < n; i++) {
if (t[i] == count) {
t[i] = 0;
p[j][count - 1] = i + 1;
count++;
i = -1;
}
}
pw.println(p[j][0] + " " + p[j][1] + " " + p[j][2]);
}
}
}
}
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 | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | ad372e785e48caedc796e1cdfc5e8deb | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.*;
public class TeamOlympiad
{
public static void main(String args[])throws IOException
{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(rd.readLine());
String s = rd.readLine();
int t1 = 0, t2 = 0, t3 = 0;
for(int i = 0, g = 0; g < n; i += 2, g++)
{
char ch = s.charAt(i);
switch(ch)
{
case '1': t1 += 1;
break;
case '2': t2 += 1;
break;
case '3': t3 += 1;
break;
}
}
int teams = Math.min(Math.min(t1,t2),t3);
System.out.println(teams);
if( teams != 0)
{
t1 = s.indexOf('1',0);
t2 = s.indexOf('2',0);
t3 = s.indexOf('3',0);
for(int i = 0; i < teams; i++)
{
System.out.println((t1/2 + 1) + " " + (t2/2 + 1) + " " + (t3/2 + 1));
t1 = s.indexOf('1',t1 + 1);
t2 = s.indexOf('2',t2 + 1);
t3 = s.indexOf('3',t3 + 1);
}
}}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | cb267a74dbae7d9bfc2a2ec22bc521f5 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.*;
public class TeamOlympiad
{
public static void main(String args[])throws IOException
{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(rd.readLine());
String s = rd.readLine();
int t1 = 0, t2 = 0, t3 = 0;
for(int i = 0, g = 0; g < n; i += 2, g++)
{
char ch = s.charAt(i);
switch(ch)
{
case '1': t1 += 1;
break;
case '2': t2 += 1;
break;
case '3': t3 += 1;
break;
}
}
int teams = Math.min(Math.min(t1,t2),t3);
System.out.println(teams);
if( teams != 0)
{
t1 = s.indexOf('1',0);
t2 = s.indexOf('2',0);
t3 = s.indexOf('3',0);
for(int i = 0; i < teams; i++)
{
System.out.println((t1/2 + 1) + " " + (t2/2 + 1) + " " + (t3/2 + 1));
t1 = s.indexOf('1',+t1 + 1);
t2 = s.indexOf('2',t2 + 1);
t3 = s.indexOf('3',t3 + 1);
}
}}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 8038ecec008151edb79f6feb79a67ee4 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.*;
public class TeamOlympiad
{
public static void main(String args[])throws IOException
{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(rd.readLine());
String s = rd.readLine();
int t1 = 0, t2 = 0, t3 = 0;
for(int i = 0, g = 0; g < n; i += 2, g++)
{
char ch = s.charAt(i);
switch(ch)
{
case '1': t1 += 1;
break;
case '2': t2 += 1;
break;
case '3': t3 += 1;
break;
}
}
int teams = Math.min(Math.min(t1,t2),t3);
System.out.println(+teams);
if( teams != 0)
{
t1 = s.indexOf('1',0);
t2 = s.indexOf('2',0);
t3 = s.indexOf('3',0);
for(int i = 0; i < teams; i++)
{
System.out.println((t1/2 + 1) + " " + (t2/2 + 1) + " " + (t3/2 + 1));
t1 = s.indexOf('1',t1 + 1);
t2 = s.indexOf('2',t2 + 1);
t3 = s.indexOf('3',t3 + 1);
}
}}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 38b39b4d81bf85b4afd51466e0327d75 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] arr = new int[n];
for(int i =0;i< n;i++){
arr[i] = scn.nextInt();
}
int c =0;
boolean[] visit = new boolean[n];
boolean[] unvisit = new boolean[n];
for(int i =0;i < arr.length;i++){
int idx = 0 ,idx1 =0 ,idx2 = 0;
for(int j =0;j < arr.length;j++){
if(arr[j]==1&& unvisit[j]==false){
// System.out.println(j);
idx= j+1;
unvisit[j] =true;
for(int z =0;z < arr.length;z++){
if(arr[z]==2 && unvisit[z] == false){
idx1 = z+1;
unvisit[z] = true;
for(int k = 0;k < arr.length;k++){
if(arr[k]==3 && unvisit[k]==false){idx2= k+1 ;
c++;
unvisit[k] = true;
break;}}break;}}break;}}
}
System.out.println(c);
for(int i =0;i < arr.length;i++){
int idx = 0 ,idx1 =0 ,idx2 = 0;
for(int j =0;j < arr.length;j++){
if(arr[j]==1&& visit[j]==false){
// System.out.println(j);
idx= j+1;
visit[j] =true;
for(int z =0;z < arr.length;z++){
if(arr[z]==2 && visit[z] == false){
idx1 = z+1;
visit[z] = true;
for(int k = 0;k < arr.length;k++){
if(arr[k]==3 && visit[k]==false){idx2= k+1 ;
c++;
visit[k] = true;
System.out.println(idx+" "+idx1+" "+idx2);
break;}}
break;}}
break;}}
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 7af9979c934ecd9d129e8e5cb7f47200 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int arr[] = new int[n];
String line = br.readLine(); // to read multiple integers line
String[] strs = line.trim().split("\\s+");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(strs[i]);
}
int c =0;
ArrayList<Integer> al = new ArrayList<>();
ArrayList<Integer> al1 = new ArrayList<>();
ArrayList<Integer> al2 = new ArrayList<>();
for(int i =0;i<arr.length;i++){
if(arr[i]==1){
al.add(i+1);
}else if(arr[i]==2){
al1.add(i+1);
}else if(arr[i]==3){
al2.add(i+1);
}
}
int temp = Math.min(Math.min(al.size(),al1.size()),al2.size());
System.out.println(temp );
ArrayList<Integer> ans = new ArrayList<>();
for(int i =0;i<temp;i++){
ans.add(al.get(i));
ans.add(al1.get(i));
ans.add(al2.get(i));
}
for(int i =0;i<ans.size();i++){
if(i%3==0){
if(i==0){
}else{
System.out.println();
}
}
System.out.print(ans.get(i)+" ");
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | d06b309782f354b3a1c57f1d86c6275b | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
public class MainScreen{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k=0;
int iMathStudents=0;
int iProgrammingStudents=0;
int iSportsStudents=0;
int iNumOfTeams=0;
int array[]=new int [n];
for(int i=0;i<n;i++) {
array[i]=in.nextInt();
}
for(int i=0;i<n;i++) {
if (array[i] == 1) {
iMathStudents++;
} else if (array[i] == 2) {
iProgrammingStudents++;
} else if (array[i] == 3) {
iSportsStudents++;
}
if (iMathStudents > 0 && iSportsStudents > 0 && iProgrammingStudents > 0) {
iNumOfTeams++;
iMathStudents--;
iProgrammingStudents--;
iSportsStudents--;
}
}
System.out.println(iNumOfTeams);
final int iOrderSize = (iNumOfTeams * 3);
int []iOrderArray= new int[n];
int x = 0, y = 1, z = 2;
if (iNumOfTeams==0) {
}
else {
for (int i = 0; i < n; i++) {
if (array[i] == 1) {
iOrderArray[x] =i+1 ;
if (x + 3 <= iOrderSize) {
x += 3;
}
} else if (array[i] == 2 ) {
iOrderArray[y] = i+1;
if (y + 3 <= iOrderSize) {
y += 3;
}
} else if (array[i] == 3) {
iOrderArray[z] = i+1 ;
if (z + 3 <= iOrderSize) {
z += 3;
}
}
}
for (int i = 0; i < iOrderSize; i++) {
System.out.print(iOrderArray[i] + " ");
}
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | fe7bb8e7130dc13fe6b391c892934129 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
public class TeamOlympiad {
public static void main(String args []) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<Integer, ArrayList<Integer>> students = new HashMap<>();
students.put(1, new ArrayList<Integer>());
students.put(2, new ArrayList<Integer>());
students.put(3, new ArrayList<Integer>());
for (int i = 0; i < n; i++) {
int s = sc.nextInt();
ArrayList<Integer> positions = students.putIfAbsent(s, new ArrayList<Integer>(Arrays.asList(i)));
students.get(s).add(i);
}
int maxTeams = Integer.MAX_VALUE;
Set<Integer> keys = students.keySet();
for (int key : keys) {
int numStudents = students.get(key).size();
if (students.get(key) == null) {
numStudents = 0;
}
if (numStudents < maxTeams) {
maxTeams = numStudents;
}
}
System.out.println(maxTeams);
int[][] teams = new int[maxTeams][3];
int index = 0;
for (ArrayList<Integer> values : students.values()) {
for (int i = 0; i < maxTeams; i++) {
teams[i][index] = values.get(i);
}
index++;
}
for (int i = 0; i < teams.length; i++) {
String team = "";
for (int j = 0; j < 3; j++) {
team += teams[i][j] + 1 + " ";
}
System.out.println(team.substring(0, team.length() - 1));
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | d40dd2be18a9b3bde29386b2e5fc4375 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class ss {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int len=in.nextInt();
int arr[]=new int[len];
int a1=0;int b1=0;int c1=0;
ArrayList<Integer> li1=new ArrayList<Integer>();
ArrayList<Integer> li2=new ArrayList<Integer>();
ArrayList<Integer> li3=new ArrayList<Integer>();
for (int a=0;a<arr.length;a++)
{
arr[a]=in.nextInt();
char c=(char) a;
//v=a;
if(arr[a]==1)
{
li1.add(a+1);
}
else if(arr[a]==2)
{
li2.add(a+1);
}
else if(arr[a]==3)
{
li3.add(a+1);
}
}
for(int b=0;b<arr.length;b++)
{
switch(arr[b])
{
case 1: a1++; break;
case 2: b1++; break;
case 3: c1++; break;
}
}
//to know how many of row
int arr1[]={a1,b1,c1};
Arrays.sort(arr1);
int y=arr1[0];
System.out.println(y);
for(int a=0;a<y;a++)
{
System.out.println(li1.get(a)+" "+li2.get(a)+" "+li3.get(a));
}
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 540555de073d5bdf91c6eeba5bca4286 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int a = 0;
int b = 0;
int c = 0;
List<Integer> alist = new ArrayList<>(n);
List<Integer> blist = new ArrayList<>(n);
List<Integer> clist = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
switch (in.nextInt()) {
case 1:
a++;
alist.add(i);
break;
case 2:
b++;
blist.add(i);
break;
case 3:
c++;
clist.add(i);
break;
}
}
int result = (Math.min(Math.min(a, b), c));
if (result > 0) {
out.println(result);
for (int i = 0; i < result; i++) {
out.print(alist.get(i) + 1 + " ");
out.print(blist.get(i) + 1 + " ");
out.print(clist.get(i) + 1 + "\n");
}
} else {
out.println(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());
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 5ac36d15261cf35744bd4316f0006b2a | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
List<Integer> alist = new ArrayList<>(n);
List<Integer> blist = new ArrayList<>(n);
List<Integer> clist = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
switch (in.nextInt()) {
case 1:
alist.add(i);
break;
case 2:
blist.add(i);
break;
case 3:
clist.add(i);
break;
}
}
int result = (Math.min(Math.min(alist.size(), blist.size()), clist.size()));
if (result > 0) {
out.println(result);
for (int i = 0; i < result; i++) {
out.print(alist.get(i) + 1 + " ");
out.print(blist.get(i) + 1 + " ");
out.print(clist.get(i) + 1 + "\n");
}
} else {
out.println(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());
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | b183e2f1ed8154eb3920903dc59f65e6 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.*;
import java.util.*;
public final class GFG {
public static void main (String[] args) {
//System.out.println("GfG!");
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int count=0;
int flag=0;
int col1=0,col2=0,col3=0;
int teams=n/3;
if(teams==0)
{System.out.println("0");}
else{
int[][] a=new int[teams][3];
for(int i=0;i<n;i++)
{
int p=scan.nextInt();
if(p==1&&col1<teams)
{
a[col1][0]=i+1;
col1++;
}
else if(p==2&&col2<teams)
{
a[col2][1]=i+1;
col2++;
}
else if(p==3&&col3<teams)
{
a[col3][2]=i+1;
col3++;
}
}
for(int i=0;i<teams;i++)
{ for(int j=0;j<3;j++)
{ if(a[i][j]==0)
{ flag=1;
break;
}
else
{
if(j==2)
count++;
}
}
if(flag==1)
break;
}
// System.out.println(count);
if(count>0||flag==0){
System.out.println(count);
for(int i=0;i<count;i++)
{ for(int j=0;j<3;j++)
{ System.out.print(a[i][j]+" ");}System.out.println();} }
else{
System.out.println("0");
}
}
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 97fda789a281ea4ea8df6578bca4633a | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.*;
public class teamolympiad
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int a[]=new int[n+1];
int b[]=new int[4];
int s[]=new int[5000];
int s1[]=new int[5000];
int s2[]=new int[5000];
int i,min=6000,k=0,k1=0,k2=0;
for(i=1;i<=n;i++)
{
a[i]=in.nextInt();
if(a[i]==1)
s[k++]=i;
else if(a[i]==2)
s1[k1++]=i;
else
s2[k2++]=i;
b[a[i]]+=1;
}
for(i=1;i<=3;i++)
{
if(b[i]==0)
{
System.out.println(0);
System.exit(0);
}
if(b[i]<min)
min=b[i];
}
System.out.println(min);
for(i=0;i<min;i++)
System.out.println(s[i]+" "+s1[i]+" "+s2[i]);
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 996ec0ac2a8bae66ae24a9fa15570027 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.math.*;
import java.io.*;
import java.util.Set;
import static java.lang.Math.*;
public class Competitive
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int a = s.nextInt();
ArrayList<Integer> b = new ArrayList<>();
int o = 0 , t = 0 , th = 0 ;
for(int i = 0 ; i < a ; i++){
int c = s.nextInt();
b.add(c);
if(c == 1){
o++;
}else if(c == 2){
t++;
}else{
th++;
}
}
int min = min(min(o,t),th) ;
System.out.println(min);
int[] e = new int[3];
boolean f =false , g=false , h=false;
for(int i =0 ; i < min ; i++){
for(int j =0 ; j < a ; j++ ){
if(b.get(j) == 1 && f == false ){
b.set(j,5);
e[0] = j+1;
f = true ;
}
else if(b.get(j) == 2 && g == false ){
b.set(j,5);
e[1] = j+1;
g = true ;
}
else if(b.get(j) == 3 && h == false ) {
b.set(j,5);
e[2] = j+1;
h = true ;
}
}
System.out.printf( "%d %d %d \n",e[0],e[1],e[2]);
f =false ;
g=false ;
h=false ;
// System.out.println(e.get(0));
}
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 6160d852370f4dc0fb3c389e94bb5ed5 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.math.*;
import java.io.*;
import java.util.Set;
import static java.lang.Math.*;
public class Competitive
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int a = s.nextInt();
ArrayList<Integer> b = new ArrayList<>();
int o = 0 , t = 0 , th = 0 ;
for(int i = 0 ; i < a ; i++){
int c = s.nextInt();
b.add(c);
if(c == 1){
o++;
}else if(c == 2){
t++;
}else{
th++;
}
}
int min = min(min(o,t),th) ;
System.out.println(min);
int[] e = new int[3];
boolean f =false , g=false , h=false;
for(int i =0 ; i < min ; i++){
for(int j =0 ; j < a ; j++ ){
if(b.get(j) == 1 && f == false ){
b.set(j,5);
e[0] = j+1;
f = true ;
}
else if(b.get(j) == 2 && g == false ){
b.set(j,5);
e[1] = j+1;
g = true ;
}
else if(b.get(j) == 3 && h == false ) {
b.set(j,5);
e[2] = j+1;
h = true ;
}
}
System.out.printf( "%d %d %d \n",e[0],e[1],e[2]);
f =false ;
g=false ;
h=false ;
}
}
} | Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 60e939b02cee4d5c3598c47f74a9279e | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Team_Olympiad_490A {
public static void main(String[] args) {
input in = new input();
int n = in.nextInt();
int c1=0,c2=0,c3=0;
int child[]=new int[n];
for(int i = 0 ;i<n;i++){
int tmp = in.nextInt();
child[i]=tmp;
switch(tmp){
case 1:
c1++;
break;
case 2:
c2++;
break;
case 3:
c3++;
break;
}
}
int smallest = Math.min(Math.min(c1,c2),c3);
int i1[]=new int [n],i2[]=new int[n],i3[]=new int [n];
int one=0,two=0,three=0;
if(c1==0||c2==0||c3==0) System.out.println(0);
else{
for(int i = 0 ;i<child.length;i++){
switch(child[i]){
case 1:
i1[one]=i+1;
one++;
break;
case 2:
i2[two]=i+1;
two++;
break;
case 3:
i3[three]=i+1;
three++;
break;
}
}
System.out.println(smallest);
for(int i=0 ;i<smallest ;i++){
System.out.print(i1[i]+" "+i2[i]+" "+i3[i]+"\n");
}
}
}
static class input
{
BufferedReader br;
StringTokenizer st;
public input()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
public String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | e991e0f2235ea3f592d1c363fab2b1b9 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Ashraf Mohamed
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
FastWriter out = new FastWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, FastReader in, FastWriter out) {
int n = in.nextInt();
int[] sub = new int[4];
Map<Integer, ArrayList<Integer>> index = new HashMap<>();
index.put(1, new ArrayList<>());
index.put(2, new ArrayList<>());
index.put(3, new ArrayList<>());
for (int i = 0; i < n; i++) {
int temp = in.nextInt();
sub[temp]++;
index.get(temp).add(i + 1);
}
int ans = Math.min(Math.min(sub[1], sub[2]), sub[3]);
System.out.println(ans);
for (int i = 0; i < ans; i++) {
int one = index.get(1).get(i);
int two = index.get(2).get(i);
int three = index.get(3).get(i);
System.out.println(one + " " + two + " " + three);
}
out.close();
}
}
static class FastWriter {
private final PrintWriter writer;
public FastWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public FastWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(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 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 | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 69a13c04b7b2611d8ca2fc3b7f201dea | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.Scanner;
public class Main{
private static int CountElements(String line, char separate_element){
String number = "";
int counter = 0;
char character = ' ';
for(int index = 0; index < line.length(); index++){
character = line.charAt(index);
if(character >= '0' && character <= '9')
number += character;
else if(number.length() > 0){
number = "";
counter++;
}
}
if(number.length() > 0){
number = "";
counter++;
}
return counter;
}
private static int[] ToArray(String line, char separate_element, int count_elements){
int array[] = new int[count_elements], counter = 0;
String number = "";
for(int index = 0; index < line.length(); index++){
if(line.charAt(index) != separate_element)
number += line.charAt(index);
else if(line.charAt(index) == separate_element){
array[counter] = Integer.parseInt(number);
number = "";
counter++;
}
}
array[counter] = Integer.parseInt(number);
return array;
}
private static String FormThree(int pupils[]){
String triple = "";
int predit_counter = 1;
for (int index = 0; index < pupils.length; index++) {
if(pupils[index] == predit_counter){
predit_counter++;
pupils[index] = -1;
triple += index + 1;
if(predit_counter <= 3) {
index = -1;
triple += " ";
} else index = pupils.length - 1;
}
}
return triple;
}
private static String CreateTeam(int pupils[]){
String triple = "", teams = "";
int counter = 0;
while(CountElements((triple = FormThree(pupils)), ' ') == 3) {
teams += triple + '\n';
counter++;
}
if(counter > 0)
teams = Integer.toString(counter) + '\n' + teams;
else teams += "0";
return teams;
}
public static void Solve() {
Scanner scanner = new Scanner(System.in);
String number = scanner.nextLine(), pupils = scanner.nextLine();
System.out.println(CreateTeam(ToArray(pupils, ' ', Integer.parseInt(number))));
}
public static void main(String[] args){
Solve();
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | 3bcabd3ad6b83d2233525efc289f5e99 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Alaaa {
public static void main (String[]args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
ArrayList<Integer> Ones = new ArrayList<>() ;
ArrayList<Integer> Twos = new ArrayList<>() ;
ArrayList<Integer> Threes = new ArrayList<>();
int c = 1;
for(int i= 0 ; i<s.length() ; i+=2 , c++) {
if(s.charAt(i) == '1')
Ones.add(c);
else
if(s.charAt(i) == '2')
Twos.add(c);
else
Threes.add(c);
}
int teams = Math.min(Ones.size(), Math.min(Twos.size(), Threes.size()));
System.out.println(teams);
for(int i = 0 ; i < teams ; i++) {
System.out.println(Ones.get(i)+" "+Twos.get(i)+" "+Threes.get(i));
}
// 1
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | ad82c57b4c7b783408a0198e3ac1a950 | train_001.jsonl | 1416733800 | The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? | 256 megabytes | import java.util.Scanner;
/**
*
* @author Kuari
*/
public class Teamolempics {
public static int one,two,three,num,x=1,y=0,z=1,min,arr1=0,arr2=0,arr3=0;
public static String s,s2;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
num=in.nextInt();
int []array1 = new int[5004];
int []array2 = new int[5004];
int []array3 = new int[5004];
int []array = new int[num];
for(int i = 0 ; i<num;i++){
array[i]=in.nextInt();
if(array[i]==1){
one++;
array1[arr1]=i+1;
arr1++;
}
else if(array[i]==2){
two++;
array2[arr2]=i+1;
arr2++;
}
else if(array[i]==3){
three++;
array3[arr3]=i+1;
arr3++;
}
}
if(one<=two&&one<=three){
min=one;
System.out.println(min);
}
else if(two<=one&&two<=three){
min=two;
System.out.println(min);
}
else if(three<=one&&three<=two){
min=three;
System.out.println(min);
}
for(int h = 0 ; h<min;h++){
System.out.println(array1[h]+ " " + array2[h]+ " "+ array3[h]);
}
}
}
| Java | ["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"] | 1 second | ["2\n3 5 2\n6 7 4", "0"] | null | Java 8 | standard input | [
"implementation",
"sortings",
"greedy"
] | c014861f27edf35990cc065399697b10 | The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child. | 800 | In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. | standard output | |
PASSED | b53e677cd5e55477d832d22812da0d03 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.io.*;
import java.util.*;
public class a281{
public static void main(String[] args) {
MyScanner obj = new MyScanner();
String h=obj.nextLine();
String a=obj.nextLine();
int arr[][]=new int[2][100];
int ar[][]=new int[2][100];
Arrays.fill(arr[0],0);
Arrays.fill(arr[1],0);
Arrays.fill(ar[0],0);
Arrays.fill(ar[1],0);
int n=obj.nextInt();
int t=0,pl=0;
String te,c;
for(int i=0;i<n;i++)
{
t=obj.nextInt();
te=obj.next();
pl=obj.nextInt();
c=obj.next();
if(c.equals("r")&&te.equals("h")){
if(ar[0][pl]==0){ar[0][pl]=t;System.out.println(h+" "+pl+" "+t);}}
if(c.equals("r")&&te.equals("a")){
if(ar[1][pl]==0){ar[1][pl]=t;System.out.println(a+" "+pl+" "+t);}}
if(c.equals("y")&&te.equals("h")){
arr[0][pl]+=1;if(arr[0][pl]==2&&ar[0][pl]==0){ar[0][pl]=t;System.out.println(h+" "+pl+" "+t);}}
if(c.equals("y")&&te.equals("a")){
arr[1][pl]+=1;if(arr[1][pl]==2&&ar[1][pl]==0){ar[1][pl]=t;System.out.println(a+" "+pl+" "+t);}}
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 68805858c5c45a173c090d0c1291274a | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Scanner;
public class a {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String team1 = input.nextLine();
String team2 = input.nextLine();
int n = Integer.parseInt(input.next());
int [] players1 = new int [100];
int [] players2 = new int [100];
int [] repeat1 = new int[100];
int [] repeat2 = new int [100];
for(int i = 0; i < n; i++){
int time = Integer.parseInt(input.next());
String team = input.next();
int teamNumber = Integer.parseInt(input.next());
String card = input.next();
if(card.equals("r")){
if(team.equals("h") && repeat1[teamNumber] != 1 ){
System.out.println(team1 + " " + teamNumber + " " + time);
repeat1[teamNumber] = 1;
}
else if (team.equals("a") && repeat2[teamNumber] != 1){
System.out.println(team2+ " "+ teamNumber + " " + time);
repeat2[teamNumber] =1;
}
continue;
}
if(team.equals("h")){
if(players1[teamNumber] != 0 && repeat1[teamNumber] != 1){
System.out.println(team1 + " " + teamNumber + " " + time);
repeat1[teamNumber] = 1;
}
else{
players1[teamNumber] = 1;
}
}else{
if(players2[teamNumber] != 0 && repeat2[teamNumber] != 1){
System.out.println(team2+ " "+ teamNumber + " " + time);
repeat2[teamNumber] = 1;
}
else{
players2[teamNumber] = 1;
}
}
}
}
}
/*
MC
CSKA
11
10 h 16 y
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 y
90 a 13 r
*/ | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 9a8360bec0ad89867ecd1cb49a921ed5 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
public class Problem493A {
private static int[] home = new int[99];
private static int[] away = new int[99];
private static String homeName;
private static String awayName;
private static int fouls;
public static void main(final String[] args) {
int line = 0;
//try (final BufferedReader br = new BufferedReader(new FileReader(args[0]));) {
try {
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
String content = br.readLine();
while (content != null && line < 3) {
if (line == 0) {
homeName = content;
}
if (line == 1) {
awayName = content;
}
if (line == 2) {
fouls = Integer.parseInt(content.trim());
}
line += 1;
content = br.readLine();
}
char card;
int minute;
int number;
String team;
while (content != null && line < fouls + 3) {
try {
final String[] tokens = content.split(" ");
card = tokens[3].charAt(0);
minute = Integer.parseInt(tokens[0]);
number = Integer.parseInt(tokens[2]);
team = tokens[1].charAt(0) == 'a' ? awayName : homeName;
if(team.equals(homeName)) {
if ((card == 'r' && home[number-1] < 2) || (card=='y' && home[number-1] == 1)){
System.out.println(team + ' ' + number + ' ' + minute);
home[number-1] = 2;
} else {
if(card=='y' && home[number-1]==0) {
home[number-1] = 1;
}
}
} else {
if ((card == 'r' && away[number-1] < 2) || (card=='y' && away[number-1] == 1)){
System.out.println(team + ' ' + number + ' ' + minute);
away[number-1] = 2;
} else {
if(card=='y' && away[number-1]==0) {
away[number-1] = 1;
}
}
}
} catch(Exception ex) {
}
line += 1;
content = br.readLine();
}
} catch (final IOException ioe) {
ioe.printStackTrace();
}
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 86d52e877e5d03e9ee69dbb25493116a | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String team[] = new String[2];
String map = "ha";
String card = "yr";
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 2; i++) {
team[i] = sc.next();
}
int member[][] = new int[2][100];
int N = sc.nextInt();
for(int i = 0; i < N; i++) {
int time = sc.nextInt();
int id = map.indexOf(sc.next().charAt(0));
int name = sc.nextInt();
int add = card.indexOf(sc.next().charAt(0)) + 1;
if(member[id][name] >= 2)
continue;
member[id][name] += add;
if(member[id][name] >= 2) {
System.out.println(team[id]+" "+name+" "+time);
}
}
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 70cf43f837ff96b03320a7e8ce5248cf | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class A_Div2_281 {
public static void main(String[]arg) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String home = in.readLine();
String vis = in.readLine();
int n = Integer.parseInt(in.readLine());
StringTokenizer st;
TreeSet<Integer> h = new TreeSet<Integer>();
TreeSet<Integer> a = new TreeSet<Integer>();
TreeSet<Integer> hv = new TreeSet<Integer>();
TreeSet<Integer> ha = new TreeSet<Integer>();
HashMap<String,ArrayList<Point>> map = new HashMap<String,ArrayList<Point>>();
map.put(home,new ArrayList<Point>());
map.put(vis,new ArrayList<Point>());
for(int i = 0; i < n; i++)
{
st = new StringTokenizer(in.readLine());
int t = Integer.parseInt(st.nextToken());
String e = st.nextToken();
int m = Integer.parseInt(st.nextToken());
String c = st.nextToken();
if(e.equals("h"))
{
ArrayList<Point> la = map.get(home);
if(c.equals("r") && !hv.contains(m))
{
la.add(new Point(m,t));
map.put(home, la);
System.out.println(home + " " + m + " " + t);
hv.add(m);
}
else
{
if(h.contains(m))
{
if(!hv.contains(m))
{
la.add(new Point(m,t));
map.put(home, la);
hv.add(m);
System.out.println(home + " " + m + " " + t);
}
}
else
h.add(m);
}
}
else
{
ArrayList<Point> la = map.get(vis);
if(c.equals("r")&&!ha.contains(m))
{
la.add(new Point(m,t));
map.put(vis, la);
ha.add(m);
System.out.println(vis + " " + m + " " + t);
}
else
{
if(a.contains(m))
{
if(!ha.contains(m))
{
la.add(new Point(m,t));
map.put(vis, la);
ha.add(m);
System.out.println(vis + " " + m + " " + t);
}
}
else
a.add(m);
}
}
}
/**
ArrayList<Point> ho = map.get(home);
if(!ho.isEmpty())
{
while(ho.size()>0)
{
Point p = ho.remove(0);
int m = p.x;
int t = p.y;
System.out.println(home + " "+ m + " " + t);
}
}
ArrayList<Point> vi = map.get(vis);
if(!vi.isEmpty())
{
while(vi.size()>0)
{
Point p = vi.remove(0);
int m = p.x;
int t = p.y;
System.out.println(vis + " "+ m + " " + t);
}
}**/
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | eda04d8036d5a426a6c4ea9aadacdc96 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import static java.lang.Integer.parseInt;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.StringTokenizer;
public class con281_A {
static BufferedReader br = new BufferedReader( new InputStreamReader(System.in, StandardCharsets.US_ASCII) );
static StringTokenizer tok;
public static void main(String[] args) throws Exception {
int[][] cards = new int[2][100];
// int[] cards2 = new int[100];
Arrays.fill(cards[0], 0);
Arrays.fill(cards[1], 0);
tok = newLine();
String t1 = tok.nextToken();
tok = newLine();
String t2 = tok.nextToken();
tok = newLine();
int n = parseInt(tok.nextToken());
for (int i = 0; i < n; i++) {
tok = newLine();
int t = parseInt(tok.nextToken()); // time
char c = tok.nextToken().charAt(0);
int m = parseInt(tok.nextToken()); // player number
char card = tok.nextToken().charAt(0);
String na = "";
int idx;
if ( c == 'h') {
na = t1;
idx = 0;
} else {
na = t2;
idx = 1;
}
if ( card == 'r' && cards[idx][m] < 2 ) {
cards[idx][m] += 2;
System.out.printf("%s %d %d%n", na, m, t);
} else {
cards[idx][m] += 1;
if (cards[idx][m] == 2) {
System.out.printf("%s %d %d%n", na, m, t);
}
}
}
}
private static StringTokenizer newLine() throws Exception {
return new StringTokenizer(br.readLine());
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | e9e3f4e1c51f3852af389572fd6042e4 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner s=new Scanner(System.in);
ArrayList<Integer> t1=new ArrayList<Integer>();
ArrayList<Integer> t2=new ArrayList<Integer>();
ArrayList<Integer> t3=new ArrayList<Integer>();
ArrayList<Integer> t4=new ArrayList<Integer>();
String s1=s.nextLine();
String s2=s.nextLine();
int num=Integer.parseInt(s.nextLine());
for(int i=0;i<num;i++){
String line=s.nextLine();
int time;
char card;
int no;
char tc;
if(line.charAt(1)!=' '){
time=Integer.parseInt(line.substring(0, 2));
tc=line.charAt(3);
if(line.charAt(6)!=' '){
no=Integer.parseInt(line.substring(5,7));
card=line.charAt(8);
}else{
no=Integer.parseInt(line.substring(5,6));
card=line.charAt(7);
}
}else{
time = Integer.parseInt(line.substring(0,1));
tc=line.charAt(2);
if(line.charAt(5)!=' '){
no=Integer.parseInt(line.substring(4,6));
card=line.charAt(7);
}else{
no=Integer.parseInt(line.substring(4,5));
card=line.charAt(6);
}
}
if(card=='r'){
if(tc=='h' && !t3.contains(no)){
System.out.println(s1+" "+no+" "+time);
t3.add(no);
}else if(tc=='a' && !t4.contains(no)){
System.out.println(s2+" "+no+" "+time);
t4.add(no);
}
}else{
if(tc=='h'){
if(t1.contains(no) && !t3.contains(no)){
System.out.println(s1+" "+no+" "+time);
t3.add(no);
}else if(!t1.contains(no)){
t1.add(no);
}
}else{
if(t2.contains(no) && !t4.contains(no)){
System.out.println(s2+" "+no+" "+time);
t4.add(no);
}else if(!t2.contains(no)){
t2.add(no);
}
}
}
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | fa12fba29f595ba925219c755fdc717c | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.*;
public class VasyaAndFootball {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String home = sc.nextLine();
String away = sc.nextLine();
int n = Integer.parseInt(sc.nextLine());
String line, player, team;
String[] ret;
// System.out.println("home : " + home + " away: " + away + " n : " + n);
HashMap<String, Character> map = new HashMap<String, Character>();
for(int i = 0; i < n; i++)
{
line = sc.nextLine();
// System.out.println(line);
ret = line.split(" ");
// System.out.println(ret.length);
team = (ret[1].equals("h"))?home : away;
player = team + ret[2];
if(ret[3].equals("r"))
{
if(map.containsKey(player) && map.get(player) == 'r')
continue;
System.out.println(team + " " + ret[2] + " " + ret[0]);
map.put(player, 'r');
continue;
}
if(map.containsKey(player))
{
if(map.get(player) == 'y')
{
System.out.println(team + " " + ret[2] + " " + ret[0]);
map.put(player, 'r');
}
continue;
}
map.put(player, 'y');
}
sc.close();
return;
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 188667fa92e27b402b59268613ac849d | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Scanner;
/*
* 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 Madi
*/
public class A493 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String team1 = sc.nextLine();
String team2 = sc.nextLine();
int n = Integer.parseInt(sc.nextLine());
int[] plr1 = new int[100];
int[] plr2 = new int[100];
String[] a;
for (int i = 0; i < n; i++) {
a = sc.nextLine().split(" ");
if (a[1].equalsIgnoreCase("h")) {
if (a[3].equalsIgnoreCase("r") && plr1[Integer.parseInt(a[2])] != 100) {
System.out.println(team1 + " " + a[2] + " " + a[0]);
plr1[Integer.parseInt(a[2])] = 100;
} else if (plr1[Integer.parseInt(a[2])] != 100) {
if (plr1[Integer.parseInt(a[2])] == 1) {
System.out.println(team1 + " " + a[2] + " " + a[0]);
plr1[Integer.parseInt(a[2])] = 100;
} else {
plr1[Integer.parseInt(a[2])] = 1;
}
}
} else {
if (a[3].equalsIgnoreCase("r") && plr2[Integer.parseInt(a[2])] != 100) {
System.out.println(team2 + " " + a[2] + " " + a[0]);
plr2[Integer.parseInt(a[2])] = 100;
} else if (plr2[Integer.parseInt(a[2])] != 100) {
if (plr2[Integer.parseInt(a[2])] == 1) {
System.out.println(team2 + " " + a[2] + " " + a[0]);
plr2[Integer.parseInt(a[2])] = 100;
} else {
plr2[Integer.parseInt(a[2])] = 1;
}
}
}
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 95e5947e5393a67931c81d5828bfef6a | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**Vasya and Football */
public class VF {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = null;
String hometeam = null;
String awayteam = null;
int linecount = 0;
int[] timeline = new int[256];
int[] hteam = new int[256];
int[] ateam = new int[256];
int[] hplayered = new int[256];
int[] aplayered = new int[256];
int fouls;
for(int i=0;i <ateam.length; i++){
ateam[i] = 0;
hteam[i] = 0;
}
while((input = br.readLine()) != null){
linecount++;
if (linecount == 1) {
hometeam = input;
continue;
}
if(linecount == 2) {
awayteam = input;
continue;
}
if (linecount ==3) {
fouls = Integer.parseInt(input);
continue;
}
int time;char team;int playercode;char cardType;
StringTokenizer st = new StringTokenizer(input);
while(st.hasMoreTokens()){
time = Integer.parseInt(st.nextToken());
team = st.nextToken().toCharArray()[0];
playercode = Integer.parseInt(st.nextToken());
cardType = st.nextToken().toCharArray()[0];
if (team == 'h') {
if((hteam[playercode] == 0) && cardType == 'y') {
hteam[playercode]++;
}
else if (hplayered[playercode] == 0){
hplayered[playercode]++;
System.out.println(hometeam + " "+playercode+" "+time);
}
} else {
if((ateam[playercode] == 0) && cardType == 'y') {
ateam[playercode]++;
}
else if (aplayered[playercode] == 0){
aplayered[playercode]++;
System.out.println(awayteam + " "+playercode+" "+time);
}
}
}
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 0c409a56ccbd9e62bedbc2e8f0a6faf6 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | /**
* Created by sreenidhisreesha on 12/8/14.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**Vasya and Football */
public class VF {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = null;
String hometeam = null;
String awayteam = null;
int linecount = 0;
int[] timeline = new int[256];
int[] hteam = new int[256];
int[] ateam = new int[256];
int[] hplayered = new int[256];
int[] aplayered = new int[256];
int fouls;
for(int i=0;i <ateam.length; i++){
ateam[i] = 0;
hteam[i] = 0;
}
while((input = br.readLine()) != null){
linecount++;
if (linecount == 1) {
hometeam = input;
continue;
}
if(linecount == 2) {
awayteam = input;
continue;
}
if (linecount ==3) {
fouls = Integer.parseInt(input);
continue;
}
int time;
char team;
int playercode;
char cardType;
StringTokenizer st = new StringTokenizer(input);
while(st.hasMoreTokens()){
time = Integer.parseInt(st.nextToken());
team = st.nextToken().toCharArray()[0];
playercode = Integer.parseInt(st.nextToken());
cardType = st.nextToken().toCharArray()[0];
if (team == 'h') {
if (cardType == 'r' && (hplayered[playercode] == 0)) {
System.out.println(hometeam + " "+playercode+" "+time);
hplayered[playercode] = time;
hteam[playercode] = -1;
continue;
} else if(cardType == 'y' && hteam[playercode] != -1){
if (hteam[playercode] != 0) {
System.out.println(hometeam + " "+playercode+" "+time);
hteam[playercode] = -1;
hplayered[playercode] = time;
continue;
}
hteam[playercode] = time;
}
} else {
if (cardType == 'r' && (aplayered[playercode] == 0)) {
System.out.println(awayteam + " "+playercode+" "+time);
aplayered[playercode] = time;
hteam[playercode] = -1;
continue;
} else if(cardType == 'y' && ateam[playercode] != -1){
if (ateam[playercode] != 0) {
System.out.println(awayteam + " "+playercode+" "+time);
ateam[playercode] = -1;
aplayered[playercode] = time;
continue;
} else {
ateam[playercode] = time;
}
}
}
}
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 3b5c174eb38ece57a692c0b90066831a | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.*;
public class fouls {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String tm1 = sc.nextLine();
String tm2 = sc.nextLine();
int fls = Integer.valueOf(sc.nextLine());
Map<Integer, prof> map1 = new HashMap<Integer, prof>();
Map<Integer, prof> map2 = new HashMap<Integer, prof>();
while (fls > 0) {
String[] ss = sc.nextLine().split(" ");
int min = Integer.valueOf(ss[0]);
String side = ss[1];
int pnum = Integer.valueOf(ss[2]);
String crd = ss[3];
if (side.equals("a")) {
if (map1.containsKey(pnum)) {
if (!map1.get(pnum).red)
map1.put(pnum, new prof(min, true, pnum, 1));
} else {
if (crd.equals("r")) {
map1.put(pnum, new prof(min, true, pnum, 1));
} else {
map1.put(pnum, new prof(min, false, pnum, 1));
}
}
} else {
if (map2.containsKey(pnum)) {
if (!map2.get(pnum).red)
map2.put(pnum, new prof(min, true, pnum, 2));
} else {
if (crd.equals("r")) {
map2.put(pnum, new prof(min, true, pnum, 2));
} else {
map2.put(pnum, new prof(min, false, pnum, 2));
}
}
}
fls--;
}
List<prof> res = new ArrayList<prof>();
for (prof p : map1.values()) {
if (p.red)
res.add(p);
}
for (prof p : map2.values()) {
if (p.red)
res.add(p);
}
Collections.sort(res);
for (prof h : res) {
if (h.team == 1) {
System.out.println(tm2 + " " + h.playnum + " " + h.time);
} else {
System.out.println(tm1 + " " + h.playnum + " " + h.time);
}
}
}
static class prof implements Comparable<prof> {
int time;
boolean red;
int playnum;
int team;
public prof(int time, boolean red, int playnum, int team) {
this.time = time;
this.red = red;
this.playnum = playnum;
this.team = team;
}
@Override
public int compareTo(prof arg) {
return (this.time - arg.time);
}
public String toString() {
return (this.time + " " + this.red);
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 705673ea2df27907d57907290a691e5b | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class CF_493A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String homeTeamName = in.nextLine();
String AwayTeamName = in.nextLine();
int n = in.nextInt();
in.nextLine();
// System.out.println("n = "+n);
String array[][] = new String[n][4];
int y = 0;
for(int i=0; i<n; i++){
String input[] = in.nextLine().split(" ");
array[i] = input;
if(input[3].equals("r")){
// System.out.println(input[0]+"-"+input[2]);
boolean found = false;
int j=0;
for(j=i-1; j>=0 && !found; j--){
if(array[j][2].equals(input[2]) && array[j][1].equals(input[1]) && !array[j][3].equals("y"))
found = true;
}
// if(j==0)
// found = true;
if(!found){
if(input[1].equals("h"))
System.out.print(homeTeamName+" ");
else
System.out.print(AwayTeamName+" ");
System.out.println(input[2] +" "+input[0]);
}
}else{
for(int j=i-1; j>=0; j--){
// System.out.println("j= "+j);
if(array[j][2].equals(input[2]) && array[j][1].equals(input[1]) ){
if(array[j][3].equals("y")){
if(input[1].equals("h"))
System.out.print(homeTeamName+" ");
else
System.out.print(AwayTeamName+" ");
System.out.println(input[2] +" "+input[0]);
}
array[j][3] = "r";
array[i][3] = "r";
j=-1;
}
}
}
}
// System.out.println("=============================");
//
// for(int i=0; i<n; i++){
// System.out.println(array[i][0]+"-"+array[i][1]+"-"+array[i][2]+"-"+array[i][3]);
// }
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 14f7edcbefa9097b1f06d3420bf2568c | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.HashMap;
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, OutputWriter out) {
String home = in.next();
String away = in.next();
int n = in.readInt();
HashMap<Integer, Integer> homehm = new HashMap<>();
HashMap<Integer, Integer> awayhm = new HashMap<>();
for (int i = 0; i < n; i++) {
int min = in.readInt();
char team = in.next().toCharArray()[0];
int num = in.readInt();
char card = in.next().toCharArray()[0];
int cardval = card == 'y' ? 1 : 2;
//out.printLine(min + " " + team + " " + num + " " + card);
if (team == 'h') {
if (homehm.containsKey(num) && homehm.get(num).equals(1)) {
out.printLine(home + " " + num + " " + min);
homehm.put(num, 1000);
}
else if (!homehm.containsKey(num)) {
if (cardval == 2){
out.printLine(home + " " + num + " " + min);
homehm.put(num, 1000);
}
else{
homehm.put(num, 1);
}
}
}
else{
if (awayhm.containsKey(num) && awayhm.get(num).equals(1)) {
out.printLine(away + " " + num + " " + min);
awayhm.put(num, 1000);
}
else if (!awayhm.containsKey(num)){
if (cardval == 2){
out.printLine(away + " " + num + " " + min);
awayhm.put(num, 1000);
}
else{
awayhm.put(num, 1);
}
}
}
}
}
}
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 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 printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 7159be2242b2165b9945ef6149dcd240 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
public class Trial {
static public void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String hTeam = br.readLine();
String aTeam = br.readLine();
int n = Integer.parseInt(br.readLine());
int[] home = new int[100] , away = new int[100];
for(int i=0;i<n;i++){
String[] in = br.readLine().split(" ");
if(in[1].equals("a")){
int num =Integer.parseInt(in[2]);
away[num]++;
if((away[num]==2 || in[3].equals("r")) && away[num]<=2 ){
away[num]=3;
System.out.println(aTeam+" "+num+" "+in[0]);
}
}
else{
int num =Integer.parseInt(in[2]);
home[num]++;
if( home[num]<=2 && (home[num]==2 || in[3].equals("r")) ){
home[num]=3;
System.out.println(hTeam+" "+num+" "+in[0]);
}
}
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | e2ec66424d376f05c105229ebf460ad4 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Scanner;
public class A_Vasya_and_Football_Round281 {
public static class falou {
public int min, num;
public String team, type;
}
public static class out implements Comparator<out> {
public String team;
public int min, num;
public String toString() {
return team + " " + num + " " + min;
}
@Override
public int compare(out arg0, out arg1) {
return arg0.min - arg1.min;
}
}
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
String home = x.next(), away = x.next();
int n = x.nextInt();
ArrayList<falou> list = new ArrayList<falou>();
ArrayList<out> eventOut = new ArrayList<out>();
for (int i = 0; i < n; i++) {
falou temp = new falou();
temp.min = x.nextInt();
temp.team = (x.next().charAt(0) == 'a' ? away : home);
// System.out.println( " team " + temp.team );
temp.num = x.nextInt();
temp.type = x.next();
if (temp.type.charAt(0) == 'r') {
out o = new out();
o.min = temp.min;
o.num = temp.num;
o.team = temp.team;
eventOut.add(o);
} else
list.add(temp);
}
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
if (list.get(i).team.equals(list.get(j).team)
&& list.get(i).num == list.get(j).num) {
out o = new out();
o.min = Math.max(list.get(j).min, list.get(i).min);
o.num = list.get(j).num;
o.team = list.get(j).team;
eventOut.add(o);
break;
}
}
}
Collections.sort(eventOut, new out());
for (int i = 0; i < eventOut.size(); i++) {
for (int j = i + 1 ; j < eventOut.size(); j++) {
if (eventOut.get(i).team.equals(eventOut.get(j).team) && eventOut.get(i).num == eventOut.get(j).num){
eventOut.remove(j);
j--;
}
}
}
for (int i = 0; i < eventOut.size(); i++) {
System.out.println(eventOut.get(i).toString());
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | bb325aa68fb6a7cf491f50888e1ea73c | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
/**
* Ashesh Vidyut (Drift King) *
*/
public class A {
public static void main(String[] args) {
try {
InputReader in = new InputReader(System.in);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
String home = in.readLine();
String away = in.readLine();
int n = in.readInt();
int homecard[] = new int[100];
int awaycard[] = new int[100];
Vector<Event> vec = new Vector<Event>();
for (int i = 0; i < n; i++) {
int t = in.readInt();
char teamc = in.readCharacter();
int pid = in.readInt();
char cc = in.readCharacter();
vec.add(new Event(t, teamc, pid, cc));
}
Collections.sort(vec);
Queue<RedCard> redc = new LinkedList<RedCard>();
for (int i = 0; i < n; i++) {
Event e = vec.get(i);
int pid = e.pid;
int time = e.time;
char teamc = e.teamc;
char cardc = e.cardcol;
if(teamc == 'h'){
if(cardc == 'r'){
if(homecard[pid] == 2){
continue;
}
homecard[pid] = 2;
redc.add(new RedCard(pid, home, time));
}
else{
if(homecard[pid] == 2){
continue;
}
else if(homecard[pid] == 0){
homecard[pid]++;
}
else if(homecard[pid] == 1){
homecard[pid]++;
redc.add(new RedCard(pid, home, time));
}
}
}
else{
if(cardc == 'r'){
if(awaycard[pid] == 2){
continue;
}
awaycard[pid] = 2;
redc.add(new RedCard(pid, away, time));
}
else{
if(awaycard[pid] == 2){
continue;
}
else if(awaycard[pid] == 0){
awaycard[pid]++;
}
else if(awaycard[pid] == 1){
awaycard[pid]++;
redc.add(new RedCard(pid, away, time));
}
}
}
}
while(!redc.isEmpty()){
RedCard r = redc.poll();
out.write(r.team+" ");
out.write(Integer.toString(r.playerid)+" ");
out.write(Integer.toString(r.time));
out.newLine();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
class Event implements Comparable<Event>{
int time, pid;
char teamc;
char cardcol;
public Event(int t, char tc, int pid, char cc){
this.time = t;
this.teamc = tc;
this.pid = pid;
this.cardcol = cc;
}
public int compareTo(Event that){
return this.time - that.time;
}
}
class RedCard{
int playerid;
String team;
int time;
public RedCard(int pid, String tm, int time){
this.playerid = pid;
this.team = tm;
this.time = time;
}
}class InputReader {
private boolean finished = false;
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++];
}
public int peek() {
if (numChars == -1)
return -1;
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
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 long readLong() {
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 String readString() {
int length = readInt();
if (length < 0)
return null;
byte[] bytes = new byte[length];
for (int i = 0; i < length; i++)
bytes[i] = (byte) read();
try {
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
return new String(bytes);
}
}
public static boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuffer buf = new StringBuffer();
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;
}
public String readLine(boolean ignoreEmptyLines) {
if (ignoreEmptyLines)
return readLine();
else
return readLine0();
}
public BigInteger readBigInteger() {
try {
return new BigInteger(readString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
public char readCharacter() {
int c = read();
while (isSpaceChar(c))
c = read();
return (char) c;
}
public double readDouble() {
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, readInt());
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, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean isExhausted() {
int value;
while (isSpaceChar(value = peek()) && value != -1)
read();
return value == -1;
}
public String next() {
return readString();
}
public boolean readBoolean() {
return readInt() == 1;
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 302f062ed1c16f9b7ce56adfee9a58a9 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Scanner;
public class _493A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String home = sc.next();
String nohome = sc.next();
int h[] = new int[100];
int n[] = new int[100];
boolean hjjj[] = new boolean[100];
boolean njjj[] = new boolean[100];
int am = sc.nextInt();
for (int i = 0; i < am; i++) {
int time = sc.nextInt();
String c = sc.next();
int yyy = sc.nextInt();
if (c.equals("a")) {
if ((n[yyy] += ((sc.next().equals("y")) ? 1 : 2)) >= 2
&& !njjj[yyy]) {
System.out.println(nohome + " " + yyy + " " + time);
njjj[yyy] = true;
}
} else if ((h[yyy] += ((sc.next().equals("y")) ? 1 : 2)) >= 2
&& !hjjj[yyy]) {
System.out.println(home + " " + yyy + " " + time);
hjjj[yyy] = true;
}
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 78d7f2ad464652fa5ded2dc9c4a48a79 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner s=new Scanner(System.in);
String a=s.next();String b=s.next();
int n=s.nextInt();
int c[]=new int[n];
char d[]=new char[n];
int e[]=new int[n];
char f[]=new char[n];
for(int i=0;i<n;i++){
//int t=s.nextInt();
c[i]=s.nextInt();
d[i]=s.next().charAt(0);
e[i]=s.nextInt();
f[i]=s.next().charAt(0);
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(d[i]==d[j] && e[i]==e[j] && f[i]==f[j] && f[i]=='y'){
f[j]='r';
}
}
}
int g[]=new int[n];
for(int i=0;i<n;i++)
g[i]=c[i];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(d[i]==d[j] && e[i]==e[j] && f[i]==f[j] && f[i]=='r'){
f[j]='y';
//f[j]='r';/
}
}
}
for(int i=0;i<n;i++ ){
if(f[i]=='r'){
if(d[i]=='h'){
System.out.print(a+" ");
}
else
System.out.print(b+" ");
System.out.println(e[i]+" "+c[i]);}
//System.out.println();
}
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 9e2d65e9cc440e1fc5d1a5decb03a86b | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(System.out)));
public static void main(String[] args) throws IOException {
// PrintStream out = new PrintStream(new
// FileOutputStream("out.out"));
Scan scan = new Scan();
String home = scan.next();
String away = scan.next();
int n =scan.nextInt();
p p[] = new p[n];
int top = 0;
for(int i = 0;i<n;i++){
int time = scan.nextInt();
String s = scan.next();
int num = scan.nextInt();
String card = scan.next();
boolean flag =true;
for(int j = 0;j<top;j++){
if(p[j].s.equals(s)&&p[j].num==num){
if(!p[j].card.equals("r")){
p[j].card="r";
p[j].time = time;}
flag = false;
}
}
if(flag)
p[top++] = new p(time,s,num,card);
}Arrays.sort(p,0,top,new compare());
for(int i = 0 ;i<top;i++){
if(p[i].card.equals("r")){
if(p[i].s.equals("h"))
out.println(home+" "+p[i].num+" "+p[i].time);
else
out.println(away+" "+p[i].num+" "+p[i].time);
}
}
out.flush();
}
static class p{
int time;
String s;
int num;
String card;
public p(int time,String s,int num,String card){
this.time=time;
this.s=s;
this.num=num;
this.card=card;
}
}
static class compare implements Comparator<p>{
@Override
public int compare(p a, p b) {
if(a.time>b.time)
return 1;
return -1;
}
}
}
class Scan {
BufferedReader buffer;
StringTokenizer tok;
Scan() {
buffer = new BufferedReader(new InputStreamReader(System.in));
// FileReader filereader=null;
// try {
// filereader = new FileReader("in.in");
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// buffer = new BufferedReader(filereader);
}
boolean hasNext() {
while (tok == null || !tok.hasMoreElements()) {
try {
tok = new StringTokenizer(buffer.readLine());
} catch (Exception e) {
return false;
}
}
return true;
}
String next() {
if (hasNext())
return tok.nextToken();
return null;
}
String nextLine() {
String s = null;
try {
s = buffer.readLine();
} catch (Exception e) {
return null;
}
return s;
}
char nextChar() {
try {
return ((char) buffer.read());
} catch (Exception e) {
}
return '\0';
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 0c136acda4880ec5b6aa6ccd18a57438 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Scanner;
public class Contest_281 {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
String home = "", away = "";
home = in.next();
away = in.next();
int n = in.nextInt();
int m1[] = new int[101];
boolean f1[] = new boolean[101];
int m2[] = new int[101];
boolean f2[] = new boolean[101];
int f = 0;
for(int i = 0 ; i < n ; i++){
int t = in.nextInt();
String h = in.next();
f = in.nextInt();
String y = in.next();
if(h.charAt(0)=='h'){
if(y.charAt(0)=='y'){
m1[f]+=1;
}else{
m1[f]+=2;
}
if(m1[f]>=2&&f1[f]==false){
System.out.println(home+" "+f+" "+t);
f1[f] = true;
}
}else{
if(y.charAt(0)=='y'){
m2[f]+=1;
}else{
m2[f]+=2;
}
if(m2[f]>=2&&f2[f]==false){
System.out.println(away+" "+f+" "+t);
f2[f] = true;
}
}
}
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | c6a5368c001ab2fc6a6749a821c66d41 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | //package Codeforces.Div2A_281.Code1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
/*
* some cheeky quote
*/
public class Main
{
FastScanner in;
PrintWriter out;
ArrayList<Player> home = new ArrayList<Player>();
ArrayList<Player> away = new ArrayList<Player>();
public void solve() throws IOException
{
String homeName = in.next();
String awayName = in.next();
int n = in.nextInt();
for (int i = 0; i < n; i++)
{
int min = in.nextInt();
boolean isHome = in.next().charAt(0) == 'h';
int num = in.nextInt();
char card = in.next().charAt(0);
boolean isFound = false;
ArrayList<Player> temp = (isHome) ? home : away;
for (int j = 0; j < temp.size(); j++)
{
Player p = temp.get(j);
if (p.n == num)
{
isFound = true;
if ((card == 'r' || p.card == 'y') && p.card != 'r')
{
String team = isHome ? homeName : awayName;
System.out.println(team + " " + num + " " + min);
temp.get(j).card = 'r';
}
}
}
if (!isFound)
{
Player t = new Player(num, isHome, card);
temp.add(t);
if (card == 'r')
{
String team = isHome ? homeName : awayName;
System.out.println(team + " " + num + " " + min);
}
}
}
}
public void run()
{
try
{
in = new FastScanner();
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
class FastScanner
{
BufferedReader br;
StringTokenizer st;
FastScanner()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
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());
}
}
public static void main(String[] arg)
{
new Main().run();
}
}
class Player
{
int n;
boolean isHome;
char card;
public Player(int n, boolean isHome, char card)
{
this.n = n;
this.isHome = isHome;
this.card = card;
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 34a4620e4eb6af5826c4c3f66d4307ca | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;
/**
* Created by ramasamy on 12/3/2014.
*/
public class VFootball {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String homeTeam = sc.nextLine();
String awayTeam = sc.nextLine();
int n = sc.nextInt();
int[] h = new int[100];
int[] a = new int[100];
for (int i = 0; i < n; i++) {
int t = sc.nextInt();
int s = sc.next().charAt(0);
int p = sc.nextInt();
int f = sc.next().charAt(0);
if (s == 'h'){
if (f == 'r' && (h[p] == -1 || h[p] == 0))
h[p] = t;
if ((f == 'y') && (h[p] == -1)){
h[p] = t;
}
if (f == 'y' && h[p] == 0){
h[p] = -1;
}
}else{
if (f == 'r' && (a[p] == -1 || a[p] == 0))
a[p] = t;
if (f == 'y' && a[p] == -1){
a[p] = t;
}if (f == 'y' && a[p] == 0){
a[p] = -1;
}
}
}
ArrayList<Sorter> al = new ArrayList<Sorter>();
for (int i = 0; i < 100; i++) {
if (h[i] != 0 && h[i] != -1){
Sorter s = new Sorter();
s.team = homeTeam;
s.number = i;
s.minute = h[i];
al.add(s);
}
if (a[i] != 0 && a[i] != -1){
Sorter s = new Sorter();
s.team = awayTeam;
s.number = i;
s.minute = a[i];
al.add(s);
}
}
Collections.sort(al);
for (Sorter s : al){
System.out.println(s.team + " "+ s.number + " "+ s.minute);
}
}
}
class Sorter implements Comparable<Sorter>{
String team;
int number;
int minute;
public int compareTo(Sorter t){
return minute - t.minute;
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | 78d70cff4a79d6b9eb25ce226093dba9 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class P493A {
public P493A() {
// TODO Auto-generated constructor stub
Scanner scan = new Scanner(System.in);
String teamA = scan.nextLine();
String teamB = scan.nextLine();
int fouls = Integer.parseInt(scan.nextLine());
HashMap<String, Integer> player = new HashMap<String, Integer>();
for(int v=0;v<fouls;v++) {
String[] line = scan.nextLine().split(" ");
String pl = line[1] + line[2];
player.put(pl, (player.get(pl)!=null?player.get(pl):0)+ (line[3].equals("y")?1:2));
if(player.get(pl) == 2 || (line[3].equals("r") && player.get(pl) == 3)) {
System.out.println((line[1].equals("h")?teamA:teamB) + " " + line[2] + " " + line[0]);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new P493A();
}
}
| Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | d07a442356f80d27775dcfa2780657c7 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;
/*
import doge.wow.Shibeforces;
░░░░░░░░░▄░░░░░░░░░░░░░░▄░░░░
░░░░░░░░▌▒█░░░░░░░░░░░▄▀▒▌░░░
░░░░░░░░▌▒▒█░░░░░░░░▄▀▒▒▒▐░░░
░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐░░░
░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐░░░
░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌░░░
░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌░░
░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐░░
░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌░
░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌░
▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐░
▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐░
░▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌░
░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐░░
░░▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌░░
░░░░▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀░░░
░░░░░░▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀░░░░░
░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▀▀░░░░░░░░
wow
much code violence
such dangers
hw dis hapen?!!
*/
public class Main {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
String home = in.next();
String away = in.next();
int n = in.nextInt();
int h[] = new int[100];
int a[] = new int[100];
boolean hcase[] = new boolean[100];
boolean acase[] = new boolean[100];
ArrayList<String> res = new ArrayList<String>();
for(int i = 1; i <= n;i++){
int t = in.nextInt();
char team = in.next().charAt(0);
int m = in.nextInt();
char card = in.next().charAt(0);
String solu = "";
if(team == 'h'){
if(card == 'y'){
++h[m];
if(h[m] >= 2){
// solu += t + " ";
solu += home + " ";
solu += m + " ";
solu += t;
res.add(solu);
}
}else if(card == 'r'){
// solu += t + " ";
solu += home + " ";
solu += m + " ";
solu += t;
res.add(solu);
}
}else if(team == 'a'){
if(card == 'r'){
//solu += t + " ";
solu += away + " ";
solu += m + " ";
solu += t;
res.add(solu);
}else if(card == 'y'){
++a[m];
if(a[m] >= 2){
//solu += t + " ";
solu += away + " ";
solu += m + " ";
solu += t;
res.add(solu);
}
}
}
}
//for(String i : res) System.out.println(i);
LinkedHashSet<String> s = new LinkedHashSet<String>(res);
ArrayList<String> resf = new ArrayList<String>();
for(String i : s){
String temp[] = i.split(" ");
String check = temp[0] + " " + temp[1];
//System.out.println("check is "+check);
boolean flag = false;
for(int j = 0; j < resf.size();j++){
String temp2[] = resf.get(j).split(" ");
String check2 = temp2[0] + " " + temp2[1];
if(check.equals(check2)){
flag = true;
break;
}
}
if(!flag) resf.add(i);
else flag = false;
}
//System.out.println(resf);
for(String i : resf){
System.out.println(i);
}
}
}
/*
MC
CSKA
6
1 a 1 y
2 h 1 y
3 a 1 y
4 h 1 y
5 a 1 y
6 h 1 y
*/ | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output | |
PASSED | ba9e14fe33b981a423f713e30e65ed63 | train_001.jsonl | 1417618800 | Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[]args){
Scanner in = new Scanner(System.in);
String h = in.next();
String a = in.next();
int f = in.nextInt();
int[]cnt = new int[100];
int[]cnt1 = new int[100];
for(int i=0 ; i<f ; i++){
int t = in.nextInt();
char c = in.next().charAt(0);
int num = in.nextInt();
char card = in.next().charAt(0);
if(card == 'y' && c == 'h' && cnt[num] != 100){
cnt[num]++;
if(cnt[num] == 2){
System.out.println(h +" "+num + " " +t);
cnt[num] = 100;
}
}
if(card == 'y' && c == 'a' && cnt1[num] != 100){
cnt1[num]++;
if(cnt1[num] == 2){
System.out.println(a +" "+num + " " +t);
cnt1[num] = 100;
}
}
if(card == 'r' && c == 'h' && cnt[num] != 100){
System.out.println(h +" "+num + " " +t);
cnt[num] = 100;
}
else if(card == 'r' && c == 'a' && cnt1[num] != 100){
System.out.println(a +" "+num + " " +t);
cnt1[num] = 100;
}
}
}
} | Java | ["MC\nCSKA\n9\n28 a 3 y\n62 h 25 y\n66 h 42 y\n70 h 25 y\n77 a 4 y\n79 a 25 y\n82 h 42 r\n89 h 16 y\n90 a 13 r"] | 2 seconds | ["MC 25 70\nMC 42 82\nCSKA 13 90"] | null | Java 7 | standard input | [
"implementation"
] | b1f78130d102aa5f425e95f4b5b3a9fb | The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct. Next follows number n (1 ≤ n ≤ 90) — the number of fouls. Each of the following n lines contains information about a foul in the following form: first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs; then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player; then goes the player's number m (1 ≤ m ≤ 99); then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given. The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute. | 1,300 | For each event when a player received his first red card in a chronological order print a string containing the following information: The name of the team to which the player belongs; the player's number in his team; the minute when he received the card. If no player received a card, then you do not need to print anything. It is possible case that the program will not print anything to the output (if there were no red cards). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.