Submission #32779520
Source Code Expand
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
BCountingGrids solver = new BCountingGrids();
solver.solve(1, in, out);
out.close();
}
static class BCountingGrids {
int mod = 998244353;
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
Combinations comb = new Combinations(n * n + 1, mod);
long ans = comb.fact[n * n];
ans -= (long) n * n * comb.choose(n * n, 2 * n - 1) % mod
* comb.fact[n - 1] % mod
* comb.fact[n - 1] % mod
* comb.fact[(n - 1) * (n - 1)] % mod;
out.println((ans + mod) % mod);
}
}
static class MathUtils {
public static int[] inverses(int size, int mod) {
int[] inv = new int[size];
inv[1] = 1;
for (int i = 2; i < inv.length; i++) {
inv[i] = (int) ((long) (mod - mod / i) * inv[mod % i] % mod);
}
return inv;
}
}
static class FastScanner {
public BufferedReader br;
public StringTokenizer st;
public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
public FastScanner(String fileName) {
try {
br = new BufferedReader(new FileReader(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public String next() {
while (st == null || !st.hasMoreElements()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new UnknownError();
}
if (line == null) {
throw new UnknownError();
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
}
static class Combinations {
public final int max;
public final int mod;
public int[] inv;
public int[] fact;
public int[] invFact;
public Combinations(int max, int mod) {
this.max = max;
this.mod = mod;
inv = MathUtils.inverses(max, mod);
fact = new int[max];
invFact = new int[max];
fact[0] = invFact[0] = 1;
for (int i = 1; i < max; i++) {
fact[i] = (int) ((long) fact[i - 1] * i % mod);
invFact[i] = (int) ((long) invFact[i - 1] * inv[i] % mod);
}
}
public int choose(int n, int k) {
if (k < 0 || k > n) {
return 0;
}
return (int) ((long) fact[n] * invFact[k] % mod * invFact[n - k] % mod);
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Counting Grids |
| User | VArtem |
| Language | Java (OpenJDK 11.0.6) |
| Score | 500 |
| Code Size | 3737 Byte |
| Status | AC |
| Exec Time | 102 ms |
| Memory | 35932 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample01.txt, sample02.txt, sample03.txt |
| All | in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, sample01.txt, sample02.txt, sample03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 97 ms | 35172 KiB |
| in02.txt | AC | 88 ms | 34124 KiB |
| in03.txt | AC | 96 ms | 35616 KiB |
| in04.txt | AC | 88 ms | 33696 KiB |
| in05.txt | AC | 78 ms | 33380 KiB |
| in06.txt | AC | 82 ms | 34064 KiB |
| in07.txt | AC | 77 ms | 33100 KiB |
| in08.txt | AC | 77 ms | 33252 KiB |
| in09.txt | AC | 87 ms | 33300 KiB |
| in10.txt | AC | 81 ms | 32992 KiB |
| in11.txt | AC | 97 ms | 35880 KiB |
| in12.txt | AC | 102 ms | 35932 KiB |
| in13.txt | AC | 80 ms | 32708 KiB |
| sample01.txt | AC | 77 ms | 32692 KiB |
| sample02.txt | AC | 79 ms | 32560 KiB |
| sample03.txt | AC | 81 ms | 32700 KiB |