Submission #263455

# Submission time Handle Problem Language Result Execution time Memory
263455 2020-08-13T17:16:10 Z Bruteforceman Rectangles (IOI19_rect) C++14
37 / 100
5000 ms 65028 KB
#include "bits/stdc++.h"
#include "rect.h"
using namespace std;
struct rect {
  int i, j;
  int l, r;
  rect (int i, int j, int l, int r) : i(i), j(j), l(l), r(r) {}
  rect () {}
};

vector <rect> getLines(vector<std::vector<int>> a) {
  int n = a.size();
  int m = a.front().size();
  vector <int> v[m];
  vector <rect> vert;
  for(int i = 0; i < n; i++) {
    vector <int> last (n, -1);
    for(int j = 0; j < m; j++) {
      vector <int> aux (n, -1);
      for(int k = int(v[j].size()) - 1; k >= 0; k--) {
        aux[v[j][k]] = 1;
        if(a[v[j][k]][j] >= a[i][j]) break;
      }
      while(!v[j].empty() && a[v[j].back()][j] <= a[i][j]) {
        v[j].pop_back();
      }
      v[j].push_back(i);
      for(int k = 0; k < i; k++) {
        if(last[k] != -1) {
          if(aux[k] == -1) {
            if(k - 1 < i) vert.push_back(rect(k, i, last[k], j - 1));
            last[k] = -1;
          }
        } else if (aux[k] == 1) {
          last[k] = j;
        }
      }
    }
    for(int k = 0; k < i; k++) {
      if(last[k] != -1) {
        if(k < i - 1) vert.push_back(rect(k, i, last[k], m - 1));
      }
    }
  }
	return vert;
}
vector <vector <int>> rotate(vector <vector <int>> a) {
  int n = a.size();
  int m = a.front().size();
  vector <vector <int>> b (m, vector <int> (n, 0));
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < n; j++) {
      b[i][j] = a[j][i];
    }
  }
  return b;
}
/*
0 2 1 2
2 4 0 1
1 4 4 4
*/
long long count_rectangles(vector <vector <int>> a) {
  auto h = getLines(a);
  auto v = getLines(rotate(a));
  for(auto &x : v) {
    x.l -= 1;
    x.r += 1;
    // cout << x.i << " " << x.j << " " << x.l << " " << x.r << endl;
  }
  for(auto &x : h) {
    x.l -= 1;
    x.r += 1;
    // cout << x.i << " " << x.j << " " << x.l << " " << x.r << endl;
  }
  long long ans = 0;
  for(auto x : v) {
    for(auto y : h) {
      if(x.l <= y.i && y.j <= x.r) {
        if(y.l <= x.i && x.j <= y.r) {
          ++ans;
        }
      }
    }
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 36 ms 768 KB Output is correct
22 Correct 37 ms 836 KB Output is correct
23 Correct 34 ms 768 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 36 ms 768 KB Output is correct
22 Correct 37 ms 836 KB Output is correct
23 Correct 34 ms 768 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 26 ms 1408 KB Output is correct
26 Correct 27 ms 1408 KB Output is correct
27 Correct 26 ms 1536 KB Output is correct
28 Correct 316 ms 1620 KB Output is correct
29 Correct 1530 ms 2428 KB Output is correct
30 Correct 1575 ms 2556 KB Output is correct
31 Correct 1135 ms 2428 KB Output is correct
32 Correct 1180 ms 2428 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 36 ms 768 KB Output is correct
22 Correct 37 ms 836 KB Output is correct
23 Correct 34 ms 768 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 26 ms 1408 KB Output is correct
26 Correct 27 ms 1408 KB Output is correct
27 Correct 26 ms 1536 KB Output is correct
28 Correct 316 ms 1620 KB Output is correct
29 Correct 1530 ms 2428 KB Output is correct
30 Correct 1575 ms 2556 KB Output is correct
31 Correct 1135 ms 2428 KB Output is correct
32 Correct 1180 ms 2428 KB Output is correct
33 Execution timed out 5043 ms 23612 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 760 KB Output is correct
2 Correct 20 ms 640 KB Output is correct
3 Correct 27 ms 640 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 37 ms 884 KB Output is correct
6 Correct 34 ms 800 KB Output is correct
7 Correct 36 ms 856 KB Output is correct
8 Correct 36 ms 896 KB Output is correct
9 Correct 31 ms 896 KB Output is correct
10 Correct 12 ms 640 KB Output is correct
11 Correct 20 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Execution timed out 5028 ms 65028 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 3 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 36 ms 768 KB Output is correct
22 Correct 37 ms 836 KB Output is correct
23 Correct 34 ms 768 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 26 ms 1408 KB Output is correct
26 Correct 27 ms 1408 KB Output is correct
27 Correct 26 ms 1536 KB Output is correct
28 Correct 316 ms 1620 KB Output is correct
29 Correct 1530 ms 2428 KB Output is correct
30 Correct 1575 ms 2556 KB Output is correct
31 Correct 1135 ms 2428 KB Output is correct
32 Correct 1180 ms 2428 KB Output is correct
33 Execution timed out 5043 ms 23612 KB Time limit exceeded
34 Halted 0 ms 0 KB -