답안 #319708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
319708 2020-11-06T08:35:34 Z gustason Tetris (COCI17_tetris) C++14
24 / 80
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
char mat[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};

int count(vector<string> shape) {
    int r = shape.size(), c = shape[0].size();
    int cnt = 0;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (i + r > n || i + c > m) continue;
            set<char> s;
            for(int st = i; st < i + r; st++) {
                for(int el = j; el < j + c; el++) {
                    if (shape[st - i][el - j] == '1') {
                        s.insert(mat[st][el]);
                    }
                }
            }
            if ((s.size() == 1 && *s.begin() != '.')) {
                cnt++;
            }
        }
    }
    return cnt;
}
vector<string> rotate(vector<string> mt) {
  int r = mt.size(), s = mt[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] = mt[i][j];

  return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> mat[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

Compilation message

tetris.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > rotate(std::vector<std::__cxx11::basic_string<char> >)':
tetris.cpp:51: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]
   51 |   for (int i = 0; i < ret.size(); ++i)
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Correct 1 ms 364 KB Output is correct