結果

問題 No.2689 Populous
ユーザー SSRSSSRS
提出日時 2024-03-20 22:35:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,112 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 207,532 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-03-20 22:35:45
合計ジャッジ時間 6,254 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
6,548 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 6 ms
7,552 KB
testcase_21 AC 6 ms
7,552 KB
testcase_22 AC 6 ms
7,552 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (i == 0 || i == H - 1 || j == 0 || j == W - 1){
        cin >> A[i][j];
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < H - 1; i++){
    if (abs(A[i][0] - A[i + 1][0]) > 1){
      ok = false;
    }
    if (abs(A[i][W - 1] - A[i + 1][W - 1]) > 1){
      ok = false;
    }
  }
  for (int i = 0; i < W - 1; i++){
    if (abs(A[0][i] - A[0][i + 1]) > 1){
      ok = false;
    }
    if (abs(A[H - 1][i] - A[H - 1][i + 1]) > 1){
      ok = false;
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    vector<int> row_ng, col_ng;
    for (int i = 1; i < H - 1; i++){
      if (abs(A[i][0] - A[i][W - 1]) > W - 1){
        row_ng.push_back(i);
      }
    }
    for (int i = 1; i < W - 1; i++){
      if (abs(A[0][i] - A[H - 1][i]) > H - 1){
        col_ng.push_back(i);
      }
    }
    if (row_ng.empty() && col_ng.empty()){
      cout << 1 << endl;
    } else {
      assert(false);
    }
  }
}
0