Submission #53867340


Source Code Expand

#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

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

  vector<int> A(T);
  for (int i = 0; i < T; ++i)
  {
    cin >> A[i];
  }

  // 行と列と対角線のカウント
  vector<int> rowCount(N, 0);
  vector<int> colCount(N, 0);
  int diag1Count = 0, diag2Count = 0;

  // マス目に対応する行と列を保存するマップ
  unordered_map<int, pair<int, int>> positionMap;
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < N; ++j)
    {
      int num = N * i + j + 1;
      positionMap[num] = {i, j};
    }
  }

  // 印をつけてビンゴを判定
  for (int turn = 0; turn < T; ++turn)
  {
    int num = A[turn];
    auto pos = positionMap[num];
    int row = pos.first;
    int col = pos.second;

    // 行、列、対角線のカウントを増やす
    rowCount[row]++;
    colCount[col]++;
    if (row == col)
      diag1Count++;
    if (row + col == N - 1)
      diag2Count++;

    // ビンゴの判定
    if (rowCount[row] == N || colCount[col] == N || diag1Count == N || diag2Count == N)
    {
      cout << turn + 1 << endl;
      return 0;
    }
  }

  // ビンゴを達成しない場合
  cout << -1 << endl;
  return 0;
}

Submission Info

Submission Time
Task C - Bingo 2
User ryoh1004
Language C++ 23 (gcc 12.2)
Score 300
Code Size 1236 Byte
Status AC
Exec Time 256 ms
Memory 175620 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 39
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3488 KiB
00_sample_01.txt AC 1 ms 3488 KiB
00_sample_02.txt AC 1 ms 3472 KiB
01_random_00.txt AC 1 ms 3364 KiB
01_random_01.txt AC 1 ms 3488 KiB
01_random_02.txt AC 1 ms 3448 KiB
01_random_03.txt AC 1 ms 3528 KiB
01_random_04.txt AC 1 ms 3688 KiB
01_random_05.txt AC 1 ms 3520 KiB
01_random_06.txt AC 1 ms 3488 KiB
01_random_07.txt AC 1 ms 3528 KiB
01_random_08.txt AC 141 ms 83616 KiB
01_random_09.txt AC 242 ms 165424 KiB
01_random_10.txt AC 150 ms 89608 KiB
01_random_11.txt AC 174 ms 109456 KiB
01_random_12.txt AC 245 ms 166328 KiB
01_random_13.txt AC 256 ms 174732 KiB
01_random_14.txt AC 48 ms 13380 KiB
01_random_15.txt AC 48 ms 13376 KiB
01_random_16.txt AC 47 ms 13280 KiB
01_random_17.txt AC 48 ms 13292 KiB
01_random_18.txt AC 48 ms 13428 KiB
01_random_19.txt AC 47 ms 13356 KiB
01_random_20.txt AC 170 ms 106500 KiB
01_random_21.txt AC 185 ms 118732 KiB
01_random_22.txt AC 179 ms 114228 KiB
01_random_23.txt AC 166 ms 102904 KiB
01_random_24.txt AC 163 ms 98076 KiB
01_random_25.txt AC 179 ms 113172 KiB
01_random_26.txt AC 182 ms 116912 KiB
01_random_27.txt AC 240 ms 165396 KiB
01_random_28.txt AC 235 ms 175500 KiB
01_random_29.txt AC 235 ms 175524 KiB
01_random_30.txt AC 247 ms 175528 KiB
01_random_31.txt AC 246 ms 175500 KiB
01_random_32.txt AC 235 ms 175620 KiB
01_random_33.txt AC 235 ms 175560 KiB
01_random_34.txt AC 247 ms 175540 KiB
01_random_35.txt AC 245 ms 175536 KiB