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
sequencelengths 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 | f83bc251438d3b7865297679ac0afc3d | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.util.*;
public class E{
static long mod = 998244353;
static long mi(long a) {return pow(a,mod-2);}
static long pow(long b, long e) {
if (e==0)return 1;
long r = pow(b,e/2);
r = r*r%mod;
if (e % 2 == 1) return r * b % mod;
return r;
}
public static void main(String[] args) throws IOException {
// br = new BufferedReader(new FileReader(".in"));
// out = new PrintWriter(new FileWriter(".out"));
read();
int n = rI();
int m = rI();
Integer[][] a = new Integer[m][n];
for (int i = 0; i < n; i++) {
read();
for (int j = 0; j < m; j++) {
a[j][i] = rI();
}
}
long fac = 1;
for (int i =1; i <= n; i++) fac = fac * i %mod;
long pts = 0;
for (int i= 0 ; i < m; i++) {
Arrays.sort(a[i]);
// What are the chances that EVERY position in this permutation fails?
// How man permutations strictly lexicographically (so no EQ) than this position?
pts += fac;
long cur = 1;
for (int j =0 ; j < n; j++) {
cur *= Long.max(0, a[i][j]-j-1);
cur %= mod;
}
pts = (pts - cur + mod)%mod;
}
out.println(pts * mi(fac) % mod);
out.close();
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static StringTokenizer st;
static void read() throws IOException{st = new StringTokenizer(br.readLine());}
static int rI() throws IOException{return Integer.parseInt(st.nextToken());}
static long rL() throws IOException{return Long.parseLong(st.nextToken());}
static double rD() throws IOException{return Double.parseDouble(st.nextToken());}
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 11 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 9b00f6d1965a7bbde99ecfa692039bdb | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes |
import java.io.*;
import java.util.*;
public class AssimilationIV implements Runnable {
void solve() {
mod = 998244353;
int n = ri(), m = ri();
int[][] arr = new int[m][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[j][i] = ri();
}
}
long[] fac = lArr(n + 1);
fac[1] = fac[0] = 1;
for (int i = 2; i <= n; i++) {
fac[i] = mul(fac[i - 1], i);
}
// For point j to not be captured by any city i, the monument should be built on
// Steps >= n + 1 - x(distance)
long res = 0;
for (int i = 0; i < m; i++) {
long curr = 1;
Arrays.sort(arr[i]);
for (int j = 0; j < n; j++) {
int size = arr[i][j] - j - 1;
size = max(size, 0);
curr = mul(curr, size);
}
res = add(res, fac[n] - curr);
}
println(mul(res, inv(fac[n])));
}
long add(long a, long b) {
return (a + b + mod) % mod;
}
long sub(long a, long b) {
return (a - b) % mod;
}
long inv(long a) {
return biPower(a, mod - 2);
}
long biPower(long a, long b) {
long res = 1;
while (b > 0) {
if ((b & 1) == 1) {
res = mul(res, a);
}
b >>= 1;
a = mul(a, a);
}
return res;
}
long mul(long a, long b) {
return (a * b) % mod;
}
long nor(long a) {
if (a < mod)
a += mod;
return a;
}
/************************************************************************************************************************************************/
public static void main(String[] args) throws IOException {
new Thread(null, new AssimilationIV(), "1").start();
}
static PrintWriter out = new PrintWriter(System.out);
static Reader read = new Reader();
static StringBuilder sbr = new StringBuilder();
static int mod = (int) 1e9 + 7;
static int dmax = Integer.MAX_VALUE;
static long lmax = Long.MAX_VALUE;
static int dmin = Integer.MIN_VALUE;
static long lmin = Long.MIN_VALUE;
static int[] dprimes = new int[]{1, 11, 101, 1087, 99991, 100001, 1000003, 15485863, 999999937};
@Override
public void run() {
solve();
out.close();
}
static class Reader {
private byte[] buf = new byte[1024];
private int index;
private InputStream in;
private int total;
public Reader() {
in = System.in;
}
public int scan() throws IOException {
if (total < 0)
throw new InputMismatchException();
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public int intNext() throws IOException {
int integer = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
return neg * integer;
}
public double doubleNext() throws IOException {
double doub = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n) && n != '.') {
if (n >= '0' && n <= '9') {
doub *= 10;
doub += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
if (n == '.') {
n = scan();
double temp = 1;
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
temp /= 10;
doub += (n - '0') * temp;
n = scan();
} else
throw new InputMismatchException();
}
}
return doub * neg;
}
public String read() throws IOException {
StringBuilder sb = new StringBuilder();
int n = scan();
while (isWhiteSpace(n))
n = scan();
while (!isWhiteSpace(n)) {
sb.append((char) n);
n = scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
}
// Gives strict lowerBound that previous number would be smaller than the target
int lowerBound(int[] arr, int val) {
int l = 0, r = arr.length - 1;
while (l < r) {
int mid = (r + l) >> 1;
if (arr[mid] >= val) {
r = mid;
} else
l = mid + 1;
}
return l;
}
// Gives strict upperBound that next number would be greater than the target
int upperBound(int[] arr, int val) {
int l = 0, r = arr.length - 1;
while (l < r) {
int mid = (r + l + 1) >> 1;
if (arr[mid] <= val) {
l = mid;
} else
r = mid - 1;
}
return l;
}
static void print(Object object) {
out.print(object);
}
static void println(Object object) {
out.println(object);
}
static int[] iArr(int len) {
return new int[len];
}
static long[] lArr(int len) {
return new long[len];
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(Long a, Long b) {
return Math.max(a, b);
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int ri() {
try {
return read.intNext();
} catch (IOException e) {
e.printStackTrace();
}
System.exit(2);
return -1;
}
static long rl() {
try {
return Long.parseLong(read.read());
} catch (IOException e) {
e.printStackTrace();
}
System.exit(2);
return -1;
}
static String rs() {
try {
return read.read();
} catch (IOException e) {
e.printStackTrace();
}
System.exit(2);
return "";
}
static char rc() {
return rs().charAt(0);
}
static double rd() {
try {
return read.doubleNext();
} catch (IOException e) {
e.printStackTrace();
}
System.exit(2);
return -1;
}
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 11 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | afe7063be6a4f0b8eadc2ea01f679bd4 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class Div716 {
static int n, m, a[][];
static int mod = 998244353;
static long[] fact;
static long[] inv;
static void preprocess() {
fact = new long[n + 1];
inv = new long[n + 1];
fact[0] = fact[1] = inv[0] = inv[1] = 1;
for (int i = 2; i <= n; i++) {
fact[i] = (fact[i - 1] * i) % mod;
inv[i] = inv(fact[i]);
}
}
static long inv(long a) {
int e = mod - 2;
long res = 1;
while (e > 0) {
if (e % 2 == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1;
}
return res;
}
static long ncr(int n, int r) {
if (r > n || n < 0 || r < 0)
return 0;
long res = fact[n] * inv[r];
res %= mod;
return (res * inv[n - r]) % mod;
}
static long solve() {
long res = 0;
for (int i = 0; i < m; i++) {
long cur = 1;
Arrays.sort(a[i]);
for (int j = 0; j < n; j++) {
int size = a[i][j] - j - 1;
size = Math.max(size, 0);
cur *= size;
cur %= mod;
}
res += (mod + fact[n] - cur);
res %= mod;
}
return res;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
n = sc.nextInt();
m = sc.nextInt();
a = new int[m][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
a[j][i] = sc.nextInt();
}
preprocess();
pw.println((solve() * inv[n]) % mod);
pw.flush();
}
static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int[] nextIntArr(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 11 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 9866993df8b72f2dd54f015e5c64c93c | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | //package ecr109;
import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;
public class E {
InputStream is;
FastWriter out;
String INPUT = "";
void solve()
{
int n = ni(), m = ni();
int[][] a = nmi(n, m);
final int mod = 998244353;
long ans = 0;
for(int i = 0;i < m;i++){
int[] b = new int[n];
for(int j = 0;j < n;j++){
b[j] = a[j][i];
}
Arrays.sort(b);
long c = 1;
for(int j = 0;j < n;j++){
if(b[j]-(j+1) < 0)c = 0;
c = c * (b[j]-(j+1)) % mod;
}
tr(c);
ans += c;
}
ans = ans % mod;
long den = 1;
for(int i = 1;i <= n;i++)den = den * i % mod;
out.println(((m-ans*invl(den, mod))%mod+mod)%mod);
}
public static long invl(long a, long mod) {
long b = mod;
long p = 1, q = 0;
while (b > 0) {
long c = a / b;
long d;
d = a;
a = b;
b = d % b;
d = p;
p = q;
q = d - c * q;
}
return p < 0 ? p + mod : p;
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new FastWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new E().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 int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private long[] nal(int n)
{
long[] a = new long[n];
for(int i = 0;i < n;i++)a[i] = nl();
return a;
}
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[][] nmi(int n, int m) {
int[][] map = new int[n][];
for(int i = 0;i < n;i++)map[i] = na(m);
return map;
}
private int ni() { return (int)nl(); }
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();
}
}
public static class FastWriter
{
private static final int BUF_SIZE = 1<<13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter(){out = null;}
public FastWriter(OutputStream os)
{
this.out = os;
}
public FastWriter(String path)
{
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b)
{
buf[ptr++] = b;
if(ptr == BUF_SIZE)innerflush();
return this;
}
public FastWriter write(char c)
{
return write((byte)c);
}
public FastWriter write(char[] s)
{
for(char c : s){
buf[ptr++] = (byte)c;
if(ptr == BUF_SIZE)innerflush();
}
return this;
}
public FastWriter write(String s)
{
s.chars().forEach(c -> {
buf[ptr++] = (byte)c;
if(ptr == BUF_SIZE)innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000) return 10;
if (l >= 100000000) return 9;
if (l >= 10000000) return 8;
if (l >= 1000000) return 7;
if (l >= 100000) return 6;
if (l >= 10000) return 5;
if (l >= 1000) return 4;
if (l >= 100) return 3;
if (l >= 10) return 2;
return 1;
}
public FastWriter write(int x)
{
if(x == Integer.MIN_VALUE){
return write((long)x);
}
if(ptr + 12 >= BUF_SIZE)innerflush();
if(x < 0){
write((byte)'-');
x = -x;
}
int d = countDigits(x);
for(int i = ptr + d - 1;i >= ptr;i--){
buf[i] = (byte)('0'+x%10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public FastWriter write(long x)
{
if(x == Long.MIN_VALUE){
return write("" + x);
}
if(ptr + 21 >= BUF_SIZE)innerflush();
if(x < 0){
write((byte)'-');
x = -x;
}
int d = countDigits(x);
for(int i = ptr + d - 1;i >= ptr;i--){
buf[i] = (byte)('0'+x%10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision)
{
if(x < 0){
write('-');
x = -x;
}
x += Math.pow(10, -precision)/2;
// if(x < 0){ x = 0; }
write((long)x).write(".");
x -= (long)x;
for(int i = 0;i < precision;i++){
x *= 10;
write((char)('0'+(int)x));
x -= (int)x;
}
return this;
}
public FastWriter writeln(char c){
return write(c).writeln();
}
public FastWriter writeln(int x){
return write(x).writeln();
}
public FastWriter writeln(long x){
return write(x).writeln();
}
public FastWriter writeln(double x, int precision){
return write(x, precision).writeln();
}
public FastWriter write(int... xs)
{
boolean first = true;
for(int x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs)
{
boolean first = true;
for(long x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln()
{
return write((byte)'\n');
}
public FastWriter writeln(int... xs)
{
return write(xs).writeln();
}
public FastWriter writeln(long... xs)
{
return write(xs).writeln();
}
public FastWriter writeln(char[] line)
{
return write(line).writeln();
}
public FastWriter writeln(char[]... map)
{
for(char[] line : map)write(line).writeln();
return this;
}
public FastWriter writeln(String s)
{
return write(s).writeln();
}
private void innerflush()
{
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush()
{
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) { return write(b); }
public FastWriter print(char c) { return write(c); }
public FastWriter print(char[] s) { return write(s); }
public FastWriter print(String s) { return write(s); }
public FastWriter print(int x) { return write(x); }
public FastWriter print(long x) { return write(x); }
public FastWriter print(double x, int precision) { return write(x, precision); }
public FastWriter println(char c){ return writeln(c); }
public FastWriter println(int x){ return writeln(x); }
public FastWriter println(long x){ return writeln(x); }
public FastWriter println(double x, int precision){ return writeln(x, precision); }
public FastWriter print(int... xs) { return write(xs); }
public FastWriter print(long... xs) { return write(xs); }
public FastWriter println(int... xs) { return writeln(xs); }
public FastWriter println(long... xs) { return writeln(xs); }
public FastWriter println(char[] line) { return writeln(line); }
public FastWriter println(char[]... map) { return writeln(map); }
public FastWriter println(String s) { return writeln(s); }
public FastWriter println() { return writeln(); }
}
public void trnz(int... o)
{
for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
System.out.println();
}
// print ids which are 1
public void trt(long... o)
{
Queue<Integer> stands = new ArrayDeque<>();
for(int i = 0;i < o.length;i++){
for(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));
}
System.out.println(stands);
}
public void tf(boolean... r)
{
for(boolean x : r)System.out.print(x?'#':'.');
System.out.println();
}
public void tf(boolean[]... b)
{
for(boolean[] r : b) {
for(boolean x : r)System.out.print(x?'#':'.');
System.out.println();
}
System.out.println();
}
public void tf(long[]... b)
{
if(INPUT.length() != 0) {
for (long[] r : b) {
for (long x : r) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
System.out.println();
}
}
public void tf(long... b)
{
if(INPUT.length() != 0) {
for (long x : b) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 11 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | ed6db8e26635432c6df85cfbb473605d | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
//import java.math.*;
public class Task{
// ..............code begins here..............
static long mod=(long)1e9+7,mod1=998244353l,inf=(long)1e17;
/*
https://www.hackerrank.com/contests/goc-cdc-series-7/challenges/different-chocolates/submissions/code/1335897457
two ways to find Expectation
1. Ususal way - sum(probailty*no_of_conquered_points)
2. See expected value of "What" we have to find?
Here "what"==conquered points......== no of points(under some condition)
The contribution technique way we can find it like follow
Now find given a point(=="what") what is probabilty that it will be conquered
by some monument
add these probabilities for all points and since each point is corresponds to
1 point so contribution in expected value=1. That's why we just add the probabilities
which is same as => probability*no_of_point = probability*1
*/
static void solve() throws IOException {
int[] x=int_arr();
int n=x[0],m=x[1];
long[] f=new long[25];
long[] inv=new long[25];
f[0]=1;
for(int i=1;i<25;i++){
f[i]=Modmul(f[i-1],i,mod1);
}
inv[24]=ModInv(f[24],mod1);
for(int i=23;i>=0;i--)inv[i]=Modmul(i+1,inv[i+1],mod1);
int[][] a=new int[m][n];
for(int i=0;i<n;i++){
int[] d=int_arr();
for(int j=0;j<m;j++){
a[j][i]=d[j];
}
}
long res=m;
for(int i=0;i<m;i++){
int[] fre=new int[n+2];
for(int j=0;j<n;j++)fre[a[i][j]]++;
long tmp=1l;
int occ=0;
for(int j=1;j<=n+1;j++){
if(j-1-occ-fre[j]<0){tmp=0;continue;}
tmp*=Modmul(f[j-1-occ],inv[j-1-occ-fre[j]],mod1);
tmp%=mod1;
occ+=fre[j];
}
tmp=Modmul(tmp,inv[n],mod1);
res-=tmp;
}
res%=mod1;
res=(res+mod1)%mod1;
out.write(res+"\n");
}
//
public static void main(String[] args) throws IOException{
assign();
int t=1;//int_v(read()),cn=1;
while(t--!=0){
//out.write("Case #"+cn+": ");
solve();
//cn++;
}
out.flush();
}
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int add(int a,int b){int z=a+b;if(z>=mod)z-=mod;return z;}
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
//static long[] f;
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | eaaf7175ca9aa3ff6b8ba418d753d36c | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
//import java.math.*;
public class Task{
// ..............code begins here..............
static long mod=(long)1e9+7,mod1=998244353l,inf=(long)1e17;
/*
two ways to find Expectation
1. Ususal way - sum(probailty*no_of_conquered_points)
2. See expected value of "What" we have to find?
Here "what"==conquered points......== no of points(under some condition)
The contribution technique way we can find it like follow
Now find given a point(=="what") what is probabilty that it will be conquered
by some monument
add these probabilities for all points and since each point is corresponds to
1 point so contribution in expected value=1. That's why we just add the probabilities
which is same as => probability*no_of_point = probability*1
*/
static void solve() throws IOException {
int[] x=int_arr();
int n=x[0],m=x[1];
long[] f=new long[25];
long[] inv=new long[25];
f[0]=1;
for(int i=1;i<25;i++){
f[i]=Modmul(f[i-1],i,mod1);
}
inv[24]=ModInv(f[24],mod1);
for(int i=23;i>=0;i--)inv[i]=Modmul(i+1,inv[i+1],mod1);
int[][] a=new int[m][n];
for(int i=0;i<n;i++){
int[] d=int_arr();
for(int j=0;j<m;j++){
a[j][i]=d[j];
}
}
long res=m;
for(int i=0;i<m;i++){
int[] fre=new int[n+2];
for(int j=0;j<n;j++)fre[a[i][j]]++;
long tmp=1l;
int occ=0;
for(int j=1;j<=n+1;j++){
if(j-1-occ-fre[j]<0){tmp=0;continue;}
tmp*=Modmul(f[j-1-occ],inv[j-1-occ-fre[j]],mod1);
tmp%=mod1;
occ+=fre[j];
}
tmp=Modmul(tmp,inv[n],mod1);
res-=tmp;
}
res%=mod1;
res=(res+mod1)%mod1;
out.write(res+"\n");
}
//
public static void main(String[] args) throws IOException{
assign();
int t=1;//int_v(read()),cn=1;
while(t--!=0){
//out.write("Case #"+cn+": ");
solve();
//cn++;
}
out.flush();
}
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int add(int a,int b){int z=a+b;if(z>=mod)z-=mod;return z;}
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
//static long[] f;
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 5794d6e0428d1a28f93e904a5b1e731d | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
//import java.math.*;
public class Task{
// ..............code begins here..............
static long mod=(long)1e9+7,mod1=998244353l,inf=(long)1e17;
static void solve() throws IOException {
int[] x=int_arr();
int n=x[0],m=x[1];
long[] f=new long[25];
long[] inv=new long[25];
f[0]=1;
for(int i=1;i<25;i++){
f[i]=Modmul(f[i-1],i,mod1);
}
inv[24]=ModInv(f[24],mod1);
for(int i=23;i>=0;i--)inv[i]=Modmul(i+1,inv[i+1],mod1);
int[][] a=new int[m][n];
for(int i=0;i<n;i++){
int[] d=int_arr();
for(int j=0;j<m;j++){
a[j][i]=d[j];
}
}
long res=m;
for(int i=0;i<m;i++){
int[] fre=new int[n+2];
for(int j=0;j<n;j++)fre[a[i][j]]++;
long tmp=1l;
int occ=0;
for(int j=1;j<=n+1;j++){
if(j-1-occ-fre[j]<0){tmp=0;continue;}
tmp*=Modmul(f[j-1-occ],inv[j-1-occ-fre[j]],mod1);
tmp%=mod1;
occ+=fre[j];
}
tmp=Modmul(tmp,inv[n],mod1);
res-=tmp;
}
res%=mod1;
res=(res+mod1)%mod1;
out.write(res+"\n");
}
//
public static void main(String[] args) throws IOException{
assign();
int t=1;//int_v(read()),cn=1;
while(t--!=0){
//out.write("Case #"+cn+": ");
solve();
//cn++;
}
out.flush();
}
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int add(int a,int b){int z=a+b;if(z>=mod)z-=mod;return z;}
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
//static long[] f;
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 96f5f9900a0e7e26d32105fddbe1d9f4 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
//import java.math.*;
public class Task{
// ..............code begins here..............
static long mod=(long)1e9+7,mod1=998244353l,inf=(long)1e17;
static void solve() throws IOException {
int[] x=int_arr();
int n=x[0],m=x[1];
f=new long[25];
f[0]=1;
for(int i=1;i<25;i++){
f[i]=Modmul(f[i-1],(long)i,mod1);
}
int[][] a=new int[m][n];
for(int i=0;i<n;i++){
int[] d=int_arr();
for(int j=0;j<m;j++){
a[j][i]=d[j];
}
}
long res=m;
for(int i=0;i<m;i++){
int[] fre=new int[n+2];
for(int j=0;j<n;j++)fre[a[i][j]]++;
long tmp=1l;
int occ=0;
for(int j=1;j<=n+1;j++){
tmp=Modmul(tmp,nck(j-1-occ,fre[j],mod1),mod1);
tmp=Modmul(tmp,f[fre[j]],mod1);
occ+=fre[j];
}
tmp=Modmul(tmp,ModInv(f[n],mod1),mod1);
res-=tmp;
}
res%=mod1;
res=(res+mod1)%mod1;
out.write(res+"\n");
}
//
public static void main(String[] args) throws IOException{
assign();
int t=1;//int_v(read()),cn=1;
while(t--!=0){
//out.write("Case #"+cn+": ");
solve();
//cn++;
}
out.flush();
}
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int add(int a,int b){int z=a+b;if(z>=mod)z-=mod;return z;}
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
static long[] f;
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 28d6d2fb7241e4944b41f0f3d7611ca6 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
//import java.math.*;
public class Task{
// ..............code begins here..............
static long mod=(long)1e9+7,mod1=998244353l,inf=(long)1e17;
static void solve() throws IOException {
int[] x=int_arr();
int n=x[0],m=x[1];
f=new long[25];
f[0]=1;
for(int i=1;i<25;i++){
f[i]=Modmul(f[i-1],(long)i,mod1);
}
int[][] a=new int[m][n];
for(int i=0;i<n;i++){
int[] d=int_arr();
for(int j=0;j<m;j++){
a[j][i]=d[j];
}
}
long res=m;
for(int i=0;i<m;i++){
int[] fre=new int[n+2];
for(int j=0;j<n;j++)fre[a[i][j]]++;
long tmp=1l;
int occ=0;
for(int j=1;j<=n+1;j++){
if(fre[j]==0) continue;
if(j-1-occ<0){tmp=0;break;}
tmp=Modmul(tmp,nck(j-1-occ,fre[j],mod1),mod1);
//out.write(" ok "+j+" "+fre[j]+" "+occ+" ok\n");
tmp=Modmul(tmp,f[fre[j]],mod1);
occ+=fre[j];
}
tmp=Modmul(tmp,ModInv(f[n],mod1),mod1);
//out.write(tmp+", ");
res-=tmp;
}
res%=mod1;
res=(res+mod1)%mod1;
out.write(res+"\n");
//out.write(1l*ModInv(1l,mod1)+", ");
}
//
public static void main(String[] args) throws IOException{
assign();
int t=1;//int_v(read()),cn=1;
while(t--!=0){
//out.write("Case #"+cn+": ");
solve();
//cn++;
}
out.flush();
}
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static void sort(int[] a){List<Integer> l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i<a.length;i++){a[i]=l.get(i);}}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
//static String setpreciosion(double d,int k){BigDecimal d1 = new BigDecimal(Double.toString(d));return d1.setScale(k,RoundingMode.HALF_UP).toString();}//UP DOWN HALF_UP
static int add(int a,int b){int z=a+b;if(z>=mod)z-=mod;return z;}
static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static long ModInv(long a,long m){return Modpow(a,m-2,m);}
static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}
static long[] f;
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 729869544a65e61dfccc6e0f752d6c05 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class tr1 {
static PrintWriter out;
static StringBuilder sb;
static long mod = (long) 998244353;
static int[][] memo;
static int n, m;
static ArrayList<Integer>[] ad;
static HashMap<Integer, Integer>[] going;
static long inf = Long.MAX_VALUE;
static char[][] g;
static boolean[] vis;
static int[] a;
static int ans;
static int[][] turn;
static HashMap<Integer, Integer> hmC, hmG;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
out = new PrintWriter(System.out);
n = sc.nextInt();
m = sc.nextInt();
int[][] a = new int[n][m];
for (int i = 0; i < n; i++)
a[i] = sc.nextArrInt(m);
long ans = 0;
long[] f = new long[n + 5];
f[0] = 1;
for (int i = 1; i < f.length; i++)
f[i] = f[i - 1] * i % mod;
for (int i = 0; i < m; i++) {
Integer[] d = new Integer[n];
for (int j = 0; j < n; j++)
d[j] = a[j][i];
Arrays.sort(d);
if (d[0].intValue() == 1) {
ans = (ans + f[n]) % mod;
continue;
}
int all = 0;
long mul = 1;
for (int j = 0; j < n; j++) {
if (d[j].intValue() > n)
break;
int x = d[j].intValue() - 1;
mul = mul * (x - all) % mod;
all++;
}
mul = mul * f[n - all]%mod;
ans += (f[n] - mul + mod) % mod;
ans%=mod;
// System.out.println(ans + " " + i + " " + mul + " " + all);
}
// System.out.println(ans);
// System.out.println(modPow(f[n], mod - 2));
System.out.println(ans * modPow(f[n], mod - 2) % mod);
out.flush();
}
static long modPow(long a, long e)
{
long res = 1;
while (e > 0) {
if ((e & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1;
}
return res;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public int[] nextArrInt(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextArrLong(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextArrIntSorted(int n) throws IOException {
int[] a = new int[n];
Integer[] a1 = new Integer[n];
for (int i = 0; i < n; i++)
a1[i] = nextInt();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].intValue();
return a;
}
public long[] nextArrLongSorted(int n) throws IOException {
long[] a = new long[n];
Long[] a1 = new Long[n];
for (int i = 0; i < n; i++)
a1[i] = nextLong();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].longValue();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | be7b60cab61c3bd91270edd910a7a174 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class tr1 {
static PrintWriter out;
static StringBuilder sb;
static long mod = (long) 998244353;
static int[][] memo;
static int n, m;
static ArrayList<Integer>[] ad;
static HashMap<Integer, Integer>[] going;
static long inf = Long.MAX_VALUE;
static char[][] g;
static boolean[] vis;
static int[] a;
static int ans;
static int[][] turn;
static HashMap<Integer, Integer> hmC, hmG;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
out = new PrintWriter(System.out);
n = sc.nextInt();
m = sc.nextInt();
int[][] a = new int[n][m];
for (int i = 0; i < n; i++)
a[i] = sc.nextArrInt(m);
long ans = 0;
long[] f = new long[n + 5];
f[0] = 1;
for (int i = 1; i < f.length; i++)
f[i] = (f[i - 1] * i) % mod;
for (int i = 0; i < m; i++) {
Integer[] d = new Integer[n];
for (int j = 0; j < n; j++)
d[j] = a[j][i];
Arrays.sort(d);
if (d[0].intValue() == 1) {
ans = (ans + f[n]) % mod;
continue;
}
int all = 0;
long mul = 1;
for (int j = 0; j < n; j++) {
if (d[j].intValue() > n)
break;
int x = d[j].intValue() - 1;
mul = (mul * (x - all)) % mod;
all++;
}
mul = (mul * f[n - all]) % mod;
ans += (((f[n] - mul) % mod) + mod) % mod;
ans %= mod;
}
System.out.println(ans * modPow(f[n], mod - 2) % mod);
out.flush();
}
static long modPow(long a, long e)
{
long res = 1;
while (e > 0) {
if ((e & 1) == 1)
res = (res * a) % mod;
a = (a * a) % mod;
e >>= 1;
}
return res;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public int[] nextArrInt(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextArrLong(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public int[] nextArrIntSorted(int n) throws IOException {
int[] a = new int[n];
Integer[] a1 = new Integer[n];
for (int i = 0; i < n; i++)
a1[i] = nextInt();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].intValue();
return a;
}
public long[] nextArrLongSorted(int n) throws IOException {
long[] a = new long[n];
Long[] a1 = new Long[n];
for (int i = 0; i < n; i++)
a1[i] = nextLong();
Arrays.sort(a1);
for (int i = 0; i < n; i++)
a[i] = a1[i].longValue();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 98088c104a04204cf4527197401cdf58 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
public class E1525 {
static final int mod = 998244353;
public static long npk(int n, int k) {
if (k < 0 || k > n)
return 0;
long ans = 1;
for (int i = 0; i < k; i++) {
ans = ans * (n - i) % mod;
}
return ans;
}
public static long modPow(long a, long e) {
if (e == 0) {
return 1;
}
if (e % 2 == 1) {
return a * modPow(a, e - 1) % mod;
}
long p = modPow(a, e / 2);
return p * p % mod;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] arr = new int[n][];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextIntArr(m);
}
long sum = 0;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i < fac.length; i++) {
fac[i] = fac[i - 1] * i % mod;
}
for (int i = 0; i < m; i++) {
int[] cnt = new int[n + 2];
for (int j = 0; j < n; j++) {
cnt[arr[j][i]]++;
}
long ans = 1;
int av = 0;
// System.out.println(Arrays.toString(cnt));
for (int j = 1; j <= n + 1; j++) {
ans = ans * npk(av, cnt[j]) % mod;
av -= cnt[j];
av++;
}
// System.out.println(ans);
sum += fac[n] - ans;
sum %= mod;
}
// System.out.println(sum);
for (int i = 1; i <= n; i++) {
sum = sum * modPow(i, mod - 2) % mod;
}
pw.println((sum + mod) % mod);
pw.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader f) {
br = new BufferedReader(f);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public int[] nextIntArr(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(next());
}
return arr;
}
}
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 37ab131be246b886d546e5837f4c9077 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | //https://github.com/EgorKulikov/yaal/tree/master/lib/main/net/egork
import java.util.*;
import java.io.*;
public class A{
static PrintWriter out;
static InputReader in;
public static void main(String args[]){
out = new PrintWriter(System.out);
in = new InputReader();
new A();
out.flush(); out.close();
}
A(){
solve();
}
final int mod = 998244353;
final int maxn = 22;
long fac[] = new long[maxn], ifac[] = new long[maxn];
long mul(long a, long b){
a *= b;
if(a >= mod)a %= mod;
return a;
}
long add(long a, long b){
a += b;
if(a >= mod)a -= mod;
return a;
}
long sub(long a, long b){
a -= b;
if(a < 0)a += mod;
return a;
}
long rpe(long a, long b){
long ans = 1;
while(b != 0){
if(b % 2 == 1)ans = mul(ans, a);
a = mul(a, a); b >>= 1;
}return ans;
}
long ncr(int n, int r){
if(r > n)return 0;
return mul(fac[n], mul(ifac[r], ifac[n - r]));
}
long npr(int n, int r){
if(r > n || n < 0)return 0;
return mul(fac[n], ifac[n - r]);
}
void solve(){
// int t = in.nextInt();
fac[0] = ifac[0] = 1;
for(int i = 1; i < maxn; i++){
fac[i] = mul(fac[i - 1], i);
ifac[i] = rpe(fac[i], mod - 2);
}
int t = 1;
while(t-- > 0){
int n = in.nextInt(), m = in.nextInt();
int a[][] = new int[n][m];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)a[i][j] = in.nextInt();
}
int dp[] = new int[maxn];
long sub = 0;
for(int i = 0; i < m; i++){
Arrays.fill(dp, 0);
for(int j = 0; j < n; j++)dp[a[j][i]]++;
int space = 0;
long cont = 1;
for(int j = 1; j <= n + 1; j++){
if(dp[j] != 0){
cont = mul(cont, npr(space, dp[j]));
space -= dp[j];
}
space++;
}
// System.out.println(cont);
sub = add(sub, cont);
}
long ans = sub(m, mul(sub, ifac[n]));
out.print(ans);
}
}
public static class InputReader{
BufferedReader br;
StringTokenizer st;
InputReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public String next(){
while(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
}catch(IOException e){}
}
return st.nextToken();
}
}
}
| Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 78d783793e7356a2c17296f4bd0e0706 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.util.*;
public final class Solution {
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(1, 0), new Pair(0, -1), new Pair(0, 1)};
// Monocarp's empire has 𝑛 cities. In order to conquer new lands he plans to build one Monument in each city.
// The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.
//
// Monocarp has 𝑚 points on the map he'd like to control using the constructed Monuments. For each point he knows
// the distance between it and each city. Monuments work in the following way: when built in some city, a Monument
// controls all points at distance at most 1 to this city. Next turn, the Monument controls all points at distance
// at most 2, the turn after — at distance at most 3, and so on. Monocarp will build 𝑛 Monuments in 𝑛 turns and his
// empire will conquer all points that are controlled by at least one Monument.
//
// Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among
// all remaining cities (cities without Monuments). Monocarp wants to know how many points (among 𝑚 of them) he will
// conquer at the end of turn number 𝑛. Help him to calculate the expected number of conquered points!
//The first line contains two integers 𝑛 and 𝑚 (1≤𝑛≤20; 1≤𝑚≤5⋅104) — the number of cities and the number of points.
//
//Next 𝑛 lines contains 𝑚 integers each: the 𝑗-th integer of the 𝑖-th line 𝑑𝑖,𝑗 (1≤𝑑𝑖,𝑗≤𝑛+1) is the distance between the 𝑖-th city and the 𝑗-th point.
//3 5
//1 4 4 3 4
//1 4 1 4 2
//1 4 4 4 3
//10 [6 8 5 7 4 3 11 11 11 11]
//3 [4 2 3] 123 132 213 231 321 312
public static void main(String[] args) {
int tt = 1;
int mod = 998244353;
out:
while (tt-- > 0) {
int n = i(), m = i();
int[][] in = new int[m][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
in[j][i] = i();
}
}
long ans = 0;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (fac[i - 1] * i) % mod;
}
for (int i = 0; i < m; i++) {
shuffle(in[i]);
Arrays.sort(in[i]);
long smallerNotCovering = 1;
for (int j = 0; j < n; j++) {
int possiblePos = (n - in[i][j] + 1);
long curPerms = (fac[n - 1 - j] * possiblePos) % mod;
curPerms = (curPerms * smallerNotCovering) % mod;
ans = (ans + curPerms) % mod;
smallerNotCovering = (smallerNotCovering * (in[i][j] - j - 1)) % mod;
}
}
out.println((ans * modInverse(fac[n], mod)) % mod);
}
out.flush();
}
static void print(char A[]) {
for (char c : A) {
out.print(c);
}
out.println();
}
static void print(boolean A[]) {
for (boolean c : A) {
out.print(c + " ");
}
out.println();
}
static void print(int A[]) {
for (int c : A) {
out.print(c + " ");
}
out.println();
}
static void print(long A[]) {
for (long i : A) {
out.print(i + " ");
}
out.println();
}
static void print(List<Integer> A) {
for (int a : A) {
out.print(a + " ");
}
}
static void printYes() {
out.println("YES");
}
static void printNo() {
out.println("NO");
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static String s() {
return in.nextLine();
}
static int[][] inputWithIdx(int N) {
int A[][] = new int[N][2];
for (int i = 0; i < N; i++) {
A[i] = new int[]{i, in.nextInt()};
}
return A;
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
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) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static void shuffle(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int rand = (int) (Math.random() * arr.length);
int temp = arr[rand];
arr[rand] = arr[i];
arr[i] = temp;
}
}
static boolean isPerfectSquare(double number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static void swap(int A[], int a, int b) {
int t = A[a];
A[a] = A[b];
A[b] = t;
}
static long pow(long a, long b, int mod) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow = (pow * x) % mod;
}
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static long modInverse(long x, int mod) {
return pow(x, mod - 2, mod);
}
static boolean isPrime(long N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
if (N % 2 == 0 || N % 3 == 0) {
return false;
}
for (int i = 5; i * i <= N; i = i + 6) {
if (N % i == 0 || N % (i + 2) == 0) {
return false;
}
}
return true;
}
}
class Pair {
int i, j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
}
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 | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 070a39043402f6b8bd4bd833d65ac90d | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {new Main().run();}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
void run(){
work();
out.flush();
}
long mod=998244353;
long gcd(long a,long b) {
return a==0?b:gcd(b%a,a);
}
final long inf=Long.MAX_VALUE/3;
long[] rec;
long[] inv;
void work(){
int n=ni(),m=ni();
rec=new long[25];
inv=new long[25];
rec[0]=1;
inv[0]=1;
for(int i=1;i<25;i++){
rec[i]=(i*rec[i-1])%mod;
inv[i]=pow(rec[i],mod-2);
}
int[][] A=new int[m][n];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
A[j][i]=ni();
}
}
long ret=0;
for(int[] B:A){
Arrays.sort(B);
long r=1;
for(int i=0;i<n;i++){
int c=B[i]-1-i;
if(c<=0){
r=0;
break;
}
r=(r*c)%mod;
}
r=((rec[n]-r)%mod+mod)%mod;
r=(r*inv[n])%mod;
ret=(ret+r)%mod;
}
out.println(ret);
}
private long pow(long a, long b) {
long ret=1;
while(b>0){
if(b%2==1){
ret=(ret*a)%mod;
}
a=(a*a)%mod;
b/=2;
}
return ret;
}
//input
@SuppressWarnings("unused")
private ArrayList<Integer>[] ng(int n, int m) {
ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
for(int i=0;i<n;i++) {
graph[i]=new ArrayList<>();
}
for(int i=1;i<=m;i++) {
int s=in.nextInt()-1,e=in.nextInt()-1;
graph[s].add(e);
graph[e].add(s);
}
return graph;
}
private ArrayList<long[]>[] ngw(int n, int m) {
ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
for(int i=0;i<n;i++) {
graph[i]=new ArrayList<>();
}
for(int i=1;i<=m;i++) {
long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
graph[(int)s].add(new long[] {e,w});
graph[(int)e].add(new long[] {s,w});
}
return graph;
}
private int ni() {
return in.nextInt();
}
private long nl() {
return in.nextLong();
}
private String ns() {
return in.next();
}
private long[] na(int n) {
long[] A=new long[n];
for(int i=0;i<n;i++) {
A[i]=in.nextLong();
}
return A;
}
private int[] nia(int n) {
int[] A=new int[n];
for(int i=0;i<n;i++) {
A[i]=in.nextInt();
}
return A;
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
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());
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 3d01b429ac7000d9aecc797db87e97f4 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;
public class Main {
//static final long MOD = 1000000007L;
//static final long MOD2 = 1000000009L;
static final long MOD = 998244353L;
//static final long INF = 500000000000L;
static final int INF = 1000000005;
static final int NINF = -1000000005;
//static final long INF = 1000000000000000000L;
static FastScanner sc;
static PrintWriter pw;
static final int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}};
public static void main(String[] args) {
sc = new FastScanner();
pw = new PrintWriter(System.out);
int N = sc.ni();
int M = sc.ni();
int[][] nums = new int[M][N];
long num = 0;
long den = 1;
for (int i = 0; i < N; i++) {
den *= (i+1);
for (int j = 0; j < M; j++) {
nums[j][i] = sc.ni()-1;
}
}
den %= MOD;
for (int i = 0; i < M; i++) {
long bad = 1;
sort(nums[i]);
//pw.println(Arrays.toString(nums[i]));
for (int j = 0; j < N; j++) {
bad *= Math.max(0,nums[i][j]-j);
bad %= MOD;
}
num = (num+den-bad+MOD)%MOD;
}
long ans = (num*power(den,MOD-2,MOD))%MOD;
pw.println(ans);
pw.close();
}
public static long power(long x, long y, long m) {
long ans = 1;
x %= m;
while (y > 0) {
if((y&1)==1)
ans = (ans * x) % m;
y /= 2;
x = (x * x) % m;
}
return ans;
}
public static void sort(int[] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int r = rgen.nextInt(arr.length);
int temp = arr[i];
arr[i] = arr[r];
arr[r] = temp;
}
Arrays.sort(arr);
}
public static void sort(long[] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int r = rgen.nextInt(arr.length);
long temp = arr[i];
arr[i] = arr[r];
arr[r] = temp;
}
Arrays.sort(arr);
}
//Sort an array (immune to quicksort TLE)
public static void sort(int[][] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int r = rgen.nextInt(arr.length);
int[] temp = arr[i];
arr[i] = arr[r];
arr[r] = temp;
}
Arrays.sort(arr, new Comparator<int[]>() {
@Override
public int compare(int[] a, int[] b) {
return a[0]-b[0];
}
});
}
public static void sort(long[][] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int r = rgen.nextInt(arr.length);
long[] temp = arr[i];
arr[i] = arr[r];
arr[r] = temp;
}
Arrays.sort(arr, new Comparator<long[]>() {
@Override
public int compare(long[] a, long[] b) {
if (a[0] > b[0])
return 1;
else if (a[0] < b[0])
return -1;
else
return 0;
//Ascending order.
}
});
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in), 32768);
st = null;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
int[][] graph(int N, int[][] edges) {
int[][] graph = new int[N][];
int[] sz = new int[N];
for (int[] e: edges) {
sz[e[0]] += 1;
sz[e[1]] += 1;
}
for (int i = 0; i < N; i++) {
graph[i] = new int[sz[i]];
}
int[] cur = new int[N];
for (int[] e: edges) {
graph[e[0]][cur[e[0]]] = e[1];
graph[e[1]][cur[e[1]]] = e[0];
cur[e[0]] += 1;
cur[e[1]] += 1;
}
return graph;
}
int[] intArray(int N, int mod) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = ni()+mod;
return ret;
}
char[] charArray(int N) {
char[] ret = new char[N];
for (int i = 0; i < N; i++)
ret[i] = next().charAt(0);
return ret;
}
long nl() {
return Long.parseLong(next());
}
long[] longArray(int N, long mod) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = nl()+mod;
return ret;
}
double nd() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | dd86cba9e507e5ad06c75383f11ee756 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | /*
bts songs to dance to:
I need U
Run
ON
Filter
I'm fine
*/
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
public class x1525E
{
static final long MOD = 998244353L;
public static void main(String hi[]) throws Exception
{
fac = new long[22];
invfac = new long[22];
fac[0] = invfac[0] = 1L;
for(int i=1; i < 22; i++)
{
fac[i] = (fac[i-1]*i)%MOD;
invfac[i] = power(fac[i], MOD-2, MOD);
}
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] grid = new int[N][M];
for(int r=0; r < N; r++)
grid[r] = readArr(M, infile, st);
long res = 0L;
for(int a=0; a < M; a++)
{
cnt = new int[N];
for(int i=0; i < N; i++)
if(grid[i][a] > 1)
cnt[N+1-grid[i][a]]++;
prefix = new int[N];
prefix[0] = cnt[0];
for(int i=1; i < N; i++)
prefix[i] = prefix[i-1]+cnt[i];
dp = new long[N];
Arrays.fill(dp, -1);
long temp = dfs(0, N);
temp = (temp*invfac[N])%MOD;
temp = (1-temp+MOD)%MOD;
res += temp;
if(res >= MOD)
res -= MOD;
}
System.out.println(res);
}
static int[] cnt;
static int[] prefix;
static long[] dp;
static long[] fac, invfac;
public static long dfs(int i, int N)
{
if(i == N)
return 1L;
if(dp[i] != -1)
return dp[i];
if(prefix[i]-i <= 0)
return dp[i] = 0L;
long ways = prefix[i]-i;
return dp[i] = (ways*dfs(i+1, N))%MOD;
}
public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
{
int[] arr = new int[N];
st = new StringTokenizer(infile.readLine());
for(int i=0; i < N; i++)
arr[i] = Integer.parseInt(st.nextToken());
return arr;
}
public static long power(long x, long y, long p)
{
//0^0 = 1
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 227248bf7312ca8b872e52c572cbe2f6 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.util.*;
import java.io.*;
public class EdC {
static long[] mods = {1000000007, 998244353, 1000000009};
static long mod = mods[1];
public static MyScanner sc;
public static PrintWriter out;
static long[] fact;
public static void main(String[] havish) throws Exception{
// TODO Auto-generated method stub
sc = new MyScanner();
out = new PrintWriter(System.out);
fact = new long[21];
fact[0] = 1;
for(int j = 1;j<=20;j++){
fact[j] = fact[j-1] * j;
fact[j] %= mod;
}
int n = sc.nextInt();
int m = sc.nextInt();
int[][] grid = new int[n][m];
for(int j = 0;j<n;j++)
grid[j] = readArrayInt(m);
long ans = m;
long sum = 0;
for(int j = 0;j<m;j++){
int[] freq = new int[22];
for(int k = 0;k<n;k++)
freq[grid[k][j]] +=1;
for(int s = 20;s>=0;s--)
freq[s] += freq[s+1];
long prod = 1;
for(int s = n;s>=1;s--){
prod *= (freq[s+1] - n + s);
prod %= mod;
}
sum+=prod;
sum%=mod;
}
ans -= inv(fact[n])*sum;
ans %= mod;
ans += mod;
ans %= mod;
out.println(ans);
out.close();
}
public static long inv(long n){
return power(n, mod-2);
}
public static void sort(int[] array){
ArrayList<Integer> copy = new ArrayList<>();
for (int i : array)
copy.add(i);
Collections.sort(copy);
for(int i = 0;i<array.length;i++)
array[i] = copy.get(i);
}
static String[] readArrayString(int n){
String[] array = new String[n];
for(int j =0 ;j<n;j++)
array[j] = sc.next();
return array;
}
static int[] readArrayInt(int n){
int[] array = new int[n];
for(int j = 0;j<n;j++)
array[j] = sc.nextInt();
return array;
}
static int[] readArrayInt1(int n){
int[] array = new int[n+1];
for(int j = 1;j<=n;j++){
array[j] = sc.nextInt();
}
return array;
}
static long[] readArrayLong(int n){
long[] array = new long[n];
for(int j =0 ;j<n;j++)
array[j] = sc.nextLong();
return array;
}
static double[] readArrayDouble(int n){
double[] array = new double[n];
for(int j =0 ;j<n;j++)
array[j] = sc.nextDouble();
return array;
}
static int minIndex(int[] array){
int minValue = Integer.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static int minIndex(long[] array){
long minValue = Long.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static int minIndex(double[] array){
double minValue = Double.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static long power(long x, long y){
if (y == 0)
return 1;
if (y%2 == 1)
return (x*power(x, y-1))%mod;
return power((x*x)%mod, y/2)%mod;
}
static void verdict(boolean a){
out.println(a ? "YES" : "NO");
}
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;
}
}
}
//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | f7ba3eeb4994de9bf04054733f28f6fb | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
import java.util.*;
public class realfast implements Runnable
{
private static final int INF = (int) 1e9;
long in= 998244353;
long fac[]= new long[1000001];
long inv[]=new long[1000001];
public void solve() throws IOException
{
//int t = readInt();
int n = readInt();
int m = readInt();
int arr[][]=new int[n+1][m+1];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
arr[i][j]= readInt();
}
}
long pal = 1;
for(int i=1;i<=n;i++)
{
pal= (pal*i)%in;
}
// long gal =1;
long ans=0;
int count[]=new int[n+2];
for(int j=1;j<=m;j++)
{
for(int i=0;i<=n+1;i++)
count[i]=0;
for(int i=1;i<=n;i++)
{
count[arr[i][j]]++;
}
long cal = 1;
int sal=0;
for(int i=n+1;i>=2;i--)
{
sal =sal+count[i];
cal = (cal*sal)%in;
sal--;
if(sal<0)
sal=0;
}
ans = (ans%in+ (pal - cal+in)%in)%in;
}
ans = (ans*pow(pal,in-2,in))%in;
out.println(ans);
}
public int value (int seg[], int left , int right ,int index, int l, int r)
{
if(left>right)
{
return -100000000;
}
if(right<l||left>r)
return -100000000;
if(left>=l&&right<=r)
return seg[index];
int mid = left+(right-left)/2;
int val = value(seg,left,mid,2*index+1,l,r);
int val2 = value(seg,mid+1,right,2*index+2,l,r);
return Math.max(val,val2);
}
public int gcd(int a , int b )
{
if(a<b)
{
int t =a;
a=b;
b=t;
}
if(a%b==0)
return b ;
return gcd(b,a%b);
}
public long pow(long n , long p,long m)
{
if(p==0)
return 1;
long val = pow(n,p/2,m);;
val= (val*val)%m;
if(p%2==0)
return val;
else
return (val*n)%m;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
}
private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
private BufferedReader reader;
private StringTokenizer tokenizer;
private PrintWriter out;
@Override
public void run() {
try {
if (ONLINE_JUDGE || !new File("input.txt").exists()) {
reader = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
reader = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
solve();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
reader.close();
} catch (IOException e) {
// nothing
}
out.close();
}
}
private String readString() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
@SuppressWarnings("unused")
private int readInt() throws IOException {
return Integer.parseInt(readString());
}
@SuppressWarnings("unused")
private long readLong() throws IOException {
return Long.parseLong(readString());
}
@SuppressWarnings("unused")
private double readDouble() throws IOException {
return Double.parseDouble(readString());
}
}
class edge implements Comparable<edge>{
int u ;
int v;
edge(int u, int v)
{
this.u=u;
this.v=v;
}
public int compareTo(edge e)
{
return this.v-e.v;
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 66e44a44d621024c4f3c361e55f7ebe5 | train_110.jsonl | 1621152000 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.Monocarp's empire has $$$n$$$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monument per turn.Monocarp has $$$m$$$ points on the map he'd like to control using the constructed Monuments. For each point he knows the distance between it and each city. Monuments work in the following way: when built in some city, a Monument controls all points at distance at most $$$1$$$ to this city. Next turn, the Monument controls all points at distance at most $$$2$$$, the turn after — at distance at most $$$3$$$, and so on. Monocarp will build $$$n$$$ Monuments in $$$n$$$ turns and his empire will conquer all points that are controlled by at least one Monument.Monocarp can't figure out any strategy, so during each turn he will choose a city for a Monument randomly among all remaining cities (cities without Monuments). Monocarp wants to know how many points (among $$$m$$$ of them) he will conquer at the end of turn number $$$n$$$. Help him to calculate the expected number of conquered points! | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
static int mod=998244353;
static long fastpow(long n,long ti) {
if (ti == 0)
return 1l;
if(ti%2==0) {
long y=fastpow(n, ti/2);
long k=y*y;
k%=mod;
return k;
}
else {
long y=fastpow(n, ti/2);
long k=((n*y)%mod)*y;
k%=mod;
return k;
}
}
static long modInverse(long x) {
return fastpow(x, mod-2);
}
static void main() throws Exception{
int n=sc.nextInt(),m=sc.nextInt();
int[][]in=new int[m][n];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
in[j][i]=sc.nextInt();
}
}
long ans=0;
long[]fac=new long[n+1];
fac[0]=1;
for(int i=1;i<=n;i++)fac[i]=(fac[i-1]*i)%mod;
for(int i=0;i<m;i++) {
sort(in[i]);
long smallerNotCovering=1;
for(int j=0;j<n;j++) {
int possiblePos=(n-in[i][j]+1);
long curPerms=(fac[n-1-j]*possiblePos)%mod;
curPerms=(curPerms*smallerNotCovering)%mod;
ans=(ans+curPerms)%mod;
smallerNotCovering=(smallerNotCovering*(in[i][j]-j-1))%mod;
}
}
pw.println((ans*modInverse(fac[n]))%mod);
}
public static void main(String[] args) throws Exception{
sc=new MScanner(System.in);
pw = new PrintWriter(System.out);
int tc=1;
// tc=sc.nextInt();
for(int i=1;i<=tc;i++) {
main();
}
pw.flush();
}
static PrintWriter pw;
static MScanner sc;
static class MScanner {
StringTokenizer st;
BufferedReader br;
public MScanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public MScanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int[] intArr(int n) throws IOException {
int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
return in;
}
public long[] longArr(int n) throws IOException {
long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
return in;
}
public int[] intSortedArr(int n) throws IOException {
int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
shuffle(in);
Arrays.sort(in);
return in;
}
public long[] longSortedArr(int n) throws IOException {
long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
shuffle(in);
Arrays.sort(in);
return in;
}
public Integer[] IntegerArr(int n) throws IOException {
Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
return in;
}
public Long[] LongArr(int n) throws IOException {
Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
return in;
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
static void shuffle(int[]in) {
for(int i=0;i<in.length;i++) {
int idx=(int)(Math.random()*in.length);
int tmp=in[i];
in[i]=in[idx];
in[idx]=tmp;
}
}
static void shuffle(long[]in) {
for(int i=0;i<in.length;i++) {
int idx=(int)(Math.random()*in.length);
long tmp=in[i];
in[i]=in[idx];
in[idx]=tmp;
}
}
static void sort(int[]in) {
shuffle(in);
Arrays.sort(in);
}
static void sort(long[]in) {
shuffle(in);
Arrays.sort(in);
}
} | Java | ["3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3"] | 2 seconds | ["166374062"] | NoteLet's look at all possible orders of cities Monuments will be build in: $$$[1, 2, 3]$$$: the first city controls all points at distance at most $$$3$$$, in other words, points $$$1$$$ and $$$4$$$; the second city controls all points at distance at most $$$2$$$, or points $$$1$$$, $$$3$$$ and $$$5$$$; the third city controls all points at distance at most $$$1$$$, or point $$$1$$$. In total, $$$4$$$ points are controlled. $$$[1, 3, 2]$$$: the first city controls points $$$1$$$ and $$$4$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 1, 3]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[2, 3, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — point $$$1$$$. In total, $$$3$$$ points. $$$[3, 1, 2]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$ and $$$3$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. $$$[3, 2, 1]$$$: the first city controls point $$$1$$$; the second city — points $$$1$$$, $$$3$$$ and $$$5$$$; the third city — points $$$1$$$ and $$$5$$$. In total, $$$3$$$ points. The expected number of controlled points is $$$\frac{4 + 3 + 3 + 3 + 3 + 3}{6}$$$ $$$=$$$ $$$\frac{19}{6}$$$ or $$$19 \cdot 6^{-1}$$$ $$$\equiv$$$ $$$19 \cdot 166374059$$$ $$$\equiv$$$ $$$166374062$$$ $$$\pmod{998244353}$$$ | Java 8 | standard input | [
"combinatorics",
"dp",
"math",
"probabilities",
"two pointers"
] | 81f709b914ca1821b254f07b2464fbf2 | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 20$$$; $$$1 \le m \le 5 \cdot 10^4$$$) — the number of cities and the number of points. Next $$$n$$$ lines contains $$$m$$$ integers each: the $$$j$$$-th integer of the $$$i$$$-th line $$$d_{i, j}$$$ ($$$1 \le d_{i, j} \le n + 1$$$) is the distance between the $$$i$$$-th city and the $$$j$$$-th point. | 2,100 | It can be shown that the expected number of points Monocarp conquers at the end of the $$$n$$$-th turn can be represented as an irreducible fraction $$$\frac{x}{y}$$$. Print this fraction modulo $$$998\,244\,353$$$, i. e. value $$$x \cdot y^{-1} \bmod 998244353$$$ where $$$y^{-1}$$$ is such number that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$. | standard output | |
PASSED | 3bb299e1ca9c18ba10ca4454bdd7fe9a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class cf820b {
public static void main (String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0){
// int a=sc.nextInt();
// String str=sc.next();
// char [] ss=new char [51];
// int index=0;
// for(int i=a-1;i>=0;i--){
// if(str.charAt(i)=='0'){
// ss[index++]= (char)((str.charAt(i-2)-48)*10+str.charAt(i-1)-48 +96);
// i-=2;
// }
// else{
// ss[index++]= (char)(str.charAt(i)+48);
// }
// }
// for(int i=index-1;i>=0;i--){
// System.out.print(ss[i]);
// }
// System.out.println();
int a=sc.nextInt();
char str[] =sc.next().toCharArray();;
String ans="";
int temp;
for(int i=a-1;i>=0;i--){
if(str[i]=='0'){
temp= ( ((str[i-2])-48)*10+str[i-1]-48 +96);
i-=2;
}
else{
temp= (str[i]+48);
}
ans=(char)temp+ans;
} System.out.println(ans);
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | dfb7aeec875b2ba9b34c023ce23111df | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
// import java.util.Scanner;
import java.util.StringTokenizer;
public class cf820b1 {
static FastReader sc=null;
// static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
// static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
// static int nextInt() throws IOException {
// in.nextToken();
// return (int) in.nval;
// }
// static double nextDouble() throws IOException {
// in.nextToken();
// return in.nval;
// }
// static long nextLong() throws IOException {
// in.nextToken();
// return (long) in.nval;
// }
// static String next() throws IOException {
// in.nextToken();
// return in.sval;
// }
public static void main(String[] args)throws IOException{
sc=new FastReader();
int t=sc.nextInt();
while(t--!=0){
int a=sc.nextInt();
char str[] =sc.next().toCharArray();;
String ans="";
int temp;
for(int i=a-1;i>=0;i--){
if(str[i]=='0'){
temp= ( ((str[i-2])-48)*10+str[i-1]-48 +96);
i-=2;
}
else{
temp= (str[i]+48);
}
ans=(char)temp+ans;
} System.out.println(ans);
// for(int i=index-1;i>=0;i--){
// System.out.print(ss[i]);
// }
// System.out.println();
/////////////////////////////////////////////////////////////////////////////
// int n=sc.nextInt();
// char a[]=sc.next().toCharArray();
// String ans="";
// for(int i=n-1;i>=0;i--) {
// int to=0;
// if(a[i]=='0') {
// to+=a[i-1]-'0'+(a[i-2]-'0')*10;
// i-=2;
// }
// else {
// to=a[i]-'0';
// }
// ans=(char)(to-1+'a')+ans;
// }
// System.out.println(ans);
}
}
static int[] ruffleSort(int a[]) {
ArrayList<Integer> al=new ArrayList<>();
for(int i:a)al.add(i);
Collections.sort(al);
for(int i=0;i<a.length;i++)a[i]=al.get(i);
return a;
}
static void print(int a[]) {
for(int e:a) {
System.out.print(e+" ");
}
System.out.println();
}
static class FastReader{
StringTokenizer st=new StringTokenizer("");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
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());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
return a;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b8d81b4b7f82a277c7df553760a38c71 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
// import java.util.Scanner;
import java.util.StringTokenizer;
public class cf820b1 {
static FastReader sc=null;
// static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
// static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
// static int nextInt() throws IOException {
// in.nextToken();
// return (int) in.nval;
// }
// static double nextDouble() throws IOException {
// in.nextToken();
// return in.nval;
// }
// static long nextLong() throws IOException {
// in.nextToken();
// return (long) in.nval;
// }
// static String next() throws IOException {
// in.nextToken();
// return in.sval;
// }
public static void main(String[] args)throws IOException{
sc=new FastReader();
int t=sc.nextInt();
while(t--!=0){
int n=sc.nextInt();
char a[]=sc.next().toCharArray();
String ans="";
for(int i=n-1;i>=0;i--) {
int to=0;
if(a[i]=='0') {
to+=a[i-1]-'0'+(a[i-2]-'0')*10;
i-=2;
}
else {
to=a[i]-'0';
}
ans=(char)(to-1+'a')+ans;
}
System.out.println(ans);
}
}
static int[] ruffleSort(int a[]) {
ArrayList<Integer> al=new ArrayList<>();
for(int i:a)al.add(i);
Collections.sort(al);
for(int i=0;i<a.length;i++)a[i]=al.get(i);
return a;
}
static void print(int a[]) {
for(int e:a) {
System.out.print(e+" ");
}
System.out.println();
}
static class FastReader{
StringTokenizer st=new StringTokenizer("");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
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());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
return a;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 3c0f25695fac4b1ad696c7ee27c33298 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public final class program{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t != 0)
{
int n = s.nextInt();
String st = s.next();
char arr[] = new char[261];
arr[1] = 'a';
arr[2] = 'b';
arr[3] = 'c';
arr[4] = 'd';
arr[5] = 'e';
arr[6] = 'f';
arr[7] = 'g';
arr[8] = 'h';
arr[9] = 'i';
int j = 100;
for(char i = 'j'; i <= 'z'; i++)
{
arr[j] = i;
j += 10;
}
String result = "";
int i = n;
while(i > 0)
{
String sub = "";
if(i-3 <= 0)
{
sub = st.substring(0,i);
if(sub.charAt(sub.length() - 1) == '0')
{
int num = Integer.parseInt(sub);
result = arr[num] + result ;
i = 0;
}
else{
int num = Integer.parseInt("" + sub.charAt(sub.length() - 1));
result = arr[num] + result ;
i--;
}
}
else {
sub = st.substring(i-3,i);
if(sub.charAt(2) == '0')
{
int num = Integer.parseInt(sub);
result = arr[num] + result ;
i = i-3;
}
else{
// String po = sub.char
int num = Integer.parseInt("" + sub.charAt(2));
result = arr[num] + result ;
i--;
}
}
}
System.out.println(result);
t--;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ff2d071b992a4b6728a630a3de3dd695 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
int i=n-1;
String res="";
while(i>=0){
if(s.charAt(i)=='0'){
int x=Integer.parseInt(s.substring(i-2,i));
res=String.valueOf((char)(96+x))+res;
i-=3;
}
else{
int x=s.charAt(i)-'0';
res=String.valueOf((char)(96+x))+res;
i-=1;
}
}
System.out.println(res);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 175ffb786572f2ea0f4f5167f2f38740 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Problem {
public static void main(String[] args)
{
Scanner scanner=new Scanner(System.in);
int t=scanner.nextInt();
String s;
for(int i=0;i<t;i++)
{
int n=scanner.nextInt();
s=scanner.next();
System.out.println(fun(s,n));
}
}
public static String fun(String s,int n)
{
String chars="";
for(int i=n-1;i>=0;i--)
{
if(s.charAt(i)!='0')
{
char temp=(char)(s.charAt(i)-'1'+'a');
chars=temp+chars;
}
else
{
char temp=(char) ((s.charAt(i-2)-'0')*10+'a'+s.charAt(i-1)-'1');
chars=temp+chars;
i-=2;
}
}
return chars;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9d1f7240c0fc9e999590d8d3533dd499 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.Scanner;
import java.util.*;
public class Decode {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int n = sc.nextInt();
String s = sc.next();
String ss = "";
for(int i =n-1; i>=0; i--){
char ch = s.charAt(i);
if(ch == '0'){
String con = "";
con = s.charAt(i-1) + con;
con = s.charAt(i-2) + con;
int cc = Integer.parseInt(con);
ss = (char)(96 + cc) + ss;
i = i-2;
continue;
}
ss = (char) (((96+ Character.getNumericValue(ch)))) + ss;
//
}
System.out.println(ss);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c5f2212950b21ccc9a963cbb4bd53852 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Elevators{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t= sc.nextInt();
while(t!=0){
int n=sc.nextInt();
String s=sc.next();
String ans="";
n=n-1;
while(n>=0){
char e=s.charAt(n);
if(e=='0'){
ans = ((char) ( 96 + Integer.parseInt(s.substring(n-2,n) )))+ ans;
n=n-3;
}else{
char ch=s.charAt(n);
ans = ((char) ( 96 + Integer.parseInt(String.valueOf(ch)) )) + ans;
n--;
}
}
System.out.println(ans);
t--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1e7b419b9f7d26d1f66a0af47de87191 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.lang.StringBuilder;
import java.io.*;
public class Poly {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int tests = Integer.parseInt(reader.readLine());
for (int i = 0; i < tests; i++) {
String waste = reader.readLine();
String s = reader.readLine();
StringBuilder s1 = new StringBuilder();
for (int j = 0; j < s.length(); j++) {
int i1 = Integer.parseInt(Character.toString(s.charAt(j)));
if (j+2 < s.length() && Integer.parseInt(Character.toString(s.charAt(j+2))) == 0) {
if (j + 3 < s.length() && Integer.parseInt(Character.toString(s.charAt(j+3))) == 0) {
s1.append((char)(96+i1));
continue;
}
int num = 10*i1 + Integer.parseInt(Character.toString(s.charAt(j+1)));
s1.append((char)(96+num));
j += 2;
}
else {
s1.append((char)(96+ i1));
}
}
System.out.println(s1.toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 8a22328e1ab6c08517d01199e3e76aa2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
int x = Integer.parseInt(br.readLine());
String in = br.readLine();
StringBuffer ans = new StringBuffer("");
for (int i = x - 1; i >= 0; i--) {
int c = Character.getNumericValue(in.charAt(i));
if (c == 0) {
int o = (10 *Character.getNumericValue(in.charAt(i- 2))) + Character.getNumericValue(in.charAt(i - 1));
ans.insert(0, (char)(96 + o));
i -= 2;
}
else {
ans.insert(0, (char)(96 + c));
}
}
System.out.println(ans.toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 4d1985c4fa106c96d4699a9bae38b0fb | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Decode_String {
static Scanner sc = new Scanner(System.in);
public static String solve(String string, int length) {
// my first solution
// String result = "";
// String buffer = "";
// for (int i = 0; i < length; i++) {
// if (string.charAt(i) == '1' || string.charAt(i) == '2') {
// if (string.charAt(i + 1) >= '0' && string.charAt(i + 2) == '0') {
// if (length - i <= 3 || (length - i > 3 && string.charAt(i + 3) != '0')) {
// buffer = String.valueOf(string.charAt(i)) + String.valueOf(string.charAt(i + 1));
// result += (char) (Integer.parseInt(buffer) + 96);
// i += 2;
// continue;
// }
// else{
// buffer = String.valueOf(string.charAt(i));
// result += (char) (Integer.parseInt(buffer) + 96);
// }
// } else {
// buffer = String.valueOf(string.charAt(i));
// result += (char) (Integer.parseInt(buffer) + 96);
// }
// } else {
// buffer = String.valueOf(string.charAt(i));
// result += (char) (Integer.parseInt(buffer) + 96);
// }
// }
// return result;
String result = "";
for (int i = length - 1; i >= 0; i--) {
if (string.charAt(i) != '0') {
result += (char) (Integer.parseInt(String.valueOf(string.charAt(i))) + 96);
}
if (string.charAt(i) == '0' && i >= 2) {
result += (char) (Integer.parseInt(String.valueOf(string.charAt(i - 1))) + Integer.parseInt(String.valueOf(string.charAt(i - 2))) *10 + 96);
i -= 2;
}
}
StringBuilder buffer = new StringBuilder(result);
return buffer.reverse().toString();
}
public static void main(String[] args) {
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int length = sc.nextInt();
sc.nextLine();
String string = sc.nextLine();
System.out.println(solve(string, length));
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | d45dd33a62784e2180bc4e48476458d1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
public class Question2{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0){
int n = Integer.parseInt(br.readLine());
char[] s = br.readLine().toCharArray();
int i = s.length-1;
StringBuffer ans = new StringBuffer("");
while(i >= 0){
if(s[i] == '0'){
int val = Integer.parseInt(s[i-2]+""+s[i-1]);
ans.insert(0,(char)('a'+(val-1)));
i -= 3;
}else{
int val = Integer.parseInt(s[i]+"");
ans.insert(0,(char)('a'+(val-1)));
i -= 1;
}
}
System.out.println(ans.toString());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | df972553bc2bde04ae9cd3c4daa4d962 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class test {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
ArrayList<String> ans = new ArrayList<>(m);
while (m-- != 0) {
int length = sc.nextInt();
sc.nextLine();
String line = sc.nextLine();
String answer = "";
for (int i = 0; i < length;) {
if (i + 3 <= length - 1) {
if (line.charAt(i + 2) == '0') {
if (line.charAt(i + 3) == '0') {
Character n = (char) (((int) (line.charAt(i))) + 48);
answer += n;
n = (char) (Integer.parseInt(line.substring(i + 1, i + 3)) + 96);
answer += n;
i += 4;
} else {
Character n = (char) (Integer.parseInt(line.substring(i, i + 2)) + 96);
answer += n;
i += 3;
}
} else {
Character n = (char) (((int) (line.charAt(i))) + 48);
answer += n;
i++;
}
} else {
if ((i + 2 <= length - 1) && (line.charAt(i + 2) == '0')) {
Character n = (char) (Integer.parseInt(line.substring(i, i + 2)) + 96);
answer += n;
i++;
break;
} else {
Character n = (char) (((int) (line.charAt(i))) + 48);
answer += n;
i++;
if (i <= length - 1) {
n = (char) (((int) (line.charAt(i))) + 48);
answer += n;
i++;
}
if (i <= length - 1) {
n = (char) (((int) (line.charAt(i))) + 48);
answer += n;
}
break;
}
}
}
ans.add(answer);
}
for (String key : ans) {
System.out.println(key);
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 608743b8e9aaca860d89cc5a863235f5 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Q12 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
char[] ch1 = "abcdefghijklmnopqrstuvwxyz".toCharArray();
while(n!=0){
String w="";
int a=sc.nextInt();
String s=sc.next();
int i=s.length()-1;
while(i>=0){
if(s.charAt(i)=='0')
{
if(i-2<0){
int temp=Integer.parseInt(s.substring(0,i));
w=ch1[temp-1]+w;
i=-1;
continue;
}
int temp=Integer.parseInt(s.substring(i-2,i));
w=ch1[temp-1]+w;
i=i-3;
}
else{
w=ch1[(s.charAt(i)-'0')-1]+w;
i=i-1;
}
}
System.out.println(w);
w="";
n=n-1;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e40e13e13f955a513d335b3da22972b0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class CodeForces
{
public static StringBuilder sb=new StringBuilder();
public static void main(String[] args) {
//StringBuilder sb=new StringBuilder();
Scanner scn=new Scanner(System.in);
int t=scn.nextInt();
while(t-->0)
{
int num=scn.nextInt();
String str=scn.next();
StringBuilder ans=new StringBuilder();
for(int i=str.length()-1;i>=0;i--)
{
char ch=str.charAt(i);
if(ch=='0')
{
int d1=str.charAt(i-2)-'0';
int d2=str.charAt(i-1)-'0';
int dig=d1*10+d2;
i=i-2;
char c=(char)(dig+96);
ans.insert(0, c);
}
else
{
int dig=ch-'0';
char c=(char)(dig+96);
ans.insert(0, c);
}
}
sb.append(ans+"\n");
}
System.out.print(sb);
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | edc68942b9d8d9941a79527db54d059a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class DecodeString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
for (int j = 0; j < q; j++) {
int n = sc.nextInt();
String t = sc.next();
char[] code = t.toCharArray();
String a = "";
char ascii;
if (!(t.contains("100") || t.contains("200"))) {
for (int i = 0; i < n; i++) {
if (code[i] == '0') {
ascii = (char) ((((int) (code[i - 2]) - 48) * 10) + ((int) (code[i - 1]) - 49) + 97);
a = a.substring(0, a.length() - 2);
} else {
ascii = (char) ((int) (code[i]) + 97 - 49);
}
a = a.concat(String.valueOf(ascii));
}
} else {
for (int i = 0; i < n; i++) {
if (code[i] == '0' && i != n - 1 && code[i + 1] == '0' && code[i - 1] == '1') {
ascii = 'j';
i++;
a = a.substring(0, a.length() - 1);
} else if (code[i] == '0' && i != n - 1 && code[i + 1] == '0' && code[i - 1] == '2') {
ascii = 't';
i++;
a = a.substring(0, a.length() - 1);
} else if (code[i] == '0') {
ascii = (char) ((((int) (code[i - 2]) - 48) * 10) + ((int) (code[i - 1]) - 49) + 97);
a = a.substring(0, a.length() - 2);
} else {
ascii = (char) ((int) (code[i]) + 97 - 49);
}
a = a.concat(String.valueOf(ascii));
}
}
System.out.println(a);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | aa316d5fcc56877572a33cb83670b193 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.HashMap;
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
public static HashMap<String, String> charMap = new HashMap<>();
static {
for(int i = 97; i <= 122; i++){
int index = i - 96;
String character = ((char) i) + "";
if(index >= 10)
charMap.put(index + "0", character);
else
charMap.put(index + "", character);
}
}
static String[] datas;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
datas = new String[cases];
boolean a = true;
int index = 0;
for(int i = 0; index < cases; i++){
if(!a){
String code = scanner.next();
datas[index] = parse(code);
index++;
}else{
int length = scanner.nextInt();
}
a = !a;
}
for(String data : datas){
System.out.println(data);
}
}
public static String parse(String input){
StringBuilder builder = new StringBuilder();
String[] splittedChars = input.split("");
for(int j = splittedChars.length - 1; j >= 0; j--){
String currentChar = splittedChars[j];
if(currentChar.equals("0")){
if(j - 2 >= 0){
String id = splittedChars[j - 2] + splittedChars[j - 1] + "0";
String character = charMap.get(id);
builder.append(character);
j -= 2;
}else{
break;
}
}else{
builder.append(charMap.get(currentChar));
}
}
builder.reverse();
return builder.toString();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ff00818769f7d07136d61a256d582abe | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.HashMap;
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
public static HashMap<String, String> charMap = new HashMap<>();
static {
for(int i = 97; i <= 122; i++){
int index = i - 96;
String character = ((char) i) + "";
if(index >= 10)
charMap.put(index + "0", character);
else
charMap.put(index + "", character);
}
}
static Pair<String, String>[] datas;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
datas = new Pair[cases];
boolean a = true;
int index = 0;
for(int i = 0; index < cases; i++){
if(a){
int length = scanner.nextInt();
Pair<String, String> data = new Pair<>(length + "", null);
datas[index] = data;
}else{
String code = scanner.next();
String parsedString = parse(code);
Pair<String, String> data = datas[index];
data.setRight(parsedString);
index++;
}
a = !a;
}
for(Pair<String, String> data : datas){
System.out.println(data.getRight());
}
}
public static String parse(String input){
StringBuilder builder = new StringBuilder();
String[] splittedChars = input.split("");
for(int j = splittedChars.length - 1; j >= 0; j--){
String currentChar = splittedChars[j];
if(currentChar.equals("0")){
if(j - 2 >= 0){
String id = splittedChars[j - 2] + splittedChars[j - 1] + "0";
String character = charMap.get(id);
builder.append(character);
j -= 2;
}else{
break;
}
}else{
builder.append(charMap.get(currentChar));
}
}
builder.reverse();
return builder.toString();
}
public static class Pair<L, R> {
private L left;
private R right;
public Pair(L left, R right){
this.left = left;
this.right = right;
}
public L getLeft() {return this.left;}
public R getRight() {return this.right;}
public void setRight(R right){this.right = right;}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 5da811f1b77d3ca50f8b3283171c9c66 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package com.codeforces.div3.round820;
import java.util.Scanner;
/**
* https://codeforces.com/contest/1729/problem/B
*/
public class B {
private static final String[] ALPHABET = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
public static void main(String[] args) {
var scanner = new Scanner(System.in);
var numOfCases = scanner.nextLong();
while (numOfCases >= 1) {
final var strLength = scanner.nextLong();
final var str = scanner.next();
System.out.println(decode(str));
numOfCases--;
}
}
private static String decode(String str) {
final var res = new StringBuilder();
int i = str.length() - 1;
while (i >= 0) {
final var currNum = Integer.parseInt(str.charAt(i) + "");
if (currNum == 0) {
int num = Integer.parseInt(Integer.parseInt(str.charAt(i - 2) + "") + "" + Integer.parseInt(str.charAt(i - 1) + ""));
res.append(ALPHABET[num - 1]);
i -= 3;
} else {
res.append(ALPHABET[currNum - 1]);
i--;
}
}
return res.reverse().toString();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 71495e1d531ee6199963af2e8e7ddb1f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.lang.*;
public class Trial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String[] arr = new String[n];
for(int i = 0; i < n; i++)
{
//converts integer input
int len = sc.nextInt(); //also acts a while loop break variable
sc.nextLine();
String str = sc.nextLine();
// to store the numbers
String store;
String ans = "";
char rem = ' ';
while(len > 0)
{
store = ""; //resetting store string
rem = str.charAt(len - 1);
if(rem == '0')
{
store += str.substring(len - 3, len - 1);
int final_store = Integer.parseInt(store); //converts the store string into a proper 2 digit no.
char c = (char) (final_store + 'a' - 1); //converting the no. to char
ans += c; //concatenating char
str = str.substring(0, len - 3); //removing 4 whole chars, see explanation in drive with eg. (DecodeString.jpeg)
len -= 3;
}
else{
len--;
str = str.substring(0, len);
//same step as above except no '0' to remove
int final_store = rem - '1' + 'a';
ans += (char) final_store;
}
}
//created to quickly reverse the string
StringBuilder Answer = new StringBuilder();
Answer.append(ans);//appends the string
Answer = Answer.reverse();//reversing
arr[i] = Answer.toString();
}
for(int i = 0; i < n; i++)
{
System.out.println(arr[i]);
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 545428268ccba2e06fe95d42c169f8ec | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String[] args){
Scanner in = new Scanner(System.in);
int q = in.nextInt(); in.nextLine();
for (int j = 0; j < q; j++) {
String n = in.nextLine();
String t = in.nextLine();
char[] T = t.toCharArray();
String snA = "";
for (int i = t.length() - 1; i >= 0; i--) {
if (!(String.valueOf(T[i]).equals("0"))) {
snA += bukva(String.valueOf(T[i]));
} else {
snA += bukva(String.valueOf(T[i - 2]) + String.valueOf(T[i - 1]));
i = i - 2;
}
}
System.out.println(reverseString(snA));
}
}
public static String bukva (String c){
return switch (c) {
case "1" -> "a"; case "2" -> "b"; case "3" -> "c"; case "4" -> "d";
case "5" -> "e"; case "6" -> "f"; case "7" -> "g"; case "8" -> "h";
case "9" -> "i"; case "10" -> "j"; case "11" -> "k"; case "12" -> "l";
case "13" -> "m"; case "14" -> "n"; case "15" -> "o"; case "16" -> "p";
case "17" -> "q"; case "18" -> "r"; case "19" -> "s"; case "20" -> "t";
case "21" -> "u"; case "22" -> "v"; case "23" -> "w"; case "24" -> "x";
case "25" -> "y"; case "26" -> "z"; default -> "0";
};
}
public static String reverseString(String str) {
return new StringBuilder(str).reverse().toString();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f97cf34a593e7528466006008adcd456 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class MainTwo {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
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());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
// to read an array from input
int[] nextIntArray() {
return Arrays.stream(nextLine().split("\\s")).mapToInt(i -> Integer.parseInt(i)).toArray();
}
long[] nextLongArray() {
return Arrays.stream(nextLine().split("\\s")).mapToLong(i -> Long.parseLong(i)).toArray();
}
double[] nextDoubleArray() {
return Arrays.stream(nextLine().split("\\s")).mapToDouble(i -> Double.parseDouble(i)).toArray();
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
static String reverse(String s){
String temp = "";
for(int i = s.length()-1; i >= 0; i--){
temp += ""+s.charAt(i);
}
return temp;
}
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int testCases = in.nextInt();
while (testCases-- > 0) {
// write code here
int leng = in.nextInt();
String s = in.next();
String ans = "";
for(int i = s.length()-1; i >= 0; i--){
int ascii = 96;
if(s.charAt(i) != '0'){
ascii += Integer.parseInt(""+s.charAt(i));
ans += ""+(char)ascii;
}
else{
ascii += Integer.parseInt(""+s.charAt(i-2)+s.charAt(i-1));
ans += ""+(char)ascii;
i -= 2;
}
}
ans = reverse(ans);
out.println(ans);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
// return;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a69f414ac5aae0fd5222113c24c01612 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* @author Nikolay Chistykov
*/
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
while (n-- > 0) {
int t = sc.nextInt();
String s = sc.next();
StringBuilder str = new StringBuilder();
for (int i = s.length() - 1; i >= 0; i--) {
if (s.charAt(i)=='0') {
str.append((char) (96 + Integer.parseInt(String.valueOf(s.charAt(i-2)) +
String.valueOf(s.charAt(i -1)))));
i -= 2;
} else {
str.append((char) (96 + Integer.parseInt(String.valueOf(s.charAt(i)))));
}
}
System.out.println(str.reverse());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 48976f97c303b5879392ee6e6b20949f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | 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 Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
int t;
t=sc.nextInt();
first:
while(t-->0)
{
int res,fill,place;
int x=sc.nextInt();
String st =sc.next();
char ch[]=st.toCharArray();
ArrayList <Character> arr=new ArrayList<>();
StringBuilder temp=new StringBuilder();
for(int i=st.length()-1;i>=0;i--)
{
if(ch[i]=='0')
{
int a=ch[i-2]-'0';
int b=ch[i-1]-'0';
i=i-2;
temp.append((char)(96+a*10+b));
}
else
{
int a=ch[i]-'0';
temp.append((char)(96+a));
}
}
temp.reverse();
System.out.println(temp);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1eba08a4e7e1e067a9e338e6c344d871 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class index {
public static String reverse(String str) {
return new StringBuilder(str).reverse().toString();
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while( t != 0 ){
int n = input.nextInt();
String s = input.next();
int[] arr = new int[ n + 1 ];
for( int i = 0; i < n; i++ ){
arr[ i ] = Integer.parseInt(String.valueOf(s.charAt( i )));
}
String s1 = "";
for( int i = n-1; i >= 0; i-- ){
if( arr[ i ] == 0 ){
s1 += (char)(arr[ i - 1 ] + arr[ i - 2 ] * 10 + 96);
i -= 2;
} else{
s1 += (char)(arr[i] + 96);
}
}
s1 = reverse(s1);
System.out.println(s1);
t--;
}
input.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 6b0e9151ebe76d8723ed3039379b4bd7 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 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 t=Integer.parseInt(br.readLine());
for(int i=0;i<t;i++)
{
int size=Integer.parseInt(br.readLine());
String n =br.readLine();
int rem,rem1;
String s="";
for(int j=size-1;j>=0;j--)
{
rem=(n.charAt(j))-'0';
if(rem!=0)
{
s = (char)(rem+96)+s;
}
else if(rem==0)
{
rem1=(n.charAt(j-2)-'0')*10+n.charAt(j-1)-'0';
s = (char)(rem1+96)+s;
--j;
--j;
}
}
System.out.println(s);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 17d406d0f65766b5981ede96aa409fed | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.lang.System.*;
public class DecodeString implements Runnable {
private final void process() throws IOException {
// InputReader input = new InputReader(new FileReader(System.getenv("INPUT")));
// PrintWriter output = new PrintWriter(new BufferedOutputStream(new FileOutputStream(System.getenv("OUTPUT"))));
InputReader input = new InputReader(in);
PrintWriter output = new PrintWriter(new BufferedOutputStream(out));
char[] chars = new char[26];
for (char ch = 'a'; ch <= 'z'; ch++) {
chars[ch - 'a'] = ch;
}
int test = input.nextInt();
while (test-- > 0) {
int n = input.nextInt();
String strT = input.nextLine();
StringBuilder res = new StringBuilder();
for (int i = 0; i < n; i++) {
int val;
if (i + 3 < n && strT.charAt(i + 3) == '0') {
val = strT.charAt(i) - '0';
} else if (i + 2 < n && strT.charAt(i + 2) == '0' && Integer.parseInt(strT.substring(i, i + 2)) <= 26) {
val = Integer.parseInt(strT.substring(i, i + 2));
i += 2;
} else {
val = strT.charAt(i) - '0';
}
res.append(chars[val - 1]);
}
output.println(res);
}
input.close();
output.close();
}
@Override
public void run() {
try {
process();
} catch (IOException ignored) {}
}
public static void main(String... args) throws IOException {
new Thread(null, new DecodeString(), "Main", 1 << 26).start();
}
private final void printArr(PrintWriter output, short...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, int...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, double...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, long...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, char...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
private final void printArr(PrintWriter output, String...arr) {
output.println(Arrays.toString(arr).replaceAll("\\[|]|, ", " ").trim());
}
}
class InputReader {
private StringTokenizer token;
private BufferedReader buffer;
public InputReader(InputStream stream) {
buffer = new BufferedReader(new InputStreamReader(stream));
}
public InputReader(FileReader reader) throws FileNotFoundException {
buffer = new BufferedReader(reader);
}
public final String next() throws IOException {
while (token == null || !token.hasMoreTokens())
token = new StringTokenizer(buffer.readLine());
return token.nextToken();
}
public final String nextLine() throws IOException {
return buffer.readLine();
}
public final byte nextByte() throws IOException {
return Byte.parseByte(next());
}
public final short nextShort() throws IOException {
return Short.parseShort(next());
}
public final int nextInt() throws IOException {
return Integer.parseInt(next());
}
public final long nextLong() throws IOException {
return Long.parseLong(next());
}
public final double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public final char nextChar() throws IOException {
return next().charAt(0);
}
public final boolean nextBoolean() throws IOException {
return Boolean.parseBoolean(next());
// return Boolean.getBoolean(next());
// return Boolean.valueOf(next());
}
public int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
public int[] readIntArray() throws IOException {
return java.util.Arrays.stream(nextLine().split("\\s+")).
mapToInt(Integer::parseInt).toArray();
}
public long[] readLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = nextLong();
return arr;
}
public long[] readLongArray() throws IOException {
return java.util.Arrays.stream(nextLine().split("\\s+")).
mapToLong(Long::parseLong).toArray();
}
public double[] readDoubleArray(int n) throws IOException {
double[] arr = new double[n];
for (int i = 0; i < n; i++)
arr[i] = nextDouble();
return arr;
}
public double[] readDoubleArray() throws IOException {
return java.util.Arrays.stream(nextLine().split("\\s+")).
mapToDouble(Double::parseDouble).toArray();
}
public char[] readCharArray() throws IOException {
return nextLine().toCharArray();
}
public String[] readStringArray(int n) throws IOException {
String[] arr = new String[n];
for (int i = 0; i < n; i++)
arr[i] = next();
return arr;
}
public String[] readStringArray() throws IOException {
return nextLine().split("\\s+");
}
public boolean ready() throws IOException {
return buffer.ready();
}
public void close() throws IOException {
buffer.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 26e74fb91c3866ef521c4d4ee6013e9a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t > 0) {
t--;
int n = scanner.nextInt();
String s = scanner.next();
System.out.println(decoding(s));
}
}
public static String decoding(String s) {
String line = ".abcdefghijklmnopqrstuvwxyz";
int n = s.length() - 1;
String ans = "";
while (n >= 0) {
if (Character.getNumericValue(s.charAt(n)) == 0) {
ans = line.charAt(Integer.valueOf(s.substring(n - 2, n))) + ans;
n = n - 3;
} else {
ans = line.charAt(Character.getNumericValue(s.charAt(n))) + ans;
n = n - 1;
}
}
return ans;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | e03932bca0cf0a1dae6ad9a2a2a6dd4f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public final class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t = 1; t<=T; t++){
int n = sc.nextInt(); //no. of digits in string-code
String code = sc.next();
char[] arr = code.toCharArray();
StringBuilder str = new StringBuilder();
for(int i = n-1; i>=0; i--){
int ascii = 0;
if(arr[i] == '0'){
ascii = (arr[i-2]-'0')*10;
ascii += arr[i-1]-'0';
i-=2;
} else {
ascii = arr[i]-'0';
}
char c = (char) (96+ascii);
str.append(c);
}
str = str.reverse();
String ans = str.toString();
System.out.println(ans);
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | aceddd1d295247c2e7c29371ee8a0cb1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static boolean issorted(int []arr){
for(int i = 1;i<arr.length;i++){
if(arr[i]<arr[i-1]){
return false;
}
}
return true;
}
public static long sum(int []arr){
long sum = 0;
for(int i = 0;i<arr.length;i++){
sum+=arr[i];
}
return sum;
}
public static class pair implements Comparable<pair>{
int x;
int y;
pair(int x,int y){
this.x = x;
this.y = y;
}
public int compareTo(pair o){
return this.x - o.x; // sort increasingly on the basis of x
// return o.x - this.x // sort decreasingly on the basis of x
}
}
public static void swap(int []arr,int i,int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static int gcd(int a, int b){
if (b == 0)
return a;
return gcd(b, a % b);
}
static int []parent = new int[1000];
static int []size = new int[1000];
public static void make(int v){
parent[v] = v;
size[v] = 1;
}
public static int find(int v){
if(parent[v]==v){
return v;
}
else{
return parent[v] = find(parent[v]);
}
}
public static void union(int a,int b){
a = find(a);
b = find(b);
if(a!=b){
if(size[a]>size[b]){
parent[b] = parent[a];
size[b]+=size[a];
}
else{
parent[a] = parent[b];
size[a]+=size[b];
}
}
}
static boolean []visited = new boolean[1000];
public static void dfs(int vertex,ArrayList<ArrayList<Integer>>graph){
if(visited[vertex] == true){
return;
}
System.out.println(vertex);
for(int child : graph.get(vertex)){
// work to be done before entering the child
dfs(child,graph);
// work to be done after exitting the child
}
}
public static void displayint(int []arr){
for(int i = 0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
System.out.println();
}
public static void displaystr(String str){
StringBuilder sb = new StringBuilder(str);
for(int i = 0;i<sb.length();i++){
System.out.print(sb.charAt(i));
}
System.out.println();
}
public static boolean checkbalanceparenthesis(StringBuilder ans){
Stack<Character>st = new Stack<>();
int i = 0;
while(i<ans.length()){
if(ans.charAt(i) == '('){
st.push('(');
}
else{
if(st.size() == 0 || st.peek()!='('){
return false;
}
else{
st.pop();
}
}
}
return st.size() == 0;
}
public static long binaryExp(long a,long b,long m){ /// This is Iterative Version
long res = 1;
while(b>0){
if((b&1)!=0){
res = (res*a)%m;
}
b>>=1;
a = (a*a)%m;
}
return res;
}
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-->0){
int n = scn.nextInt();
String str = scn.next();
StringBuilder sb = new StringBuilder("");
HashMap<Integer,Character>map = new HashMap<>();
int j = 1;
for(char ch = 'a';ch<='z';ch++){
map.put(j,ch);
j++;
}
int i = 0;
while(i<n){
if(str.charAt(i)=='1'){
if(i+2<n){
if(str.charAt(i+2)=='0'){
if(i+2==n-1){
int val = Integer.parseInt(str.substring(i,i+2));
sb.append(map.get(val));
i = i+3;
}
else{
char ch = str.charAt(i+3);
if(ch == '0'){
sb.append('a');
i++;
}
else{
int val = Integer.parseInt(str.substring(i,i+2));
sb.append(map.get(val));
i = i+3;
}
}
}
else{
sb.append('a');
i++;
}
}
else{
sb.append('a');
i++;
}
}
else if(str.charAt(i)=='2'){
if(i+2<n){
if(str.charAt(i+2)=='0'){
if((i+2)==n-1){
int val = Integer.parseInt(str.substring(i,i+2));
sb.append(map.get(val));
i = i+3;
}
else{
char ch = str.charAt(i+3);
if(ch == '0'){
sb.append('b');
i++;
}
else{
int val = Integer.parseInt(str.substring(i,i+2));
sb.append(map.get(val));
i = i+3;
}
}
}
else{
sb.append('b');
i++;
}
}
else{
sb.append('b');
i++;
}
}
else{
sb.append(map.get(Integer.parseInt(str.substring(i,i+1))));
i++;
}
}
System.out.println(sb);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1b5093024366bf490464e44d2579386f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class DecodeString {
public static void main(String[] args) {
int q, aux, d, u, con;
String cad, res;
Scanner scanner = new Scanner(System.in);
q = Integer.parseInt(scanner.nextLine());
for(int i=0;i<q;i++)
{
aux = Integer.parseInt(scanner.nextLine());
cad = scanner.nextLine();
con=0;
res="";
for(int j=0;j<aux-2;j++) {
//System.out.println("j = " + j);
d = Integer.parseInt(cad.substring(j, j + 3));
//System.out.println("d = " + d);
u = d % 10;
boolean flag=true;
if(j+3<aux)
{
if(Integer.parseInt(cad.substring(j+3, j + 4))==0)
flag=false;
}
if (u == 0 && flag) {
res = res.concat(Character.toString((char) (d / 10 + 96)));
j += 2;
} else {
res = res.concat(Character.toString((char) (d / 100 + 96)));
}
con = j+1;
}
for(con=con; con<aux;con++){
d= Integer.parseInt(cad.substring(con,con+1));
res=res.concat(Character.toString((char)(d+96)));
}
System.out.println(res);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a19c511dc0b8f38aa96ba45d735bf150 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static FastReader s = new FastReader();
public static void solve(){
int n = s.nextInt();
String str = s.next();
// int[] arr = new int[n];
StringBuilder b = new StringBuilder();
// Read Array
// for(int i=0;i<n;i++){
// arr[i] = s.nextInt();
// }
for(int i = 0; i<str.length(); i++){
int ch = str.charAt(i) - '0';
if(str.charAt(i) != '0')
b.append((char)('a' + ch - 1));
else{
if(i != str.length() -1 && str.charAt(i+1) == '0'){
continue;
} else {
if(str.charAt(i-1) != '0')
b.deleteCharAt(b.length() - 1);
b.deleteCharAt(b.length() - 1);
b.append((char)('a'+(Integer.parseInt(str.substring(i-2, i)) - 1)));
}
}
}
System.out.println(b);
}
public static void main(String[] args) {
int t = s.nextInt();
while (t-- > 0) {
solve();
}
}
public static void printArray(int[] arr){
System.out.println(Arrays.toString(arr));
}
}
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 {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b4dc57119e62323fca45b6f0c66a60e1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class problemB {
public static void main(String[] args) {
Scanner sh = new Scanner(System.in);
int t = sh.nextInt();
while(t>0){
int n = sh.nextInt();
sh.nextLine();
String s = sh.nextLine();
StringBuilder sb = new StringBuilder();
int x = s.length()-1;
while(x>=0){
if(s.charAt(x)=='0'){
x = x-2;
int temp = Integer.valueOf(s.substring(x, x+2));
char c = (char)('a'+temp-1);
sb.insert(0, c);
x--;
}else{
int temp = Integer.valueOf(s.substring(x, x+1));
char c = (char)('a'+temp-1);
sb.insert(0,c);
x--;
}
}
System.out.println(sb.toString());
t--;}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1ef3d10599a9bfcc54c9acbd0fb8a91a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class test {
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
int x= sc.nextInt();
for(int i=0;i<x;i++){
int y= sc.nextInt();
String m= sc.next();
String code="";
for(int j=m.length()-1;j>=0;j--){
char a=' ';
if(m.charAt(j)=='0'){
if(j>=2){
int n=(int)(m.charAt(j-1)-'0');
int n1=(int)(m.charAt(j-2)-'0');
j-=2;
a=(char)('a'-1+n+(n1*10));}
else {
int n1=(int)(m.charAt(j-1)-'0');
j--;
a=(char)('a'-1+(n1*10));}
}
else{
int n=(int)(m.charAt(j)-'0');
a=(char)('a'-1+n);
}
code=a+""+code;
}
System.out.println(code);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1a80045368be1747485e88547146f2c0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class test {
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
int x= sc.nextInt();
for(int i=0;i<x;i++){
int y= sc.nextInt();
String m= sc.next();
String code="";
for(int j=m.length()-1;j>=0;j--){
char a=' ';
if(m.charAt(j)=='0'){
int n=(int)(m.charAt(j-1)-'0');
int n1=(int)(m.charAt(j-2)-'0');
j-=2;
a=(char)('a'-1+n+(n1*10));
}
else{
int n=(int)(m.charAt(j)-'0');
a=(char)('a'-1+n);
}
code=a+""+code;
}
System.out.println(code);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 30aae54034815be040183fbd5373a2a0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class decodeString {
public static void p(Object o) { System.out.println(o); }
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
while (testCases --> 0) {
int length = sc.nextInt();
char [] code = sc.next().toCharArray();
StringBuilder ans = new StringBuilder();
for (int i = code.length-1; i >= 0; i--) {
if (code[i] == '0' && code[i - 1] != '0' && code[i-2] == '2') {
switch (code[i-1]) {
case '1' -> ans.append('u');
case '2' -> ans.append('v');
case '3' -> ans.append('w');
case '4' -> ans.append('x');
case '5' -> ans.append('y');
case '6' -> ans.append('z');
}
i -= 2;
} else if (code[i] == '0' && code[i - 1] != '0' && code[i-2] == '1') {
switch (code[i-1]) {
case '1' -> ans.append('k');
case '2' -> ans.append('l');
case '3' -> ans.append('m');
case '4' -> ans.append('n');
case '5' -> ans.append('o');
case '6' -> ans.append('p');
case '7' -> ans.append('q');
case '8' -> ans.append('r');
case '9' -> ans.append('s');
}
i -= 2;
} else if (code[i] == '0' && code[i - 1] == '0' && code[i-2] == '2') {
ans.append('t');
i -= 2;
}else if (code[i] == '0' && code[i - 1] == '0' && code[i-2] == '1') {
ans.append('j');
i -= 2;
} else {
switch (code[i]) {
case '1' -> ans.append('a');
case '2' -> ans.append('b');
case '3' -> ans.append('c');
case '4' -> ans.append('d');
case '5' -> ans.append('e');
case '6' -> ans.append('f');
case '7' -> ans.append('g');
case '8' -> ans.append('h');
case '9' -> ans.append('i');
}
}
}
p(ans.reverse());
//FEAR THE MASSIVE WALL OF TEXT
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | af633a491d84e4f3183986805d29857f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0)
{
ArrayList<Integer> arr = new ArrayList<Integer>();
int l = sc.nextInt();
String s = sc.next();
for(int i=s.length()-1;i>=0;--i)
{
if(s.charAt(i)=='0')
{
arr.add((((int)s.charAt(i-2)-48)*10)+((int)s.charAt(i-1)-48));
i-=2;
}
else
arr.add((int)s.charAt(i)-48);
}
String q="";
for (int i=arr.size()-1;i>=0;--i)
{
q=q+(char)(96+arr.get(i));
}
System.out.println(q);
--t;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9e4c16bcb64969caec881f29d6398732 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class DecodeString {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
while(t!=0){
int n=input.nextInt(); //(((int)c1-48)*10)+((int)c2-48)
String s=input.next(),x="";
char m='0',y='0';
while(n!=0){
if(s.charAt(s.length()-1)=='0'){
s=s.substring(0,s.length()-1);
m=s.charAt(s.length()-2);
y=s.charAt(s.length()-1);
x=(char)( (((int)m-48)*10)+((int)y-48) +96)+x;
s=s.substring(0,s.length()-2);
n-=3;
}else{
m=s.charAt(s.length()-1);
x=(char)(((int)m-48)+96)+x;
s=s.substring(0,s.length()-1);
n--;
}
}System.out.println(x);
t--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0672350d25f9688787754a8b34a90660 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 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 t = scan.nextInt();
for (int i = 0; i < t; i++) {
int n = scan.nextInt();
scan.nextLine();
String s = scan.nextLine();
StringBuilder ans = new StringBuilder();
int j = n - 1;
while (j >= 0) {
if (s.charAt(j) == '0') {
if (j - 2 >= 0) {
int c = (s.charAt(j - 2) - '0') * 10 + (s.charAt(j - 1) - '0');
ans.append((char)(c + 'a' - 1));
}
j = j - 2;
}
else
ans.append((char)(s.charAt(j) - '1' + 'a'));
j--;
}
System.out.println(ans.reverse().toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 69177e617e42149cef42f8b557cbaad1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
public class sleep {
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 {
if(st.hasMoreTokens()){
str = st.nextToken("\n");
}
else{
str = br.readLine();
}
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static PrintWriter out;
public static String alphabets = "aabcdefghijklmnopqrstuvwxyz";
public static void main (String[] args) throws java.lang.Exception {
FastReader sc = new FastReader();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String s = sc.next();
StringBuilder ans = new StringBuilder();
for(int i=0;i<n;i++){
if(i+2<n && s.charAt(i+2)=='0'){
if(i+3<n && s.charAt(i+3)=='0'){
ans.append(alphabets.charAt(Integer.parseInt(String.valueOf(s.charAt(i)))));
}else{
String ind = String.valueOf(s.charAt(i))+ s.charAt(i + 1);
i+=2;
ans.append(alphabets.charAt(Integer.parseInt(ind)));
}
}else{
ans.append(alphabets.charAt(Integer.parseInt(String.valueOf(s.charAt(i)))));
}
}
out.println(ans);
}
out.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 12794a9d911ae3bfb32ccc98bb4301ac | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class hello {
public static void main(String[] args){
Scanner innn = new Scanner(System.in);
int n = innn.nextInt();
int k = 0;
int nn = 0;
String ans = "";
String s = "";
for(int j = 0; j < n; j++){
ans = "";
nn = innn.nextInt();
s = innn.next();
for(int i = s.length() - 1; i >= 0; i--) {
if (s.charAt(i) != '0'){
k = 96 + Character.getNumericValue(s.charAt(i));
}else if (s.charAt(i) == '0'){
k = 96 + (Character.getNumericValue(s.charAt(i - 2)) * 10 + Character.getNumericValue(s.charAt(i - 1)));
i = i - 2;
}
ans = (char)k + ans;
}
System.out.println(ans);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 22453907e3d70e8acd1e90d5c21a177d | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
String currentData;
StringBuilder ans = new StringBuilder("");
String alp = "0abcdefghijklmnopqrstuvwxyz";
int len;
for (int i = 0; i < n; i++){
len =input.nextInt();
currentData = input.next();
for (int j = 0; j < len; j++){
if(j+3 < len && currentData.charAt(j+2) == '0' && currentData.charAt(j+3) == '0'){
ans.append(alp.charAt((int) currentData.charAt(j) - (int)'0'));
}else if(j+2 < len && currentData.charAt(j+2) == '0'){
ans.append(alp.charAt(Integer.parseInt(currentData.substring(j, j + 2))));
j += 2;
}else{
ans.append(alp.charAt((int) currentData.charAt(j) - (int)'0'));
}
}
System.out.println(ans);
ans = new StringBuilder("");
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 13f4dc0c37d61ad4f1cdb39f9ff10e6a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Abai {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0){
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
String answer = "";
StringBuilder sb = new StringBuilder();
sb.append(s);
sb.reverse();
String q = sb.toString();
for (int i = 0; i < q.length();) {
int a = Integer.parseInt(q.substring(i,i+1));
if(a<=26 && a>0){
char c = (char)(a+96);
String temp = Character.toString(c);
answer = answer+temp;
i++;
}else if(a==0){
int b = Integer.parseInt(q.substring(i+1,i+2));
int c = Integer.parseInt(q.substring(i+2,i+3));
int d = (c*10)+b;
char w = (char)(d+96);
String z = Character.toString(w);
answer = answer +z;
i=i+3;
}
}
StringBuilder z = new StringBuilder(answer);
z.reverse();
String v = z.toString();
System.out.println(v);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f26ca5c4c9bda26a6b986d93578db871 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
public class Solution {
public static String sol(int a, String b) {
String res = "";
for (int i = b.length() - 1; i >= 0; i--) {
if (b.charAt(i) == '0') {
int x = Integer.parseInt("" + b.charAt(i - 2) + b.charAt(i - 1));
res += (char) (x + 'a' - 1);
i-=2;
} else {
res += (char) (Integer.parseInt("" + b.charAt(i)) + 'a' - 1);
}
}
StringBuilder builder = new StringBuilder(res);
return builder.reverse().toString();
}
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();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
read();
}
public static void read() {
FastScanner fastScanner = new FastScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int n = fastScanner.nextInt();
for (int i = 0; i < n; i++) {
int a;
String b;
a = fastScanner.nextInt();
b = fastScanner.next();
out.println(sol(a, b));
}
out.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | da5da52a76c22465cf489899c87183f1 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
while (x-- > 0) {
StringBuilder s = new StringBuilder();
int n = sc.nextInt();
String t = sc.next();
char[] ch = t.toCharArray();
for (int i = 0; i < n; i++) {
if (i == n - 2 || i == n - 1 || ch[i + 2] != '0')
s.append((char)(((int)ch[i]) + 97 - 48 - 1));
else {
if (i + 3 < n && ch[i + 3] == '0') {
s.append((char)(((int)ch[i]) + 97 - 48 - 1));
} else {
int a = ((int)ch[i]) - 48;
int b = ((int)ch[i + 1]) - 48;
int c = (a * 10 + b) + 97 - 1;
s.append((char)c);
if (i < n)
i += 2;
}
}
}
System.out.println(s.toString());
}
sc.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | f172ae593926ba722b5a6472db741eb3 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.math.*;
public class codeforces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long t = sc.nextInt();
while(t>0){
int n = sc.nextInt();
String s = sc.next();
String ans ="";
String cha="" ;
char[] ch = s.toCharArray();
int i=n-1;
while( i>=0){
if(ch[i]=='0') {
cha = ch[i - 2] + "" + ch[i - 1];
ans = (char) (Integer.parseInt(cha) + 96) + ans;
i = i - 3;
}
else {
cha = ch[i] +"";
ans = (char)(Integer.parseInt(cha)+96) + ans;
i = i-1;
}
}
System.out.println(ans);
t--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | d38f39f4e4c0be3a569a9c07d2aa5a0c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.Scanner;
public class pro2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int q= sc.nextInt();
while(q>0) {
int n = sc.nextInt();
String t = sc.next();
q--;
System.out.println(solve(t, n));
}
}
public static String solve(String t, int n) {
String op = "";
for(int i=n-1;i>=0;i--) {
if(t.charAt(i)=='0') {
int num = Character.getNumericValue(t.charAt(i-1)) + 10*Character.getNumericValue(t.charAt(i-2));
//System.out.println(num);
op = (char)(num+96) + op;
//op.append(char(num+96));
i=i-2;
}
else {
int num = Character.getNumericValue(t.charAt(i));
//System.out.println(num);
op = (char)(num + 96) + op;
}
}
return op;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 19808ac8c97d7d45f9367e651747b6fc | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
static ArrayList<Integer> prime = new ArrayList<>();
static long mod = 1000000007;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
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());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int t = in.nextInt();
while ( t-- > 0 ) {
int n = in.nextInt();
String s = in.next();
ArrayList<Character> ans = new ArrayList<>();
for ( int i = n-1;i>=0;--i ){
if ( s.charAt(i) == '0' ){
String ssad = s.substring(i-2,i);
int asciiValue = Integer.parseInt(ssad);
asciiValue += 96;
char convertedChar = (char)asciiValue;
ans.add(convertedChar);
i -= 2;
}else{
char ch =s.charAt(i);
int asciiValue = ch - '0';
asciiValue += 96;
char convertedChar = (char)asciiValue;
ans.add(convertedChar);
}
}
for ( int i=ans.size()-1;i>=0;--i ){
out.print(ans.get(i));
}
out.println("");
}
out.close();
} catch (Exception e) {
return;
}
}
public static long countSetBits(long n) {
long count = 0;
while (n > 0) {
count += n & 1;
n >>= 1;
}
return count;
}
public static void sortbykey(HashMap<Long, Long> map) {
TreeMap<Long, Long> sorted = new TreeMap<>();
sorted.putAll(map);
}
public static long sum(int n) {
if ( n <= 1 ) return n;
return n + sum(n - 1);
}
public static ArrayList<Long> prefix( ArrayList<Long> arr1 ) {
Collections.sort(arr1);
ArrayList<Long> arr = new ArrayList<>();
long prefix = 0;
for ( int i = 0; i < arr1.size(); ++i ) {
prefix += arr1.get(i);
arr.add(prefix);
}
return arr;
}
public static int solve(int[][] m, int n) {
int ans = 0;
int vis[][] = new int[n][n];
int di[] = {1, 0, 0, -1};
int dj[] = {0, -1, 1, 0};
if (m[0][0] == 1) mazerunner(0, 0, m, n, ans, "", vis, di, dj);
return ans;
}
public static void mazerunner(int i, int j, int m[][], int n, int ans, String move, int vis[][], int di[] , int dj[]) {
if ( i == n - 1 && j == n - 1) {
ans++;
return;
}
String dir = "DLRU";
for (int ind = 0; ind < 4; ind++) {
int nexti = i + di[ind];
int nextj = j + dj[ind];
if (nexti >= 0 && nextj >= 0 && nexti < n && nextj < n && vis[nexti][nextj] == 0 && m[nexti][nextj] == 1) {
vis[i][j] = 0;
mazerunner(nexti, nextj, m, n, ans, move + dir.charAt(ind), vis, di, dj);
vis[i][j] = -1;
}
}
}
public static long pow( long k , long n ) {
long ans = 1;
while ( n > 0 ) {
if ( n % 2 == 1 ) {
ans += (ans * k) % mod;
n--;
} else {
k = (k * k) % mod;
n /= 2;
}
}
return ans % mod;
}
public static long fact(long n ) {
long ans = 0;
for (int i = 1; i < n; ++i) {
ans += (long)i;
}
return ans;
}
public static boolean isValid( long mid, long arr[] , long k ) {
long req = 0;
for ( int i = 1; i < arr.length; ++i) {
req += Math.min( (arr[i] - arr[i - 1] ) , mid );
}
req += mid;
if ( req >= k ) return true;
return false;
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
private static void reverse( ArrayList<Long> arr , int i, int j ) {
while ( i <= j ) {
swap( arr, i, j);
i++; j--;
}
}
private static void swap( ArrayList<Long> arr , int i, int j ) {
long temp = arr.get(i);
arr.set(i, arr.get(j));
arr.set(j, temp);
}
private static boolean isPrime(long n ) {
if ( n == 1 ) return true;
for ( int i = 2; i <= Math.sqrt(n); i++) {
if ( n % i == 0 ) {
return false ;
}
}
return true;
}
private static boolean[] sieve() {
int n = 100000000;
boolean sieve[] = new boolean[n + 1];
Arrays.fill(sieve, true);
for ( int i = 2; i * i <= n; i++) {
for ( int j = i * i; j <= n; j += i) {
sieve[j] = false;
}
}
return sieve;
}
private static ArrayList<Integer> generatePrimes(int n ) {
boolean sieve[] = sieve();
for ( int i = 2; i <= n; i++) {
if ( sieve[i] == true ) {
prime.add(i);
}
}
return prime;
}
private static void segmentedSieve( int l , int r ) {
int n = (int) Math.sqrt(r);
ArrayList<Integer> pr = generatePrimes(n);
int dummy[] = new int[r - l + 1];
Arrays.fill(dummy, 1);
for ( int p : pr ) {
int firstMultiple = (l / p) * p;
if ( firstMultiple < l ) firstMultiple += p;
for ( int j = Math.max(firstMultiple, p * p); j <= r; j += p) {
dummy[j - l] = 0;
}
}
for ( int i = l; i <= r; i++) {
if ( dummy[i - l] == 1 ) {
System.out.println(i);
}
}
}
private static int[] primeFactors() {
int n = 1000000;
int prime[] = new int[n + 1];
for (int i = 1; i <= n; i++) {
prime[i] = i;
}
for (int i = 2; i * i <= n; i++) {
if ( prime[i] == i ) {
for (int j = i * i; j <= n; j += i) {
if ( prime[j] == j ) {
prime[j] = i;
}
}
}
}
return prime;
}
private static boolean isPalindrome(String s ) {
int i = 0, j = s.length() - 1;
while ( i <= j ) {
if ( s.charAt(i) != s.charAt(j) ) {
return false;
}
i++; j--;
}
return true;
}
private static long power( long a , long b ) {
long ans = 1;
while ( b > 0 ) {
if ( (b & 1) != 0 ) {
ans = binMultiply(ans, a);
}
a = binMultiply(a, a );
b >>= 1;
}
return ans;
}
private static int GCD ( int a , int b ) {
if ( b == 0) return a;
return GCD( b , a % b);
}
private static long binMultiply(long a , long b ) {
long ans = 0;
while ( b > 0 ) {
if ( (b & 1) != 0 ) {
ans = (ans + a ); // if m is given in ques than use ans = ans+a % m ;
}
a = (a + a); // if m is given in ques than use a = (a+a)%m;
b >>= 1;
}
return ans;
}
private static int binarySearch(int l , int r , int[] arr , int find ) {
int mid = l + (r - l) / 2;
if ( arr[mid] == find ) {
return mid;
} else if ( arr[mid] > find ) {
return binarySearch(l, mid - 1, arr, find);
}
return binarySearch(mid + 1, r, arr, find);
}
private static int upper_bound(ArrayList<Long> arr , long element ) {
int l = 0 ;
int h = arr.size() - 1;
int mid = 0;
while ( h - l > 1 ) {
mid = (h + l) / 2;
if ( arr.get(mid) <= element ) {
l = mid + 1;
} else {
h = mid ;
}
}
if ( arr.get(l) > element ) return l;
if ( arr.get(h) > element ) return h;
return -1;
}
private static int lower_bound(ArrayList<Integer> arr , int element ) {
int l = 0 ;
int h = arr.size() - 1;
int mid = 0;
while ( h - l > 1 ) {
mid = (h - l) / 2;
if ( arr.get(mid) < element ) {
l = mid + 1;
} else {
h = mid ;
}
}
if ( arr.get(l) >= element ) return l;
if ( arr.get(h) >= element ) return h;
return -1;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | ffdbff1c183acda3a54c27b8531815d2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class decodeString {
public static PrintWriter pw = new PrintWriter(System.out);
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 main(String[] args) {
FastReader sc = new FastReader();
// english alphabet array
char[] arr = new char[26];
for (int i = 0; i < 26; i++) {
arr[i] = (char) (i + 97);
}
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
String str = sc.nextLine();
String rev = "";
for (int i = str.length() - 1; i >= 0; i--) {
rev += str.charAt(i);
}
String newStr = "";
for (int i = 0; i < rev.length(); i++) {
if (rev.charAt(i) == '0') {
String temp = "" + rev.charAt(i + 2) + rev.charAt(i + 1);
int tempInt = Integer.parseInt(temp);
newStr = arr[tempInt - 1] + newStr;
i += 2;
} else {
String temp = "" + rev.charAt(i);
int tempInt = Integer.parseInt(temp);
newStr = arr[tempInt - 1] + newStr;
}
}
System.out.println(newStr);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 25751aadb78132f84f79424ec6eb79b9 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.*;
public class B {
public static void solve(Scanner sc) {
int n = Integer.parseInt(sc.nextLine());
String s = sc.nextLine();
StringBuilder sb = new StringBuilder();
for(int i = 0;i < n; i++) {
if(s.charAt(i) > '2') {
sb.append((char)((s.charAt(i)-'0') +96));
}
else if(s.charAt(i) == '1') {
if(i+3 < n && s.charAt(i+3) == '0') {
sb.append((char)((s.charAt(i)-'0') + 96));
continue;
}
if(i+2 < n && s.charAt(i+2) == '0') {
sb.append((char)((s.charAt(i)-'0')*10 + (s.charAt(i+1)-'0') + 96));
i+=2;
}
else {
sb.append((char)((s.charAt(i)-'0') + 96));
}
}
else if(s.charAt(i) == '2') {
if(i+3 < n && s.charAt(i+3) =='0') {
sb.append((char)((s.charAt(i)-'0') + 96));
continue;
}
if(i+2 < n && s.charAt(i+2) == '0') {
sb.append((char)((s.charAt(i)-'0')*10 + (s.charAt(i+1)-'0') + 96));
i+=2;
}
else {
sb.append((char)((s.charAt(i)-'0') + 96));
}
}
}
System.out.println(sb.toString());
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while(t-->0) {
solve(sc);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 60a88d5598dc33fb9f060a0870abc82c | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
import java.lang.*;
public class Solution {
public static void main(String []args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
String s=sc.next();
String ans="";
for(int i=n-1;i>=0;i--){
char p=s.charAt(i);
if(p!='0'){
int x=Character.getNumericValue(p);
char c=(char)(96+x);
ans=c+ans;
}
else{
int x2=Integer.valueOf(s.substring(i-2,i));
char c2=(char)(96+x2);
ans=c2+ans;
i=i-2;
}
}
System.out.println(ans);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 737b6ef6ebaa4193c8789a1fcd5a5342 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 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
{
int t;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
while(t-->0){
int n;
n=sc.nextInt();
String waste=sc.nextLine();
String s=sc.nextLine();
// System.out.println(t+" "+n+" "+s);
String res="";
for(int i=n-1;i>=0;i--){
char ch=s.charAt(i);
int val=0;
if(ch=='0'){
val=Integer.parseInt(s.substring(i-2,i));
i=i-2;
}
else
{
val=Integer.parseInt(s.charAt(i)+"");
}
res=(char)(val+96)+res;
}
System.out.println(res);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 824a2452270ef0e1459d1539867212c6 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class decode
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=1;i<=T;i++){
int n=sc.nextInt();
String s=sc.next();
String code="";
int num=0;
for(int j=n-1;j>=0;j--){
if(s.charAt(j)=='0'){
num=96 + Integer.parseInt(s.substring(j-2,j));
code= (char)num + code;
j=j-2;
}
else{
num=96 + Integer.parseInt(s.substring(j,j+1));
code= (char)num + code;
}
num=0;
}
System.out.println(code);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | fadf7957d73211fd33bc870e6728f66e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes |
import java.io.*;
import java.math.BigInteger;
import java.util.*;
/**
*
* @author eslam
*/
public class Solution {
// Beginning of the solution
static Kattio input = new Kattio();
static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
static ArrayList<ArrayList<Integer>> powerSet = new ArrayList<>();
static ArrayList<LinkedList<Integer>> allprem = new ArrayList<>();
static ArrayList<LinkedList<String>> allprems = new ArrayList<>();
static ArrayList<Long> luc = new ArrayList<>();
static long mod = (long) (Math.pow(10, 9) + 7);
static int grid[][] = {{0, 0, 1, -1, 1, 1, -1, -1}, {1, -1, 0, 0, 1, -1, 1, -1}};
static int dp[][];
static double cmp = 0.000000001;
public static void main(String[] args) throws IOException {
// Kattio input = new Kattio("input");
// BufferedWriter log = new BufferedWriter(new FileWriter("output.txt"));
char ch[] = new char[27];
for (int i = 1; i <= 26; i++) {
ch[i] = (char) ('a' + (i - 1));
}
int test = input.nextInt();
loop:
for (int o = 1; o <= test; o++) {
int n = input.nextInt();
String w = input.next();
for (int i = 0; i < n; i++) {
if (i + 2 < n) {
if (w.charAt(i + 2) == '0') {
if (i + 3 < n) {
if (w.charAt(i + 3) == '0') {
char c = w.charAt(i);
log.write(ch[c - '0'] + "");
} else {
char c = w.charAt(i);
char c1 = w.charAt(i + 1);
int in = Integer.parseInt(c + "" + c1);
log.write(ch[in] + "");
i += 2;
}
} else {
char c = w.charAt(i);
char c1 = w.charAt(i + 1);
int in = Integer.parseInt(c + "" + c1);
log.write(ch[in] + "");
i += 2;
}
} else {
char c = w.charAt(i);
log.write(ch[c - '0'] + "");
}
} else {
char c = w.charAt(i);
log.write(ch[c - '0'] + "");
}
}
log.write("\n");
}
log.flush();
}
static Comparator<tri> cmpTri() {
Comparator<tri> c = new Comparator<tri>() {
@Override
public int compare(tri o1, tri o2) {
if (o1.x > o2.x) {
return 1;
} else if (o1.x < o2.x) {
return -1;
} else {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
if (o1.z > o2.z) {
return 1;
} else if (o1.z < o2.z) {
return -1;
} else {
return 0;
}
}
}
}
};
return c;
}
static Comparator<pair> cmpPair() {
Comparator<pair> c = new Comparator<pair>() {
@Override
public int compare(pair o1, pair o2) {
if (o1.x > o2.x) {
return 1;
} else if (o1.x < o2.x) {
return -1;
} else {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
return 0;
}
}
}
};
return c;
}
static class rec {
long x1;
long x2;
long y1;
long y2;
public rec(long x1, long y1, long x2, long y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public long getArea() {
return (x2 - x1) * (y2 - y1);
}
}
static int sumOfRange(int x1, int y1, int x2, int y2, int e, int a[][][]) {
return (a[e][x2][y2] - a[e][x1 - 1][y2] - a[e][x2][y1 - 1]) + a[e][x1 - 1][y1 - 1];
}
public static int[][] bfs(int i, int j, String w[]) {
Queue<pair> q = new ArrayDeque<>();
q.add(new pair(i, j));
int dis[][] = new int[w.length][w[0].length()];
for (int k = 0; k < w.length; k++) {
Arrays.fill(dis[k], -1);
}
dis[i][j] = 0;
while (!q.isEmpty()) {
pair p = q.poll();
int cost = dis[p.x][p.y];
for (int k = 0; k < 4; k++) {
int nx = p.x + grid[0][k];
int ny = p.y + grid[1][k];
if (isValid(nx, ny, w.length, w[0].length())) {
if (dis[nx][ny] == -1 && w[nx].charAt(ny) == '.') {
q.add(new pair(nx, ny));
dis[nx][ny] = cost + 1;
}
}
}
}
return dis;
}
public static void dfs(int node, ArrayList<Integer> a[], boolean vi[]) {
vi[node] = true;
for (Integer ch : a[node]) {
if (!vi[ch]) {
dfs(ch, a, vi);
}
}
}
public static void graphRepresintion(ArrayList<Integer>[] a, int q) throws IOException {
for (int i = 0; i < a.length; i++) {
a[i] = new ArrayList<>();
}
while (q-- > 0) {
int x = input.nextInt();
int y = input.nextInt();
a[x].add(y);
a[y].add(x);
}
}
public static boolean isValid(int i, int j, int n, int m) {
return (i > -1 && i < n) && (j > -1 && j < m);
}
// present in the left and right indices
public static int[] swap(int data[], int left, int right) {
// Swap the data
int temp = data[left];
data[left] = data[right];
data[right] = temp;
// Return the updated array
return data;
}
// Function to reverse the sub-array
// starting from left to the right
// both inclusive
public static int[] reverse(int data[], int left, int right) {
// Reverse the sub-array
while (left < right) {
int temp = data[left];
data[left++] = data[right];
data[right--] = temp;
}
// Return the updated array
return data;
}
// Function to find the next permutation
// of the given integer array
public static boolean findNextPermutation(int data[]) {
// If the given dataset is empty
// or contains only one element
// next_permutation is not possible
if (data.length <= 1) {
return false;
}
int last = data.length - 2;
// find the longest non-increasing suffix
// and find the pivot
while (last >= 0) {
if (data[last] < data[last + 1]) {
break;
}
last--;
}
// If there is no increasing pair
// there is no higher order permutation
if (last < 0) {
return false;
}
int nextGreater = data.length - 1;
// Find the rightmost successor to the pivot
for (int i = data.length - 1; i > last; i--) {
if (data[i] > data[last]) {
nextGreater = i;
break;
}
}
// Swap the successor and the pivot
data = swap(data, nextGreater, last);
// Reverse the suffix
data = reverse(data, last + 1, data.length - 1);
// Return true as the next_permutation is done
return true;
}
public static pair[] dijkstra(int node, ArrayList<pair> a[]) {
PriorityQueue<tri> q = new PriorityQueue<>(new Comparator<tri>() {
@Override
public int compare(tri o1, tri o2) {
if (o1.y > o2.y) {
return 1;
} else if (o1.y < o2.y) {
return -1;
} else {
return 0;
}
}
});
q.add(new tri(node, 0, -1));
pair distance[] = new pair[a.length];
while (!q.isEmpty()) {
tri p = q.poll();
int cost = p.y;
if (distance[p.x] != null) {
continue;
}
distance[p.x] = new pair(p.z, cost);
ArrayList<pair> nodes = a[p.x];
for (pair node1 : nodes) {
if (distance[node1.x] == null) {
tri pa = new tri(node1.x, cost + node1.y, p.x);
q.add(pa);
}
}
}
return distance;
}
public static String revs(String w) {
String ans = "";
for (int i = w.length() - 1; i > -1; i--) {
ans += w.charAt(i);
}
return ans;
}
public static boolean isPalindrome(String w) {
for (int i = 0; i < w.length() / 2; i++) {
if (w.charAt(i) != w.charAt(w.length() - i - 1)) {
return false;
}
}
return true;
}
public static void getPowerSet(Queue<Integer> a) {
int n = a.poll();
if (!a.isEmpty()) {
getPowerSet(a);
}
int s = powerSet.size();
for (int i = 0; i < s; i++) {
ArrayList<Integer> ne = new ArrayList<>();
ne.add(n);
for (int j = 0; j < powerSet.get(i).size(); j++) {
ne.add(powerSet.get(i).get(j));
}
powerSet.add(ne);
}
ArrayList<Integer> p = new ArrayList<>();
p.add(n);
powerSet.add(p);
}
public static int getlo(int va) {
int v = 1;
while (v <= va) {
if ((va&v) != 0) {
return v;
}
v <<= 1;
}
return 0;
}
static long fast_pow(long a, long p, long mod) {
long res = 1;
while (p > 0) {
if (p % 2 == 0) {
a = (a * a) % mod;
p /= 2;
} else {
res = (res * a) % mod;
p--;
}
}
return res;
}
public static int countPrimeInRange(int n, boolean isPrime[]) {
int cnt = 0;
Arrays.fill(isPrime, true);
for (int i = 2; i * i <= n; i++) {
if (isPrime[i]) {
for (int j = i * 2; j <= n; j += i) {
isPrime[j] = false;
}
}
}
for (int i = 2; i <= n; i++) {
if (isPrime[i]) {
cnt++;
}
}
return cnt;
}
public static void create(long num) {
luc.add(num);
if (num > power(10, 9)) {
return;
}
create(num * 10 + 4);
create(num * 10 + 7);
}
public static long ceil(long a, long b) {
return (a + b - 1) / b;
}
public static long round(long a, long b) {
if (a < 0) {
return (a - b / 2) / b;
}
return (a + b / 2) / b;
}
public static void allPremutationsst(LinkedList<String> l, boolean visited[], ArrayList<String> st) {
if (l.size() == st.size()) {
allprems.add(l);
}
for (int i = 0; i < st.size(); i++) {
if (!visited[i]) {
visited[i] = true;
LinkedList<String> nl = new LinkedList<>();
for (String x : l) {
nl.add(x);
}
nl.add(st.get(i));
allPremutationsst(nl, visited, st);
visited[i] = false;
}
}
}
public static void allPremutations(LinkedList<Integer> l, boolean visited[], int a[]) {
if (l.size() == a.length) {
allprem.add(l);
}
for (int i = 0; i < a.length; i++) {
if (!visited[i]) {
visited[i] = true;
LinkedList<Integer> nl = new LinkedList<>();
for (Integer x : l) {
nl.add(x);
}
nl.add(a[i]);
allPremutations(nl, visited, a);
visited[i] = false;
}
}
}
public static int binarySearch(long[] a, long value) {
int l = 0;
int r = a.length - 1;
while (l <= r) {
int m = (l + r) / 2;
if (a[m] == value) {
return m;
} else if (a[m] > value) {
r = m - 1;
} else {
l = m + 1;
}
}
return -1;
}
public static void reverse(int l, int r, char ch[]) {
for (int i = 0; i < r / 2; i++) {
char c = ch[i];
ch[i] = ch[r - i - 1];
ch[r - i - 1] = c;
}
}
public static int logK(long v, long k) {
int ans = 0;
while (v > 1) {
ans++;
v /= k;
}
return ans;
}
public static long power(long a, long n) {
if (n == 1) {
return a;
}
long pow = power(a, n / 2);
pow *= pow;
if (n % 2 != 0) {
pow *= a;
}
return pow;
}
public static long get(long max, long x) {
if (x == 1) {
return max;
}
int cnt = 0;
while (max > 0) {
cnt++;
max /= x;
}
return cnt;
}
public static int numOF0(long v) {
long x = 1;
int cnt = 0;
while (x <= v) {
if ((x & v) == 0) {
cnt++;
}
x <<= 1;
}
return cnt;
}
public static int log2(double n) {
int cnt = 0;
while (n > 1) {
n /= 2;
cnt++;
}
return cnt;
}
public static int[] bfs(int node, ArrayList<Integer> a[]) {
Queue<Integer> q = new LinkedList<>();
q.add(node);
int distances[] = new int[a.length];
Arrays.fill(distances, -1);
distances[node] = 0;
while (!q.isEmpty()) {
int parent = q.poll();
ArrayList<Integer> nodes = a[parent];
int cost = distances[parent];
for (Integer node1 : nodes) {
if (distances[node1] == -1) {
q.add(node1);
distances[node1] = cost + 1;
}
}
}
return distances;
}
public static ArrayList<Integer> primeFactors(int n) {
ArrayList<Integer> a = new ArrayList<>();
while (n % 2 == 0) {
a.add(2);
n /= 2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
a.add(i);
n /= i;
}
if (n < i) {
break;
}
}
if (n > 2) {
a.add(n);
}
return a;
}
public static ArrayList<Integer> printPrimeFactoriztion(int n) {
ArrayList<Integer> a = new ArrayList<>();
for (int i = 1; i < Math.sqrt(n) + 1; i++) {
if (n % i == 0) {
if (isPrime(i)) {
a.add(i);
n /= i;
i = 0;
} else if (isPrime(n / i)) {
a.add(n / i);
n = i;
i = 0;
}
}
}
return a;
}
// end of solution
public static BigInteger f(long n) {
if (n <= 1) {
return BigInteger.ONE;
}
long t = n - 1;
BigInteger b = new BigInteger(t + "");
BigInteger ans = new BigInteger(n + "");
while (t > 1) {
ans = ans.multiply(b);
b = b.subtract(BigInteger.ONE);
t--;
}
return ans;
}
public static long factorial(long n) {
if (n <= 1) {
return 1;
}
long t = n - 1;
while (t > 1) {
n = mod((mod(n, mod) * mod(t, mod)), mod);
t--;
}
return n;
}
public static long rev(long n) {
long t = n;
long ans = 0;
while (t > 0) {
ans = ans * 10 + t % 10;
t /= 10;
}
return ans;
}
public static boolean isPalindrome(int n) {
int t = n;
int ans = 0;
while (t > 0) {
ans = ans * 10 + t % 10;
t /= 10;
}
return ans == n;
}
static class tri {
int x, y, z;
public tri(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public String toString() {
return x + " " + y + " " + z;
}
}
static boolean isPrime(long num) {
if (num == 1) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
if (num == 3) {
return true;
}
for (int i = 3; i <= Math.sqrt(num) + 1; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static void prefixSum(int[] a) {
for (int i = 1; i < a.length; i++) {
a[i] = a[i] + a[i - 1];
}
}
public static void suffixSum(long[] a) {
for (int i = a.length - 2; i > -1; i--) {
a[i] = a[i] + a[i + 1];
}
}
static long mod(long a, long b) {
long r = a % b;
return r < 0 ? r + b : r;
}
public static long binaryToDecimal(String w) {
long r = 0;
long l = 0;
for (int i = w.length() - 1; i > -1; i--) {
long x = (w.charAt(i) - '0') * (long) Math.pow(2, l);
r = r + x;
l++;
}
return r;
}
public static String decimalToBinary(long n) {
String w = "";
while (n > 0) {
w = n % 2 + w;
n /= 2;
}
return w;
}
public static boolean isSorted(int[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] >= a[i + 1]) {
return false;
}
}
return true;
}
public static void print(int[] a) throws IOException {
for (int i = 0; i < a.length; i++) {
log.write(a[i] + " ");
}
log.write("\n");
}
public static void read(int[] a) {
for (int i = 0; i < a.length; i++) {
a[i] = input.nextInt();
}
}
static class gepair {
long x;
long y;
public gepair(long x, long y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + " " + y;
}
}
static class pair {
int x;
int y;
public pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + " " + y;
}
}
static class pai {
long x;
int y;
public pai(long x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return x + " " + y;
}
}
public static long LCM(long x, long y) {
return x / GCD(x, y) * y;
}
public static long GCD(long x, long y) {
if (y == 0) {
return x;
}
return GCD(y, x % y);
}
public static void simplifyTheFraction(int a, int b) {
long GCD = GCD(a, b);
System.out.println(a / GCD + " " + b / GCD);
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() {
this(System.in, System.out);
}
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(problemName + ".out");
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
String nextLine() {
String str = "";
try {
str = r.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(r.readLine());
}
return st.nextToken();
} catch (Exception e) {
}
return null;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b3a4346606d425527664f3afe998626e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class codechef
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
int t1=sc.nextInt();
while(t1-->0){
int n=sc.nextInt();
String t=sc.next();
String ans="";
for(int i=n-1;i>=0;i--){
char ch=t.charAt(i);
if(ch=='0'){
char ch1=t.charAt(i-2);
char ch2=t.charAt(i-1);
int a=((int)ch1-48)*10;
int b=((int)ch2-48)*1;
ans=(char)((a+b)+96)+(ans);
i=i-2;
}
else{
ans=(char)((int)ch+96-48)+(ans);
}
}
System.out.println(ans);
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 450bdaf8a0f414c1015186981d3ee003 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.lang.reflect.Array;
import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
char[] a=new char[26];
for(int i=0;i<26;i++)
a[i]= (char) ('a'+i);
for(int i=0;i<t;i++)
{
int n = sc.nextInt();
String s= sc.next();
String ns="";
int j=n-1;
while(j>=0)
{
if(s.charAt(j)!='0')
{
int d=s.charAt(j)-'0';
ns= a[d-1]+ns;
j--;
}
else
{
int d=Integer.valueOf(s.substring(j-2,j));
ns=a[d-1]+ns;
j=j-3;
}
}
System.out.println(ns);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0d3df9bfce6200e43490568e3ed74bc7 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
final int T = in.nextInt();
in.nextLine();
for (int t = T; t > 0; t--) {
in.nextLine();
final String s = in.nextLine();
LinkedList<Character> sb = new LinkedList<>();
for (int i = 0; i < s.length(); i++) {
sb.add((char) (s.charAt(i)-1 - '0' + 'a'));
if (s.charAt(i) == '0') {
if (i < s.length() - 1 && s.charAt(i + 1) == '0') continue;
sb.pollLast();
final int r = sb.pollLast()-'a'+1;
final int l = sb.pollLast()-'a'+1;
sb.add((char) (Integer.parseInt("" + l + r) - 1 + 'a'));
}
}
print(out, sb);
}
}
}
private static void print(PrintWriter out, List<Character> sb) {
sb.forEach(out::print);
out.println();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9c9bd8c2d8d7cb92197893888d23bc8a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B {
private static Scan sc = new Scan();
public static void main(String[] args) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
solve();
}
}
private static void solve() {
int l = sc.nextInt();
String s = sc.next();
StringBuilder sb = new StringBuilder();
boolean t = false;
boolean u = false;
for (int i = 2; i < l - 1; i++) {
if (s.charAt(i) == '0' && s.charAt(i + 1) != '0') {
sb.append((char) (Integer.valueOf(s.substring(i - 2, i)) + 96));
i += 2;
if (i == l) {
t = true;
} else if (i == l - 1) {
u = true;
}
} else {
sb.append((char) ((int) s.charAt(i - 2) + 48));
}
}
if (s.charAt(l - 1) == '0') {
sb.append((char) (Integer.valueOf(s.substring(l - 3, l - 1)) + 96));
} else if (l == 1 || t) {
sb.append((char) ((int) s.charAt(l - 1) + 48));
} else if (l == 2 || u) {
sb.append((char) ((int) s.charAt(l - 2) + 48));
sb.append((char) ((int) s.charAt(l - 1) + 48));
} else {
sb.append((char) ((int) s.charAt(l - 3) + 48));
sb.append((char) ((int) s.charAt(l - 2) + 48));
sb.append((char) ((int) s.charAt(l - 1) + 48));
}
System.out.println(sb);
}
private static class Scan {
BufferedReader br;
StringTokenizer st;
public Scan() {
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());
}
String nextLine() {
String line = "";
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return line;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 301100ac81bf98485e95b274e816a2af | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Template {
public static void main(String args[]){
int t;
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
for(int q = 0; q < t; q++) {
int n = sc.nextInt();
String code = sc.next();
StringBuilder msg = new StringBuilder();
char[] arr = new char[26];
for(int i = 0; i < 26; i++) {
arr[i] = (char)(97+i);
}
for(int i = code.length()-1; i >= 0; i--) {
if(code.charAt(i) == '0') {
msg.append(arr[convert(code.substring(i-2,i))]);
i -= 2;
}
else {
msg.append(arr[code.charAt(i) - 48-1]);
}
}
System.out.println(msg.reverse().toString());
}
}
public static int convert(String abs) {
int res = 0;
for(int i = 0; i < abs.length(); i++) {
res = res*10 + (abs.charAt(i) - 48);
}
return res-1;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 6f1d7497e273ac9ab3047f87a3b3398e | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class DecodeString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int q = Integer.parseInt(sc.nextLine());
int n, j;
String s;
String decoded;
Dictionary<String, String> codes = new Hashtable<>();
String alph = "abcdefghijklmnopqrstuvwxyz";
for (int i=0; i<26; i++) {
codes.put("" + ((int) alph.charAt(i) - 'a' + 1), "" + alph.charAt(i));
}
for (int i=0; i<q; i++) {
decoded = "";
n = Integer.parseInt(sc.nextLine());
s = sc.nextLine();
j = 0;
while (j < n) {
if (j+2 < n) {
if ((s.charAt(j+2)!='0') || (j+3 < n && s.charAt(j+3)=='0')) {
decoded += codes.get(""+s.charAt(j));
j++;
}
else {
decoded += codes.get(s.substring(j, j+2));
j+=3;
}
}
else {
decoded += codes.get(""+s.charAt(j));
j++;
}
}
System.out.println(decoded);
}
sc.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | a2721b83768cf54d40486653f3d75eed | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class compare{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
String s = sc.next();
StringBuilder input1 = new StringBuilder();
for(int i = n - 1; i>=0 ;i--) {
if (s.charAt(i) == '0') {
char a = (char) (Integer.parseInt(s.substring(i-2,i)) + 96);
input1.append(a);
i = i - 2;
} else {
char b = (char) ((int) s.charAt(i) + 48);
input1.append(b);
}
}
System.out.println(input1.reverse());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 02b394aea61ded1aebb7c379d0b7f334 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
public static HashMap<String, String> charMap = new HashMap<>();
static {
for(int i = 97; i <= 122; i++){
int index = i - 96;
String character = ((char) i) + "";
if(index >= 10)
charMap.put(index + "0", character);
else
charMap.put(index + "", character);
}
}
static String[] datas;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
datas = new String[cases];
boolean a = true;
int index = 0;
for(int i = 0; index < cases; i++){
if(!a){
String code = scanner.next();
datas[index] = parse(code);
index++;
}else{
int length = scanner.nextInt();
}
a = !a;
}
for(String data : datas){
System.out.println(data);
}
}
public static String parse(String input){
StringBuilder builder = new StringBuilder();
String[] splittedChars = input.split("");
for(int j = splittedChars.length - 1; j >= 0; j--){
String currentChar = splittedChars[j];
if(currentChar.equals("0")){
if(j - 2 >= 0){
String id = splittedChars[j - 2] + splittedChars[j - 1] + "0";
String character = charMap.get(id);
builder.append(character);
j -= 2;
}else{
break;
}
}else{
builder.append(charMap.get(currentChar));
}
}
builder.reverse();
return builder.toString();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 88b93accf2840e416be9aef338221daa | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package _Decode_String;
import java.util.Scanner;
import java.util.Stack;
public class Solution {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int t = scan.nextInt(); //testcases
while(t-->0)
{
int n = scan.nextInt(); //size of String
String s = scan.next();
System.out.println(decode(s));
}
}
private static String decode(String s)
{
Stack<Character> st = new Stack<>();
for(int i=0;i<s.length()-1;i++) {
if (s.charAt(i) == '0' && s.charAt(i+1)!='0') {
int a = (st.pop()-'0') + ((st.pop()-'0') * 10);
st.push((char) (a + 96));
} else {
st.push(s.charAt(i));
}
}
if (s.charAt(s.length()-1) == '0') {
int a = (st.pop()-'0') + ((st.pop()-'0') * 10);
st.push((char) (a + 96));
} else {
st.push(s.charAt(s.length()-1));
}
StringBuffer sb = new StringBuffer();
while(!st.isEmpty())
{
char a = st.pop();
if(a>='0' && a<='9')
sb.append((char)(a-'0'+96));
else
sb.append(a);
}
return sb.reverse().toString();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | cf0393f5314ea69c254e177eb507dcaf | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
import java.lang.StringBuilder;
public class Main {
public static HashMap<String, String> charMap = new HashMap<>();
static {
for(int i = 97; i <= 122; i++){
int index = i - 96;
String character = ((char) i) + "";
if(index >= 10)
charMap.put(index + "0", character);
else
charMap.put(index + "", character);
}
}
static String[] datas;
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
datas = new String[cases];
boolean a = true;
int index = 0;
for(int i = 0; index < cases; i++){
if(!a){
String code = scanner.next();
datas[index] = parse(code);
index++;
}else{
int length = scanner.nextInt();
}
a = !a;
}
for(String data : datas){
System.out.println(data);
}
}
public static String parse(String input){
StringBuilder builder = new StringBuilder();
String[] splittedChars = input.split("");
for(int j = splittedChars.length - 1; j >= 0; j--){
String currentChar = splittedChars[j];
if(currentChar.equals("0")){
if(j - 2 >= 0){
String id = splittedChars[j - 2] + splittedChars[j - 1] + "0";
String character = charMap.get(id);
builder.append(character);
j -= 2;
}else{
break;
}
}else{
builder.append(charMap.get(currentChar));
}
}
builder.reverse();
return builder.toString();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 1eab2df5ec7c118ef792d9d460628df0 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Decode_String_1729B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0){
int l = sc.nextInt();
String st = sc.next();
String ans = "";
for(int i = l-1 ; i >=0 ; i--){
char ch = st.charAt(i);
if(ch == '0'){
int a = Integer.parseInt(st.substring(i-2 , i));
// System.out.println(i + " ---> " + a);
ans = String.valueOf((char)('a' - 1 + a)) + ans;
i = i-2;
}
else{
int a = ch - '0';
// System.out.println(i + "--->" + a);
ans = String.valueOf((char) ('a' - 1 + a)) + ans;
}
}
System.out.println(ans);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 89d9ab5fa8ec8309ff6635ce6db72300 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt(),i;
char [] arr = new char[27];
char c = 'a';
for(i=1;i<=26;i++){
arr[i]=c;
c++;
}
StringBuilder sb = new StringBuilder();
String str = sc.nextLine();
for(i=n-1;i>=0;i--){
if(str.charAt(i)!='0')
sb.insert(0,(char)('a'+(str.charAt(i)-'0' -1)));
else{
int curr = str.charAt(i-2) - '0';
curr= curr*10;
curr = curr + str.charAt(i-1) - '0';
// char curr = (char)(str.charAt(i-2)-'0'-1)*10) + (str.charAt(i-1)-'0'-1)));
sb.insert(0,arr[curr]);
i=i-2;
}
}
out.println(sb.toString());
// int [] a = new int[n];
// for(i=0;i<n;i++)
// a[i]=sc.nextInt();
}
out.close();
}
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 | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | bc7c135237352b2eee7795b17da944f6 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
while (count > 0) {
int length = scanner.nextInt();
String str = scanner.next();
String[] strings = new String[length];
for (int i = 0; i < length; i++) {
strings[i] = Character.toString(str.charAt(i));
}
String s = "";
for (int i = 0; i < length; i++) {
if (i == length - 1 || i == length - 2) {
s += (char) (Integer.parseInt(strings[i]) + 96);
} else if (strings[i + 2].equals("0")) {
if (i < length - 3 && strings[i + 3].equals("0")) {
s += (char) (Integer.parseInt(strings[i]) + 96);
} else {
s += (char) (Integer.parseInt(strings[i]) * 10 + Integer.parseInt(strings[i + 1]) + 96);
i += 2;
}
} else {
s += (char) (Integer.parseInt(strings[i]) + 96);
}
}
System.out.println(s);
count--;
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 373e44440c4f2fa02355d9254110691f | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class problem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t --> 0) {
int n = sc.nextInt();
String s = sc.next();
StringBuilder sb = new StringBuilder();
for (int i = n - 1; i >= 0; i--) {
if (s.charAt(i) != '0') {
sb.append((char) (s.charAt(i) + 96 - 48));
} else if (i > 1) {
sb.append((char) (s.charAt(i - 1) - 48 + (s.charAt(i - 2) - 48) * 10 + 96));
i -= 2;
}
}
sb.reverse();
System.out.println(sb);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 5ba46dcee2dba87315878158ccb373bf | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | //package com;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
Scanner in = new Scanner(System.in);
Map<Integer,Character> map = new HashMap();
for(int i=1;i<=26;i++){
map.put(i,(char)(96+i));
}
int t = in.nextInt();
while(t-- >0) {
int n = in.nextInt();
String s = in.next();
StringBuilder sb = new StringBuilder();
int pos = 0;
//System.out.println("123333333333333");
while(pos<s.length()){
int sum = 0;
sum = s.charAt(pos) - '0';
if( pos+2<s.length()&&s.charAt(pos+2) == '0') {
if(pos+3<s.length() && s.charAt(pos+3)=='0'){}
else
{
sum = sum * 10 + (s.charAt(pos + 1) - '0');
pos += 2;
}
}
//System.out.println(sum);
pos++;
sb.append(map.get(sum));
}
System.out.println(sb.toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | faac379a8d49276e928c542240eca066 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner jin=new Scanner(System.in);
int t=jin.nextInt();
while(t-->0){
int n=jin.nextInt();
String str=jin.next();
String ans="";
StringBuilder res=new StringBuilder(ans);
for(int i=n-1;i>=0;i--){
char ch=str.charAt(i);
if(ch!='0'){
res.append(""+((char)(ch+'a'-'1')));
}else{
String temp=""+str.charAt(i-2);
temp+=str.charAt(i-1);
i-=2;
int letval=Integer.parseInt(temp);
char letter=(char)(letval+'a'-1);
res.append(letter);
}
}res=res.reverse();
System.out.println(res);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 16d270257d7139f1db977ac3a9e62a6a | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Solve {
static Scanner sc = new Scanner(System.in);
private static void solve() {
ArrayList<Character> alp = new ArrayList<>();
for (int i = 0; i < 26; i++) {
int b = 49 + i + '0';
Character a = (char) b;
alp.add(a);
}
int n = sc.nextInt();
String s = sc.next();
String answer = "";
int idx = n - 1;
while (idx >= 0) {
int a = 0;
if (s.charAt(idx) == '0') {
a += (s.charAt(idx - 2) - '0') * 10;
a += (s.charAt(idx - 1) - '0');
idx -= 3;
} else {
a += (s.charAt(idx) - '0');
idx--;
}
answer += alp.get(a - 1);
}
StringBuilder output = new StringBuilder(answer).reverse();
System.out.println(output);
}
public static void main(String[] args) {
int tt = sc.nextInt();
while (tt-- > 0) {
solve();
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 2c67baaaeaa213024e930dff6829b753 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class test {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
StringBuilder snew=new StringBuilder("");
int n=sc.nextInt();
n -= 1;
String s=sc.next();
while(n>=0)
{
if(s.charAt(n)=='0')
{
int ch=(((int)(s.charAt(n-2))-48)*10+(int)(s.charAt(n-1)-48))+96;
//System.out.println(ch);
char abcd=(char) ch;
snew.append(abcd);
// System.out.println(snew);
n -= 3;
}
else
{
int ch=(int)(s.charAt(n))+96-48;
//System.out.println(ch);
char abcd=(char) ch;
snew.append(abcd);
// System.out.println(snew);
n--;
}
}
System.out.println(snew.reverse());
t--;
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 9e20560269a82afaf3c7623b8a37f7b2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt(), i = 1;
while(i <= n)
{
int l = scan.nextInt();
String s = scan.next();
String ans = "";
char[] a = s.toCharArray();
for(int j = 0; j < l; j++)
{
int num = 0;
if(j < (l-2))
{
if(a[j+2] == '0')
{
if(j < (l -3))
{
if(a[j+3] != '0') {
String st = String.valueOf(a[j]);
st+= String.valueOf(a[j+1]);
num = Integer.parseInt(st);
j+=2;
}
else
{
String st = String.valueOf(a[j]);
num = Integer.parseInt(st);
}
}
else
{
String st = String.valueOf(a[j]);
st+= String.valueOf(a[j+1]);
num = Integer.parseInt(st);
j+=2;
}
}
else
{
String st = String.valueOf(a[j]);
num = Integer.parseInt(st);
}
}
else
{
String st = String.valueOf(a[j]);
num = Integer.parseInt(st);
}
ans += getcharacter(num);
}
ans = ans.toLowerCase();
System.out.println(ans);
i++;
}
}
static String getcharacter(int n)
{
n--;
char a = 'A';
a+=n;
String s = String.valueOf(a);
return s;
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 7211e17c1eecfda25bda82cfea8809f7 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String alf = " abcdefghijklmnopqrstuvwxyz";
// ввод n
int n = scanner.nextInt();
// ввод наборов
for (int i = 0; i < n; i++) {
int len = scanner.nextInt();
String set = scanner.next();
String code = "";
// обработка набора
int ch = len-1;
while (ch >= 0) {
char simbol = set.charAt(ch);
String s = "";
if (simbol == '0') {
s = set.substring(ch-2, ch);
ch -= 3;
}
else {
s = set.substring(ch, ch+1);
ch -= 1;
}
code += alf.charAt(Integer.parseInt(s));
}
System.out.println(new StringBuilder(code).reverse().toString());
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | b8b34cf89c30a10dad002386c88afe84 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Main{
static Scanner sc = new Scanner(System.in);
static void solve()
{
int n = sc.nextInt();
String s = sc.next();
String str = "";
for(int i = n-1; i>=0; i--)
{
if(s.charAt(i)=='0')
{
int t1 = s.charAt(i-1) - '0';
int t2 = s.charAt(i-2) - '0';
i -= 2;
int t3 = t2*10 + t1;
str = Character.toString('a' + t3 - 1) + str;
}
else
{
int t = s.charAt(i) - '0';
str = Character.toString('a' + t -1) + str;
}
}
System.out.println(str);
}
public static void main(String[] args) {
int T = sc.nextInt();
while(T-- >0)
{
solve();
}
sc.close();
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 502dcb8df74771537aa36c04597541cc | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class decodeString {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for (int i = 0; i < n; i++) {
int len = s.nextInt();
String word = s.next();
StringBuilder ans = new StringBuilder();
for (int j = word.length() - 1; j >= 0; j--) {
if (word.charAt(j) == '0') {
String sub = word.substring(j - 2, j);
int num = Integer.parseInt(sub);
ans.append((char) ('a' + num - 1));
j -= 2;
} else {
ans.append((char) ('a' + word.charAt(j) - '0' - 1));
}
}
ans.reverse();
System.out.println(ans);
}
s.close();
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 66960621300363dcc0337bdb40ec4384 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int length = in.nextInt();
String tt = in.next();
int[] d = new int[tt.length()];
for (int j = 0; j < d.length; j++) {
d[j] = (tt.charAt(j) - '0');
}
StringBuilder sb = new StringBuilder();
for (int j = d.length - 1; j >= 0; j--) {
if(d[j] != 0) {
sb.append((char)('a' + d[j] - 1));
} else if(d[j] == 0 && d[j - 1] != 0) {
sb.append((char)(('a' + d[j - 2] * 10 + d[j - 1]) - 1));
j-=2;
} else {
sb.append((char)(('a' + (d[j - 2] * 10)) - 1));
j-=2;
}
}
System.out.println(sb.reverse());
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | bdd6e6cd335851f730cfe1e4b2e003d2 | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.util.Scanner;
public class hello {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = 0;
int nn = 0;
String ans = "";
String s = "";
for(int j = 0; j < n; j++){
ans = "";
nn = sc.nextInt();
s = sc.next();
for(int i = s.length() - 1; i >= 0; i--) {
if (s.charAt(i) != '0'){
k = 96 + Character.getNumericValue(s.charAt(i));
}else if (s.charAt(i) == '0'){
k = 96 + (Character.getNumericValue(s.charAt(i - 2)) * 10 + Character.getNumericValue(s.charAt(i - 1)));
i = i - 2;
}
ans = (char)k + ans;
}
System.out.println(ans);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | c2780905c541b59f7289d857d33c19ff | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | // Input : Pratik
import java.io.*;
import java.util.*;
public class JavaDeveoper {
public static void main(String[] args) {
try {
System.setIn(new FileInputStream("input.txt"));
System.setOut (new PrintStream(new FileOutputStream("output.txt")));
} catch (Exception e) {
System.err.println("Error");
}
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int b = 0; b < t; b++) {
int n = sc.nextInt();
String s = sc.next();
String str = "";
int k;
char c;
for (int i = n - 1; i >= 0; i--) {
if ((s.charAt(i)) == '0') {
k = Integer.parseInt(s.substring(i - 2, i));
c = (char)(k + 97 - 1);
str = str + c;
i = i - 2;
} else {
k = s.charAt(i) - '0';
c = (char)(k + 97 - 1);
str = str + c;
}
}
StringBuilder d = new StringBuilder(str);
d.reverse();
String st = d.toString();
System.out.println(st);
}
}
} | Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output | |
PASSED | 0d929ec4fc846ac814a8c5bdcd75f8ff | train_110.jsonl | 1662993300 | Polycarp has a string $$$s$$$ consisting of lowercase Latin letters.He encodes it using the following algorithm.He goes through the letters of the string $$$s$$$ from left to right and for each letter Polycarp considers its number in the alphabet: if the letter number is single-digit number (less than $$$10$$$), then just writes it out; if the letter number is a two-digit number (greater than or equal to $$$10$$$), then it writes it out and adds the number 0 after. For example, if the string $$$s$$$ is code, then Polycarp will encode this string as follows: 'c' — is the $$$3$$$-rd letter of the alphabet. Consequently, Polycarp adds 3 to the code (the code becomes equal to 3); 'o' — is the $$$15$$$-th letter of the alphabet. Consequently, Polycarp adds 15 to the code and also 0 (the code becomes 3150); 'd' — is the $$$4$$$-th letter of the alphabet. Consequently, Polycarp adds 4 to the code (the code becomes 31504); 'e' — is the $$$5$$$-th letter of the alphabet. Therefore, Polycarp adds 5 to the code (the code becomes 315045). Thus, code of string code is 315045.You are given a string $$$t$$$ resulting from encoding the string $$$s$$$. Your task is to decode it (get the original string $$$s$$$ by $$$t$$$). | 256 megabytes | import java.lang.*;
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int b=0;b<t;b++)
{
int n= sc.nextInt();
String s = sc.next();
String str = "";
int k;
char c;
for(int i=n-1;i>=0;i--)
{
if((s.charAt(i))=='0')
{
k = Integer.parseInt(s.substring(i-2,i));
c = (char)(k+97-1);
str=str+c;
i=i-2;
}
else
{
k = s.charAt(i)-'0';
c = (char)(k+97-1);
str=str+c;
}
}
StringBuilder d = new StringBuilder(str);
d.reverse();
String st = d.toString();
System.out.println(st);
}
}
}
| Java | ["9\n\n6\n\n315045\n\n4\n\n1100\n\n7\n\n1213121\n\n6\n\n120120\n\n18\n\n315045615018035190\n\n7\n\n1111110\n\n7\n\n1111100\n\n5\n\n11111\n\n4\n\n2606"] | 1 second | ["code\naj\nabacaba\nll\ncodeforces\naaaak\naaaaj\naaaaa\nzf"] | NoteThe first test case is explained above.In the second test case, the answer is aj. Indeed, the number of the letter a is equal to $$$1$$$, so 1 will be appended to the code. The number of the letter j is $$$10$$$, so 100 will be appended to the code. The resulting code is 1100.There are no zeros in the third test case, which means that the numbers of all letters are less than $$$10$$$ and are encoded as one digit. The original string is abacaba.In the fourth test case, the string $$$s$$$ is equal to ll. The letter l has the number $$$12$$$ and is encoded as 120. So ll is indeed 120120. | Java 17 | standard input | [
"greedy",
"strings"
] | 43081557fe2fbac39dd9b72b137b8fb0 | The first line of the input contains an integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases in the input. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the given code. The second line of the description of each test case contains a string $$$t$$$ of length $$$n$$$ — the given code. It is guaranteed that there exists such a string of lowercase Latin letters, as a result of encoding which the string $$$t$$$ is obtained. | 800 | For each test case output the required string $$$s$$$ — the string that gives string $$$t$$$ as the result of encoding. It is guaranteed that such a string always exists. It can be shown that such a string is always unique. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.