답안 #425099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
425099 2021-06-12T13:24:32 Z madlogic Vision Program (IOI19_vision) C++17
66 / 100
13 ms 1124 KB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;

// int cur;
// int N, M;
// map<pair<int, int>, int> grid;

// int add_xor(vector<int> v) {
//   int xo = 0;
//   for (int p : v) {
//     int r = p / M, c = p % M;
//     xo ^= grid[{r, c}];
//   }
//   ++cur;
//   int r = cur / M;
//   int c = cur % M;
//   grid[{r, c}] = xo;
//   return cur;
// }

// int getId(int id) {
//   int r = id / M, c = id % M;
//   return grid[{r, c}];
// }

// int add_or(vector<int> v) {
//   int xo = 0;
//   for (int p : v) {
//     int r = p / M, c = p % M;
//     xo |= grid[{r, c}];
//   }
//   ++cur;
//   int r = cur / M;
//   int c = cur % M;
//   grid[{r, c}] = xo;
//   return cur;
// }

// int add_and(vector<int> v) {
//   int xo = 1;
//   for (int p : v) {
//     int r = p / M, c = p % M;
//     xo &= grid[{r, c}];
//   }
//   ++cur;
//   int r = cur / M;
//   int c = cur % M;
//   grid[{r, c}] = xo;
//   return cur;
// }

// int add_not(int val) {
//   int x = val / M;
//   int y = val % M; 
//   int here = grid[{x, y}];
//   ++cur;
//   int r = cur / M;
//   int c = cur % M;
//   grid[{r, c}] = !here;
//   return cur;
// }

void construct_network(int H, int W, int K) {
  // cur = (H - 1) * W + (W - 1);
  if (K == 1) {
    // cout << "In here" << endl;
    vector<int> indsRow;
    for (int i = 0; i < H; i++) {
      vector<int> idx;
      for (int j = 0; j < W; j++) {
        idx.push_back(i * W + j);
      }
      indsRow.push_back(add_xor(idx));
    }
    vector<int> indsCol;
    for (int i = 0; i < W; i++) {
      vector<int> idx;
      for (int j = 0; j < H; j++) {
        idx.push_back(j * W + i);
      }
      indsCol.push_back(add_xor(idx));
    }
    // for (int p : indsRow) {
    //   cout << getId(p) << '\n';
    // }
    // cout << '\n';
    // for (int p : indsCol) {
    //   cout << getId(p) << '\n';
    // } 
    // cout << '\n';
    int id1 = add_not(add_or(indsRow));
    int id2 = add_not(add_or(indsCol));
    // cout << "all rows: " << getId(id1) << endl;
    // cout << "all cols: " << getId(id2) << endl;
    int nn = (int) indsRow.size();
    vector<int> aa;
    for (int i = 0; i + 1 < nn; i++) {
      aa.push_back(add_and({indsRow[i], indsRow[i + 1]}));
    }
    int mm = (int) indsCol.size();
    vector<int> bb;
    for (int i = 0; i + 1 < mm; i++) {
      bb.push_back(add_and({indsCol[i], indsCol[i + 1]}));
    }
    int id3 = (aa.empty() ? -1 : add_or(aa));
    int id4 = (bb.empty() ? -1 : add_or(bb));
    // cout << getId(id3) << endl;
    // cout << getId(id4) << endl;
    if (id3 == -1) {
      int id = add_and({id1, id4});
      // cout << getId(id) << '\n';
    } else if (id4 == -1) {
      int id = add_and({id2, id3});
      // cout << getId(id) << '\n';
    } else {
      int id = add_xor({add_and({id1, id4}), add_and({id2, id3})});
      // cout << getId(id) << '\n';
    }
    // 1 1 0
    // 0 0 0 
    // 0 0 0
  } else if (1ll * H * W >= 1000) {
    vector<int> v;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (!(i == 0 && j == 0) && abs(i) + abs(j) == K) {
          v.push_back(add_and({0, i * W + j}));
        }
      }
    }
    if (!v.empty()) {
      add_or(v);
    }
  } else {
    vector<vector<vector<int>>> dp(3, vector<vector<int>>(H, vector<int>(W, -1)));
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        vector<int> v{i * W + j};
        for (int x = 0; x <= K; x++) {
          int y = K - x;
          set<int> s;
          s.insert(y);
          s.insert(-y);
          for (int ys : s) {
            int dx = i + x;
            int dy = j + ys;
            if (dx >= 0 && dx < H && dy >= 0 && dy < W) {
              int yy = dx * W + dy;
              v.push_back(yy);
            }
          }
        }
        dp[0][i][j] = add_xor(v);
        dp[1][i][j] = add_or(v);
        reverse(v.begin(), v.end());
        v.pop_back();
        if (!v.empty()) {
          dp[2][i][j] = add_xor(v);
        }
      }
    }
    vector<int> v;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int a = dp[0][i][j];
        int b = dp[1][i][j];
        if (dp[2][i][j] != -1) {
          int id1 = add_xor({a, b});
          int idx = add_and({id1, dp[2][i][j]});
          v.push_back(idx);
        }
      }
    }
    if (!v.empty()) {
      add_or(v);
    } else {
      add_and({0, 1});
    }
  }
}

// int main() {
//   ios::sync_with_stdio(false);
//   cin.tie(0);
//   N = 3;
//   M = 3;
//   for (int i = 0; i < N; i++) {
//     for (int j = 0; j < M; j++) {
//       grid[{i, j}] = 0;
//     }
//   }
//   grid[{2, 1}] = 1;
//   grid[{1, 1}] = 1;
//   construct_network(N, M, 1);
//   return 0;
// }

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:111:11: warning: unused variable 'id' [-Wunused-variable]
  111 |       int id = add_and({id1, id4});
      |           ^~
vision.cpp:114:11: warning: unused variable 'id' [-Wunused-variable]
  114 |       int id = add_and({id2, id3});
      |           ^~
vision.cpp:117:11: warning: unused variable 'id' [-Wunused-variable]
  117 |       int id = add_xor({add_and({id1, id4}), add_and({id2, id3})});
      |           ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 10 ms 968 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 460 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 11 ms 900 KB Output is correct
35 Correct 9 ms 768 KB Output is correct
36 Correct 6 ms 460 KB Output is correct
37 Correct 7 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 10 ms 968 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 460 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 11 ms 900 KB Output is correct
35 Correct 9 ms 768 KB Output is correct
36 Correct 6 ms 460 KB Output is correct
37 Correct 7 ms 372 KB Output is correct
38 Incorrect 1 ms 204 KB on inputs (8, 61), (22, 97), expected 1, but computed 0
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 4 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 5 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 4 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 4 ms 332 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 5 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 5 ms 332 KB Output is correct
20 Correct 6 ms 692 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 5 ms 716 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 13 ms 1100 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1124 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 6 ms 716 KB Output is correct
9 Correct 10 ms 1100 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 10 ms 968 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 460 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 11 ms 900 KB Output is correct
35 Correct 9 ms 768 KB Output is correct
36 Correct 6 ms 460 KB Output is correct
37 Correct 7 ms 372 KB Output is correct
38 Incorrect 1 ms 204 KB on inputs (8, 61), (22, 97), expected 1, but computed 0
39 Halted 0 ms 0 KB -