Click Here to go back to the homepage.

Tetris Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    map<int, vector<vector<int>>> pieces = {
        {1, {{0}, {0, 0, 0, 0}}}, 
        {2, {{0, 0}}},
        {3, {{0, 0, 1}, {0, -1}}},
        {4, {{0, -1, 0}, {0, 1}}},
        {5, {{0, 0, 0,}, {0, 1}, {0, -1}, {0, -1, 1}}},
        {6, {{0, 0, 0}, {0, 0}, {0, 1, 0}, {0, -2}}},
        {7, {{0, 0, 0}, {0, 0}, {0, 2}, {0, 0, -1}}}};

    int columns, piece;
    cin >> columns >> piece;
    int board[columns];
    for(int i = 0; i < columns; i++){
        cin >> board[i];
    }
    
    auto find = pieces.find(piece);
    vector<vector<int>> rotations = (*find).second;
    int column, variations = 0;
    for(int i = 0; i < columns; i++){
        column = board[i];
        for(vector<int> v: rotations){
            if(i + v.size() > columns){
                continue;
            }
            for(int j = 1; j < v.size(); j++){
                if(board[i + j] - column != v[j]){
                    goto nextRotation;
                }
                column = board[i + j];
            }
            variations++;
            nextRotation:
            column = board[i];
        }
    }
    cout << variations << endl;
    return 0;
}