id
stringlengths 3
12
| title
stringlengths 3
66
| title_slug
stringlengths 3
66
| description
stringlengths 39
25.4k
| description_md
stringlengths 39
4.82k
| difficulty
stringclasses 113
values | tags
listlengths 0
9
| source
stringclasses 5
values | url
stringlengths 37
96
| type
stringclasses 2
values | release_timestamp
int64 1.7B
1.73B
⌀ | release_date
stringlengths 19
19
⌀ | time_limit_nanos
int64 1B
9B
⌀ | memory_limit_bytes
int64 256M
2.1B
⌀ | starter_code
dict | solutions
dict | test_case_generator
stringlengths 521
16.9k
| evaluator
stringlengths 200
5.31k
| generated_tests
stringlengths 3.2k
359M
| test_runners
dict |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1444
|
Yokohama Phenomena
|
yokohama-phenomena
|
Yokohama Phenomena
Do you know about Yokohama Phenomena? The phenomenon takes place when three programmers, sitting around a table, hold a single pen together above a board. A grid of squares is drawn on the board, with each square marked with a single letter. Although none of the participants purposely moves the pen, its nib, as if it has a will, goes down to one of the squares marked with Y, and then starts moving on the board. The squares passed are marked with O, K, O, H, A, and M in this order, and then the nib stops on the square marked with A.
Let us call the series of squares along such a trajectory of the nib a YOKOHAMA trace. A YOKOHAMA trace is defined as follows.
It is a series of eight squares in the given grid of squares.
Every square in the series, except for the first one, shares an edge with (is edge-adjacent to) its directly preceding square in the series.
The letters marked in the eight squares of the series are Y, O, K, O, H, A, M, and A, in this order.
Note that the same square may appear more than once in the series.
Figure A.1 (a) is an illustration of the board corresponding to Sample Input 1. Figures A.1 (b) and (c) show trajectories on two of the YOKOHAMA traces. Both traces start at the leftmost square in the upper row. The same square marked with O appears twice in the trace illustrated in Figure A.1 (c).
Figure A.1. A board and trajectories on two of the YOKOHAMA traces
You are given a grid of squares, each marked with one of six letters, A, H, K, M, O, or Y. Your task is to count how many distinct YOKOHAMA traces are possible on it.
Input
The input consists of a single test case of the following format.
$n$ $m$
$x_{1,1}$ ... $x_{1,m}$
.
.
.
$x_{n,1}$ ... $x_{n,m}$
The first two integers $n$ and $m$ ($1 \leq n \leq 10, 1 \leq m \leq 10$) describe the size of the grid. The grid has squares arranged in an $n \times m$ matrix. The following n lines describe the letters marked in the squares. The square at the $i$-th row and the $j$-th column in the grid ($1 \leq i \leq n, 1 \leq j \leq m$) has letter $x_{i,j}$ marked in it. Each $x_{i,j}$ is one of the six letters, A, H, K, M, O, or Y.
Output
Output a line containing the number of distinct YOKOHAMA traces.
Sample Input 1
2 4
YOHA
OKAM
Sample Output 1
8
Sample Input 2
3 4
YOKH
OKHA
KHAM
Sample Output 2
0
Sample Input 3
3 6
MAYOHA
AHOKAM
MAYOHA
Sample Output 3
80
|
Yokohama Phenomena
Do you know about Yokohama Phenomena? The phenomenon takes place when three programmers, sitting around a table, hold a single pen together above a board. A grid of squares is drawn on the board, with each square marked with a single letter. Although none of the participants purposely moves the pen, its nib, as if it has a will, goes down to one of the squares marked with Y, and then starts moving on the board. The squares passed are marked with O, K, O, H, A, and M in this order, and then the nib stops on the square marked with A.
Let us call the series of squares along such a trajectory of the nib a YOKOHAMA trace. A YOKOHAMA trace is defined as follows.
It is a series of eight squares in the given grid of squares.
Every square in the series, except for the first one, shares an edge with (is edge-adjacent to) its directly preceding square in the series.
The letters marked in the eight squares of the series are Y, O, K, O, H, A, M, and A, in this order.
Note that the same square may appear more than once in the series.
Figure A.1 (a) is an illustration of the board corresponding to Sample Input 1. Figures A.1 (b) and (c) show trajectories on two of the YOKOHAMA traces. Both traces start at the leftmost square in the upper row. The same square marked with O appears twice in the trace illustrated in Figure A.1 (c).
Figure A.1. A board and trajectories on two of the YOKOHAMA traces
You are given a grid of squares, each marked with one of six letters, A, H, K, M, O, or Y. Your task is to count how many distinct YOKOHAMA traces are possible on it.
Input
The input consists of a single test case of the following format.
$n$ $m$
$x_{1,1}$ ... $x_{1,m}$
.
.
.
$x_{n,1}$ ... $x_{n,m}$
The first two integers $n$ and $m$ ($1 \leq n \leq 10, 1 \leq m \leq 10$) describe the size of the grid. The grid has squares arranged in an $n \times m$ matrix. The following n lines describe the letters marked in the squares. The square at the $i$-th row and the $j$-th column in the grid ($1 \leq i \leq n, 1 \leq j \leq m$) has letter $x_{i,j}$ marked in it. Each $x_{i,j}$ is one of the six letters, A, H, K, M, O, or Y.
Output
Output a line containing the number of distinct YOKOHAMA traces.
Sample Input 1
2 4
YOHA
OKAM
Sample Output 1
8
Sample Input 2
3 4
YOKH
OKHA
KHAM
Sample Output 2
0
Sample Input 3
3 6
MAYOHA
AHOKAM
MAYOHA
Sample Output 3
80
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1444?year=2023
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null |
{
"cpp": {
"code": "#include <iostream>\n#include <vector>\n#include <string>\n\nusing namespace std;\n\nint n, m;\nvector<string> grid;\nstring target = \"YOKOHAMA\";\nint target_len = 8;\nint directions[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n\nbool isValid(int x, int y) {\n return x >= 0 && x < n && y >= 0 && y < m;\n}\n\nint dfs(int x, int y, int index) {\n if (index == target_len - 1) return 1;\n\n int count = 0;\n for (int i = 0; i < 4; ++i) {\n int nx = x + directions[i][0];\n int ny = y + directions[i][1];\n if (isValid(nx, ny) && grid[nx][ny] == target[index + 1]) {\n count += dfs(nx, ny, index + 1);\n }\n }\n return count;\n}\n\nint countYokohamaTraces() {\n int count = 0;\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n if (grid[i][j] == 'Y') {\n count += dfs(i, j, 0);\n }\n }\n }\n return count;\n}\n\nint main() {\n cin >> n >> m;\n grid.resize(n);\n for (int i = 0; i < n; ++i) {\n cin >> grid[i];\n }\n\n int result = countYokohamaTraces();\n cout << result << endl;\n\n return 0;\n}",
"memory": 3,
"memoryDistribution": "[[3, 0, \"#include <iostream>\\n#include <vector>\\n#include <string>\\n\\nusing namespace std;\\n\\nint n, m;\\nvector<string> grid;\\nstring target = \\\"YOKOHAMA\\\";\\nint target_len = 8;\\nint directions[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\\n\\nbool isValid(int x, int y) {\\n return x >= 0 && x < n && y >= 0 && y < m;\\n}\\n\\nint dfs(int x, int y, int index) {\\n if (index == target_len - 1) return 1;\\n\\n int count = 0;\\n for (int i = 0; i < 4; ++i) {\\n int nx = x + directions[i][0];\\n int ny = y + directions[i][1];\\n if (isValid(nx, ny) && grid[nx][ny] == target[index + 1]) {\\n count += dfs(nx, ny, index + 1);\\n }\\n }\\n return count;\\n}\\n\\nint countYokohamaTraces() {\\n int count = 0;\\n for (int i = 0; i < n; ++i) {\\n for (int j = 0; j < m; ++j) {\\n if (grid[i][j] == 'Y') {\\n count += dfs(i, j, 0);\\n }\\n }\\n }\\n return count;\\n}\\n\\nint main() {\\n cin >> n >> m;\\n grid.resize(n);\\n for (int i = 0; i < n; ++i) {\\n cin >> grid[i];\\n }\\n\\n int result = countYokohamaTraces();\\n cout << result << endl;\\n\\n return 0;\\n}\"]]",
"runtime": 0,
"runtimeDistribution": "[[0, 0, \"#include <iostream>\\n#include <vector>\\n#include <string>\\n\\nusing namespace std;\\n\\nint n, m;\\nvector<string> grid;\\nstring target = \\\"YOKOHAMA\\\";\\nint target_len = 8;\\nint directions[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\\n\\nbool isValid(int x, int y) {\\n return x >= 0 && x < n && y >= 0 && y < m;\\n}\\n\\nint dfs(int x, int y, int index) {\\n if (index == target_len - 1) return 1;\\n\\n int count = 0;\\n for (int i = 0; i < 4; ++i) {\\n int nx = x + directions[i][0];\\n int ny = y + directions[i][1];\\n if (isValid(nx, ny) && grid[nx][ny] == target[index + 1]) {\\n count += dfs(nx, ny, index + 1);\\n }\\n }\\n return count;\\n}\\n\\nint countYokohamaTraces() {\\n int count = 0;\\n for (int i = 0; i < n; ++i) {\\n for (int j = 0; j < m; ++j) {\\n if (grid[i][j] == 'Y') {\\n count += dfs(i, j, 0);\\n }\\n }\\n }\\n return count;\\n}\\n\\nint main() {\\n cin >> n >> m;\\n grid.resize(n);\\n for (int i = 0; i < n; ++i) {\\n cin >> grid[i];\\n }\\n\\n int result = countYokohamaTraces();\\n cout << result << endl;\\n\\n return 0;\\n}\"]]"
},
"golang": {
"code": "package main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n)\n\nfunc main() {\n\tscanner := bufio.NewScanner(os.Stdin)\n\tscanner.Scan()\n\tvar n, m int\n\tfmt.Sscanf(scanner.Text(), \"%d %d\", &n, &m)\n\n\tgrid := make([]string, n)\n\tfor i := 0; i < n; i++ {\n\t\tscanner.Scan()\n\t\tgrid[i] = scanner.Text()\n\t}\n\n\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\n\n\tvar dfs func(i, j, k int) int\n\tdfs = func(i, j, k int) int {\n\t\tif k == 7 {\n\t\t\treturn 1\n\t\t}\n\t\tres := 0\n\t\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\n\t\tfor _, dir := range directions {\n\t\t\tni, nj := i+dir[0], j+dir[1]\n\t\t\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\n\t\t\t\tif grid[ni][nj] == sequence[k+1] {\n\t\t\t\t\tres += dfs(ni, nj, k+1)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res\n\t}\n\n\tans := 0\n\tfor i := 0; i < n; i++ {\n\t\tfor j := 0; j < m; j++ {\n\t\t\tif grid[i][j] == sequence[0] {\n\t\t\t\tans += dfs(i, j, 0)\n\t\t\t}\n\t\t}\n\t}\n\tfmt.Println(ans)\n}",
"memory": 8,
"memoryDistribution": "[[8, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [8, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [8, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [8, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [8, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"]]",
"runtime": 0,
"runtimeDistribution": "[[0, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [0, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [0, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [0, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"], [0, 0, \"package main\\n\\nimport (\\n\\t\\\"bufio\\\"\\n\\t\\\"fmt\\\"\\n\\t\\\"os\\\"\\n)\\n\\nfunc main() {\\n\\tscanner := bufio.NewScanner(os.Stdin)\\n\\tscanner.Scan()\\n\\tvar n, m int\\n\\tfmt.Sscanf(scanner.Text(), \\\"%d %d\\\", &n, &m)\\n\\n\\tgrid := make([]string, n)\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tscanner.Scan()\\n\\t\\tgrid[i] = scanner.Text()\\n\\t}\\n\\n\\tsequence := []byte{'Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'}\\n\\n\\tvar dfs func(i, j, k int) int\\n\\tdfs = func(i, j, k int) int {\\n\\t\\tif k == 7 {\\n\\t\\t\\treturn 1\\n\\t\\t}\\n\\t\\tres := 0\\n\\t\\tdirections := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}\\n\\t\\tfor _, dir := range directions {\\n\\t\\t\\tni, nj := i+dir[0], j+dir[1]\\n\\t\\t\\tif ni >= 0 && ni < n && nj >= 0 && nj < m {\\n\\t\\t\\t\\tif grid[ni][nj] == sequence[k+1] {\\n\\t\\t\\t\\t\\tres += dfs(ni, nj, k+1)\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\treturn res\\n\\t}\\n\\n\\tans := 0\\n\\tfor i := 0; i < n; i++ {\\n\\t\\tfor j := 0; j < m; j++ {\\n\\t\\t\\tif grid[i][j] == sequence[0] {\\n\\t\\t\\t\\tans += dfs(i, j, 0)\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\tfmt.Println(ans)\\n}\"]]"
},
"java": {
"code": "import java.util.*;\n\npublic class Main {\n static int n, m;\n static char[][] grid;\n static final String sequence = \"YOKOHAMA\";\n static int[] dx = {-1, 1, 0, 0};\n static int[] dy = {0, 0, -1, 1};\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n n = scanner.nextInt();\n m = scanner.nextInt();\n scanner.nextLine(); // consume the rest of the line\n grid = new char[n][m];\n for (int i = 0; i < n; i++) {\n String line = scanner.nextLine();\n for (int j = 0; j < m; j++) {\n grid[i][j] = line.charAt(j);\n }\n }\n\n int total = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (grid[i][j] == 'Y') {\n total += dfs(i, j, 0);\n }\n }\n }\n System.out.println(total);\n }\n\n private static int dfs(int i, int j, int k) {\n if (k == 7) {\n return 1;\n }\n int res = 0;\n for (int dir = 0; dir < 4; dir++) {\n int ni = i + dx[dir];\n int nj = j + dy[dir];\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\n res += dfs(ni, nj, k + 1);\n }\n }\n }\n return res;\n }\n}",
"memory": 8,
"memoryDistribution": "[[8, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"], [8, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"], [8, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"], [8, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"]]",
"runtime": 0,
"runtimeDistribution": "[[0, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"], [0, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"], [0, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"], [0, 0, \"import java.util.*;\\n\\npublic class Main {\\n static int n, m;\\n static char[][] grid;\\n static final String sequence = \\\"YOKOHAMA\\\";\\n static int[] dx = {-1, 1, 0, 0};\\n static int[] dy = {0, 0, -1, 1};\\n\\n public static void main(String[] args) {\\n Scanner scanner = new Scanner(System.in);\\n n = scanner.nextInt();\\n m = scanner.nextInt();\\n scanner.nextLine(); // consume the rest of the line\\n grid = new char[n][m];\\n for (int i = 0; i < n; i++) {\\n String line = scanner.nextLine();\\n for (int j = 0; j < m; j++) {\\n grid[i][j] = line.charAt(j);\\n }\\n }\\n\\n int total = 0;\\n for (int i = 0; i < n; i++) {\\n for (int j = 0; j < m; j++) {\\n if (grid[i][j] == 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n System.out.println(total);\\n }\\n\\n private static int dfs(int i, int j, int k) {\\n if (k == 7) {\\n return 1;\\n }\\n int res = 0;\\n for (int dir = 0; dir < 4; dir++) {\\n int ni = i + dx[dir];\\n int nj = j + dy[dir];\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] == sequence.charAt(k + 1)) {\\n res += dfs(ni, nj, k + 1);\\n }\\n }\\n }\\n return res;\\n }\\n}\"]]"
},
"javascript": {
"code": "const readline = require('readline');\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout\n});\n\nlet n, m;\nlet grid = [];\nlet linesRead = 0;\n\nrl.on('line', (line) => {\n if (linesRead === 0) {\n [n, m] = line.trim().split(' ').map(Number);\n linesRead++;\n } else {\n grid.push(line.trim());\n if (grid.length === n) {\n rl.close();\n }\n }\n}).on('close', () => {\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\n \n function dfs(i, j, step) {\n if (step === 7) {\n return 1;\n }\n let count = 0;\n for (const [di, dj] of directions) {\n const ni = i + di;\n const nj = j + dj;\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\n if (grid[ni][nj] === sequence[step + 1]) {\n count += dfs(ni, nj, step + 1);\n }\n }\n }\n return count;\n }\n \n let total = 0;\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < m; j++) {\n if (grid[i][j] === 'Y') {\n total += dfs(i, j, 0);\n }\n }\n }\n \n console.log(total);\n process.exit(0);\n});",
"memory": 8,
"memoryDistribution": "[[8, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [8, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [8, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [8, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [8, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"]]",
"runtime": 0,
"runtimeDistribution": "[[0, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [0, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [0, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [0, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"], [0, 0, \"const readline = require('readline');\\n\\nconst rl = readline.createInterface({\\n input: process.stdin,\\n output: process.stdout\\n});\\n\\nlet n, m;\\nlet grid = [];\\nlet linesRead = 0;\\n\\nrl.on('line', (line) => {\\n if (linesRead === 0) {\\n [n, m] = line.trim().split(' ').map(Number);\\n linesRead++;\\n } else {\\n grid.push(line.trim());\\n if (grid.length === n) {\\n rl.close();\\n }\\n }\\n}).on('close', () => {\\n const directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];\\n const sequence = ['Y', 'O', 'K', 'O', 'H', 'A', 'M', 'A'];\\n \\n function dfs(i, j, step) {\\n if (step === 7) {\\n return 1;\\n }\\n let count = 0;\\n for (const [di, dj] of directions) {\\n const ni = i + di;\\n const nj = j + dj;\\n if (ni >= 0 && ni < n && nj >= 0 && nj < m) {\\n if (grid[ni][nj] === sequence[step + 1]) {\\n count += dfs(ni, nj, step + 1);\\n }\\n }\\n }\\n return count;\\n }\\n \\n let total = 0;\\n for (let i = 0; i < n; i++) {\\n for (let j = 0; j < m; j++) {\\n if (grid[i][j] === 'Y') {\\n total += dfs(i, j, 0);\\n }\\n }\\n }\\n \\n console.log(total);\\n process.exit(0);\\n});\"]]"
},
"python3": {
"code": "# ICPC_1444\nn, m = map(int, input().split())\nx = [input() for _ in range(n)]\n\ndef dfs(i, j, k=0):\n if k==7:\n return 1\n res = 0\n for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):\n if not (0<=i+di<n and 0<=j+dj<m):\n continue\n if x[i+di][j+dj]!=\"YOKOHAMA\"[k+1]:\n continue\n res += dfs(i+di, j+dj, k+1)\n return res\n\nans = 0\nfor i in range(n):\n for j in range(m):\n if x[i][j]==\"Y\":\n ans += dfs(i, j)\nprint(ans)",
"memory": 8,
"memoryDistribution": "[[8, 0, \"# ICPC_1444\\nn, m = map(int, input().split())\\nx = [input() for _ in range(n)]\\n\\ndef dfs(i, j, k=0):\\n if k==7:\\n return 1\\n res = 0\\n for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):\\n if not (0<=i+di<n and 0<=j+dj<m):\\n continue\\n if x[i+di][j+dj]!=\\\"YOKOHAMA\\\"[k+1]:\\n continue\\n res += dfs(i+di, j+dj, k+1)\\n return res\\n\\nans = 0\\nfor i in range(n):\\n for j in range(m):\\n if x[i][j]==\\\"Y\\\":\\n ans += dfs(i, j)\\nprint(ans)\"]]",
"runtime": 0,
"runtimeDistribution": "[[0, 0, \"# ICPC_1444\\nn, m = map(int, input().split())\\nx = [input() for _ in range(n)]\\n\\ndef dfs(i, j, k=0):\\n if k==7:\\n return 1\\n res = 0\\n for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):\\n if not (0<=i+di<n and 0<=j+dj<m):\\n continue\\n if x[i+di][j+dj]!=\\\"YOKOHAMA\\\"[k+1]:\\n continue\\n res += dfs(i+di, j+dj, k+1)\\n return res\\n\\nans = 0\\nfor i in range(n):\\n for j in range(m):\\n if x[i][j]==\\\"Y\\\":\\n ans += dfs(i, j)\\nprint(ans)\"]]"
},
"ruby": {
"code": "h, w = gets.chomp.split.map(&:to_i)\nboard = [\"#\" * (w + 2)]\nh.times{board << \"#\" + gets.chomp + \"#\"}\nboard << \"#\" * (w + 2)\n\ntemp = []\n1.upto(h){|i| 1.upto(w){|j| temp << [i, j, 1] if board[i][j] == \"Y\"}}\nyokohama = \"YOKOHAMA\"\nresult = 0\nidx = 0\nwhile idx < temp.length\n i, j, k = temp[idx]\n idx += 1\n if k == 8\n result += 1\n next\n end\n [[i+1, j], [i-1, j], [i, j+1], [i, j-1]].each{|y, x|\n temp << [y, x, k + 1] if board[y][x] == yokohama[k]\n }\nend\nputs result",
"memory": 8,
"memoryDistribution": "[[8, 0, \"h, w = gets.chomp.split.map(&:to_i)\\nboard = [\\\"#\\\" * (w + 2)]\\nh.times{board << \\\"#\\\" + gets.chomp + \\\"#\\\"}\\nboard << \\\"#\\\" * (w + 2)\\n\\ntemp = []\\n1.upto(h){|i| 1.upto(w){|j| temp << [i, j, 1] if board[i][j] == \\\"Y\\\"}}\\nyokohama = \\\"YOKOHAMA\\\"\\nresult = 0\\nidx = 0\\nwhile idx < temp.length\\n i, j, k = temp[idx]\\n idx += 1\\n if k == 8\\n result += 1\\n next\\n end\\n [[i+1, j], [i-1, j], [i, j+1], [i, j-1]].each{|y, x|\\n temp << [y, x, k + 1] if board[y][x] == yokohama[k]\\n }\\nend\\nputs result\"]]",
"runtime": 40,
"runtimeDistribution": "[[40, 0, \"h, w = gets.chomp.split.map(&:to_i)\\nboard = [\\\"#\\\" * (w + 2)]\\nh.times{board << \\\"#\\\" + gets.chomp + \\\"#\\\"}\\nboard << \\\"#\\\" * (w + 2)\\n\\ntemp = []\\n1.upto(h){|i| 1.upto(w){|j| temp << [i, j, 1] if board[i][j] == \\\"Y\\\"}}\\nyokohama = \\\"YOKOHAMA\\\"\\nresult = 0\\nidx = 0\\nwhile idx < temp.length\\n i, j, k = temp[idx]\\n idx += 1\\n if k == 8\\n result += 1\\n next\\n end\\n [[i+1, j], [i-1, j], [i, j+1], [i, j-1]].each{|y, x|\\n temp << [y, x, k + 1] if board[y][x] == yokohama[k]\\n }\\nend\\nputs result\"]]"
}
}
|
def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:
import random
# collections is not strictly needed for the current DFS implementation
# import collections
random.seed(seed)
# --- Solver (adapted from problem description) ---
# Memoization cache for the DFS. Must be reset for each call to solve_yokohama.
_solver_memo_cache = {}
def _dfs_solver(r: int, c: int, k: int, n_val: int, m_val: int, grid_val: list[str], target_seq: str) -> int:
state = (r, c, k)
if state in _solver_memo_cache:
return _solver_memo_cache[state]
# Base case: successfully found the entire "YOKOHAMA" sequence.
# k is the index of the character just placed.
# target_seq has length 8 (indices 0-7).
# If k == 7, it means the 8th character (target_seq[7]) has been placed.
if k == len(target_seq) - 1:
return 1
count = 0
# Moves: up, down, left, right
# (dr, dc) pairs for (-1,0), (1,0), (0,-1), (0,1)
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]
for i in range(4): # Iterate over 4 possible directions
nr, nc = r + dr[i], c + dc[i]
if 0 <= nr < n_val and 0 <= nc < m_val:
# Check if the character in the next square matches the next character in the target sequence
if grid_val[nr][nc] == target_seq[k+1]:
count += _dfs_solver(nr, nc, k + 1, n_val, m_val, grid_val, target_seq)
_solver_memo_cache[state] = count
return count
def solve_yokohama(n_val: int, m_val: int, grid_val: list[str]) -> int:
_solver_memo_cache.clear() # Reset memoization for each new grid processing
target_sequence = "YOKOHAMA" # The sequence to find
total_traces = 0
# Validate inputs based on problem constraints (optional here, assuming valid inputs from generator)
# if not (1 <= n_val <= 10 and 1 <= m_val <= 10): return 0
# if not grid_val or len(grid_val) != n_val or not all(len(row) == m_val for row in grid_val): return 0
for r_start in range(n_val):
for c_start in range(m_val):
# Start DFS if the current square matches the first character of the sequence ('Y')
if grid_val[r_start][c_start] == target_sequence[0]:
# k=0 means we are at the first char 'Y' (index 0 of target_sequence)
total_traces += _dfs_solver(r_start, c_start, 0, n_val, m_val, grid_val, target_sequence)
return total_traces
# --- Serialization helpers ---
def serialize_input(n_val: int, m_val: int, grid_val: list[str]) -> str:
input_lines = [f"{n_val} {m_val}"]
input_lines.extend(grid_val) # grid_val is list of strings, each representing a row
return "\n".join(input_lines)
def serialize_output(count: int) -> str:
return str(count)
test_cases = []
seen_inputs = set() # To ensure unique test cases by input string
letters_pool = "AHKMOY" # Allowed characters in the grid
# Define a list of generator functions for specific categories of test cases
# Each generator yields (n, m, grid_list_of_strings) tuples
case_generators = []
# Generator 1: Sample Inputs from problem description
def gen_sample_cases():
yield (2, 4, ["YOHA", "OKAM"])
yield (3, 4, ["YOKH", "OKHA", "KHAM"])
yield (3, 6, ["MAYOHA", "AHOKAM", "MAYOHA"])
case_generators.append(gen_sample_cases)
# Generator 2: Boundary dimensions and simple content
def gen_boundary_dim_cases():
# 1x1 grids
for char_code in letters_pool:
yield 1, 1, [char_code]
# Max dimensions (10x10)
yield 10, 10, ["".join(random.choices(letters_pool, k=10)) for _ in range(10)] # Random content
yield 10, 10, ['Y'*10 for _ in range(10)] # All 'Y's
yield 10, 10, ['A'*10 for _ in range(10)] # All 'A's (no 'Y', so 0 traces)
# Min one dimension, Max other (e.g., 1x10, 10x1)
yield 1, 10, ["".join(random.choices(letters_pool, k=10))]
# For Nx1 grid: list of N single-char strings. e.g. for 10x1, 10 strings of length 1.
yield 10, 1, [random.choice(letters_pool) for _ in range(10)]
# Grids that exactly spell "YOKOHAMA" or parts of it
yield 1, 8, ["YOKOHAMA"] # Expected: 1 trace
yield 8, 1, list("YOKOHAMA") # list("S") -> ['S'], so this is correct for Nx1
yield 1, 7, ["YOKOHAM"] # Incomplete, expected: 0 traces
yield 1, 9, ["YOKOHAMAA"] # Valid path + extra char, expected: 1 trace
case_generators.append(gen_boundary_dim_cases)
# Generator 3: Specific patterns and edge cases
def gen_pattern_cases():
# All same character for various small/medium sizes
for char_code in letters_pool:
n, m = random.randint(3,6), random.randint(3,6)
yield n, m, [char_code * m for _ in range(n)]
# Grid with no 'Y' characters
n, m = random.randint(4,7), random.randint(4,7)
yield n, m, ["".join(random.choices("OKAHM", k=m)) for _ in range(n)]
# Grid with only 'Y' and 'O' characters
n, m = random.randint(3,5), random.randint(3,5)
yield n, m, ["".join(random.choices("YO", k=m)) for _ in range(n)]
# A manually crafted grid with a known path structure
# Path: Y(0,0) O(0,1) K(1,1) O(2,1) H(3,1) A(3,2) M(2,2) A(1,2)
yield 4, 3, ["YOA", "AKA", "AOM", "AHA"]
# Grid designed to test revisiting a square (O-K-O part)
# Path: Y(0,0) O(0,1) K(1,0) O(0,1) H(2,0) A(2,1) M(2,2) A(3,3)
yield 4, 4, ["YOAA", "KOAA", "HAMA", "AAAA"] # 'A's are fillers
case_generators.append(gen_pattern_cases)
# Process predefined cases from generators
for generator_func in case_generators:
if len(test_cases) >= num_cases:
break
for n_val, m_val, grid_val_list in generator_func():
if len(test_cases) >= num_cases:
break
s_input = serialize_input(n_val, m_val, grid_val_list)
if s_input not in seen_inputs:
s_output = serialize_output(solve_yokohama(n_val, m_val, grid_val_list))
test_cases.append({"input": s_input, "output": s_output})
seen_inputs.add(s_input)
# Fill remaining test case slots with randomly generated grids
while len(test_cases) < num_cases:
n_val = random.randint(1, 10)
m_val = random.randint(1, 10)
current_grid_val = []
# Strategy for random grid content
grid_content_roll = random.random()
if grid_content_roll < 0.7: # 70% chance: Purely random characters
current_grid_val = ["".join(random.choices(letters_pool, k=m_val)) for _ in range(n_val)]
elif grid_content_roll < 0.9: # 20% chance: 'Y'-heavy grid
rows = []
for _ in range(n_val):
row_chars = []
for _ in range(m_val):
if random.random() < 0.35: # 35% chance for a 'Y'
row_chars.append('Y')
else:
row_chars.append(random.choice("OKAHM")) # Other non-'Y' critical path letters
rows.append("".join(row_chars))
current_grid_val = rows
else: # 10% chance: Grid filled with a single character
char_to_fill = random.choice(letters_pool)
current_grid_val = [char_to_fill * m_val for _ in range(n_val)]
s_input = serialize_input(n_val, m_val, current_grid_val)
if s_input not in seen_inputs:
s_output = serialize_output(solve_yokohama(n_val, m_val, current_grid_val))
test_cases.append({"input": s_input, "output": s_output})
seen_inputs.add(s_input)
return test_cases[:num_cases] # Ensure exactly num_cases are returned
|
def evaluate(expected_output: str, program_output: str) -> bool:
import math # Required by instructions, though not used for this integer-only problem.
# Kept for adherence, can be removed if strictly not needed.
# --- Deserialization logic (must be independent) ---
# This problem's output is a single integer.
def deserialize_single_integer(s: str) -> int:
# Handle potential surrounding whitespace from program output
cleaned_s = s.strip()
if not cleaned_s: # Empty string after strip
raise ValueError("Output string is empty or only whitespace.")
try:
return int(cleaned_s)
except ValueError as e:
# Re-raise with a more specific message if needed, or just let it propagate
raise ValueError(f"Cannot parse '{cleaned_s}' as an integer: {e}")
try:
expected_val = deserialize_single_integer(expected_output)
# Program output might have extra newlines, etc. strip() handles this.
actual_val = deserialize_single_integer(program_output)
except ValueError:
# If deserialization fails for either string, it's a mismatch.
return False
# Direct comparison for integer values.
# The problem does not involve floating point numbers, so math.isclose is not needed here.
# If it did, the comparison would be: math.isclose(expected_val, actual_val, rel_tol=..., abs_tol=...)
return expected_val == actual_val
|
[{"input": "2 4\nYOHA\nOKAM", "output": "8"}, {"input": "3 4\nYOKH\nOKHA\nKHAM", "output": "0"}, {"input": "3 6\nMAYOHA\nAHOKAM\nMAYOHA", "output": "80"}, {"input": "1 1\nA", "output": "0"}, {"input": "1 1\nH", "output": "0"}, {"input": "1 1\nK", "output": "0"}, {"input": "1 1\nM", "output": "0"}, {"input": "1 1\nO", "output": "0"}, {"input": "1 1\nY", "output": "0"}, {"input": "10 10\nMAHHOOYAKA\nHMAHMMHMOA\nOOKAYKAAYM\nOOMYKMOMYM\nOAHHAHAHMK\nKHHYMMHOAK\nYMMOYOHAHH\nHYYHMKYKHH\nMHMYKHYMAA\nAMOKAKYMYY", "output": "0"}, {"input": "10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY", "output": "0"}, {"input": "10 10\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA\nAAAAAAAAAA", "output": "0"}, {"input": "1 10\nAOOMHMAKKY", "output": "0"}, {"input": "10 1\nY\nK\nO\nH\nO\nA\nY\nK\nY\nO", "output": "0"}, {"input": "1 8\nYOKOHAMA", "output": "2"}, {"input": "8 1\nY\nO\nK\nO\nH\nA\nM\nA", "output": "2"}, {"input": "1 7\nYOKOHAM", "output": "1"}, {"input": "1 9\nYOKOHAMAA", "output": "2"}, {"input": "4 4\nAAAA\nAAAA\nAAAA\nAAAA", "output": "0"}, {"input": "5 4\nHHHH\nHHHH\nHHHH\nHHHH\nHHHH", "output": "0"}, {"input": "3 5\nKKKKK\nKKKKK\nKKKKK", "output": "0"}, {"input": "6 3\nMMM\nMMM\nMMM\nMMM\nMMM\nMMM", "output": "0"}, {"input": "3 5\nOOOOO\nOOOOO\nOOOOO", "output": "0"}, {"input": "5 4\nYYYY\nYYYY\nYYYY\nYYYY\nYYYY", "output": "0"}, {"input": "4 5\nMMOAO\nHHOAA\nKMAKA\nHKKMH", "output": "0"}, {"input": "4 5\nYYYYO\nOYOYY\nYYOYY\nOOOOY", "output": "0"}, {"input": "4 3\nYOA\nAKA\nAOM\nAHA", "output": "2"}, {"input": "4 4\nYOAA\nKOAA\nHAMA\nAAAA", "output": "0"}, {"input": "8 7\nAKKKOOY\nAKKYHHK\nKHHYKYM\nAYYYYYA\nKHKAKYH\nOKKYYMO\nAHYMMOA\nMMYAYAH", "output": "0"}, {"input": "10 2\nHA\nYH\nMM\nKM\nMY\nHO\nHK\nOH\nHO\nAK", "output": "0"}, {"input": "10 2\nHH\nYY\nYK\nAY\nOM\nYM\nAO\nHM\nYA\nAA", "output": "0"}, {"input": "9 3\nMOH\nMHK\nYYA\nKHA\nOMH\nOMK\nAAY\nYMY\nMAA", "output": "0"}, {"input": "5 6\nOKOMHK\nKKOYHK\nYOOKYA\nYKYHYA\nMMYYAY", "output": "0"}, {"input": "5 1\nK\nO\nH\nM\nM", "output": "0"}, {"input": "7 10\nAKMOOYOHKY\nYMMAYMOHOM\nHMKOHMKYHH\nOMHKOMOYOM\nHMMAYHHOAA\nYMOKYMOKKA\nOYYYOHOOKM", "output": "0"}, {"input": "2 8\nKMMHOKOY\nKYKAYKOY", "output": "0"}, {"input": "5 9\nHKOHKYAAK\nAHKHKAOKO\nYAYMKYHKY\nYMOOYKHKK\nOOOYYYMYM", "output": "0"}, {"input": "1 2\nAK", "output": "0"}, {"input": "1 5\nHHOKO", "output": "0"}, {"input": "7 5\nMYKOK\nYYYYM\nHAYOK\nOAHKY\nKYMMA\nAYOHY\nHHYAM", "output": "0"}, {"input": "8 8\nOHYOAYHK\nMKAYHHOK\nYOHAYAOK\nOOMKOAHO\nHMKMKOHO\nHHAHAMOH\nHKOYMHAH\nHHAMHYMO", "output": "0"}, {"input": "3 8\nAHKKYHYA\nAKMOAOYA\nHMKMMOKY", "output": "0"}, {"input": "5 10\nKKKKKKKKKK\nKKKKKKKKKK\nKKKKKKKKKK\nKKKKKKKKKK\nKKKKKKKKKK", "output": "0"}, {"input": "10 10\nYAOMHAHMAK\nOKAHHYAHHO\nMOHAHAHAAO\nMOYKKHKHMK\nMYOMAHOYMA\nOOMOHMKHYK\nOYKKHAAKKM\nKOAAHAOYOA\nYKAMMKKAHA\nHYKAMOOHAK", "output": "2"}, {"input": "4 2\nAO\nKO\nMH\nYY", "output": "0"}, {"input": "4 8\nKYMYYHOK\nYMOHHMYK\nAMKMMKHH\nOMHOAOOO", "output": "0"}, {"input": "7 3\nAMM\nYYK\nMKO\nKMA\nKYK\nOMY\nYYK", "output": "0"}, {"input": "6 8\nYYAOOOAO\nYYHYMKYY\nMHKYHYYA\nKYMYAAYH\nYAAYHYOH\nAKAYYYKO", "output": "0"}, {"input": "5 8\nKAYHKHOY\nKMHAYYYH\nYOKAOHOO\nKYMAKHAK\nOHKMKOKM", "output": "0"}, {"input": "9 6\nHHHHHH\nHHHHHH\nHHHHHH\nHHHHHH\nHHHHHH\nHHHHHH\nHHHHHH\nHHHHHH\nHHHHHH", "output": "0"}, {"input": "2 8\nKKKKKKKK\nKKKKKKKK", "output": "0"}, {"input": "7 2\nYH\nKA\nYA\nKO\nOY\nKO\nAK", "output": "0"}, {"input": "2 8\nYHOHKHKY\nKYMAHYYO", "output": "0"}, {"input": "2 4\nMAOH\nAMAO", "output": "0"}, {"input": "4 10\nYHAYAYAAHH\nMAAOHHHAOM\nOKOMAMYAOY\nMKYAKKOKYA", "output": "0"}, {"input": "2 6\nAHMMHY\nMKMAOY", "output": "0"}, {"input": "9 4\nYKOK\nOHHH\nYOKA\nAKOK\nAAYM\nOKYY\nKYAH\nHAMA\nKYKM", "output": "0"}, {"input": "2 5\nOYYOM\nMAYOH", "output": "0"}, {"input": "3 5\nYYYMO\nYOYHA\nYYYMY", "output": "0"}, {"input": "1 3\nMOH", "output": "0"}, {"input": "7 8\nKHMKAOMM\nHHYAHYOO\nHAKKAMHM\nOKKOKKAH\nKKMHKYHY\nKOKKAKKA\nYOHOAMMH", "output": "0"}, {"input": "6 6\nKYYYOY\nHMHMMY\nAYYAMY\nAOYOOM\nMOMAMY\nYYAOKY", "output": "0"}, {"input": "8 8\nMKYKOOAM\nKHMKHYYM\nAAMYHMMA\nOAMMHAOY\nYYAOMAHY\nKOHYAHOM\nMOMMYMMA\nHOMYOAKO", "output": "2"}, {"input": "8 10\nOKMHOKYKYY\nKHKMYOOAHM\nYMAYYHOHYA\nKYHKKAAMHY\nKAYYMOAHOO\nAOKAAHYMOM\nAHHAKOKAYM\nAMHAKMHKMA", "output": "0"}, {"input": "6 2\nOO\nOO\nOO\nOO\nOO\nOO", "output": "0"}, {"input": "9 9\nKKMYHAOKO\nMOOHAMOHO\nKOMOAOKHA\nHAYMYMHOH\nKOYHAKYOY\nKYKKYMOOA\nMOMHAMHMK\nOKAYKYHYY\nAMKOOYAMO", "output": "0"}, {"input": "1 3\nOKK", "output": "0"}, {"input": "10 1\nO\nY\nK\nO\nM\nM\nK\nM\nH\nA", "output": "0"}, {"input": "3 8\nYAOOHMOY\nHAAHOYOY\nYOOMHHAO", "output": "0"}, {"input": "3 6\nAHAOAM\nKOMMAH\nYOMOOA", "output": "0"}, {"input": "6 2\nOK\nYO\nMH\nYK\nYA\nAA", "output": "0"}, {"input": "3 3\nOKY\nYYH\nMMA", "output": "0"}, {"input": "5 10\nMHYAMOMYMO\nAAMMMOKMKM\nHYKOOHAAKK\nHMHOOYYAKM\nHKHHAHKMHY", "output": "0"}, {"input": "3 6\nYYYYYY\nYYYYYY\nYYYYYY", "output": "0"}, {"input": "6 4\nMAOM\nKYOY\nHYYY\nYYHH\nYAOH\nAMOY", "output": "0"}, {"input": "2 7\nYMKAMKA\nAOOMAYA", "output": "0"}, {"input": "10 6\nYOHKOM\nOHOKOY\nMOOOAK\nYOOMOM\nHMMYAO\nAYAAHA\nOKOYYO\nAAHHMM\nHHYKKO\nOMOMHH", "output": "0"}, {"input": "9 5\nYHHHO\nHKYOH\nAOKYO\nYOHHO\nKKHKH\nMYOAM\nMHOMM\nAKOAO\nAMYKY", "output": "0"}, {"input": "8 8\nOHHAOMHO\nYAYKYYAY\nOHOYHAHM\nYKKMMYAM\nHOHOMOAK\nHOHMMKKH\nKAYKYAKK\nHHMMHKHO", "output": "0"}, {"input": "8 5\nOYYOO\nMYKHY\nKKYKO\nYOOOO\nOMOMM\nKYAOY\nHMAYK\nOOKYK", "output": "0"}, {"input": "1 8\nKMMOHAHA", "output": "0"}, {"input": "4 10\nKOMAYYKHHA\nMOYKYKYKAY\nYAYAYKAYYO\nYKOKKHKAHY", "output": "0"}, {"input": "2 1\nO\nY", "output": "0"}, {"input": "2 2\nKO\nYH", "output": "0"}, {"input": "1 7\nMOOAYHY", "output": "0"}, {"input": "10 6\nOOHYYM\nKHMMOH\nOMAKMK\nMOKHHM\nHHYAKA\nKKMKHH\nAKKMOA\nKMAAOM\nOHHYHY\nHHOOOY", "output": "0"}, {"input": "10 4\nHHHK\nMHKY\nKOOO\nHHHA\nYOAM\nMOHH\nHMHM\nYKOK\nOOKO\nKAMH", "output": "0"}, {"input": "9 1\nY\nA\nO\nA\nA\nA\nM\nA\nA", "output": "0"}, {"input": "4 9\nAMYYMAMKA\nOMHMOKYHY\nMHMHKOAYK\nHOHOAYMAK", "output": "0"}, {"input": "7 9\nMOAYMHYYY\nYHYOMHYOH\nMMHYAHAOO\nYHMMYOMKO\nOOAOKAHAM\nMMYHMOKHM\nKHMKOHHAH", "output": "0"}, {"input": "7 3\nYYY\nYAY\nYMH\nYYM\nAOY\nOMK\nKKY", "output": "0"}, {"input": "5 5\nAKKKA\nHHMMH\nAHYHM\nOHKOY\nYAHYH", "output": "0"}, {"input": "6 3\nKKK\nKKK\nKKK\nKKK\nKKK\nKKK", "output": "0"}, {"input": "5 8\nHHHHHHHH\nHHHHHHHH\nHHHHHHHH\nHHHHHHHH\nHHHHHHHH", "output": "0"}, {"input": "6 7\nOKYHYHO\nAOYHOOA\nYOOAHHA\nKKKMMMY\nYKAYOOM\nYAHMAMM", "output": "0"}, {"input": "7 6\nMMMMMM\nMMMMMM\nMMMMMM\nMMMMMM\nMMMMMM\nMMMMMM\nMMMMMM", "output": "0"}, {"input": "2 1\nH\nO", "output": "0"}, {"input": "9 10\nHKKOOAYKHY\nAOOKKOMKAO\nKAAOAKAOYO\nMMHKKOMHMK\nOYKKAHHOOM\nOMKHAOKYHK\nKAKKHOOYMO\nHHAKAKMMKK\nMYYHHHHYMY", "output": "0"}, {"input": "1 8\nOYMKOKYK", "output": "0"}, {"input": "2 10\nOHHMHKOOMA\nAOOKOAOMYA", "output": "0"}]
| null |
|
1447
|
Nested Repetition Compression
|
nested-repetition-compression
| "Nested Repetition Compression\n\nYou have a number of strings of lowercase letters to be sent in e-(...TRUNCATED)
| "Nested Repetition Compression\n\nYou have a number of strings of lowercase letters to be sent in e-(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1447?year=2023
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n#if __has_include(<atcoder/all>)\n#i(...TRUNCATED)
| "def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n import random\n from(...TRUNCATED)
| "def evaluate(expected_output: str, program_output: str) -> bool:\n # No external library imports(...TRUNCATED)
| "[{\"input\": \"abababaaaaa\", \"output\": \"3(ab)5(a)\"}, {\"input\": \"abababcaaaaaabababcaaaaa\",(...TRUNCATED)
| null |
|
1448
|
Chayas
|
chayas
| "Chayas\n\nOnce upon a time, there were a number of chayas (teahouses) along one side of an east-wes(...TRUNCATED)
| "Chayas\n\nOnce upon a time, there were a number of chayas (teahouses) along one side of an east-wes(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1448?year=2023
|
io
| null | null | 8,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\nusing vll = ve(...TRUNCATED)
| "def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n import random\n impo(...TRUNCATED)
| "def evaluate(expected_output: str, program_output: str) -> bool:\n \"\"\"\n Determine if a su(...TRUNCATED)
| "[{\"input\": \"5 4\\n1 2 4\\n2 3 5\\n3 2 4\\n1 3 2\\n\", \"output\": \"4\"}, {\"input\": \"4 2\\n3 (...TRUNCATED)
| null |
|
1449
|
Color Inversion on a Huge Chessboard
|
color-inversion-on-a-huge-chessboard
| "Color Inversion on a Huge Chessboard\n\nYou are given a set of square cells arranged in a chessboar(...TRUNCATED)
| "Color Inversion on a Huge Chessboard\n\nYou are given a set of square cells arranged in a chessboar(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1449?year=2023
|
io
| null | null | 4,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"#include <bits/stdc++.h>\n\n// NOLINTBEGIN\n// clang-format off\n// DO NOT REMOVE TH(...TRUNCATED)
| "import random\n\ndef generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n random(...TRUNCATED)
| "import math # Required by template, not used for this problem's integer outputs\n\ndef evaluate(exp(...TRUNCATED)
| "[{\"input\": \"159 3\\nROW 7\\nROW 88\\nCOLUMN 46\\n\", \"output\": \"24963\\n24645\\n24335\\n\"}, (...TRUNCATED)
| null |
|
1455
|
Ribbon on the Christmas Present
|
ribbon-on-the-christmas-present
| "Ribbon on the Christmas Present\n\nYou are preparing a ribbon to decorate the Christmas present box(...TRUNCATED)
| "Ribbon on the Christmas Present\n\nYou are preparing a ribbon to decorate the Christmas present box(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1455?year=2024
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"#include<bits/stdc++.h>\n#define rep(i,j,n) for(ll i=j;i<(ll)(n);i++)\n#define rrep((...TRUNCATED)
| "def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n import random\n impo(...TRUNCATED)
| "def evaluate(expected_output: str, program_output: str) -> bool:\n \n # Helper for deserializ(...TRUNCATED)
| "[{\"input\": \"6\\n50 100 50 50 100 50\", \"output\": \"3\\n\"}, {\"input\": \"5\\n1 2 3 2 1\", \"o(...TRUNCATED)
| null |
|
1456
|
The Sparsest Number in Between
|
the-sparsest-number-in-between
| "The Sparsest Number in Between\n\nYou are given a pair of positive integers $a$ and $b$ ($a \\leq b(...TRUNCATED)
| "The Sparsest Number in Between\n\nYou are given a pair of positive integers $a$ and $b$ ($a \\leq b(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1456?year=2024
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"#include <iostream>\n#include <climits>\n\nusing namespace std;\n\nlong long countOn(...TRUNCATED)
| "import random\n\n# Task 1: Test Case Generator\ndef generate_test_cases(num_cases: int, seed: int =(...TRUNCATED)
| "import math # Not strictly needed for this problem, but good practice for the template\n\n# Task 2:(...TRUNCATED)
| "[{\"input\": \"10 13\", \"output\": \"10\"}, {\"input\": \"11 15\", \"output\": \"12\"}, {\"input\"(...TRUNCATED)
| null |
|
1459
|
E-Circuit Is Now on Sale!
|
e-circuit-is-now-on-sale!
| "E-Circuit Is Now on Sale!\n\nAre you looking for math education tools for your children? Then, why (...TRUNCATED)
| "E-Circuit Is Now on Sale!\n\nAre you looking for math education tools for your children? Then, why (...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1459?year=2024
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"// AOJ #1459\n// E-Circuit Is Now on Sale! 2025.1.14\n\n#include <bits/stdc++.h>\nus(...TRUNCATED)
| "def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n import random\n impo(...TRUNCATED)
| "def evaluate(expected_output: str, program_output: str) -> bool:\n # Deserialization for output:(...TRUNCATED)
| "[{\"input\": \"6 8\\n3.......\\n#....P..\\n#....#.2\\n#.###*#+\\n##-....#\\n..1...4#\", \"output\":(...TRUNCATED)
| null |
|
1460
|
The Farthest Point
|
the-farthest-point
| "The Farthest Point\n\nAnant is on one of the vertices, say the starting vertex, of a rectangular cu(...TRUNCATED)
| "The Farthest Point\n\nAnant is on one of the vertices, say the starting vertex, of a rectangular cu(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1460?year=2024
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n\n\n//----------------------------(...TRUNCATED)
| "def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n import math\n import(...TRUNCATED)
| "def evaluate(expected_output: str, program_output: str) -> bool:\n import math\n\n # Deserial(...TRUNCATED)
| "[{\"input\": \"11 20 10\", \"output\": \"29.09682113221305\"}, {\"input\": \"84 51 41\", \"output\"(...TRUNCATED)
| null |
|
1464
|
Mixing Solutions
|
mixing-solutions
| "Mixing Solutions\n\nLet’s prepare for an experiment with the chemical Yokohama Yellow, or YY in s(...TRUNCATED)
| "Mixing Solutions\n\nLet’s prepare for an experiment with the chemical Yokohama Yellow, or YY in s(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Regional/1464?year=2024
|
io
| null | null | 2,000,000,000
| 2,097,152,000
| null | {"cpp":{"code":"// O(n log n log M): yosupo さんの解法\n#include <bits/stdc++.h>\nusing namespa(...TRUNCATED)
| "def generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n import random\n from(...TRUNCATED)
| "def evaluate(expected_output: str, program_output: str) -> bool:\n from fractions import Fractio(...TRUNCATED)
| "[{\"input\": \"3 10 5000\\n10 2000 3000\\n10 4000 6000\\n10 7000 8000\", \"output\": \"1 2\"}, {\"i(...TRUNCATED)
| null |
|
1664
|
Which Team Should Receive the Sponsor Prize?
|
which-team-should-receive-the-sponsor-prize?
| "Problem A\nWhich Team Should Receive the Sponsor Prize?\n\nIn ICQC (International Collegiate Quiz C(...TRUNCATED)
| "Problem A\nWhich Team Should Receive the Sponsor Prize?\n\nIn ICQC (International Collegiate Quiz C(...TRUNCATED)
|
[] |
aizu
|
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Prelim/1664?year=2023
|
io
| null | null | 8,000,000,000
| 262,144,000
| null | {"cpp":{"code":"#include <stdio.h>\n#include <stdlib.h>\n\n#define SEC 2023\n\nint main()\n{\n int (...TRUNCATED)
| "import random\n\ndef generate_test_cases(num_cases: int, seed: int = 42) -> list[dict]:\n random(...TRUNCATED)
| "import math # math.isclose is not needed for this problem as outputs are integers\n\ndef evaluate(e(...TRUNCATED)
| "[{\"input\": \"5\\n8936 1425 2020 9675 6913\\n6\\n2023 3812 8280 9864 435 9196\\n0\\n\", \"output\"(...TRUNCATED)
| null |
Dataset Card for EffiBench-X
EffiBench-X is the first multi-language benchmark designed specifically to evaluate the efficiency of LLM-generated code across six programming languages: Python, C++, Java, JavaScript, Ruby, and Golang. The dataset comprises 623 competitive programming problems paired with human expert solutions as efficiency baselines.
Dataset Details
Dataset Description
EffiBench-X addresses critical limitations in existing code generation benchmarks by providing:
Multi-language evaluation across Python, C++, Java, JavaScript, Ruby, and Golang
Efficiency-focused metrics including execution time, memory peak, and memory integral
Human expert baselines for reliable efficiency comparison
Curated by: Yuhao Qing, Boyu Zhu, Mingzhe Du, Zhijiang Guo, Terry Yue Zhuo, Qianru Zhang, Jie M. Zhang, Heming Cui, Siu-Ming Yiu, Dong Huang, See-Kiong Ng, Luu Anh Tuan
Institutions: HKU, UCL, NTU, NUS, HKUST, Monash University, CSIRO's Data61, KCL
Language(s) (NLP): English
License: Apache License 2.0
Dataset Sources
- Repository: EffiBench-X (GitHub)
- Dataset: EffiBench/effibench-x
- Paper: arXiv:2505.13004
- Problem Sources:
Uses
Direct Use
- Benchmarking LLM code generation efficiency: Evaluate models on runtime performance, memory usage, and correctness across multiple languages
- Cross-language performance analysis: Compare model capabilities across different programming paradigms
- Model development: Train and fine-tune models for efficient code generation
- Research: Study efficiency gaps between LLM-generated and human expert code
Out-of-Scope Use
- Production deployment without validation: Solutions should be verified before production use
- Security-critical applications: The dataset focuses on algorithmic efficiency, not security
- Non-competitive programming domains: Problems are algorithmic in nature and may not represent all software engineering contexts
Dataset Structure
The dataset contains 623 problems categorized into:
- Functional problems: Implement specific functions/classes with I/O handled by test templates
- Standard I/O problems: Complete programs reading from stdin and writing to stdout
Key fields per record include:
id,title,title_slug,description,description_md,difficulty,tags,source,url,type- Limits:
time_limit_nanos,memory_limit_bytes - Code artifacts:
starter_code: language-keyed starter snippetssolutions: language-keyed canonical solutions (e.g., forcpp,golang,java,javascript,python3,ruby)test_case_generator: executable code string that programmatically produces testsevaluator: executable code string to determine pass/fail given expected vs. program outputgenerated_tests: serialized tests produced by the generatortest_runners: language-keyed runner templates for executing solutions
All problems are from competitive programming platforms.
Dataset Creation
Curation Rationale
Existing code generation benchmarks primarily focus on functional correctness with limited attention to efficiency, often restricted to Python. EffiBench-X addresses three critical limitations:
- Language diversity: Extends beyond Python to include statically-typed (C++, Java, Go) and dynamically-typed languages (Python, JavaScript, Ruby)
- Data contamination: Uses recent problems (post-October 2023) to avoid memorization effects
- Complexity: Features algorithmically challenging problems requiring optimization techniques
Source Data
Data Collection and Processing
Problems are curated from competitive programming platforms. Each problem includes:
- Human expert solutions verified for correctness and efficiency
- 100 programmatically generated test cases
- Test runners and evaluators for automated assessment
- Cross-language validation to ensure consistency
Who are the source data producers?
- Problem creators: Competitive programming platforms and contest organizers
- Solution authors: Human expert programmers from competitive programming communities
- Dataset curators: EffiBench research team
Citation
Please cite our paper if you use this dataset:
@article{qing2025effibench,
title={EffiBench-X: A Multi-Language Benchmark for Measuring Efficiency of LLM-Generated Code},
author={Qing, Yuhao and Zhu, Boyu and Du, Mingzhe and Guo, Zhijiang and Zhuo, Terry Yue and Zhang, Qianru and Zhang, Jie M and Cui, Heming and Yiu, Siu-Ming and Huang, Dong and Ng, See-Kiong and Tuan, Luu Anh},
journal={Advances in neural information processing systems},
year={2025}
}
More Information
- Dataset Statistics: 623 problems, 100 test cases per problem, 6 languages
- Evaluation: Sandboxed execution environment for consistent performance measurements
- For detailed information and benchmark results, please refer to the paper and GitHub repository
Dataset Card Contact
For questions and feedback, please open an issue on our GitHub repository.
- Downloads last month
- 193