이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import java.io.*;
import java.util.*;
public class kocka {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int[] L = new int[n];
for (int i = 0; i < n; i++)
L[i] = sc.nextInt();
boolean ok = true;
int[] first = new int[n], last = new int[n];
Arrays.fill(first, -1);
Arrays.fill(last, -1);
for (int row = 0; row < n; row++) {
int r = sc.nextInt(), l = L[row];
if (l == -1 || r == -1) {
ok &= l == r;
} else {
r = n - r - 1;
if (l > r)
ok = false;
if (first[l] == -1)
first[l] = row;
last[l] = row;
if (first[r] == -1)
first[r] = row;
last[r] = row;
}
}
int[] U = new int[n];
for (int i = 0; i < n; i++)
U[i] = sc.nextInt();
for (int col = 0; col < n; col++) {
int d = sc.nextInt(), u = U[col];
if (d == -1 || u == -1) {
ok &= u == d;
ok &= first[col] == -1;
ok &= last[col] == -1;
} else {
d = n - d - 1;
if (u > d)
ok = false;
if (first[col] != -1 && first[col] < u) {
ok = false;
}
if (last[col] != -1 && last[col] > d)
ok = false;
}
}
out.println(ok ? "DA" : "NE");
out.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
Scanner(String fileName) throws FileNotFoundException {
br = new BufferedReader(new FileReader(fileName));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
boolean ready() throws IOException {
return br.ready();
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |