F. Find / -type f -or -type d

Codeforces
IDCF10260F
Time1000ms
Memory1024MB
Difficulty
English · Original
Formal · Original
Cuber QQ wants to know the number of files with extension _.eoj_ in his computer. This can be easily done with a command _find / -type f | grep '$backslash$.eoj$' | wc -l_. However, Cuber QQ is a grep-hater, who would rather write his own program than using grep. So he decides to take a detour: what if the command starts with something else? Is it still possible to recover the results? If you are not familiar with command usages in Linux, all you need to know is that _ls_ and _find_ are two easy-to-use commands to inspect files and subdirectories a directory contains. For example, when you are trying to get a list of everything in your computer, you might try to use: _find / -type f -or -type d_, which will give you a list like: To make the problem even more interesting, Cuber QQ adds another _shuf_ after _find_, so that the list is shuffled into a random order and his secrets will stay covered. Cuber QQ is wondering whether it's possible to write a program _cuber-qq-grep_ that filters out all the files with extension _.eoj_ from the given shuffled list, which is his initial intention. Still, instead of giving the filtered list directly, Cuber QQ wants to know the length of this list, i.e., the number of files found. In other words, the following two commands will be almost equivalent: Well, there can be some subtle differences in input/output formats, but that's not essential. One more thing, on your file system, directory is only a logical concept. This means, a directory is created only when there is a file which relies on this directory is created and a directory cannot exist without files. TL;DR, given the randomly shuffled list of all directories and files on a computer, count the number of files that ends with _.eoj_. The input starts with a line of one number $n$ ($1 <= n <= 10^5$), which is the length of the following list. In the following $n$ lines, each line contains one string, which is an absolute path to a file or a directory. The path starts with _/_, and is composed of multiple tokens (file names and directory names) concatenated with _/_. The tokens always start with a lowercase letter, followed by no more than $9$ lowercase letters or dots. The root folder alone will not be included in this list. It is guaranteed that the total length of $n$ lines will be no longer than $10^6$. Output the number of files satisfying the above-mentioned condition, in one line. ## Input The input starts with a line of one number $n$ ($1 <= n <= 10^5$), which is the length of the following list.In the following $n$ lines, each line contains one string, which is an absolute path to a file or a directory. The path starts with _/_, and is composed of multiple tokens (file names and directory names) concatenated with _/_. The tokens always start with a lowercase letter, followed by no more than $9$ lowercase letters or dots. The root folder alone will not be included in this list.It is guaranteed that the total length of $n$ lines will be no longer than $10^6$. ## Output Output the number of files satisfying the above-mentioned condition, in one line. [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the number of paths. Let $ P = (p_1, p_2, \dots, p_n) $ be a sequence of strings, where each $ p_i $ is an absolute file or directory path starting with `/`. **Constraints** 1. $ 1 \le n \le 10^5 $ 2. Each $ p_i $: - Starts with `/` - Composed of tokens separated by `/` - Each token: starts with a lowercase letter, followed by at most 9 lowercase letters or dots 3. Total length of all $ p_i $: $ \le 10^6 $ **Objective** Count the number of paths $ p_i $ that correspond to **files** (not directories) and end with the extension `.eoj`. A path $ p_i $ represents a file if and only if it does **not** end with `/` and its last token contains a `.` and ends with `.eoj`. Compute: $$ \left| \left\{ p_i \in P \mid p_i \text{ ends with } \texttt{.eoj} \right\} \right| $$
API Response (JSON)
{
  "problem": {
    "name": "F. Find / -type f -or -type d",
    "description": {
      "content": "Cuber QQ wants to know the number of files with extension _.eoj_ in his computer. This can be easily done with a command _find / -type f | grep '$backslash$.eoj$' | wc -l_. However, Cuber QQ is a grep",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 1048576
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10260F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Cuber QQ wants to know the number of files with extension _.eoj_ in his computer. This can be easily done with a command _find / -type f | grep '$backslash$.eoj$' | wc -l_. However, Cuber QQ is a grep...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of paths.  \nLet $ P = (p_1, p_2, \\dots, p_n) $ be a sequence of strings, where each $ p_i $ is an absolute file or directory path starting with...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments