답안 #948486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948486 2024-03-18T06:58:27 Z vjudge1 무지개나라 (APIO17_rainbow) C++17
11 / 100
375 ms 1048576 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S& a, const T& b) {
	return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S& a, const T& b) {
	return a < b ? (a = b) == b : false;
}

const vector<int> dx = {0, 0, -1, 1};
const vector<int> dy = {-1, 1, 0, 0};

int n, m, x, y, k;
string s;
vector<vector<char>> g;
vector<vector<bool>> vis;
vector<int> pref[2], cmp;

void init(int R, int C, int sr, int sc, int M, char* S) {
  n = R, m = C, x = sr - 1, y = sc - 1, k = M, s = S;
  g.resize(n);
  vis.resize(n);
  for (int i = 0; i < n; ++i) {
    g[i].assign(m, '.');
    vis[i].assign(m, false);
  }
  g[x][y] = '#';
  for (int i = 0; i < k; ++i) {
    if (s[i] == 'N') x--;
    else if (s[i] == 'S') x++;
    else if (s[i] == 'E') y++;
    else y--;
    g[x][y] = '#';
  }
  if (n == 2) {
    pref[0].resize(m);
    pref[1].resize(m);
    cmp.resize(m);
    for (int i = 0; i < 2; ++i) {
      pref[i][0] = g[i][0] == '.';
      for (int j = 1; j < m; ++j) {
        int add = 0;
        if (g[i][j] == '.' && g[i][j - 1] == '#') {
          add = 1;
        }
        pref[i][j] = pref[i][j - 1] + add;
      }
    }
    if (g[0][0] == '.' || g[1][0] == '.') cmp[0] = 1;
    else cmp[0] = 0;
    for (int j = 1; j < m; ++j) {
      int add = (g[0][j] == '.' || g[1][j] == '.');
      if (g[0][j] == '.' && g[0][j - 1] == '.') add = 0;
      if (g[1][j] == '.' && g[1][j - 1] == '.') add = 0;
      cmp[j] = cmp[j - 1] + add;
    }
  }
}

bool check(int i, int j, int ar, int ac, int br, int bc) {
  return i >= ar && i <= br && j >= ac && j <= bc;
}

void dfs(int i, int j, int ar, int ac, int br, int bc) {
  vis[i][j] = true;
  for (int idx = 0; idx < 4; ++idx) {
    int I = i + dx[idx], J = j + dy[idx];
    if (check(I, J, ar, ac, br, bc) && !vis[I][J] && g[I][J] != '#') {
      dfs(I, J, ar, ac, br, bc);
    }
  }
}

int colour(int ar, int ac, int br, int bc) {
  ar--, ac--, br--, bc--;
  if (n <= 50 && m <= 50) {
    int cnt = 0;
    for (int i = ar; i <= br; ++i) {
      for (int j = ac; j <= bc; ++j) {
        if (!vis[i][j] && g[i][j] == '.') {
          cnt++;
          dfs(i, j, ar, ac, br, bc);
        }
      }
    }
    for (int i = ar; i <= br; ++i) {
      for (int j = ac; j <= bc; ++j) {
        vis[i][j] = false;
      }
    }
    return cnt;
  } else {
    int cnt = 0;
    if (ar == br) {
      cnt = pref[ar][bc];
      if (ac) cnt -= pref[ar][ac - 1];
    } else {
      cnt = cmp[bc];
      if (ac) {
        cnt -= cmp[ac - 1];
        int add = 0;
        if (g[0][ac] == '.' && g[0][ac - 1] == '.') add = 1;
        if (g[1][ac] == '.' && g[1][ac] - 1 == '.') add = 1;
        cnt += add;
      }
    }
    return cnt;
  }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 13 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 11 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 8 ms 516 KB Output is correct
14 Correct 5 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 41 ms 3904 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 375 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 13 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 11 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 8 ms 516 KB Output is correct
14 Correct 5 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Runtime error 3 ms 3164 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 13 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 11 ms 348 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 8 ms 516 KB Output is correct
14 Correct 5 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Runtime error 3 ms 3164 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -