結果

問題 No.1169 Row and Column and Diagonal
ユーザー noritakenoritake
提出日時 2020-08-14 21:53:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,035 bytes
コンパイル時間 1,751 ms
コンパイル使用メモリ 167,164 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:38:20
合計ジャッジ時間 2,845 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 9 ms
5,376 KB
testcase_09 AC 12 ms
5,376 KB
testcase_10 AC 22 ms
5,376 KB
testcase_11 AC 24 ms
5,376 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 24 ms
5,376 KB
testcase_14 AC 27 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:35:45: warning: 'target_column' may be used uninitialized [-Wmaybe-uninitialized]
   35 |             swap(G[i][x], G[i][target_column]);
      |                                             ^
main.cpp:26:13: note: 'target_column' was declared here
   26 |         int target_column;
      |             ^~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int N; cin >> N;

    vector<vi> G(N, vi(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            G[i][(j + i) % N] = j;
        }
    }


    for (int x = 1; x < N; x++) {

// xが2の時、Gのうち2行目の値が2の列を見つける
        int target_column;
        for (int column = x; column < N; column++) {
            if (G[x][column] == x) {
                target_column = column;
                break;
            }
        }

        for (int i = 0; i < N; i++) {
            swap(G[i][x], G[i][target_column]);
        }
    }

    rep(i, N) {
        rep(j, N) {
            cout << (G[i][j] + 1);

            if (j != N - 1) cout << " ";
        }
        cout << endl;
    }


}
0