結果

問題 No.2689 Populous
ユーザー SSRSSSRS
提出日時 2024-03-20 22:36:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,139 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 207,536 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-03-20 22:36:21
合計ジャッジ時間 3,623 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(row_ng.empty() || col_ng.empty());
    }
  }
}
0