제출 #319716

#제출 시각아이디문제언어결과실행 시간메모리
319716gustasonTetris (COCI17_tetris)C++14
80 / 80
1 ms708 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int r, s;
char grid[11][11];

vector<string> shape1{"11",
                      "11"};

vector<string> shape2{"1111"};

vector<string> shape3{"011",
                      "110"};

vector<string> shape4{"110",
                      "011"};

vector<string> shape5{"010",
                      "111"};

const vector<vector<string>> shapes = {shape1, shape2, shape3, shape4, shape5};
const vector<int> rot = {1, 2, 2, 2, 4};

vector<string> rotate(vector<string> mat) {
  int r = mat.size(), s = mat[0].size();
  vector<string> ret;

  ret.resize(s);
  for (int i = 0; i < ret.size(); ++i)
    ret[i].resize(r);

  for (int i = 0; i < r; ++i)
    for (int j = 0; j < s; ++j)
      ret[j][r - 1 - i] = mat[i][j];

  return ret;
}

int count(vector<string> shape) {
  int rr = shape.size(), ss = shape[0].size();
  int ret = 0;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < s; ++j) {
      if (i + rr > r || j + ss > s) continue;
      set <char> S;
      for (int _r = i; _r < i + rr; ++_r)
        for (int _s = j; _s < j + ss; ++_s)
          if (shape[_r - i][_s - j] == '1')
            S.insert(grid[_r][_s]);
      ret += (S.size() == 1 && *S.begin() != '.');
    }
  }
  return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> r >> s;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < s; j++) {
            cin >> grid[i][j];
        }
    }

    for(int i = 0; i <= 4; i++) {
        auto shape = shapes[i];
        int cnt = 0;
        for(int j = 0; j < rot[i]; j++) {
            cnt += count(shape);
            shape = rotate(shape);
        }
        cout << cnt << "\n";
    }
    return 0;
}
//~ check for overflows

컴파일 시 표준 에러 (stderr) 메시지

tetris.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > rotate(std::vector<std::__cxx11::basic_string<char> >)':
tetris.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int i = 0; i < ret.size(); ++i)
      |                   ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...