2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【電脳少女プログラミング2088 ─壊レタ君を再構築─】B:ギャングのアジト

Last updated at Posted at 2025-02-20

目的

電脳少女プログラミング2088 ─壊レタ君を再構築─の問題「ギャングのアジト」をC++で解いたのでその解説を行う。

読者の方へ、
他の考え方をして解いた方は教えていただきたいです。

コード

#include <iostream>
#include <vector>

using namespace std;

int main(void){
    // 入力
    int n;
    cin >> n;
    vector<vector<int>> b(n,vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) cin >> b[i][j];
    }

    // 縦横半分だけ調べて、都度反対と同じかを確認する
    // i:縦方向, j:横方向
    for (int i = 0; i < n/2; ++i) {
        for (int j = 0; j < n/2; ++j) {
            // 左右対称の確認
            // 対象でない場合、"No"を出力してreturnする
            if (b[i][j] != b[i][n-1-j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

計算量

上記コードの計算量は二重forループなのでO((n/2)^2)となる。
入力Nの条件が1 ≤ N ≤ 50なので10^3くらい?になる。
今回、実行時間は問われていないので関係ないが、一応考慮してみた。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?