Skip to content

Instantly share code, notes, and snippets.

@Naba0123
Created October 12, 2015 01:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Naba0123/c008eca96e9fa0a1336b to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
// 入力
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String rs = "";
rs = br.readLine();
String[] xyLength = rs.split(" ");
int xLength = Integer.parseInt(xyLength[0]);
int yLength = Integer.parseInt(xyLength[1]);
int selectNum = Integer.parseInt(xyLength[2]);
int[][] xy = new int[xLength][yLength];
int[][] xySelect = new int[xLength][yLength];
int y_ = 0;
while (y_ < yLength) {
rs = br.readLine();
String[] y = rs.split(" ");
for (int i = 0; i < y.length; i++) {
int x_ = Integer.parseInt(y[i]);
xy[i][y_] = x_;
}
y_++;
}
// フラグを立てる
while ((rs = br.readLine()) != null) {
String[] select = rs.split(" ");
for (int i = Integer.parseInt(select[1]) - 1; i < Integer.parseInt(select[3]); i++) {
for (int j = Integer.parseInt(select[0]) - 1; j < Integer.parseInt(select[2]); j++) {
xySelect[j][i] = 1;
}
}
}
int ans = 0;
for (int i = 0; i < xLength; i++) {
for (int j = 0; j < yLength; j++) {
if (xySelect[i][j] == 1) {
ans += xy[i][j];
}
}
}
System.out.println(ans);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment