結果

問題 No.3596 Queen Score Attack 1
コンテスト
ユーザー tnakao0123
提出日時 2026-07-25 16:15:49
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 363µs
コード長 2,109 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 204 ms
コンパイル使用メモリ 55,372 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-25 16:15:56
合計ジャッジ時間 2,011 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3596.cc:  No.3596 Queen Score Attack 1 - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_H = 100;
const int MAX_W = 100;
const int MAX_L = MAX_H + MAX_W - 1;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_H][MAX_W];
int hs0[MAX_H], hs1[MAX_H], vs0[MAX_W], vs1[MAX_W];
int ds0[MAX_L], ds1[MAX_L], es0[MAX_L], es1[MAX_L];

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) scanf("%d", as[i] + j);

    int l = h + w - 1;
    fill(hs0, hs0 + h, -INF);
    fill(hs1, hs1 + h, -INF);
    fill(vs0, vs0 + w, -INF);
    fill(vs1, vs1 + w, -INF);
    fill(ds0, ds0 + l, -INF);
    fill(ds1, ds1 + l, -INF);
    fill(es0, es0 + l, -INF);
    fill(es1, es1 + l, -INF);
    
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++) {
	if (as[i][j] > hs0[i]) hs1[i] = hs0[i], hs0[i] = as[i][j];
	else if (as[i][j] > hs1[i]) hs1[i] = as[i][j];

	if (as[i][j] > vs0[j]) vs1[j] = vs0[j], vs0[j] = as[i][j];
	else if (as[i][j] > vs1[j]) vs1[j] = as[i][j];

	int dk = i + j;
	if (as[i][j] > ds0[dk]) ds1[dk] = ds0[dk], ds0[dk] = as[i][j];
	else if (as[i][j] > ds1[dk]) ds1[dk] = as[i][j];

	int ek = i + (w - 1 - j);
	if (as[i][j] > es0[ek]) es1[ek] = es0[ek], es0[ek] = as[i][j];
	else if (as[i][j] > es1[ek]) es1[ek] = as[i][j];
      }

    bool f = false;
    for (int i = 0; ! f && i < h; i++)
      for (int j = 0; ! f && j < w; j++) {
	int h = (as[i][j] != hs0[i]) ? hs0[i] : hs1[i];
	if (as[i][j] + h > 0) { f = true; break; }
	
	int v = (as[i][j] != vs0[j]) ? vs0[j] : vs1[j];
	if (as[i][j] + v > 0) { f = true; break; }

	int dk = i + j;
	int d = (as[i][j] != ds0[dk]) ? ds0[dk] : ds1[dk];
	if (as[i][j] + d > 0) { f = true; break; }

	int ek = i + (w - 1 - j);
	int e = (as[i][j] != es0[ek]) ? es0[ek] : es1[ek];
	if (as[i][j] + e > 0) { f = true; break; }
      }

    if (f) puts("infinite");
    else puts("finite");
  }

  return 0;
}

0