| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 562624 | SSRS | Land of the Rainbow Gold (APIO17_rainbow) | C++14 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "rainbow.h"
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<vector<int>> land;
void init(int R, int C, int sr, int sc, int M, char *S){
  sr--;
  sc--;
  land = vector<vector<int>>(R, vector<int>(C, 1));
  int x = sr, y = sc;
  land[x][y] = 0;
  for (int i = 0; i < M; i++){
    if (S[i] == 'N'){
      x--;
    }
    if (S[i] == 'S'){
      x++;
    }
    if (S[i] == 'E'){
      y++;
    }
    if (S[i] == 'W'){
      y--;
    }
    land[x][y] = 0;
  }
}
int colour(int ar, int ac, int br, int bc){
  ar--;
  ac--;
  int R = land.size();
  int C = land[0].size();
  vector<vector<bool>> used(R, vector<bool>(C, false));
  int ans = 0;
  for (int i = ar; i < br; i++){
    for (int j = ac; j < bc; j++){
      if (land[i][j] == 1 && !used[i][j]){
        ans++;
        used[i][j] = true;
        queue<pair<int, int>> Q;
        Q.push(make_pair(i, j));
        while (!Q.empty()){
          int x = Q.front().first;
          int y = Q.front().second;
          Q.pop();
          for (int k = 0; k < 4; k++){
            int x2 = x + dx[k];
            int y2 = y + dy[k];
            if (ar <= x2 && x2 < br && ac <= y2 && y2 < bc){
              if (land[x2][y2] == 1 && !used[x2][y2]){
                used[x2][y2] = true;
                Q.push(make_pair(x2, y2));
              }
            }
          }
        }
      }
    }
  }
  return ans;
}
int main(){
  init(6, 4, 3, 3, 9, "NWESSWEWS");
  cout << colour(2, 3, 2, 3) << endl;
  cout << colour(3, 2, 4, 4) << endl;
  cout << colour(5, 3, 6, 4) << endl;
  cout << colour(1, 2, 5, 3) << endl;
}
