git reimport
This commit is contained in:
87
archive/2017.01/2017.01.07 - unsorted/F.java
Normal file
87
archive/2017.01/2017.01.07 - unsorted/F.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class F {
|
||||
class Point {
|
||||
final int x;
|
||||
final int y;
|
||||
|
||||
public Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Point point = (Point) o;
|
||||
|
||||
if (x != point.x) return false;
|
||||
return y == point.y;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = x;
|
||||
result = 31 * result + y;
|
||||
return result;
|
||||
}
|
||||
|
||||
public Point sub(Point p) {
|
||||
return new Point(x - p.x, y - p.y);
|
||||
}
|
||||
|
||||
public Point add(Point p) {
|
||||
return new Point(x + p.x, y + p.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + " " + y;
|
||||
}
|
||||
}
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
int m = in.nextInt();
|
||||
|
||||
boolean[][] a = new boolean[n][m];
|
||||
|
||||
Map<Integer, Point> locations = new HashMap<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
int t = in.nextInt();
|
||||
locations.put(t, new Point(i, j));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n * m; i++) {
|
||||
int t = in.nextInt();
|
||||
Point p = locations.get(t);
|
||||
|
||||
int x = p.x;
|
||||
int y = p.y;
|
||||
|
||||
if (x < n - 1) {
|
||||
if (!a[x + 1][y]) {
|
||||
out.println("NO");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
a[x][y] = true;
|
||||
}
|
||||
|
||||
out.println("YES");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user